[vtkusers] Textures
Wes Turner
wes.turner at kitware.com
Tue Nov 24 17:01:57 EST 2009
I believe that there is a limit of one texture per vtkActor, which gives you
two alternatives. Either you need to combine your 6 views into a single
texture or you need to make each side of the cube a separate actor.
- Wes
2009/11/24 "André Rohde" <Rohy at gmx.de>
> Dear Vtk Users,
> i´d like to map one texture to each side of a cube (6 sides = 6 different
> textures) from different arrays. (Only one Array in my Code yet)
> Mapping one texture to the cube works fine for me. But i don´t have an idea
> how this is gonna work for each side of a cube. The general idea behind my
> program is to take an specific amount of snapshots from a camera and
> generate an array/cube of this pictures in vtk.
>
> Here´s my Code:
>
> //First Array > Image Data should be mapped to the first side of the
> cube...
> vtkFloatArray *vtkArray = vtkFloatArray::New();
> vtkArray->SetNumberOfComponents(1);
> vtkArray->SetNumberOfTuples(1392*1040);
>
> unsigned indexInverted = 0;
>
> for(int k = 0; k < 1040; k++)
> {
> for(int l = 0; l < 1392; l++)
> {
> //pcFrame contains the ImageData from the Camera
> vtkArray->SetTuple1(indexInverted,pcFrame[((1392*1040)-(1392*(k+1)))+l]);
> indexInverted++;
> }
> }
>
> vtkImageData *myImage = vtkImageData::New();
> myImage->SetDimensions(1392,1040,1);
> myImage->SetSpacing(1,1,1);
> myImage->SetOrigin(0,0,0);
> myImage->SetNumberOfScalarComponents(1);
> myImage->SetScalarTypeToFloat();
> myImage->AllocateScalars();
> myImage->GetPointData()->SetScalars(vtkArray);
>
> int i;
> //Cube Coordinates
> static float x[8][3]={{0,0,0}, {1392,0,0}, {1392,1040,0}, {0,1040,0},
> {0,0,700}, {1392,0,700}, {1392,1040,700}, {0,1040,700}};
>
> static vtkIdType pts[6][4]={{0,1,2,3},{4,5,6,7}, {0,1,5,4},{1,2,6,5},
> {2,3,7,6}, {3,0,4,7}};
>
> // Color LookupTable
> vtkLookupTable *table = vtkLookupTable::New();
> table->SetTableRange(0,255);
> table->SetValueRange(0.0,1.0);
> table->SetSaturationRange(0.0,0.0);
> table->SetHueRange(0.0,0.0);
> table->SetAlphaRange(1.0,1.0);
> table->SetNumberOfColors(256);
> table->Build();
>
>
> // Create texture
> vtkTexture *atext = vtkTexture::New();
> atext->SetInput(myImage);
> atext->SetLookupTable(table);
> atext->InterpolateOff();
>
> // We'll create the building blocks of polydata including data attributes.
> vtkPolyData *cube = vtkPolyData::New();
> vtkPoints *points = vtkPoints::New();
> vtkCellArray *polys = vtkCellArray::New();
> vtkFloatArray *tCoords = vtkFloatArray::New();
>
> tCoords->SetNumberOfComponents(2);
> tCoords->InsertTuple2(0, 0, 0);
> tCoords->InsertTuple2(1, 1, 0);
> tCoords->InsertTuple2(2, 1, 1);
> tCoords->InsertTuple2(3, 0, 1);
> tCoords->InsertTuple2(4, 0, 0);
> tCoords->InsertTuple2(5, 1, 0);
> tCoords->InsertTuple2(6, 1, 1);
> tCoords->InsertTuple2(7, 0, 1);
>
> // Load the point, cell, and data attributes.
> for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
> for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
>
> // We now assign the pieces to the vtkPolyData.
> cube->SetPoints(points);
> points->Delete();
> cube->SetPolys(polys);
> polys->Delete();
> cube->GetPointData()->SetTCoords(tCoords);
> tCoords->Delete();
>
>
> vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
> cubeMapper->SetInput(cube);
> vtkActor *cubeActor = vtkActor::New();
> cubeActor->SetMapper(cubeMapper);
> cubeActor->SetTexture(atext);
>
> // The usual rendering stuff.
> vtkCamera *camera = vtkCamera::New();
> camera->SetPosition(1,1,1);
> camera->SetFocalPoint(0,0,0);
>
> vtkRenderer *renderer = vtkRenderer::New();
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(renderer);
>
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> vtkWidget->SetRenderWindow(renWin);
>
> renderer->AddActor(cubeActor);
> renderer->SetActiveCamera(camera);
> renderer->ResetCamera();
> renderer->SetBackground(0.4,0.5,0.6);
>
> //interact with data
> renWin->Render();
> iren->Start();
>
> with kind regards
> Andy
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> _______________________________________________
> 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
>
--
Wesley D. Turner, Ph.D.
Kitware, Inc.
Technical Leader
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4920
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091124/62cf1a3f/attachment.htm>
More information about the vtkusers
mailing list