Compile a program with the following error:
Main. CPP (51): Error c2664: 'void _ thiscall vtkvolumemapper: setinput (class vtkimagedata *) ': cannot convert parameter 1 from 'class vtkstructuredpoints *' to 'class vtkimagedata *'
Vtkstructuredpoints is a subclass of vtkimagedata. Why is the above error? It turns out that there is no "# include" vtkstructuredpoints. H "(the header file of the subclass )". Without this header file, the compiler does not know the inheritance relationship between these two classes.
# Include "vtkactor. H"
# Include "vtkrenderwindow. H"
# Include "vtkrenderer. H"
# Include "vtkrenderwindowindowinteractor. H"
# Include "vtkproperty. H"
# Include "vtkstructuredpointsreader. H"
# Include "vtkstructuredpoints. H" // if this row does not exist, the preceding error occurs.
# Include "vtkpiecewisefunction. H"
# Include "vtkcolortransferfunction. H"
# Include "vtkvolumeproperty. H"
# Include "vtkvolumeraycastcompositefunction. H"
# Include "vtkvolumeraycaw.apper. H"
# Include "vtkvolume. H"
Void main ()
{
Vtkrenderer * Ren = vtkrenderer: New ();
Vtkrenderwindow * renwin = vtkrenderwindow: New ();
Renwin-> addrenderer (ren );
Vtkrenderwindowindowinteractor * iren = vtkrenderwindowindowinteractor: 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 ();
Vtkvolumeraycaw.apper * volumemapper =
Vtkvolumeraycaw.apper: 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 ();
}