1

I have a 3 dimensional array(named V). it contains voxel information. Where ever there is a voxel present, the value of V[i][j][k] is 1. where ever there is no voxel present, the value of V[i][j][k] is 0 I want to visualise this shape using VTK.

i have written this code:

MyVTKPointPlotter pointPlotter;

for(int i=0;i<x_count;i++)
{
   for(int j=0;j<y_count;j++)
   {
      for(int k=0;k<z_count;k++)
      {
         if(V[i][j][k] != 0)
         {
             pointPlotter.PlotPoint(i,j,k,128,128,128);
         }
      }
   }
}

Note: the functions MyVTKPointPlotter are all obtained from this link: http://nawigacjarobota.googlecode.com/svn-history/r10/trunk/wykObMAT/myVTKPointPlotter.cpp

The problem in this code is that all the points are getting plotted but the rendering is extremely slow. Also the points are 2 dimentional points and hence they do not have thickness. So when i rotate my object, i can see points with no thickness(the points are seen as disks).

Can anyone tell me how to visualise this 3D shape?

  • Instead of using a plotter, can you just instantiate a 3D object (as a sphere) in the position of each point to plot? First of all, it would be a 3D representation, and maybe the computation will also be faster. See here for how to instantiate a sphere: http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Sphere and just change the setCenter() method using, at each iteration, your i, j and k. – Andrea Nov 21 '13 at 15:08
  • The sphere aproach has the disadvantage of having an actor for each sphere. Is better to follow a similar solution: a Point cloud – El Marce Nov 22 '13 at 14:12

1 Answers1

0

If your voxels are all together forming big concentrations, you may use an isosurface visualization: http://www.evl.uic.edu/aspale/cs526/final/3-5-2-0.htm. If the previous is to complicated, google it, there are quite a few examples on how to do this.

OR

If your white voxels are scattered, I think you may want to create an Point cloud.

I had this code in Python that I modify to fit your questions code. Translate to your languaje (This is NOT tested, but will get you the idea):

points = vtk.vtkPoints()
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)

#Create the point cloud 
for i in xrange(0, x_count):
   for j in xrange(0, y_count):
      for k in xrange(0, z_count):
         if V[i][j][k] != 0:
            #If they are many points better use the faster combination of
            #SetPointCount and SetPoint methods 
            points.InsertNextPoint(i, j, k)
            colors.InsertNextTuple3(128, 128, 128)  



pointsPolyData = vtk.vtkPolyData()
vertexFilter = vtk.vtkVertexGlyphFilter()
polyData = vtk.vtkPolyData()

mapper = vtk.vtkPolyDataMapper()
actor = vtk.vtkActor()
actor.GetProperty().SetPointSize(5)

pointsPolyData.SetPoints(points)
vertexFilter.SetInputConnection(pointsPolyData.GetProducerPort())
polyData.ShallowCopy(vertexFilter.GetOutput())
polyData.GetPointData().SetScalars(colors)
mapper.SetInputConnection(polyData.GetProducerPort())
actor.SetMapper(mapper)


//Then you'll have to add the actor to your renderer, of course
myRenderer.AddViewProp(actor)
El Marce
  • 3,144
  • 1
  • 26
  • 40
  • Thank you El Marce.. I tried as you told me.. I guess that my voxel cloud is not dense enough and hence when i zoom the rendered shape, i can see gaps in between the voxels... i tried to create a surface over the points.. but i guess for that, we need hollow contours instead of filled ones.. this is what i did: first took the edge map of the countours(referenced to Z axis) Then created a surface using info on this link: http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/SurfaceFromUnorganizedPoints it has come quite neat... Huge thanks to you... :) – Utkarsh Deshmukh Nov 27 '13 at 12:16
  • If you liked the answer you may vote it up ;) Glad it helps. I'm checking out your solution. You also may post it stackoverflow.com, it will help the community! – El Marce Dec 02 '13 at 14:01