[vtkusers] display tens of thousands of cubes

Alex Southern mrapsouthern at gmail.com
Mon Feb 13 07:36:23 EST 2012


Hi,

I'm trying to display cubes with different sizes and each size is 
assigned its own color, see code below.

So far I have managed to correctly,

Assign the colors but not the sizes ( this case is the code below )
OR
Assign the sizes but not the colors

I can post the whole code if it helps. Any help on this would be greatly 
appreciated.

Thanks
Alex.

// Setup scales
     vtkSmartPointer<vtkFloatArray> scales = 
vtkSmartPointer<vtkFloatArray>::New();
     scales->SetName("scales");
// setup colors
     vtkSmartPointer<vtkUnsignedCharArray> colors = 
vtkSmartPointer<vtkUnsignedCharArray>::New();
     colors->SetName("colors");
     colors->SetNumberOfComponents(3);

for (int i = 0; i < ca.numCubes; i++)
     {
         points->InsertNextPoint(ca.cubeCentre[i].x ,ca.cubeCentre[i].y 
,ca.cubeCentre[i].z);
         scales->InsertNextValue(ca.cubeLength[i]);
for ( int j = 0; j < numLengths; j++)
         {
if (ca.cubeLength[i] == t_lengths[j])
             {
                 colors->InsertNextTupleValue(rgb[j]);
break;
             }
         }

     }

     vtkSmartPointer<vtkPolyData> polydata = 
vtkSmartPointer<vtkPolyData>::New();
     polydata->SetPoints(points);
     polydata->GetPointData()->SetScalars(scales);
     polydata->GetPointData()->SetScalars(colors);

     vtkSmartPointer<vtkCubeSource> cubeSource = 
vtkSmartPointer<vtkCubeSource>::New();

     vtkSmartPointer<vtkGlyph3D> glyph3D = 
vtkSmartPointer<vtkGlyph3D>::New();
     glyph3D->SetColorModeToColorByScalar();
     glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
     glyph3D->SetInput(polydata);
     glyph3D->Update();

     vtkSmartPointer<vtkPolyDataMapper> mapper = 
vtkSmartPointer<vtkPolyDataMapper>::New();
     mapper->SetInputConnection(glyph3D->GetOutputPort());

// create mapper
     vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
     actor->SetMapper(mapper);



On 2/10/2012 1:01 PM, David Doria wrote:
> On Fri, Feb 10, 2012 at 5:34 AM, Alex Southern<mrapsouthern at gmail.com>  wrote:
>> Is possible to set the color of each glyph individually?
>>
>> i.e. i'd like glyph's with different scaling to have different colors.
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ColorGlyphs
>
> David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120213/128c1113/attachment.htm>


More information about the vtkusers mailing list