Using the FemurCutExample with a different ImageData file

I am trying to generate a level set deformable model using LocalMarchingCubes through the same method as the FemurCutExample with a different ImageData file. When importing the model and generating surface mesh data, it appears that the normals are flipped, however when using surfMesh->flipNormals() the normals still do not match the mesh until a collision occurs between the tool and the model. Also, collision does not appear to be working properly. The tool will often get stuck on the model or outright disappear and does not deform the model correctly.

My suspicion:
1.) You had previously mentioned this was a binary mask. Given the resolution I’m seeing is this still a binary mask? You must feed the LevelSetModel a Signed Distance Field. Many popular tools can compute an SDF ImageData from a input polygon. iMSTK can as well:

SurfaceMeshDistanceTransform computeSdf;
computeSdf.setInputMesh(dragonSurfMesh); // Make sure its closed (no duplicate vertices/disconnected polygons)
computeSdf.setDimensions(50, 50, 50);
// Bounds will be default computed for you should you not provide it
computeSdf.setBounds(minBoundsVec3, maxBoundsVec3);
std::shared_ptr<ImageData> initLvlsetImage = computeSdf->getOutputImage();

2.) The normals could be backwards if the surface is extracted backwards. For a Signed Distance Field (which gives signed (inside/outside) shortest distance to the surface at every point in the image) the negatives should be inside, the positives outside.

Additional tip on setting up:
1.) You can control a push factor in the interaction to change cut/erosion speed.
2.) You can toggle proportional force to cut speed.
3.) For LocalMarchingCubes you must ensure the size of the image is divisible by the chunks. If not divisible a warning is thrown and it will take the next remainder found (could be undesirably large). Also chunks can quickly grow in memory. Only 10x10x10=1000 allocated VisualModels.
4.) You can volume render the image by directly giving the ImageData to the VisualModel and setting a transfer function where val>0 β†’ transparent & val<=0 β†’ opaque
5.) This interaction has an opportunity for improvement with usage of PBD rigid bodies instead RigidBodyModel2. Interaction not programmed yet.

This worked to fix the normals for the surfaces, however there are some holes in the generated surface meshes. I tested it with two of the included meshes, β€œ/Surgical Instruments/Scalpel/Scalpel_Hull_Subdivided.stl” and β€œ/legs/femurBone.stl” and this was the result.

If your bounds cuts off the shape you would see this sort of plane cut. Kinda looks like what that is?

That appears to fix the issue with the holes in the meshes, however for the mesh I am trying to use, if I change the value of the bounds away from the default generated values, the normals of the mesh flip.

My mistake it looks like I set up the bounds incorrectly which resulted in the problems with the mesh. Thanks for the help!

1 Like