[vtkusers] Texture mapping on quad...

chrisyeshi chrisyeshi at gmail.com
Tue Apr 26 16:34:12 EDT 2011


Hi

I have read the example 
http://www.vtk.org/Wiki/VTK/Examples/Visualization/TextureMapQuad 
http://www.vtk.org/Wiki/VTK/Examples/Visualization/TextureMapQuad 
But it doesn't work when I "copy" it to my application.
My VTK is 4.2, so I cannot direct copy it. Instead, I rewrite it in the 4.2
compatible way.
The logic should be exactly the same...
While my picture is a colorful picture, the quad is just white at the
beginning.
When I interact with the scene (rotate), it changes colors, which is weird,
I have no code to make it respond to interactions.
However, I do see a relationship between the colors and the picture's
colors.

Here's my codes:

	vtkJPEGReader *reader = vtkJPEGReader::New();
	std::string path = AnatomageApplicationImpl::GetApplicationPath();
	reader->SetFileName("C:/Users/Yucong/Desktop/Samples/images.jpg");

	vtkPoints *pts = vtkPoints::New();
	pts->InsertNextPoint(0.0, 0.0, 0.0);
	pts->InsertNextPoint(1.0, 0.0, 0.0);
	pts->InsertNextPoint(1.0, 1.0, 0.0);
	pts->InsertNextPoint(0.0, 1.0, 0.0);

	vtkCellArray *polygons = vtkCellArray::New();
	vtkPolygon *polygon = vtkPolygon::New();
	polygon->GetPointIds()->SetNumberOfIds(4);
	polygon->GetPointIds()->SetId(0, 0);
	polygon->GetPointIds()->SetId(1, 1);
	polygon->GetPointIds()->SetId(2, 2);
	polygon->GetPointIds()->SetId(3, 3);

	polygons->InsertNextCell(polygon);

	vtkPolyData *quad = vtkPolyData::New();
	quad->SetPoints(pts);
	quad->SetPolys(polygons);

	vtkFloatArray *textureCoordinates = vtkFloatArray::New();
	textureCoordinates->SetNumberOfComponents(3);
	textureCoordinates->SetName("TextureCoordinates");

	float tuple[3] = {0.0, 0.0, 0.0};
	textureCoordinates->InsertNextTuple(tuple);
	tuple[0] = 1.0; tuple[1] = 0.0; tuple[2] = 0.0;
	textureCoordinates->InsertNextTuple(tuple);
	tuple[0] = 1.0; tuple[1] = 1.0; tuple[2] = 0.0;
	textureCoordinates->InsertNextTuple(tuple);
	tuple[0] = 0.0; tuple[1] = 1.0; tuple[2] = 0.0;
	textureCoordinates->InsertNextTuple(tuple);

	quad->GetPointData()->SetTCoords(textureCoordinates);

	vtkTexture *texture = vtkTexture::New();
	texture->InterpolateOff();
	texture->RepeatOff();
	texture->SetInput(reader->GetOutput());

	vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
	mapper->SetInput(quad);

	vtkActor *actor = vtkActor::New();
	actor->SetMapper(mapper);
	actor->SetTexture(texture);

	d_ctrlRenderer->AddVTKProp(actor);

Please Help!~

--
View this message in context: http://vtk.1045678.n5.nabble.com/Texture-mapping-on-quad-tp4341973p4341973.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list