Texture mapping is killing me

Gong Jianhua jhgong at cuhk.edu.hk
Sat Jun 19 21:26:55 EDT 1999


Hi,

Here is a simple example.

Jianhua
===========================================================
 vtkRenderer *ren = vtkRenderer::New();
       vtkRenderWindow *renWin = vtkRenderWindow::New();
          renWin->AddRenderer(ren);

     vtkPolyDataReader *m_reader = vtkPolyDataReader::New();
     vtkPolyDataMapper *m_mapper = vtkPolyDataMapper::New();
           vtkActor *m_actor = vtkActor::New();

     m_reader->SetFileName(FileNameI);

  // Image ( Texture ) Mapping
  vtkTexture *text = vtkTexture::New();
  vtkTextureMapToPlane *planeMap = vtkTextureMapToPlane::New();
  vtkPolyData *PolyDataT=vtkPolyData::New();

  if ( ImageCheck==TRUE )  // Mapping
  {
   vtkStructuredPointsReader *PlaneTexture = vtkStructuredPointsReader::New();
      PlaneTexture->SetFileName(ImageFileName);
   PlaneTexture->Update();
   int *Dim=new int[3];
   float *Spacing=new float[3];
   float *Origin=new float[3];
   PlaneTexture->GetOutput()->GetDimensions(Dim);  // Get rows, columns, and Levels

   PlaneTexture->GetOutput()->GetSpacing(Spacing);  // row,col piexellength
   PlaneTexture->GetOutput()->GetOrigin(Origin);  // Origin

   text->SetInput(PlaneTexture->GetOutput());

   text->InterpolateOn();

   // Compute Texture Coordinates according to the Polydata file
   // Filter that filters data & generates texture coords

   float ijk[3];
   //ijk[0]=Dim[0]*Spacing[0];
   //ijk[1]=Dim[1]*Spacing[1];
   ijk[2]=0;   // 2-D
   ijk[0]=Dim[0]*Spacing[0]+Origin[0];
   ijk[1]=Dim[1]*Spacing[1]+Origin[1];

   planeMap->AutomaticPlaneGeneration=FALSE;
   planeMap->SetOrigin(Origin[0],Origin[1],Origin[2]);             // Define plane
to map on
   planeMap->SetPoint1(ijk[0],Origin[1],0); // SetPlaneNormal=ON
   planeMap->SetPoint2(Origin[0],ijk[1],0);
   planeMap->SetInput(m_reader->GetOutput());   // Put int the 3D data

   delete Dim;
   delete Spacing;
   delete Origin;
  }
  if ( ImageCheck==TRUE )  // Set Texture Coordinate
      m_mapper->SetInput(planeMap->GetPolyDataOutput());
  if ( ImageCheck==TRUE )  // Set Texture Map
        m_actor->SetTexture(text);
  ren->AddActor(m_actor);





Jordi Cabot wrote:

> Hi vtkUsers,
>
> I'm really desperate so I'm replying myself. I don't understand at all
> texture mapping and how the texture coordinates work. In the book it
> doesn't say much, and in the examples the TCoords are automatically
> generated. Please, some good soul help me.
>
>  1) What are exactly the TCoords? For what I have understood every point
>  (of polygonal data) has 2 coords (if we want to map a 2D image) which
>  correspond to the position of the image, so 0 0 is upper left, 1 1 is
>  down right. Is this correct?
>
>  2) This means that all the points of the dataset must have TCoords?
> What if
> I just want to color a region of my surface? If all the points of the
> mesh have
> TCoords associated, all of them must be mapped?
>
>  3) Let's say that I have four points of the mesh which define kind of a
> frame and I want
> limit the texture map to this frame? Is that possible? How can I do it?
> I guess that
> the 4 points are assigned TCoords 0,0 1,0 0,1 and 1,1. But the rest of
> the points(those outside the frame and those inside), what do I do with
> them?
>
> Thanks,
>
> Jordi
>
> Jordi Cabot wrote:
> >
> > Hi vtkUsers
> >
> >  I'm using vtk for visualization 3D of medical images. After getting tha
> > brain and scalp
> > stuff from an MRI and getting the contour etc... , I want to color map a
> > region of the
> >  scalp and/or brain using some matlab results. These results are the
> > electrode (for
> > example placed in the musculs of the hand) response to EM stimulation of
> > the brain. We stimulate the brain in points of a grid which we put over
> > the head of the patient and we get the points with  a 3D digiting system
> > (it just take the coordinates relative to an emisor placed for example
> > in the front of the head). Anyway, we obtain a 10x10
> > matrix colored according to the intensity of the response. With the
> > CellLocator->IntersectWithLine I get the points in the brain
> > corresponding to the points where we have stimulated, and what I'd like
> > to do is, knowing this correspondance between points, texture map the
> > matrix into the brain.
> >
> > Right know I'm just putting spheres (glyphs) in teh intersection points
> > and I color them according to the scalar associated. And since yesterday
> > I'm trying with vtkClipPolyData to render only the intersection of the
> > spheres with the brain. The result is a kind of cercle which respects
> > the rugosities of the brain
> >
> >  This is texture mapping, what I need, isn't it?
> >
> > I need help,
> >
> > jordi
> >
> > -----------------------------------------------------------------------------
> > This is the private VTK discussion list.  Please keep messages on-topic.
> > Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
> > To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> > <majordomo at gsao.med.ge.com>.  For help, send message body containing
> > "info vtkusers" to the same address.     Live long and prosper.
> > -----------------------------------------------------------------------------
>
> -----------------------------------------------------------------------------
> This is the private VTK discussion list.  Please keep messages on-topic.
> Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
> To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> <majordomo at gsao.med.ge.com>.  For help, send message body containing
> "info vtkusers" to the same address.     Live long and prosper.
> -----------------------------------------------------------------------------



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------





More information about the vtkusers mailing list