Gib Bogle
2018-11-30 18:12:14 UTC
I am sequentially rendering a scene composed of an increasing number of actors, each of which is a clipped and capped cone (to be precise, each member of the scene is made up of two actors - the clipped cone and the cap). I am not sure about the right way to remove the actors and free the associated memory when the time comes. The list of things created with New() for each composite actor is quite long (the code is based on the CapClip example.):
coneSource = vtkSmartPointer<vtkConeSource>::New();
plane = vtkSmartPointer<vtkPlane>::New();
clipMapper = vtkSmartPointer<vtkDataSetMapper>::New();
clipActor = vtkSmartPointer<vtkActor>::New();
boundaryEdges = vtkSmartPointer<vtkFeatureEdges>::New();
boundaryStrips = vtkSmartPointer<vtkStripper>::New();
boundaryPoly = vtkSmartPointer<vtkPolyData>::New();
boundaryMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
boundaryActor = vtkSmartPointer<vtkActor>::New();
My proposed approach is to use a struct to hold all the vtkSmartPointers, creating a new ACTOR_STRUCT (stored in an array or list) every time a composite actor is created:
struct actor_struct {
vtkSmartPointer<vtkConeSource> coneSource;
vtkSmartPointer<vtkPlane> plane;
vtkSmartPointer<vtkClipPolyData> clipper;
vtkSmartPointer<vtkDataSetMapper> clipMapper;
vtkSmartPointer<vtkActor> clipActor;
vtkSmartPointer<vtkFeatureEdges> boundaryEdges;
vtkSmartPointer<vtkStripper> boundaryStrips;
vtkSmartPointer<vtkPolyData> boundaryPoly;
vtkSmartPointer<vtkPolyDataMapper> boundaryMapper;
vtkSmartPointer<vtkActor> boundaryActor;
};
typedef actor_struct ACTOR_STRUCT;
The motivation is to be able to locate all the allocated objects when memory needs to be freed, but I suspect it is neither the conventional nor the best way. I have two questions:
What is the usual way to handle this situation?
If my proposed method is OK, how should all the actor memory be freed?
I'd be grateful if somebody with a better understanding of VTK and C++ could advise me.
Thanks
Gib
coneSource = vtkSmartPointer<vtkConeSource>::New();
plane = vtkSmartPointer<vtkPlane>::New();
clipMapper = vtkSmartPointer<vtkDataSetMapper>::New();
clipActor = vtkSmartPointer<vtkActor>::New();
boundaryEdges = vtkSmartPointer<vtkFeatureEdges>::New();
boundaryStrips = vtkSmartPointer<vtkStripper>::New();
boundaryPoly = vtkSmartPointer<vtkPolyData>::New();
boundaryMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
boundaryActor = vtkSmartPointer<vtkActor>::New();
My proposed approach is to use a struct to hold all the vtkSmartPointers, creating a new ACTOR_STRUCT (stored in an array or list) every time a composite actor is created:
struct actor_struct {
vtkSmartPointer<vtkConeSource> coneSource;
vtkSmartPointer<vtkPlane> plane;
vtkSmartPointer<vtkClipPolyData> clipper;
vtkSmartPointer<vtkDataSetMapper> clipMapper;
vtkSmartPointer<vtkActor> clipActor;
vtkSmartPointer<vtkFeatureEdges> boundaryEdges;
vtkSmartPointer<vtkStripper> boundaryStrips;
vtkSmartPointer<vtkPolyData> boundaryPoly;
vtkSmartPointer<vtkPolyDataMapper> boundaryMapper;
vtkSmartPointer<vtkActor> boundaryActor;
};
typedef actor_struct ACTOR_STRUCT;
The motivation is to be able to locate all the allocated objects when memory needs to be freed, but I suspect it is neither the conventional nor the best way. I have two questions:
What is the usual way to handle this situation?
If my proposed method is OK, how should all the actor memory be freed?
I'd be grateful if somebody with a better understanding of VTK and C++ could advise me.
Thanks
Gib