69{
70 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
71 vtkInformation *outInfo = outputVector->GetInformationObject(0);
72
73 vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
74 vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
75
77 {
78 vtkErrorMacro("Name of seam scalars array not specified.");
79 return 1;
80 }
81
82 vtkDoubleArray* sourceArray = vtkDoubleArray::New();
83
84 vtkIdType numberOfPoints = input->GetNumberOfPoints();
85
87 {
88 if (input->GetPointData()->GetArray(this->SeamScalarsArrayName))
89 {
90 sourceArray->DeepCopy(input->GetPointData()->GetArray(this->SeamScalarsArrayName));
91 }
92 else
93 {
94 vtkErrorMacro("Seam scalars with name specified does not exist and seam function not specified.");
95 return 1;
96 }
97 }
98 else
99 {
100 sourceArray->SetNumberOfTuples(input->GetNumberOfPoints());
101 double point[3], value;
102 for (vtkIdType i=0; i<numberOfPoints; i++)
103 {
104 input->GetPoint(i,point);
106 sourceArray->SetValue(i,value);
107 }
108 }
109
110 vtkIdType numberOfCells = input->GetNumberOfCells();
111
112 vtkUnsignedCharArray* visitedArray = vtkUnsignedCharArray::New();
113 visitedArray->SetNumberOfTuples(numberOfPoints);
114 visitedArray->FillComponent(0,0.0);
115
116 vtkDoubleArray* seamArray = vtkDoubleArray::New();
118 seamArray->SetNumberOfTuples(numberOfPoints);
119 seamArray->FillComponent(0,0.0);
120
121 input->BuildCells();
122 input->BuildLinks();
123
124 vtkIdType firstSeamPointId = -1;
126
127 vtkIdType npts;
128 const vtkIdType *pts;
129
130 for (vtkIdType i=0; i<numberOfCells; i++)
131 {
132 input->GetCellPoints(i,npts,pts);
133 for (vtkIdType j=0; j<npts-1; j++)
134 {
135 vtkIdType point0Id = pts[j];
136 vtkIdType point1Id = pts[j+1];
137 double point0Value = sourceArray->GetTuple1(point0Id);
138 double point1Value = sourceArray->GetTuple1(point1Id);
139 if (point0Value * point1Value < 0.0)
140 {
141 double point0[3], point1[3];
142 input->GetPoint(point0Id,point0);
143 input->GetPoint(point1Id,point1);
144 double dist0 = vtkMath::Distance2BetweenPoints(point0,this->
ClosestPoint);
145 double dist1 = vtkMath::Distance2BetweenPoints(point1,this->
ClosestPoint);
146 if (dist0 < minDist)
147 {
148 minDist = dist0;
149 firstSeamPointId = point0Id;
150 }
151 if (dist1 < minDist)
152 {
153 minDist = dist1;
154 firstSeamPointId = point1Id;
155 }
156 continue;
157 }
158 }
159 }
160
161 std::queue<vtkIdType> seamQueue;
162
163 seamQueue.push(firstSeamPointId);
164
165 std::queue<vtkIdType> leftQueue;
166 std::queue<vtkIdType> rightQueue;
167
168 vtkIdType *cells;
169 vtkIdType ncells;
170
171 while (!seamQueue.empty())
172 {
173 vtkIdType point0Id = seamQueue.front();
174 seamQueue.pop();
175 double point0Value = sourceArray->GetTuple1(point0Id);
176 visitedArray->SetValue(point0Id,1);
177 seamArray->SetValue(point0Id,point0Value);
178 input->GetPointCells(point0Id,ncells,cells);
179 for (vtkIdType i=0; i<ncells; i++)
180 {
181 vtkIdType cellId = cells[i];
182 input->GetCellPoints(cellId,npts,pts);
183 for (vtkIdType j=0; j<npts; j++)
184 {
185 vtkIdType point1Id = pts[j];
186 if (visitedArray->GetValue(point1Id) == 1)
187 {
188 continue;
189 }
190 double point1Value = sourceArray->GetTuple1(point1Id);
191 if (point0Value * point1Value > 0.0)
192 {
193 seamArray->SetValue(point1Id,point1Value);
194 if (point1Value > 0.0)
195 {
196 rightQueue.push(point1Id);
197 }
198 else
199 {
200 leftQueue.push(point1Id);
201 }
202 continue;
203 }
204 visitedArray->SetValue(point1Id,1);
205 seamArray->SetValue(point1Id,point1Value);
206 seamQueue.push(point1Id);
207 }
208 }
209 }
210
211 const double leftValue = -1.0;
212 const double rightValue = 1.0;
213
214 while(!leftQueue.empty())
215 {
216 vtkIdType point0Id = leftQueue.front();
217 leftQueue.pop();
218 visitedArray->SetValue(point0Id,1);
219 input->GetPointCells(point0Id,ncells,cells);
220 for (vtkIdType i=0; i<ncells; i++)
221 {
222 vtkIdType cellId = cells[i];
223 input->GetCellPoints(cellId,npts,pts);
224 for (vtkIdType j=0; j<npts; j++)
225 {
226 vtkIdType point1Id = pts[j];
227 if (visitedArray->GetValue(point1Id) == 1)
228 {
229 continue;
230 }
231 visitedArray->SetValue(point1Id,1);
232 seamArray->SetValue(point1Id,leftValue);
233 leftQueue.push(point1Id);
234 }
235 }
236 }
237
238 while(!rightQueue.empty())
239 {
240 vtkIdType point0Id = rightQueue.front();
241 rightQueue.pop();
242 visitedArray->SetValue(point0Id,1);
243 input->GetPointCells(point0Id,ncells,cells);
244 for (vtkIdType i=0; i<ncells; i++)
245 {
246 vtkIdType cellId = cells[i];
247 input->GetCellPoints(cellId,npts,pts);
248 for (vtkIdType j=0; j<npts; j++)
249 {
250 vtkIdType point1Id = pts[j];
251 if (visitedArray->GetValue(point1Id) == 1)
252 {
253 continue;
254 }
255 visitedArray->SetValue(point1Id,1);
256 seamArray->SetValue(point1Id,rightValue);
257 rightQueue.push(point1Id);
258 }
259 }
260 }
261
262 output->DeepCopy(input);
263 output->GetPointData()->AddArray(seamArray);
265
266 visitedArray->Delete();
267 sourceArray->Delete();
268 seamArray->Delete();
269
270 return 1;
271}
#define VTK_VMTK_LARGE_DOUBLE