[vtkusers] displaying 3D Matrix

h0ppel h0ppel at web.de
Wed Aug 17 02:42:30 EDT 2011


Hi, 

I want to display a 3d Matrix given in a jagged array...

This is my code until now:

            int i, j, k;

            int[][][] Matrix;
            var rand = new Random(100);

            var x = 100; var y = 200; var z = 35;
            var size = x * y * z * sizeof(int);

            Matrix = new int[x][][];

            for ( i = 0; i < x; i++)
            {
                Matrix[i] = new int[y][];

                for ( j = 0; j < y; j++)
                {
                    Matrix[i][j] = new int[z];

                    for ( k = 0; k < z; k++)
                    {
                        Matrix[i][j][k] = rand.Next();                        
                    }
                }
            }

            vtkImageData image = new vtkImageData();

            image.SetDimensions(100, 200, 35);
            image.SetSpacing(1, 1, 1);
            image.SetOrigin(0, 0, 0);
            image.SetNumberOfScalarComponents(1);
            image.SetScalarTypeToFloat();
            image.AllocateScalars();

            unsafe
            {
                int* ptr = (int*)(image.GetScalarPointer());

                for (i = 0; i < 100; i++)
                {
                    for (j = 0; j < 200; ++j)
                    {
                        for (k = 0; k < 35; ++k)
                        {
                            *ptr++ = Matrix[i][j][k];
                        }
                    }
                }
            }

            vtkContourFilter Cfilter = new vtkContourFilter();
            Cfilter.SetInput(image);
            Cfilter.Update();

            vtkPolyDataMapper mapper = new vtkPolyDataMapper();
            mapper.SetInput(Cfilter.GetOutput());

            vtkActor actor = new vtkActor();
            actor.SetMapper(mapper);

            vtkRenderer render = new vtkRenderer();
            render.AddActor(actor);
            vtkRenderWindow renwin = new vtkRenderWindow();
           
            renwin.AddRenderer(render);
            renwin.Render();

            //Create vtkImageViewer, shows the correct image at program
start
            vtkImageViewer2 viewer = new vtkImageViewer2();
            viewer.SetColorLevel(0.0);
            viewer.SetColorWindow(100);
            viewer.SetInput(image);
            viewer.Render(); 
        
the viewer shows me a pointcloud,
but how can I see the hole matrix in the renderwinder?

thanks



--
View this message in context: http://vtk.1045678.n5.nabble.com/displaying-3D-Matrix-tp4707038p4707038.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list