[Paraview] Re: Volume Splatting: vtkCSCSPointSprites and GLU linking problems

Jordi Campos i Miralles jcampos at maia.ub.es
Tue Jun 26 16:03:58 EDT 2007


Hi John,

     1. Solving minor issues about vtkPointSpritesMapper
             1. Cleaning: OK, I wait... thanks!
             2. Resource dir: Understood, I corrected my examples.
             3. Python wrapping:
                      * I updated CMakeList.txt to generate the Python
                        wrapper and translated the example into Python
                        language (it will be easier to test, and at the
                        end I will convert it back to Cxx). [the files
                        are listed below #1 and #2]
     2. vtkVolumeSplattingMapper
             1. Splatting "sets of voxels": trying to use ColorLUT
                     1. I tried to use a ColorLUT without success, I
                        attach the file below #3. What am I doing wrong?
             2. Splatting "image data": to be solve after the previous
                issue.
     3. Creating a Paraview plugin:
              * I'm interested in investing some time with Paraview, so
                if you send me the current PV-attached-code I could try
                to start deriving a plugin. At least, I can try to
                "prepare it" and ask for help.
              * I'm suggesting my research group to migrate to VTK
                +Paraview, so I should learn as much as possible ;)

The following listed files are below:
- 1 CMakeList.txt to generate Python wrapper
- 2 Python example
- 3 Trying to use a ColorLUT

Thanks one more time,

jor;)i

PS: I still send copies to both list in case anybody else is interested
in something similar. In the other hand, when one start facing VTK, one
appreciates each "piece" of code found in forum messages, specially in
python ;)


