[vtkusers] how to get a colorful cube from vtkCubeSource?&In-Reply-To=479440.12638.qm at web61313.mail.

Toron J. ji_wi at yahoo.com
Fri Nov 16 22:52:03 EST 2007


Hi,  Thanks for your response! 

But why can I only see two colorful faces of the cube but not six faces?. Here is the screen shot http://farm3.static.flickr.com/2325/2039496734_7b98ce59af_o.jpg . I use VC6.0 on WinXP.

If the cube is from an obj file (I use vtkOBJReader to read th obj file), do I need to convert the cube to polydata then assign colors?  Where do I need to call xxx-Update()?

Thanks again!

Toron



Tracy Hu <tracy.hu at yahoo.com> wrote: if you add 
    box->Update();
immediately after vtkCubeSource *box = vtkCubeSource::New();

you should see a colorful cube. I think this has to do with vtk pipeline's demand-driven feature.




"Toron J." <ji_wi at yahoo.com> wrote: Hi,

I want to use vtkCubeSource to create a colorful box (I just modify the VTK example Cube.cxx). But I can not see a colorful cube but only white one. Does anyone can help me?

-------- My code -----------------------------------------------------------
#include "vtkCubeSource.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPointData.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"

void main ()
{
    vtkFloatArray *scalars = vtkFloatArray::New();
    for (int i=0; i<8; i++) 
        scalars->InsertValue(i, i);    // Set color
 
    vtkCubeSource *box = vtkCubeSource::New();
     
    vtkPolyData *cube = vtkPolyData::New();    // convert to polydata
        cube = box->GetOutput();

        cube->GetPointData()->SetScalars(scalars);    // assign color to vertex

    vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
        cubeMapper->SetInput(cube);
        cubeMapper->SetScalarRange(0,7);    // set hue range

    vtkActor *cubeActor = vtkActor::New();
        cubeActor->SetMapper(cubeMapper);

    vtkRenderer *renderer = vtkRenderer::New();
        renderer->AddActor(cubeActor);
        renderer->SetBackground(0,0,0);
  
    vtkRenderWindow *renWin =  vtkRenderWindow::New();
        renWin->SetSize(500,500);
        renWin->AddRenderer(renderer);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
        iren->SetRenderWindow(renWin);

    renWin->Render();
    iren->Start();
}
---------------------------------------------------------------------------

Thanks a lot!

Toron


       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071116/068dfd1a/attachment.htm>


More information about the vtkusers mailing list