[vtkusers] Adding a Scalar to a Cube Source

Mike Jackson mike.jackson at imts.us
Tue Jan 30 12:38:37 EST 2007


I am reading some data from a file and rendering that data to screen.  
The data in the file are basically sets of (x,y,z) position + Radius  
value that describe either a Cube or Sphere. Using the vtkCubeSource  
and vtkSpehereSource classes was easy enough to get my data on  
screen. ( I am actually using ParaView but that shouldn't matter).  
What I need to do is basically assign a value to each cube or sphere  
so That I can filter out one or the other. I tried to add a Scalar  
attribute to the CubeSource like Follows:

vtkSmartPointer<vtkAppendPolyData> append =  
vtkSmartPointer<vtkAppendPolyData>::New();
vtkSmartPointer<vtkCubeSource> cube =  
vtkSmartPointer<vtkCubeSource>::New();
       cube->SetCenter( (double)precip->x, (double)precip->y, (double) 
precip->z);
       sideLength = precip->radius * 2.0;
       cube->SetXLength(sideLength);
       cube->SetYLength(sideLength);
       cube->SetZLength(sideLength);

       cube->Update();
       append->AddInput( cube->GetOutput() );
       vtkIdType size = cube->GetOutput()->GetPointData()- 
 >GetNumberOfTuples() ;
       vtkSmartPointer<vtkCharArray> type =  
vtkSmartPointer<vtkCharArray>::New();
       type->SetName("GeoType");
       type->SetNumberOfComponents(1);
       type->SetNumberOfTuples( size );
       cube->GetOutput()->GetPointData()->SetScalars(type);
       for ( int i = 0; i < size; ++i) {
         type->InsertNextValue(1);
       }

But this isn't really working. I am getting values from -128 to 127.  
I was thinking I would just get values from 0-1.

Or is there a better way to do this? Any and all ideas are accepted.

Thanks for any help

-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services






More information about the vtkusers mailing list