Parsing 3dm file

 From:  Michael Gibson
5061.2 In reply to 5061.1 
Hi miquik, the diagram here may help:

> My question is : Am I always sure that every BrepLoop I read is closed?

There's a m_type field on ON_BrepLoop which marks the type of the loop as one of:

  enum TYPE {
    unknown  = 0,
    outer    = 1,  // 2d loop curves form a simple closed curve with a counterclockwise orientation
    inner    = 2,  // 2d loop curves form a simple closed curve with a clockwise orientation
    slit     = 3,  // always closed - used internally during splitting operations
    crvonsrf = 4,  // "loop" is a curveonsrf made from a single 
                   // (open or closed) trim that is has type ON_BrepTrim::crvonsrf.
    ptonsrf = 5,   // "loop" is a ptonsrf made from a single 
                   // trim that is has type ON_BrepTrim::ptonsrf.
    type_count = 6

If the type is one of: outer, inner, or slit then it is supposed to form a closed loop and you shouldn't have to check it for being closed. If it's marked as a type "crvonsrf", then the loop is not actually a trim loop that actually cuts the face but is instead a holder for just a regular curve that lives on the surface, and if it's marked as "ptonsrf" then it actually doesn't have any curves at all and it's just a holder for a uv point that lives on the surface.

MoI will only make loops of the "outer" or "inner" varieties and not these other types, but other programs could. You probably just want to skip the "crvonsrf" or "ptonsrf" ones since those do not actually cut anything on the face, they're more like for sticking curves and points embedded into the brep so that they are carried around with the brep while some various kinds of code may be passing it around and doing different kinds of things to it.

> Other question : the list of BrepTrim are in correct order (i
> mean the end vertex of BrepTrim1 is equal to BrepTrim2 start
> vertex, and so on?)

Yes, I'm pretty sure that's the case.

> BrepTrims are always oriented correctly (I mean clockwise order
> for outer trimming loop and counter-clockwise for every internal
> trimming loop)?

Yeah each trim holds a UV curve and each of those UV curves will be oriented in the loop direction such that the active part of the face is on the left-hand side of the trim curve, so it's actually opposite of what you wrote here, it's counter-clockwise for the outer one and clockwise for each inner one. You shouldn't need to check that unless you want to possibly deal with correcting files that were not written properly by the generating application.

But this is all for the UV parameter space curves - the 3D edge curves are separate from that and the 3D edge curve that's associated with the trim can be reversed in direction from the UV loop direction since it's possible for different loop boundaries to share the same 3D edge curve where they are joined to one another. When that's the case the m_bRev3d flag will be set on the trim.

Hope this helps!

- Michael