VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataBranchUtilities Class Reference

Utility functions to ease working with branches and surfaces. More...

#include <vtkvmtkPolyDataBranchUtilities.h>

Inheritance diagram for vtkvmtkPolyDataBranchUtilities:
[legend]
Collaboration diagram for vtkvmtkPolyDataBranchUtilities:
[legend]

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataBranchUtilities * NewInstance () const

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkPolyDataBranchUtilities * SafeDownCast (vtkObjectBase *o)
static vtkvmtkPolyDataBranchUtilities * New ()
static void GetGroupsIdList (vtkPolyData *surface, const char *groupIdsArrayName, vtkIdList *groupIds)
static void ExtractGroup (vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataBranchUtilities ()
 ~vtkvmtkPolyDataBranchUtilities ()

Detailed Description

Utility functions to ease working with branches and surfaces.

  • ExtractGroup: Extract a single surface branch group from a surface which has already been grouped.
  • GetGroupIdsList: get the group ids which are contained within a grouped surface as a vtkIdList.

Definition at line 36 of file vtkvmtkPolyDataBranchUtilities.h.

Member Typedef Documentation

◆ Superclass

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataBranchUtilities()

vtkvmtkPolyDataBranchUtilities::vtkvmtkPolyDataBranchUtilities ( )
inlineprotected

Definition at line 56 of file vtkvmtkPolyDataBranchUtilities.h.

56{};

◆ ~vtkvmtkPolyDataBranchUtilities()

vtkvmtkPolyDataBranchUtilities::~vtkvmtkPolyDataBranchUtilities ( )
inlineprotected

Definition at line 57 of file vtkvmtkPolyDataBranchUtilities.h.

57{};

Member Function Documentation

◆ IsTypeOf()

int vtkvmtkPolyDataBranchUtilities::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkPolyDataBranchUtilities::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkPolyDataBranchUtilities * vtkvmtkPolyDataBranchUtilities::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataBranchUtilities::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataBranchUtilities * vtkvmtkPolyDataBranchUtilities::NewInstance ( ) const

◆ New()

vtkvmtkPolyDataBranchUtilities * vtkvmtkPolyDataBranchUtilities::New ( )
static

◆ GetGroupsIdList()

void vtkvmtkPolyDataBranchUtilities::GetGroupsIdList ( vtkPolyData * surface,
const char * groupIdsArrayName,
vtkIdList * groupIds )
static

Fill groupIds with the list of all distinct group ids found in the groupIdsArrayName cell data array of surface.

Definition at line 34 of file vtkvmtkPolyDataBranchUtilities.cxx.

35{
36 vtkDataArray* groupIdsArray = surface->GetPointData()->GetArray(groupIdsArrayName);
37
38 int numberOfPoints = surface->GetNumberOfPoints();
39
40 groupIds->Initialize();
41
42 int maxGroupId = 0;
43 int i;
44 for (i=0; i<numberOfPoints; i++)
45 {
46 vtkIdType groupId = static_cast<int>(groupIdsArray->GetComponent(i,0));
47 if (groupId > maxGroupId)
48 {
49 maxGroupId = groupId;
50 }
51 }
52
53 vtkIdList* isGroupList = vtkIdList::New();
54 isGroupList->SetNumberOfIds(maxGroupId+1);
55
56 for (i=0; i<maxGroupId+1; i++)
57 {
58 isGroupList->SetId(i,0);
59 }
60
61 for (i=0; i<numberOfPoints; i++)
62 {
63 vtkIdType groupId = static_cast<int>(groupIdsArray->GetComponent(i,0));
64 isGroupList->SetId(groupId,1);
65 }
66
67 for (i=0; i<maxGroupId+1; i++)
68 {
69 int isGroup = isGroupList->GetId(i);
70 if (isGroup == 1)
71 {
72 groupIds->InsertNextId(i);
73 }
74 }
75
76 isGroupList->Delete();
77}

◆ ExtractGroup()

void vtkvmtkPolyDataBranchUtilities::ExtractGroup ( vtkPolyData * surface,
const char * groupIdsArrayName,
vtkIdType groupId,
bool cleanGroupSurface,
vtkPolyData * groupSurface )
static

Extract into groupSurface the subset of cells of surface belonging to groupId (as identified by the groupIdsArrayName cell data array). If cleanGroupSurface is true, unused points are removed (vtkCleanPolyData) from the extracted group.

Definition at line 79 of file vtkvmtkPolyDataBranchUtilities.cxx.

80{
81 vtkDataArray* groupIdsArray = surface->GetPointData()->GetArray(groupIdsArrayName);
82
83 surface->BuildCells();
84
85 int numberOfCells = surface->GetPolys()->GetNumberOfCells();
86
87 vtkCellArray* groupPolys = vtkCellArray::New();
88 vtkIdType npts;
89 const vtkIdType *pts;
90 for (int j=0; j<numberOfCells; j++)
91 {
92 surface->GetCellPoints(j,npts,pts);
93 bool insertCell = true;
94 for (int k=0; k<npts; k++)
95 {
96 if (static_cast<int>(groupIdsArray->GetComponent(pts[k],0) != groupId))
97 {
98 insertCell = false;
99 break;
100 }
101 }
102 if (!insertCell)
103 {
104 continue;
105 }
106 groupPolys->InsertNextCell(npts,pts);
107 }
108 groupPolys->Squeeze();
109
110 // Assemble the group surface from scratch instead of deep copying the input
111 // and swapping out its polys. Once the input has its cell map built,
112 // DeepCopy brings a copy of that map along, and mutating the polys array
113 // afterwards leaves the map out of sync with the actual cells - downstream
114 // filters then read cells through the stale map and crash (observed with
115 // VTK >= 9.6 inside vtkCleanPolyData and vtkPolyDataConnectivityFilter).
116 // This also no longer copies the input's cell data, which referred to the
117 // original full set of cells and was meaningless for the extracted subset.
118 groupSurface->Initialize();
119 vtkPoints* groupPoints = vtkPoints::New();
120 groupPoints->DeepCopy(surface->GetPoints());
121 groupSurface->SetPoints(groupPoints);
122 groupPoints->Delete();
123 groupSurface->GetPointData()->DeepCopy(surface->GetPointData());
124 groupSurface->SetPolys(groupPolys);
125 groupPolys->Delete();
126
127 if (cleanGroupSurface)
128 {
129 vtkCleanPolyData* cleaner = vtkCleanPolyData::New();
130 cleaner->SetInputData(groupSurface);
131 cleaner->Update();
132
133 groupSurface->DeepCopy(cleaner->GetOutput());
134
135 cleaner->Delete();
136 }
137}

The documentation for this class was generated from the following files: