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

Remove non essential Voronoi polygon points (little spikes). More...

#include <vtkvmtkSimplifyVoronoiDiagram.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkSimplifyVoronoiDiagram * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetUnremovablePointIds (vtkIdList *)
virtual vtkIdList * GetUnremovablePointIds ()
virtual void SetUnremovableCellIds (vtkIdList *)
virtual vtkIdList * GetUnremovableCellIds ()
virtual void SetSimplification (int)
virtual int GetSimplification ()
void SetSimplificationToRemoveBoundaryPoints ()
void SetSimplificationToRemoveBoundaryCells ()
virtual void SetIncludeUnremovable (int)
virtual int GetIncludeUnremovable ()
virtual void IncludeUnremovableOn ()
virtual void IncludeUnremovableOff ()
virtual void SetOnePassOnly (int)
virtual int GetOnePassOnly ()
virtual void OnePassOnlyOn ()
virtual void OnePassOnlyOff ()

Static Public Member Functions

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

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkSimplifyVoronoiDiagram ()
 ~vtkvmtkSimplifyVoronoiDiagram () override
int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkIdType IsBoundaryEdge (vtkCellLinks *links, vtkIdType *edge)

Protected Attributes

vtkIdList * UnremovablePointIds
vtkIdList * UnremovableCellIds
int Simplification
int IncludeUnremovable
int OnePassOnly

Detailed Description

Remove non essential Voronoi polygon points (little spikes).

This class identifies and removes Voronoi polygon points if they are used by one cell and they are not poles. This helps to get rid of noisy Voronoi diagram parts induced by non smooth surface point distribution. This operation has no effect on the accuracy of the computation of centerlines and of surface related quantities.

See also
vtkVoronoiDiagram3D

Definition at line 43 of file vtkvmtkSimplifyVoronoiDiagram.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkSimplifyVoronoiDiagram::Superclass

Definition at line 47 of file vtkvmtkSimplifyVoronoiDiagram.h.

Constructor & Destructor Documentation

◆ vtkvmtkSimplifyVoronoiDiagram()

vtkvmtkSimplifyVoronoiDiagram::vtkvmtkSimplifyVoronoiDiagram ( )
protected

◆ ~vtkvmtkSimplifyVoronoiDiagram()

vtkvmtkSimplifyVoronoiDiagram::~vtkvmtkSimplifyVoronoiDiagram ( )
overrideprotected

Definition at line 44 of file vtkvmtkSimplifyVoronoiDiagram.cxx.

45{
46 if (this->UnremovablePointIds)
47 {
48 this->UnremovablePointIds->Delete();
49 this->UnremovablePointIds = NULL;
50 }
51
52 if (this->UnremovableCellIds)
53 {
54 this->UnremovableCellIds->Delete();
55 this->UnremovableCellIds = NULL;
56 }
57}

Member Function Documentation

◆ New()

vtkvmtkSimplifyVoronoiDiagram * vtkvmtkSimplifyVoronoiDiagram::New ( )
static

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkSimplifyVoronoiDiagram::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkSimplifyVoronoiDiagram * vtkvmtkSimplifyVoronoiDiagram::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 362 of file vtkvmtkSimplifyVoronoiDiagram.cxx.

363{
364 this->Superclass::PrintSelf(os,indent);
365}

◆ SetUnremovablePointIds()

virtual void vtkvmtkSimplifyVoronoiDiagram::SetUnremovablePointIds ( vtkIdList * )
virtual

Set/Get the ids of Voronoi diagram points that must never be removed, regardless of whether they would otherwise qualify for removal (used when Simplification is VTK_VMTK_REMOVE_BOUNDARY_POINTS, typically to protect the Voronoi poles). If IncludeUnremovable is off, cells referencing only points not in this list may still be entirely removed.

◆ GetUnremovablePointIds()

virtual vtkIdList * vtkvmtkSimplifyVoronoiDiagram::GetUnremovablePointIds ( )
virtual

Set/Get the ids of Voronoi diagram points that must never be removed, regardless of whether they would otherwise qualify for removal (used when Simplification is VTK_VMTK_REMOVE_BOUNDARY_POINTS, typically to protect the Voronoi poles). If IncludeUnremovable is off, cells referencing only points not in this list may still be entirely removed.

◆ SetUnremovableCellIds()

virtual void vtkvmtkSimplifyVoronoiDiagram::SetUnremovableCellIds ( vtkIdList * )
virtual

Set/Get the ids of Voronoi diagram cells that must never be removed, regardless of whether they would otherwise qualify for removal (used when Simplification is VTK_VMTK_REMOVE_BOUNDARY_CELLS).

◆ GetUnremovableCellIds()

virtual vtkIdList * vtkvmtkSimplifyVoronoiDiagram::GetUnremovableCellIds ( )
virtual

