NorMIT-nav  22.09
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxNavigatedVideoImage.h"
14 #include <vtkImageData.h>
15 #include "cxVideoSource.h"
16 #include "cxImageLUT2D.h"
17 #include "cxSliceProxy.h"
18 namespace cx
19 {
20 NavigatedVideoImage::NavigatedVideoImage(QString uid, VideoSourcePtr source, SliceProxyPtr sliceProxy, QString name):
21  Image(uid, source->getVtkImageData(), name),
22  mSliceProxy(sliceProxy)
23 {
24  mToolPositionX = -1;
25  mToolPositionY = -1;
26  connect(source.get(), &VideoSource::newFrame, this, &NavigatedVideoImage::newFrame);
27  getLookupTable2D()->setFullRangeWinLevel(source->getVtkImageData());
28 }
29 
30 static double computeEffectiveOffset(double offset, double size)
31 {
32  if (offset >= 0)
33  {
34  return offset;
35  }
36  return size/2;
37 }
38 
45 {
46  int size[3];
47  double spacing[3];
48  mBaseImageData->GetDimensions(size);
49  mBaseImageData->GetSpacing(spacing);
50  double offsetX = computeEffectiveOffset( mToolPositionX, size[0] );
51  double offsetY = computeEffectiveOffset( mToolPositionY, size[1] );
52  Transform3D T = createTransformTranslate(Vector3D(-(size[0]-offsetX)*spacing[0], -offsetY*spacing[1], 0));
53  Transform3D Flip = createTransformScale(Vector3D(1, -1, 1)); // Video data has inverted Y axis compared to other data
54  return mSliceProxy->get_sMr().inv() * Flip * T;
55 }
56 
62 {
63  int size[3];
64  mBaseImageData->GetDimensions(size);
65  double scalefactorX =(viewport[1]-viewport[0])/(double)size[0];
66  double scalefactorY = (viewport[3]-viewport[2])/(double)size[1];
67  return std::min(scalefactorX, scalefactorY);
68 }
69 
70 void NavigatedVideoImage::newFrame()
71 {
72  double spacing[3];
73  mBaseImageData->GetSpacing(spacing);
74  if (spacing[0] != mSpacing[0] || spacing[1] != mSpacing[1] ||
75  spacing[2] != mSpacing[2] )
76  {
77  emit transformChanged();
78  }
79  emit vtkImageDataChanged();
80  mSpacing[0] = spacing[0];
81  mSpacing[1] = spacing[1];
82  mSpacing[2] = spacing[2];
83 }
84 
91 void NavigatedVideoImage::setToolPosition(double positionX, double positionY)
92 {
93  mToolPositionX = positionX;
94  mToolPositionY = positionY;
95  emit transformChanged();
96 }
97 
98 };
cx::Image::mBaseImageData
vtkImageDataPtr mBaseImageData
image data in data space
Definition: cxImage.h:170
cx::VideoSource::newFrame
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::NavigatedVideoImage::NavigatedVideoImage
NavigatedVideoImage(QString uid, VideoSourcePtr source, SliceProxyPtr sliceProxy, QString name="")
Definition: cxNavigatedVideoImage.cpp:20
cx::Image::vtkImageDataChanged
void vtkImageDataChanged(QString uid=QString())
emitted when the vktimagedata are invalidated and must be retrieved anew.
cx::createTransformScale
Transform3D createTransformScale(const Vector3D &scale_)
Definition: cxTransform3D.cpp:157
cx::NavigatedVideoImage::computeFullViewZoomFactor
virtual double computeFullViewZoomFactor(DoubleBoundingBox3D viewport) const
Compute the largest zoom factor that will still fit the entire video image in the given viewport.
Definition: cxNavigatedVideoImage.cpp:61
cx::NavigatedVideoImage::setToolPosition
virtual void setToolPosition(double, double)
Set the position of the tool point in the video image.
Definition: cxNavigatedVideoImage.cpp:91
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
cx::VideoSourcePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
Definition: cxForwardDeclarations.h:109
cxVideoSource.h
cx::Image::getLookupTable2D
virtual ImageLUT2DPtr getLookupTable2D()
Definition: cxImage.cpp:316
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::NavigatedVideoImage::get_rMd
virtual Transform3D get_rMd() const
Definition: cxNavigatedVideoImage.cpp:44
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cx::createTransformTranslate
Transform3D createTransformTranslate(const Vector3D &translation)
Definition: cxTransform3D.cpp:164
cxSliceProxy.h
cxNavigatedVideoImage.h
cxImageLUT2D.h
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42