CustusX  18.04
An IGT application
cxFilterImpl.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 
12 #include "cxFilterImpl.h"
13 
14 #include "cxImage.h"
16 #include "cxDoubleProperty.h"
17 #include "cxDoublePairProperty.h"
18 #include "cxStringProperty.h"
19 #include "cxPatientModelService.h"
20 #include "cxVisServices.h"
21 
22 namespace cx
23 {
24 
26  mActive(false), mServices(services)
27 {
28 }
29 
31 {
32  return mServices->patient();
33 }
34 
35 QString FilterImpl::getUid() const
36 {
37  if (mUid.isEmpty())
38  return this->getType();
39  return mUid;
40 }
41 
42 void FilterImpl::initialize(QDomElement root, QString uid)
43 {
44  if (!uid.isEmpty())
45  mUid = uid;
46 
47  mOptions = root;
48 }
49 
50 std::vector<PropertyPtr> FilterImpl::getOptions()
51 {
52  if (mOptionsAdapters.empty())
53  {
54  this->createOptions();
55  }
56  return mOptionsAdapters;
57 }
58 
59 std::vector<SelectDataStringPropertyBasePtr> FilterImpl::getInputTypes()
60 {
61  if (mInputTypes.empty())
62  {
63  this->createInputTypes();
64  }
65 
66  return mInputTypes;
67 }
68 
69 std::vector<SelectDataStringPropertyBasePtr> FilterImpl::getOutputTypes()
70 {
71  if (mOutputTypes.empty())
72  {
73  this->createOutputTypes();
74  }
75 
76  return mOutputTypes;
77 }
78 
79 void FilterImpl::setActive(bool on)
80 {
81  mActive = on;
82 }
83 
84 
86 {
87 // std::cout << "FilterImpl::preProcess " << mInputTypes.size() << std::endl;
88 
89  mCopiedInput.clear();
90  for (unsigned i=0; i<mInputTypes.size(); ++i)
91  {
92  mCopiedInput.push_back(mInputTypes[i]->getData());
93  }
94 
95  mCopiedOptions = mOptions.cloneNode(true).toElement();
96 
97  // clear output
98  for (unsigned i=0; i<mOutputTypes.size(); ++i)
99  mOutputTypes[i]->setValue("");
100 
101  return true;
102 }
103 
105 {
106  if (mCopiedInput.size() < index+1)
107  return ImagePtr();
108  return boost::dynamic_pointer_cast<Image>(mCopiedInput[index]);
109 }
110 
112 {
113  ImagePtr image = mServices->patient()->getData<Image>(uid);
114  if(!image)
115  return;
116  threshold->setValueRange(DoubleRange(image->getMin(), image->getMax(), 1));
117  int oldLower = threshold->getValue();
118  // avoid reset if old value is still within range,
119  // but reset anyway if old val is 0..1, this can indicate old image was binary.
120  if ((image->getMin() > oldLower )||( oldLower > image->getMax() )||( oldLower<=1 ))
121  {
122  int initLower = ::ceil(double(image->getMin()) + double(image->getRange())/10); // round up
123  threshold->setValue(initLower);
124  }
125 // std::cout << "FilterImpl::imageChangedSlot " << image->getMin() << " " << image->getMax() << std::endl;
126 // std::cout << " imageChangedSlot() " << threshold->getValue() << std::endl;
127 }
128 
130 {
131  ImagePtr image = mServices->patient()->getData<Image>(uid);
132  if(!image)
133  return;
134  threshold->setValueRange(DoubleRange(image->getMin(), image->getMax(), 1));
135 
136  int initLower = ::ceil(double(image->getMin()) + double(image->getRange())/10); // round up
137  int initUpper = image->getMax();
138  threshold->setValue(Eigen::Vector2d(initLower, initUpper));
139 }
140 
141 
142 } // namespace cx
143 
virtual void initialize(QDomElement root, QString uid="")
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:73
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:80
virtual std::vector< SelectDataStringPropertyBasePtr > getOutputTypes()
Vector3D ceil(const Vector3D &a)
Definition: cxVector3D.cpp:84
virtual void createInputTypes()=0
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
virtual bool preProcess()
void updateThresholdPairFromImageChange(QString uid, DoublePairPropertyPtr threshold)
FilterImpl(VisServicesPtr services)
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
std::vector< DataPtr > mCopiedInput
Definition: cxFilterImpl.h:79
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:75
VisServicesPtr mServices
Definition: cxFilterImpl.h:82
PatientModelServicePtr patientService()
A volumetric data set.
Definition: cxImage.h:45
virtual std::vector< PropertyPtr > getOptions()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
ImagePtr getCopiedInputImage(int index=0)
virtual void setActive(bool on)
virtual void createOptions()=0
QDomElement mOptions
Definition: cxFilterImpl.h:76
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
virtual QString getUid() const
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:74
boost::shared_ptr< class DoublePairProperty > DoublePairPropertyPtr
virtual std::vector< SelectDataStringPropertyBasePtr > getInputTypes()
virtual void createOutputTypes()=0
void updateThresholdFromImageChange(QString uid, DoublePropertyPtr threshold)
virtual QString getType() const =0
Namespace for all CustusX production code.