Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
33 #include "cxFilterImpl.h"
34 
35 #include "cxImage.h"
37 #include "cxDoubleProperty.h"
38 #include "cxDoublePairProperty.h"
39 #include "cxStringProperty.h"
40 #include "cxPatientModelService.h"
41 #include "cxVisServices.h"
42 
43 namespace cx
44 {
45 
47  mActive(false), mServices(services)
48 {
49 }
50 
52 {
53  return mServices->patient();
54 }
55 
56 QString FilterImpl::getUid() const
57 {
58  if (mUid.isEmpty())
59  return this->getType();
60  return mUid;
61 }
62 
63 void FilterImpl::initialize(QDomElement root, QString uid)
64 {
65  if (!uid.isEmpty())
66  mUid = uid;
67 
68  mOptions = root;
69 }
70 
71 std::vector<PropertyPtr> FilterImpl::getOptions()
72 {
73  if (mOptionsAdapters.empty())
74  {
75  this->createOptions();
76  }
77  return mOptionsAdapters;
78 }
79 
80 std::vector<SelectDataStringPropertyBasePtr> FilterImpl::getInputTypes()
81 {
82  if (mInputTypes.empty())
83  {
84  this->createInputTypes();
85  }
86 
87  return mInputTypes;
88 }
89 
90 std::vector<SelectDataStringPropertyBasePtr> FilterImpl::getOutputTypes()
91 {
92  if (mOutputTypes.empty())
93  {
94  this->createOutputTypes();
95  }
96 
97  return mOutputTypes;
98 }
99 
101 {
102  mActive = on;
103 }
104 
105 
107 {
108 // std::cout << "FilterImpl::preProcess " << mInputTypes.size() << std::endl;
109 
110  mCopiedInput.clear();
111  for (unsigned i=0; i<mInputTypes.size(); ++i)
112  {
113  mCopiedInput.push_back(mInputTypes[i]->getData());
114  }
115 
116  mCopiedOptions = mOptions.cloneNode(true).toElement();
117 
118  // clear output
119  for (unsigned i=0; i<mOutputTypes.size(); ++i)
120  mOutputTypes[i]->setValue("");
121 
122  return true;
123 }
124 
126 {
127  if (mCopiedInput.size() < index+1)
128  return ImagePtr();
129  return boost::dynamic_pointer_cast<Image>(mCopiedInput[index]);
130 }
131 
133 {
134  ImagePtr image = mServices->patient()->getData<Image>(uid);
135  if(!image)
136  return;
137  threshold->setValueRange(DoubleRange(image->getMin(), image->getMax(), 1));
138  int oldLower = threshold->getValue();
139  // avoid reset if old value is still within range,
140  // but reset anyway if old val is 0..1, this can indicate old image was binary.
141  if ((image->getMin() > oldLower )||( oldLower > image->getMax() )||( oldLower<=1 ))
142  {
143  int initLower = ::ceil(double(image->getMin()) + double(image->getRange())/10); // round up
144  threshold->setValue(initLower);
145  }
146 // std::cout << "FilterImpl::imageChangedSlot " << image->getMin() << " " << image->getMax() << std::endl;
147 // std::cout << " imageChangedSlot() " << threshold->getValue() << std::endl;
148 }
149 
151 {
152  ImagePtr image = mServices->patient()->getData<Image>(uid);
153  if(!image)
154  return;
155  threshold->setValueRange(DoubleRange(image->getMin(), image->getMax(), 1));
156 
157  int initLower = ::ceil(double(image->getMin()) + double(image->getRange())/10); // round up
158  int initUpper = image->getMax();
159  threshold->setValue(Eigen::Vector2d(initLower, initUpper));
160 }
161 
162 
163 } // namespace cx
164 
virtual void initialize(QDomElement root, QString uid="")
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:101
virtual std::vector< SelectDataStringPropertyBasePtr > getOutputTypes()
Vector3D ceil(const Vector3D &a)
Definition: cxVector3D.cpp:105
virtual void createInputTypes()=0
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
virtual bool preProcess()
void updateThresholdPairFromImageChange(QString uid, DoublePairPropertyPtr threshold)
FilterImpl(VisServicesPtr services)
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
std::vector< DataPtr > mCopiedInput
Definition: cxFilterImpl.h:100
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:96
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
PatientModelServicePtr patientService()
A volumetric data set.
Definition: cxImage.h:66
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:97
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
virtual QString getUid() const
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:95
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