VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataManifoldNeighborhood.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataManifoldNeighborhood.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:44 $
7Version: $Revision: 1.3 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23
24#include "vtkObjectFactory.h"
25#include "vtkIdList.h"
26#include "vtkCell.h"
27#include "vtkMath.h"
28
29
31
33{
34 vtkIdType i, j, id;
35 vtkIdType numCellsInStencil;
36 vtkIdType startCell, nextCell;
37 vtkIdType p1, p2;
38 vtkIdType bp1, bp2;
39 vtkIdType K;
40 vtkIdType pointId;
41 vtkIdList *cellIds, *ptIds, *stencilIds;
42 vtkCell* cell;
43 vtkPolyData* pdata = vtkPolyData::SafeDownCast(this->DataSet);
44
45 if (pdata==NULL)
46 {
47 vtkErrorMacro(<< "Input data NULL or not poly data");
48 }
49
50 pointId = this->DataSetPointId;
51
52 this->NPoints = 0;
53
54 cellIds = vtkIdList::New();
55 ptIds = vtkIdList::New();
56 stencilIds = vtkIdList::New();
57
58 pdata->GetPointCells (pointId, cellIds);
59 numCellsInStencil = cellIds->GetNumberOfIds();
60 if (numCellsInStencil < 1)
61 {
62 // vtkWarningMacro("numCellsInStencil < 1: " << numCellsInStencil);
63 cellIds->Delete();
64 ptIds->Delete();
65 stencilIds->Delete();
66 return;
67 }
68
69 pdata->GetCellPoints(cellIds->GetId(0),ptIds);
70 p2 = ptIds->GetId(0);
71 i = 1;
72 while (pointId == p2)
73 {
74 p2 = ptIds->GetId(i++);
75 }
76
77 pdata->GetCellEdgeNeighbors (-1,pointId,p2,cellIds);
78
79 nextCell = cellIds->GetId(0);
80 bp2 = -1;
81 bp1 = p2;
82 if (cellIds->GetNumberOfIds() == 1)
83 {
84 startCell = -1;
85 }
86 else
87 {
88 startCell = cellIds->GetId(1);
89 }
90
91 stencilIds->InsertNextId(p2);
92
93 // walk around the stencil counter-clockwise and get cells
94 for (j=0; j<numCellsInStencil; j++)
95 {
96 cell = pdata->GetCell(nextCell);
97 p1 = -1;
98 for (i = 0; i < 3; i++)
99 {
100 if ((p1 = cell->GetPointId(i)) != pointId && cell->GetPointId(i) != p2)
101 {
102 break;
103 }
104 }
105
106 p2 = p1;
107 stencilIds->InsertNextId (p2);
108 pdata->GetCellEdgeNeighbors (nextCell, pointId, p2, cellIds);
109 if (cellIds->GetNumberOfIds() != 1)
110 {
111 bp2 = p2;
112 j++;
113 break;
114 }
115 nextCell = cellIds->GetId(0);
116 }
117
118 // now walk around the other way. this will only happen if there
119 // is a boundary cell left that we have not visited
120 nextCell = startCell;
121 p2 = bp1;
122 for (; j<numCellsInStencil && startCell!=-1; j++)
123 {
124 cell = pdata->GetCell(nextCell);
125 p1 = -1;
126 for (i=0; i<3; i++)
127 {
128 if ((p1=cell->GetPointId(i))!=pointId && cell->GetPointId(i)!=p2)
129 {
130 break;
131 }
132 }
133 p2 = p1;
134 stencilIds->InsertNextId(p2);
135 pdata->GetCellEdgeNeighbors (nextCell, pointId, p2, cellIds);
136 if (cellIds->GetNumberOfIds() != 1)
137 {
138 bp1 = p2;
139 break;
140 }
141 nextCell = cellIds->GetId(0);
142 }
143
144 if (bp2 != -1) // boundary edge
145 {
146 this->IsBoundary = true;
147 id = stencilIds->IsId(bp2);
148 for (i=0; i<=id/2; i++)
149 {
150 p1 = stencilIds->GetId(i);
151 p2 = stencilIds->GetId(id-i);
152 stencilIds->SetId(i,p2);
153 stencilIds->SetId(id-i,p1);
154 }
155 }
156 else
157 {
158 this->IsBoundary = false;
159 K = stencilIds->GetNumberOfIds();
160 // Remove last id. It's a duplicate of the first
161 stencilIds->SetNumberOfIds(--K);
162 }
163
164 this->NPoints = stencilIds->GetNumberOfIds();
165 if (this->PointIds!=NULL)
166 {
167 delete[] this->PointIds;
168 this->PointIds = NULL;
169 }
170 this->PointIds = new vtkIdType[this->NPoints];
171 memcpy(this->PointIds,stencilIds->GetPointer(0),this->NPoints*sizeof(vtkIdType));
172
173 cellIds->Delete();
174 ptIds->Delete();
175 stencilIds->Delete();
176}
177
Apply a neighborhood to the points of a manifold surface.
vtkStandardNewMacro(vtkvmtkPolyDataManifoldNeighborhood)