Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxDummyTool.h
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 #ifndef CXDUMMYTOOL_H_
34 #define CXDUMMYTOOL_H_
35 
36 #include "cxResourceExport.h"
37 
38 #include "cxToolImpl.h"
39 #include <vector>
40 #include <QThread>
41 #include <QDateTime>
42 #include <QTimer>
43 #include "cxBoundingBox3D.h"
44 #include "vtkForwardDeclarations.h"
45 #include "cxProbeSector.h"
46 #include "cxTime.h"
47 
48 typedef boost::shared_ptr<class QTimer> QTimerPtr;
49 
50 namespace cx
51 {
52 class ToolManager;
53 
59 class cxResource_EXPORT DummyProbe: public Probe
60 {
61  Q_OBJECT
62 public:
63  virtual ~DummyProbe() {}
64  virtual bool isValid() const
65  {
66  return mProbeDefinition.getType() != ProbeDefinition::tNONE;
67  }
68  virtual QStringList getAvailableVideoSources() { return QStringList() << "active"; }
69  virtual ProbeDefinition getProbeDefinition(QString uid="active") const
70  {
71  return mProbeDefinition;
72  }
73  virtual ProbeSectorPtr getSector(QString uid="active")
74  {
75  ProbeSectorPtr retval(new ProbeSector());
76  retval->setData(this->getProbeDefinition());
77  return retval;
78  }
79  virtual VideoSourcePtr getRTSource(QString uid="active") const
80  {
81  return mVideoSource;
82  }
83 
84  virtual void setActiveStream(QString uid) {}
85  virtual QString getActiveStream() const { return mProbeDefinition.getUid(); }
86 
87  virtual void addXml(QDomNode& dataNode) {}
88  virtual void parseXml(QDomNode& dataNode) {}
89 
90  virtual QStringList getConfigIdList() const { return QStringList(); }
91  virtual QString getConfigName(QString uid) { return QString(); }
92  virtual QString getConfigId() const { return QString(); }
93  virtual QString getConfigurationPath() const { return QString(); }
94  virtual void removeCurrentConfig() {}
95  virtual void saveCurrentConfig(QString uid, QString name) {}
96 
97  virtual void applyNewConfigurationWithId(QString uid) {}
98  virtual void setTemporalCalibration(double val) {}
99  virtual void setSoundSpeedCompensationFactor(double val) {}
100  virtual void setProbeDefinition(ProbeDefinition probeDefinition)
101  {
102  mProbeDefinition = probeDefinition;
103  emit sectorChanged();
104  }
105  virtual void setRTSource(VideoSourcePtr source)
106  {
107  mVideoSource = source;
108  emit sectorChanged();
109  }
110  virtual void removeRTSource(VideoSourcePtr source)
111  {
112  if (source!=mVideoSource)
113  return;
114  mVideoSource.reset();
115  emit sectorChanged();
116  }
117 
118 private:
119  ProbeDefinition mProbeDefinition;
120  VideoSourcePtr mVideoSource;
121 };
122 
126 class cxResource_EXPORT DummyToolThread : public QThread
127 {
128  Q_OBJECT
129 public:
130  DummyToolThread(int interval, QObject* parent=NULL) : QThread(parent), mInterval(interval)
131  {
132  this->setObjectName("org.custusx.resource.core.tracking.dummytool"); // becomes the thread name
133  }
134 protected:
135  void run()
136  {
137  QTimer* timer = new QTimer;
138  timer->start(mInterval);
139  connect(timer, SIGNAL(timeout()), this, SIGNAL(ping())); // this signal will be executed in the thread of THIS, i.e. the main thread.
140 // connect(timer, SIGNAL(timeout()), this, SLOT(pong())); // this signal will be executed in the thread of THIS, i.e. the main thread.
141  exec();
142  delete timer;
143  }
145 private slots:
146  void pong()
147  {
148  std::cout << "Thread Pong " << QDateTime::currentDateTime().toString("mm:ss:zzz").toStdString() << std::endl;
149  }
150 signals:
151  void ping();
152 };
153 
154 struct cxResource_EXPORT DummyToolTestUtilities
155 {
156  static DummyToolPtr createDummyTool(ProbeDefinition probeDefinition = ProbeDefinition());
157  static ProbeDefinition createProbeDefinitionLinear(double depth=40, double width=50, Eigen::Array2i frameSize=Eigen::Array2i(80,40));
158  static ProbeDefinition createProbeDefinition(ProbeDefinition::TYPE, double depth=40, double width=50, Eigen::Array2i frameSize=Eigen::Array2i(80,40));
159 };
160 
170 class cxResource_EXPORT DummyTool : public ToolImpl
171 {
172  Q_OBJECT
173 public:
174  explicit DummyTool(const QString& uid="dummytool");
175  ~DummyTool();
176  virtual std::set<Type> getTypes() const;
177  virtual void setType(Type);
178 
179  virtual vtkPolyDataPtr getGraphicsPolyData() const;
180  virtual void setTransformSaveFile(const QString& filename);
181  virtual bool getVisible() const;
182  virtual QString getUid() const;
183  virtual QString getName() const;
184  virtual int getIndex() const{return 0;}
185  virtual bool isCalibrated() const;
186  virtual ProbePtr getProbe() const
187  {
188  return mProbe;
189  }
190  void setProbeSector( ProbeDefinition probeDefinition )
191  {
192  mProbeDefinition = probeDefinition;
193  mProbe.reset(new DummyProbe());
194  mProbe->setProbeDefinition(mProbeDefinition);
195  emit toolProbeSector();
196  }
198  {
199  mProbe = probe;
200  mProbeDefinition = probe->getProbeDefinition();
201  emit toolProbeSector();
202  }
203  virtual double getTimestamp() const { return getMilliSecondsSinceEpoch(); }
204 
205  void startTracking(int interval=33);
206  void stopTracking();
207 
208  void setToolPositionMovement(const std::vector<Transform3D>& positions);
209  void setToolPositionMovementBB(const DoubleBoundingBox3D& bb);
210  std::vector<Transform3D> createToolPositionMovementTranslationOnly(const DoubleBoundingBox3D& bb) const;
211  std::vector<Transform3D> getToolPositionMovement();
212  void set_prMt(const Transform3D& ptMt);
213  void setVisible(bool val);
214 
215 // virtual double getTooltipOffset() const;
216 // virtual void setTooltipOffset(double val);
217  virtual Transform3D getCalibration_sMt() const;
218 
219  virtual std::map<int, Vector3D> getReferencePoints() const {return std::map<int, Vector3D>();};
220 
221  static vtkPolyDataPtr createPolyData(double h1, double h2, double r1, double r2);
222 
223 private slots:
224  virtual void sendTransform();
225 
226 private:
227  void stopThread();
228  void createPolyData();
229  std::vector<Transform3D> createToolPositionMovement(const DoubleBoundingBox3D& bb) const;
230  Transform3D* getNextTransform();
231  void createLinearMovement(std::vector<Transform3D>* retval, Transform3D* T_in, const Transform3D& R, const Vector3D& a, const Vector3D& b, double step) const;
232 
233  vtkPolyDataPtr mPolyData;
234  bool mVisible;
235  QString mTransformSaveFileName;
236  QTimerPtr mTimer;
237  std::vector<Transform3D> mTransforms;
238 
239  static int mTransformCount;
240 // Type mType;
241  std::set<Type> mTypes;
242  ProbeDefinition mProbeDefinition;
243  ProbePtr mProbe;
244  DummyToolThread* mThread;
245 };
246 typedef boost::shared_ptr<DummyTool> DummyToolPtr;
247 }//namespace cx
248 #endif /* CXDUMMYTOOL_H_ */
virtual void setProbeDefinition(ProbeDefinition probeDefinition)
Definition: cxDummyTool.h:100
virtual bool isValid() const
Definition: cxDummyTool.h:64
virtual QStringList getAvailableVideoSources()
Return a list of all available video source. The default is one with uid=='active'.
Definition: cxDummyTool.h:68
virtual void saveCurrentConfig(QString uid, QString name)
save current config to disk under ids (uid,name).
Definition: cxDummyTool.h:95
virtual void removeRTSource(VideoSourcePtr source)
Definition: cxDummyTool.h:110
virtual std::map< int, Vector3D > getReferencePoints() const
Get the optional reference points from this tool.
Definition: cxDummyTool.h:219
virtual void addXml(QDomNode &dataNode)
Definition: cxDummyTool.h:87
virtual int getIndex() const
Definition: cxDummyTool.h:184
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Common functionality for Tool subclasses.
Definition: cxToolImpl.h:50
double getMilliSecondsSinceEpoch()
Definition: cxTime.cpp:65
virtual ProbeDefinition getProbeDefinition(QString uid="active") const
Return a ProbeDefinition for the given uid. Use 'active' to get the default.
Definition: cxDummyTool.h:69
virtual QString getConfigName(QString uid)
Definition: cxDummyTool.h:91
virtual void setActiveStream(QString uid)
Definition: cxDummyTool.h:84
virtual ~DummyProbe()
Definition: cxDummyTool.h:63
virtual QStringList getConfigIdList() const
Definition: cxDummyTool.h:90
virtual QString getActiveStream() const
Definition: cxDummyTool.h:85
virtual ProbeSectorPtr getSector(QString uid="active")
Definition: cxDummyTool.h:73
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:93
boost::shared_ptr< class DummyTool > DummyToolPtr
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
US Probe interface.
Definition: cxProbe.h:53
virtual VideoSourcePtr getRTSource(QString uid="active") const
Return a VideoSource for the given uid. Use 'active' to get the default stream.
Definition: cxDummyTool.h:79
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools) ...
Definition: cxDummyTool.h:203
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual QString getConfigId() const
Definition: cxDummyTool.h:92
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.
Implementation of a Tool used for testing.
Definition: cxDummyTool.h:170
virtual void parseXml(QDomNode &dataNode)
Definition: cxDummyTool.h:88
boost::shared_ptr< class ProbeSector > ProbeSectorPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
Definition of characteristics for an Ultrasound Probe Sector.
DummyToolThread(int interval, QObject *parent=NULL)
Definition: cxDummyTool.h:130
virtual QString getConfigurationPath() const
Definition: cxDummyTool.h:93
Utility functions for drawing an US Probe sector.
Definition: cxProbeSector.h:59
virtual ProbePtr getProbe() const
additional information if the tool represents an US Probe. Extends getProbeSector() ...
Definition: cxDummyTool.h:186
void setProbeSector(ProbePtr probe)
Definition: cxDummyTool.h:197
virtual void removeCurrentConfig()
remove the current config from disk
Definition: cxDummyTool.h:94
void setProbeSector(ProbeDefinition probeDefinition)
Definition: cxDummyTool.h:190
virtual void setSoundSpeedCompensationFactor(double val)
Definition: cxDummyTool.h:99
virtual void setRTSource(VideoSourcePtr source)
Definition: cxDummyTool.h:105
boost::shared_ptr< class QTimer > QTimerPtr
Definition: cxDummyTool.h:48
virtual void applyNewConfigurationWithId(QString uid)
Definition: cxDummyTool.h:97
virtual void setTemporalCalibration(double val)
Definition: cxDummyTool.h:98