NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxTrackedStream.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 #include "cxTrackedStream.h"
13 
14 #include <vtkImageData.h>
15 
16 #include "cxTool.h"
18 #include "cxVideoSource.h"
19 
20 #include "cxProbeSector.h"
21 #include "cxSpaceProvider.h"
22 
23 namespace cx
24 {
25 
26 TrackedStreamPtr TrackedStream::create(const QString &uid, const QString &name)
27 {
28  return TrackedStreamPtr(new TrackedStream(uid, name, ToolPtr(), VideoSourcePtr()));
29 }
30 
31 TrackedStream::TrackedStream(const QString& uid, const QString& name, const ToolPtr &probe, const VideoSourcePtr &videosource) :
32  Data(uid, name), mProbeTool(probe), mVideoSource(VideoSourcePtr()),
33  mImage(ImagePtr()),
34  mSpaceProvider(SpaceProviderPtr())
35 {
36  if(mProbeTool)
37  emit newTool(mProbeTool);
38 
39  setVideoSource(videosource);
40 }
41 
43 {
44  if(mVideoSource)
45  {
46  disconnect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
47  disconnect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
48  }
49 }
50 
51 void TrackedStream::setProbeTool(const ToolPtr &probeTool)
52 {
53  if(mProbeTool)
54  disconnect(mProbeTool.get(), &Tool::toolTransformAndTimestamp, this, &TrackedStream::toolTransformAndTimestamp);
55 
56  mProbeTool = probeTool;
57  emit newTool(mProbeTool);
58 
59  if(mProbeTool)
60  connect(mProbeTool.get(), &Tool::toolTransformAndTimestamp, this, &TrackedStream::toolTransformAndTimestamp);
61 }
62 
63 void TrackedStream::toolTransformAndTimestamp(Transform3D prMt, double timestamp)
64 {
65  //tMu calculation in ProbeSector differ from the one used here
66 // Transform3D tMu = mProbeDefinition.get_tMu();
67  Transform3D tMu = this->get_tMu();
68  Transform3D rMpr = mSpaceProvider->get_rMpr();
69  Transform3D rMu = rMpr * prMt * tMu;
70 
71  if (mImage)
72  mImage->get_rMd_History()->setRegistration(rMu);
73  emit newPosition();
74 }
75 
76 Transform3D TrackedStream::get_tMu()
77 {
78  //Made tMu by copying and modifying code from ProbeSector::get_tMu()
79  QString streamUid = mVideoSource->getUid();
80  ProbeDefinition probeDefinition = mProbeTool->getProbe()->getProbeDefinition(streamUid);
81  Vector3D origin_p = probeDefinition.getOrigin_p();
82  Vector3D spacing = probeDefinition.getSpacing();
83  Vector3D origin_u(origin_p[0]*spacing[0], origin_p[1]*spacing[1], origin_p[2]*spacing[2]);
84 
87  Transform3D R = (Rx * Ry);
89 
90  Transform3D tMu = R * T;
91  return tMu;
92 }
93 
95 {
96  return mProbeTool;
97 }
98 
100 {
101  if(mVideoSource)
102  {
103  disconnect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
104  disconnect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
105  }
106 
107  mVideoSource = videoSource;
108  emit streamChanged(this->getUid());
109  emit newVideoSource(mVideoSource);
110 
111  if(mVideoSource)
112  {
113  connect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
114  connect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
115  }
116 }
117 
118 void TrackedStream::newFrameSlot()
119 {
120  if (mImage && mVideoSource && mVideoSource->isStreaming())
121  {
122  mImage->setVtkImageData(mVideoSource->getVtkImageData(), false);
123  emit newFrame();
124  }
125 }
126 
128 {
129  return mVideoSource;
130 }
131 
133 {
134  mSpaceProvider = spaceProvider;
135 }
136 
137 void TrackedStream::addXml(QDomNode &dataNode)
138 {
139  Data::addXml(dataNode);
140 }
141 
142 void TrackedStream::parseXml(QDomNode &dataNode)
143 {
144  Data::parseXml(dataNode);
145 }
146 
148 {
149  DoubleBoundingBox3D bounds;
150  if(this->hasVideo())
151  bounds = DoubleBoundingBox3D(mVideoSource->getVtkImageData()->GetBounds());
152  return bounds;
153 }
154 
155 QString TrackedStream::getType() const
156 {
157  return getTypeName();
158 }
159 
161 {
162  return "trackedStream";
163 }
164 
166 {
167  if(!mVideoSource)
168  return ImagePtr();
169  if (!mImage)
170  mImage = ImagePtr(new Image(this->getUid()+"_TrackedStreamHelper", mVideoSource->getVtkImageData(), this->getName()+"_TrackedStreamHelper"));
171  return mImage;
172 }
173 
175 {
176  mImage = ImagePtr();
177 }
178 
180 {
181  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 3) )
182  return true;
183  else
184  return false;
185 }
186 
188 {
189  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 2) )
190  return true;
191  else
192  return false;
193 }
194 
196 {
197  if(!mVideoSource || !mVideoSource->getVtkImageData())
198  return false;
199  return true;
200 }
201 
203 {
204  if (this->hasVideo())
205  return mVideoSource->isStreaming();
206  return false;
207 }
208 
209 } //cx
cx::TrackedStream::deleteImageToStopEmittingFrames
void deleteImageToStopEmittingFrames()
Definition: cxTrackedStream.cpp:174
cx::VideoSource::newFrame
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
cx::TrackedStream::setSpaceProvider
void setSpaceProvider(SpaceProviderPtr spaceProvider)
Definition: cxTrackedStream.cpp:132
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::Data::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:123
cx::Tool::toolTransformAndTimestamp
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::TrackedStream::hasVideo
bool hasVideo() const
Definition: cxTrackedStream.cpp:195
cx::TrackedStream::getTypeName
static QString getTypeName()
Definition: cxTrackedStream.cpp:160
cx::VideoSourcePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
Definition: cxForwardDeclarations.h:109
cxVideoSource.h
cx::TrackedStream::newFrame
void newFrame()
cx::TrackedStream::streamChanged
void streamChanged(QString uid)
cx::TrackedStream::boundingBox
virtual DoubleBoundingBox3D boundingBox() const
Definition: cxTrackedStream.cpp:147
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::TrackedStream::setVideoSource
void setVideoSource(const VideoSourcePtr &videoSource)
Definition: cxTrackedStream.cpp:99
cx::TrackedStream::getVideoSource
VideoSourcePtr getVideoSource()
Definition: cxTrackedStream.cpp:127
cxTool.h
cx::TrackedStream::setProbeTool
void setProbeTool(const ToolPtr &probeTool)
Definition: cxTrackedStream.cpp:51
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::TrackedStream::TrackedStream
TrackedStream(const QString &uid, const QString &name, const ToolPtr &probe, const VideoSourcePtr &videoSource)
Definition: cxTrackedStream.cpp:31
cxRegistrationTransform.h
cx::TrackedStream::newVideoSource
void newVideoSource(VideoSourcePtr videoSource)
cx::Data::getUid
virtual QString getUid() const
Definition: cxData.cpp:64
cx::createTransformRotateX
Transform3D createTransformRotateX(const double angle)
Definition: cxTransform3D.cpp:171
cx::TrackedStream::getProbeTool
ToolPtr getProbeTool()
Definition: cxTrackedStream.cpp:94
M_PI
#define M_PI
Definition: cxReconstructParams.cpp:25
cx::TrackedStream::newTool
void newTool(ToolPtr tool)
cx::TrackedStream::is3D
bool is3D()
Definition: cxTrackedStream.cpp:179
cx::TrackedStream::newPosition
void newPosition()
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::TrackedStream::streaming
void streaming(bool on)
emitted when streaming started/stopped
cxProbeSector.h
cx::TrackedStream::~TrackedStream
~TrackedStream()
Definition: cxTrackedStream.cpp:42
cx::Data::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:149
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cx::createTransformTranslate
Transform3D createTransformTranslate(const Vector3D &translation)
Definition: cxTransform3D.cpp:164
cx::TrackedStream::is2D
bool is2D()
Definition: cxTrackedStream.cpp:187
cx::createTransformRotateY
Transform3D createTransformRotateY(const double angle)
Definition: cxTransform3D.cpp:178
cx::TrackedStream::getType
virtual QString getType() const
Definition: cxTrackedStream.cpp:155
cx::Data
Superclass for all data objects.
Definition: cxData.h:89
cx::TrackedStream::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxTrackedStream.cpp:142
cx::TrackedStream::getChangingImage
ImagePtr getChangingImage()
Definition: cxTrackedStream.cpp:165
cx::TrackedStream::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxTrackedStream.cpp:137
cx::VideoSource::streaming
void streaming(bool on)
emitted when streaming started/stopped
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::TrackedStreamPtr
boost::shared_ptr< class TrackedStream > TrackedStreamPtr
Definition: cxStreamPropertiesWidget.h:22
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23
cx::TrackedStream::isStreaming
bool isStreaming() const
Definition: cxTrackedStream.cpp:202
cxSpaceProvider.h
cx::TrackedStream::create
static TrackedStreamPtr create(const QString &uid, const QString &name="")
Definition: cxTrackedStream.cpp:26
cxTrackedStream.h