Fraxinus  18.10
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  //TODO: Check if we need to turn this on/off
121  if (mImage && mVideoSource && mVideoSource->isStreaming())
122  {
123  mImage->setVtkImageData(mVideoSource->getVtkImageData(), false);
124  emit newFrame();
125  }
126 }
127 
129 {
130  return mVideoSource;
131 }
132 
134 {
135  mSpaceProvider = spaceProvider;
136 }
137 
138 void TrackedStream::addXml(QDomNode &dataNode)
139 {
140  Data::addXml(dataNode);
141 }
142 
143 void TrackedStream::parseXml(QDomNode &dataNode)
144 {
145  Data::parseXml(dataNode);
146 }
147 
149 {
150  DoubleBoundingBox3D bounds;
151  if(this->hasVideo())
152  bounds = DoubleBoundingBox3D(mVideoSource->getVtkImageData()->GetBounds());
153  return bounds;
154 }
155 
156 QString TrackedStream::getType() const
157 {
158  return getTypeName();
159 }
160 
162 {
163  return "trackedStream";
164 }
165 
167 {
168  if(!mVideoSource)
169  return ImagePtr();
170  if (!mImage)
171  mImage = ImagePtr(new Image(this->getUid()+"_TrackedStreamHelper", mVideoSource->getVtkImageData(), this->getName()+"_TrackedStreamHelper"));
172  return mImage;
173 }
174 
176 {
177  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 3) )
178  return true;
179  else
180  return false;
181 }
182 
184 {
185  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 2) )
186  return true;
187  else
188  return false;
189 }
190 
192 {
193  if(!mVideoSource || !mVideoSource->getVtkImageData())
194  return false;
195  return true;
196 }
197 
199 {
200  if (this->hasVideo())
201  return mVideoSource->isStreaming();
202  return false;
203 }
204 
205 } //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.
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:88
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