[vtkusers] the code always give erorr : Can't use the ray cast mapper without scalars!
Bryn Lloyd
blloyd at vision.ee.ethz.ch
Wed Sep 2 07:53:51 EDT 2009
Hi,
Like the message says: Your data needs scalar values, e.g. a data array
with a scalar value for each point in the unstructured grid. The array
can be double, float etc.
It must be added to the grid.
example:
vtkDoubleArray *arr = vtkDoubleArray::New();
arr->SetNumberOfTuples(grid->GetNumberOfPoints());
arr->FillComponent(0,value); // e.g. double value = 1.0;
arr->SetName("myarray");
grid->GetPointData()->SetScalars(arr);
// or grid->GetPointData()->AddArray(arr);
Of course you can set something more interesting than a single scalar,
e.g. the distance to the spheres surface...
Have a look at the mentioned classes (also vtkPointData, vtkCellData).
InfoSeekerr wrote:
> Dear All,
>
> I wanted to apply traingular mish on sphere , but the code always give
> erorr : Can't use the ray cast mapper without scalars! , how to fix this
> error please,I used the following code (written in c#) :
>
> // volume property
> int shade = 0,compos = 0, //Classify First or Interpolate
> First
> interp = 0;
>
> // renderer
> vtkRenderer ren1= new vtkRenderer();
> ren1.SetBackground( 1.0, 1.0, 1.0 );
>
> // render window
> vtkRenderWindow renWin = new vtkRenderWindow();
> renWin.AddRenderer( ren1 );
> renWin.SetSize( 800, 600 );
>
> // interactor
> vtkRenderWindowInteractor iren1 = new
> vtkRenderWindowInteractor();
> iren1.SetRenderWindow(renWin);
>
> // set up the input file for unstructured grid reader
> //1.Create a volume data
> // create sphere geometry
> vtkSphereSource sphere = new vtkSphereSource();
> sphere.SetRadius(1.0);
> sphere.SetThetaResolution(18);
> sphere.SetPhiResolution(18);
> //2.Apply the tetrahedral mish
> vtkPolyData vp = new vtkPolyData();
>
> vtkDelaunay3D unstructuredReader = new vtkDelaunay3D();
> unstructuredReader.SetInput(sphere.GetOutput());
>
>
> // set up opacity transfer function
> vtkPiecewiseFunction opacityTransferFunction = new
> vtkPiecewiseFunction();
> opacityTransferFunction.AddPoint(0, 0.02);
> opacityTransferFunction.AddPoint(4095.0, 1.0);
>
> // set up color transfer function
> vtkColorTransferFunction colorTransferFunction = new
> vtkColorTransferFunction();
> colorTransferFunction.AddRGBPoint( 0.0, 0.1, 0.1, 0.1);
> colorTransferFunction.AddRGBPoint( 4095.0, 1.0, 0.0, 1.0);
>
> // set up volume property
> vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
> volumeProperty.SetColor(colorTransferFunction);
> volumeProperty.SetScalarOpacity(opacityTransferFunction);
> volumeProperty.SetInterpolationType(interp);
> volumeProperty.SetShade(shade);
>
> // composite function for strucured grid renderer
> vtkVolumeRayCastCompositeFunction compositeFunction = new
> vtkVolumeRayCastCompositeFunction();
> compositeFunction.SetCompositeMethod(compos);
>
> //unstructuredGridRendering
> vtkUnstructuredGridVolumeRayCastMapper volumeUnstructedMapper = new
> vtkUnstructuredGridVolumeRayCastMapper();
> // vtkVolumeRayCastMapper volumeUnstructedMapper = new
> vtk.vtkVolumeRayCastMapper();
> //volumeUnstructedMapper.set (compositeFunction);
>
> volumeUnstructedMapper.SetInputConnection(unstructuredReader.GetOutputPort());
>
>
> vtkVolume volume = new vtkVolume();
>
> volume.SetMapper(volumeUnstructedMapper);
>
> volume.SetProperty(volumeProperty);
>
> // add volume to renderer
> ren1.AddVolume(volume);
>
> renWin.Render();
>
> iren1.Start();
>
> ren1.Dispose();
> renWin.Dispose();
> iren1.Dispose();
> opacityTransferFunction.Dispose();
> colorTransferFunction.Dispose();
> volumeProperty.Dispose();
> compositeFunction.Dispose();
> // unstructured grid case
> volumeUnstructedMapper.Dispose();
> unstructuredReader.Dispose();
> volume.Dispose();
> ///////////////////////////////////////////////
>
>
>
--
-------------------------------------------------
Bryn Lloyd
Computer Vision Laboratory
ETH Zürich, Sternwartstrasse 7, ETF C110
CH - 8092 Zürich, Switzerland
Tel: +41 44 63 26668
Fax: +41 44 63 21199
-------------------------------------------------
More information about the vtkusers
mailing list