[vtkusers] How to get the center of vtkboxwwidget

David Doria daviddoria+vtk at gmail.com
Sat Aug 7 12:25:20 EDT 2010


On Sat, Aug 7, 2010 at 12:08 PM, Ali Habib <ali.mahmoud.habib at gmail.com> wrote:
> I have vtkpolydata that I want to transer I want to make box of them have
> the same origin
>
> How to get the origin of the vtkboxwidget , and the vtkpolydata please
>
> Best regards

Here is a way to get the "center" of the polydata:

void CenterOfMass(vtkPoints* points, double* center)
{
  center[0] = 0.0;
  center[1] = 0.0;
  center[2] = 0.0;

  for(vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
  {
    double point[3];
    points->GetPoint(i, point);

    center[0] += point[0];
    center[1] += point[1];
    center[2] += point[2];
  }

  double numberOfPoints = static_cast<double>(points->GetNumberOfPoints());
  center[0] = center[0]/numberOfPoints;
  center[1] = center[1]/numberOfPoints;
  center[2] = center[2]/numberOfPoints;
}

You could also do something based on this:
http://www.vtk.org/Wiki/VTK/Examples/PolyData/DataBounds

As for the box widget, you'll need to do this:

vtkSmartPointer<vtkPolyData> pd =
  vtkSmartPointer<vtkPolyData>::New();
      static_cast<vtkBoxRepresentation*>(boxWidget->GetRepresentation())->GetPolyData
(polydata);

      double center[3];
      polydata->GetPoint(14,center);

I've updated this example with a description (based on this:
http://www.vtk.org/doc/nightly/html/classvtkBoxRepresentation.html#a8acd87bde00ca86f677bde81c9e7d6ef)

Good luck!

David



More information about the vtkusers mailing list