[vtkusers] vtk smart pointer

ran kor1581 at gmail.com
Fri Nov 24 05:35:32 EST 2017


I have few doubts about vtk smart pointers usage, as in case of different
scenarios explained below

Scenario1:

For example if I have two class Red and Blue with following structure

Class Red
{
Public:
	Red(){}
SetVTKtem(vtkSmartPointer<vtkType>  ptrParam)
{
	ptr  =  ptrParam
}	
private:
	vtkSmartPointer<vtkType> ptr  ;
};

Class Blue
{
Public:
    	Blue ()
   	{
       		ptr1   = vtkSmartPointer< vtkType >::New();
ptr2   = vtkSmartPointer< vtkType >::New();
   	}
	vtkSmartPointer<vtkType> GetPtr1()
{
	return ptr1 ;
}
	vtkSmartPointer<vtkType> GetPtr2()
{
	return ptr2 ;
}
  private:
	vtkSmartPointer<vtkType> ptr1  ;
vtkSmartPointer<vtkType> ptr2  ;
};

Then in main method,

void main()
{
Blue *objBlue = new Blue ;
Red * objRed =  new Red;

//In a series of events in main, will set prt1, ptr2, ptr3 in objBlue to ptr
in objRed

//in first event, set

objRed ->SetVTKtem(objBlue -> GetPtr1());

// second event, set
objRed ->SetVTKtem(objBlue -> GetPtr2());


// in third event, again will set 
objRed ->SetVTKtem(objBlue -> GetPtr1());


//Then if  delete objBlue, what happens to the object vtk objects pointed 
by ptr1, ptr2, ptr3.

delete objBlue;
}
Then
1)	After calling, 
objRed ->SetVTKtem(objBlue -> GetPtr2());
will reference of ptr1 of objBlue decrement to one?
will reference of ptr of objRed decrement to one?

2)	After deleting objBlue, what happens to the object vtk objects pointed 
by ptr1, ptr2, ptr3? 
Will there reference be zero?


Scenario2:

I have another doubt,
 is it safe to call vtkSmartPointer and vtkNew pointers in local variable to
functions which calling recursively? 
For example

Class Yellow
{
public:
function()
{
		vtkNew<vtkType1> ptrType1  = vtkSmartPointer< vtkType1>::New();
}
};	


Then in main method,
void main()
{
Yellow objYellow = new Yellow;
//Then in a series of events

//In first event
	objYellow-> function();
//In second event
objYellow-> function();
..
}

After second call to function(), will object pointed by ptrType1  in first
call be function be deleted?

Scenario3:
Another doubt is if,

Class Red
{
Public:
	Red(){}
SetVTKtem(vtkSmartPointer<vtkType>  ptrParam)
{
	ptr  =  ptrParam
}	
private:
	vtkSmartPointer<vtkType> ptr  ;
};

Class Blue
{
Public:
	vtkSmartPointer<vtkType> GetPtr1()
{
	return ptr1.GetPointer() ;
}
  private:
	vtkNew<vtkType> ptr1  ;
};


Then in main function,

void main()
{
Blue *objBlue = new Blue ;
Red * objRed =  new Red;

//In a series of events in main, will set prt1, ptr2, ptr3 in objBlue to ptr
in objRed

//in first event, set





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list