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

Not implemented / experimental. Cuts a surface open along a polyline that follows existing mesh edges, duplicating points so the two sides of the cut become topologically disconnected. More...

#include <vtkvmtkPolyDataScissors.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataScissors * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetCutLine (vtkPolyData *)
virtual vtkPolyData * GetCutLine ()
virtual void SetCutLinePointIdsArrayName (const char *)
virtual char * GetCutLinePointIdsArrayName ()

Static Public Member Functions

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

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataScissors ()
 ~vtkvmtkPolyDataScissors ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
int GetCellsOnSameSide (vtkPolyData *input, vtkIdType targetCellId0, vtkIdType targetCellId1, vtkIdType referenceCellId, vtkIdType linePointId0, vtkIdType linePointId1, vtkIdType linePointId2, vtkIdList *cellsOnSameSide)
int IsEdgeInCell (vtkPolyData *input, vtkIdType edgePointId0, vtkIdType edgePointId1, vtkIdType cellId)

Protected Attributes

char * CutLinePointIdsArrayName
vtkPolyData * CutLine

Detailed Description

Not implemented / experimental. Cuts a surface open along a polyline that follows existing mesh edges, duplicating points so the two sides of the cut become topologically disconnected.

For each internal segment of CutLine (a polyline whose points map to input surface points through CutLinePointIdsArrayName), this class attempts to duplicate the corresponding input point and reassign it, on one side of the cut, to the cells lying on that side, so that the surface can be opened up along the line (as with a pair of scissors). This is not part of any released pype script and should be considered experimental/unfinished.

Definition at line 37 of file vtkvmtkPolyDataScissors.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkPolyDataScissors::Superclass

Definition at line 40 of file vtkvmtkPolyDataScissors.h.

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataScissors()

vtkvmtkPolyDataScissors::vtkvmtkPolyDataScissors ( )
protected

Definition at line 35 of file vtkvmtkPolyDataScissors.cxx.

36{
37 this->CutLine = NULL;
38 this->CutLinePointIdsArrayName = NULL;
39}

◆ ~vtkvmtkPolyDataScissors()

vtkvmtkPolyDataScissors::~vtkvmtkPolyDataScissors ( )
protected

Definition at line 41 of file vtkvmtkPolyDataScissors.cxx.

42{
43 if (this->CutLine)
44 {
45 this->CutLine->Delete();
46 this->CutLine = NULL;
47 }
48}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataScissors::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataScissors * vtkvmtkPolyDataScissors::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 398 of file vtkvmtkPolyDataScissors.cxx.

399{
400 this->Superclass::PrintSelf(os,indent);
401}

◆ New()

vtkvmtkPolyDataScissors * vtkvmtkPolyDataScissors::New ( )
static

◆ SetCutLine()

virtual void vtkvmtkPolyDataScissors::SetCutLine ( vtkPolyData * )
virtual

Set/Get the poly data holding the line (polyline cells) along which the input surface should be cut open. Every point of CutLine must lie on an edge of the input mesh and carry, in CutLinePointIdsArrayName, the id of the corresponding input surface point.

◆ GetCutLine()

virtual vtkPolyData * vtkvmtkPolyDataScissors::GetCutLine ( )
virtual

Set/Get the poly data holding the line (polyline cells) along which the input surface should be cut open. Every point of CutLine must lie on an edge of the input mesh and carry, in CutLinePointIdsArrayName, the id of the corresponding input surface point.

◆ SetCutLinePointIdsArrayName()

virtual void vtkvmtkPolyDataScissors::SetCutLinePointIdsArrayName ( const char * )
virtual

Set/Get the name of the point data array on CutLine giving, for each cut line point, the id of the corresponding point on the input surface. Required input.

◆ GetCutLinePointIdsArrayName()

virtual char * vtkvmtkPolyDataScissors::GetCutLinePointIdsArrayName ( )
virtual

Set/Get the name of the point data array on CutLine giving, for each cut line point, the id of the corresponding point on the input surface. Required input.

◆ RequestData()

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

Definition at line 151 of file vtkvmtkPolyDataScissors.cxx.

