Identify all the vertices of part

Hello,

I'm a newbie with OCC. I want to ask you 1 question: How can I extract coordinates of all the vertices of a slot from a STEP file and input the result to a text file with name separately for each vertex (like vertex1 (3; 4; 5), vertex2 (1; 2; 3)?

I hope to receive your answers soon. 

Tuan

Giovanni Bettega's picture

Ciao


//! all includes have been intentionally omitted
//! assuming you .step file is FILENAME
//! coords are written onto stdoutput
//! BRepTool::Pnt(const TopoDS_Vertex) gets access to the point coords

STEPControl_Reader aReader;
IFSelect_ReturnStatus stat = aReader.ReadFile(FILENAME);

if(stat!=IFSelect_RetDone) exit(1);

aReader.TransferRoots();
const TopoDS_Shape &aShape = aReader.OneShape();

TopTools_IndexedMapOfShape vMap;
TopExp::MapShapes(aShape,TopAbs_VERTEX,vMap);
for(int n=1; n<=vMap.Extent(); n++)
{
    const TopoDS_Vertex &aVertex = TopoDS::Vertex(vMap.FindKey(n));
    const gp_Pnt &P = BRep_Tool::Pnt(aVertex);
    int index = vMap.FindIndex(aVertex);
    printf("Vertex index: %d Coords(%f, %f, %f)\n",index,P.X(),P.Y(),P.Z());
}

Giovanni

haituandn2010_145903's picture

Hello Giovanni,

Thank you for your reply. It worked.

Can you help me with a problem about the normal vector?

 I extracted the normal vector of all planes of Slot. But do you know how to calculate the cross and dot product between 2 normal vectors?

Tuan 

Giovanni Bettega's picture

Ciao

gp_Dir identifies a unit vector in space. Example for a dot product:

gp_Dir aDirection1;

gp_Dir aDirection2;

double val = aDirection1.Dot(aDirection2); //! scalar procuct

For a the vectorial product use the method gp_Dir::cross. 

Several methods are available. See the documentation of package gp for further details.

Giovanni

haituandn2010_145903's picture

Hello,

Thank you for your answer.

Do you know how to choose exactly the normal vector of 3 planes creating the slot (see in the step file)? 

Any loop to find them quickly?

Tuan 

Attachments: