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

Extract boundary edges as poly lines. More...

#include <vtkvmtkPolyDataBoundaryExtractor.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataBoundaryExtractor * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkPolyDataBoundaryExtractor * SafeDownCast (vtkObjectBase *o)
static vtkvmtkPolyDataBoundaryExtractor * New ()

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataBoundaryExtractor ()
 ~vtkvmtkPolyDataBoundaryExtractor ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override

Detailed Description

Extract boundary edges as poly lines.

This class identifies boundary edges and organizes them into poly lines based on connectivity. It also provides the output with a point data vtkIntArray (set as active scalars) in which the ids of boundary points in the input dataset are stored.

Each poly line lists every point of its boundary once and does not repeat the first point at the end: a boundary is a ring, and the caller closes it, stepping round with (j+1) modulo the number of points of the cell, which is what every caller in vmtk does.

See also
vtkvmtkBoundaryLabels, vtkvmtkPolyDataBoundaryLabeler, vtkvmtkBoundaryReferenceSystems

Definition at line 39 of file vtkvmtkPolyDataBoundaryExtractor.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkPolyDataBoundaryExtractor::Superclass

Definition at line 42 of file vtkvmtkPolyDataBoundaryExtractor.h.

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataBoundaryExtractor()

vtkvmtkPolyDataBoundaryExtractor::vtkvmtkPolyDataBoundaryExtractor ( )
protected

Definition at line 37 of file vtkvmtkPolyDataBoundaryExtractor.cxx.

38{
39}

◆ ~vtkvmtkPolyDataBoundaryExtractor()

vtkvmtkPolyDataBoundaryExtractor::~vtkvmtkPolyDataBoundaryExtractor ( )
inlineprotected

Definition at line 49 of file vtkvmtkPolyDataBoundaryExtractor.h.

49{};

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataBoundaryExtractor::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataBoundaryExtractor * vtkvmtkPolyDataBoundaryExtractor::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkPolyDataBoundaryExtractor::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 238 of file vtkvmtkPolyDataBoundaryExtractor.cxx.

239{
240 this->Superclass::PrintSelf(os,indent);
241}

◆ New()

vtkvmtkPolyDataBoundaryExtractor * vtkvmtkPolyDataBoundaryExtractor::New ( )
static

◆ RequestData()

int vtkvmtkPolyDataBoundaryExtractor::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotectedvirtual

Definition at line 41 of file vtkvmtkPolyDataBoundaryExtractor.cxx.

