[vtkusers] Visualizing 2D array of data in VTK

Asad Mahmood asadthemahmood at gmail.com
Fri Mar 19 23:40:53 EDT 2010


Hi,

I'm fairly new to VTK so I was wondering what was the best way to visualize
a 1D array of doubles in a grid format. Thinking that a 3D grid would be the
best way to represent the data, I first converted the 1D array to a 3D
array:

    double V1array[ ][ ][ ] = new double[numRows][numColumns][1];
    int k = 0;
    for (int a=0; a<numRows; a++){
        for (int b=0; b<numColumns; b++){
            for (int c=0; c<1; c++){
              V1array[a][b][c] = Varr1[k];
              k+=1;
            }
        }
    }

I then created an instance of vtkStructuredGrid, set its dimensions as
numRows, numColumns and 0 and then added the data to the grid through
vtkPoints:

   vtkStructuredGrid V1 = new vtkStructuredGrid();
   V1.SetDimensions(numRows, numColumns, 0);
    vtkPoints points = new vtkPoints();
    for (int a=0; a<numRows; a++){
        for (int b=0; b<numColumns; b++){
            for(int c=0; c<1; c++){
                points.InsertNextPoint(V1array[a][b][c],0,0);
            }
        }
    }
    V1.SetPoints(points);

I then set the geometry of the grid with StructuredGridGeometryFilter and a
gridMapper and set the Actor, Renderer and Render Window:

    vtkStructuredGridGeometryFilter plane = new
vtkStructuredGridGeometryFilter();
    plane.SetInput(V1);


    vtkPolyDataMapper sgridMapper = new vtkPolyDataMapper();
    sgridMapper.SetInputConnection(plane.GetOutputPort());

    vtkActor sgridActor = new vtkActor();
    sgridActor.SetMapper(sgridMapper);
    sgridActor.GetProperty().SetRepresentationToWireframe();
    sgridActor.GetProperty().SetColor(0, 0, 0);

    vtkRenderer renderer = new vtkRenderer();
    vtkRenderWindow renWin = new vtkRenderWindow();
    renWin.AddRenderer(renderer);

    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin);

    renderer.AddActor(sgridActor);
    renderer.SetBackground(1,1,1);
    renderer.ResetCamera();
    renWin.SetSize(500,500);

    renWin.Render();
    iren.Start();

However, all I get is a white screen for my render window and not a numRows
X numColumns grid containing my data points. Any suggestions on how to fix
my code and get a properly dimensioned grid of data? I intend on then using
a LookUp Table to color code the data points in the grid so I first need a
grid filled with all the data.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100319/f546b5b3/attachment.htm>


More information about the vtkusers mailing list