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
109 {
110 vtkErrorMacro(<<"StretchedMappingArrayName not set.");
111 return 1;
112 }
113
115 {
116 vtkErrorMacro(<<"HarmonicMappingArrayName not set.");
117 return 1;
118 }
119
121
122 if (!harmonicMappingArray)
123 {
124 vtkErrorMacro(<<"HarmonicMappingArrayName with name specified does not exist.");
125 return 1;
126 }
127
129 {
130 vtkErrorMacro(<<"GroupIdsArrayName not set.");
131 return 1;
132 }
133
134 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->
GroupIdsArrayName);
135
136 if (!groupIdsArray)
137 {
138 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist.");
139 return 1;
140 }
141
143 {
144 vtkErrorMacro(<<"MetricArrayName not set.");
145 return 1;
146 }
147
148 vtkDataArray* metricArray = input->GetPointData()->GetArray(this->
MetricArrayName);
149
150 if (!metricArray)
151 {
152 vtkErrorMacro(<<"MetricArrayName with name specified does not exist.");
153 return 1;
154 }
155
156 vtkDataArray* boundaryMetricArray = NULL;
158 {
160 {
161 vtkErrorMacro(<<"BoundaryMetricArrayName not set.");
162 return 1;
163 }
164
166
167 if (!boundaryMetricArray)
168 {
169 vtkErrorMacro(<<"BoundaryMetricArrayName with name specified does not exist.");
170 return 1;
171 }
172 }
173
174 int numberOfInputPoints = input->GetNumberOfPoints();
175
176 output->DeepCopy(input);
177
178 vtkDoubleArray* stretchedMapping = vtkDoubleArray::New();
180 stretchedMapping->SetNumberOfComponents(1);
181 stretchedMapping->SetNumberOfTuples(numberOfInputPoints);
182
183 output->GetPointData()->AddArray(stretchedMapping);
184
185 vtkIdList* groupIds = vtkIdList::New();
187
188 int i, j, k;
189 for (i=0; i<groupIds->GetNumberOfIds(); i++)
190 {
191 vtkIdType groupId = groupIds->GetId(i);
192 vtkPolyData* cylinder = vtkPolyData::New();
195
196
197
199 vtkDataArray* cylinderMetricArray = cylinder->GetPointData()->GetArray(this->
MetricArrayName);
201
202 double boundaryMappings[2];
203 double boundaryMetrics[2];
204 double boundaryMetricUsefulBounds[2];
205
206
208 boundaryExtractor->SetInputData(cylinder);
209 boundaryExtractor->Update();
210
211 int numberOfBoundaries = boundaryExtractor->GetOutput()->GetNumberOfCells();
212 if (numberOfBoundaries != 2)
213 {
214 vtkErrorMacro(<<"Branch not topologically a cylinder.");
215 return 1;
216 }
217
218 double contourMetricBounds[2][2];
219 contourMetricBounds[0][0] = VTK_DOUBLE_MAX;
220 contourMetricBounds[0][1] = VTK_DOUBLE_MIN;
221 contourMetricBounds[1][0] = VTK_DOUBLE_MAX;
222 contourMetricBounds[1][1] = VTK_DOUBLE_MIN;
223 for (j=0; j<numberOfBoundaries; j++)
224 {
225 vtkCell* boundary = boundaryExtractor->GetOutput()->GetCell(j);
226 if (boundary->GetNumberOfPoints() == 0)
227 {
228 vtkErrorMacro(<<"Degenerate branch found.");
229 return 1;
230 }
231 vtkDataArray* boundaryPointIds = boundaryExtractor->GetOutput()->GetPointData()->GetScalars();
232 vtkIdType boundaryPointId = static_cast<int>(boundaryPointIds->GetComponent(boundary->GetPointId(0),0));
233 boundaryMappings[j] = cylinderHarmonicMappingArray->GetComponent(boundaryPointId,0);
235 {
236 boundaryMetrics[j] = cylinderBoundaryMetricArray->GetComponent(boundaryPointId,0);
237 }
238
239 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
240 for (k=0; k<numberOfBoundaryPoints; k++)
241 {
242 boundaryPointId = static_cast<int>(boundaryPointIds->GetComponent(boundary->GetPointId(k),0));
243 double metricValue = cylinderMetricArray->GetComponent(boundaryPointId,0);
244 if (metricValue < contourMetricBounds[j][0])
245 {
246 contourMetricBounds[j][0] = metricValue;
247 }
248 if (metricValue > contourMetricBounds[j][1])
249 {
250 contourMetricBounds[j][1] = metricValue;
251 }
252 }
253 }
254
255 if (boundaryMetrics[0] > boundaryMetrics[1])
256 {
257 double temp;
258 temp = boundaryMappings[1];
259 boundaryMappings[1] = boundaryMappings[0];
260 boundaryMappings[0] = temp;
261 temp = boundaryMetrics[1];
262 boundaryMetrics[1] = boundaryMetrics[0];
263 boundaryMetrics[0] = temp;
264 temp = contourMetricBounds[1][0];
265 contourMetricBounds[1][0] = contourMetricBounds[0][0];
266 contourMetricBounds[0][0] = temp;
267 temp = contourMetricBounds[1][1];
268 contourMetricBounds[1][1] = contourMetricBounds[0][1];
269 contourMetricBounds[0][1] = temp;
270 }
271
272
273
274
275 boundaryMetricUsefulBounds[0] = contourMetricBounds[0][0] + this->
MetricBoundsGapFactor * (contourMetricBounds[0][1] - contourMetricBounds[0][0]);
276 boundaryMetricUsefulBounds[1] = contourMetricBounds[1][1] - this->
MetricBoundsGapFactor * (contourMetricBounds[1][1] - contourMetricBounds[1][0]);
277
279 {
280 boundaryMetrics[0] = contourMetricBounds[0][0];
281 boundaryMetrics[1] = contourMetricBounds[1][1];
282 }
283
284 boundaryExtractor->Delete();
285
286 vtkContourFilter* contourFilter = vtkContourFilter::New();
287 contourFilter->SetInputData(cylinder);
288 contourFilter->SetValue(0,0.5);
289 contourFilter->Update();
290
291 int numberOfContours = static_cast<int>(10.0 * fabs(boundaryMetrics[1] - boundaryMetrics[0]) / (contourFilter->GetOutput()->GetLength()/2.0));
292
293 double interval = 1.0/static_cast<double>(numberOfContours);
294 for (j=0; j<=numberOfContours; j++)
295 {
296 contourFilter->SetValue(j,static_cast<double>(j) * interval);
297 }
298 contourFilter->Update();
299
300 vtkStripper* contourStripper = vtkStripper::New();
301 contourStripper->SetInputConnection(contourFilter->GetOutputPort());
302 contourStripper->Update();
303
304 vtkPolyData* contours = contourStripper->GetOutput();
305
306
307 vtkPiecewiseFunction* stretchFunction = vtkPiecewiseFunction::New();
308
309 int numberOfComputedContours = contours->GetNumberOfCells();
310
311 vtkDataArray* contourMetricArray = contours->GetPointData()->GetArray(this->
MetricArrayName);
312
313 for (j=0; j<numberOfComputedContours; j++)
314 {
315 vtkPolyLine* contour = vtkPolyLine::SafeDownCast(contours->GetCell(j));
316
317 if (!contour)
318 {
319 continue;
320 }
321
322 double harmonicMappingValue = contours->GetPointData()->GetScalars()->GetComponent(contour->GetPointId(0),0);
323
324 int numberOfContourPoints = contour->GetNumberOfPoints();
325
326 double contourLength = 0.0;
327 double metricIntegral = 0.0;
328
329 for (k=0; k<numberOfContourPoints; k++)
330 {
331 int pointId0 = contour->GetPointId(k);
332 int pointId1 = contour->GetPointId((k+1)%numberOfContourPoints);
333
334 double point0[3];
335 double point1[3];
336
337 contours->GetPoint(pointId0,point0);
338 contours->GetPoint(pointId1,point1);
339
340 double length = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
341
343 {
344 continue;
345 }
346
347 contourLength += length;
348
349 double metricValue0 = contourMetricArray->GetComponent(pointId0,0);
350 double metricValue1 = contourMetricArray->GetComponent(pointId1,0);
351
352 metricIntegral += length * 0.5 * (metricValue0 + metricValue1);
353 }
354
356 {
357 continue;
358 }
359
360 double metricMean = metricIntegral / contourLength;
361
362
363
364
365
366
367 if (metricMean < boundaryMetricUsefulBounds[0] || metricMean > boundaryMetricUsefulBounds[1])
368 {
369 continue;
370 }
371
372 stretchFunction->AddPoint(harmonicMappingValue, metricMean);
373 }
374
375 stretchFunction->AddPoint(boundaryMappings[0], boundaryMetrics[0]);
376 stretchFunction->AddPoint(boundaryMappings[1], boundaryMetrics[1]);
377
378
379
380
381
382
383
384 for (j=0; j<numberOfInputPoints; j++)
385 {
386 vtkIdType currentGroupId = static_cast<int>(groupIdsArray->GetComponent(j,0));
387
388 if (currentGroupId != groupId)
389 {
390 continue;
391 }
392
393 double harmonicMappingValue = harmonicMappingArray->GetComponent(j,0);
394
395
396 double stretchedMappingValue = stretchFunction->GetValue(harmonicMappingValue);
397
398 stretchedMapping->SetComponent(j,0,stretchedMappingValue);
399 }
400
401 stretchFunction->Delete();
402 contourFilter->Delete();
403 contourStripper->Delete();
404 cylinder->Delete();
405 }
406
407 groupIds->Delete();
408 stretchedMapping->Delete();
409
410 return 1;
411}
static void ExtractGroup(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)
static void GetGroupsIdList(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdList *groupIds)
#define VTK_VMTK_DOUBLE_TOL