[vtkusers] Drawing cubes in vtk
    frency v 
    frencyvarghese at yahoo.com
       
    Thu Aug 13 09:45:03 EDT 2009
    
    
  
Hello everyone,
I am also trying to draw not one cube but  more than 100 cubes.I was going through  questions on vtk user list on drawing cubes. I found one code to draw one cube.   I tried the example i found online but using tht i cud draw only one. Can someone pls help me in this? Also, can the dimensions of the cube be changed? If yes, how?
What defines the dimensions of the cube in this code i am sending along with this mail.
Regards
Frency
here is the code
int v1,v2, v3,  //* are the vertices of the n cubes i want to draw.
float x[8][3] = { {v1,v2,v3},  {v1+1,v2,v3}, {v1+1,v2+1,v3},  {v1,v2+1,v3},
{v1,v2,v3+1},  {v1+1,v2,v3+1},  {v1+1,v2+1,v3+1},  {v1,v2+1,v3+1} };
vtkIdType pts[6][4] = { {0,3,2,1},{2,3,7,6},{0,4,7,3},{1,2,6,5},{4,5,6,7},{0,1,5,4} };
  vtkPolyData * cube = vtkPolyData::New();
       int i ;
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);
   cube->SetPoints(points);
cube->SetPolys(polys);
cube->GetPointData()->SetScalars(scalars);
             vtkPolyDataMapper*  colorcubeMapper = vtkPolyDataMapper::New();
//colorcubeMapper->SetInputConnection(colorcube->GetOutputPort());
colorcubeMapper->SetInput(cube);
colorcubeMapper->ScalarVisibilityOn();
// colorcubeMapper->SetScalarModeToUsePointData();
//colorcubeMapper->SetLookupTable(lut);
       vtkActor*   colorcubeActor = vtkActor::New();
    colorcubeActor->SetMapper(colorcubeMapper);
       vtkCamera *camera = vtkCamera::New();
camera->SetPosition(1,1,1);
camera->SetFocalPoint(0,0,0);
vtkRenderer* ren1 = vtkRenderer::New();
vtkRenderWindow* renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
       ren1->AddActor(colorcubeActor);
ren1->SetActiveCamera(camera);
ren1->ResetCamera();
ren1->SetBackground(1,1,1);patrikspring at yahoo.com.cn
renWin->SetSize(300,300);
renWin->Render();
       iren->Initialize();
iren->Start();
       points->Delete();
polys->Delete();
scalars->Delete();
return 0;
      
    
    
More information about the vtkusers
mailing list