Fraxinus  2023.01.05-dev+develop.0da12
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_ */
virtual void setProbeDefinition(ProbeDefinition probeDefinition)
Definition: cxDummyTool.h:79
virtual bool isValid() const
Definition: cxDummyTool.h:43
virtual QStringList getAvailableVideoSources()
Return a list of all available video source. The default is one with uid==&#39;active&#39;.
Definition: cxDummyTool.h:47
virtual std::map< QString, Vector3D > getReferencePoints() const
Get the optional reference points from this tool.
Definition: cxDummyTool.h:197
virtual void saveCurrentConfig(QString uid, QString name)
save current config to disk under ids (uid,name).
Definition: cxDummyTool.h:74
virtual void removeRTSource(VideoSourcePtr source)
Definition: cxDummyTool.h:89
virtual void addXml(QDomNode &dataNode)
Definition: cxDummyTool.h:66
virtual int getIndex() const
Definition: cxDummyTool.h:162
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Common functionality for Tool subclasses.
Definition: cxToolImpl.h:30
double getMilliSecondsSinceEpoch()
Definition: cxTime.cpp:44
virtual ProbeDefinition getProbeDefinition(QString uid="active") const
Return a ProbeDefinition for the given uid. Use &#39;active&#39; to get the default.
Definition: cxDummyTool.h:48
virtual QString getConfigName(QString uid)
Definition: cxDummyTool.h:70
virtual void setActiveStream(QString uid)
Definition: cxDummyTool.h:63
virtual ~DummyProbe()
Definition: cxDummyTool.h:42
virtual QStringList getConfigIdList() const
Definition: cxDummyTool.h:69
virtual QString getActiveStream() const
Definition: cxDummyTool.h:64
virtual ProbeSectorPtr getSector(QString uid="active")
Definition: cxDummyTool.h:52
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72
boost::shared_ptr< class DummyTool > DummyToolPtr
US Probe interface.
Definition: cxProbe.h:32
virtual VideoSourcePtr getRTSource(QString uid="active") const
Return a VideoSource for the given uid. Use &#39;active&#39; to get the default stream.
Definition: cxDummyTool.h:58
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools) ...
Definition: cxDummyTool.h:181
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual QString getConfigId() const
Definition: cxDummyTool.h:71
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:149
virtual void parseXml(QDomNode &dataNode)
Definition: cxDummyTool.h:67
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class ProbeSector > ProbeSectorPtr
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.
DummyToolThread(int interval, QObject *parent=NULL)
Definition: cxDummyTool.h:109
virtual QString getConfigurationPath() const
Definition: cxDummyTool.h:72
Utility functions for drawing an US Probe sector.
Definition: cxProbeSector.h:38
virtual ProbePtr getProbe() const
additional information if the tool represents an US Probe. Extends getProbeSector() ...
Definition: cxDummyTool.h:164
void setProbeSector(ProbePtr probe)
Definition: cxDummyTool.h:175
virtual void removeCurrentConfig()
remove the current config from disk
Definition: cxDummyTool.h:73
void setProbeSector(ProbeDefinition probeDefinition)
Definition: cxDummyTool.h:168
virtual void setSoundSpeedCompensationFactor(double val)
Definition: cxDummyTool.h:78
virtual void setRTSource(VideoSourcePtr source)
Definition: cxDummyTool.h:84
boost::shared_ptr< class QTimer > QTimerPtr
Definition: cxDummyTool.h:27
virtual void applyNewConfigurationWithId(QString uid)
Definition: cxDummyTool.h:76
Namespace for all CustusX production code.
virtual void setTemporalCalibration(double val)
Definition: cxDummyTool.h:77