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