VMTK
Loading...
Searching...
No Matches
vtkvmtkStreamlineOsculatingCentersFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkStreamlineOsculatingCentersFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/07/17 09:53:14 $
7Version: $Revision: 1.6 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkInformation.h"
24#include "vtkInformationVector.h"
25#include "vtkObjectFactory.h"
26#include "vtkVersion.h"
27
28#include "vtkvmtkConstants.h"
29
30#include "vtkDoubleArray.h"
31#include "vtkPointData.h"
32#include "vtkCellData.h"
33#include "vtkMath.h"
34#include "vtkSplineFilter.h"
35#include "vtkCellLocator.h"
36#include "vtkCellArray.h"
37#include "vtkCell.h"
38
39
41
48
50{
51 if (this->VoronoiDiagram)
52 {
53 this->VoronoiDiagram->Delete();
54 this->VoronoiDiagram = NULL;
55 }
56 if (this->OsculatingCenters)
57 {
58 this->OsculatingCenters->Delete();
59 this->OsculatingCenters = NULL;
60 }
62 {
63 delete[] this->VoronoiSheetIdsArrayName;
64 this->VoronoiSheetIdsArrayName = NULL;
65 }
66}
67
69 vtkInformation *vtkNotUsed(request),
70 vtkInformationVector **inputVector,
71 vtkInformationVector *outputVector)
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
86 if (this->OsculatingCenters)
87 {
88 this->OsculatingCenters->Delete();
89 this->OsculatingCenters = NULL;
90 }
91
92 this->OsculatingCenters = vtkPolyData::New();
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;
108 if (this->VoronoiDiagram)
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();
118 sheetIdsArray->SetName(this->VoronoiSheetIdsArrayName);
119 cellLocator = vtkCellLocator::New();
120 cellLocator->SetDataSet(this->VoronoiDiagram);
121 cellLocator->BuildLocator();
122 streamlineSheetIdsArray = vtkIntArray::New();
123 streamlineSheetIdsArray->SetName(this->VoronoiSheetIdsArrayName);
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);
171 if (fabs(u_dot_x2_a) < VTK_VMTK_DOUBLE_TOL)
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);
187 if (this->VoronoiDiagram)
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
200 this->OsculatingCenters->SetPoints(outputPoints);
201 this->OsculatingCenters->SetVerts(outputVertices);
202 this->OsculatingCenters->GetPointData()->AddArray(labelArray);
203 this->OsculatingCenters->GetPointData()->AddArray(radiusArray);
204 if (sheetIdsArray)
205 {
206 this->OsculatingCenters->GetPointData()->AddArray(sheetIdsArray);
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}
231
232void vtkvmtkStreamlineOsculatingCentersFilter::PrintSelf(std::ostream& os, vtkIndent indent)
233{
234 this->Superclass::PrintSelf(os,indent);
235}
Compute the osculating (center-of-curvature) points of a set of streamlines.
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
#define VTK_VMTK_DOUBLE_TOL
vtkStandardNewMacro(vtkvmtkStreamlineOsculatingCentersFilter)