72{
73 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
74 vtkInformation *outInfo = outputVector->GetInformationObject(0);
75
76 vtkPolyData *input = vtkPolyData::SafeDownCast(
77 inInfo->Get(vtkDataObject::DATA_OBJECT()));
78 vtkPolyData *output = vtkPolyData::SafeDownCast(
79 outInfo->Get(vtkDataObject::DATA_OBJECT()));
80
81 if (input->GetNumberOfPoints() < 1)
82 {
83 return 1;
84 }
85
87 {
90 }
91
93
94 double resampleLength = 0.1;
95
96 vtkSplineFilter* splineFilter = vtkSplineFilter::New();
97 splineFilter->SetInputData(input);
98 splineFilter->SetSubdivideToLength();
99 splineFilter->SetLength(resampleLength);
100 splineFilter->Update();
101
102 vtkPolyData* streamlines = splineFilter->GetOutput();
103
104 vtkIntArray* voronoiSheetIdsArray = NULL;
105 vtkIntArray* sheetIdsArray = NULL;
106 vtkIntArray* streamlineSheetIdsArray = NULL;
107 vtkCellLocator* cellLocator = NULL;
109 {
110 if (!this->
VoronoiDiagram->GetCellData()->GetArray(this->VoronoiSheetIdsArrayName))
111 {
112 vtkErrorMacro(<< "VoronoiSheetIdsArray with name specified does not exist!");
113 return 1;
114 }
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());
125 }
126
127 int numberOfCells = streamlines->GetNumberOfCells();
128
129 vtkIntArray* labelArray = vtkIntArray::New();
130 labelArray->SetName("Label");
131
132 vtkDoubleArray* radiusArray = vtkDoubleArray::New();
133 radiusArray->SetName("Radius");
134
135 vtkPoints* outputPoints = vtkPoints::New();
136 vtkCellArray* outputVertices = vtkCellArray::New();
137
138 for (int i=0; i<numberOfCells; i++)
139 {
140 vtkCell* streamline = streamlines->GetCell(i);
141 int numberOfStreamlinePoints = streamline->GetNumberOfPoints();
142 for (int ip=1; ip<numberOfStreamlinePoints-1; ip++)
143 {
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);
148 double u[3], a[3];
149 for (int j=0; j<3; j++)
150 {
151 a[j] = 0.5 * (x1[j] + x0[j]);
152 }
153 double x2_x1[3], x1_x0[3];
154 double x2_a[3];
155 for (int j=0; j<3; j++)
156 {
157 x2_x1[j] = x2[j] - x1[j];
158 x1_x0[j] = x1[j] - x0[j];
159 x2_a[j] = x2[j] - a[j];
160 }
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++)
166 {
167 u[j] = (x2[j] - x1[j]) - (x1[j] - x0[j]) * (x2_x1_dot_x1_x0 / x2_x1_sq);
168 }
169 vtkMath::Normalize(u);
170 double u_dot_x2_a = vtkMath::Dot(u, x2_a);
172 {
173 continue;
174 }
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++)
178 {
179 osculatingCenter[j] = a[j] + t * u[j];
180 }
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);
188 {
189 double closestPoint[3], dist2;
190 vtkIdType sheetId, cellId;
191 int subId;
192 cellLocator->FindClosestPoint(osculatingCenter,closestPoint,cellId,subId,dist2);
193 sheetId = voronoiSheetIdsArray->GetValue(cellId);
194 sheetIdsArray->InsertNextValue(sheetId);
195 streamlineSheetIdsArray->InsertValue(streamline->GetPointId(ip),sheetId);
196 }
197 }
198 }
199
204 if (sheetIdsArray)
205 {
207 }
208
209 output->DeepCopy(streamlines);
210 if (sheetIdsArray)
211 {
212 output->GetPointData()->AddArray(streamlineSheetIdsArray);
213 }
214
215 splineFilter->Delete();
216 outputPoints->Delete();
217 outputVertices->Delete();
218 labelArray->Delete();
219 radiusArray->Delete();
220
221 if (voronoiSheetIdsArray)
222 {
223 voronoiSheetIdsArray->Delete();
224 sheetIdsArray->Delete();
225 streamlineSheetIdsArray->Delete();
226 cellLocator->Delete();
227 }
228
229 return 1;
230}
#define VTK_VMTK_DOUBLE_TOL