CustusX  22.04-rc5
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
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Transform3D createTransformRotateY(const double angle)
boost::shared_ptr< class TrackedStream > TrackedStreamPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void streaming(bool on)
emitted when streaming started/stopped
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
void streaming(bool on)
emitted when streaming started/stopped
void setVideoSource(const VideoSourcePtr &videoSource)
bool hasVideo() const
virtual DoubleBoundingBox3D boundingBox() const
TrackedStream(const QString &uid, const QString &name, const ToolPtr &probe, const VideoSourcePtr &videoSource)
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
void newVideoSource(VideoSourcePtr videoSource)
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:123
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual QString getUid() const
Definition: cxData.cpp:64
void setSpaceProvider(SpaceProviderPtr spaceProvider)
Vector3D getOrigin_p() const
void setProbeTool(const ToolPtr &probeTool)
void streamChanged(QString uid)
static TrackedStreamPtr create(const QString &uid, const QString &name="")
virtual QString getName() const
Definition: cxData.cpp:69
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:149
A volumetric data set.
Definition: cxImage.h:45
virtual QString getType() const
void newTool(ToolPtr tool)
boost::shared_ptr< class VideoSource > VideoSourcePtr
Transform3D createTransformTranslate(const Vector3D &translation)
ImagePtr getChangingImage()
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.
void deleteImageToStopEmittingFrames()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
Definition of characteristics for an Ultrasound Probe Sector.
Vector3D getSpacing() const
bool isStreaming() const
Superclass for all data objects.
Definition: cxData.h:89
static QString getTypeName()
VideoSourcePtr getVideoSource()
Transform3D createTransformRotateX(const double angle)
void newFrame()
emitted when a new frame has arrived (getVtkImageData() returns something new). info/status/name/vali...
#define M_PI
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr