Skip to content

Commit

Permalink
Add functionality to add a ModelFaceID array and Normals to a mesh face.
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbolt committed Mar 8, 2024
1 parent decc181 commit 499bea7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
41 changes: 40 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,43 @@ 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 Expand Up @@ -535,8 +573,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
6 changes: 6 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,6 +661,7 @@ 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();

if (VtkUtils_PDCheckArrayName(mesh,0,"GlobalNodeID") != SV_OK)
{
Expand Down Expand Up @@ -747,6 +748,7 @@ int TGenUtils_GetFacePolyData(int id,vtkPolyData *mesh, vtkPolyData *face)
selectFaces->InsertNextCell(facePointIds);
globalElement2Ids->InsertNextValue(globalElement2);
lessElementIds->InsertNextValue(globalElementIds->GetValue(cellId));
modelFaceIds->InsertNextValue(id);
}
}

Expand All @@ -767,6 +769,10 @@ 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");

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

0 comments on commit 499bea7

Please sign in to comment.