76 double polyballFunctionValue, minPolyBallFunctionValue;
77 double point0[3], point1[3];
78 double radius0, radius1;
79 double vector0[4], vector1[4], closestPoint[4];
82 vtkDataArray *polyballRadiusArray = NULL;
86 vtkErrorMacro(<<
"No Input specified!");
90 if (this->
Input->GetNumberOfPoints()==0)
92 vtkWarningMacro(<<
"Empty Input specified!");
100 vtkErrorMacro(<<
"No PolyBallRadiusArrayName specified!");
106 if (polyballRadiusArray==NULL)
108 vtkErrorMacro(<<
"PolyBallRadiusArray with name specified does not exist!");
113 if (this->
Input->GetLines()==NULL)
115 vtkWarningMacro(<<
"No lines in Input dataset.");
119 this->
Input->BuildCells();
123 closestPoint[0] = closestPoint[1] = closestPoint[2] = closestPoint[2] = 0.0;
131 vtkIdList* cellIds = vtkIdList::New();
143 cellIds->SetNumberOfIds(this->
Input->GetNumberOfCells());
144 for (k=0; k<this->
Input->GetNumberOfCells(); k++)
150 for (k=0; k<cellIds->GetNumberOfIds(); k++)
152 vtkIdType cellId = cellIds->GetId(k);
154 if (this->
Input->GetCellType(cellId)!=VTK_LINE && this->Input->GetCellType(cellId)!=VTK_POLY_LINE)
159 this->
Input->GetCellPoints(cellId,npts,pts);
161 for (i=0; i<npts-1; i++)
163 this->
Input->GetPoint(pts[i],point0);
164 this->
Input->GetPoint(pts[i+1],point1);
167 radius0 = polyballRadiusArray->GetComponent(pts[i],0);
168 radius1 = polyballRadiusArray->GetComponent(pts[i+1],0);
175 vector0[0] = point1[0] - point0[0];
176 vector0[1] = point1[1] - point0[1];
177 vector0[2] = point1[2] - point0[2];
178 vector0[3] = radius1 - radius0;
179 vector1[0] = x[0] - point0[0];
180 vector1[1] = x[1] - point0[1];
181 vector1[2] = x[2] - point0[2];
182 vector1[3] = 0.0 - radius0;
199 closestPoint[0] = point0[0];
200 closestPoint[1] = point0[1];
201 closestPoint[2] = point0[2];
202 closestPoint[3] = radius0;
207 closestPoint[0] = point1[0];
208 closestPoint[1] = point1[1];
209 closestPoint[2] = point1[2];
210 closestPoint[3] = radius1;
214 closestPoint[0] = point0[0] + t * vector0[0];
215 closestPoint[1] = point0[1] + t * vector0[1];
216 closestPoint[2] = point0[2] + t * vector0[2];
217 closestPoint[3] = radius0 + t * vector0[3];
220 polyballFunctionValue = (x[0]-closestPoint[0])*(x[0]-closestPoint[0]) + (x[1]-closestPoint[1])*(x[1]-closestPoint[1]) + (x[2]-closestPoint[2])*(x[2]-closestPoint[2]) - closestPoint[3]*closestPoint[3];
222 if (polyballFunctionValue<minPolyBallFunctionValue)
224 minPolyBallFunctionValue = polyballFunctionValue;
238 return minPolyBallFunctionValue;