[vtkusers] Show an image in true size with vtkImageViewer2
Steven Koch
SKoch at trinityconsultants.com
Fri Mar 2 10:34:47 EST 2007
I'm trying to use vtkImageViewer2 to generate texture maps of a
rectilinear grid with contour lines (to project onto terrain grids). Below
you'll see that vtkCoordinate conversion is used to 'extract' the rendered
image from the vtkRenderWindow. This has two problems for your
application: 1) the image extents change, and 2) there will be 'pixel
drift'. Can anybody suggest a way to control the rendered image size?
I will try to correct for the 'pixel drift' by using
vtkCoordinate.GetComputedDoubleDisplayValue and correcting with the
sub-pixel corrections when calling the final vtkImage.SetOutputOrigin and
vtkImage.SetOutputSpacing.
'Use vtkImageViewer2 to render images of rectilinear grid and
contour lines to use as texture maps
Dim m_vtkContourMapRenderer As New vtk.vtkImageViewer2
m_vtkContourMapRenderer.SetInput(vtkBackImage) <--- Created a
10x10 vtkImageData with appropriate Origing and Spacing
m_vtkContourMapRenderer.SetSliceOrientationToXY()
m_vtkContourMapRenderer.GetRenderer.AddActor(vtkActor1)
m_vtkContourMapRenderer.GetRenderer.AddActor(vtkActor2)
m_vtkContourMapRenderer.GetRenderWindow.PointSmoothingOn()
m_vtkContourMapRenderer.OffScreenRenderingOn()
m_vtkContourMapRenderer.SetSize(1000, 1000)
m_vtkContourMapRenderer.GetRenderer.GetActiveCamera.ParallelProjectionOn()
m_vtkContourMapRenderer.GetRenderer.ResetCamera()
\
\
\
\
'Grid data range
Dim dblRngX() As Double =
m_vtkGrid2D.GetXCoordinates.GetRange(1)
Dim dblRngY() As Double =
m_vtkGrid2D.GetYCoordinates.GetRange(1)
'Render contour map image
m_vtkContourMapRenderer.Render()
Dim vtkRenderedImage As New vtk.vtkWindowToImageFilter
vtkRenderedImage.SetInput(m_vtkContourMapRenderer.GetRenderWindow)
vtkRenderedImage.Update()
'Extract rendered image
Dim vtkCrnPt As New vtk.vtkCoordinate
vtkCrnPt.SetCoordinateSystemToWorld()
vtkCrnPt.SetValue(dblRngX(0), dblRngY(0), 0.0)
Dim intLLPix() As Integer =
vtkCrnPt.GetComputedDisplayValue(m_vtkContourMapRenderer.GetRenderer)
vtkCrnPt.SetValue(dblRngX(1), dblRngY(1), 0.0)
Dim intURPix() As Integer =
vtkCrnPt.GetComputedDisplayValue(m_vtkContourMapRenderer.GetRenderer)
Dim vtkExtract As New vtk.vtkImageClip
vtkExtract.SetInputConnection(vtkRenderedImage.GetOutputPort)
vtkExtract.ClipDataOn()
vtkExtract.SetOutputWholeExtent(intLLPix(0), intURPix(0),
intLLPix(1), intURPix(1), 0, 0)
vtkExtract.Update()
'Set the image properties
Dim intExt() As Integer = vtkExtract.GetOutput.GetExtent
Dim vtkImage As New vtk.vtkImageChangeInformation
vtkImage.SetInputConnection(vtkExtract.GetOutputPort)
vtkImage.SetOutputOrigin(dblRngX(0), dblRngY(0), 0.0)
vtkImage.SetOutputSpacing((dblRngX(1) - dblRngX(0)) /
(intExt(1) - intExt(0)), (dblRngY(1) - dblRngY(0)) / (intExt(3) -
intExt(2)), 1.0)
vtkImage.SetOutputExtentStart(0, 0, 0)
vtkImage.Update()
Steve Koch
> Hello,
>
> I'm using vtkImageViewer2 to view my datasets and sometimes I need to
view them in true size, so one pixel on the display corresponds always to
one pixel on the image. How can I achieve this with the class
vtkImageViewer2? I > know that if I use vtkImageViewer I'll get this, but
I built a more complex 2D Viewing class with vtkImageViewer2 so I want to
find a solution if possible with vtkImageViewer2.
>
> Any suggestions?
>
> Thanks in advance!
_________________________________________________________________________
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you
Received this in error, please contact the sender and delete the material
from any computer.
_________________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070302/3ec3ebd4/attachment.htm>
More information about the vtkusers
mailing list