Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vtkSmartPointer with Android

Just what may be a simple question but, while looking at the code for all the examples on Android, I noticed that vtkSmartPointer<> are not used at all in the examples. Is there any particular reason for that? I kind of got used to using them now and I was wondering if their use might lead to some issues or not?

For instance this is the struct used in VolumeRenderer:

struct userData
{
  vtkRenderWindow *RenderWindow;
  vtkRenderer *Renderer;
  vtkAndroidRenderWindowInteractor *Interactor;
};

I just tried to re-implement this example using only smartpointers and I'm not running into any issue so far but I was wondering if that was a good idea or not. So this is what I have for the exact same structure:

struct userData
{
  vtkSmartPointer<vtkRenderWindow> RenderWindow;
  vtkSmartPointer<vtkRenderer> Renderer;
  vtkSmartPointer<vtkAndroidRenderWindowInteractor> Interactor;
};

Thanks in advance.

like image 418
LBes Avatar asked Apr 25 '26 22:04

LBes


2 Answers

There should be no issue at all in using vtkNew and/or vtkSmartPointer in your Android (or iOS) applications. In this case vtkNew looks more appropriate and maintains strong ownership, if you need to set these members externally for some reason then vtkSmartPointer would be the way to go.

For more information on which pointer class is appropriate I would recommend taking a look at this Source article

like image 124
Marcus D. Hanwell Avatar answered Apr 27 '26 13:04

Marcus D. Hanwell


It mostly depends on the use-case of userData. Using vtkSmartPointer will increment the ref counter and therefore as long as userData is valid, you will have the other pointers valid too. However, in this case, you are storing references to render window objects which could go away because of some external event in that case you want to consider using vtkWeakPointer.

like image 21
Aashish Avatar answered Apr 27 '26 14:04

Aashish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!