Skip to content

Commit

Permalink
Create mesh complete folder python 1049 (SimVascular#1050)
Browse files Browse the repository at this point in the history
* Add functionality to add a ModelFaceID array and Normals to a mesh face.

* Add creating a ModelRegionID array and move adding Normal data into sv_tetgenmesh_utils.cxx.
  • Loading branch information
ktbolt authored Mar 12, 2024
1 parent decc181 commit b2bfa30
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Code/Source/PythonAPI/MeshingMesher_PyClass.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <functional>

#include "sv_TetGenMeshObject.h"
#include "vtkPolyDataNormals.h"

extern cvSolidModel * GetModelFromPyObj(PyObject* obj);

Expand Down Expand Up @@ -238,6 +239,7 @@ Mesher_get_face_polydata(PyMeshingMesher* self, PyObject* args, PyObject* kwargs

vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata = cvPolydata->GetVtkPolyData();

return PyUtilGetVtkObject(api, polydata);
}

Expand Down Expand Up @@ -535,8 +537,9 @@ Mesher_get_surface(PyMeshingMesher* self, PyObject* args)
return nullptr;
}

vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
auto polydata = vtkSmartPointer<vtkPolyData>::New();
polydata = cvPolydata->GetVtkPolyData();

return PyUtilGetVtkObject(api, polydata);
}

Expand Down
2 changes: 1 addition & 1 deletion Code/Source/PythonAPI/MeshingTetGenOptions_PyClass.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ PyTetGenOptionsCreateFromList(cvMeshObject* mesher, std::vector<std::string>& op
try {
SetValueMap[name](options, tokens, faceMap);
} catch (const std::bad_function_call& except) {
std::cout << "[PyTetGenOptionsCreateFromList] Unknown name: " << name << std::endl;
std::cout << "[SV.PythonAPI] An unknown meshing option '" << name << "' was found in the MESH.msh file." << std::endl;
}

// Save commands not processed in cvTetGenMeshObject::SetMeshOptions().
Expand Down
41 changes: 41 additions & 0 deletions Code/Source/sv/Mesh/TetGenMeshObject/sv_tetgenmesh_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -661,26 +661,39 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
vtkSmartPointer<vtkIntArray> lessNodeIds = vtkSmartPointer<vtkIntArray>::New();
vtkSmartPointer<vtkIntArray> lessElementIds = vtkSmartPointer<vtkIntArray>::New();
vtkSmartPointer<vtkIntArray> globalElement2Ids = vtkSmartPointer<vtkIntArray>::New();
vtkSmartPointer<vtkIntArray> modelFaceIds = vtkSmartPointer<vtkIntArray>::New();
vtkSmartPointer<vtkIntArray> modelFaceRegionIds = vtkSmartPointer<vtkIntArray>::New();
vtkSmartPointer<vtkIntArray> modelRegionIds = vtkSmartPointer<vtkIntArray>::New();

if (VtkUtils_PDCheckArrayName(mesh,0,"GlobalNodeID") != SV_OK)
{
fprintf(stderr,"Array name 'GlobalNodeID' does not exist.");
fprintf(stderr," IDs on mesh may not have been assigned properly\n");
return SV_ERROR;
}

if (VtkUtils_PDCheckArrayName(mesh,1,"GlobalElementID") != SV_OK)
{
fprintf(stderr,"Array name 'GlobalElementID' does not exist.");
fprintf(stderr," IDs on mesh may not have been assigned properly\n");
return SV_ERROR;
}

if (VtkUtils_PDCheckArrayName(mesh,1,"ModelFaceID") != SV_OK)
{
fprintf(stderr,"Array name 'ModelFaceID' does not exist. Regions must be identified");
fprintf(stderr," and named 'ModelFaceID' prior to this function call\n");
return SV_ERROR;
}

bool has_ModelRegionIDs = false;

if (VtkUtils_PDCheckArrayName(mesh,1,"ModelRegionID") == SV_OK)
{
has_ModelRegionIDs = true;
modelRegionIds = vtkIntArray::SafeDownCast(mesh->GetCellData()->GetScalars("ModelRegionID"));
}

globalNodeIds = vtkIntArray::SafeDownCast(mesh->GetPointData()->GetScalars("GlobalNodeID"));
globalElementIds = vtkIntArray::SafeDownCast(mesh->GetCellData()->GetScalars("GlobalElementID"));
boundaryScalars = vtkIntArray::SafeDownCast(mesh->GetCellData()->GetScalars("ModelFaceID"));
Expand Down Expand Up @@ -747,6 +760,10 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
selectFaces->InsertNextCell(facePointIds);
globalElement2Ids->InsertNextValue(globalElement2);
lessElementIds->InsertNextValue(globalElementIds->GetValue(cellId));
modelFaceIds->InsertNextValue(id);
if (has_ModelRegionIDs) {
modelFaceRegionIds->InsertNextValue(modelRegionIds->GetValue(cellId));
}
}
}

Expand All @@ -767,6 +784,30 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
tempFace->GetCellData()->AddArray(lessElementIds);
tempFace->GetCellData()->SetActiveScalars("GlobalElementID");

modelFaceIds->SetName("ModelFaceID");
tempFace->GetCellData()->AddArray(modelFaceIds);
tempFace->GetCellData()->SetActiveScalars("ModelFaceID");

if (has_ModelRegionIDs) {
modelFaceRegionIds->SetName("ModelRegionID");
tempFace->GetCellData()->AddArray(modelFaceRegionIds);
tempFace->GetCellData()->SetActiveScalars("ModelRegionID");
}

// Add cell normals.
//
auto normals = vtkSmartPointer<vtkPolyDataNormals>::New();
normals->SplittingOff();
normals->ConsistencyOn();
normals->AutoOrientNormalsOn();
normals->ComputeCellNormalsOn();
normals->ComputePointNormalsOff();
normals->SetInputData(tempFace);
normals->Update();

tempFace->DeepCopy(normals->GetOutput());
tempFace->GetCellData()->GetNormals()->SetName("Normals");

delete [] pointOnFace;
delete [] pointMapping;
delete [] cellOnFace;
Expand Down

0 comments on commit b2bfa30

Please sign in to comment.