45{
46 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
47 vtkInformation *outInfo = outputVector->GetInformationObject(0);
48
49 vtkPolyData *input = vtkPolyData::SafeDownCast(
50 inInfo->Get(vtkDataObject::DATA_OBJECT()));
51 vtkPolyData *output = vtkPolyData::SafeDownCast(
52 outInfo->Get(vtkDataObject::DATA_OBJECT()));
53
54 vtkIdList *boundary, *boundaryIds, *cellEdgeNeighbors, *newCell;
55 vtkIdType i, j, currentId, id, id0, id1;
56 vtkCell* cell;
57 bool foundAny, foundNeighbor, done;
58 vtkPoints* newPoints;
59 vtkCellArray* newLines;
60 vtkIdTypeArray* newScalars;
61
62 // The topology queries below need cell links, but they must not be built on the input: a
63 // filter does not own its input, and since VTK 9.4 the links hold a reference back to the
64 // dataset they were built for. That reference cycle is normally reclaimed by VTK's garbage
65 // collector, but when it is created while another filter's Update() is executing - this
66 // extractor runs inside vtkvmtkPolyDataSurfaceRemeshing, among others - the collector never
67 // reclaims it, and the caller's surface is leaked together with the links, its cell map and
68 // its cell instances. The links are built instead on a shallow structural copy, which shares
69 // the points and cell arrays (so every point and cell id below means the same thing) but
70 // keeps the acceleration structures, and their reference cycle, to itself.
71 vtkPolyData* working = vtkPolyData::New();
72 working->CopyStructure(input);
73 working->BuildCells();
74 working->BuildLinks();
75
76 // Allocate
77 boundary = vtkIdList::New();
78 boundaryIds = vtkIdList::New();
79 cellEdgeNeighbors = vtkIdList::New();
80 newCell = vtkIdList::New();
81 newPoints = vtkPoints::New();
82 newLines = vtkCellArray::New();
83 newScalars = vtkIdTypeArray::New();
84
85 // Execute
86 for (i=0; i<working->GetNumberOfCells(); i++)
87 {
88 cell = working->GetCell(i);
89 for (j=0; j<3; j++)
90 {
91 cellEdgeNeighbors->Initialize();
92 auto edge = cell->GetEdge(j);
93 if (!edge) continue;
94 auto pointIds = edge->GetPointIds();
95 id0 = pointIds->GetId(0);
96 id1 = pointIds->GetId(1);
97 working->GetCellEdgeNeighbors(i,id0,id1,cellEdgeNeighbors);
98 if (cellEdgeNeighbors->GetNumberOfIds()==0)
99 {
100 boundaryIds->InsertUniqueId(id0);
101 boundaryIds->InsertUniqueId(id1);
102 }
103 }
104 }
105
106 if (boundaryIds->GetNumberOfIds() == 0)
107 {
108 output->SetPoints(newPoints);
109 output->SetLines(newLines);
110 output->GetPointData()->SetScalars(newScalars);
111
112 newPoints->Delete();
113 newLines->Delete();
114 newScalars->Delete();
115
116 boundary->Delete();
117 boundaryIds->Delete();
118 cellEdgeNeighbors->Delete();
119 newCell->Delete();
120
121 // Dropping the links first breaks their reference cycle with the working copy by plain
122 // reference counting, so its destruction cannot depend on the garbage collector either.
123 working->Initialize();
124 working->Delete();
125
126 return 1;
127 }
128
129 foundAny = false;
130 foundNeighbor = false;
131 done = false;
132 currentId = -1;
133 int loopCount = 0;
134 bool isBoundaryEdge;
135
136 while (!done)
137 {
138 foundAny = false;
139 foundNeighbor = false;
140
141 for (i=0; i<boundaryIds->GetNumberOfIds(); i++)
142 {
143 id = boundaryIds->GetId(i);
144 if (id!=-1)
145 {
146 foundAny = true;
147 isBoundaryEdge = false;
148 if (currentId!=-1 && working->IsEdge(currentId,id))
149 {
150 cellEdgeNeighbors->Initialize();
151 working->GetCellEdgeNeighbors(-1,currentId,id,cellEdgeNeighbors);
152 if (cellEdgeNeighbors->GetNumberOfIds() == 1)
153 {
154 isBoundaryEdge = true;
155 }
156 }
157 if ((currentId==-1) || isBoundaryEdge)
158 {
159 foundNeighbor = true;
160 }
161
162 if (foundNeighbor)
163 {
164 currentId = id;
165 boundary->InsertNextId(currentId);
166 boundaryIds->SetId(i,-1);
167 break;
168 }
169 }
170 }
171
172 if ( (((!foundNeighbor)&&(foundAny))||(!foundAny)) && (boundary->GetNumberOfIds() > 2))
173 {
174 // Each point of the boundary is listed once. The polyline is a ring, and the caller closes
175 // it, which is what every caller in vmtk does: it takes the number of points of the cell
176 // and steps round with (j+1) modulo that. Repeating the first point at the end to mark the
177 // ring as closed would put a duplicate in the middle of that arithmetic, which biases the
178 // barycenter, the mean radius and the normal computed from these points, and leaves a
179 // degenerate triangle in the fan of a cap and in the first layer of a flow extension.
180 newCell->Initialize();
181 newCell->SetNumberOfIds(boundary->GetNumberOfIds());
182 for (j=0; j<boundary->GetNumberOfIds(); j++)
183 {
184 id = boundary->GetId(j);
185 newCell->SetId(j,newPoints->InsertNextPoint(working->GetPoint(id)));
186 newScalars->InsertNextValue(id);
187 }
188
189 newLines->InsertNextCell(newCell);
190
191 currentId = -1;
192 boundary->Initialize();
193 }
194
195 if (!foundAny)
196 {
197 done = true;
198 }
199
200 loopCount++;
201 if (loopCount > 2*boundaryIds->GetNumberOfIds())
202 {
203 int missing = 0;
204 for (int n=0; n<boundaryIds->GetNumberOfIds(); n++)
205 {
206 if (boundaryIds->GetId(n) != -1)
207 {
208 missing++;
209 }
210 }
211 vtkErrorMacro(<<"Can't find adjacent point. Bailing out.");
212 done = true;
213 }
214 }
215
216 output->SetPoints(newPoints);
217 output->SetLines(newLines);
218 output->GetPointData()->SetScalars(newScalars);
219
220 // Destroy
221 newPoints->Delete();
222 newLines->Delete();
223 newScalars->Delete();
224
225 boundary->Delete();
226 boundaryIds->Delete();
227 cellEdgeNeighbors->Delete();
228 newCell->Delete();
229
230 // Dropping the links first breaks their reference cycle with the working copy by plain
231 // reference counting, so its destruction cannot depend on the garbage collector either.
232 working->Initialize();
233 working->Delete();
234
235 return 1;
236}

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