155{
156 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
157 vtkInformation *outInfo = outputVector->GetInformationObject(0);
158
159 vtkPolyData *input = vtkPolyData::SafeDownCast(
160 inInfo->Get(vtkDataObject::DATA_OBJECT()));
161 vtkPolyData *output = vtkPolyData::SafeDownCast(
162 outInfo->Get(vtkDataObject::DATA_OBJECT()));
163
164 vtkIdType k, i , j;
165 vtkIdType surfacePointId, newPointId;
166 vtkIdType id0, id1, previousId;
167 vtkIdType duplicatePointLocation;
168 vtkIdType numberOfLines, numberOfLinePoints, numberOfInputPoints;
169 vtkIdType cellId, previousCellToEdit;
170 vtkIdType npts;
171 const vtkIdType *pts;
172 vtkDataArray *cutLinePointIdsArray;
173 vtkCell *polyLine;
174 vtkPoints *newPoints;
175 vtkCellArray *newPolys;
176 vtkCellArray *editedCells;
177 vtkIdList *duplicatePointIds;
178 vtkIdList *duplicatedPointIds;
179 vtkIdList *cellsToEdit, *editedCellIds;
180 vtkIdList *cellEdgeNeighbors;
181 vtkIdList *cellsOnSameSide;
182 vtkPointData *inputPD = input->GetPointData();
183 vtkPointData *outputPD = output->GetPointData();
184
185 previousCellToEdit = -1;
186
187 if (this->CutLine==NULL)
188 {
189 vtkErrorMacro(<<"CutLine not specified!");
190 return 1;
191 }
192
193 if (this->CutLinePointIdsArrayName==NULL)
194 {
195 vtkErrorMacro(<<"CutLinePointIdsArrayName not specified!");
196 return 1;
197 }
198
199 cutLinePointIdsArray = this->CutLine->GetPointData()->GetArray(this->CutLinePointIdsArrayName);
200
201 if (cutLinePointIdsArray==NULL)
202 {
203 vtkErrorMacro(<<"CutLinePointIdsArray with name specified does not exist!");
204 return 1;
205 }
206
207 newPoints = vtkPoints::New();
208 newPolys = vtkCellArray::New();
209
210 editedCells = vtkCellArray::New();
211
212 duplicatePointIds = vtkIdList::New();
213 duplicatedPointIds = vtkIdList::New();
214 cellsToEdit = vtkIdList::New();
215 editedCellIds = vtkIdList::New();
216 cellEdgeNeighbors = vtkIdList::New();
217 cellsOnSameSide = vtkIdList::New();
218
219 numberOfInputPoints = input->GetNumberOfPoints();
220 newPoints->DeepCopy(input->GetPoints());
221
222 numberOfLinePoints = this->CutLine->GetNumberOfPoints();
223
224 numberOfLines = this->CutLine->GetNumberOfCells();
225
226 input->BuildCells();
227 input->BuildLinks();
228 this->CutLine->BuildCells();
229
230 for (k=0; k<numberOfLines; k++)
231 {
232 polyLine = this->CutLine->GetCell(k);
233 if (polyLine->GetCellType() != VTK_LINE && polyLine->GetCellType() != VTK_POLY_LINE)
234 {
235 continue;
236 }
237
238 numberOfLinePoints = polyLine->GetNumberOfPoints();
239
240 duplicatedPointIds->Initialize();
241 duplicatePointIds->Initialize();
242 cellsToEdit->Initialize();
243
244 for (i=0; i<numberOfLinePoints; i++)
245 {
246 surfacePointId = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i),0));
247 newPointId = newPoints->InsertNextPoint(input->GetPoint(surfacePointId));
248 duplicatedPointIds->InsertNextId(surfacePointId);
249 duplicatePointIds->InsertNextId(newPointId);
250 }
251
252 for (i=0; i<numberOfLinePoints-1; i++)
253 {
254 id0 = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i),0));
255 id1 = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i+1),0));
256
257 if (id0==id1)
258 {
259 vtkErrorMacro(<<"Coincident points found on CutLine! ");
260 return 1;
261 }
262
263 if (!input->IsEdge(id0,id1))
264 {
265 vtkErrorMacro(<<"CutLine is not entirely defined on mesh edges! ");
266 return 1;
267 }
268
269 cellEdgeNeighbors->Initialize();
270 input->GetCellEdgeNeighbors(-1,id0,id1,cellEdgeNeighbors);
271
272 if (cellEdgeNeighbors->GetNumberOfIds()<2)
273 {
274 vtkWarningMacro(<<"Surface boundary or hole found.");
275 continue;
276 }
277
278 if (cellEdgeNeighbors->GetNumberOfIds()>2)
279 {
280 vtkErrorMacro(<<"Surface is non-manifold! ");
281 return 1;
282 }
283
284 // try to choose the first cell in order to maintain consistency in the orientation, if at all possible
285
286 // this is a bit too naive (it basically doesn't work most of the times). TODO: special treatment of joints + consistency.
287 if (i==0)
288 {
289 if (k==0)
290 {
291 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(0));
292 previousCellToEdit = cellEdgeNeighbors->GetId(0);
293 }
294 else
295 {
296 if (cellsToEdit->IsId(cellEdgeNeighbors->GetId(0))!=-1)
297 {
298 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(0));
299 previousCellToEdit = cellEdgeNeighbors->GetId(0);
300 }
301 else
302 {
303 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(1));
304 previousCellToEdit = cellEdgeNeighbors->GetId(1);
305 }
306 }
307 continue;
308 }
309
310 previousId = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i-1),0));
311
312 // select the cells lying on the same side of the cut line.
313
314 cellsOnSameSide->Initialize();
315 if (this->GetCellsOnSameSide(input,cellEdgeNeighbors->GetId(0),cellEdgeNeighbors->GetId(1),previousCellToEdit,previousId,id0,id1,cellsOnSameSide))
316 {
317 for (j=0; j<cellsOnSameSide->GetNumberOfIds(); j++)
318 {
319 cellsToEdit->InsertUniqueId(cellsOnSameSide->GetId(j));
320 }
321 previousCellToEdit = cellsOnSameSide->GetId(cellsOnSameSide->GetNumberOfIds()-1);
322 }
323 else
324 {
325 // well, we could try to, going the other way and getting the complementary cells, but there's no time now (this is a TODO)
326 vtkErrorMacro(<<"Hole in the surface found. Can't determine line orientation.");
327 return 1;
328 }
329 }
330
331 for (i=0; i<cellsToEdit->GetNumberOfIds(); i++)
332 {
333 cellId = cellsToEdit->GetId(i);
334 input->GetCellPoints(cellId,npts,pts);
335
336 editedCellIds->InsertUniqueId(cellId);
337 editedCells->InsertNextCell(npts);
338 for (j=0; j<npts; j++)
339 {
340 duplicatePointLocation = duplicatedPointIds->IsId(pts[j]);
341 if (duplicatePointLocation!=-1)
342 {
343 editedCells->InsertCellPoint(duplicatePointIds->GetId(duplicatePointLocation));
344 }
345 else
346 {
347 editedCells->InsertCellPoint(pts[j]);
348 }
349 }
350 }
351 }
352
353 input->GetPolys()->InitTraversal();
354 for (i=0; i<input->GetPolys()->GetNumberOfCells(); i++)
355 {
356 input->GetPolys()->GetNextCell(npts,pts);
357 if (editedCellIds->IsId(i)==-1)
358 {
359 newPolys->InsertNextCell(npts,pts);
360 }
361 }
362
363 editedCells->InitTraversal();
364 for (i=0; i<editedCells->GetNumberOfCells(); i++)
365 {
366 editedCells->GetNextCell(npts,pts);
367 newPolys->InsertNextCell(npts,pts);
368 }
369
370 output->SetPoints(newPoints);
371 output->SetPolys(newPolys);
372
373 outputPD->CopyAllocate(inputPD,numberOfInputPoints+numberOfLinePoints);
374
375 for (i=0; i<numberOfInputPoints; i++)
376 {
377 outputPD->CopyData(inputPD,i,i);
378 }
379
380 for (i=0; i<duplicatedPointIds->GetNumberOfIds(); i++)
381 {
382 outputPD->CopyData(inputPD,duplicatedPointIds->GetId(i),duplicatePointIds->GetId(i));
383 }
384
385 duplicatePointIds->Delete();
386 duplicatedPointIds->Delete();
387 cellsToEdit->Delete();
388 cellEdgeNeighbors->Delete();
389 cellsOnSameSide->Delete();
390 editedCells->Delete();
391 editedCellIds->Delete();
392 newPoints->Delete();
393 newPolys->Delete();
394
395 return 1;
396}
int GetCellsOnSameSide(vtkPolyData *input, vtkIdType targetCellId0, vtkIdType targetCellId1, vtkIdType referenceCellId, vtkIdType linePointId0, vtkIdType linePointId1, vtkIdType linePointId2, vtkIdList *cellsOnSameSide)

