CustusX  15.4.0-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "cxEnumConverter.h"
41 #include "cxTool.h"
42 #include "cxImageAlgorithms.h"
44 #include "cxLogger.h"
45 #include "cxActiveImageProxy.h"
46 #include "cxVideoSource.h"
47 #include "cxVideoService.h"
48 #include "cxPatientModelService.h"
49 #include "cxActiveToolProxy.h"
50 
51 //TODO: remove
52 #include "cxLegacySingletons.h"
53 
54 namespace cx
55 {
57 {
60 }
61 
63 {
64  return mActiveTool->getTool()->getTooltipOffset();
65 }
66 
68 {
69  mActiveTool->getTool()->setTooltipOffset(val);
70  return true;
71 }
72 
74 {
75  double range = 200;
76  return DoubleRange(0,range,1);
77 }
78 
79 //---------------------------------------------------------
80 //---------------------------------------------------------
81 //---------------------------------------------------------
82 
84  mPatientModelService(patientModelService)
85 {
86  mActiveImageProxy = ActiveImageProxy::New(patientModelService);
87  connect(mActiveImageProxy.get(), &ActiveImageProxy::activeImageChanged, this, &DoublePropertyActiveImageBase::activeImageChanged);
89 }
90 void DoublePropertyActiveImageBase::activeImageChanged()
91 {
92  mImage = mPatientModelService->getActiveImage();
93  emit changed();
94 }
96 {
97  if (!mImage)
98  return 0.0;
99  return getValueInternal();
100 }
102 {
103  if (!mImage)
104  return false;
105  setValueInternal(val);
106  return true;
107 }
108 
109 //---------------------------------------------------------
110 //---------------------------------------------------------
111 
113 {
114  return mImage->getLookupTable2D()->getWindow();
115 }
117 {
118  mImage->getLookupTable2D()->setWindow(val);
119 }
121 {
122  if (!mImage)
123  return DoubleRange();
124  double range = mImage->getRange();
125  return DoubleRange(1,range,range/1000.0);
126 }
127 
128 //---------------------------------------------------------
129 //---------------------------------------------------------
130 
132 {
133  return mImage->getLookupTable2D()->getLevel();
134 }
136 {
137  mImage->getLookupTable2D()->setLevel(val);
138 }
140 {
141  if (!mImage)
142  return DoubleRange();
143 
144  double max = mImage->getMax();
145  return DoubleRange(1,max,max/1000.0);
146 }
147 
151 
153  mPatientModelService(patientModelService)
154 {
156 }
157 
159 {
161 }
162 
164 {
165  std::map<QString, VideoSourcePtr> streams = mPatientModelService->getStreams();
166  QStringList retval;
167  retval << "<no real time source>";
168  std::map<QString, VideoSourcePtr>::iterator it = streams.begin();
169  for (; it !=streams.end(); ++it)
170  retval << qstring_cast(it->second->getUid());
171  return retval;
172 }
173 
175 {
176  VideoSourcePtr rtSource = mPatientModelService->getStream(internal);
177  if (!rtSource)
178  return "<no real time source>";
179  return qstring_cast(rtSource->getName());
180 }
181 //---------------------------------------------------------
182 //---------------------------------------------------------
183 //---------------------------------------------------------
184 
186 {
188 }
189 
191 {
192  return "Stream";
193 }
194 
196 {
197  if (value == this->getValue())
198  return false;
199  videoService()->setActiveVideoSource(value);
200  emit changed();
201  return true;
202 }
203 
205 {
206  return videoService()->getActiveVideoSource()->getUid();
207 }
208 
210 {
211  std::vector<VideoSourcePtr> sources = videoService()->getVideoSources();
212  QStringList retval;
213  for (unsigned i=0; i<sources.size(); ++i)
214  retval << sources[i]->getUid();
215  return retval;
216 }
217 
219 {
220  return "Select the active video source.";
221 }
222 
223 
224 //---------------------------------------------------------
225 //---------------------------------------------------------
226 //---------------------------------------------------------
227 
228 
230  StringPropertySelectRTSourceBase(patientModelService),
231  mValueName("Select Real Time Source")
232 {
233  connect(patientModelService.get(), &PatientModelService::streamLoaded, this, &StringPropertySelectRTSource::setDefaultSlot);
234  this->setDefaultSlot();
235 }
236 
238 {
239  return mValueName;
240 }
241 
242 bool StringPropertySelectRTSource::setValue(const QString& value)
243 {
244  if(mRTSource && (mRTSource->getUid() == value))
245  return false;
246 
247  if(mRTSource)
248  disconnect(mRTSource.get(), &VideoSource::streaming, this, &Property::changed);
249 
250  VideoSourcePtr rtSource = mPatientModelService->getStream(value);
251  if(!rtSource)
252  return false;
253 
254  mRTSource = rtSource;
255  connect(mRTSource.get(), &VideoSource::streaming, this, &Property::changed);
256 
257  emit changed();
258  return true;
259 }
260 
262 {
263  if(!mRTSource)
264  return "<no real time source>";
265  return mRTSource->getUid();
266 }
267 
269 {
270  return "Select a real time source";
271 }
272 
274 {
275  return mRTSource;
276 }
277 
279 {
280  mValueName = name;
281 }
282 
283 void StringPropertySelectRTSource::setDefaultSlot()
284 {
285  std::map<QString, VideoSourcePtr> streams = mPatientModelService->getStreams();
286  std::map<QString, VideoSourcePtr>::iterator it = streams.begin();
287  if(it != streams.end())
288  {
289  this->setValue(it->first);
290  }
291 }
292 
293 
294 //---------------------------------------------------------
295 //---------------------------------------------------------
296 //---------------------------------------------------------
297 
298 
300  mPatientModelService(patientModelService)
301 {
303 }
304 
306 {
307  if (mData)
308  disconnect(mData.get(), &Data::transformChanged, this, &Property::changed);
309  mData = data;
310  if (mData)
311  connect(mData.get(), &Data::transformChanged, this, &Property::changed);
312  emit changed();
313 }
314 
316 {
318 }
319 
321 {
322  return "Parent Frame";
323 }
324 
325 bool StringPropertyParentFrame::setValue(const QString& value)
326 {
327  if (!mData)
328  return false;
329  mData->get_rMd_History()->addParentSpace(value);
330  return true;
331 }
332 
334 {
335  if (!mData)
336  return "";
337  return qstring_cast(mData->getParentSpace());
338 }
339 
341 {
342  if (!mData)
343  return "";
344  return "Select the parent frame for " + qstring_cast(mData->getName()) + ".";
345 }
346 
348 {
349  QStringList retval;
350  retval << "";
351 
352  std::map<QString, DataPtr> allData = mPatientModelService->getData();
353  for (std::map<QString, DataPtr>::iterator iter=allData.begin(); iter!=allData.end(); ++iter)
354  {
355  if (mData && (mData->getUid() == iter->first))
356  continue;
357 
358  retval << qstring_cast(iter->first);
359  }
360  return retval;
361 }
362 
364 {
365  DataPtr data = mPatientModelService->getData(internal);
366  if (!data)
367  return "<no data>";
368  return qstring_cast(data->getName());
369 }
370 
371 //---------------------------------------------------------
372 //---------------------------------------------------------
373 //---------------------------------------------------------
374 
376  StringPropertyParentFrame(patientModelService)
377 {
378 }
379 
380 bool StringPropertySetParentFrame::setValue(const QString& value)
381 {
382  if (!mData)
383  return false;
384  mData->get_rMd_History()->setParentSpace(value);
385  return true;
386 }
387 
388 //---------------------------------------------------------
389 //---------------------------------------------------------
390 //---------------------------------------------------------
391 
393 {
394 }
395 
397 {
398  return "Name";
399 }
400 
402 {
403  if (!mData)
404  return false;
405  mData->setName(value);
406  return true;
407 }
408 
410 {
411  if (mData)
412  return mData->getName();
413  return "";
414 }
415 
417 {
418  mData = data;
419  emit changed();
420 }
421 
422 //---------------------------------------------------------
423 //---------------------------------------------------------
424 //---------------------------------------------------------
425 
427 {
428 }
429 
431 {
432  return "Uid";
433 }
434 
435 bool StringPropertyDataUidEditable::setValue(const QString& value)
436 {
437  return false;
438 }
439 
441 {
442  if (mData)
443  return mData->getUid();
444  return "";
445 }
446 
448 {
449  mData = data;
450  emit changed();
451 }
452 
453 //---------------------------------------------------------
454 //---------------------------------------------------------
455 //---------------------------------------------------------
456 
458  mPatientModelService(patientModelService)
459 {
461 }
462 
464 {
466 }
467 
469 {
470  if (mData)
471  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
472  mData = data;
473  if (mData)
474  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
475  emit changed();
476 }
477 
479 {
480  return "Modality";
481 }
482 
483 bool StringPropertyDataModality::setValue(const QString& value)
484 {
485  if (!mData)
486  return false;
487  mData->setModality(value);
488  return true;
489 }
490 
492 {
493  if (!mData)
494  return "";
495  return mData->getModality();
496 }
497 
499 {
500  if (!mData)
501  return "";
502  return "Select the modality for " + qstring_cast(mData->getName()) + ".";
503 }
504 
506 {
507  QStringList retval;
508  retval << "";
509  if (mData)
510  retval << mData->getModality();
511  retval << "CT" << "MR" << "US";
512  return QStringList::fromSet(QSet<QString>::fromList(retval));
513 }
514 
515 //---------------------------------------------------------
516 //---------------------------------------------------------
517 //---------------------------------------------------------
518 
520  mPatientModelService(patientModelService)
521 {
523 }
524 
526 {
527  if (mData)
528  disconnect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
529  mData = data;
530  if (mData)
531  connect(mData.get(), &Data::propertiesChanged, this, &Property::changed);
532  emit changed();
533 }
534 
536 {
538 }
539 
541 {
542  return "Image Type";
543 }
544 
545 bool StringPropertyImageType::setValue(const QString& value)
546 {
547  if (!mData)
548  return false;
549  mData->setImageType(value);
550  return true;
551 }
552 
554 {
555  if (!mData)
556  return "";
557  return mData->getImageType();
558 }
559 
561 {
562  if (!mData)
563  return "";
564  return "Select the image type for " + qstring_cast(mData->getName()) + ".";
565 }
566 
568 {
569  QStringList retval;
570  retval << "";
571  if (mData)
572  {
573  retval << mData->getImageType();
574  if (mData->getModality()=="CT")
575  retval << "";
576  if (mData->getModality()=="MR")
577  retval << "T1" << "T2" << "ANGIO";
578  if (mData->getModality()=="US")
579  retval << "B-Mode" << "Angio";
580  }
581  return QStringList::fromSet(QSet<QString>::fromList(retval));
582 }
583 
584 } // namespace cx
QString qstring_cast(const T &val)
StringPropertyParentFrame(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.
void setValueName(const QString name)
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual DoubleRange getValueRange() const
virtual QString getValue() const
get the data value.
virtual bool setValue(const QString &value)
set 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
void streaming(bool on)
emitted when streaming started/stopped
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 bool setValue(const QString &value)
set the data value.
virtual bool setValue(const QString &value)
set the data value.
virtual double getValueInternal() const =0
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
StringPropertySelectRTSourceBase(PatientModelServicePtr patientModelService)
void transferFunctionsChanged()
virtual bool setValue(const QString &value)
set the data value.
virtual void setValueInternal(double val)=0
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
virtual bool setValue(const QString &value)
set the data value.
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
boost::shared_ptr< class Data > DataPtr
virtual double getValueInternal() const
Adapter that selects the parent frame of the given Data.
StringPropertySelectRTSource(PatientModelServicePtr patientModelService)
virtual QStringList getValueRange() const
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getValue() const
get the data value.
virtual double getValueInternal() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
void tooltipOffset(double offset)
virtual QString getValue() const
get the data value.
PatientModelServicePtr mPatientModelService
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual void setData(DataPtr data)
virtual QString getDisplayName() const
name of data entity. Used for display to user.
PatientModelServicePtr mPatientModelService
void changed()
emit when the underlying data value is changed: The user interface will be updated.
Base class for all Properties that selects a real time source.
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.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
cxLogicManager_EXPORT VideoServicePtr videoService()
virtual double getValue() const
get the data value.
StringPropertyImageType(PatientModelServicePtr patientModelService)
virtual QString getUid() const
virtual QString getValue() const
get the data value.
static ActiveImageProxyPtr New(PatientModelServicePtr patientModelService)
PatientModelServicePtr mPatientModelService
virtual double getValue() const
get the data value.
PatientModelServicePtr mPatientModelService
cxLogicManager_EXPORT TrackingServicePtr trackingService()
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual bool setValue(double val)
set the data value.
StringPropertySetParentFrame(PatientModelServicePtr patientModelService)
DoublePropertyActiveImageBase(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.
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
virtual QStringList getValueRange() const
virtual void setData(DataPtr data)
void activeVideoSourceChanged()
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.