Compute bounding sphere

Hi everybody,

Can you help me to extract bounding sphere of my segment ?
I did it with bounding box but not with bounding sphere.
I use CT scan and segmentation

I’m new on Slicer it’s still difficult for me to understand all “3D-knowledges”


I don’t think bounding spheres is implemented in any of the libraries that are bundled with Slicer. We use directed bounding box instead, because it can be computed very quickly.

Why do you need a bounding sphere?

I just found this in vtkSphere Class Reference

function static void ComputeBoundingSphere (float *pts, vtkIdType numPts, float sphere[4], vtkIdType hints[2])

But I was in troubles with arguments to use it, and slicer-app crashes …

Do you know what is exactly the type of data required with argument 1 “Points” ?

I still have my segment :

n = getNode(‘Segmentation’)
s = n.GetSegmentation()
ssid = s.GetSegmentIdBySegmentName(‘mysegment’)
ss = s.GetSegment(ssid)
pd = ss.GetRepresentation(‘Closed surface’)

In fact I have a volume which looks like a half-sphere and I want to have the sphere center.
I can’t use the center of gravity here because the center of sphere and half-sphere is not same.

Thanks @lassoan

Thanks for the additional information. It is now clear that you need high-accuracy sphere fitting - this rules out most of the fast implementations (that only provide approximate results).

There are still many options how to approach this. Optimal method depends on what are the next steps and how much and what kind of interactions and manual processing do you plan to do.

Would you like to implement automatic sizing and positioning of hip implants? Do you plan to segment the femoral head or you would place points on the bone surface on a number of slices?


Thanks it’s ok for me for the function now.

I just try to analyze segments by myself for the moment.

I’m still in troubles with argument 4 “hints” now

I can’t use None for arg4 when I call the function, it’s said hints are required in error message

In code source I can see that an else condition can execute script without “hints”

void vtkSphereComputeBoundingSphere(T *pts, vtkIdType numPts, T sphere[4],
                                    vtkIdType hints[2])

  vtkIdType i;
  T *p, d1[3], d2[3];
  if ( hints )
  else //no hints provided, compute an initial guess
{ [...]

Normally without hints the function has to find the points that span the greatest distance on the x-y-z axes and define a sphere centered between the two points.

Can you help me ?

You can fit spheres using various calibration and registration methods that are already available in Slicer but it is not possible to recommend a good choice without knowing what specific input and constraints you have. So, it would be useful if you could tell us the big picture - what you would like to achieve - and we can help you to get you there. Also, most likely several people have done very similar things that you would like to do, so they can share their experience - what worked for them and what not.

For example, you can fit a generic sphere model using SlicerIGT extension. Create a sphere model using CreeateModel module then register it to another model’s points using SlicerIGT extension’s Model registration module, using Similarity method. The resulting transform gives you the sphere’s origin and relative scale to the input sphere model. This may or may not be the ideal method, depending on your end goal.