[vtkusers] How to draw a line on an image?

永强 谭 yqtan at realss.com
Wed Jan 12 22:26:50 EST 2005


Hi, vtk users,

I have trouble drawing a line on an image. I used vtkImageReslice to extract
vtkImageData and then got vtkImageActor from it. The image displayed exactly
as what i had expected. 
Now I want a line to displayed on the image, but I couldn't make it. If I
didn't show the image, the line is visible:
  ren AddProp imageSagittal; # comment this line will make the lineActor
visible
  ren AddActor lineActor

Any insight in this problem will be greately appriciated. The complete code
is here:

package require vtk
package require vtkinteraction

set xspace 3.2
set yspace 3.2
set zspace 1.5

vtkVolume16Reader reader
  reader SetDataDimensions 64 64  
  reader SetDataByteOrderToLittleEndian  
  reader SetFilePrefix "$VTK_DATA_ROOT/headsq/quarter"   
  reader SetImageRange 1 93
  reader SetDataSpacing $xspace $yspace $zspace
  reader SetDataOrigin [expr -0.5 * $xspace * 63] [expr -0.5 * $yspace * 63]
[expr -0.5 * $zspace * 92] 
  reader Update 

vtkTransform transformSagittal
  transformSagittal RotateX 0
  transformSagittal RotateY -90
  transformSagittal RotateZ 0

vtkImageReslice resliceSagittal
  resliceSagittal SetInput [reader GetOutput]
  [resliceSagittal GetInput] SetUpdateExtentToWholeExtent
  resliceSagittal SetOutputSpacing 1 1 $xspace
  resliceSagittal SetResliceTransform transformSagittal
  resliceSagittal SetOutputExtent 0 511 0 511 0 0
  resliceSagittal SetResliceAxesOrigin 0.0 0.0 0.0
  resliceSagittal SetOutputDimensionality 2
  resliceSagittal InterpolateOn
  resliceSagittal Update

vtkImageMapToWindowLevelColors sagColors
  sagColors SetInput [resliceSagittal GetOutput]
  sagColors SetWindow 2000
  sagColors SetLevel 1000

vtkImageActor imageSagittal
  imageSagittal SetInput [sagColors GetOutput]
  
vtkRenderer ren

vtkRenderWindow renWin
  renWin AddRenderer ren
  renWin SetSize 512 512

vtkRenderWindowInteractor iren
  iren SetRenderWindow renWin

vtkInteractorStyleImage styleImage
  iren SetInteractorStyle styleImage

vtkLineSource lineSource
  lineSource SetResolution 20
  lineSource SetPoint1 0 255 0
  lineSource SetPoint2 512 255 0

vtkPolyDataMapper lineMapper
  lineMapper SetInput [lineSource GetOutput]

vtkActor lineActor
  lineActor SetMapper lineMapper

  ren AddProp imageSagittal; # comment this line will make the lineActor
visible
  ren AddActor lineActor

iren Initialize



--
桃花庵歌

                           ——唐伯虎

桃花坞里桃花庵,桃花庵里桃花仙;桃花仙人种桃树,又摘桃花换酒钱。
酒醒只在花间坐,酒醉还来花下眠;半醒半醉日复日,花开花落年复年。
但愿老死花酒间,不愿鞠躬车马前;车尘马足贵者趣,酒盏花枝贫者缘。
若将贫贱比贫者,一在平地一在天;若将贫贱比车马,他得驱驰我得闲。
别人笑我忒疯癫,我笑他人看不穿;不见无陵豪杰墓,无花无酒锄作田。





More information about the vtkusers mailing list