How to make a shape selected without the click in the scene for VTK Integration Services (VIS)

      Hi, everyone~~. I would like to use the tree structure to show the shape topology of OCCT entities, where a sub_shape is represented by a tree node(QTreeWidgetItem in Qt). Hence, I want to make the sub_shape selected or highhighted by clicking the the tree node item, intead of the selection in the scene. By now, I would like to use the VTK Integration Services (VIS) for the visualizaion and selection and fail to find some associated APIs. I wonder if someone have some ideas, thank you very much~~. best wishes ^_^

Forum supervisor's picture

Dear Once,

VIS component follows the design of the toolkit it is based on - i.e. VTK.

In VTK, there is no notion of "selected objects" as they are understood by OCCT visualization. Instead, there are "picked objects", which are returned by vtkAbstractPicker algorithm, they represent results of interactive picking (selection). However, you do not need to pick anything in your case, you just need to highlight some actors you already know. It is recommended to have a look at IVtkDraw_Interactor::OnSelection() for a sample implementation of OCCT shape highlighting in a VTK scene using VIS.

Best regards

FSR.

Once's picture

Dear supervisor:

     I am so glad and appreciated you have given me some advices. I have got contant with the open Cascade for over two weeks and continue to read the TKIVtk and TKIVtkDraw projects in the sourc code these three days.Now I think I have got something. It seems that the IVtkTools_SubPolyDataFileter can be used to tranform a sub_shape into a polydata object and then an corresponding actor could be built in VTK integration Services. All I need to know is the id of the sub_shape that I want to highlight.I have written a sample:

 ...

         vtkSmartPointer<IVtkTools_SubPolyDataFilter> subShapesFilter=vtkSmartPointer<IVtkTools_SubPolyDataFilter>::New();
            subShapesFilter->SetInputConnection(Ds->GetOutputPort());

            IVtk_ShapeIdList subShapeIds;
            subShapeIds.Append(2);// 2 is the sub_shape id;
            subShapesFilter->SetData(subShapeIds);
            subShapesFilter->Modified();
            vtkSmartPointer<vtkPolyDataMapper> aSubMapper=vtkSmartPointer<vtkPolyDataMapper>::New();
            aSubMapper->AddInputConnection(subShapesFilter->GetOutputPort());
            vtkSmartPointer<vtkLODActor> aSubActor=vtkSmartPointer<vtkLODActor>::New();
            aSubActor->SetMapper(aSubMapper);
            aSubActor->GetProperty()->SetColor(1.0,0.0,0.0);
            renderer->AddActor(aSubActor);

.....

    In IVtkDraw_Interactor.cxx and IVtkDraw.cxx, it is a little complicated for they use a collection of IVtkDraw_HighlightAndSelectionPipelines to do such things. One IVtkDraw_HighlightAndSelectionPipeline object contains the  myActor,the myHiliActor and the mySelActor memebers with the corresponding IVtkTools_SubPolyDataFilters to execute the display mode, the highlight and the selection rendering in the pipeline. 

    Now I have a another question. the IVtkOCC_Shape class can get the sub_shape ids with the member function:

 Standard_EXPORT IVtk_ShapeIdList GetSubIds (const IVtk_IdType) const;

    However,it make me feel strange that it doesn't give a member function to obtain the sub_shape id of the top-level shape that represents the whole model. I know the value of this id is usually 1, which has been tested in my program. However, it will be unsafe if the second level sub_shapes are obtained by just perform:

    IVtk_ShapeIdList Ids=occ_shape->GetSubIds(1);

   I will be so thankful if you can solve this confusion of mine.

Best regards

Once.

Forum supervisor's picture

Dear Once,

If you think something in IVTk API can and should be improved, please do not hesitate to formulate your vision via OCCT Mantis issue (http://tracker.dev.opencascade.org). This is a common entry point for all OCCT bug fixes and improvements. We would be glad to receive a relevant contribution from you.

Best regards

FSR.

Once's picture

Dear supervisor:

     Thank you for your advice, I will keep an eye on the OCCT Mantis issue. Have a good day~

Best regards

Once.