[vtkusers] Texture mapping on quad...
Bill Lorensen
bill.lorensen at gmail.com
Tue Apr 26 16:47:52 EDT 2011
vtk4.2 is a really old version. I am not surprised that the example does not
work. Is there a compelling reason why you cannot upgrade to a more recent
version?
Bill
On Tue, Apr 26, 2011 at 4:34 PM, chrisyeshi <chrisyeshi at gmail.com> wrote:
> 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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110426/f96af10a/attachment.htm>
More information about the vtkusers
mailing list