VIS CAD model interaction

Hello,

I encountered a problem when using VIS that the ShapeId(IVtk_IdType) I obtained when selecting with the mouse was incorrect. Causing the obtained ShapeIdList(IVtk_ShapeIdList) to be empty. I don't know how to solve this problem. Do you have any good suggestions.

Vispec DMIS's picture

code for loading the model:
IGESControl_Reader ReaderIGES;
IFSelect_ReturnStatus statIGES = ReaderIGES.ReadFile("E:/Fire_Moloudi.igs");
IFSelect_PrintCount modeIGES = IFSelect_ListByItem;
ReaderIGES.PrintCheckLoad(Standard_True, modeIGES);
ReaderIGES.TransferRoots();
TopoDS_Shape shapeIGES = ReaderIGES.OneShape();

vtkSmartPointer<IVtkTools_ShapeDataSource> shapeDS = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
Handle(IVtkOCC_Shape) iShape = new IVtkOCC_Shape(shapeIGES);
shapeDS->SetShape(iShape);

vtkSmartPointer<IVtkTools_DisplayModeFilter> filter = vtkSmartPointer<IVtkTools_DisplayModeFilter>::New();
filter->AddInputConnection(shapeDS->GetOutputPort());
filter->SetDisplayMode(DM_Shading);

vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(shapeDS->GetOutputPort());
mapper->Update();

vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

this->Ren->AddActor(actor);
this->SetViewCenter();

IVtkTools_ShapeObject::SetShapeSource(shapeDS, actor);

Vispec DMIS's picture

code for selection:
aPicker->SetSelectionMode(SM_Face);
aPicker->Pick(clickPos[0], clickPos[1], 0);

// Traversing results
vtkActor* aPickedActor = NULL;
vtkSmartPointer<vtkActorCollection> anActorCollection = aPicker->GetPickedActors();
int num = anActorCollection->GetNumberOfItems();
//
if (anActorCollection && anActorCollection->GetNumberOfItems() > 0)
{
anActorCollection->InitTraversal();
while (vtkActor* anActor = anActorCollection->GetNextActor())
{
aPickedActor = anActor;
IVtkTools_ShapeDataSource* aDataSource = IVtkTools_ShapeObject::GetShapeSource(aPickedActor);
if (!aDataSource)
continue;

// Access initial shape wrapper
Handle(IVtkOCC_Shape) aShapeWrapper = aDataSource->GetShape();
if (aShapeWrapper.IsNull())
continue;

IVtk_IdType aShapeID = aShapeWrapper->GetId();
IVtk_ShapeIdList subShapeIds = aPicker->GetPickedSubShapesIds(aShapeID);

// Get IDs of cells for picked sub-shapes.
TColStd_PackedMapOfInteger aCellMask;
for (IVtk_ShapeIdList::Iterator sIt(subShapeIds); sIt.More(); sIt.Next())
{
aCellMask.Add((int) sIt.Value());
const TopoDS_Shape& aSubShape = aShapeWrapper->GetSubShape(sIt.Value());
cout << "--------------------------------------------------------------" << endl;
cout << "Sub-shape ID: " << sIt.Value() << endl;
cout << "Sub-shape type: " << aSubShape.TShape()->DynamicType()->Name() << endl;
}

break;
}
}

Vispec DMIS's picture

Have you ever encountered this problem and how did you solve it.

Attachments: