[vtkusers] vtkTexture : apply texture
Alain SIMAC
alain.simac at visioterra.com
Mon Jul 18 08:54:22 EDT 2005
Hi advanced customers of vtk,
I wish to apply a texture to an object (a DEM). For the moment, I do not
arrive at the appliquer.Mon object takes the color of the first pixel of the
image whereas I want to apply all the image.
Did somebody already have the problem ? Does somebody have a solution ?
Thanks
Alain SIMAC
Actual code :
Image : type jpeg
/***************************************************************************
**/
/* VTK library inclusion files
*/
/***************************************************************************
**/
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkDataSetReader.h"
#include "vtkDoubleArray.h"
#include "vtkStructuredPoints.h"
#include "vtkPoints.h"
#include "vtkPointData.h"
#include "vtkStructuredGrid.h"
#include "vtkCellData.h"
#include "vtkStructuredGridGeometryFilter.h"
#include "vtkPolyDataNormals.h"
#include "vtkTexture.h"
//#include "vtkImageReader.h"
#include "vtkJPEGReader.h"
#include "vtkImageData.h"
/***************************************************************************
**/
/***************************************************************************
**/
/* Visualisation program main
*/
/***************************************************************************
**/
int main(int argc, char *argv[])
{
/***************************************************************************
**/
/* Setup parameters
*/
/***************************************************************************
**/
const char* m_filename = argv[1];
double m_maxvizu = 400;
double m_minvizu = -4000;
double m_elevation = 60000;
/***************************************************************************
**/
/* Texture configuration
*/
/***************************************************************************
**/
const char* image = argv[2];
vtkJPEGReader *jpegReader;
vtkTexture *texture;
jpegReader=vtkJPEGReader::New();
jpegReader->SetFileName(image);
texture = vtkTexture::New();
texture->InterpolateOn();
texture->SetInput(jpegReader->GetOutput());
/***************************************************************************
**/
/* Create VTK renderer
*/
/***************************************************************************
**/
vtkRenderer* Ren1 = vtkRenderer::New();
vtkRenderWindow* RenWin1 = vtkRenderWindow::New();
RenWin1->AddRenderer(Ren1);
RenWin1->SetSize(800,600);
/***************************************************************************
**/
/* Create VTK interactor
*/
/***************************************************************************
**/
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(RenWin1);
/***************************************************************************
**/
/* Create VTK DataSetReader
*/
/***************************************************************************
**/
vtkDataSetReader* m_datasetreader;
m_datasetreader = vtkDataSetReader::New();
m_datasetreader->SetFileName(m_filename);
m_datasetreader->Update();
/***************************************************************************
**/
/* Get Dataset dimensions
*/
/***************************************************************************
**/
vtkDataSet* m_points = m_datasetreader->GetOutput();
int dimx =
m_datasetreader->GetStructuredPointsOutput()->GetDimensions()[0];
int dimy =
m_datasetreader->GetStructuredPointsOutput()->GetDimensions()[1];
/***************************************************************************
**/
/* Allocate vtkPoint structure
*/
/***************************************************************************
**/
vtkPoints* m_point = vtkPoints::New();
m_point->SetNumberOfPoints(dimx*dimy);
/***************************************************************************
**/
/* Allocate scalar array
*/
/***************************************************************************
**/
vtkDoubleArray* m_array = vtkDoubleArray::New();
m_array->SetNumberOfComponents(1);
m_array->SetNumberOfTuples(dimx*dimy);
/***************************************************************************
**/
/* Fill point and scalar array
*/
/***************************************************************************
**/
for (int y=0;y<dimy;y++)
for (int x=0;x<dimx;x++)
{
int offset = x+y*dimx;
double m_coord[3];
m_points->GetPoint (offset,m_coord);
int offset2 = x+y*(dimx-1);
double* m_value = m_points->GetPointData()->GetTuple(offset);
if (m_value[0] > m_maxvizu)
m_value[0] = m_maxvizu;
if (m_value[0] < m_minvizu)
m_value[0] = m_minvizu;
m_array->SetTuple1(offset2,100-
((((double)m_value[0]-m_minvizu)/(m_maxvizu-m_minvizu))*100));
m_point->InsertPoint(offset,m_coord[0],m_coord[1],
(((double)m_value[0]-m_minvizu)/(m_maxvizu-m_minvizu))*m_elevation);
}
/***************************************************************************
**/
/* Create vtkStructuredGrid for vizualisation
*/
/***************************************************************************
**/
vtkStructuredGrid* m_grid = vtkStructuredGrid::New();
m_grid->SetDimensions(dimx,dimy,1);
//m_grid->GetCellData()->SetScalars(m_array);
m_grid->SetPoints(m_point);
vtkStructuredGridGeometryFilter* m_gridgeometry
=
vtkStructuredGridGeometryFilter::New();
m_gridgeometry->SetInput(m_grid);
/***************************************************************************
**/
/* Create normals for better vizualisation
*/
/***************************************************************************
**/
vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
normals->SetInput(m_gridgeometry->GetOutput());
normals->ComputeCellNormalsOn();
normals->Update();
/***************************************************************************
**/
/* Create mapper
*/
/***************************************************************************
**/
vtkPolyDataMapper* m_mapper = vtkPolyDataMapper::New();
m_mapper->SetInput(normals->GetOutput());
m_mapper->SetScalarRange(0,100);
m_mapper->ScalarVisibilityOn();
/***************************************************************************
**/
/* Create actor
*/
/***************************************************************************
**/
vtkActor* m_actor = vtkActor::New();
m_actor->SetMapper(m_mapper);
m_actor->SetTexture(texture);
/***************************************************************************
**/
/* Rendering
*/
/***************************************************************************
**/
Ren1->AddActor(m_actor);
Ren1->SetBackground(0,0,0);
RenWin1->Render();
iren->Start();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050718/86ba30f5/attachment.htm>
More information about the vtkusers
mailing list