103 vtkInformation *vtkNotUsed(request),
104 vtkInformationVector **inputVector,
105 vtkInformationVector *outputVector)
107 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
108 vtkInformation *outInfo = outputVector->GetInformationObject(0);
110 vtkPolyData *input = vtkPolyData::SafeDownCast(
111 inInfo->Get(vtkDataObject::DATA_OBJECT()));
112 vtkPolyData *output = vtkPolyData::SafeDownCast(
113 outInfo->Get(vtkDataObject::DATA_OBJECT()));
117 vtkErrorMacro(<<
"LongitudinalPatchNumberArrayName not set.");
123 vtkErrorMacro(<<
"CircularPatchNumberArrayName not set.");
129 vtkErrorMacro(<<
"PatchAreaArrayName not set.");
135 vtkErrorMacro(<<
"LongitudinalMappingArrayName not set.");
141 if (!longitudinalMappingArray)
143 vtkErrorMacro(<<
"LongitudinalMappingArray with name specified does not exist.");
147 vtkDataArray* circularMappingArray = NULL;
153 vtkErrorMacro(<<
"CircularMappingArrayName not set.");
159 if (!circularMappingArray)
161 vtkErrorMacro(<<
"CircularMappingArray with name specified does not exist.");
168 vtkErrorMacro(<<
"GroupIdsArrayName not set.");
172 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->
GroupIdsArrayName);
176 vtkErrorMacro(<<
"GroupIdsArray with name specified does not exist.");
180 int numberOfInputPoints = input->GetNumberOfPoints();
182 double circumferentialActualPatchSize = this->
PatchSize[1] * 2.0 * vtkMath::Pi();
184 char shiftedCircularMapping90ArrayName[] =
"ShiftedCircularMapping90";
185 char shiftedCircularMapping180ArrayName[] =
"ShiftedCircularMapping180";
186 char shiftedCircularMapping270ArrayName[] =
"ShiftedCircularMapping270";
188 vtkDoubleArray* shiftedCircularMapping90Array = vtkDoubleArray::New();
189 shiftedCircularMapping90Array->SetName(shiftedCircularMapping90ArrayName);
190 shiftedCircularMapping90Array->SetNumberOfComponents(1);
191 shiftedCircularMapping90Array->SetNumberOfTuples(numberOfInputPoints);
192 vtkDoubleArray* shiftedCircularMapping180Array = vtkDoubleArray::New();
193 shiftedCircularMapping180Array->SetName(shiftedCircularMapping180ArrayName);
194 shiftedCircularMapping180Array->SetNumberOfComponents(1);
195 shiftedCircularMapping180Array->SetNumberOfTuples(numberOfInputPoints);
196 vtkDoubleArray* shiftedCircularMapping270Array = vtkDoubleArray::New();
197 shiftedCircularMapping270Array->SetName(shiftedCircularMapping270ArrayName);
198 shiftedCircularMapping270Array->SetNumberOfComponents(1);
199 shiftedCircularMapping270Array->SetNumberOfTuples(numberOfInputPoints);
204 for (i=0; i<numberOfInputPoints; i++)
206 double value = circularMappingArray->GetComponent(i,0);
207 double shiftedValue = value + 0.5 * vtkMath::Pi();
208 if (shiftedValue > vtkMath::Pi())
210 shiftedValue -= 2.0 * vtkMath::Pi();
212 shiftedCircularMapping90Array->SetValue(i,shiftedValue);
213 shiftedValue = value + vtkMath::Pi();
214 if (shiftedValue > vtkMath::Pi())
216 shiftedValue -= 2.0 * vtkMath::Pi();
218 shiftedCircularMapping180Array->SetValue(i,shiftedValue);
219 shiftedValue = value + 1.5 * vtkMath::Pi();
220 if (shiftedValue > vtkMath::Pi())
222 shiftedValue -= 2.0 * vtkMath::Pi();
224 shiftedCircularMapping270Array->SetValue(i,shiftedValue);
229 shiftedCircularMapping90Array->FillComponent(0,0.0);
230 shiftedCircularMapping180Array->FillComponent(0,0.0);
231 shiftedCircularMapping270Array->FillComponent(0,0.0);
234 input->GetPointData()->AddArray(shiftedCircularMapping90Array);
235 input->GetPointData()->AddArray(shiftedCircularMapping180Array);
236 input->GetPointData()->AddArray(shiftedCircularMapping270Array);
246 vtkPointData* patchedDataPointData = this->
PatchedData->GetPointData();
247 patchedDataPointData->CopyAllocate(input->GetPointData(),0);
249 vtkIntArray* patchedDataLongitudinalPatchNumberArray = vtkIntArray::New();
251 patchedDataLongitudinalPatchNumberArray->SetNumberOfComponents(1);
253 vtkIntArray* patchedDataCircularPatchNumberArray = vtkIntArray::New();
255 patchedDataCircularPatchNumberArray->SetNumberOfComponents(1);
257 vtkDoubleArray* patchedDataPatchAreaArray = vtkDoubleArray::New();
259 patchedDataPatchAreaArray->SetNumberOfComponents(1);
261 vtkAppendPolyData* patchAppendFilter = vtkAppendPolyData::New();
269 int circularPatchStartIndex = 0;
270 int circularPatchEndIndex = 0;
275 if (circularPatchStartIndex*circumferentialActualPatchSize - this->
PatchOffsets[1] < - vtkMath::Pi())
277 circularPatchStartIndex += 1;
279 circularPatchEndIndex = vtkMath::Floor((this->
CircularPatchBounds[1] - this->
PatchOffsets[1] - 1E-3 * circumferentialActualPatchSize) / circumferentialActualPatchSize);
282 int numberOfPreviousPatchDataLines = 0;
283 vtkIdList* groupIds = vtkIdList::New();
285 for (i=0; i<groupIds->GetNumberOfIds(); i++)
287 vtkIdType groupId = groupIds->GetId(i);
288 vtkPolyData* cylinder = vtkPolyData::New();
296 vtkClipPolyData* longitudinalClipper0 = vtkClipPolyData::New();
297 longitudinalClipper0->SetInputData(cylinder);
298 longitudinalClipper0->GenerateClipScalarsOff();
299 longitudinalClipper0->InsideOutOff();
301 vtkClipPolyData* longitudinalClipper1 = vtkClipPolyData::New();
302 longitudinalClipper1->SetInputConnection(longitudinalClipper0->GetOutputPort());
303 longitudinalClipper1->GenerateClipScalarsOff();
304 longitudinalClipper1->InsideOutOn();
306 vtkClipPolyData* circularClipper0 = vtkClipPolyData::New();
307 circularClipper0->SetInputConnection(longitudinalClipper1->GetOutputPort());
308 circularClipper0->GenerateClipScalarsOff();
309 circularClipper0->InsideOutOff();
311 vtkClipPolyData* circularClipper1 = vtkClipPolyData::New();
312 circularClipper1->SetInputConnection(circularClipper0->GetOutputPort());
313 circularClipper1->GenerateClipScalarsOff();
314 circularClipper1->InsideOutOn();
316 vtkPolyDataConnectivityFilter* patchConnectivityFilter = vtkPolyDataConnectivityFilter::New();
317 patchConnectivityFilter->SetInputConnection(circularClipper1->GetOutputPort());
318 patchConnectivityFilter->SetExtractionModeToLargestRegion();
320 double longitudinalMappingRange[2];
322 longitudinalMappingArray->GetRange(longitudinalMappingRange,0);
324 double longitudinalCylinderPatchBounds[2];
328 longitudinalCylinderPatchBounds[0] = longitudinalMappingRange[0];
329 longitudinalCylinderPatchBounds[1] = longitudinalMappingRange[1];
337 int longitudinalPatchStartIndex = vtkMath::Floor((longitudinalCylinderPatchBounds[0] - this->
PatchOffsets[0]) / this->
PatchSize[0]);
338 int longitudinalPatchEndIndex = vtkMath::Floor((longitudinalCylinderPatchBounds[1] - this->
PatchOffsets[0] - 1E-3 * this->
PatchSize[0]) / this->
PatchSize[0]);
341 for (j=longitudinalPatchStartIndex; j<=longitudinalPatchEndIndex; j++)
344 double longitudinalPatchEnd = this->
PatchOffsets[0] + (j+1) * this->PatchSize[0];
346 longitudinalClipper0->SetValue(longitudinalPatchStart);
347 longitudinalClipper1->SetValue(longitudinalPatchEnd);
348 longitudinalClipper1->Update();
350 if (longitudinalClipper1->GetOutput()->GetNumberOfPoints() == 0)
355 for (k=circularPatchStartIndex; k<=circularPatchEndIndex; k++)
357 int patchId = k - circularPatchStartIndex + (j - longitudinalPatchStartIndex) * (circularPatchEndIndex-circularPatchStartIndex+1) + numberOfPreviousPatchDataLines * (circularPatchEndIndex-circularPatchStartIndex+1);
358 double circularPatchCenter = 0.0;
359 double shiftedCircularPatchCenter = 0.0;
360 char* patchShiftedCircularMappingArrayName = NULL;
364 double circularPatchStart = this->
PatchOffsets[1] + k * circumferentialActualPatchSize;
365 double circularPatchEnd = this->
PatchOffsets[1] + (k+1) * circumferentialActualPatchSize;
367 double pi = vtkMath::Pi();
369 if (circularPatchStart < -pi)
371 circularPatchStart += 2.0 * pi;
372 circularPatchEnd += 2.0 * pi;
375 circularPatchCenter = 0.5 * (circularPatchStart + circularPatchEnd);
378 if (circularPatchCenter <= - 0.75 * pi || circularPatchCenter >= 0.75 * pi)
380 patchShiftedCircularMappingArrayName = shiftedCircularMapping180ArrayName;
381 if (circularPatchCenter <= - 0.75 * pi)
383 circularPatchStart += pi;
384 circularPatchEnd += pi;
386 else if (circularPatchCenter >= 0.75 * pi)
388 circularPatchStart -= pi;
389 circularPatchEnd -= pi;
393 else if (circularPatchCenter >= 0.25 * pi && circularPatchCenter < 0.75 * pi)
395 patchShiftedCircularMappingArrayName = shiftedCircularMapping270ArrayName;
396 circularPatchStart -= 0.5 * pi;
397 circularPatchEnd -= 0.5 * pi;
400 else if (circularPatchCenter > -0.75 * pi && circularPatchCenter <= -0.25 * pi)
402 patchShiftedCircularMappingArrayName = shiftedCircularMapping90ArrayName;
403 circularPatchStart += 0.5 * pi;
404 circularPatchEnd += 0.5 * pi;
411 longitudinalClipper1->GetOutput()->GetPointData()->SetActiveScalars(patchShiftedCircularMappingArrayName);
413 shiftedCircularPatchCenter = 0.5 * (circularPatchStart + circularPatchEnd);
415 circularClipper0->Modified();
416 circularClipper0->SetValue(circularPatchStart);
417 circularClipper1->SetValue(circularPatchEnd);
418 circularClipper1->Update();
420 if (circularClipper1->GetOutput()->GetNumberOfPoints() == 0)
426 vtkTriangleFilter* patchTriangleFilter = vtkTriangleFilter::New();
432 patchConnectivityFilter->SetInputConnection(circularClipper1->GetOutputPort());
436 patchConnectivityFilter->SetInputConnection(longitudinalClipper1->GetOutputPort());
438 patchConnectivityFilter->Update();
439 patchTriangleFilter->SetInputConnection(patchConnectivityFilter->GetOutputPort());
445 patchTriangleFilter->SetInputConnection(circularClipper1->GetOutputPort());
449 patchTriangleFilter->SetInputConnection(longitudinalClipper1->GetOutputPort());
453 patchTriangleFilter->Update();
455 vtkPolyData* patch = vtkPolyData::New();
456 patch->DeepCopy(patchTriangleFilter->GetOutput());
459 int patchNumberOfCells = patch->GetNumberOfCells();
464 vtkDataArray* patchShiftedCircularMappingArray = patch->GetPointData()->GetArray(patchShiftedCircularMappingArrayName);
466 double angularOffset = circularPatchCenter - shiftedCircularPatchCenter;
468 vtkIdType patchNumberOfPoints = patch->GetNumberOfPoints();
470 for (pointId=0; pointId<patchNumberOfPoints; pointId++)
472 double circularMappingValue = patchShiftedCircularMappingArray->GetTuple1(pointId);
473 circularMappingValue += angularOffset;
474 patchCircularMappingArray->SetTuple1(pointId,circularMappingValue);
478 vtkIntArray* longitudinalPatchNumberArray = vtkIntArray::New();
480 longitudinalPatchNumberArray->SetNumberOfComponents(1);
481 longitudinalPatchNumberArray->SetNumberOfTuples(patchNumberOfCells);
483 vtkIntArray* circularPatchNumberArray = vtkIntArray::New();
485 circularPatchNumberArray->SetNumberOfComponents(1);
486 circularPatchNumberArray->SetNumberOfTuples(patchNumberOfCells);
488 vtkDoubleArray* patchAreaArray = vtkDoubleArray::New();
490 patchAreaArray->SetNumberOfComponents(1);
491 patchAreaArray->SetNumberOfTuples(patchNumberOfCells);
493 double patchArea = 0.0;
495 vtkPointData* patchPointData = patch->GetPointData();
497 vtkCellData* patchCellData = vtkCellData::New();
498 patchCellData->CopyAllocate(patchPointData,patchNumberOfCells);
500 vtkCellData* patchedPatchCellData = patch->GetCellData();
501 patchedPatchCellData->CopyAllocate(patchCellData,patchNumberOfCells);
504 for (cellId=0; cellId < patchNumberOfCells; cellId++)
506 vtkTriangle* triangle = vtkTriangle::SafeDownCast(patch->GetCell(cellId));
512 double point0[3], point1[3], point2[3];
513 triangle->GetPoints()->GetPoint(0,point0);
514 triangle->GetPoints()->GetPoint(1,point1);
515 triangle->GetPoints()->GetPoint(2,point2);
516 patchArea += vtkTriangle::TriangleArea(point0,point1,point2);
519 weights[1] = 1.0/3.0;
520 weights[2] = 1.0/3.0;
521 weights[0] = (1.0 - weights[1] - weights[2]);
523 patchCellData->InterpolatePoint(patchPointData,cellId,triangle->GetPointIds(),weights);
526 for (cellId = 0; cellId < patchNumberOfCells; cellId++)
528 longitudinalPatchNumberArray->SetValue(cellId,j);
529 circularPatchNumberArray->SetValue(cellId,k);
530 patchAreaArray->SetValue(cellId,patchArea);
533 patchedDataLongitudinalPatchNumberArray->InsertValue(patchId,j);
534 patchedDataCircularPatchNumberArray->InsertValue(patchId,k);
535 patchedDataPatchAreaArray->InsertValue(patchId,patchArea);
537 int numberOfArrays = patchCellData->GetNumberOfArrays();
539 for (arrayId = 0; arrayId<numberOfArrays; arrayId++)
541 vtkDataArray* patchArray = patchCellData->GetArray(arrayId);
542 vtkDataArray* patchedArray = patchedPatchCellData->GetArray(patchArray->GetName());
543 vtkDataArray* patchedDataArray = patchedDataPointData->GetArray(arrayId);
549 int dataType = patchArray->GetDataType();
550 if (dataType != VTK_FLOAT && dataType != VTK_DOUBLE)
552 for (cellId = 0; cellId < patchNumberOfCells; cellId++)
554 patchedArray->InsertTuple(cellId,patchArray->GetTuple(cellId));
556 if (patchNumberOfCells > 0)
558 patchedDataArray->InsertTuple(patchId,patchArray->GetTuple(0));
563 double* integralTuple =
new double[patchArray->GetNumberOfComponents()];
565 for (componentId = 0; componentId < patchArray->GetNumberOfComponents(); componentId++)
567 integralTuple[componentId] = 0.0;
569 for (cellId = 0; cellId < patchNumberOfCells; cellId++)
571 vtkTriangle* triangle = vtkTriangle::SafeDownCast(patch->GetCell(cellId));
576 double point0[3], point1[3], point2[3];
577 triangle->GetPoints()->GetPoint(0,point0);
578 triangle->GetPoints()->GetPoint(1,point1);
579 triangle->GetPoints()->GetPoint(2,point2);
580 double area = vtkTriangle::TriangleArea(point0,point1,point2);
582 for (componentId = 0; componentId < patchArray->GetNumberOfComponents(); componentId++)
584 integralTuple[componentId] += area * patchArray->GetComponent(cellId,componentId);
587 for (componentId = 0; componentId < patchArray->GetNumberOfComponents(); componentId++)
589 integralTuple[componentId] /= patchArea;
591 for (cellId = 0; cellId < patchNumberOfCells; cellId++)
593 patchedArray->InsertTuple(cellId,integralTuple);
596 patchedDataArray->InsertTuple(patchId,integralTuple);
598 delete[] integralTuple;
601 patch->GetCellData()->AddArray(longitudinalPatchNumberArray);
602 patch->GetCellData()->AddArray(circularPatchNumberArray);
603 patch->GetCellData()->AddArray(patchAreaArray);
605 patchAppendFilter->AddInputData(patch);
608 patchTriangleFilter->Delete();
609 patchCellData->Delete();
610 longitudinalPatchNumberArray->Delete();
611 circularPatchNumberArray->Delete();
612 patchAreaArray->Delete();
618 longitudinalClipper0->Delete();
619 longitudinalClipper1->Delete();
620 circularClipper0->Delete();
621 circularClipper1->Delete();
622 patchConnectivityFilter->Delete();
624 numberOfPreviousPatchDataLines += longitudinalPatchEndIndex - longitudinalPatchStartIndex + 1;
630 this->
PatchedData->SetExtent(0,circularPatchEndIndex-circularPatchStartIndex,0,numberOfPreviousPatchDataLines-1,0,0);
632 this->
PatchedData->GetPointData()->AddArray(patchedDataLongitudinalPatchNumberArray);
633 this->
PatchedData->GetPointData()->AddArray(patchedDataCircularPatchNumberArray);
634 this->
PatchedData->GetPointData()->AddArray(patchedDataPatchAreaArray);
636 this->
PatchedData->GetPointData()->RemoveArray(shiftedCircularMapping90ArrayName);
637 this->
PatchedData->GetPointData()->RemoveArray(shiftedCircularMapping180ArrayName);
638 this->
PatchedData->GetPointData()->RemoveArray(shiftedCircularMapping270ArrayName);
640 patchAppendFilter->Update();
641 output->DeepCopy(patchAppendFilter->GetOutput());
643 output->GetPointData()->RemoveArray(shiftedCircularMapping90ArrayName);
644 output->GetPointData()->RemoveArray(shiftedCircularMapping180ArrayName);
645 output->GetPointData()->RemoveArray(shiftedCircularMapping270ArrayName);
646 output->GetCellData()->RemoveArray(shiftedCircularMapping90ArrayName);
647 output->GetCellData()->RemoveArray(shiftedCircularMapping180ArrayName);
648 output->GetCellData()->RemoveArray(shiftedCircularMapping270ArrayName);
650 input->GetPointData()->RemoveArray(shiftedCircularMapping90ArrayName);
651 input->GetPointData()->RemoveArray(shiftedCircularMapping180ArrayName);
652 input->GetPointData()->RemoveArray(shiftedCircularMapping270ArrayName);
654 patchedDataLongitudinalPatchNumberArray->Delete();
655 patchedDataCircularPatchNumberArray->Delete();
656 patchedDataPatchAreaArray->Delete();
658 patchAppendFilter->Delete();
660 shiftedCircularMapping90Array->Delete();
661 shiftedCircularMapping180Array->Delete();
662 shiftedCircularMapping270Array->Delete();