Hi, I’m a beginner of VTK. I faced an special issue about vtkNew
and vtkSmartPointer
I have such code:
#include <vtkNIFTIImageReader.h>
#include <vtkNIFTIImageWriter.h>
#include <vtkCamera.h>
#include <vtkImageActor.h>
#include <vtkActor2D.h>
#include <vtkImageButterworthHighPass.h>
#include <vtkImageExtractComponents.h>
#include <vtkImageFFT.h>
#include <vtkImageIdealHighPass.h>
#include <vtkImageMapToWindowLevelColors.h>
#include <vtkImageMapper3D.h>
#include <vtkImageProperty.h>
#include <vtkImageRFFT.h>
#include <vtkImageReader2.h>
#include <vtkImageReader2Factory.h>
#include <vtkInteractorStyleImage.h>
#include <vtkNamedColors.h>
#include <vtkImageData.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkProp.h>
{
...
vtkSmartPointer < vtkNIFTIImageReader > NiftReader = vtkSmartPointer < vtkNIFTIImageReader > ::New() ;
NiftReader->SetFileName ( argv[1] ) ;
vtkNew<vtkImageActor> butterworthActor;
butterworthActor->GetMapper()->SetInputConnection(NiftReader->GetOutputPort());
butterworthActor->GetProperty()->SetInterpolationTypeToNearest();
vtkNew<vtkRenderer> butterworthRenderer;
butterworthRenderer->AddActor(butterworthActor); // wrong here
...
}
I am using vtkNew
now. But I got some error:
/home/zhaoz22/Desktop/FINAL/src/Butterworth.cxx: In function ‘int main(int, char**)’:
/home/zhaoz22/Desktop/FINAL/src/Butterworth.cxx:60:33: error: cannot convert ‘vtkNew<vtkImageActor>’ to ‘vtkProp*’
60 | butterworthRenderer->AddActor(butterworthActor);
| ^~~~~~~~~~~~~~~~
| |
| vtkNew<vtkImageActor>
In file included from /home/zhaoz22/Desktop/FINAL/src/Butterworth.cxx:22:
/usr/include/vtk-6.3/vtkRenderer.h:68:26: note: initializing argument 1 of ‘void vtkRenderer::AddActor(vtkProp*)’
68 | void AddActor(vtkProp *p);
| ~~~~~~~~~^
make[2]: *** [CMakeFiles/Butterworth.dir/build.make:63: CMakeFiles/Butterworth.dir/Butterworth.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/Butterworth.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
After I change those two vtkNew
to vtkSmartPointer
, it works fine like this:
vtkSmartPointer < vtkImageActor > butterworthActor = vtkSmartPointer < vtkImageActor > ::New() ;
vtkSmartPointer < vtkRenderer > butterworthRenderer = vtkSmartPointer < vtkRenderer > ::New() ;
Is there any reason for this?
Thanks!