96 vtkInformation *vtkNotUsed(request),
97 vtkInformationVector **inputVector,
98 vtkInformationVector *outputVector)
100 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
101 vtkInformation *outInfo = outputVector->GetInformationObject(0);
103 vtkPolyData *input = vtkPolyData::SafeDownCast(
104 inInfo->Get(vtkDataObject::DATA_OBJECT()));
105 vtkPolyData *output = vtkPolyData::SafeDownCast(
106 outInfo->Get(vtkDataObject::DATA_OBJECT()));
110 vtkErrorMacro(<<
"StretchedMappingArrayName not set.");
116 vtkErrorMacro(<<
"HarmonicMappingArrayName not set.");
122 if (!harmonicMappingArray)
124 vtkErrorMacro(<<
"HarmonicMappingArrayName with name specified does not exist.");
130 vtkErrorMacro(<<
"GroupIdsArrayName not set.");
134 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->
GroupIdsArrayName);
138 vtkErrorMacro(<<
"GroupIdsArray with name specified does not exist.");
144 vtkErrorMacro(<<
"MetricArrayName not set.");
148 vtkDataArray* metricArray = input->GetPointData()->GetArray(this->
MetricArrayName);
152 vtkErrorMacro(<<
"MetricArrayName with name specified does not exist.");
156 vtkDataArray* boundaryMetricArray = NULL;
161 vtkErrorMacro(<<
"BoundaryMetricArrayName not set.");
167 if (!boundaryMetricArray)
169 vtkErrorMacro(<<
"BoundaryMetricArrayName with name specified does not exist.");
174 int numberOfInputPoints = input->GetNumberOfPoints();
176 output->DeepCopy(input);
178 vtkDoubleArray* stretchedMapping = vtkDoubleArray::New();
180 stretchedMapping->SetNumberOfComponents(1);
181 stretchedMapping->SetNumberOfTuples(numberOfInputPoints);
183 output->GetPointData()->AddArray(stretchedMapping);
185 vtkIdList* groupIds = vtkIdList::New();
189 for (i=0; i<groupIds->GetNumberOfIds(); i++)
191 vtkIdType groupId = groupIds->GetId(i);
192 vtkPolyData* cylinder = vtkPolyData::New();
199 vtkDataArray* cylinderMetricArray = cylinder->GetPointData()->GetArray(this->
MetricArrayName);
202 double boundaryMappings[2];
203 double boundaryMetrics[2];
204 double boundaryMetricUsefulBounds[2];
208 boundaryExtractor->SetInputData(cylinder);
209 boundaryExtractor->Update();
211 int numberOfBoundaries = boundaryExtractor->GetOutput()->GetNumberOfCells();
212 if (numberOfBoundaries != 2)
214 vtkErrorMacro(<<
"Branch not topologically a cylinder.");
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++)
225 vtkCell* boundary = boundaryExtractor->GetOutput()->GetCell(j);
226 if (boundary->GetNumberOfPoints() == 0)
228 vtkErrorMacro(<<
"Degenerate branch found.");
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);
236 boundaryMetrics[j] = cylinderBoundaryMetricArray->GetComponent(boundaryPointId,0);
239 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
240 for (k=0; k<numberOfBoundaryPoints; k++)
242 boundaryPointId =
static_cast<int>(boundaryPointIds->GetComponent(boundary->GetPointId(k),0));
243 double metricValue = cylinderMetricArray->GetComponent(boundaryPointId,0);
244 if (metricValue < contourMetricBounds[j][0])
246 contourMetricBounds[j][0] = metricValue;
248 if (metricValue > contourMetricBounds[j][1])
250 contourMetricBounds[j][1] = metricValue;
255 if (boundaryMetrics[0] > boundaryMetrics[1])
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;
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]);
280 boundaryMetrics[0] = contourMetricBounds[0][0];
281 boundaryMetrics[1] = contourMetricBounds[1][1];
284 boundaryExtractor->Delete();
286 vtkContourFilter* contourFilter = vtkContourFilter::New();
287 contourFilter->SetInputData(cylinder);
288 contourFilter->SetValue(0,0.5);
289 contourFilter->Update();
291 int numberOfContours =
static_cast<int>(10.0 * fabs(boundaryMetrics[1] - boundaryMetrics[0]) / (contourFilter->GetOutput()->GetLength()/2.0));
293 double interval = 1.0/
static_cast<double>(numberOfContours);
294 for (j=0; j<=numberOfContours; j++)
296 contourFilter->SetValue(j,
static_cast<double>(j) * interval);
298 contourFilter->Update();
300 vtkStripper* contourStripper = vtkStripper::New();
301 contourStripper->SetInputConnection(contourFilter->GetOutputPort());
302 contourStripper->Update();
304 vtkPolyData* contours = contourStripper->GetOutput();
307 vtkPiecewiseFunction* stretchFunction = vtkPiecewiseFunction::New();
309 int numberOfComputedContours = contours->GetNumberOfCells();
311 vtkDataArray* contourMetricArray = contours->GetPointData()->GetArray(this->
MetricArrayName);
313 for (j=0; j<numberOfComputedContours; j++)
315 vtkPolyLine* contour = vtkPolyLine::SafeDownCast(contours->GetCell(j));
322 double harmonicMappingValue = contours->GetPointData()->GetScalars()->GetComponent(contour->GetPointId(0),0);
324 int numberOfContourPoints = contour->GetNumberOfPoints();
326 double contourLength = 0.0;
327 double metricIntegral = 0.0;
329 for (k=0; k<numberOfContourPoints; k++)
331 int pointId0 = contour->GetPointId(k);
332 int pointId1 = contour->GetPointId((k+1)%numberOfContourPoints);
337 contours->GetPoint(pointId0,point0);
338 contours->GetPoint(pointId1,point1);
340 double length = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
347 contourLength += length;
349 double metricValue0 = contourMetricArray->GetComponent(pointId0,0);
350 double metricValue1 = contourMetricArray->GetComponent(pointId1,0);
352 metricIntegral += length * 0.5 * (metricValue0 + metricValue1);
360 double metricMean = metricIntegral / contourLength;
367 if (metricMean < boundaryMetricUsefulBounds[0] || metricMean > boundaryMetricUsefulBounds[1])
372 stretchFunction->AddPoint(harmonicMappingValue, metricMean);
375 stretchFunction->AddPoint(boundaryMappings[0], boundaryMetrics[0]);
376 stretchFunction->AddPoint(boundaryMappings[1], boundaryMetrics[1]);
384 for (j=0; j<numberOfInputPoints; j++)
386 vtkIdType currentGroupId =
static_cast<int>(groupIdsArray->GetComponent(j,0));
388 if (currentGroupId != groupId)
393 double harmonicMappingValue = harmonicMappingArray->GetComponent(j,0);
396 double stretchedMappingValue = stretchFunction->GetValue(harmonicMappingValue);
398 stretchedMapping->SetComponent(j,0,stretchedMappingValue);
401 stretchFunction->Delete();
402 contourFilter->Delete();
403 contourStripper->Delete();
408 stretchedMapping->Delete();