[vtkusers] Color Scalars
David Thompson
david.thompson at kitware.com
Tue Jul 16 20:41:07 EDT 2013
Hi Patrick,
Most probably, the scalars are being reported as unsigned char values between 0 and 255. If so, when you call
[[[[geomBMP GetOutput] GetPointData] GetScalars] GetClassName]
you will see it return "vtkUnsignedCharArray."
David
> Dear VTK Users,
>
> I am trying to process the color content of BMP images. I use the following Tcl/Tk script to load and process a BMP file. The scalar data reported from the poly data is shown below the code and the saved poly data shown below that. While the saved poly data has the desired color scalar values the value generated using GetPointData is something I don't understand. Can someone assist me in using the correct command to access the color scalars.
>
> Thanks for your help.
>
> Patrick
>
> CODE
> # Create the RenderWindow, Renderer and Interactor
> #
> catch {load vtktcl}
>
> # Get the interactor ui
> # VTK 4.0
> package require vtk
> package require vtkinteraction
>
> #source voi.tcl
>
> vtkRenderer ren1
> vtkRenderWindow renWin
> renWin AddRenderer ren1
> vtkRenderWindowInteractor iren
> iren SetRenderWindow renWin
>
> toplevel .debug
> text .debug.t -height 20 -width 60 -background white
> pack .debug.t
>
> vtkBMPReader readBMP
> readBMP SetFileName "TstCore1.bmp"
> readBMP Update
> set dim [[readBMP GetOutput] GetExtent]
> .debug.t insert end "Extent: $dim\n" ; update
>
> vtkDataSetMapper mapBMP
> mapBMP SetInput [readBMP GetOutput]
> mapBMP ScalarVisibilityOn
> vtkActor actorBMP
> actorBMP SetMapper mapBMP
> ren1 AddActor actorBMP
>
> vtkImageDataGeometryFilter geomBMP
> geomBMP SetInput [readBMP GetOutput]
> geomBMP SetExtent 0 1000000 0 1000000 0 0
> geomBMP Update
> for {set i 0} {$i < 1000} {incr i} {
> set scalrange [[[[geomBMP GetOutput] GetPointData] GetScalars] GetValue $i]
> .debug.t insert end "Scalar: $i $scalrange\n" ; update
> }
> vtkPolyDataWriter polyWriter
> polyWriter SetInput [geomBMP GetOutput]
> polyWriter SetFileName "OBsurf.vtk"
> # polyWriter SetFileTypeToBinary
> polyWriter Write
>
> ren1 SetBackground 1.0 1.0 1.0
> renWin SetSize 1000 1000
> [ren1 GetActiveCamera] SetViewUp 0.0 1.0 1.0
> [ren1 GetActiveCamera] Elevation 0.0
> [ren1 GetActiveCamera] Zoom 1.5
>
> # render the image
> #
> iren Initialize
> #iren SetUserMethod {wm deiconify .vtkInteract}
>
> SCALARS OUTPUT FROM CODE
> Scalar: 0 70
> Scalar: 1 71
> Scalar: 2 89
> Scalar: 3 78
> Scalar: 4 81
> Scalar: 5 96
> Scalar: 6 118
> Scalar: 7 122
> Scalar: 8 134
> Scalar: 9 139
> Scalar: 10 143
> Scalar: 11 152
> Scalar: 12 130
> Scalar: 13 151
> Scalar: 14 152
>
> SCALARS IN OUTPUT FILE
> POINT_DATA 241902
> COLOR_SCALARS BMPImage 3
> 0.27451 0.278431 0.34902 0.305882 0.317647 0.376471 0.462745 0.478431 0.52549
> 0.545098 0.560784 0.596078 0.509804 0.592157 0.596078
> 0.329412 0.384314 0.388235 0.298039 0.305882 0.301961
> 0.313725 0.278431 0.258824 0.286275 0.215686 0.160784
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list