Fraxinus  17.12-rc1
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) 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 #include "cxDataInterface.h"
33 #include "cxImage.h"
34 #include <QSet>
35 #include "cxMesh.h"
36 #include "cxImageLUT2D.h"
37 #include "cxTrackingService.h"
38 #include "cxTypeConversions.h"
39 #include "cxDefinitionStrings.h"
40 #include "cxTool.h"
41 #include "cxImageAlgorithms.h"
43 #include "cxLogger.h"
44 #include "cxActiveImageProxy.h"
45 #include "cxVideoSource.h"
46 #include "cxVideoService.h"
47 #include "cxPatientModelService.h"
48 #include "cxActiveToolProxy.h"
49 #include "cxActiveData.h"
50 
51 namespace cx
52 {
54  mActiveTool(activeTool)
55 {
57 }
58 
60 {
61  return mActiveTool->getTool()->getTooltipOffset();
62 }
63 
65 {
66  mActiveTool->getTool()->setTooltipOffset(val);
67  return true;
68 }
69 
71 {
72  double range = 200;
73  return DoubleRange(0,range,1);
74 }
75 
76 //---------------------------------------------------------
77 //---------------------------------------------------------
78 //---------------------------------------------------------
79 
81  mTool(tool)
82 {
83  this->setTool(tool);
84 }
85 
87 {
88  if (mTool)
89  disconnect(mTool.get(), &Tool::tooltipOffset, this, &Property::changed);
90  mTool = tool;
91  if (mTool)
92  connect(mTool.get(), &Tool::tooltipOffset, this, &Property::changed);
93  emit changed();
94 }
95 
97 {
98  return mTool->getTooltipOffset();
99 }
100 
102 {
103  mTool->setTooltipOffset(val);
104  return true;
105 }
106 
108 {
109  double range = 200;
110  return DoubleRange(0,range,1);
111 }
112 
113 
114 //---------------------------------------------------------
115 //---------------------------------------------------------
116 //---------------------------------------------------------
117 
119  mActiveData(activeData)
120 {
122  connect(mActiveImageProxy.get(), &ActiveImageProxy::activeImageChanged, this, &DoublePropertyActiveImageBase::activeImageChanged);
124 }
125 void DoublePropertyActiveImageBase::activeImageChanged()
126 {
127  mImage = mActiveData->getActive<Image>();
128  emit changed();
129 }
131 {
132  if (!mImage)
133  return 0.0;
134  return getValueInternal();
135 }
137 {
138  if (!mImage)
139  return false;
140  setValueInternal(val);
141  return true;
142 }
143 
144 //---------------------------------------------------------
145 //---------------------------------------------------------
146 
148 {
149  return mImage->getLookupTable2D()->getWindow();
150 }
152 {
153  mImage->getLookupTable2D()->setWindow(val);
154 }
156 {
157  if (!mImage)
158  return DoubleRange();
159  double range = mImage->getRange();
160  return DoubleRange(1,range,range/1000.0);
161 }
162 
163 //---------------------------------------------------------
164 //---------------------------------------------------------
165 
167 {
168  return mImage->getLookupTable2D()->getLevel();
169 }
171 {
172  mImage->getLookupTable2D()->setLevel(val);
173 }
175 {
176  if (!mImage)
177  return DoubleRange();
178 
179  double max = mImage->getMax();
180  return DoubleRange(1,max,max/1000.0);
181 }
182 
183 
184 //---------------------------------------------------------
185 //---------------------------------------------------------
186 //---------------------------------------------------------
187 
188 
190  mPatientModelService(patientModelService)
191 {
193 }
194 
196 {
197  if (mData)
198  disconnect(mData.get(), &Data::transformChanged, this, &Property::changed);
199  mData = data;
200  if (mData)
201  connect(mData.get(), &Data::transformChanged, this, &Property::changed);
202  emit changed();
203 }
204 
206 {
208 }
209 
211 {
212  return "Parent Frame";
213 }
214 
215 bool StringPropertyParentFrame::setValue(const QString& value)
216 {
217  if (!mData)
218  return false;
219  mData->get_rMd_History()->addParentSpace(value);
220  return true;
221 }
222 
224 {
225  if (!mData)
226  return "";
227  return qstring_cast(mData->getParentSpace());
228 }
229 
231 {
232  if (!mData)
233  return "";
234  return "Select the parent frame for " + qstring_cast(mData->getName()) + ".";
235 }
236 
238 {
239  QStringList retval;
240  retval << "";
241 
242  std::map<QString, DataPtr> allData = mPatientModelService->getDatas();
243  for (std::map<QString, DataPtr>::iterator iter=allData.begin(); iter!=allData.end(); ++iter)
244  {
245  if (mData && (mData->getUid() == iter->first))
246  continue;
247 
248  retval << qstring_cast(iter->first);
249  }
250  return retval;
251 }
252 
254 {
255  DataPtr data = mPatientModelService->getData(internal);
256  if (!data)
257  return "<no data>";
258  return qstring_cast(data->getName());
259 }
260 
261 //---------------------------------------------------------
262 //---------------------------------------------------------
263 //---------------------------------------------------------
264 
266  StringPropertyParentFrame(patientModelService)
267 {
268 }
269 
270 bool StringPropertySetParentFrame::setValue(const QString& value)
271 {
272  if (!mData)
273  return false;
274  mData->get_rMd_History()->setParentSpace(value);
275  return true;
276 }
277 
278 //---------------------------------------------------------
279 //---------------------------------------------------------
280 //---------------------------------------------------------
281 
283 {
284 }
285 
287 {
288  return "Name";
289 }
290 
292 {
293  if (!mData)
294  return false;
295  mData->setName(value);
296  return true;
297 }
298 
300 {
301  if (mData)
302  return mData->getName();
303  return "";
304 }
305 
307 {
308  mData = data;
309  emit changed();
310 }
311 
312 //---------------------------------------------------------
313 //---------------------------------------------------------
314 //---------------------------------------------------------
315 
317 {
318 }
319 
321 {
322  return "Uid";
323 }
324 
325 bool StringPropertyDataUidEditable::setValue(const QString& value)
326 {
327  return false;
328 }
329 
331 {
332  if (mData)
333  return mData->getUid();
334  return "";
335 }
336 
338 {
339  mData = data;
340  emit changed();
341 }
342 
343 //---------------------------------------------------------
344 //---------------------------------------------------------
345 //---------------------------------------------------------
346 
348  mPatientModelService(patientModelService)
349 {
351 }
352 
354 {
356 }
357 
359 {
360  if (mData)
361  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
362  mData = data;
363  if (mData)
364  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
365  emit changed();
366 }
367 
369 {
370  return "Modality";
371 }
372 
373 bool StringPropertyDataModality::setValue(const QString& value)
374 {
375  if (!mData)
376  return false;
377  mData->setModality(value);
378  return true;
379 }
380 
382 {
383  if (!mData)
384  return "";
385  return mData->getModality();
386 }
387 
389 {
390  if (!mData)
391  return "";
392  return "Select the modality for " + qstring_cast(mData->getName()) + ".";
393 }
394 
396 {
397  QStringList retval;
398  retval << "";
399  if (mData)
400  retval << mData->getModality();
401  retval << "CT" << "MR" << "US";
402  return QStringList::fromSet(QSet<QString>::fromList(retval));
403 }
404 
405 //---------------------------------------------------------
406 //---------------------------------------------------------
407 //---------------------------------------------------------
408 
410  mPatientModelService(patientModelService)
411 {
413 }
414 
416 {
417  if (mData)
418  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
419  mData = data;
420  if (mData)
421  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
422  emit changed();
423 }
424 
426 {
428 }
429 
431 {
432  return "Image Type";
433 }
434 
435 bool StringPropertyImageType::setValue(const QString& value)
436 {
437  if (!mData)
438  return false;
439  mData->setImageType(value);
440  return true;
441 }
442 
444 {
445  if (!mData)
446  return "";
447  return mData->getImageType();
448 }
449 
451 {
452  if (!mData)
453  return "";
454  return "Select the image type for " + qstring_cast(mData->getName()) + ".";
455 }
456 
458 {
459  QStringList retval;
460  retval << "";
461  if (mData)
462  {
463  retval << mData->getImageType();
464  if (mData->getModality()=="CT")
465  retval << "";
466  if (mData->getModality()=="MR")
467  retval << "T1" << "T2" << "ANGIO";
468  if (mData->getModality()=="US")
469  retval << "B-Mode" << "Angio";
470  }
471  return QStringList::fromSet(QSet<QString>::fromList(retval));
472 }
473 
474 //---------------------------------------------------------
475 //---------------------------------------------------------
476 //---------------------------------------------------------
477 
479  mPatientModelService(patientModelService)
480 {
482 }
483 
485 {
487 }
488 
490 {
491  if (mData)
492  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
493  mData = data;
494  if (mData)
495  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
496  emit changed();
497 }
498 
500 {
501  return "Set glyph orientation array";
502 }
503 
505 {
506  if (!mData)
507  return false;
508  mData->setOrientationArray(value.toStdString().c_str());
509  return true;
510 }
511 
513 {
514  if (!mData)
515  return "";
516  return mData->getOrientationArray();
517 }
518 
520 {
521  if (!mData)
522  return "";
523  return "Select which array to use for orientation of the glyphs.";
524 }
525 
527 {
528  if (!mData)
529  {
530  QStringList retval;
531  retval << "";
532  return retval;
533  }
534  return mData->getOrientationArrayList();
535 }
536 //---------------------------------------------------------
537 //---------------------------------------------------------
538 //---------------------------------------------------------
539 
541  mPatientModelService(patientModelService)
542 {
544 }
545 
547 {
549 }
550 
552 {
553  if (mData)
554  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
555  mData = data;
556  if (mData)
557  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
558  emit changed();
559 }
560 
562 {
563  return "Set glyph color array";
564 }
565 
566 bool StringPropertyGlyphColorArray::setValue(const QString& value)
567 {
568  if (!mData)
569  return false;
570  mData->setColorArray(value.toStdString().c_str());
571  return true;
572 }
573 
575 {
576  if (!mData)
577  return "";
578  return mData->getColorArray();
579 }
580 
582 {
583  if (!mData)
584  return "";
585  return "Select which array to use for coloring the glyphs.";
586 }
587 
589 {
590  if (!mData)
591  {
592  QStringList retval;
593  retval << "";
594  return retval;
595  }
596  return mData->getColorArrayList();
597 }
598 
599 //---------------------------------------------------------
600 //---------------------------------------------------------
601 //---------------------------------------------------------
602 
604  mPatientModelService(patientModelService)
605 {
607 }
608 
610 {
612 }
613 
615 {
616  if (mData)
617  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
618  mData = data;
619  if (mData)
620  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
621  emit changed();
622 }
623 
625 {
626  return "Set glyph color LUT";
627 }
628 
629 bool StringPropertyGlyphLUT::setValue(const QString& value)
630 {
631  if (!mData)
632  return false;
633  mData->setGlyphLUT(value.toStdString().c_str());
634  return true;
635 }
636 
638 {
639  if (!mData)
640  return "";
641  return mData->getGlyphLUT();
642 }
643 
645 {
646  if (!mData)
647  return "";
648  return "Select which color LUT to use for coloring the glyphs.";
649 }
650 
652 {
653  QStringList retval;
654 
655  retval <<
656  "Spectrum"<<
657  "Warm"<<
658  "Cool"<<
659  "Blues"<<
660  "Wild Flower"<<
661  "Citrus"<<
662 
663  "Brewer Diverging Purple-Orange"<<
664  "Brewer Diverging Spectral"<<
665  "Brewer Diverging Brown-Blue-Green"<<
666 
667  "Brewer Sequential Blue-Green"<<
668  "Brewer Sequential Yellow-Orange-Brown"<<
669  "Brewer Sequential Blue-Purple"<<
670 
671  "Brewer Qualitative Accent"<<
672  "Brewer Qualitative Dark2"<<
673  "Brewer Qualitative Set2"<<
674  "Brewer Qualitative Pastel2"<<
675  "Brewer Qualitative Pastel1"<<
676  "Brewer Qualitative Set1"<<
677  "Brewer Qualitative Paired"<<
678  "Brewer Qualitative Set3";
679 
680  return retval;
681 }
682 
683 
684 } // namespace cx
685 
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.
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)
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:53
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
virtual QString getDisplayName() const
name of data entity. Used for display to user.
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
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.
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:66
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:53
virtual void setData(DataPtr data)
virtual QString getDisplayName() const
name of data entity. Used for display to user.
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
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
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
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