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

本文介绍了一种在使用VTK库进行三维图像处理时遇到的编译错误,并详细解释了错误原因及解决方法。主要问题是由于缺少特定子类的头文件引入,导致编译器无法识别类间的继承关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编译一程序,出现如下错误:
 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(200.0);
    opacityTransferFunction
->AddPoint(2550.2);

    vtkColorTransferFunction 
*colorTransferFunction = 
        vtkColorTransferFunction::New();
    colorTransferFunction
->AddRGBPoint(0.00.00.00.0);
    colorTransferFunction
->AddRGBPoint(64.01.00.00.0);
    colorTransferFunction
->AddRGBPoint(128.00.00.01.0);
    colorTransferFunction
->AddRGBPoint(192.00.01.00.0);
    colorTransferFunction
->AddRGBPoint(255.00.00.20.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(111);
    renWin
->SetSize(600600);
    renWin
->Render();

    iren
->Initialize();
    renWin
->Render();
    iren
->Start();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值