[vtkusers] How to get texture values for a vertex?

Andrea Bottino andrea.bottino at polito.it
Mon Sep 15 11:12:52 EDT 2008


(I send again the msg in text mode...)

Hi all,
I have an .obj model with an associated texture, and I need to access 
vertex coordinates as well as their RGB values. However, I'm blocked on 
the last point. Here's my code:

// loading the obj model & texture
    model = vtkOBJReader::New();
    model->SetFileName(filename);

    if(readableFile(textureName))
    {
        vtkPNGReader* png1 = vtkPNGReader::New();
        png1->SetFileName("train_02463_1.png");
        texture = vtkTexture::New();
        texture->SetInputConnection(png1->GetOutputPort());
        texture->InterpolateOn();
    }

// ...
// then I create the actor, and finally set the texture to the actor

   vtkActor* actor = vtkActor::New();
   vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
   mapper->SetInput(model->GetOutput());
   actor->SetMapper(mapper);

   if(texture)
    actor->SetTexture(texture);

Then, for accessing the (x,y,z) and (R,G,B) values for each model vertex:

  vtkPoints *inPts = model->GetOutput()->GetPoints(); 
  vtkIdType numPts = model->GetOutput()->GetNumberOfPoints();
  double x[3];

  if (numPts < 1)
  {
        // vtkErrorMacro(<<"No vertices in the model!");
        return;
  }
   

  for (vtkIdType ptId=0; ptId < numPts; ptId++)
  {
      inPts->GetPoint(ptId, x);
      //cout << ptId << ") " << x[0] << ", " << x[1] << ", " << x[2] << 
endl;

    // getting texture values
   //  --> and I have no idea how to get these values...
  } 


best regards,
a.


-- 
Andrea Bottino
Politecnico di Torino, DAUIN
Corso Duca degli Abruzzi, 24
10129 Torino ITALY
Tel +39 011 5647175 / Fax +39 011 5647099.
http://www.polito.it/cgvg




More information about the vtkusers mailing list