[vtkusers] why i could not see a color cube? a strange problem!

Patrik Spring patrikspring at yahoo.com.cn
Thu Jan 11 02:27:54 EST 2007


I use vtk to draw a color cube,I think my program have no error! But it could not draw the graphic which I want to ?
       
      I think have someone in here could indicate where have error in my program!
       
      thank advanced!
       
       
      #include "vtkLookupTable.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
      int main()
{
 float x[8][3] = { {0.0,0.0,0.0}, {1.0,0.0,0.0}, {1.0,1.0,0.0},  {0.0,1.0,0.0}, 
 {0.0,0.0,1.0},  {1.0,0.0,1.0},  {1.0,1.0,1.0},  {0.0,1.0,1.0} };
        
 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();
 vtkPoints *points = vtkPoints::New();
 vtkCellArray *polys = vtkCellArray::New();
 vtkFloatArray *scalars = vtkFloatArray::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);
      
 vtkLookupTable* lut =   vtkLookupTable::New();
 lut->SetNumberOfColors(256);
 lut->SetTableValue(0,0,0,0,1);
 lut->SetTableValue(1,1,0,0,1);
 lut->SetTableValue(2,0,1,0,1);
 lut->SetTableValue(3,0,0,1,1);
 lut->SetTableValue(4,1,1,0,1);
 lut->SetTableValue(5,1,0,1,1);
 lut->SetTableValue(6,0,1,1,1);
 lut->SetTableValue(7,1,1,1,1);
 lut->Build();
      
 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);
 renWin->SetSize(300,300);
 renWin->Render();
       iren->Initialize();
 iren->Start();
       points->Delete();
 polys->Delete();
 scalars->Delete();
     
 return 0;
}
  
 		
---------------------------------
 Mp3疯狂搜-新歌热歌高速下   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070111/aab7c663/attachment.htm>


More information about the vtkusers mailing list