MCPcopy Create free account
hub / github.com/Kitware/VTK / ComputeBoundingSphere

Method ComputeBoundingSphere

Common/DataModel/vtkCell.cxx:157–285  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

155
156//------------------------------------------------------------------------------
157double vtkCell::ComputeBoundingSphere(double center[3]) const
158{
159 // We do easy cases first for number of points <= 4
160 switch (this->Points->GetNumberOfPoints())
161 {
162 case 0:
163 center[0] = std::numeric_limits<double>::quiet_NaN();
164 center[1] = std::numeric_limits<double>::quiet_NaN();
165 center[2] = std::numeric_limits<double>::quiet_NaN();
166 return std::numeric_limits<double>::quiet_NaN();
167 case 1:
168 this->Points->GetPoint(0, center);
169 return 0.0;
170 case 2:
171 {
172 auto points = vtk::DataArrayTupleRange(this->Points->GetData());
173 auto p0 = points[0], p1 = points[1];
174 center[0] = 0.5 * (p0[0] + p1[0]);
175 center[1] = 0.5 * (p0[1] + p1[1]);
176 center[2] = 0.5 * (p0[2] + p1[2]);
177 return vtkMath::Distance2BetweenPoints(center, p0);
178 }
179 case 3:
180 {
181 if (!vtkTriangle::ComputeCentroid(this->Points, nullptr, center))
182 {
183 break;
184 }
185 auto points = vtk::DataArrayTupleRange(this->Points->GetData());
186 return vtkMath::Distance2BetweenPoints(center, points[0]);
187 }
188 case 4:
189 {
190 if (!vtkTetra::ComputeCentroid(this->Points, nullptr, center))
191 {
192 break;
193 }
194 auto points = vtk::DataArrayTupleRange(this->Points->GetData());
195 return vtkMath::Distance2BetweenPoints(center, points[0]);
196 }
197 default:
198 break;
199 }
200
201 // For more complex cells, we follow Ritter's bounding sphere algorithm
202 // 1. Pick a point x (first point in our case) in the cell, and look for
203 // a point y the furthest from x.
204 // 2. Look for a point z the furthest from y.
205 // 3. Create a sphere centered at [z,y] with appropriate radius
206 // 4. Until all points are not in the sphere, take a point outside the sphere,
207 // and update the sphere to include former sphere + this point
208
209 auto points = vtk::DataArrayTupleRange(this->Points->GetData());
210 using ConstRefType = typename decltype(points)::ConstTupleReferenceType;
211
212 ConstRefType x = points[0];
213 vtkIdType yid = 1, zid = 0;
214

Callers 1

Calls 8

NormFunction · 0.70
NormalizeFunction · 0.70
sqrtFunction · 0.50
maxFunction · 0.50
GetNumberOfPointsMethod · 0.45
GetPointMethod · 0.45
GetDataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected