CustusX  15.4.0-beta
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 
63 void TrackedStream::setProbeTool(const ToolPtr &probeTool)
64 {
65  if(mProbeTool)
66  disconnect(mProbeTool.get(), &Tool::toolTransformAndTimestamp, this, &TrackedStream::toolTransformAndTimestamp);
67 
68  mProbeTool = probeTool;
69  emit newTool(mProbeTool);
70 
71  if(mProbeTool)
72  connect(mProbeTool.get(), &Tool::toolTransformAndTimestamp, this, &TrackedStream::toolTransformAndTimestamp);
73 }
74 
75 void TrackedStream::toolTransformAndTimestamp(Transform3D prMt, double timestamp)
76 {
77  //tMu calculation in ProbeSector differ from the one used here
78 // Transform3D tMu = mProbeData.get_tMu();
79  Transform3D tMu = this->get_tMu();
80  Transform3D rMpr = mSpaceProvider->get_rMpr();
81  Transform3D rMu = rMpr * prMt * tMu;
82 
83  if (mImage)
84  mImage->get_rMd_History()->setRegistration(rMu);
85 }
86 
87 Transform3D TrackedStream::get_tMu()
88 {
89  //Made tMu by copying and modifying code from ProbeSector::get_tMu()
90  ProbeDefinition probeDefinition = mProbeTool->getProbe()->getProbeData();
91  Vector3D origin_p = probeDefinition.getOrigin_p();
92  Vector3D spacing = probeDefinition.getSpacing();
93  Vector3D origin_u(origin_p[0]*spacing[0], origin_p[1]*spacing[1], origin_p[2]*spacing[2]);
94 
97  Transform3D R = (Rx * Ry);
99 
100  Transform3D tMu = R * T;
101  return tMu;
102 }
103 
105 {
106  return mProbeTool;
107 }
108 
110 {
111  if(mVideoSource)
112  {
113  disconnect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrame);
114  disconnect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
115  }
116 
117  mVideoSource = videoSource;
118  emit streamChanged(this->getUid());
119  emit newVideoSource(mVideoSource);
120 
121  if(mVideoSource)
122  {
123  connect(mVideoSource.get(), &VideoSource::newFrame, this, &TrackedStream::newFrameSlot);
124  connect(mVideoSource.get(), &VideoSource::streaming, this, &TrackedStream::streaming);
125  }
126 }
127 
128 void TrackedStream::newFrameSlot()
129 {
130  //TODO: Check if we need to turn this on/off
131  if (mImage && mVideoSource)
132  {
133  mImage->setVtkImageData(mVideoSource->getVtkImageData(), false);
134  emit newFrame();
135  }
136 }
137 
139 {
140  return mVideoSource;
141 }
142 
144 {
145  mSpaceProvider = spaceProvider;
146 }
147 
148 void TrackedStream::addXml(QDomNode &dataNode)
149 {
150  Data::addXml(dataNode);
151 }
152 
153 void TrackedStream::parseXml(QDomNode &dataNode)
154 {
155  Data::parseXml(dataNode);
156 }
157 
159 {
160  DoubleBoundingBox3D bounds;
161  if(this->hasVideo())
162  bounds = DoubleBoundingBox3D(mVideoSource->getVtkImageData()->GetBounds());
163  return bounds;
164 }
165 
166 QString TrackedStream::getType() const
167 {
168  return getTypeName();
169 }
170 
172 {
173  return "TrackedStream";
174 }
175 
177 {
178  if(!mVideoSource)
179  return ImagePtr();
180  if (!mImage)
181  mImage = ImagePtr(new Image(this->getUid()+"_TrackedStreamHelper", mVideoSource->getVtkImageData(), this->getName()+"_TrackedStreamHelper"));
182  return mImage;
183 }
184 
186 {
187  if(this->hasVideo() && ( mVideoSource->getVtkImageData()->GetDataDimension() == 3) )
188  return true;
189  else
190  return false;
191 }
192 
194 {
195  if(!mVideoSource || !mVideoSource->getVtkImageData())
196  return false;
197  return true;
198 }
199 
200 } //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:120
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:78
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:83
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:146
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
Superclass for all data objects.
Definition: cxData.h:69
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