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 to get wires from single face?

Malcolm Revenge's picture
Forums: 

Hi! I need collection of 3d lines of shape edges, how i can get it?

I have TopoDS_Shape, i know, how to iterate all faces, so i have TopoDS_Face -s, and now i want to take edges of each face for rendering it with custom 3d engine. I need simple collection of 3d lines, like this: LINE1(v1,v2), LINE2(v1,v2) and so on...

need help :(

Malcolm Revenge's picture

Guys, ok. I don't need edges of single face :-) I need all edges of the shape,for example, box have 10 edges. How i can to retrieve this edges of my shape?

qa qa's picture

Hello,

Please look at "TopExp_Explorer" class. It allows to iterate over sub-shapes.

qa qa

Malcolm Revenge's picture

Please look at "TopExp_Explorer" class. It allows to iterate over sub-shapes.

Thank you very much for reply! But sorry, i'm really newbie in OCC, can you show me few lines of C++ code to get edges of...for example, simple box shape? I need collection of 3d lines with start and end vertices for each line to drawing native in OpenGl as lines...

P.S.: at now i really don't understand, how OCC topology works, handlers...strange class names, strange FOR itarators...:-)

Thanks

Jeason Diesel's picture

Hello! You can search "TopExp_Explorer" in your OCC samples (just like "Geometry" or "Modeling" which is in "All-vc-10").And you can solve many problems in this way !Just try "ctrl+F" 

qa qa's picture

Hello,

Here is my short sample:

  TopoDS_Shape aShape = ...; // Your initial shape.
  for (TopExp_Explorer anExp(aShape, TopAbs_EDGE); anExp.More(); anExp.Next())
  {
    // Iterate over edges in input shape.
    const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());

    // Take geometrical data from edge.
    Standard_Real aF, aL;
    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aF, aL);

    // After that, it is possible to take sample points to discretize the curve.
    const Standard_Integer NBPOINTS = 10;
    for (Standard_Integer i = 1; i <= NBPOINTS; ++i)
    {
      Standard_Real aPreviousPntParam = aF + (aL - aF) * (i - 1) / (NBPOINTS);
      Standard_Real aCurrentPntParam =  aF + (aL - aF) *  i      / (NBPOINTS);

      gp_Pnt aPreviousPnt = aCurve->Value(aPreviousPntParam);
      gp_Pnt aCurrentPnt = aCurve->Value(aCurrentPntParam);

      // aPreviousPnt, aCurrentPnt - points on which you can construct line.
    }
  }

 
qa qa

Malcolm Revenge's picture

Here is my short sample:

Thank you! you are my idol! :-)

Hmm.. If my edges is a simple segments (simple box shape), it's mean, that here i need only 2 points? Can i iterate over segment edges or in any case, i need first iterate over curves and after transform it into the line segment?

qa qa's picture

Well, when your underlying curves are represented by lines, this snippet can be significantly simplified - you can you use TopExp::Vertices(...) instead of discretization procedure. Here is updated sample:

  TopoDS_Shape aShape = ...; // Your initial shape.
  for (TopExp_Explorer anExp(aShape, TopAbs_EDGE); anExp.More(); anExp.Next())
  {
    // Iterate over edges in input shape.
    const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());

    // Take the first and the last vertices from edge
    TopoDS_Vertex aVFirst = TopExp::FirstVertex(anEdge);
    TopoDS_Vertex aVLast  = TopExp::LastVertex(anEdge);

    // Take geometrical information from vertices.
    gp_Pnt aPntFirst = BRep_Tool::Pnt(aVFirst);
    gp_Pnt aPntLast = BRep_Tool::Pnt(aVLast);
  }

qa qa

Malcolm Revenge's picture

Wow!  Many thanks, bro!