
Wed, 05/09/2012 - 14:58
Forums:
Hi,
I opened a local context, loaded a mesh and selected some triangles with "Select". How can I enumerate the selected Triangles?
int contextID = context->OpenLocalContext(0, 1);
aisMesh->SetMeshSelMethod(MeshVS_MSM_BOX);
context->Load(aisObj);
context->SetSelectionMode(aisObj, 8);
context->Activate(aisObj, 8);
// Select some triangles
context->Select(0, 0, ui.qOCViewer->width() / 2, ui.qOCViewer->height() / 2, view);
Regards
SK
Attachments:
Thu, 05/10/2012 - 11:53
After *HOURS* I found this solution, deeply buried in the documentation:
for (context->InitSelected(); context->MoreSelected(); context->NextSelected())
{
Handle_MeshVS_MeshEntityOwner owner = Handle_MeshVS_MeshEntityOwner::DownCast( context->SelectedOwner());
if(owner.IsNull()) continue;
if(owner->Type() == MeshVS_ET_Face)
{
Handle_MeshVS_DataSource source = aisMesh->GetDataSource();
Handle_MeshVS_Drawer drawer = aisMesh->GetDrawer();
int maxFaceNodes;
if (drawer->GetInteger(MeshVS_DA_MaxFaceNodes, maxFaceNodes) && maxFaceNodes > 0)
{
MeshVS_Buffer coordsBuf (3 * maxFaceNodes * sizeof(Standard_Real));
TColStd_Array1OfReal coords ( coordsBuf, 1, 3 * maxFaceNodes );
int nbNodes = 0;
MeshVS_EntityType entityType;
if (source->GetGeom(owner->ID(), true, coords, nbNodes, entityType))
{
if (nbNodes >= 3)
{
gp_Pnt p1 = gp_Pnt( coords(1), coords(2), coords(3));
gp_Pnt p2 = gp_Pnt( coords(4), coords(5), coords(6));
gp_Pnt p3 = gp_Pnt( coords(7), coords(8), coords(9));
// do something with p1, p2 and p3
}
}
}
}
}