For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

How can I get the information of a Shape

siyamalan's picture
Forums: 

Hi,
I have a shape. I want to get all the information about it such that vertices(value of x,y and z), edges, wires, faces, etc. How can I do that?

Paul Jimenez's picture

TopExp_Explorer and BRep_Tool::Pnt.

siyamalan's picture

Could you please give me a small example...

Paul Jimenez's picture

// Explore faces...
for (TopExp_Explorer fExpl(aShape, TopAbs_FACE); fExpl.More(); fExpl.Next())
{
const TopoDS_Face &curFace = static_cast(fExpl.Current());

for (TopExp_Explorer wExpl(curFace, TopAbs_WIRE); wExpl.More(); wExpl.Next())
{
// ...
// somewhere deeper
const TopoDS_Vertex &curVertex = static_cast(vExpl.Current());
const gp_Pnt curVertexPos = BRep_Tool::Pnt(curVertex);
// ...
}
}

You may also want to check all methods of TopExp.

siyamalan's picture

Thank you very much for your reply. But what I want to know is.............

An EDGE can be any type a polyline, a curve, an arc etc. If I have an EDGE, I want to know that type(polyline, curve, arc or any other types) and if that is a curve I want to know the control points and other details.
How can I get those details?

Mikael Aronsson's picture

A quick look in the documentation could be a good idea, there are a number of examples on how to use TopExp_Explorer.

siyamalan's picture

Thank you very much for your reply. But what I want to know is.............

An EDGE can be any type a polyline, a curve, an arc etc. If I have an EDGE, I want to know that type(polyline, curve, arc or any other types) and if that is a curve I want to know the control points and other details.
How can I get those details?

Sharjith Naramparambath's picture

I think first of all an Edge cannot be a polyline because, the Edge always has an underlying geometry of a curve. A polyline could be a Wire in which Edges are connected together - open or closed. In that case each edge would again have underlying geometry of Curve (line).

What you can do is, use the following pseudocode to get the underlying curve of each edge...

Handle(Geom_Curve) crv = BRep_Tool::Curve(edge);
if(crv->DynamicType() == STANDARD_TYPE(Geom_Line))
{
Handle(Geom_Line) lin = Handle(Geom_Line)::DownCast(crv);
... do whatever with line
}
else if (crv->DynamicType() == STANDARD_TYPE(Geom_BezierCurve))
{
Handle(Geom_BezierCurve) bez = Handle(Geom_BezierCurve)::DownCast(crv);
... get the control point array...
}
else
...

Remember, if you have a wire you can use TopExp to explore each edge and find out what each one is.

BRep_Tool has static methods Surface, Curve and Pnt to give Geom_Surface, Geom_Curve and gp_Pnt from TopoDS_Face, TopoDS_Edge and TopoDS_Vertex respectively .

Hope this solves your problem

Regards
N. Sharjith

siyamalan's picture

Hi,

Thank you very much for you all.

I got it.

Vidhyan's picture

for (Ex1.Init(ResultShape,TopAbs_SOLID); Ex1.More(); Ex1.Next())
{
count1++;
TDF_Label L1 = L.FindChild(5);
TDataStd_Name::Set(L1, "Solid");
for (Ex2.Init(Ex1.Current(),TopAbs_SHELL); Ex2.More(); Ex2.Next())
{
TDF_Label L2 = TDF_TagSource::NewChild(L1);
TDataStd_Name::Set(L2, "Shell");
count2++;
for (Ex3.Init(Ex2.Current(),TopAbs_FACE); Ex3.More(); Ex3.Next())
{
TDF_Label L3 = TDF_TagSource::NewChild(L2);
TDataStd_Name::Set(L3, "Face");
count3++;
for (Ex4.Init(Ex3.Current(),TopAbs_WIRE); Ex4.More(); Ex4.Next())
{
TDF_Label L4 = TDF_TagSource::NewChild(L3);
TDataStd_Name::Set(L4, "Wire");
count4++;
for (Ex5.Init(Ex4.Current(),TopAbs_EDGE); Ex5.More(); Ex5.Next())
{
TDF_Label L5 = TDF_TagSource::NewChild(L4);
TDataStd_Name::Set(L5, "Edge");
count5++;
for (Ex6.Init(Ex5.Current(),TopAbs_VERTEX); Ex6.More(); Ex6.Next())
{
TDF_Label L6 = TDF_TagSource::NewChild(L5);
TDataStd_Name::Set(L6, "Point");
TopoDS_Vertex vertex = TopoDS::Vertex(Ex6.Current());
gp_Pnt pt = BRep_Tool::Pnt(vertex);
Standard_Real x1= pt.X();
Standard_Real y1= pt.Y();
Standard_Real z1= pt.Z();
TDataStd_Real::Set(L6.FindChild(1), x1);
TDataStd_Real::Set(L6.FindChild(2), y1);
TDataStd_Real::Set(L6.FindChild(3), z1);
count6++;
}

}

}

}

}

}

This code will help You

siyamalan's picture

Hi,

Thank you very much for you all.

I got it.

Divya's picture

Hi,
can u tell me wat function needs to be used to get edge information of a shape.

arkoala's picture

You have it just in this thread: Vidhyan answer.

You can study all the hierarchical structure of a solid, just copying and pasting.

All the 'Ex#' variables must to be defined as TopExp_Explorer.

This is one of my reference posts!

Regards.