◆ GetCellsOnSameSide()

int vtkvmtkPolyDataScissors::GetCellsOnSameSide ( vtkPolyData * input,
vtkIdType targetCellId0,
vtkIdType targetCellId1,
vtkIdType referenceCellId,
vtkIdType linePointId0,
vtkIdType linePointId1,
vtkIdType linePointId2,
vtkIdList * cellsOnSameSide )
protected

Definition at line 69 of file vtkvmtkPolyDataScissors.cxx.

70{
71 vtkIdType i, j;
72 vtkIdType *cells;
73 vtkIdType previousCellId;
74 vtkIdType npts;
75 const vtkIdType *pts;
76 vtkIdType ncells;
77 vtkIdType edge[2];
78 bool done;
79
80 if (cellsOnSameSide->GetNumberOfIds()>0)
81 {
82 cellsOnSameSide->Initialize();
83 }
84
85 input->GetPointCells(linePointId1,ncells,cells);
86
87 edge[0] = linePointId1;
88
89 input->GetCellPoints(referenceCellId,npts,pts);
90
91 edge[1] = -1;
92
93 for (i=0; i<npts; i++)
94 {
95 if (pts[i]!=linePointId1 && pts[i]!=linePointId0)
96 {
97 edge[1] = pts[i];
98 break;
99 }
100 }
101
102 if (edge[1]==-1)
103 {
104 vtkErrorMacro(<<"Bad request for CellsOnSameSide of CutLine. Not an edge.");
105 return -1;
106 }
107
108 previousCellId = referenceCellId;
109
110 done = false;
111
112 while(!done)
113 {
114 done = true;
115 for (i=0; i<ncells; i++)
116 {
117 if (cells[i]==previousCellId)
118 continue;
119
120 if (this->IsEdgeInCell(input,edge[0],edge[1],cells[i]))
121 {
122 if ((cells[i]==targetCellId0)||(cells[i]==targetCellId1))
123 {
124 cellsOnSameSide->InsertNextId(cells[i]);
125 return 1;
126 }
127
128 done = false;
129
130 cellsOnSameSide->InsertNextId(cells[i]);
131 previousCellId = cells[i];
132
133 input->GetCellPoints(cells[i],npts,pts);
134 for (j=0; j<npts; j++)
135 {
136 if (pts[j]!=edge[0] && pts[j]!=edge[1])
137 {
138 edge[1] = pts[j];
139 break;
140 }
141 }
142
143 break;
144 }
145 }
146 }
147
148 return 0;
149}
int IsEdgeInCell(vtkPolyData *input, vtkIdType edgePointId0, vtkIdType edgePointId1, vtkIdType cellId)

◆ IsEdgeInCell()

int vtkvmtkPolyDataScissors::IsEdgeInCell ( vtkPolyData * input,
vtkIdType edgePointId0,
vtkIdType edgePointId1,
vtkIdType cellId )
protected

Definition at line 50 of file vtkvmtkPolyDataScissors.cxx.

51{
52 vtkIdType npts;
53 const vtkIdType *pts;
54 vtkIdType i;
55
56 input->GetCellPoints(cellId,npts,pts);
57
58 for (i=0; i<npts; i++)
59 {
60 if ((pts[i]==edgePointId0 && pts[(i+1)%npts]==edgePointId1) || (pts[i]==edgePointId1 && pts[(i+1)%npts]==edgePointId0))
61 {
62 return 1;
63 }
64 }
65
66 return 0;
67}

Member Data Documentation

◆ CutLinePointIdsArrayName

char* vtkvmtkPolyDataScissors::CutLinePointIdsArrayName
protected

Definition at line 72 of file vtkvmtkPolyDataScissors.h.

◆ CutLine

vtkPolyData* vtkvmtkPolyDataScissors::CutLine
protected

Definition at line 73 of file vtkvmtkPolyDataScissors.h.


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