[vtkusers] How to change the color of cube?

Malcolm Drummond malcolm at geovision.co.za
Thu Sep 2 08:41:07 EDT 2004


Hi Wang

Also, if there are scalar values present the mapper is going to use these by
default. You can switch off use of scalars with ...

cubeMapper->ScalarVisibilityOff();

... and then use SetColor(r,g,b) as Amy advised.

Or are you referring to controlling saturation and value in the mapped
scalars?

HTH
Malcolm

----- Original Message -----
From: "Amy Henderson" <amy.henderson at kitware.com>
To: <vtkusers at vtk.org>
Sent: Thursday, September 02, 2004 2:21 PM
Subject: Re: [vtkusers] How to change the color of cube?


Hi Wang,

I'm not sure what you mean by "pure colors", but to change the color of an
actor, you need to do something similar to the following:

actor->GetProperty()->SetColor(1, 1, 1);

The above code will set the color to white.  (The three parameters to
SetColor are red, green, and blue values between 0 and 1.)

- Amy

At 11:57 PM 9/1/2004, wang minyou wrote:
>I use vtkPolydata to create a cube, but it only can display pure colors
>but not blank or white. Any one can help me to achieve that?
>Thank you in advance!
>
>My relevant codes:
>  int i;
>  static float x[8][3]={{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0},
>                        {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1}};
>  static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4},
>                        {1,2,6,5}, {2,3,7,6}, {3,0,4,7}};
>
>  // We'll create the building blocks of polydata including data
attributes.
>  vtkPolyData *cube = vtkPolyData::New();
>  vtkPoints *points = vtkPoints::New();
>  vtkCellArray *polys = vtkCellArray::New();
>  vtkFloatArray *scalars = vtkFloatArray::New();
>
>  // Load the point, cell, and data attributes.
>  for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
>  for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
>  for (i=0; i<8; i++) scalars->InsertTuple1(i,i);
>
>  // We now assign the pieces to the vtkPolyData.
>  cube->SetPoints(points);
>  points->Delete();
>  cube->SetPolys(polys);
>  polys->Delete();
>  cube->GetPointData()->SetScalars(scalars);
>  scalars->Delete();
>
>  // Now we'll look at it.
>  vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
>      cubeMapper->SetInput(cube);
>      cubeMapper->SetScalarRange(0,7);
>  vtkActor *cubeActor = vtkActor::New();
>      cubeActor->SetMapper(cubeMapper);
>
>  // The usual rendering stuff.
>  vtkCamera *camera = vtkCamera::New();
>      camera->SetPosition(1,1,1);
>      camera->SetFocalPoint(0,0,0);
>
>  vtkRenderer *renderer = vtkRenderer::New();
>  vtkRenderWindow *renWin = vtkRenderWindow::New();
>    renWin->AddRenderer(renderer);
>
>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>    iren->SetRenderWindow(renWin);
>
>  renderer->AddActor(cubeActor);
>      renderer->SetActiveCamera(camera);
>      renderer->ResetCamera();
>      renderer->SetBackground(1,1,1);
>
>  renWin->SetSize(300,300);
>
>_________________________________________________________________
>ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£  http://www.hotmail.com
>
>_______________________________________________
>This is the private VTK discussion list. Please keep messages on-topic.
>Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers



_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list