Set/Get the ids of Voronoi diagram cells that must never be removed, regardless of whether they would otherwise qualify for removal (used when Simplification is VTK_VMTK_REMOVE_BOUNDARY_CELLS).

◆ SetSimplification()

virtual void vtkvmtkSimplifyVoronoiDiagram::SetSimplification ( int )
virtual

Set/Get type of simplification.

◆ GetSimplification()

virtual int vtkvmtkSimplifyVoronoiDiagram::GetSimplification ( )
virtual

Set/Get type of simplification.

◆ SetSimplificationToRemoveBoundaryPoints()

void vtkvmtkSimplifyVoronoiDiagram::SetSimplificationToRemoveBoundaryPoints ( )
inline

Set/Get type of simplification.

Definition at line 76 of file vtkvmtkSimplifyVoronoiDiagram.h.

◆ SetSimplificationToRemoveBoundaryCells()

void vtkvmtkSimplifyVoronoiDiagram::SetSimplificationToRemoveBoundaryCells ( )
inline

Set/Get type of simplification.

Definition at line 78 of file vtkvmtkSimplifyVoronoiDiagram.h.

◆ SetIncludeUnremovable()

virtual void vtkvmtkSimplifyVoronoiDiagram::SetIncludeUnremovable ( int )
virtual

Toggle whether points/cells listed in UnremovablePointIds/UnremovableCellIds (and the cells built from them) are kept in the output (on) or dropped entirely once simplification has otherwise converged (off). Only relevant when at least one such id was supplied. Default: on.

◆ GetIncludeUnremovable()

virtual int vtkvmtkSimplifyVoronoiDiagram::GetIncludeUnremovable ( )
virtual

Toggle whether points/cells listed in UnremovablePointIds/UnremovableCellIds (and the cells built from them) are kept in the output (on) or dropped entirely once simplification has otherwise converged (off). Only relevant when at least one such id was supplied. Default: on.

◆ IncludeUnremovableOn()

virtual void vtkvmtkSimplifyVoronoiDiagram::IncludeUnremovableOn ( )
virtual

Toggle whether points/cells listed in UnremovablePointIds/UnremovableCellIds (and the cells built from them) are kept in the output (on) or dropped entirely once simplification has otherwise converged (off). Only relevant when at least one such id was supplied. Default: on.

◆ IncludeUnremovableOff()

virtual void vtkvmtkSimplifyVoronoiDiagram::IncludeUnremovableOff ( )
virtual

Toggle whether points/cells listed in UnremovablePointIds/UnremovableCellIds (and the cells built from them) are kept in the output (on) or dropped entirely once simplification has otherwise converged (off). Only relevant when at least one such id was supplied. Default: on.

◆ SetOnePassOnly()

virtual void vtkvmtkSimplifyVoronoiDiagram::SetOnePassOnly ( int )
virtual

Toggle limiting the simplification to a single pass over the Voronoi diagram cells, instead of iterating until no more points/cells qualify for removal. Default: off (iterate to convergence).

◆ GetOnePassOnly()

virtual int vtkvmtkSimplifyVoronoiDiagram::GetOnePassOnly ( )
virtual

Toggle limiting the simplification to a single pass over the Voronoi diagram cells, instead of iterating until no more points/cells qualify for removal. Default: off (iterate to convergence).

◆ OnePassOnlyOn()

virtual void vtkvmtkSimplifyVoronoiDiagram::OnePassOnlyOn ( )
virtual

Toggle limiting the simplification to a single pass over the Voronoi diagram cells, instead of iterating until no more points/cells qualify for removal. Default: off (iterate to convergence).

◆ OnePassOnlyOff()

virtual void vtkvmtkSimplifyVoronoiDiagram::OnePassOnlyOff ( )
virtual

Toggle limiting the simplification to a single pass over the Voronoi diagram cells, instead of iterating until no more points/cells qualify for removal. Default: off (iterate to convergence).

◆ RequestData()

int vtkvmtkSimplifyVoronoiDiagram::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotected

Definition at line 95 of file vtkvmtkSimplifyVoronoiDiagram.cxx.

