60{
61 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
62 vtkInformation *outInfo = outputVector->GetInformationObject(0);
63
64 vtkPolyData *input = vtkPolyData::SafeDownCast(
65 inInfo->Get(vtkDataObject::DATA_OBJECT()));
66 vtkPolyData *output = vtkPolyData::SafeDownCast(
67 outInfo->Get(vtkDataObject::DATA_OBJECT()));
68
70 {
71 vtkErrorMacro("Origin point id not specified");
72 return 1;
73 }
74
75 input->BuildCells();
76 input->BuildLinks();
77
78 vtkFloatArray* normals = vtkFloatArray::New();
79
80 if (input->GetPointData()->GetNormals())
81 {
82 normals->DeepCopy(input->GetPointData()->GetNormals());
83 }
84 else
85 {
86 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
87 normalsFilter->SetInputData(input);
88 normalsFilter->AutoOrientNormalsOn();
89 normalsFilter->FlipNormalsOn();
90 normalsFilter->ConsistencyOn();
91 normalsFilter->ComputeCellNormalsOff();
92 normalsFilter->SplittingOff();
93 normalsFilter->Update();
94
95 normals->DeepCopy(normalsFilter->GetOutput()->GetPointData()->GetNormals());
96
97 normalsFilter->Delete();
98 }
99
100 vtkPointLocator* locator = vtkPointLocator::New();
101 locator->SetDataSet(input);
102 locator->BuildLocator();
103
104 vtkIdTypeArray* connectivityArray = vtkIdTypeArray::New();
106 {
107 vtkPolyDataConnectivityFilter* connectivityFilter = vtkPolyDataConnectivityFilter::New();
108 connectivityFilter->SetInputData(input);
109 connectivityFilter->SetExtractionModeToAllRegions();
110 connectivityFilter->ColorRegionsOn();
111 connectivityFilter->Update();
112
113 connectivityArray->DeepCopy(connectivityFilter->GetOutput()->GetPointData()->GetScalars());
114 connectivityFilter->Delete();
115 }
116
117 vtkIdType npts, *cells;
118 vtkIdType ncells;
119
121
122 double averageLength = 0.0;
123
124 for (vtkIdType i=0; i<ncells; i++)
125 {
126 averageLength += sqrt(input->GetCell(cells[i])->GetLength2());
127 }
128 averageLength /= ncells;
129
130 double radiusStep = averageLength;
131
132 double direction[3];
133 double normal0[3], normal1[3];
134
137
138 vtkIdType regionId = -1;
140 {
142 }
143
144 vtkIdList* pointIdsWithinRadius = vtkIdList::New();
145
146 bool doneOnce = false;
147
148
149
150 for (int k=0; k<100; k++)
151 {
152 pointIdsWithinRadius->Initialize();
153
154 double radius = k * radiusStep;
155 locator->FindPointsWithinRadius(radius,this->
Origin,pointIdsWithinRadius);
156
157 vtkIdType numberOfIds = pointIdsWithinRadius->GetNumberOfIds();
158
159 vtkIdType neighborhoodSize = numberOfIds;
160
162 {
163 for (vtkIdType i=0; i<numberOfIds; i++)
164 {
165 vtkIdType id = pointIdsWithinRadius->GetId(i);
166 if (connectivityArray->GetValue(id) == regionId)
167 {
168 neighborhoodSize += 1;
169 }
170 }
171 }
172
174 {
175 continue;
176 }
177
178 double kdirection[3];
179 kdirection[0] = kdirection[1] = kdirection[2] = 0.0;
180
181 bool done = false;
182
183 for (vtkIdType i=0; i<numberOfIds; i++)
184 {
185 vtkIdType id = pointIdsWithinRadius->GetId(i);
186
187 if (this->
UseConnectivity && connectivityArray->GetValue(
id) != regionId)
188 {
189 continue;
190 }
191
192 normals->GetTuple(id,normal0);
193
194 double dot = vtkMath::Dot(normal0,normal1);
195
196 if (fabs(dot) > 0.6) {
197 continue;
198 }
199
200 if (dot < -0.5 && doneOnce) {
201 done = true;
202 break;
203 }
204
205 double cross[3];
206 vtkMath::Cross(normal0,normal1,cross);
207
208 if (vtkMath::Dot(kdirection,cross) < 0.0) {
209 cross[0] *= -1.0;
210 cross[1] *= -1.0;
211 cross[2] *= -1.0;
212 }
213
214 kdirection[0] += cross[0];
215 kdirection[1] += cross[1];
216 kdirection[2] += cross[2];
217 doneOnce = true;
218 }
219
220 if (!doneOnce)
221 {
222 continue;
223 }
224
225 vtkMath::Normalize(kdirection);
226
227 if (done)
228 {
229 break;
230 }
231
232 this->
Normal[0] = kdirection[0];
233 this->
Normal[1] = kdirection[1];
234 this->
Normal[2] = kdirection[2];
235 }
236
237 vtkMath::Normalize(this->
Normal);
238
239 normals->Delete();
240 locator->Delete();
241 pointIdsWithinRadius->Delete();
242 connectivityArray->Delete();
243
244 return 1;
245}