69 vtkInformation *vtkNotUsed(request),
70 vtkInformationVector **inputVector,
71 vtkInformationVector *outputVector)
73 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
74 vtkInformation *outInfo = outputVector->GetInformationObject(0);
76 vtkPolyData *input = vtkPolyData::SafeDownCast(
77 inInfo->Get(vtkDataObject::DATA_OBJECT()));
78 vtkPolyData *output = vtkPolyData::SafeDownCast(
79 outInfo->Get(vtkDataObject::DATA_OBJECT()));
81 if (input->GetNumberOfPoints() < 1)
94 double resampleLength = 0.1;
96 vtkSplineFilter* splineFilter = vtkSplineFilter::New();
97 splineFilter->SetInputData(input);
98 splineFilter->SetSubdivideToLength();
99 splineFilter->SetLength(resampleLength);
100 splineFilter->Update();
102 vtkPolyData* streamlines = splineFilter->GetOutput();
104 vtkIntArray* voronoiSheetIdsArray = NULL;
105 vtkIntArray* sheetIdsArray = NULL;
106 vtkIntArray* streamlineSheetIdsArray = NULL;
107 vtkCellLocator* cellLocator = NULL;
110 if (!this->
VoronoiDiagram->GetCellData()->GetArray(this->VoronoiSheetIdsArrayName))
112 vtkErrorMacro(<<
"VoronoiSheetIdsArray with name specified does not exist!");
115 voronoiSheetIdsArray = vtkIntArray::New();
116 voronoiSheetIdsArray->DeepCopy(this->
VoronoiDiagram->GetCellData()->GetArray(this->VoronoiSheetIdsArrayName));
117 sheetIdsArray = vtkIntArray::New();
119 cellLocator = vtkCellLocator::New();
121 cellLocator->BuildLocator();
122 streamlineSheetIdsArray = vtkIntArray::New();
124 streamlineSheetIdsArray->SetNumberOfTuples(streamlines->GetNumberOfPoints());
127 int numberOfCells = streamlines->GetNumberOfCells();
129 vtkIntArray* labelArray = vtkIntArray::New();
130 labelArray->SetName(
"Label");
132 vtkDoubleArray* radiusArray = vtkDoubleArray::New();
133 radiusArray->SetName(
"Radius");
135 vtkPoints* outputPoints = vtkPoints::New();
136 vtkCellArray* outputVertices = vtkCellArray::New();
138 for (
int i=0; i<numberOfCells; i++)
140 vtkCell* streamline = streamlines->GetCell(i);
141 int numberOfStreamlinePoints = streamline->GetNumberOfPoints();
142 for (
int ip=1; ip<numberOfStreamlinePoints-1; ip++)
144 double x0[3], x1[3], x2[3];
145 streamlines->GetPoint(streamline->GetPointId(ip-1),x0);
146 streamlines->GetPoint(streamline->GetPointId(ip),x1);
147 streamlines->GetPoint(streamline->GetPointId(ip+1),x2);
149 for (
int j=0; j<3; j++)
151 a[j] = 0.5 * (x1[j] + x0[j]);
153 double x2_x1[3], x1_x0[3];
155 for (
int j=0; j<3; j++)
157 x2_x1[j] = x2[j] - x1[j];
158 x1_x0[j] = x1[j] - x0[j];
159 x2_a[j] = x2[j] - a[j];
161 double a_x2_sq = vtkMath::Distance2BetweenPoints(a,x2);
162 double a_x1_sq = vtkMath::Distance2BetweenPoints(a,x1);
163 double x2_x1_dot_x1_x0 = vtkMath::Dot(x2_x1,x1_x0);
164 double x2_x1_sq = vtkMath::Distance2BetweenPoints(x2,x1);
165 for (
int j=0; j<3; j++)
167 u[j] = (x2[j] - x1[j]) - (x1[j] - x0[j]) * (x2_x1_dot_x1_x0 / x2_x1_sq);
169 vtkMath::Normalize(u);
170 double u_dot_x2_a = vtkMath::Dot(u, x2_a);
175 double t = (a_x2_sq - a_x1_sq) / (2.0 * u_dot_x2_a);
176 double osculatingCenter[3];
177 for (
int j=0; j<3; j++)
179 osculatingCenter[j] = a[j] + t * u[j];
181 double radius = sqrt(vtkMath::Distance2BetweenPoints(osculatingCenter,x1));
182 vtkIdType
id = outputPoints->InsertNextPoint(osculatingCenter);
183 outputVertices->InsertNextCell(1);
184 outputVertices->InsertCellPoint(
id);
185 labelArray->InsertNextValue(i);
186 radiusArray->InsertNextValue(radius);
189 double closestPoint[3], dist2;
190 vtkIdType sheetId, cellId;
192 cellLocator->FindClosestPoint(osculatingCenter,closestPoint,cellId,subId,dist2);
193 sheetId = voronoiSheetIdsArray->GetValue(cellId);
194 sheetIdsArray->InsertNextValue(sheetId);
195 streamlineSheetIdsArray->InsertValue(streamline->GetPointId(ip),sheetId);
209 output->DeepCopy(streamlines);
212 output->GetPointData()->AddArray(streamlineSheetIdsArray);
215 splineFilter->Delete();
216 outputPoints->Delete();
217 outputVertices->Delete();
218 labelArray->Delete();
219 radiusArray->Delete();
221 if (voronoiSheetIdsArray)
223 voronoiSheetIdsArray->Delete();
224 sheetIdsArray->Delete();
225 streamlineSheetIdsArray->Delete();
226 cellLocator->Delete();