编译一程序,出现如下错误:
main.cpp(51) : error C2664: 'void __thiscall vtkVolumeMapper::SetInput(class vtkImageData *)' : cannot convert parameter 1 from 'class vtkStructuredPoints *' to 'class vtkImageData *'
vtkStructuredPoints是vtkImageData的子类,为何会有上述错误?原来是没有“#include "vtkStructuredPoints.h"(子类的头文件)”。因为没有这个头文件,编译器根本不知道这两个类之间有继承关系。
#include
"
vtkActor.h
"
#include " vtkRenderWindow.h "
#include " vtkRenderer.h "
#include " vtkRenderWindowInteractor.h "
#include " vtkProperty.h "
#include " vtkStructuredPointsReader.h "
#include " vtkStructuredPoints.h " // 没有这一行就会出现上述错误
#include " vtkPiecewiseFunction.h "
#include " vtkColorTransferFunction.h "
#include " vtkVolumeProperty.h "
#include " vtkVolumeRayCastCompositeFunction.h "
#include " vtkVolumeRayCastMapper.h "
#include " vtkVolume.h "
void main ()
{
vtkRenderer * ren = vtkRenderer::New();
vtkRenderWindow * renWin = vtkRenderWindow::New();
renWin -> AddRenderer(ren);
vtkRenderWindowInteractor * iren = vtkRenderWindowInteractor::New();
iren -> SetRenderWindow(renWin);
vtkStructuredPointsReader * reader = vtkStructuredPointsReader::New();
reader -> SetFileName( " ./Data/ironProt.vtk " );
vtkPiecewiseFunction * opacityTransferFunction =
vtkPiecewiseFunction::New();
opacityTransferFunction -> AddPoint( 20 , 0.0 );
opacityTransferFunction -> AddPoint( 255 , 0.2 );
vtkColorTransferFunction * colorTransferFunction =
vtkColorTransferFunction::New();
colorTransferFunction -> AddRGBPoint( 0.0 , 0.0 , 0.0 , 0.0 );
colorTransferFunction -> AddRGBPoint( 64.0 , 1.0 , 0.0 , 0.0 );
colorTransferFunction -> AddRGBPoint( 128.0 , 0.0 , 0.0 , 1.0 );
colorTransferFunction -> AddRGBPoint( 192.0 , 0.0 , 1.0 , 0.0 );
colorTransferFunction -> AddRGBPoint( 255.0 , 0.0 , 0.2 , 0.0 );
vtkVolumeProperty * volumeProperty = vtkVolumeProperty::New();
volumeProperty -> SetColor(colorTransferFunction);
volumeProperty -> SetScalarOpacity(opacityTransferFunction);
volumeProperty -> ShadeOn();
volumeProperty -> SetInterpolationTypeToLinear();
vtkVolumeRayCastCompositeFunction * compositeFunction =
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper * volumeMapper =
vtkVolumeRayCastMapper::New();
volumeMapper -> SetVolumeRayCastFunction(compositeFunction);
// volumeMapper->SetInputConnection(reader->GetOutputPort());
volumeMapper -> SetInput(reader -> GetOutput());
vtkVolume * volume = vtkVolume::New();
volume -> SetMapper(volumeMapper);
volume -> SetProperty(volumeProperty);
ren -> AddVolume(volume);
ren -> SetBackground( 1 , 1 , 1 );
renWin -> SetSize( 600 , 600 );
renWin -> Render();
iren -> Initialize();
renWin -> Render();
iren -> Start();
}
#include " vtkRenderWindow.h "
#include " vtkRenderer.h "
#include " vtkRenderWindowInteractor.h "
#include " vtkProperty.h "
#include " vtkStructuredPointsReader.h "
#include " vtkStructuredPoints.h " // 没有这一行就会出现上述错误
#include " vtkPiecewiseFunction.h "
#include " vtkColorTransferFunction.h "
#include " vtkVolumeProperty.h "
#include " vtkVolumeRayCastCompositeFunction.h "
#include " vtkVolumeRayCastMapper.h "
#include " vtkVolume.h "
void main ()
{
vtkRenderer * ren = vtkRenderer::New();
vtkRenderWindow * renWin = vtkRenderWindow::New();
renWin -> AddRenderer(ren);
vtkRenderWindowInteractor * iren = vtkRenderWindowInteractor::New();
iren -> SetRenderWindow(renWin);
vtkStructuredPointsReader * reader = vtkStructuredPointsReader::New();
reader -> SetFileName( " ./Data/ironProt.vtk " );
vtkPiecewiseFunction * opacityTransferFunction =
vtkPiecewiseFunction::New();
opacityTransferFunction -> AddPoint( 20 , 0.0 );
opacityTransferFunction -> AddPoint( 255 , 0.2 );
vtkColorTransferFunction * colorTransferFunction =
vtkColorTransferFunction::New();
colorTransferFunction -> AddRGBPoint( 0.0 , 0.0 , 0.0 , 0.0 );
colorTransferFunction -> AddRGBPoint( 64.0 , 1.0 , 0.0 , 0.0 );
colorTransferFunction -> AddRGBPoint( 128.0 , 0.0 , 0.0 , 1.0 );
colorTransferFunction -> AddRGBPoint( 192.0 , 0.0 , 1.0 , 0.0 );
colorTransferFunction -> AddRGBPoint( 255.0 , 0.0 , 0.2 , 0.0 );
vtkVolumeProperty * volumeProperty = vtkVolumeProperty::New();
volumeProperty -> SetColor(colorTransferFunction);
volumeProperty -> SetScalarOpacity(opacityTransferFunction);
volumeProperty -> ShadeOn();
volumeProperty -> SetInterpolationTypeToLinear();
vtkVolumeRayCastCompositeFunction * compositeFunction =
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper * volumeMapper =
vtkVolumeRayCastMapper::New();
volumeMapper -> SetVolumeRayCastFunction(compositeFunction);
// volumeMapper->SetInputConnection(reader->GetOutputPort());
volumeMapper -> SetInput(reader -> GetOutput());
vtkVolume * volume = vtkVolume::New();
volume -> SetMapper(volumeMapper);
volume -> SetProperty(volumeProperty);
ren -> AddVolume(volume);
ren -> SetBackground( 1 , 1 , 1 );
renWin -> SetSize( 600 , 600 );
renWin -> Render();
iren -> Initialize();
renWin -> Render();
iren -> Start();
}