[ CMakeList.txt to generate Python wrapper ------------------------ #1 ]

IF(VTK_WRAP_PYTHON)
  INCLUDE(${VTK_CMAKE_DIR}/vtkWrapPython.cmake)
  VTK_WRAP_PYTHON3(${PROJECT_NAME}Python vtkCSCSPointSpritesPYTHON_SRCS "${vtkCSCSPointSprites_SRCS}")
  ADD_LIBRARY(${PROJECT_NAME}PythonD ${vtkCSCSPointSpritesPYTHON_SRCS})
  ADD_LIBRARY(${PROJECT_NAME}Python MODULE ${PROJECT_NAME}PythonInit.cxx)
  TARGET_LINK_LIBRARIES(${PROJECT_NAME}PythonD ${PROJECT_NAME})

  FOREACH(c ${vtkCSCSPointSprites_LIBS})
    TARGET_LINK_LIBRARIES(${PROJECT_NAME}PythonD ${c}PythonD)
  ENDFOREACH(c)
  TARGET_LINK_LIBRARIES(${PROJECT_NAME}Python ${PROJECT_NAME}PythonD)
ENDIF(VTK_WRAP_PYTHON)


[ Python example -------------------------------------------------- #2 ]
#!/usr/bin/python
#                                                    201-PointsToSprites.py
# execution:
# PYTHONPATH=$PYTHONPATH:<pathto-libvtkCSCSPointSpritesPython.so> python <script> <resources>
# PYTHONPATH=$PYTHONPATH:vtkPointSprites/bin python 201-PointsToSprites.py vtkPointSprites/bin/resources

import vtk, os, sys
from   vtk     import *

if os.name == 'posix': from libvtkCSCSPointSpritesPython import *
else:                  from    vtkCSCSPointSpritesPython import *

SHADERS   = True  # alpha-size(shaders=T, sprites=F)
SPRITES   = False # alpha(shaders=F, sprites=T) squares(shaders=sprites=F)
ROWS      = 10
NUMVOXELS = ROWS*ROWS*ROWS

try: resources = sys.argv[1]                         # Resources dir
except Exception: sys.exit("\n<resources-dir> argument required\n");
os.environ["USER_MATERIALS_DIRS"]=resources

points = vtkPoints()                                 # Coordinates
points.SetNumberOfPoints(NUMVOXELS)

sizes = vtkFloatArray()                              # Sizes
sizes.SetName("PointSizes")
sizes.SetNumberOfTuples(NUMVOXELS)
sizes.SetNumberOfComponents(1)

alpha = vtkFloatArray()                              # Alphas
alpha.SetName("Alpha")
alpha.SetNumberOfTuples(NUMVOXELS)
alpha.SetNumberOfComponents(1)

for z in range(0, ROWS):                             # Fill arrays
  for y in range(0, ROWS):
    for x in range(0, ROWS):
      id = z*ROWS*ROWS + y*ROWS + x   ; points.SetPoint(id, x, y, z)
      sizes.SetValue(id, .1 + .04 * z);  alpha.SetValue(id, 1. - .05 * z)

voxels = vtkPolyData()                               # Voxels =
voxels.SetPoints(points);                            #  coordinates
voxels.GetPointData().AddArray(sizes);               #  + sizes
voxels.GetPointData().AddArray(alpha);               #  + alphas

sColor = vtkElevationFilter()                        # ColorLUT
sColor.SetInput(voxels)
sColor.SetLowPoint ( 0.0, 0.0, 0.0)
sColor.SetHighPoint( ROWS, ROWS, 0.0)

mapper = vtkPointSpriteMapper()                      # Mapper
mapper.SetInputConnection(sColor.GetOutputPort())
mapper.SetResourceDirectory(resources)
mapper.SetImmediateModeRendering(1)
mapper.SetRadiusChannelArray("PointSizes")
mapper.SetAlphaChannelArray("Alpha")
mapper.SelectColorArray("Elevation")
mapper.SetEnableDepthSort(1)
if   SHADERS:
  mapper.SetRenderModeToShadingLanguage()
  mapper.SetDefaultRadius(0.0001)
elif SPRITES:
  image = resources + "/sphere_64x64.png"
  mapper.SetParticleImageFileName(image)
  mapper.SetParticleImage(None)
  mapper.SetRenderModeToPointSprite()
  mapper.SetBlendModeToOcclude()
  mapper.SetDefaultPointSize(64)
  mapper.SetQuadraticPointDistanceAttenuation(1.0, 0.1, 0.0)

actor = vtkActor()                                   # Actor
actor.SetMapper(mapper)

ren = vtkRenderer()                                  # Renderer
ren.AddActor(actor)

renWin = vtkRenderWindow()                           # Window
renWin.SetSize(512, 512)
renWin.AddRenderer(ren)

iren = vtkRenderWindowInteractor()                   # Interactor
iren.SetRenderWindow(renWin)

iren.Initialize()
iren.Start()




[ Trying to use a ColorLUT --------------------------------------- #3 ]
(file equal to the above one, but with the following differences:)
densities = vtkUnsignedCharArray()                   # Densities
densities.SetName("Densities")
densities.SetNumberOfTuples(NUMVOXELS)
densities.SetNumberOfComponents(1)

for z in range(0, ROWS):                             # Fill arrays
  for y in range(0, ROWS):
    for x in range(0, ROWS):
      id = z*ROWS*ROWS + y*ROWS + x
      points.SetPoint(id, x, y, z)
      densities.SetValue(id, 10 + z * 20 )

voxels = vtkPolyData()                               # Voxels =
voxels.SetPoints(points);                            #  coordinates
voxels.GetPointData().AddArray(densities);           #  + densities
voxels.GetPointData().SetActiveScalars("Densities")

colorTF = vtkColorTransferFunction()                 # Color (RGB-TF)
colorTF.AddRGBPoint(  0, 0, 1, 0)
colorTF.AddRGBPoint(255, 1, 0, 0)

mapper = vtkPointSpriteMapper()                      # Mapper
mapper.SetInput(voxels)
mapper.SetResourceDirectory(resources)
mapper.SetImmediateModeRendering(1)

mapper.SetLookupTable( colorTF )                     # Trying ColorLUT
mapper.SetScalarRange( densities.GetRange(0) )
mapper.UseLookupTableScalarRangeOn()
mapper.ScalarVisibilityOn()
mapper.SetColorModeToMapScalars()





El dt 26 de 06 del 2007 a les 12:15 +0200, en/na John Biddiscombe va
escriure:
> Jordi
> 
> 
> >      1. Solving minor issues about vtkPointSpritesMapper
> >              1. Cleaning: you said, you had planned to clean it. So, I
> >                 could wait the "code cleaning" before continue working
> >                 on it.
> >   
> 
> I'll let you know when it is clean. Won't take long to do, but I have 
> other things to finish first.
> 
> >              2. Resource dir: I left the resource dir setting in blank,
> >                 because even if I set it to the correct path, I obtain
> >                 an "vtkXMLShader (0x806cd58): Failed to locate file
> >                 *.glsl". It seems it founds correctly the *.xml, but
> >                 afterwards I need to be in the resources directory to
> >                 let it find the *.glsl
> >   
> NB. The resource dir is used by the sprite render to fetch the textuer, 
> but when in GLSL mode, you have to pick up the shaders. Look at the 
> tests and see that at the start they set an environment var which is 
> then picked up in vtkXMLShader or somewhere - this makes sure the xml 
> code gets the correct resource dir. I should have documented the 
> difference. - but now I've done it :)
> >      2. Adapting the current vtkPointSpritesMapper to some kind of
> >         vtkVolumeSplattingMapper
> >              1. Splatting "sets of voxels": could be done with the
> >                 current PolyData container, but
> >                      1. Use color/opacity transfer functions instead of
> >                         Elevation
> >              2. Splatting "image data": think about the mapper
> >                 adaptation.
> >   
> 
> No comment on this for now
> 
> >      3. Creating a Paraview plugin
> >              1. I'm just entering into Paraview arquitecture (I left my
> >                 notes in the tutorial I mentioned before); but I would
> >                 be interested in helping to create the Paraview plugin.
> >
> > So, if it is possible to join some efforts with other "Volume Splatting
> > interested people", it would be great.
> >   
> 
> I have the mapper running in ParaView CVS head. I will have a think 
> about how to make a plug-in - or at least a distribution that is 
> reasonably self contained..
> I welcome help....The learning curve for PV internals is quite steep - 
> you will want to invest some time in it.
> 
> JB
> 
> 
-- 
Jordi Campos i Miralles
Departament de Matemàtica Aplicada i Anàlisi, MAiA
Facultat de Matemàtiques, Universitat de Barcelona
Gran Via de les Corts Catalanes, 585
08007 Barcelona
Telf : +34 93 403 93 72 



More information about the ParaView mailing list