[vtkusers] color a mesh with another scalar

yi mu mugjfyi at yahoo.com
Tue Sep 12 00:24:25 EDT 2006


I am trying to color a mesh with another scalar, bu no matter how hard I tried, I always get a dull gray, I am using the approach described in the VTK user guide (p. 86, 5.1) I guessed my problem is the example is used to color isosurface, but what I have is mesh generate from points cloud, any suggestion? I have been struggle for a while, so any help will be appreciated!
 
 
 
 # Read some points. Use a programmable filter to read them.
 #
 vtkProgrammableSource pointSource
     pointSource SetExecuteMethod readPoints
     
 
 
  vtkDoubleArray colorArray
      colorArray SetName "HU"
      vtkPoints points
 
 proc readPoints {} {
 
     set output [pointSource GetPolyDataOutput]
     # vtkPoints points
     $output SetPoints points
     
    set file [open "data/elm-1.dat" r]
    while { [gets $file line] != -1 } {
          scan $line "%f %f %f %f %f %f %f %f %f" x y z head v1 v2 v3 v4 v5
          points InsertNextPoint $x $y $head
          colorArray InsertNextValue [expr $head/10000*5]
    
  
    }
    
    points Delete; #okay, reference counting
 }
 
 
 [[pointSource GetPolyDataOutput] GetPointData] SetScalars colorArray
 
       
 vtkSurfaceReconstructionFilter surf
     surf SetInput [pointSource GetPolyDataOutput]
 
 vtkContourFilter cf
     cf SetInputConnection [surf GetOutputPort]
     cf SetValue 0 0.0
 
 # Sometimes the contouring algorithm can create a volume whose gradient
 # vector and ordering of polygon (using the right hand rule) are 
 # inconsistent. vtkReverseSense cures this problem.
 vtkReverseSense reverse
   reverse SetInputConnection [cf GetOutputPort]
   reverse ReverseCellsOn
   reverse ReverseNormalsOn
 
 vtkPolyDataMapper map
     map SetInputConnection [reverse GetOutputPort]
     map ScalarVisibilityOn
   
     map SetScalarRange 0 1.5 //range for data in colorArray
      map SetScalarModeToUsePointFieldData
     map ColorByArrayComponent "HU" 0
 
 
 vtkLODActor surfaceActor
     surfaceActor SetMapper map
 
     
 
 
 # Create the RenderWindow, Renderer and both Actors
 #
 vtkRenderer ren1
 vtkRenderWindow renWin
     renWin AddRenderer ren1
 vtkRenderWindowInteractor iren
     iren SetRenderWindow renWin
 
 # Add the actors to the renderer, set the background and size
 #
 ren1 AddActor surfaceActor
 ren1 SetBackground 1 1 1
 renWin SetSize 400 400
 [ren1 GetActiveCamera] SetFocalPoint 0 0 0
 [ren1 GetActiveCamera] SetPosition 1 0 0
 [ren1 GetActiveCamera] SetViewUp 0 0 1
 ren1 ResetCamera
 [ren1 GetActiveCamera] Azimuth 20
 [ren1 GetActiveCamera] Elevation 30
 [ren1 GetActiveCamera] Dolly 1.2
 ren1 ResetCameraClippingRange
 
 # render the image
 #
 iren AddObserver UserEvent {wm deiconify .vtkInteract}
 
 renWin Render
 
 # prevent the tk window from showing up then start the event loop
 wm withdraw .
 
 
 
 
 		
---------------------------------
 All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060911/9ae3be1d/attachment.htm>


More information about the vtkusers mailing list