Skip to content

Commit

Permalink
Replace vtkTheshold with VtkUtils_ThresholdSurface() VtkUtils_Thresho…
Browse files Browse the repository at this point in the history
…ldUgrid() functions.
  • Loading branch information
ktbolt committed May 21, 2024
1 parent 14a3611 commit 9f508bc
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 80 deletions.
22 changes: 15 additions & 7 deletions Code/Source/sv/Geometry/sv_sys_geom.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4126,32 +4126,40 @@ int sys_geom_set_ids_for_caps( cvPolyData *pd,cvPolyData **outpd,int **doublecap
for (int i = 0; i < facemax; i++)
{
double facecaprange[2];
vtkNew(vtkThreshold,threshold1);
auto threshold_surface = VtkUtils_ThresholdSurface(i+1.0, i+1.0, "ModelFaceID", geom);
/* dp
vtkNew(vtkThreshold, threshold1);
threshold1->SetInputData(geom);
threshold1->SetInputArrayToProcess(0,0,0,1,"ModelFaceID");
//dp threshold1->ThresholdBetween(i+1,i+1);
threshold1->ThresholdBetween(i+1,i+1);
threshold1->Update();
vtkNew(vtkDataSetSurfaceFilter,surfacer);
surfacer->SetInputData(threshold1->GetOutput());
surfacer->Update();
*/

vtkNew(vtkIntArray,modelfacecaps);
vtkNew(vtkIntArray, modelfacecaps);

if (VtkUtils_PDCheckArrayName(surfacer->GetOutput(),1,"CapID") != SV_OK)
if (VtkUtils_PDCheckArrayName(threshold_surface, 1, "CapID") != SV_OK)
//dp if (VtkUtils_PDCheckArrayName(surfacer->GetOutput(),1,"CapID") != SV_OK)
{
fprintf(stderr,"Second\n");
fprintf(stderr,"CapID Array is not on the surface\n");
delete [] capone;
delete [] captwo;
return SV_ERROR;
}
modelfacecaps = vtkIntArray::SafeDownCast(surfacer->GetOutput()->
GetCellData()->GetArray("CapID"));

modelfacecaps = vtkIntArray::SafeDownCast(threshold_surface->GetCellData()->GetArray("CapID"));
//dp modelfacecaps = vtkIntArray::SafeDownCast(surfacer->GetOutput()->GetCellData()->GetArray("CapID"));

capone[i] = 0;
captwo[i] = 0;
(*doublecaps)[i] = 0;
for (int j = 0; j < surfacer->GetOutput()->GetNumberOfCells();j++)

for (int j = 0; j < threshold_surface->GetNumberOfCells();j++)
//dp for (int j = 0; j < surfacer->GetOutput()->GetNumberOfCells();j++)
{
if (modelfacecaps->GetValue(j) == 1)
capone[i] = 1;
Expand Down
22 changes: 16 additions & 6 deletions Code/Source/sv/Mesh/VMTKUtils/sv_vmtk_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/

#include "sv_vmtk_utils.h"
#include "sv_vtk_utils.h"

#include "SimVascular.h"
#include "sv_tetgenmesh_utils.h"
Expand Down Expand Up @@ -1612,38 +1613,47 @@ int VMTKUtils_CreateBoundaryLayerSurfaceAndCaps(vtkUnstructuredGrid* boundaryMes

// Create boundary layer surface mesh from cells with 'isSurface' array value 1.
//
/* dp
auto thresholder = vtkSmartPointer<vtkThreshold>::New();
thresholder->SetInputData(boundaryMesh);
thresholder->SetInputArrayToProcess(0, 0, 0, 1, "isSurface");
//dp thresholder->ThresholdBetween(1, 1);
thresholder->ThresholdBetween(1, 1);
thresholder->Update();
auto surfacer = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
surfacer->SetInputData(thresholder->GetOutput());
surfacer->Update();
boundaryMeshSurface->DeepCopy(surfacer->GetOutput());
*/
auto threshold_surface = VtkUtils_ThresholdSurface(1.0, 1.0, "isSurface", boundaryMesh);
boundaryMeshSurface->DeepCopy(threshold_surface);

// Create boundary layer volume mesh from cells with 'isSurface' array value 0.
//
/* dp
thresholder->SetInputData(boundaryMesh);
thresholder->SetInputArrayToProcess(0, 0, 0, 1, "isSurface");
//dp thresholder->ThresholdBetween(0, 0);
thresholder->ThresholdBetween(0, 0);
thresholder->Update();

boundaryMeshVolume->DeepCopy(thresholder->GetOutput());
*/
auto threshold_volume = VtkUtils_ThresholdUgrid(0.0, 0.0, "isSurface", boundaryMesh);
boundaryMeshVolume->DeepCopy(threshold_volume);

// Create boundary layer mesh caps from cells with 'WallID' array value 0.
//
/* dp
thresholder->SetInputData(surfaceWithSize);
thresholder->SetInputArrayToProcess(0,0,0,1,"WallID");
//dp thresholder->ThresholdBetween(0,0);
dp thresholder->ThresholdBetween(0,0);
thresholder->Update();

surfacer->SetInputData(thresholder->GetOutput());
surfacer->Update();

surfaceMeshCaps->DeepCopy(surfacer->GetOutput());
*/
auto threshold_caps = VtkUtils_ThresholdSurface(0.0, 0.0, "WallID", surfaceWithSize);
surfaceMeshCaps->DeepCopy(threshold_caps);

// Set the values of the 'ModelFaceID' array for the caps to 9999(?).
//
Expand Down
27 changes: 15 additions & 12 deletions Code/Source/sv/Model/OCCTSolidModel/sv_OCCTSolidModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1707,33 +1707,36 @@ int cvOCCTSolidModel::GetOnlyPD(vtkPolyData *pd,double &max_dist) const
cleaner->SetInputData(pd);
cleaner->PointMergingOn();
cleaner->Update();

auto threshold_surface = VtkUtils_ThresholdSurface(7.0, 7.0, "MESH_TYPES", cleaner->GetOutput());

#ifdef dp_old
vtkSmartPointer<vtkThreshold> thresholder =
vtkSmartPointer<vtkThreshold>::New();
thresholder->SetInputData(cleaner->GetOutput());

//Set Input Array to 0 port,0 connection,1 for Cell Data, and MESh_TYPES is the type name
thresholder->SetInputArrayToProcess(0,0,0,1,"MESH_TYPES");
//Source polydata is on MESH_TYPE 7
//dp thresholder->ThresholdBetween(7,7);
thresholder->SetInputArrayToProcess(0,0,0,1,"MESH_TYPES");
thresholder->ThresholdBetween(7,7);
thresholder->Update();
//Extract surface
vtkSmartPointer<vtkDataSetSurfaceFilter> surfacer =
vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
surfacer->SetInputData(thresholder->GetOutput());
surfacer->Update();
//For polydata of just edges, MESH_TYPE is not 7
//Only want if not edges
//fprintf(stderr,"Num Points bef! %d\n",surfacer->GetOutput()->GetNumberOfPoints());
// vtkSmartPointer<vtkQuadricDecimation> decimator =
// vtkSmartPointer<vtkQuadricDecimation>::New();
// decimator->SetInputData(surfacer->GetOutput());
// decimator->SetTargetReduction(0.2);
// decimator->GetOutput();
// pd->DeepCopy(decimator->GetOutput());
#endif

if (threshold_surface->GetNumberOfPoints() != 0)
{
pd->DeepCopy(threshold_surface);
}
/* dp
if (surfacer->GetOutput()->GetNumberOfPoints() != 0)
{
pd->DeepCopy(surfacer->GetOutput());
}
//fprintf(stderr,"Num Points now! %d\n",pd->GetNumberOfPoints());
*/
}

return SV_OK;
Expand Down
46 changes: 45 additions & 1 deletion Code/Source/sv/Utils/sv_vtk_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
#include "sv_misc_utils.h"
#include "sv_cgeom.h"

#include <vtkDataSetSurfaceFilter.h>
#include <vtkSmartPointer.h>
#include <vtkThreshold.h>
#include <vtkUnstructuredGrid.h>

#define START -1
#define INTERMED 0
#define DEADEND 1
#define CLOSED 2


typedef struct {
double x, y, z;
int postId;
Expand Down Expand Up @@ -78,6 +81,47 @@ static int GetStartPt( int *state, int stateSz );
static int UpdateCells( int *cells, int numCells,
vtkIdType **newCells, int *numNewCells );

//-------------------------
// VtkUtils_ThresholdUgrid
//-------------------------
// Create a vtkUnstructuredGrid object from a threshold of a cellular
// data array contained in a vtkDataObject object.
//
vtkSmartPointer<vtkUnstructuredGrid>
VtkUtils_ThresholdUgrid(const double lower, const double upper, const std::string& data_name,
vtkDataObject* vtk_data)
{
int idx = 0;
int port = 0;
int connection = 0;
auto fieldAssociation = vtkDataObject::FieldAssociations::FIELD_ASSOCIATION_CELLS;

auto threshold = vtkSmartPointer<vtkThreshold>::New();
threshold->SetLowerThreshold(lower);
threshold->SetUpperThreshold(upper);
threshold->SetInputData(vtk_data);
threshold->SetInputArrayToProcess(idx, port, connection, fieldAssociation, data_name.c_str());
threshold->Update();
return threshold->GetOutput();
}

//---------------------------
// VtkUtils_ThresholdSurface
//---------------------------
// Create a vtkPolyData object from a threshold of a cellular
// data array contained in a vtkDataObject object.
//
vtkSmartPointer<vtkPolyData>
VtkUtils_ThresholdSurface(const double lower, const double upper, const std::string& data_name,
vtkDataObject* vtk_data)
{
auto threshold_ugrid = VtkUtils_ThresholdUgrid(lower, upper, data_name, vtk_data);

auto surfacer = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
surfacer->SetInputData(vtk_data);
surfacer->Update();
return surfacer->GetOutput();
}

// -----------------------
// VtkUtils_NewVtkPolyData
Expand Down
8 changes: 8 additions & 0 deletions Code/Source/sv/Utils/sv_vtk_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ int SV_EXPORT_UTILS VtkUtils_NewVtkPolyDataLines( vtkPolyData **pd, int numPts,
// same (potentially redundant) point set, and just change the id's
// that get used by Lines and Polys.

vtkSmartPointer<vtkUnstructuredGrid>
VtkUtils_ThresholdUgrid(const double lower, const double upper, const std::string& data_name,
vtkDataObject* vtk_data);

vtkSmartPointer<vtkPolyData>
VtkUtils_ThresholdSurface(const double lower, const double upper, const std::string& data_name,
vtkDataObject* vtk_data);

int SV_EXPORT_UTILS VtkUtils_FixTopology( vtkPolyData *pd, double tol );

int SV_EXPORT_UTILS VtkUtils_GetPoints( vtkPolyData *pd, double **pts, int *numPts );
Expand Down
2 changes: 2 additions & 0 deletions Code/Source/sv2/ImageProcessing/sv2_img_threshold.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "sv_VTK.h"
#include "vtkThresholdPoints.h"

// [TODO:DaveP] This does not seem to be used anywhere.
//
int img_threshold (vtkStructuredPoints *image, vtkFloatingPointType thrMin, vtkFloatingPointType thrMax,
int max_num_pts, cvPolyData **result) {

Expand Down
18 changes: 13 additions & 5 deletions Code/Source/sv3/Path/sv3_PathUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "SimVascular.h"
#include "sv3_PathUtils.h"
#include "sv_vtk_utils.h"

#include <vtkCellData.h>
#include <vtkDataSetSurfaceFilter.h>
Expand Down Expand Up @@ -72,33 +73,40 @@ PathUtils::ExtractCenterlinesSections(vtkSmartPointer<vtkPolyData>& centerlines)
// Extract sections based on cells with group IDs for each centerline ID.
//
for (int cid = minId; cid <= maxId; cid++) {
auto centerlinesCidThreshold = VtkUtils_ThresholdSurface(cid, cid, CenterlineIdsArrayName, centerlines);
/*dp
auto threshold = vtkSmartPointer<vtkThreshold>::New();
threshold->SetInputData(centerlines);
threshold->SetInputArrayToProcess(0, 0, 0, "vtkDataObject::FIELD_ASSOCIATION_CELLS", CenterlineIdsArrayName.c_str());
//dp threshold->ThresholdBetween(cid, cid);
threshold->ThresholdBetween(cid, cid);
threshold->Update();

auto threshold_mesh = VtkUtils_ThresholdPolyData(CenterlineIdsArrayName, centerlines);
auto surfacer = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
surfacer->SetInputData(threshold->GetOutput());
surfacer->SetInputData(threshold_mesh);
surfacer->Update();
auto centerlinesCidThreshold = surfacer->GetOutput();
*/

auto groupData = centerlinesCidThreshold->GetCellData()->GetArray(GroupIdsArrayName.c_str());
double lowerValue = groupData->GetRange()[0];
double upperValue = groupData->GetRange()[1];

auto group_threshold = VtkUtils_ThresholdSurface(lowerValue, upperValue, GroupIdsArrayName, centerlinesCidThreshold);
/* dp
auto groupThreshold = vtkSmartPointer<vtkThreshold>::New();
groupThreshold->SetInputData(centerlinesCidThreshold);
groupThreshold->SetInputArrayToProcess(0, 0, 0, "vtkDataObject::FIELD_ASSOCIATION_CELLS", GroupIdsArrayName.c_str());
//dp groupThreshold->ThresholdBetween(lowerValue, upperValue);
groupThreshold->ThresholdBetween(lowerValue, upperValue);
groupThreshold->Update();
auto groupSurfacer = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
groupSurfacer->SetInputData(groupThreshold->GetOutput());
groupSurfacer->Update();
*/

auto groupCenterlines = vtkSmartPointer<vtkPolyData>::New();
groupCenterlines->DeepCopy(groupSurfacer->GetOutput());
groupCenterlines->DeepCopy(group_threshold);
//dp groupCenterlines->DeepCopy(groupSurfacer->GetOutput());
pathsGeometry.push_back(groupCenterlines);
}

Expand Down
26 changes: 22 additions & 4 deletions Code/Source/sv4gui/Modules/Mesh/Common/sv4gui_MeshLegacyIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "sv4gui_MitkMeshIO.h"

#include "sv_polydatasolid_utils.h"
#include "sv_vtk_utils.h"

#include <QDir>

Expand Down Expand Up @@ -185,10 +186,15 @@ bool sv4guiMeshLegacyIO::WriteFiles(mitk::DataNode::Pointer meshNode, sv4guiMode

// Extract surface mesh.
//
auto threshold_surface = VtkUtils_ThresholdSurface(i, i, "ModelRegionID", surfaceMesh);
if (threshold_surface->GetNumberOfCells() == 0) {
continue;
}
/* dp
auto surfThresholder = vtkSmartPointer<vtkThreshold>::New();
surfThresholder->SetInputData(surfaceMesh);
surfThresholder->SetInputArrayToProcess(0,0,0,1,"ModelRegionID");
//dp surfThresholder->ThresholdBetween(i,i);
surfThresholder->ThresholdBetween(i,i);
surfThresholder->Update();
if (surfThresholder->GetOutput()->GetNumberOfCells() == 0) {
continue;
Expand All @@ -200,23 +206,30 @@ bool sv4guiMeshLegacyIO::WriteFiles(mitk::DataNode::Pointer meshNode, sv4guiMode
if (surfacer->GetOutput()->GetNumberOfCells() == 0) {
continue;
}
*/

// Extract volume mesh.
auto threshold_volume = VtkUtils_ThresholdUgrid(i, i, "ModelRegionID", volumeMesh);
if (threshold_volume->GetNumberOfCells() == 0) {
continue;
}
/* dp
auto volumeThresholder = vtkSmartPointer<vtkThreshold>::New();
volumeThresholder->SetInputData(volumeMesh);
volumeThresholder->SetInputArrayToProcess(0,0,0,1,"ModelRegionID");
//dp volumeThresholder->ThresholdBetween(i,i);
volumeThresholder->ThresholdBetween(i,i);
volumeThresholder->Update();
if (volumeThresholder->GetOutput()->GetNumberOfCells() == 0) {
continue;
}
*/

// Write meshes.
//
fprintf(stdout, "[sv4guiMeshLegacyIO::WriteFiles] Writing domain %d\n", i);
QString newDir = meshDir+"_domain-" + QString::number(i);
QDir().mkpath(newDir);
if (WriteFiles(surfacer->GetOutput(), volumeThresholder->GetOutput(), modelElement, newDir) == false) {
if (WriteFiles(threshold_surface, threshold_volume, modelElement, newDir) == false) {
return false;
}
}
Expand Down Expand Up @@ -322,10 +335,14 @@ bool sv4guiMeshLegacyIO::WriteFiles(vtkSmartPointer<vtkPolyData> surfaceMesh, vt
if (connectFilter->GetNumberOfExtractedRegions() > 1) {

for (int j = 0; j < connectFilter->GetNumberOfExtractedRegions(); j++) {
auto region_surface = VtkUtils_ThresholdSurface(j, j, "RegionId", connectFilter->GetOutput());
region_surface->GetCellData()->RemoveArray("RegionId");
region_surface->GetPointData()->RemoveArray("RegionId");
/* dp
auto thresholder = vtkSmartPointer<vtkThreshold>::New();
thresholder->SetInputData(connectFilter->GetOutput());
thresholder->SetInputArrayToProcess(0,0,0,1,"RegionId");
//dp thresholder->ThresholdBetween(j, j);
thresholder->ThresholdBetween(j, j);
thresholder->Update();
auto surfacer = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
Expand All @@ -334,6 +351,7 @@ bool sv4guiMeshLegacyIO::WriteFiles(vtkSmartPointer<vtkPolyData> surfaceMesh, vt
surfacer->GetOutput()->GetCellData()->RemoveArray("RegionId");
surfacer->GetOutput()->GetPointData()->RemoveArray("RegionId");
auto region_surface = surfacer->GetOutput();
*/

vtpFilePath = meshDir + "/walls_combined_connected_region_" + QString::number(j) + ".vtp";
vtpFilePath = QDir::toNativeSeparators(vtpFilePath);
Expand Down
Loading

0 comments on commit 9f508bc

Please sign in to comment.