99{
100 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
101 vtkInformation* outInfo = outputVector->GetInformationObject(0);
102
103 vtkPolyData* input = vtkPolyData::SafeDownCast(
104 inInfo->Get(vtkDataObject::DATA_OBJECT()));
105 vtkPolyData* output = vtkPolyData::SafeDownCast(
106 outInfo->Get(vtkDataObject::DATA_OBJECT()));
107
108 bool anyRemoved, removeCell, considerPoint;
109 bool* isUnremovable;
110 vtkIdType i, j, id;
111 vtkIdType n;
112 vtkIdType npts, ncells;
113 const vtkIdType *pts;
114 vtkPolyData* poly = vtkPolyData::New();
115 poly->SetPoints(input->GetPoints());
116 npts = 0;
117 pts = NULL;
118 vtkIdType edge[2];
119 vtkCellArray* currentPolys;
120 vtkCellLinks* currentLinks;
121 vtkIdType newCellId;
122 vtkCellArray* inputPolys = input->GetPolys();
123
124 currentPolys = vtkCellArray::New();
125 currentLinks = vtkCellLinks::New();
126
127 n = 0;
129 {
130 n = input->GetNumberOfPoints();
131 }
133 {
134 n = inputPolys->GetNumberOfCells();
135 }
136
137 isUnremovable = new bool[n];
138
139 bool anyUnremovable = false;
140
141 for (i=0; i<n; i++)
142 {
143 isUnremovable[i] = false;
144 }
145
147 {
148 if (this->UnremovablePointIds)
149 {
150 for (i=0; i<this->UnremovablePointIds->GetNumberOfIds(); i++)
151 {
152 id = this->UnremovablePointIds->GetId(i);
153 if ((id >= 0) && (id < n))
154 {
155 anyUnremovable = true;
156 isUnremovable[id] = true;
157 }
158 else
159 {
160 vtkErrorMacro(<< "Out of range id found among UnremovablePointIds!");
161 }
162 }
163 }
164 }
166 {
167 if (this->UnremovableCellIds)
168 {
169 for (i=0; i<this->UnremovableCellIds->GetNumberOfIds(); i++)
170 {
171 id = this->UnremovableCellIds->GetId(i);
172 if ((id >= 0) && (id < n))
173 {
174 anyUnremovable = true;
175 isUnremovable[id] = true;
176 }
177 else if (id<0)
178 {
179 vtkErrorMacro(<< "Out of range id found among UnremovableCellIds!");
180 }
181 }
182 }
183 }
184
185 currentPolys->DeepCopy(inputPolys);
186
187 currentLinks->Allocate(input->GetNumberOfPoints());
188
189 // Reworking cell links classes for performance and consistent API
190 // See https://github.com/Kitware/VTK/commit/88efc809a25130c2ab83dd89a80cea458e3bb56a
191 // #pragma message "vtkvmtkSimplifyVoronoiDiagram::RequestData not functional. Must be updated based on Kitware/VTK@88efc809a"
192 // if (true)
193 // {
194 // vtkErrorMacro(<< "vtkvmtkSimplifyVoronoiDiagram::RequestData is not functional when built against VTK >= 9");
195 // return 0;
196 // }
197 poly->SetPolys(currentPolys);
198
199#if ((VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 0 && VTK_BUILD_VERSION >= 20221108) || (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 2 && VTK_BUILD_VERSION >= 0))
200 currentLinks->SetDataSet(poly);
201 currentLinks->BuildLinks();
202#else
203 currentLinks->BuildLinks(poly);
204#endif
205
206 anyRemoved = true;
207 while (anyRemoved)
208 {
209 anyRemoved = false;
210 vtkCellArray* newPolys = vtkCellArray::New();
211 vtkIdList* newCell = vtkIdList::New();
212 currentPolys->InitTraversal();
213 for (i=0; i<currentPolys->GetNumberOfCells(); i++)
214 {
215 currentPolys->GetNextCell(npts,pts);
216
217 if (npts==0)
218 {
219 continue;
220 }
221
222 newCell->Initialize();
224 {
225 for (j=0; j<npts; j++)
226 {
227 considerPoint = false;
228 ncells = currentLinks->GetNcells(pts[j]);
229
230 if (ncells==1)
231 {
232 considerPoint = true;
233 }
234
235 if (considerPoint)
236 {
237 if (isUnremovable[pts[j]])
238 {
239 newCell->InsertNextId(pts[j]);
240 }
241 else
242 {
243 anyRemoved = true;
244 }
245 }
246 else
247 {
248 newCell->InsertNextId(pts[j]);
249 }
250 }
251 }
253 {
254 removeCell = false;
255 if (!isUnremovable[i])
256 {
257 for (j=0; j<npts; j++)
258 {
259 edge[0] = pts[j];
260 edge[1] = pts[(j+1)%npts];
261
262 if (this->IsBoundaryEdge(currentLinks,edge)>0)
263 {
264 removeCell = true;
265 break;
266 }
267 }
268 }
269
270 if (removeCell)
271 {
272 anyRemoved = true;
273 }
274 else
275 {
276 for (j=0; j<npts; j++)
277 {
278 newCell->InsertNextId(pts[j]);
279 }
280 }
281 }
282
283 if (newCell->GetNumberOfIds() > 2)
284 {
285 newCellId = newPolys->InsertNextCell(newCell);
286 }
287 }
288
289 currentPolys->DeepCopy(newPolys);
290 currentLinks->Delete();
291 currentLinks = vtkCellLinks::New();
292 currentLinks->Allocate(input->GetNumberOfPoints());
293
294 // Reworking cell links classes for performance and consistent API
295 // See https://github.com/Kitware/VTK/commit/88efc809a25130c2ab83dd89a80cea458e3bb56a
296 // #pragma message "vtkvmtkSimplifyVoronoiDiagram::RequestData not functional. Must be updated based on Kitware/VTK@88efc809a"
297 // vtkErrorMacro(<< "!");
298 poly->SetPolys(currentPolys);
299#if ((VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 0 && VTK_BUILD_VERSION >= 20221108) || (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 2 && VTK_BUILD_VERSION >= 0))
300 currentLinks->SetDataSet(poly);
301 currentLinks->BuildLinks();
302#else
303 currentLinks->BuildLinks(poly);
304#endif
305
306 newPolys->Delete();
307 newCell->Delete();
308 if (this->OnePassOnly)
309 {
310 break;
311 }
312 }
313
314 if (anyUnremovable && !this->IncludeUnremovable)
315 {
316 vtkCellArray* newPolys = vtkCellArray::New();
317 vtkIdList* newCell = vtkIdList::New();
318 currentPolys->InitTraversal();
319 for (i=0; i<currentPolys->GetNumberOfCells(); i++)
320 {
321 currentPolys->GetNextCell(npts,pts);
322 newCell->Initialize();
323 if (npts==0)
324 {
325 newPolys->InsertNextCell(npts,pts);
326 continue;
327 }
328 if (!isUnremovable[i])
329 {
330 for (j=0; j<npts; j++)
331 {
332 newCell->InsertNextId(pts[j]);
333 }
334 }
335 if (newCell->GetNumberOfIds() > 2)
336 {
337 newPolys->InsertNextCell(newCell);
338 }
339 }
340 currentPolys->DeepCopy(newPolys);
341 newPolys->Delete();
342 newCell->Delete();
343 }
344
345 // simply passes points and point data (eventually vtkCleanPolyData)
346 // will have less cells but same points
347 output->SetPoints(input->GetPoints());
348 output->GetPointData()->PassData(input->GetPointData());
349
350 // WARNING: cell data are thrown away in the current version
351 output->SetPolys(currentPolys);
352
353 delete[] isUnremovable;
354
355 currentLinks->Delete();
356 currentPolys->Delete();
357 poly->Delete();
358
359 return 1;
360}
vtkIdType IsBoundaryEdge(vtkCellLinks *links, vtkIdType *edge)

