NorMIT-nav  22.09
An IGT application
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) 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 #ifndef CXDUMMYTOOL_H_
13 #define CXDUMMYTOOL_H_
14 
15 #include "cxResourceExport.h"
16 
17 #include "cxToolImpl.h"
18 #include <vector>
19 #include <QThread>
20 #include <QDateTime>
21 #include <QTimer>
22 #include "cxBoundingBox3D.h"
23 #include "vtkForwardDeclarations.h"
24 #include "cxProbeSector.h"
25 #include "cxTime.h"
26 
27 typedef boost::shared_ptr<class QTimer> QTimerPtr;
28 
29 namespace cx
30 {
31 class ToolManager;
32 
38 class cxResource_EXPORT DummyProbe: public Probe
39 {
40  Q_OBJECT
41 public:
42  virtual ~DummyProbe() {}
43  virtual bool isValid() const
44  {
45  return mProbeDefinition.getType() != ProbeDefinition::tNONE;
46  }
47  virtual QStringList getAvailableVideoSources() { return QStringList() << "active"; }
48  virtual ProbeDefinition getProbeDefinition(QString uid="active") const
49  {
50  return mProbeDefinition;
51  }
52  virtual ProbeSectorPtr getSector(QString uid="active")
53  {
54  ProbeSectorPtr retval(new ProbeSector());
55  retval->setData(this->getProbeDefinition());
56  return retval;
57  }
58  virtual VideoSourcePtr getRTSource(QString uid="active") const
59  {
60  return mVideoSource;
61  }
62 
63  virtual void setActiveStream(QString uid) {}
64  virtual QString getActiveStream() const { return mProbeDefinition.getUid(); }
65 
66  virtual void addXml(QDomNode& dataNode) {}
67  virtual void parseXml(QDomNode& dataNode) {}
68 
69  virtual QStringList getConfigIdList() const { return QStringList(); }
70  virtual QString getConfigName(QString uid) { return QString(); }
71  virtual QString getConfigId() const { return QString(); }
72  virtual QString getConfigurationPath() const { return QString(); }
73  virtual void removeCurrentConfig() {}
74  virtual void saveCurrentConfig(QString uid, QString name) {}
75 
76  virtual void applyNewConfigurationWithId(QString uid) {}
77  virtual void setTemporalCalibration(double val) {}
78  virtual void setSoundSpeedCompensationFactor(double val) {}
79  virtual void setProbeDefinition(ProbeDefinition probeDefinition)
80  {
81  mProbeDefinition = probeDefinition;
82  emit sectorChanged();
83  }
84  virtual void setRTSource(VideoSourcePtr source)
85  {
86  mVideoSource = source;
87  emit sectorChanged();
88  }
89  virtual void removeRTSource(VideoSourcePtr source)
90  {
91  if (source!=mVideoSource)
92  return;
93  mVideoSource.reset();
94  emit sectorChanged();
95  }
96 
97 private:
98  ProbeDefinition mProbeDefinition;
99  VideoSourcePtr mVideoSource;
100 };
101 
105 class cxResource_EXPORT DummyToolThread : public QThread
106 {
107  Q_OBJECT
108 public:
109  DummyToolThread(int interval, QObject* parent=NULL) : QThread(parent), mInterval(interval)
110  {
111  this->setObjectName("org.custusx.resource.core.tracking.dummytool"); // becomes the thread name
112  }
113 protected:
114  void run()
115  {
116  QTimer* timer = new QTimer;
117  timer->start(mInterval);
118  connect(timer, SIGNAL(timeout()), this, SIGNAL(ping())); // this signal will be executed in the thread of THIS, i.e. the main thread.
119  // connect(timer, SIGNAL(timeout()), this, SLOT(pong())); // this signal will be executed in the thread of THIS, i.e. the main thread.
120  exec();
121  delete timer;
122  }
124 private slots:
125  void pong()
126  {
127  std::cout << "Thread Pong " << QDateTime::currentDateTime().toString("mm:ss:zzz").toStdString() << std::endl;
128  }
129 signals:
130  void ping();
131 };
132 
133 struct cxResource_EXPORT DummyToolTestUtilities
134 {
135  static DummyToolPtr createDummyTool(ProbeDefinition probeDefinition = ProbeDefinition());
136  static ProbeDefinition createProbeDefinitionLinear(double depth=40, double width=50, Eigen::Array2i frameSize=Eigen::Array2i(80,40));
137  static ProbeDefinition createProbeDefinition(ProbeDefinition::TYPE, double depth=40, double width=50, Eigen::Array2i frameSize=Eigen::Array2i(80,40));
138 };
139 
149 class cxResource_EXPORT DummyTool : public ToolImpl
150 {
151  Q_OBJECT
152 public:
153  explicit DummyTool(const QString& uid="dummytool");
154  ~DummyTool();
155  virtual std::set<Type> getTypes() const;
156  virtual void setType(Type);
157 
158  virtual void setTransformSaveFile(const QString& filename);
159  virtual bool getVisible() const;
160  virtual QString getUid() const;
161  virtual QString getName() const;
162  virtual int getIndex() const{return 0;}
163  virtual bool isCalibrated() const;
164  virtual ProbePtr getProbe() const
165  {
166  return mProbe;
167  }
168  void setProbeSector( ProbeDefinition probeDefinition )
169  {
170  mProbeDefinition = probeDefinition;
171  mProbe.reset(new DummyProbe());
172  mProbe->setProbeDefinition(mProbeDefinition);
173  emit toolProbeSector();
174  }
176  {
177  mProbe = probe;
178  mProbeDefinition = probe->getProbeDefinition();
179  emit toolProbeSector();
180  }
181  virtual double getTimestamp() const { return getMilliSecondsSinceEpoch(); }
182 
183  void startTracking(int interval=33);
184  void stopTracking();
185 
186  void setToolPositionMovement(const std::vector<Transform3D>& positions);
187  void setToolPositionMovementBB(const DoubleBoundingBox3D& bb);
188  std::vector<Transform3D> createToolPositionMovementTranslationOnly(const DoubleBoundingBox3D& bb) const;
189  std::vector<Transform3D> getToolPositionMovement();
190  void set_prMt(const Transform3D& ptMt);
191  void setVisible(bool val);
192 
193  // virtual double getTooltipOffset() const;
194  // virtual void setTooltipOffset(double val);
195  virtual Transform3D getCalibration_sMt() const;
196 
197  virtual std::map<QString, Vector3D> getReferencePoints() const {return std::map<QString, Vector3D>();};
198 
199  static vtkPolyDataPtr createPolyData(double h1, double h2, double r1, double r2);
200 
201 private slots:
202  virtual void sendTransform();
203 
204 private:
205  void stopThread();
206  void createPolyData();
207  std::vector<Transform3D> createToolPositionMovement(const DoubleBoundingBox3D& bb) const;
208  Transform3D* getNextTransform();
209  void createLinearMovement(std::vector<Transform3D>* retval, Transform3D* T_in, const Transform3D& R, const Vector3D& a, const Vector3D& b, double step) const;
210 
211  bool mVisible;
212  QString mTransformSaveFileName;
213  QTimerPtr mTimer;
214  std::vector<Transform3D> mTransforms;
215 
216  static int mTransformCount;
217  // Type mType;
218  std::set<Type> mTypes;
219  ProbeDefinition mProbeDefinition;
220  ProbePtr mProbe;
221  DummyToolThread* mThread;
222 };
223 typedef boost::shared_ptr<DummyTool> DummyToolPtr;
224 }//namespace cx
225 #endif /* CXDUMMYTOOL_H_ */
cx::ProbeDefinition
Definition of characteristics for an Ultrasound Probe Sector.
Definition: cxProbeDefinition.h:101
cx::DummyToolThread::DummyToolThread
DummyToolThread(int interval, QObject *parent=NULL)
Definition: cxDummyTool.h:109
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::DummyProbe::isValid
virtual bool isValid() const
Definition: cxDummyTool.h:43
cx::DummyProbe::setActiveStream
virtual void setActiveStream(QString uid)
Definition: cxDummyTool.h:63
cx::DummyProbe::getConfigurationPath
virtual QString getConfigurationPath() const
Definition: cxDummyTool.h:72
cx::DummyProbe::getRTSource
virtual VideoSourcePtr getRTSource(QString uid="active") const
Return a VideoSource for the given uid. Use 'active' to get the default stream.
Definition: cxDummyTool.h:58
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DummyToolThread::run
void run()
Definition: cxDummyTool.h:114
cx::DummyTool::getReferencePoints
virtual std::map< QString, Vector3D > getReferencePoints() const
Definition: cxDummyTool.h:197
cx::ProbeDefinition::TYPE
TYPE
Definition: cxProbeDefinition.h:104
cx::getMilliSecondsSinceEpoch
double getMilliSecondsSinceEpoch()
Definition: cxTime.cpp:44
cx::DummyProbe::getAvailableVideoSources
virtual QStringList getAvailableVideoSources()
Return a list of all available video source. The default is one with uid=='active'.
Definition: cxDummyTool.h:47
cx::DummyToolTestUtilities
Definition: cxDummyTool.h:133
cxBoundingBox3D.h
cx::VideoSourcePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
Definition: cxForwardDeclarations.h:109
cx::DummyTool
Implementation of a Tool used for testing.
Definition: cxDummyTool.h:149
cx::DummyProbe::setRTSource
virtual void setRTSource(VideoSourcePtr source)
Definition: cxDummyTool.h:84
cx::ProbeSectorPtr
boost::shared_ptr< class ProbeSector > ProbeSectorPtr
Definition: cxForwardDeclarations.h:57
cx::DummyToolThread
Definition: cxDummyTool.h:105
cx::DummyProbe::parseXml
virtual void parseXml(QDomNode &dataNode)
Definition: cxDummyTool.h:67
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::DummyProbe::setProbeDefinition
virtual void setProbeDefinition(ProbeDefinition probeDefinition)
Definition: cxDummyTool.h:79
cx::DummyProbe::applyNewConfigurationWithId
virtual void applyNewConfigurationWithId(QString uid)
Definition: cxDummyTool.h:76
cx::DummyProbe::getConfigIdList
virtual QStringList getConfigIdList() const
Definition: cxDummyTool.h:69
cx::DummyProbe::setTemporalCalibration
virtual void setTemporalCalibration(double val)
Definition: cxDummyTool.h:77
cx::ProbeDefinition::tNONE
@ tNONE
undefined
Definition: cxProbeDefinition.h:104
vtkForwardDeclarations.h
cx::DummyTool::getProbe
virtual ProbePtr getProbe() const
Definition: cxDummyTool.h:164
cx::Probe
US Probe interface.
Definition: cxProbe.h:32
cx::DummyToolThread::mInterval
int mInterval
Definition: cxDummyTool.h:123
cx::DummyProbe::removeRTSource
virtual void removeRTSource(VideoSourcePtr source)
Definition: cxDummyTool.h:89
cx::DummyProbe::addXml
virtual void addXml(QDomNode &dataNode)
Definition: cxDummyTool.h:66
cx::DummyProbe::getProbeDefinition
virtual ProbeDefinition getProbeDefinition(QString uid="active") const
Return a ProbeDefinition for the given uid. Use 'active' to get the default.
Definition: cxDummyTool.h:48
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cxToolImpl.h
cx::DummyProbe::removeCurrentConfig
virtual void removeCurrentConfig()
remove the current config from disk
Definition: cxDummyTool.h:73
cx::DummyProbe
Definition: cxDummyTool.h:38
cx::ProbeSector
Utility functions for drawing an US Probe sector.
Definition: cxProbeSector.h:38
cxTime.h
cx::DummyProbe::getConfigId
virtual QString getConfigId() const
Definition: cxDummyTool.h:71
cx::DummyProbe::getConfigName
virtual QString getConfigName(QString uid)
Definition: cxDummyTool.h:70
cx::DummyTool::setProbeSector
void setProbeSector(ProbeDefinition probeDefinition)
Definition: cxDummyTool.h:168
cxProbeSector.h
cx::DummyProbe::setSoundSpeedCompensationFactor
virtual void setSoundSpeedCompensationFactor(double val)
Definition: cxDummyTool.h:78
cx::DummyProbe::getActiveStream
virtual QString getActiveStream() const
Definition: cxDummyTool.h:64
cx::DummyProbe::getSector
virtual ProbeSectorPtr getSector(QString uid="active")
Definition: cxDummyTool.h:52
QTimerPtr
boost::shared_ptr< class QTimer > QTimerPtr
Definition: cxDummyTool.h:27
cx::DummyTool::setProbeSector
void setProbeSector(ProbePtr probe)
Definition: cxDummyTool.h:175
cx::DummyProbe::~DummyProbe
virtual ~DummyProbe()
Definition: cxDummyTool.h:42
cx::ToolImpl
Common functionality for Tool subclasses.
Definition: cxToolImpl.h:30
cx::DummyProbe::saveCurrentConfig
virtual void saveCurrentConfig(QString uid, QString name)
save current config to disk under ids (uid,name).
Definition: cxDummyTool.h:74
cx::DummyTool::getIndex
virtual int getIndex() const
Definition: cxDummyTool.h:162
cx::DummyTool::getTimestamp
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools)
Definition: cxDummyTool.h:181
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::DummyToolPtr
boost::shared_ptr< class DummyTool > DummyToolPtr
Definition: cxForwardDeclarations.h:44
cx::ProbePtr
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72