[vtkusers] vtkPointRepresentation3D positioning

John O'Brien john.t.obrien at gmail.com
Fri Jun 16 04:53:11 EDT 2006


 Hello,

I've been using the vtkPointRepresentation3D class along with
vtkHandleWidget to place seeds within some volume data as follows:

void vtkSeedManager::AddSeed(double iq[3])
{
    double origin[3];
    this->ImageData->GetOrigin(origin);
    double spacing[3];
    this->ImageData->GetSpacing(spacing);

    /* data coords to world */
    int i;
    double q[3];
    for(i=0;i<3;i++){
        q[i] = iq[i]*spacing[i]+origin[i];
    }

    /* Create representation */
    vtkPointHandleRepresentation3D *rep =
vtkPointHandleRepresentation3D::New();
    rep->SetProperty(this->Property);
    rep->PlaceWidget(this->InitialBounds);

    rep->SetWorldPosition(q);
    rep->SetRenderer(this->CurrentRenderer);

    /* Create Handle */
    vtkHandleWidget *hw = vtkHandleWidget::New();
    hw->SetInteractor(this->Interactor);
    hw->SetRepresentation(rep);
    hw->On();
    this->Seeds->push_back(hw);

    if (this->Interactor) {
       this->Interactor->Render();
    }
}

This worked fine for VTK 5.1, but with the latest CVS copy it has
stopped working. I've temporarily fixed the problem by patching
vtkPointRepresentation3D.cxx with:

--- vtkPointHandleRepresentation3D.cxx       2006-06-15
15:33:03.060962792 +0100
+++ vtkPointHandleRepresentation3D.cxx  2006-06-15 16:11:50.479141448
+0100
@@ -372,13 +372,14 @@
     }
   radius = this->CurrentHandleSize*sqrt(radius);

-  double center[3], newBounds[6];
-  for (i=0; i<3; i++)
-    {
-    center[i] = (bounds[2*i] + bounds[2*i+1])/2.0;
-    newBounds[2*i] = center[i] - radius;
-    newBounds[2*i+1] = center[i] + radius;
-    }
+    double apt[3], newBounds[6];
+    this->GetWorldPosition(apt);
+    newBounds[0] = apt[0] - radius;
+    newBounds[1] = apt[0] + radius;
+    newBounds[2] = apt[1] - radius;
+    newBounds[3] = apt[1] + radius;
+    newBounds[4] = apt[2] - radius;
+    newBounds[5] = apt[2] + radius;
   this->Cursor3D->SetModelBounds(newBounds);
 }

However I'm not sure if this actually a problem with the class or if I'm
just incorrectly setting up the Widget placement.


Many Thanks,


John.



More information about the vtkusers mailing list