parts of topology not getting triangulation data

I've attached a comparison picture where, what the model should look like is on the left and what I'm generating is on the right. You can see that I'm missing parts of the green area. The green and blue are part of the same shell, and when I'm iterating through all the faces for this shell, I do come across some that do not have triangulation data, and have confirmed that their color is green. I use BRepMesh_IncrementalMesh to generate the data. As far as I understand, iterating through shape topology is the way to obtain polygon data. Am I missing something? 

Patrik Mueller's picture

Hi Aaron,

posting your algorithm would help :-)

I've attached a sample of your model with other parts hidden. So the values inside OCC are correct.

Greets,

Patrik

Attachments: 
Aaron McDonald's picture

It seems that triangles are missing in your picture as well, since the entire inside should be green, except for the tube.
My process is as follows (i've omitted some code for readability):

//collect all free shapes and build single compound

TDF_LabelSequence frshapes;
myAssembly->GetFreeShapes(frshapes);

TopoDS_Compound totalShape;
BRep_Builder shapeBuilder;
shapeBuilder.MakeCompound(totalShape);

std::vector<TDF_Label> labelsList;

Standard_Integer length = frshapes.Length();
for (Standard_Integer i(1); i <= length; ++i) {
    const TDF_Label& label = frshapes.Value(i);
    TopoDS_Shape shape;
    myAssembly->GetShape(label, shape);
    shapeBuilder.Add(totalShape, shape);
}

//calculate tolerance based on object size

//generate mesh

BRepTools::Clean(totalShape);
BRepMesh_IncrementalMesh(totalShape, TOLERANCE, Standard_False, 0.5, Standard_True);

//iterate through labels​

for (Standard_Integer i(1); i <= length; ++i) {
    const TDF_Label& label = frshapes.Value(i);

    parseLabelChildren(label, handler, color, model, location);
}

//inside parse label children function

//check for color

if (assembly->IsAssembly(label)) {
    TDF_LabelSequence comps;
    assembly>GetComponents(label, comps);

    for (Standard_Integer i(1); i <= comps.Length(); ++i) {
        TDF_Label subLabel = comps.Value(i);
        TopLoc_Location newLoc = location;
        TopoDS_Shape shape;
        if (handlers.pAssembly->get()->GetShape(label, shape)) {
            TopLoc_Location loc = shape.Location();
            newLoc = location.Multiplied(loc);
        }

        parseLabelChildren(subLabel, handlers, color, model, newLoc);
    }
}
else if (assembly->IsComponent(label)) {
    TDF_Label refLabel;
    assembly->GetReferredShape(label, refLabel);
    TopLoc_Location newLoc = location;
    TopoDS_Shape shape;
    if (handlers.pAssembly->get()->GetShape(label, shape)) {
        TopLoc_Location loc = shape.Location();
        newLoc = location.Multiplied(loc);
    }

    parseLabelChildren(refLabel, handlers, color, model, newLoc);
}
else {
    TopoDS_Shape shape;
    if (assembly->GetShape(label, shape)) {
        if (shape.ShapeType() == TopAbs_COMPOUND) {
            parseCompound(shape, model, handlers, color, location);
        }
        else if (shape.ShapeType() == TopAbs_SOLID) {
            parseCompound(shape, model, handlers, color, location);
        }
        else if (shape.ShapeType() == TopAbs_SHELL) {
            parseSolid(shape, model, handlers, color, location);
        }
    }
}

at this point parseCompound just iteratest hrough topology looking for subshapes until i get to a shell, where I then iterate through all the faces. the process looks something like this

TopLoc_Location newLoc = location;
TopLoc_Location loc = shape.Location();
newLoc = location.Multiplied(loc);

Mesh mesh; //custom mesh object
uint32_t indexOffset(0);
TopExp_Explorer faceExplorer(shape, TopAbs_FACE);
while (faceExplorer.More()) {
    parseFace(faceExplorer.Current(), model, handlers, mesh, indexOffset, color, newLoc);
    faceExplorer.Next();
}

//parseFace function
//check for color, adjust transform, etc
TopLoc_Location catchLoc;

Handle(Poly_Triangulation) tri = BRep_Tool::Triangulation(face, catchLoc);
gp_Trsf transform = newLoc;
if (tri.IsNull() == Standard_False) {
    const TColgp_Array1OfPnt& nodes = tri->Nodes();
    gp_Pnt transformedPoint;

    //collect points
    for (auto point : nodes) {

        transformedPoint = point.Transformed(transform);
        mesh.Vertices.push_back(Point3D(transformedPoint.X(), transformedPoint.Y(), transformedPoint.Z()));
        mesh.Colors.push_back(Point3D(subColor.Red(), subColor.Green(), subColor.Blue()));
    }
//collect indices

    const Poly_Array1OfTriangle& triangles = tri->Triangles();
    const Standard_Integer triCount = tri->NbTriangles();

    Standard_Integer pointA(-1), pointB(-1), pointC(-1);
    Triangle polyTri;
    for (auto triangle : triangles) {
        triangle.Get(pointA, pointB, pointC);

        Standard_Integer trueA = pointA - 1 + indexOffset, trueB, trueC;
        if (face.Orientation() == TopAbs_REVERSED) {
            trueB = pointC - 1 + indexOffset;
            trueC = pointB - 1 + indexOffset;
        }
        else if (face.Orientation() == TopAbs_FORWARD) {
            trueB = pointB - 1 + indexOffset;
            trueC = pointC - 1 + indexOffset;
        }

        polyTri.a = trueA;
        polyTri.b = trueB;
        polyTri.c = trueC;
        mesh.Triangles.push_back(polyTri);

    }

//get normals...

}

and so on and so forth, for each shell. I've uploaded the cpp which contains all the parsing and iterating. it is a bit of a mess since I'm still messing around with stuff.

Attachments: 
Patrik Mueller's picture

Hi Aaron,

I've got the same view in my viewer as in CAD Assistant.

But looking at your code: in "parseLabelChildren", try to find the color without the curve colors (or switch the order for color check so that the curve is the latest one).

Have you checked the STEP file in applications without OCCT?

Greets,

Patrik

Aaron McDonald's picture

Interesting. The application I test with is autodesk's 360 viewer https://a360.autodesk.com/viewer/. I'm not sure what the tech is underneath. In the picture I attached in my first post you can see the result on the left, with the entire inside being green.

Aaron McDonald's picture

loaded the step file into SolidWorks and it also has no issues with all the green faces. I can't seem to figure out where exactly the issue is and why these faces wont receive any triangulation data. The problem does seem related to curves however, as I've started to notice gaps in curved parts of other shapes.