NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxNavigatedVideoImage.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include "cxNavigatedVideoImage.h"
35 #include <vtkImageData.h>
36 #include "cxVideoSource.h"
37 #include "cxImageLUT2D.h"
38 #include "cxSliceProxy.h"
39 namespace cx
40 {
41 NavigatedVideoImage::NavigatedVideoImage(QString uid, VideoSourcePtr source, SliceProxyPtr sliceProxy, QString name):
42  Image(uid, source->getVtkImageData(), name),
43  mSliceProxy(sliceProxy)
44 {
45  mToolPositionX = -1;
46  mToolPositionY = -1;
47  connect(source.get(), &VideoSource::newFrame, this, &NavigatedVideoImage::newFrame);
48  getLookupTable2D()->setFullRangeWinLevel(source->getVtkImageData());
49 }
50 
51 static double computeEffectiveOffset(double offset, double size)
52 {
53  if (offset >= 0)
54  {
55  return offset;
56  }
57  return size/2;
58 }
59 
66 {
67  int size[3];
68  double spacing[3];
69  mBaseImageData->GetDimensions(size);
70  mBaseImageData->GetSpacing(spacing);
71  double offsetX = computeEffectiveOffset( mToolPositionX, size[0] );
72  double offsetY = computeEffectiveOffset( mToolPositionY, size[1] );
73  Transform3D T = createTransformTranslate(Vector3D(-(size[0]-offsetX)*spacing[0], -offsetY*spacing[1], 0));
74  Transform3D Flip = createTransformScale(Vector3D(1, -1, 1)); // Video data has inverted Y axis compared to other data
75  return mSliceProxy->get_sMr().inv() * Flip * T;
76 }
77 
83 {
84  int size[3];
85  mBaseImageData->GetDimensions(size);
86  double scalefactorX =(viewport[1]-viewport[0])/(double)size[0];
87  double scalefactorY = (viewport[3]-viewport[2])/(double)size[1];
88  return std::min(scalefactorX, scalefactorY);
89 }
90 
91 void NavigatedVideoImage::newFrame()
92 {
93  double spacing[3];
94  mBaseImageData->GetSpacing(spacing);
95  if (spacing[0] != mSpacing[0] || spacing[1] != mSpacing[1] ||
96  spacing[2] != mSpacing[2] )
97  {
98  emit transformChanged();
99  }
100  emit vtkImageDataChanged();
101  mSpacing[0] = spacing[0];
102  mSpacing[1] = spacing[1];
103  mSpacing[2] = spacing[2];
104 }
105 
112 void NavigatedVideoImage::setToolPosition(double positionX, double positionY)
113 {
114  mToolPositionX = positionX;
115  mToolPositionY = positionY;
116  emit transformChanged();
117 }
118 
119 };
virtual void setToolPosition(double, double)
Set the position of the tool point in the video image.
Transform3D createTransformScale(const Vector3D &scale_)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
void transformChanged()
emitted when transform is changed
NavigatedVideoImage(QString uid, VideoSourcePtr source, SliceProxyPtr sliceProxy, QString name="")
virtual double computeFullViewZoomFactor(DoubleBoundingBox3D viewport) const
Compute the largest zoom factor that will still fit the entire video image in the given viewport...
A volumetric data set.
Definition: cxImage.h:66
boost::shared_ptr< class VideoSource > VideoSourcePtr
Transform3D createTransformTranslate(const Vector3D &translation)
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
void vtkImageDataChanged()
emitted when the vktimagedata are invalidated and must be retrieved anew.
virtual Transform3D get_rMd() const
vtkImageDataPtr mBaseImageData
image data in data space
Definition: cxImage.h:189
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
virtual ImageLUT2DPtr getLookupTable2D()
Definition: cxImage.cpp:337