[vtkusers] color a mesh with another scalar

yi mu mugjfyi at yahoo.com
Tue Sep 12 19:39:01 EDT 2006


I didn't work, I guess I try to associate the
colorArray to the vtkPolyData by doing:

[[pointSource GetPolyDataOutput] GetPointData]
 SetScalars colorArray

and pass the [pointSource GetPolyDataOutput] to the
surfaceReconstructure filter, for some reason, the
array did not get associated with the vtkPolyData. 
How to assoicate the array with the PolyData
correctly? any suggestion?

Thanks,

Yi

--- Naim <naim at electromagneticworks.com> wrote:

> Hi,
> 
> Try "SetScalarModeToUsePointData"  instead
> "SetScalarModeToUsePointFieldData".
> 
>  
> 
> Naim Himrane
> 
> Electromagnetic Works Inc.
> 
>  
> 
>   _____  
> 
> From:
>
vtkusers-bounces+naim=electromagneticworks.com at vtk.org
>
[mailto:vtkusers-bounces+naim=electromagneticworks.com at vtk.org]
> On Behalf Of
> yi mu
> Sent: September 12, 2006 12:24 AM
> To: vtkusers at vtk.org
> Subject: [vtkusers] color a mesh with another scalar
> 
>  
> 
> 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
>
<http://us.rd.yahoo.com/evt=43256/*http:/advision.webevents.yahoo.com/mailbe
> ta>  Yahoo! Mail - Fire up a more powerful email and
> get things done faster.
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the vtkusers mailing list