◆ IsBoundaryEdge()

vtkIdType vtkvmtkSimplifyVoronoiDiagram::IsBoundaryEdge ( vtkCellLinks * links,
vtkIdType * edge )
protected

Definition at line 59 of file vtkvmtkSimplifyVoronoiDiagram.cxx.

60{
61 vtkIdType j, k;
62 vtkIdType cellId, ncells0, *cells0, ncells1, *cells1;
63
64 ncells0 = links->GetNcells(edge[0]);
65 cells0 = links->GetCells(edge[0]);
66 ncells1 = links->GetNcells(edge[1]);
67 cells1 = links->GetCells(edge[1]);
68
69 cellId = -1;
70
71 for (j=0; j<ncells0; j++)
72 {
73 for (k=0; k<ncells1; k++)
74 {
75 if (cells0[j]==cells1[k])
76 {
77 if (cellId==-1)
78 {
79 cellId = cells0[j];
80 }
81 else if (cells0[j]!=cellId)
82 {
83 return 0;
84 }
85 }
86 }
87 }
88
89 if (cellId==-1)
90 return -1;
91
92 return 1;
93}

Member Data Documentation

◆ UnremovablePointIds

vtkIdList* vtkvmtkSimplifyVoronoiDiagram::UnremovablePointIds
protected

Definition at line 110 of file vtkvmtkSimplifyVoronoiDiagram.h.

◆ UnremovableCellIds

vtkIdList* vtkvmtkSimplifyVoronoiDiagram::UnremovableCellIds
protected

Definition at line 111 of file vtkvmtkSimplifyVoronoiDiagram.h.

◆ Simplification

int vtkvmtkSimplifyVoronoiDiagram::Simplification
protected

Definition at line 113 of file vtkvmtkSimplifyVoronoiDiagram.h.

◆ IncludeUnremovable

int vtkvmtkSimplifyVoronoiDiagram::IncludeUnremovable
protected

Definition at line 114 of file vtkvmtkSimplifyVoronoiDiagram.h.

◆ OnePassOnly

int vtkvmtkSimplifyVoronoiDiagram::OnePassOnly
protected

Definition at line 115 of file vtkvmtkSimplifyVoronoiDiagram.h.


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