[vtk-developers] vtkSeedWidget - seeds disappear
Jean-Christophe Fillion-Robin
jchris.fillionr at kitware.com
Tue Aug 10 12:20:08 EDT 2010
Hi Daniel,
Using the macro VTK_CREATE(vtkClass, var) means:
vtkSmartPointer<vtkClass> var = vtkSmartPointer<vtkClass>::New()
It's also important to understand the smartpointer object will go out of
scope when the function PlaceSeed seed returns. Assuming the created object
isn't referenced somewhere else, it will be deleted !
Just make sure you keep a reference of your object ...
Thks
Jc
On Tue, Aug 10, 2010 at 11:55 AM, Daniel Haehn <haehn at bwh.harvard.edu>wrote:
> Hi,
>
> I try to use the vtkSeedWidget in a displayableManager of Slicer4 with the
> following code:
>
>
> // Create vtkSeedWidget with display coordinates and directly add one seed
> void vtkMRMLAnnotationDisplayableManager::PlaceSeed(double x, double y)
> {
> std::cout << "PlaceSeed" << x << ":" << y << std::endl;
>
> VTK_CREATE(vtkSphereHandleRepresentation, handle);
> handle->GetProperty()->SetColor(1,0,0);
> handle->SetHandleSize(5);
>
> VTK_CREATE(vtkSeedRepresentation, rep);
> rep->SetHandleRepresentation(handle);
>
> //seed widget
> VTK_CREATE(vtkSeedWidget, seedWidget);
> //seedWidget->CreateDefaultRepresentation();
> seedWidget->SetRepresentation(rep);
>
> seedWidget->SetInteractor(this->GetInteractor());
> seedWidget->SetCurrentRenderer(this->GetRenderer());
>
> double p[3];
> p[0]=x;
> p[1]=y;
> p[2]=0;
> //seedWidget->ProcessEventsOff();
>
> vtkHandleWidget* newhandle = seedWidget->CreateNewHandle();
>
>
> vtkHandleRepresentation::SafeDownCast(newhandle->GetRepresentation())->SetDisplayPosition(p);
>
>
> //this->GetRenderer()->AddActor(newhandle->GetRepresentation());
>
> //this->RequestRender();
>
> seedWidget->On();
>
> }
>
>
> I tried different scenarios (see comments) but with the code above the
> small sphereHandles appear shortly and then directly disappear again.
>
> If I add the vtkHandleRepresentation as an actor to the renderer, the
> sphereHandles appear until I rotate or zoom the 3D Render Window.
>
> What am I doing wrong? As a side note: it does not make a difference if I
> call RequestRender() or not. I don't know if I might be using VTK wrong or
> if there is a problem in combination with the displayableManager.
>
>
> Thank you so much!!
>
> Daniel
--
Phone: 1-518-836-2174
Ext: 304
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100810/3fc69487/attachment.html>
More information about the vtk-developers
mailing list