<div dir="ltr">Hello,<br><br>I am trying to render a vtkHexahedron within a vtkUnstructuredGrid but I do not see anything when I run the program.&nbsp; Have I missed something basic?<br><br>Thank you for your help.<br><br>Here is the c++ code I am using:<br>
<br>#include &quot;vtkHexahedron.h&quot;<br>#include &quot;vtkPoints.h&quot;<br>#include &quot;vtkDataSetMapper.h&quot;<br>#include &quot;vtkUnstructuredGrid.h&quot;<br>#include &quot;vtkProperty.h&quot;<br>#include &quot;vtkVolumeProperty.h&quot;<br>
#include &quot;vtkColorTransferFunction.h&quot;<br>#include &quot;vtkPiecewiseFunction.h&quot;<br><br>#include &quot;vtkSphereSource.h&quot;<br>#include &quot;vtkPolyDataMapper.h&quot;<br>#include &quot;vtkActor.h&quot;<br>
#include &quot;vtkRenderWindow.h&quot;<br>#include &quot;vtkRenderer.h&quot;<br>#include &quot;vtkRenderWindowInteractor.h&quot;<br>#include &quot;vtkUnstructuredGridVolumeRayCastMapper.h&quot;<br>#include &quot;vtkDataSetTriangleFilter.h&quot;<br>
#include &quot;vtkUnstructuredGridVolumeMapper.h&quot;<br>#include &quot;vtkProjectedTetrahedraMapper.h&quot;<br>#include &quot;vtkFloatArray.h&quot;<br>#include &quot;vtkPointData.h&quot;<br><br>int main ()<br>{<br>&nbsp;&nbsp;&nbsp; float xmin = 0.0;<br>
&nbsp;&nbsp;&nbsp; float xmax = 1.0;<br>&nbsp;&nbsp;&nbsp; float ymin = 0.0;<br>&nbsp;&nbsp;&nbsp; float ymax = 1.0;<br>&nbsp;&nbsp;&nbsp; float zmin = 0.0;<br>&nbsp;&nbsp;&nbsp; float zmax = 1.0;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //create points of hexahedron<br>&nbsp;&nbsp;&nbsp; vtkPoints *hexPoints = vtkPoints::New();<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;SetNumberOfPoints(8);<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(0, xmin, ymin, zmin);<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(1, xmax, ymin, zmin);<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(2, xmax, ymax, zmin);<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(3, xmin, ymax, zmin);<br>
&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(4, xmin, ymin, zmax);<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(5, xmax, ymin, zmax);<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(6, xmax, ymax, zmax);<br>&nbsp;&nbsp;&nbsp; hexPoints-&gt;InsertPoint(7, xmin, ymax, zmax);&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //create the hexahedron<br>&nbsp;&nbsp;&nbsp; vtkHexahedron *theHex = vtkHexahedron::New();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt;8; i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; theHex-&gt;GetPointIds()-&gt;SetId(i,i);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //Create scalars<br>
&nbsp;&nbsp;&nbsp; vtkFloatArray *scalars = vtkFloatArray::New();<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(0, 1.0);<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(1, 1.2);<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(2, 1.0);<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(3, 1.2);<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(4, 1.0);<br>
&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(5, 1.2);<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(6, 1.0);<br>&nbsp;&nbsp;&nbsp; scalars-&gt;InsertTuple1(7, 1.2);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //create an unstructured grid for the hexahedron<br>&nbsp;&nbsp;&nbsp; vtkUnstructuredGrid *theGrid = vtkUnstructuredGrid::New();<br>
&nbsp;&nbsp;&nbsp; theGrid-&gt;Allocate(1, 1);<br>&nbsp;&nbsp;&nbsp; theGrid-&gt;InsertNextCell(theHex-&gt;GetCellType(), theHex-&gt;GetPointIds());<br>&nbsp;&nbsp;&nbsp; theGrid-&gt;SetPoints(hexPoints);<br>&nbsp;&nbsp;&nbsp; theGrid-&gt;GetPointData()-&gt;SetScalars(scalars);<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //create a mapper for the hexahedron<br>&nbsp;&nbsp;&nbsp; vtkDataSetMapper *theHexMapper = vtkDataSetMapper::New();<br>&nbsp;&nbsp;&nbsp; theHexMapper-&gt;SetInput(theGrid);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //create a volume renderer for the unstructured grid<br>
&nbsp;&nbsp;&nbsp; vtkUnstructuredGridVolumeRayCastMapper *volumeMapper = vtkUnstructuredGridVolumeRayCastMapper::New();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //Triangulate the surfaces<br>&nbsp;&nbsp;&nbsp; vtkDataSetTriangleFilter *tri = vtkDataSetTriangleFilter::New();<br>
&nbsp;&nbsp;&nbsp; tri-&gt;SetInput(theGrid);<br>&nbsp;&nbsp;&nbsp; volumeMapper-&gt;SetInput(tri-&gt;GetOutput());<br><br>&nbsp;&nbsp;&nbsp; //create the volumeproperty object to define how our volume looks<br>&nbsp;&nbsp;&nbsp; vtkColorTransferFunction *colorTF = vtkColorTransferFunction::New();<br>
&nbsp;&nbsp;&nbsp; colorTF-&gt;AddRGBPoint(0.0, 0.0, 0.0, 0.0);<br>&nbsp;&nbsp;&nbsp; colorTF-&gt;AddRGBPoint(64.0, 1.0, 0.0, 0.0);<br>&nbsp;&nbsp;&nbsp; colorTF-&gt;AddRGBPoint(128.0, 0.0, 0.0, 1.0);<br>&nbsp;&nbsp;&nbsp; colorTF-&gt;AddRGBPoint(192.0, 0.0, 1.0, 0.0);<br>&nbsp;&nbsp;&nbsp; colorTF-&gt;AddRGBPoint(255.0, 0.0, 0.2, 0.0);<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; vtkPiecewiseFunction *opacityTF = vtkPiecewiseFunction::New();<br>&nbsp;&nbsp;&nbsp; opacityTF-&gt;AddPoint(20.0, 0.0);<br>&nbsp;&nbsp;&nbsp; opacityTF-&gt;AddPoint(255.0, 0.2);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();<br>
&nbsp;&nbsp;&nbsp; volumeProperty-&gt;SetColor(colorTF);<br>&nbsp;&nbsp;&nbsp; volumeProperty-&gt;SetScalarOpacity(opacityTF);<br>&nbsp;&nbsp;&nbsp; volumeProperty-&gt;ShadeOff();<br>&nbsp;&nbsp;&nbsp; volumeProperty-&gt;SetInterpolationTypeToLinear();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //create a volume to render<br>
&nbsp;&nbsp;&nbsp; vtkVolume *theVolume = vtkVolume::New();<br>&nbsp;&nbsp;&nbsp; theVolume-&gt;SetMapper(volumeMapper);<br>&nbsp;&nbsp;&nbsp; theVolume-&gt;SetProperty(volumeProperty);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // a renderer and render window<br>&nbsp;&nbsp;&nbsp; vtkRenderer *ren1 = vtkRenderer::New();<br>
&nbsp;&nbsp;&nbsp; vtkRenderWindow *renWin = vtkRenderWindow::New();<br>&nbsp;&nbsp;&nbsp; renWin-&gt;AddRenderer(ren1);<br>&nbsp;&nbsp;&nbsp; ren1-&gt;AddViewProp(theVolume);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // an interactor<br>&nbsp;&nbsp;&nbsp; vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br>
&nbsp;&nbsp;&nbsp; iren-&gt;SetRenderWindow(renWin);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; ren1-&gt;SetBackground(1,1,1); // Background color white<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // render an image (lights and cameras are created automatically)<br>&nbsp;&nbsp;&nbsp; renWin-&gt;Render();<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // begin mouse interaction<br>&nbsp;&nbsp;&nbsp; iren-&gt;Initialize();<br>&nbsp;&nbsp;&nbsp; iren-&gt;Start();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 1;<br>}<br><br></div>