80 vtkInformation *vtkNotUsed(request),
81 vtkInformationVector **inputVector,
82 vtkInformationVector *outputVector)
84 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
85 vtkInformation *outInfo = outputVector->GetInformationObject(0);
87 vtkPolyData *input = vtkPolyData::SafeDownCast(
88 inInfo->Get(vtkDataObject::DATA_OBJECT()));
89 vtkPolyData *output = vtkPolyData::SafeDownCast(
90 outInfo->Get(vtkDataObject::DATA_OBJECT()));
92 if ( input->GetNumberOfPoints() < 1 )
100 vtkPoints* newPoints = vtkPoints::New();
101 newPoints->DeepCopy(input->GetPoints());
103 vtkCellArray* newPolys = vtkCellArray::New();
104 newPolys->DeepCopy(input->GetPolys());
107 vtkIdTypeArray* cellEntityIdsArray = NULL;
111 cellEntityIdsArray = vtkIdTypeArray::New();
112 cellEntityIdsArray->SetName(this->CellEntityIdsArrayName);
113 if (input->GetCellData()->GetArray(this->CellEntityIdsArrayName))
115 cellEntityIdsArray->DeepCopy(input->GetCellData()->GetArray(this->CellEntityIdsArrayName));
119 cellEntityIdsArray->SetNumberOfTuples(newPolys->GetNumberOfCells());
127 vtkNew<vtkPolyData> boundaries;
128 vtkNew<vtkIdList> boundaryLabels;
133 for (boundaryId=0; boundaryId<boundaries->GetNumberOfCells(); boundaryId++)
137 vtkIdType capBoundaryId = useBoundaryLabels ? boundaryLabels->GetId(boundaryId) : boundaryId;
146 vtkPolyLine* boundaryCell = vtkPolyLine::SafeDownCast(boundaries->GetCell(boundaryId));
148 int numberOfBoundaryPoints = boundaryCell->GetNumberOfPoints();
149 double boundaryDiagonal = sqrt(boundaryCell->GetLength2());
151 vtkIdList* boundaryPointIds = vtkIdList::New();
153 for (i=0; i<numberOfBoundaryPoints; i++)
155 vtkIdType boundaryPointId =
static_cast<vtkIdType
>(boundaries->GetPointData()->GetScalars()->GetComponent(boundaryCell->GetPointId(i),0));
156 boundaryPointIds->InsertNextId(boundaryPointId);
159 vtkPoints* outerRingPoints = vtkPoints::New();
160 vtkIdList* pointCells = vtkIdList::New();
161 vtkIdList* cellPoints = vtkIdList::New();
162 for (i=0; i<numberOfBoundaryPoints; i++)
164 vtkIdType boundaryPointId = boundaryPointIds->GetId(i);
165 pointCells->Initialize();
166 input->GetPointCells(boundaryPointId,pointCells);
167 double outerRingPoint[3];
168 outerRingPoint[0] = outerRingPoint[1] = outerRingPoint[2] = 0.0;
169 double areaSum = 0.0;
171 for (j=0; j<pointCells->GetNumberOfIds(); j++)
173 vtkIdType cellId = pointCells->GetId(j);
174 input->GetCellPoints(cellId,cellPoints);
176 double point0[3], point1[3], point2[3];
177 input->GetPoint(cellPoints->GetId(0),point0);
178 input->GetPoint(cellPoints->GetId(1),point1);
179 input->GetPoint(cellPoints->GetId(2),point2);
180 double triangleCenter[3];
181 vtkTriangle::TriangleCenter(point0,point1,point2,triangleCenter);
182 double triangleArea = vtkTriangle::TriangleArea(point0,point1,point2);
183 outerRingPoint[0] += triangleArea * triangleCenter[0];
184 outerRingPoint[1] += triangleArea * triangleCenter[1];
185 outerRingPoint[2] += triangleArea * triangleCenter[2];
186 areaSum += triangleArea;
188 outerRingPoint[0] /= areaSum;
189 outerRingPoint[1] /= areaSum;
190 outerRingPoint[2] /= areaSum;
191 double boundaryPoint[3];
192 input->GetPoint(boundaryPointId,boundaryPoint);
193 double boundaryVector[3];
194 boundaryVector[0] = outerRingPoint[0] - boundaryPoint[0];
195 boundaryVector[1] = outerRingPoint[1] - boundaryPoint[1];
196 boundaryVector[2] = outerRingPoint[2] - boundaryPoint[2];
197 vtkMath::Normalize(boundaryVector);
199 outerRingPoint[0] = distance * boundaryVector[0] + boundaryPoint[0];
200 outerRingPoint[1] = distance * boundaryVector[1] + boundaryPoint[1];
201 outerRingPoint[2] = distance * boundaryVector[2] + boundaryPoint[2];
202 outerRingPoints->InsertNextPoint(outerRingPoint);
205 pointCells->Delete();
206 cellPoints->Delete();
208 vtkThinPlateSplineTransform* thinPlateSplineTransform = vtkThinPlateSplineTransform::New();
209 thinPlateSplineTransform->SetBasisToR2LogR();
210 thinPlateSplineTransform->SetSigma(1.0);
211 vtkPoints* sourceLandmarks = vtkPoints::New();
212 vtkPoints* targetLandmarks = vtkPoints::New();
214 for (i=0; i<numberOfBoundaryPoints; i++)
216 double angle = (double)i / (
double)numberOfBoundaryPoints * 2.0*vtkMath::Pi();
217 double sourcePoint[3];
218 sourcePoint[0] = cos(angle);
219 sourcePoint[1] = sin(angle);
220 sourcePoint[2] = 0.0;
221 sourceLandmarks->InsertNextPoint(sourcePoint);
222 targetLandmarks->InsertNextPoint(boundaryCell->GetPoints()->GetPoint(i));
223 double outerRingRadius = 1.25;
224 sourcePoint[0] = outerRingRadius * cos(angle);
225 sourcePoint[1] = outerRingRadius * sin(angle);
226 sourcePoint[2] = 0.0;
227 sourceLandmarks->InsertNextPoint(sourcePoint);
228 targetLandmarks->InsertNextPoint(outerRingPoints->GetPoint(i));
231 thinPlateSplineTransform->SetSourceLandmarks(sourceLandmarks);
232 thinPlateSplineTransform->SetTargetLandmarks(targetLandmarks);
234 outerRingPoints->Delete();
236 vtkIdList* circlePointIds = vtkIdList::New();
237 vtkIdList* previousCirclePointIds = vtkIdList::New();
239 circlePointIds->DeepCopy(boundaryPointIds);
244 previousCirclePointIds->DeepCopy(circlePointIds);
245 circlePointIds->Initialize();
246 for (i=0; i<numberOfBoundaryPoints; i++)
248 double angle = (double)i / (
double)numberOfBoundaryPoints * 2.0*vtkMath::Pi();
249 double radius = 1.0 - (double)k/(
double)this->NumberOfRings;
250 double sourcePoint[3];
251 sourcePoint[0] = radius * cos(angle);
252 sourcePoint[1] = radius * sin(angle);
253 sourcePoint[2] = 0.0;
254 double transformedPoint[3];
255 thinPlateSplineTransform->TransformPoint(sourcePoint,transformedPoint);
256 vtkIdType circlePointId = newPoints->InsertNextPoint(transformedPoint);
257 circlePointIds->InsertNextId(circlePointId);
259 for (i=0; i<numberOfBoundaryPoints; i++)
267 vtkIdType previousId = previousCirclePointIds->GetId(i);
268 vtkIdType previousNextId = previousCirclePointIds->GetId((i+1)%numberOfBoundaryPoints);
269 vtkIdType currentId = circlePointIds->GetId(i);
270 vtkIdType currentNextId = circlePointIds->GetId((i+1)%numberOfBoundaryPoints);
272 vtkIdType firstTriangle[3] = {previousId, previousNextId, currentId};
273 vtkIdType secondTriangle[3] = {previousNextId, currentNextId, currentId};
274 newPolys->InsertNextCell(3,firstTriangle);
275 newPolys->InsertNextCell(3,secondTriangle);
278 vtkIdType capCellEntityId = this->
CapCellEntityId(boundaryId,capBoundaryId,useBoundaryLabels);
279 cellEntityIdsArray->InsertNextValue(capCellEntityId);
280 cellEntityIdsArray->InsertNextValue(capCellEntityId);
289 double tipCentre[3] = {0.0, 0.0, 0.0};
290 vtkIdType numberOfTipPoints = circlePointIds->GetNumberOfIds();
291 for (i=0; i<numberOfTipPoints; i++)
294 newPoints->GetPoint(circlePointIds->GetId(i),tipPoint);
295 for (
int component=0; component<3; component++)
297 tipCentre[component] += tipPoint[component];
300 for (
int component=0; component<3; component++)
302 tipCentre[component] /=
static_cast<double>(numberOfTipPoints);
304 vtkIdType tipCentreId = newPoints->InsertNextPoint(tipCentre);
305 for (i=0; i<numberOfTipPoints; i++)
307 vtkIdType tipTriangle[3] = {circlePointIds->GetId(i),
308 circlePointIds->GetId((i+1)%numberOfTipPoints),
310 newPolys->InsertNextCell(3,tipTriangle);
313 cellEntityIdsArray->InsertNextValue(this->
CapCellEntityId(boundaryId,capBoundaryId,useBoundaryLabels));
317 boundaryPointIds->Delete();
319 circlePointIds->Delete();
320 previousCirclePointIds->Delete();
322 thinPlateSplineTransform->Delete();
323 sourceLandmarks->Delete();
324 targetLandmarks->Delete();
327 output->SetPoints(newPoints);
328 output->SetPolys(newPolys);
332 output->GetCellData()->AddArray(cellEntityIdsArray);
333 cellEntityIdsArray->Delete();