CustusX  22.04-rc5
An IGT application
cxDataInterface.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) 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 #include "cxDataInterface.h"
12 #include "cxImage.h"
13 #include <QSet>
14 #include "cxMesh.h"
15 #include "cxImageLUT2D.h"
16 #include "cxTrackingService.h"
17 #include "cxTypeConversions.h"
18 #include "cxTool.h"
19 #include "cxImageAlgorithms.h"
21 #include "cxLogger.h"
22 #include "cxActiveImageProxy.h"
23 #include "cxVideoSource.h"
24 #include "cxVideoService.h"
25 #include "cxPatientModelService.h"
26 #include "cxActiveToolProxy.h"
27 #include "cxActiveData.h"
28 #include "cxEnumConversion.h"
29 
30 namespace cx
31 {
33  mActiveTool(activeTool)
34 {
36 }
37 
39 {
40  return mActiveTool->getTool()->getTooltipOffset();
41 }
42 
44 {
45  mActiveTool->getTool()->setTooltipOffset(val);
46  return true;
47 }
48 
50 {
51  double range = 200;
52  return DoubleRange(0,range,1);
53 }
54 
55 //---------------------------------------------------------
56 //---------------------------------------------------------
57 //---------------------------------------------------------
58 
60  mTool(tool)
61 {
62  this->setTool(tool);
63 }
64 
66 {
67  if (mTool)
68  disconnect(mTool.get(), &Tool::tooltipOffset, this, &Property::changed);
69  mTool = tool;
70  if (mTool)
71  connect(mTool.get(), &Tool::tooltipOffset, this, &Property::changed);
72  emit changed();
73 }
74 
76 {
77  return mTool->getTooltipOffset();
78 }
79 
81 {
82  mTool->setTooltipOffset(val);
83  return true;
84 }
85 
87 {
88  double range = 200;
89  return DoubleRange(0,range,1);
90 }
91 
92 
93 //---------------------------------------------------------
94 //---------------------------------------------------------
95 //---------------------------------------------------------
96 
98  mActiveData(activeData)
99 {
101  connect(mActiveImageProxy.get(), &ActiveImageProxy::activeImageChanged, this, &DoublePropertyActiveImageBase::activeImageChanged);
103 }
104 void DoublePropertyActiveImageBase::activeImageChanged()
105 {
106  mImage = mActiveData->getActive<Image>();
107  emit changed();
108 }
110 {
111  if (!mImage)
112  return 0.0;
113  return getValueInternal();
114 }
116 {
117  if (!mImage)
118  return false;
119  setValueInternal(val);
120  return true;
121 }
122 
123 //---------------------------------------------------------
124 //---------------------------------------------------------
125 
127 {
128  return mImage->getLookupTable2D()->getWindow();
129 }
131 {
132  mImage->getLookupTable2D()->setWindow(val);
133 }
135 {
136  if (!mImage)
137  return DoubleRange();
138  double range = mImage->getRange();
139  return DoubleRange(1,range,range/1000.0);
140 }
141 
142 //---------------------------------------------------------
143 //---------------------------------------------------------
144 
146 {
147  return mImage->getLookupTable2D()->getLevel();
148 }
150 {
151  mImage->getLookupTable2D()->setLevel(val);
152 }
154 {
155  if (!mImage)
156  return DoubleRange();
157 
158  double max = mImage->getMax();
159  return DoubleRange(1,max,max/1000.0);
160 }
161 
162 
163 //---------------------------------------------------------
164 //---------------------------------------------------------
165 //---------------------------------------------------------
166 
167 
169  mPatientModelService(patientModelService)
170 {
172 }
173 
175 {
176  if (mData)
177  disconnect(mData.get(), &Data::transformChanged, this, &Property::changed);
178  mData = data;
179  if (mData)
180  connect(mData.get(), &Data::transformChanged, this, &Property::changed);
181  emit changed();
182 }
183 
185 {
187 }
188 
190 {
191  return "Parent Frame";
192 }
193 
194 bool StringPropertyParentFrame::setValue(const QString& value)
195 {
196  if (!mData)
197  return false;
198  mData->get_rMd_History()->addParentSpace(value);
199  return true;
200 }
201 
203 {
204  if (!mData)
205  return "";
206  return qstring_cast(mData->getParentSpace());
207 }
208 
210 {
211  if (!mData)
212  return "";
213  return "Select the parent frame for " + qstring_cast(mData->getName()) + ".";
214 }
215 
217 {
218  QStringList retval;
219  retval << "";
220 
221  std::map<QString, DataPtr> allData = mPatientModelService->getDatas();
222  for (std::map<QString, DataPtr>::iterator iter=allData.begin(); iter!=allData.end(); ++iter)
223  {
224  if (mData && (mData->getUid() == iter->first))
225  continue;
226 
227  retval << qstring_cast(iter->first);
228  }
229  return retval;
230 }
231 
233 {
234  DataPtr data = mPatientModelService->getData(internal);
235  if (!data)
236  return "<no data>";
237  return qstring_cast(data->getName());
238 }
239 
240 //---------------------------------------------------------
241 //---------------------------------------------------------
242 //---------------------------------------------------------
243 
245  StringPropertyParentFrame(patientModelService)
246 {
247 }
248 
249 bool StringPropertySetParentFrame::setValue(const QString& value)
250 {
251  if (!mData)
252  return false;
253  mData->get_rMd_History()->setParentSpace(value);
254  emit parentChanged();
255  return true;
256 }
257 
258 //---------------------------------------------------------
259 //---------------------------------------------------------
260 //---------------------------------------------------------
261 
263 {
264 }
265 
267 {
268  return "Name";
269 }
270 
272 {
273  if (!mData)
274  return false;
275  mData->setName(value);
276  return true;
277 }
278 
280 {
281  if (mData)
282  return mData->getName();
283  return "";
284 }
285 
287 {
288  mData = data;
289  emit changed();
290 }
291 
292 //---------------------------------------------------------
293 //---------------------------------------------------------
294 //---------------------------------------------------------
295 
297 {
298 }
299 
301 {
302  return "Uid";
303 }
304 
305 bool StringPropertyDataUidEditable::setValue(const QString& value)
306 {
307  return false;
308 }
309 
311 {
312  if (mData)
313  return mData->getUid();
314  return "";
315 }
316 
318 {
319  mData = data;
320  emit changed();
321 }
322 
323 //---------------------------------------------------------
324 //---------------------------------------------------------
325 //---------------------------------------------------------
326 
328  mPatientModelService(patientModelService)
329 {
331 }
332 
334 {
336 }
337 
339 {
340  if (mData)
341  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
342  mData = data;
343  if (mData)
344  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
345  emit changed();
346 }
347 
349 {
350  return "Modality";
351 }
352 
353 bool StringPropertyDataModality::setValue(const QString& value)
354 {
355  if (!mData)
356  return false;
357  mData->setModality(string2enum<IMAGE_MODALITY>(value));
358  return true;
359 }
360 
362 {
363  if (!mData)
364  return "";
365  return enum2string(mData->getModality());
366 }
367 
369 {
370  if (!mData)
371  return "";
372  return "Select the modality for " + qstring_cast(mData->getName()) + ".";
373 }
374 
376 {
377  QStringList retval;
378  retval << "";
379  if (mData)
380  retval << enum2string(mData->getModality());
381  retval << enum2string(imCT) << enum2string(imMR) << enum2string(imUS);
382  return QStringList::fromSet(QSet<QString>::fromList(retval));
383 }
384 
385 //---------------------------------------------------------
386 //---------------------------------------------------------
387 //---------------------------------------------------------
388 
390  mPatientModelService(patientModelService)
391 {
393 }
394 
396 {
397  if (mData)
398  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
399  mData = data;
400  if (mData)
401  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
402  emit changed();
403 }
404 
406 {
408 }
409 
411 {
412  return "Image Type";
413 }
414 
415 bool StringPropertyImageType::setValue(const QString& value)
416 {
417  if (!mData)
418  return false;
419  mData->setImageType(string2enum<IMAGE_SUBTYPE>(value));
420  return true;
421 }
422 
424 {
425  if (!mData)
426  return "";
427  return enum2string(mData->getImageType());
428 }
429 
431 {
432  if (!mData)
433  return "";
434  return "Select the image type for " + qstring_cast(mData->getName()) + ".";
435 }
436 
438 {
439  QStringList retval;
440  retval << "";
441  if (mData)
442  {
443  retval << enum2string(mData->getImageType());
444  if (mData->getModality() == imCT)
445  retval << enum2string(istSEGMENTATION);
446  if (mData->getModality() == imMR)
448  if (mData->getModality() == imUS)
450  }
451  return QStringList::fromSet(QSet<QString>::fromList(retval));
452 }
453 
454 //---------------------------------------------------------
455 //---------------------------------------------------------
456 //---------------------------------------------------------
457 
459  mPatientModelService(patientModelService)
460 {
462 }
463 
465 {
467 }
468 
470 {
471  if (mData)
472  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
473  mData = data;
474  if (mData)
475  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
476  emit changed();
477 }
478 
480 {
481  return "Set glyph orientation array";
482 }
483 
485 {
486  if (!mData)
487  return false;
488  mData->setOrientationArray(value.toStdString().c_str());
489  return true;
490 }
491 
493 {
494  if (!mData)
495  return "";
496  return mData->getOrientationArray();
497 }
498 
500 {
501  if (!mData)
502  return "";
503  return "Select which array to use for orientation of the glyphs.";
504 }
505 
507 {
508  if (!mData)
509  {
510  QStringList retval;
511  retval << "";
512  return retval;
513  }
514  return mData->getOrientationArrayList();
515 }
516 //---------------------------------------------------------
517 //---------------------------------------------------------
518 //---------------------------------------------------------
519 
521  mPatientModelService(patientModelService)
522 {
524 }
525 
527 {
529 }
530 
532 {
533  if (mData)
534  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
535  mData = data;
536  if (mData)
537  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
538  emit changed();
539 }
540 
542 {
543  return "Set glyph color array";
544 }
545 
546 bool StringPropertyGlyphColorArray::setValue(const QString& value)
547 {
548  if (!mData)
549  return false;
550  mData->setColorArray(value.toStdString().c_str());
551  return true;
552 }
553 
555 {
556  if (!mData)
557  return "";
558  return mData->getColorArray();
559 }
560 
562 {
563  if (!mData)
564  return "";
565  return "Select which array to use for coloring the glyphs.";
566 }
567 
569 {
570  if (!mData)
571  {
572  QStringList retval;
573  retval << "";
574  return retval;
575  }
576  return mData->getColorArrayList();
577 }
578 
579 //---------------------------------------------------------
580 //---------------------------------------------------------
581 //---------------------------------------------------------
582 
584  mPatientModelService(patientModelService)
585 {
587 }
588 
590 {
592 }
593 
595 {
596  if (mData)
597  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
598  mData = data;
599  if (mData)
600  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
601  emit changed();
602 }
603 
605 {
606  return "Set glyph color LUT";
607 }
608 
609 bool StringPropertyGlyphLUT::setValue(const QString& value)
610 {
611  if (!mData)
612  return false;
613  mData->setGlyphLUT(value.toStdString().c_str());
614  return true;
615 }
616 
618 {
619  if (!mData)
620  return "";
621  return mData->getGlyphLUT();
622 }
623 
625 {
626  if (!mData)
627  return "";
628  return "Select which color LUT to use for coloring the glyphs.";
629 }
630 
632 {
633  QStringList retval;
634 
635  retval <<
636  "Spectrum"<<
637  "Warm"<<
638  "Cool"<<
639  "Blues"<<
640  "Wild Flower"<<
641  "Citrus"<<
642 
643  "Brewer Diverging Purple-Orange"<<
644  "Brewer Diverging Spectral"<<
645  "Brewer Diverging Brown-Blue-Green"<<
646 
647  "Brewer Sequential Blue-Green"<<
648  "Brewer Sequential Yellow-Orange-Brown"<<
649  "Brewer Sequential Blue-Purple"<<
650 
651  "Brewer Qualitative Accent"<<
652  "Brewer Qualitative Dark2"<<
653  "Brewer Qualitative Set2"<<
654  "Brewer Qualitative Pastel2"<<
655  "Brewer Qualitative Pastel1"<<
656  "Brewer Qualitative Set1"<<
657  "Brewer Qualitative Paired"<<
658  "Brewer Qualitative Set3";
659 
660  return retval;
661 }
662 
663 
664 } // namespace cx
665 
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
QString qstring_cast(const T &val)
StringPropertyParentFrame(PatientModelServicePtr patientModelService)
StringPropertyGlyphOrientationArray(PatientModelServicePtr patientModelService)
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual void setValueInternal(double val)
virtual QStringList getValueRange() const
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual QString getValue() const
get the data value.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual double getValue() const
get the data value.
istMRT1
virtual DoubleRange getValueRange() const
virtual bool setValue(const QString &value)
set the data value.
virtual bool setValue(const QString &value)
set the data value.
virtual QString getValue() const
get the data value.
StringPropertyDataModality(PatientModelServicePtr patientModelService)
imMR
virtual bool setValue(const QString &value)
set the data value.
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
void transformChanged()
emitted when transform is changed
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
istANGIO
virtual QString getDisplayName() const
name of data entity. Used for display to user.
istMRFLAIR
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
virtual bool setValue(const QString &value)
set the data value.
virtual double getValueInternal() const =0
StringPropertyGlyphLUT(PatientModelServicePtr patientModelService)
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
DoublePropertyActiveImageBase(ActiveDataPtr activeData)
virtual QString getValue() const
get the data value.
void transferFunctionsChanged()
virtual bool setValue(const QString &value)
set the data value.
virtual void setValueInternal(double val)=0
virtual QString getDisplayName() const
name of data entity. Used for display to user.
istUSBMODE
virtual bool setValue(const QString &value)
set the data value.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
boost::shared_ptr< class Data > DataPtr
virtual double getValueInternal() const
Adapter that selects the parent frame of the given Data.
virtual bool setValue(double val)
set the data value.
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
void tooltipOffset(double offset)
A volumetric data set.
Definition: cxImage.h:45
virtual QString getValue() const
get the data value.
virtual double getValueInternal() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void tooltipOffset(double offset)
DoubleRange getValueRange() const
virtual QString getValue() const
get the data value.
virtual bool setValue(const QString &value)
set the data value.
virtual QString getValue() const
get the data value.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
boost::shared_ptr< class ActiveToolProxy > ActiveToolProxyPtr
Definition: cxStatusBar.h:32
virtual void setData(DataPtr data)
virtual QString getDisplayName() const
name of data entity. Used for display to user.
istSEGMENTATION
istMRT2
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QStringList getValueRange() const
virtual QStringList getValueRange() const
virtual QString getValue() const
get the data value.
virtual QStringList getValueRange() const
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
DoublePropertyActiveToolOffset(ActiveToolProxyPtr activeTool)
virtual QStringList getValueRange() const
imUS
StringPropertyGlyphColorArray(PatientModelServicePtr patientModelService)
virtual double getValue() const
get the data value.
StringPropertyImageType(PatientModelServicePtr patientModelService)
PatientModelServicePtr mPatientModelService
PatientModelServicePtr mPatientModelService
virtual double getValue() const
get the data value.
PatientModelServicePtr mPatientModelService
PatientModelServicePtr mPatientModelService
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
virtual bool setValue(double val)
set the data value.
StringPropertySetParentFrame(PatientModelServicePtr patientModelService)
virtual QStringList getValueRange() const
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual bool setValue(const QString &value)
set the data value.
PatientModelServicePtr mPatientModelService
imCT
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
boost::shared_ptr< class Mesh > MeshPtr
virtual void setData(DataPtr data)
ActiveImageProxyPtr mActiveImageProxy
virtual DoubleRange getValueRange() const
QString enum2string(const ENUM &val)
virtual bool setValue(double val)
set the data value.
virtual void setValueInternal(double val)
PatientModelServicePtr mPatientModelService
virtual bool setValue(const QString &value)
set the data value.
virtual QString getValue() const
get the data value.
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr