[vtk-developers] vtkSeedWidget - seeds disappear

Bill Lorensen bill.lorensen at gmail.com
Tue Aug 10 12:30:42 EDT 2010


This is an argument not to use macros. One can easily forget what is
hidden inside. Certainly for vtkSmartPointer, saving a few keystrokes
may not be worth it. Yes, you still need to understand smart pointers,
but this macro and others I have seen to save stkoes with
vtkSmartPointer's, can add further confusion.

Just my opinion,

Bill

On Tue, Aug 10, 2010 at 12:25 PM, Daniel Haehn <haehn at bwh.harvard.edu> wrote:
> Hi jc,
>
> This makes sense! Thank you so much!
>
> Daniel
>
> Jean-Christophe Fillion-Robin <jchris.fillionr at kitware.com> wrote:
>
>>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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>



More information about the vtk-developers mailing list