Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxTrackedStream.h"
34 
35 #include <vtkImageData.h>
36 
37 #include "cxTool.h"
39 #include "cxVideoSource.h"
40 
41 #include "cxProbeSector.h"
42 #include "cxSpaceProvider.h"
43 
44 namespace cx
45 {
46 
47 TrackedStreamPtr TrackedStream::create(const QString &uid, const QString &name)
48 {
49  return TrackedStreamPtr(new TrackedStream(uid, name, ToolPtr(), VideoSourcePtr()));
50 }
51 
52 TrackedStream::TrackedStream(const QString& uid, const QString& name, const ToolPtr &probe, const VideoSourcePtr &videosource) :
53  Data(uid, name), mProbeTool(probe), mVideoSource(VideoSourcePtr()),
54  mImage(ImagePtr()),
55  mSpaceProvider(SpaceProviderPtr())
56 {
57  if(mProbeTool)
58  emit newTool(mProbeTool);
59 
60  setVideoSource(videosource);
61 }
62 
64 {
65  if(mVideoSource)
66  {
67  disconnect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
68  disconnect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
69  }
70 }
71 
72 void TrackedStream::setProbeTool(const ToolPtr &probeTool)
73 {
74  if(mProbeTool)
75  disconnect(mProbeTool.get(), &Tool::toolTransformAndTimestamp, this, &TrackedStream::toolTransformAndTimestamp);
76 
77  mProbeTool = probeTool;
78  emit newTool(mProbeTool);
79 
80  if(mProbeTool)
81  connect(mProbeTool.get(), &Tool::toolTransformAndTimestamp, this, &TrackedStream::toolTransformAndTimestamp);
82 }
83 
84 void TrackedStream::toolTransformAndTimestamp(Transform3D prMt, double timestamp)
85 {
86  //tMu calculation in ProbeSector differ from the one used here
87 // Transform3D tMu = mProbeDefinition.get_tMu();
88  Transform3D tMu = this->get_tMu();
89  Transform3D rMpr = mSpaceProvider->get_rMpr();
90  Transform3D rMu = rMpr * prMt * tMu;
91 
92  if (mImage)
93  mImage->get_rMd_History()->setRegistration(rMu);
94  emit newPosition();
95 }
96 
97 Transform3D TrackedStream::get_tMu()
98 {
99  //Made tMu by copying and modifying code from ProbeSector::get_tMu()
100  QString streamUid = mVideoSource->getUid();
101  ProbeDefinition probeDefinition = mProbeTool->getProbe()->getProbeDefinition(streamUid);
102  Vector3D origin_p = probeDefinition.getOrigin_p();
103  Vector3D spacing = probeDefinition.getSpacing();
104  Vector3D origin_u(origin_p[0]*spacing[0], origin_p[1]*spacing[1], origin_p[2]*spacing[2]);
105 
108  Transform3D R = (Rx * Ry);
109  Transform3D T = createTransformTranslate(-origin_u);
110 
111  Transform3D tMu = R * T;
112  return tMu;
113 }
114 
116 {
117  return mProbeTool;
118 }
119 
121 {
122  if(mVideoSource)
123  {
124  disconnect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
125  disconnect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
126  }
127 
128  mVideoSource = videoSource;
129  emit streamChanged(this->getUid());
130  emit newVideoSource(mVideoSource);
131 
132  if(mVideoSource)
133  {
134  connect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
135  connect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
136  }
137 }
138 
139 void TrackedStream::newFrameSlot()
140 {
141  //TODO: Check if we need to turn this on/off
142  if (mImage && mVideoSource && mVideoSource->isStreaming())
143  {
144  mImage->setVtkImageData(mVideoSource->getVtkImageData(), false);
145  emit newFrame();
146  }
147 }
148 
150 {
151  return mVideoSource;
152 }
153 
155 {
156  mSpaceProvider = spaceProvider;
157 }
158 
159 void TrackedStream::addXml(QDomNode &dataNode)
160 {
161  Data::addXml(dataNode);
162 }
163 
164 void TrackedStream::parseXml(QDomNode &dataNode)
165 {
166  Data::parseXml(dataNode);
167 }
168 
170 {
171  DoubleBoundingBox3D bounds;
172  if(this->hasVideo())
173  bounds = DoubleBoundingBox3D(mVideoSource->getVtkImageData()->GetBounds());
174  return bounds;
175 }
176 
177 QString TrackedStream::getType() const
178 {
179  return getTypeName();
180 }
181 
183 {
184  return "trackedStream";
185 }
186 
188 {
189  if(!mVideoSource)
190  return ImagePtr();
191  if (!mImage)
192  mImage = ImagePtr(new Image(this->getUid()+"_TrackedStreamHelper", mVideoSource->getVtkImageData(), this->getName()+"_TrackedStreamHelper"));
193  return mImage;
194 }
195 
197 {
198  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 3) )
199  return true;
200  else
201  return false;
202 }
203 
205 {
206  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 2) )
207  return true;
208  else
209  return false;
210 }
211 
213 {
214  if(!mVideoSource || !mVideoSource->getVtkImageData())
215  return false;
216  return true;
217 }
218 
220 {
221  if (this->hasVideo())
222  return mVideoSource->isStreaming();
223  return false;
224 }
225 
226 } //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:48
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:126
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:84
void setSpaceProvider(SpaceProviderPtr spaceProvider)
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:89
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:152
A volumetric data set.
Definition: cxImage.h:66
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.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
bool isStreaming() const
Superclass for all data objects.
Definition: cxData.h:109
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
boost::shared_ptr< class Tool > ToolPtr