[vtkusers] DRAW and REDRAW method

Hamp Donald hampdonald at yahoo.com
Wed Apr 7 15:12:00 EDT 2004


Hi
    i want to draw and redraw multiple lines. If I
draw , say two lines for first time, I will draw three
lines next time and so on. Please find below my code.
It is drawing two lines and then doing nothing. I
tried with do -while loop. It is messy. Please suggest
something.

Best Regards
Subhas 


int main( int argc, char *argv[] )
{
  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}};
  static vtkIdType pts[8][2]={{0,1}, {1,2}, {2,3},
{3,4}, {4,5}, {5,6}, {6,7}, {7,8}};
                                                      
                                        
  // We'll create the building blocks of polydata
including data attributes.
  vtkPolyData *cube = vtkPolyData::New();
  vtkPoints *points = vtkPoints::New();
   vtkCellArray *lines = vtkCellArray::New();
                                                      
                                        
  vtkFloatArray *scalars = vtkFloatArray::New();
                                                      
                                        
  int Line_Number = 2;
  // Load the point, cell, and data attributes.
  for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
  //for (i=0; i<8; i++)
lines->InsertNextCell(2,pts[i]);
  for (i=0; i < Line_Number; i++)
lines->InsertNextCell(2,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->SetLines(lines);
  lines->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);
                                                      
                                        
   do {
  cube->SetPoints(points);
  cube->SetLines(lines);
  cube->GetPointData()->SetScalars(scalars);
  for (i=0; i < Line_Number; i++)
lines->InsertNextCell(2,pts[i]);
      cubeMapper->SetInput(cube);
      cubeActor->SetMapper(cubeMapper);
  // interact with data
  renWin->Render();
  //iren->Start();
   Line_Number++;
   cout << "Coming Here ....." << endl;
    getchar();
     } while (Line_Number < 6) ;
                                                      
                                        


  

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/



More information about the vtkusers mailing list