150{
151 int numberOfPoints = input->GetNumberOfPoints();
152
153 parallelTransportNormalsArray->SetNumberOfTuples(numberOfPoints);
154 parallelTransportNormalsArray->FillComponent(0,0.0);
155
156 int numberOfCells = input->GetNumberOfCells();
157 int numberOfPointsInCell;
158
159 vtkTransform* transform = vtkTransform::New();
160
161 vtkIdType id0, id1, id2;
162 double p0[3], p1[3], p2[3];
163
164 double t0[3], t1[3], v[3];
165 double dot, theta;
166 double n0[3], n1[3];
167
168 id2 = -1;
169
170 for (int k=0; k<numberOfCells; k++)
171 {
172 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(input->GetCell(k));
173
174 if (!polyLine)
175 {
176 continue;
177 }
178
179 numberOfPointsInCell = polyLine->GetNumberOfPoints();
180
181 if (numberOfPointsInCell < 2)
182 {
183 continue;
184 }
185
186 t0[0] = t0[1] = t0[2] = 0.0;
187
188 id0 = polyLine->GetPointId(0);
189 input->GetPoint(id0,p0);
190
191 vtkIdType nextId = 1;
193 {
194 id1 = polyLine->GetPointId(nextId);
195 input->GetPoint(id1,p1);
196
197 t0[0] = p1[0] - p0[0];
198 t0[1] = p1[1] - p0[1];
199 t0[2] = p1[2] - p0[2];
200
201 ++nextId;
202 }
203
204 vtkMath::Normalize(t0);
205
206 double dummy[3];
207 vtkMath::Perpendiculars(t0,n0,dummy,0.0);
208
209 parallelTransportNormalsArray->SetTuple(id0,n0);
210
211 for (int i=1; i<numberOfPointsInCell-1; i++)
212 {
213 id0 = polyLine->GetPointId(i-1);
214 id1 = polyLine->GetPointId(i);
215 id2 = polyLine->GetPointId(i+1);
216 input->GetPoint(id0,p0);
217 input->GetPoint(id1,p1);
218 input->GetPoint(id2,p2);
219
220 t0[0] = p1[0] - p0[0];
221 t0[1] = p1[1] - p0[1];
222 t0[2] = p1[2] - p0[2];
223
224 t1[0] = p2[0] - p1[0];
225 t1[1] = p2[1] - p1[1];
226 t1[2] = p2[2] - p1[2];
227
228 vtkMath::Normalize(t0);
229 vtkMath::Normalize(t1);
230
231 dot = vtkMath::Dot(t0,t1);
232
234 {
235 theta = 0.0;
236 }
237 else
238 {
239 theta = acos(dot) * 180.0 / vtkMath::Pi();
240 }
241
242 vtkMath::Cross(t0,t1,v);
243
244 transform->Identity();
245 transform->RotateWXYZ(theta,v);
246 transform->TransformPoint(n0,n1);
247
248 dot = vtkMath::Dot(t1,n1);
249 n1[0] -= dot * t1[0];
250 n1[1] -= dot * t1[1];
251 n1[2] -= dot * t1[2];
252
253 vtkMath::Normalize(n1);
254
255 parallelTransportNormalsArray->SetTuple(id1,n1);
256
257 n0[0] = n1[0];
258 n0[1] = n1[1];
259 n0[2] = n1[2];
260 }
261
262 parallelTransportNormalsArray->SetTuple(id2,n1);
263 }
264
265 transform->Delete();
266}
#define VTK_VMTK_DOUBLE_TOL