Below is sample code on how you select and highlight sub-entity geometry.
Note: You will need to enable sub-entity option in both selection and highlighting kit.
HPS::SelectionOptionsKit myKit;
myKit.GetDefault();
HPS::SegmentKey modelKey = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey();
Point points[4] = { Point(0, 0, 0),
Point(2, 0, 0),
Point(2, 2, 0),
Point(0, 2, 0) };
int faceList[5] = { 4, 0, 1, 2, 3 };
modelKey.GetSelectabilityControl().SetVertices(true);
modelKey.Subsegment().InsertShell(4, points, 5, faceList);
modelKey.GetVisibilityControl().SetFaces(false).SetEdges(false).SetVertices(true);
modelKey.GetMarkerAttributeControl().SetSize(2);
GetCanvas().GetFrontView().FitWorld();
GetCanvas().UpdateWithNotifier().Wait();
// Set Highlight Style
HPS::PortfolioKey portfolio = GetCanvas().GetFrontView().GetAttachedModel().GetPortfolioKey();
SegmentKey style1_source = Database::CreateRootSegment();
NamedStyleDefinition style1 = portfolio.DefineNamedStyle("style1", style1_source);
style1_source.GetMaterialMappingControl()
.SetVertexColor(RGBAColor(1.0f, 0.0f, 0.0f));
auto options1 = HighlightOptionsKit("style1");
options1.SetSubentityHighlighting(true);
/// <summary>
///
/// </summary>
HPS::SelectionOptionsKit selectionOptions;
selectionOptions.SetAlgorithm(HPS::Selection::Algorithm::Analytic);
selectionOptions.SetLevel(HPS::Selection::Level::Subentity);
selectionOptions.SetInternalLimit(-1).SetRelatedLimit(-1);
HPS::SelectionResults selectionResults;
// specify the window-space rectangle where you want to select
size_t numSelectedItems =
GetCanvas().GetWindowKey().GetSelectionControl().SelectByArea(HPS::Rectangle(0, 1, -1, 1), selectionOptions, selectionResults);
HPS::SelectionResultsIterator srIterator = selectionResults.GetIterator();
while (srIterator.IsValid()) {
HPS::SelectionItem selectionItem = srIterator.GetItem();
HPS::Key key;
selectionItem.ShowSelectedItem(key); // 'key' is the HPS::Key of the selected item
if (key.Type() == HPS::Type::ShellKey) {
// if we get here, the shell has selected at least one sphere
HPS::SizeTArray out_faces, out_vertices, edges1, edges2;
// out_faces is a list of faces
selectionItem.ShowFaces(out_faces);
// out_vertices is list of vertices
selectionItem.ShowVertices(out_vertices);
// edges1 and edges2 are parallel
selectionItem.ShowEdges(edges1, edges2);
HPS::KeyPath selectionKeyPath;
selectionItem.ShowPath(selectionKeyPath);
GetCanvas().GetWindowKey().GetHighlightControl().Highlight(key, options1, out_vertices, edges1, edges2, out_faces);
GetCanvas().UpdateWithNotifier().Wait();
}
srIterator.Next();
}