Thu, 03/31/2022 - 09:20
Forums:
Hello OCCT Community,
After reading the STEP file, I made an implementation to show each corner and center point when I click on any face on the resulting shapes. In some STEP files this works, in others it draws the vertex out of the shape. This problem can be seen in the images that I have attached. And, I'm sharing my code-snippets:
When mouse pressed:
if(!ais_interactive_context_->DetectedOwner().IsNull())
{
std::cout<<"Detected Owner of AIS Interactive Context is not NULL!"<<std::endl;
Handle(AIS_InteractiveObject) picked = ais_interactive_context_->DetectedInteractive();
ais_interactive_context_->InitSelected();
Handle(SelectMgr_EntityOwner) aSelOwner = ais_interactive_context_->SelectedOwner();
Handle(SelectMgr_EntityOwner) detectedOwner = ais_interactive_context_->DetectedOwner();
Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (detectedOwner);
if (!aBRepOwner.IsNull() && aBRepOwner->Shape().ShapeType() == TopAbs_FACE){
face_sub_shape_ = TopoDS::Face(aBRepOwner->Shape());
std::cout<<"Selected BRepOwner is not NULL & Shape Type is FACE!"<<std::endl;
}else if(!aBRepOwner.IsNull() && aBRepOwner->Shape().ShapeType() == TopAbs_VERTEX){
vertex_sub_shape_ = TopoDS::Vertex(aBRepOwner->Shape());
std::cout<<"Selected BRepOwner is not NULL & Shape Type is VERTEX!"<<std::endl;
std::cout<<"Selected Shape type is VERTEX! "<<std::endl;
for(TopExp_Explorer vertEx(vertex_sub_shape_, TopAbs_VERTEX); vertEx.More(); vertEx.Next()) {
TopoDS_Vertex aVertex = TopoDS::Vertex(vertEx.Current());
gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
std::cout << "Selected VERTEX of the Selected FACE: " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z()<<std::endl;
this->createSphere(aPnt, 5.0, Quantity_NOC_RED);
}
}else {
std::cout<<"Selected BRepOwner is NULL!"<<std::endl;
return;
}
if ( face_sub_shape_.ShapeType() == TopAbs_FACE )
{
const TopoDS_Face& face = TopoDS::Face(face_sub_shape_);
GProp_GProps surfaceProperties;
BRepGProp::SurfaceProperties(face_sub_shape_,surfaceProperties, false, false);
std::cout << "Surface's Center of Mass: " << surfaceProperties.CentreOfMass().X() << " " << surfaceProperties.CentreOfMass().Y() << " " << surfaceProperties.CentreOfMass().Z() << std::endl;
gp_Pnt center_point_of_surface (surfaceProperties.CentreOfMass().X(), surfaceProperties.CentreOfMass().Y(), surfaceProperties.CentreOfMass().Z());
this->createVertex(center_point_of_surface, Quantity_NameOfColor::Quantity_NOC_BLUE);
// Show all Vertices of the Selected Surface
for(TopExp_Explorer vertEx(face_sub_shape_, TopAbs_VERTEX); vertEx.More(); vertEx.Next()) {
TopoDS_Vertex aVertex = TopoDS::Vertex(vertEx.Current());
gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
this->createVertex(aPnt, Quantity_NameOfColor::Quantity_NOC_BLUE);
}
}
}
updateView();
}
Do you have any suggestion about this issue? Could you clearly understand where I made a mistake when you look at the code? If not, I can add more code snippets.
Thank you in advance!
Attachments:
Thu, 03/31/2022 - 11:31
How shape is displayed in the viewer? Maybe your AIS_Shape has non-identity location?
Thu, 03/31/2022 - 14:18
Thu, 03/31/2022 - 14:21
Thu, 03/31/2022 - 15:06
So indeed, you assign transformation to AIS_Shape presentation. TopoDS_Shape returned by StdSelect_BRepOwner::Shape() usually doesn't include this transformation - so that you may try to apply this location (your STEP file does define some transformations to shapes).
Tue, 04/19/2022 - 00:15
Hello Kirill,
I've been investigating and trying on official OCCT samples with some modifications for a while. For example, I've used the "STEP import methods from OCCT/samples/ios/UIKitSample/UIKitSample" for getting individual labels in STEP topology and list them in a tree on UI. This application is attached as sample_1.zip. The main problem here is that when I select a face, it places the vertices in an area outside the object (Just like the problem I mentioned before, but this time I'm adding the whole sample program here for a clearer understanding).
As another example I've used the "OCCT/samples/qt/OCCTOverview --> Data Exchange Category & Import STEP Sample" and in this example, whichever face I clicked, the vertices on it visualizes and this was exactly the result I would like to achieve. What I require to add here is to take each label in the step topology separately, as I mentioned in the first example, and list them in a tree. So if I visualize the assembly as a whole and select it with the mouse, it correctly positions the vertexes. This application also is attached as sample_2.zip.
I apologize for could not understanding your solution. However, do I need to go to the solution without using the SetLocalTransformation method here? If so, how can I properly visualize the location information I get while reading the STEP file?
Thank you for your guidance.