Skip to content

Commit

Permalink
Add creating a ModelRegionID array and move adding Normal data into s…
Browse files Browse the repository at this point in the history
…v_tetgenmesh_utils.cxx.
  • Loading branch information
ktbolt committed Mar 12, 2024
1 parent 499bea7 commit 6f9f475
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
36 changes: 0 additions & 36 deletions Code/Source/PythonAPI/MeshingMesher_PyClass.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -240,42 +240,6 @@ Mesher_get_face_polydata(PyMeshingMesher* self, PyObject* args, PyObject* kwargs
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata = cvPolydata->GetVtkPolyData();

// Add a Normals point or cell array.
//
bool have_cell_normals = true;
#define compute_cell_normals
#ifdef compute_cell_normals
auto normals = vtkSmartPointer<vtkPolyDataNormals>::New();
normals->SplittingOff();
normals->ConsistencyOn();
normals->AutoOrientNormalsOn();
normals->ComputeCellNormalsOn();
normals->ComputePointNormalsOff();
normals->SetInputData(polydata);
normals->Update();
have_cell_normals = true;

#else
auto normals = vtkSmartPointer<vtkPolyDataNormals>::New();
normals->SetInputData(polydata);
normals->ConsistencyOn();
normals->AutoOrientNormalsOn();
normals->FlipNormalsOff();
normals->ComputePointNormalsOn();
normals->ComputeCellNormalsOff();
normals->SplittingOn();
normals->Update();
have_cell_normals = false;
#endif

polydata->DeepCopy(normals->GetOutput());

if (have_cell_normals) {
polydata->GetCellData()->GetNormals()->SetName("Normals");
} else {
polydata->GetPointData()->GetNormals()->SetName("Normals");
}

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
35 changes: 35 additions & 0 deletions Code/Source/sv/Mesh/TetGenMeshObject/sv_tetgenmesh_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -662,26 +662,38 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
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 @@ -749,6 +761,9 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
globalElement2Ids->InsertNextValue(globalElement2);
lessElementIds->InsertNextValue(globalElementIds->GetValue(cellId));
modelFaceIds->InsertNextValue(id);
if (has_ModelRegionIDs) {
modelFaceRegionIds->InsertNextValue(modelRegionIds->GetValue(cellId));
}
}
}

Expand All @@ -773,6 +788,26 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
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 6f9f475

Please sign in to comment.