[vtk-developers] Failed to locate vtkImageActor to the center of outline

XiongXiang Zhang zhangxx110 at 126.com
Wed Nov 14 20:40:38 EST 2012


Hi,
We try to locate a instance of vtkImageActor at the center of a cube, but not at the correct location.Our code as the
following:
 
//instance  OutlineFilter, imagedata is type of vtkImageData
 vtkSmartPointer<vtkOutlineFilter> outlineData = vtkSmartPointer<vtkOutlineFilter>::New();
  outlineData->SetInput(imagedata);
  outlineData->Update();

  vtkSmartPointer<vtkPolyDataMapper> mapOutline =vtkSmartPointer<vtkPolyDataMapper>::New();
  mapOutline->SetInputConnection(outlineData->GetOutputPort());

  vtkSmartPointer<vtkActor> outline = vtkSmartPointer<vtkActor>::New();
  outline->SetMapper(mapOutline);
  outline->GetProperty()->SetColor(0,0,0);

  ren->AddActor(outline);
 
//get the center of the outline
 outline->GetBounds(bounds);
   width[0]=bounds[1]-bounds[0];
   width[1]=bounds[3]-bounds[2];
   width[2]=bounds[5]-bounds[4];
   center[0]=bounds[0]+width[0]*0.5;
   center[1]=bounds[2]+width[1]*0.5;
   center[2]=bounds[4]+width[2]*0.5;
 
//instance vtkImageMapToColors
vtkSmartPointer<vtkImageMapToColors> axialColors = vtkSmartPointer<vtkImageMapToColors>::New();
  axialColors->SetInput(imagedata);
  axialColors->Update();
 
//add axialColors to ImageActor
  vtkSmartPointer<vtkImageActor> axial =vtkSmartPointer<vtkImageActor>::New();
  axial->SetInput(axialColors->GetOutput());
  axial->SetDisplayExtent(bounds[0],bounds[1], bounds[2],bounds[3],center[2],center[2]);//the center of Z axis
 
We use the method of "vtkImageActor::SetDisplayExtent" to locate the imageactor at the center of the outline, but
it not at the center. The result shown in the attached image "result.png". We don't modify the coordinate system
(all  are default). How could we solve this problem.
The version of VTK is 5.10.0, which is compiled from source, our systerm is Windows XP (SP3).
Thanks!
 
XiongXiang Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20121115/176e7446/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: result.png
Type: image/png
Size: 58676 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20121115/176e7446/attachment-0001.png>


More information about the vtk-developers mailing list