[vtkusers] the code always give erorr : Can't use the ray cast mapper without scalars!

InfoSeekerr ali.mahmoud.habib at gmail.com
Thu Sep 3 07:56:57 EDT 2009


I added the array as following but the same error appear:

// 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);
           // Add scaler value
           vtkDoubleArray arr =new vtkDoubleArray();
          
arr.SetNumberOfTuples(unstructuredReader.GetOutput().GetNumberOfPoints());
           arr.FillComponent(0, 1.0); // e.g. double value = 1.0;
           arr.SetName("myarray");
          // MessageBox.Show(arr.GetData(
           //unstructuredReader.GetOutput().GetPointData().SetScalars();
           unstructuredReader.GetOutput().GetPointData().AddArray(arr);
          
unstructuredReader.GetOutput().GetPointData().SetActiveScalars("myarray");


           // 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.SetInput(unstructuredReader.GetOutput());


           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-2 wrote:
> 
> 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
> -------------------------------------------------
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 

-- 
View this message in context: http://www.nabble.com/the--code-always-give-erorr-%3A-Can%27t-use-the-ray-cast-mapper-without-scalars%21-tp25254954p25274545.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list