When using OOC, loading and storing of data in memory can be a highly intensive process. When highlights are active, this means almost every update HOOPS has to recollect the highlighted objects adding more intensity and could slow down performance if you are working with a big OOC model.
A workaround to this problem is to query and insert the selected data directly to HOOPS’s database. Using this method, HOOPS does not have to recollect highlighted objects for every update.
Below is sample code using a custom operator.
class OOCHighlightOperator: public SelectAreaOperator {
SegmentKey m_highlight_segment;
ShellKey m_shell;
Canvas m_canvas;
PointArray GetPointsFromItem(SelectionItem const& item)
{
PointArray points;
Key key;
item.ShowSelectedItem(key);
// Ensure we are on a shell and extract selected points
if (key.Type() == Type::ShellKey) {
ShellKey shell_key(key);
PointArray shell_points;
shell_key.ShowPoints(shell_points);
SizeTArray selected_points;
item.ShowVertices(selected_points);
for (size_t const pt: selected_points) {
points.push_back(shell_points[pt]);
}
}
return points;
}
PointArray GetPointsFromSelection()
{
PointArray points;
auto it = GetActiveSelection().GetIterator();
while (it.IsValid()) {
// Get key path for ooc transformation
KeyPath path;
it.GetItem().ShowPath(path);
MatrixKit kit;
path.ShowNetModellingMatrix(kit);
m_highlight_segment.SetModellingMatrix(kit);
PointArray new_points = GetPointsFromItem(it.GetItem());
points.insert(points.end(), new_points.begin(), new_points.end());
it.Next();
}
return points;
}
public:
explicit OOCHighlightOperator(SegmentKey key): m_highlight_segment(std::move(key)) {}
explicit OOCHighlightOperator(Canvas const& canvas): m_canvas(canvas)
{
// Setup the highlight segment
m_highlight_segment = m_canvas.GetFrontView().GetSegmentKey().Subsegment("fast_highlight_ooc");
m_highlight_segment.GetMaterialMappingControl()
.SetVertexColor(RGBColor(1.0f, 1.0f, 0.0f))
.SetMarkerColor(RGBColor(1.0f, 1.0f, 0.0f));
m_highlight_segment.GetDrawingAttributeControl().SetOverlay(Drawing::Overlay::InPlace);
m_highlight_segment.GetVisibilityControl().SetVertices(true);
// Setup the selection options on Subentities i.e. vertices
SelectionOptionsKit kit;
kit.SetLevel(Selection::Level::Subentity).SetInternalLimit(5000).SetRelatedLimit(5000);
SetSelectionOptions(kit);
}
bool OnMouseUp(MouseState const& state) override
{
bool result = SelectAreaOperator::OnMouseUp(state);
// Delete previous shell
m_shell.Delete();
PointArray points = GetPointsFromSelection();
// Insert the shell to display only the vertices
IntArray indices;
m_shell = m_highlight_segment.InsertShell(points, indices);
m_canvas.Update();
return result;
}
};
void CHPSView::OnUserCode1()
{
GetCanvas().GetFrontView().GetOperatorControl().Push(new OOCHighlightOperator(GetCanvas()));
}