Announcement

Collapse
No announcement yet.

Errors when attempting to get the triangles from a PoTriangleMesh2D

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Errors when attempting to get the triangles from a PoTriangleMesh2D

    I have a bunch of x, y and z points and have a bit of code that creates a triangular mesh.

    Code:
    auto meshDataNode = new PoTriangleMesh2D();
    meshDataNode->setGeometry(numPoints, x, y);
    meshDataNode->addValuesSet(0, z);
    I am now trying to get the triangles from this mesh

    Code:
    auto mesh = meshDataNode->mesh.getValue();
    int numVals, numTris;
    const float* xVals = nullptr; // Not used
    const float* yVals = nullptr; // Not used
    const float* zVals = nullptr; // Not used
    const int32_t* indices = nullptr;
    mesh.getGeometry(numVals, xVals, yVals, zVals, numTris, indices);
    std::cout << numTris << " triangles created\n";
    
    // Set the mesh data again, this time with Z coords and triangle indices
    int32_t* triIndices = new int32_t[numTris * 3];
    memcpy(triIndices, indices, sizeof(int32_t) * numTris * 3);
    meshDataNode = new PoTriangleMesh2D();
    meshDataNode->setGeometry(numVals, xvals, yvals, zvals, numTris, triIndices);
    m_scene->addChild(meshDataNode);
    
    // Finally create a node to render the mesh.
    auto meshDrawNode = new PoMeshFilled();
    m_scene->addChild(meshDrawNode);
    However, I get a crash when I get to the line where I'm creating the PoMeshFilled object.


    2022-04-01_09-09-37.png
    What is going wrong? I am using Open Inventor 9.8 and associated MeshViz version.

    Thanks

    Lisa

  • #2
    Originally posted by lisamcgregor View Post
    However, I get a crash when I get to the line where I'm creating the PoMeshFilled object.
    Hi Lisa,
    Sorry, but I don't see anything that should cause a crash like that. Attached is a test case TestDelaunay2.zip that, I think, does what your code is doing. It works fine on my machine with OIV 9.9. You could try my test case and see if it works on your machine.

    Minor: My text case also shows an alternate way to set the computed triangles - see the ifdef "OTHER". I don't think your code should cause a crash, but note that you are creating a new PoTriangleMesh2D and assigning it to the existing pointer 'meshDataNode'. That's a memory leak. :-)
    Regards,
    Mike

    Comment

    Working...
    X