NorMIT-nav  2023.01.05-dev+develop.0da12
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 
cx::FilterImpl::setActive
virtual void setActive(bool on)
Definition: cxFilterImpl.cpp:79
cxDoublePairProperty.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FilterImpl::initialize
virtual void initialize(QDomElement root, QString uid="")
Definition: cxFilterImpl.cpp:42
cx::FilterImpl::mCopiedInput
std::vector< DataPtr > mCopiedInput
Definition: cxFilterImpl.h:79
cxImage.h
cx::FilterImpl::createOptions
virtual void createOptions()=0
cx::FilterImpl::createInputTypes
virtual void createInputTypes()=0
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cx::FilterImpl::FilterImpl
FilterImpl(VisServicesPtr services)
Definition: cxFilterImpl.cpp:25
cxDoubleProperty.h
cx::FilterImpl::mOutputTypes
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:74
cx::FilterImpl::createOutputTypes
virtual void createOutputTypes()=0
cx::FilterImpl::mInputTypes
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:73
cx::FilterImpl::mOptions
QDomElement mOptions
Definition: cxFilterImpl.h:76
cx::FilterImpl::mCopiedOptions
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:80
cx::FilterImpl::getCopiedInputImage
ImagePtr getCopiedInputImage(int index=0)
Definition: cxFilterImpl.cpp:104
cx::DoublePropertyPtr
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
Definition: cxReconstructionMethodService.h:33
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::DoublePairPropertyPtr
boost::shared_ptr< class DoublePairProperty > DoublePairPropertyPtr
Definition: cxForwardDeclarations.h:145
cxPatientModelService.h
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::FilterImpl::updateThresholdPairFromImageChange
void updateThresholdPairFromImageChange(QString uid, DoublePairPropertyPtr threshold)
Definition: cxFilterImpl.cpp:129
cx::FilterImpl::getUid
virtual QString getUid() const
Definition: cxFilterImpl.cpp:35
cx::FilterImpl::getOptions
virtual std::vector< PropertyPtr > getOptions()
Definition: cxFilterImpl.cpp:50
cxFilterImpl.h
cx::ceil
Vector3D ceil(const Vector3D &a)
Definition: cxVector3D.cpp:84
cx::FilterImpl::getInputTypes
virtual std::vector< SelectDataStringPropertyBasePtr > getInputTypes()
Definition: cxFilterImpl.cpp:59
cx::Filter::getType
virtual QString getType() const =0
cx::FilterImpl::patientService
PatientModelServicePtr patientService()
Definition: cxFilterImpl.cpp:30
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cxStringProperty.h
cxSelectDataStringProperty.h
cx::FilterImpl::preProcess
virtual bool preProcess()
Definition: cxFilterImpl.cpp:85
cx::FilterImpl::updateThresholdFromImageChange
void updateThresholdFromImageChange(QString uid, DoublePropertyPtr threshold)
Definition: cxFilterImpl.cpp:111
cx::DoubleRange
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
cx::FilterImpl::mOptionsAdapters
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:75
cx::FilterImpl::mActive
bool mActive
Definition: cxFilterImpl.h:81
cx::FilterImpl::mServices
VisServicesPtr mServices
Definition: cxFilterImpl.h:82
cx::FilterImpl::getOutputTypes
virtual std::vector< SelectDataStringPropertyBasePtr > getOutputTypes()
Definition: cxFilterImpl.cpp:69
cxVisServices.h