子类指针不能转换为父类指针???

编译一程序,出现如下错误:
 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();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值