[vtkusers] Assigning color to points in a polydata surface

Syed Hassan Amin sha1 at doc.ic.ac.uk
Wed Oct 19 07:39:57 EDT 2005


Hi,
   I am trying to assign a color to each of the points on the polydata 
surface , but it seems not to be working. Can any body have a look at it 
, and suggest anything about why it is not working and how to make it work .

    char *path="c://orl//s2//2.pgm";
    Cpq1->Render_PolyData(polyF);
    CImagePQ *Cpq=new CImagePQ;
    vtkPolyDataReader *ply_reader = vtkPolyDataReader::New();
    ply_reader->SetFileName(polyF);
    ply_reader->Update();
      //Read the image
    vil_image_view<vxl_byte>  image1;
    int height,width;
    image1=Cpq->read_gray(path);
    height=image1.nj();// Assume no. of columns
    width=image1.ni();// Assume no. of rows
    
cout<<height*width<<"="<<ply_reader->GetOutput()->GetNumberOfPoints()<<endl;
    vtkFloatArray *fa=vtkFloatArray::New();
    fa->SetNumberOfValues(ply_reader->GetOutput()->GetNumberOfPoints());
    double  count=1;
    for (int i=0;i<width;i++)
        for (int j=0;j<height;j++)
        {
            float x=image1(i,j);
            fa->SetValue(count++,float(x));
        }
    ply_reader->GetOutput()->GetPointData()->SetScalars(fa);
    ply_reader->GetOutput()->GetCellData()->SetScalars(fa);
    ply_reader->Modified();
    ply_reader->Update();
    vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
    coneMapper->SetInput( ply_reader->GetOutput() );
    
coneMapper->SetScalarRange(0,ply_reader->GetOutput()->GetNumberOfPoints());
    coneMapper ->ScalarVisibilityOn();
   // coneMapper->SetScalarModeToUsePointData();
   // coneMapper->SetColorModeToMapScalars();

  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );
 
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );
 
  vtkRenderWindow *renWin= vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );
  //Setting Camera

  //Setting Light

  //For Event Processing
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  renWin->Render();
  //Setting up event processing loop
  iren->Initialize();
  iren->Start();

Thanks ,

S. Hassan Amin



More information about the vtkusers mailing list