Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxDummyFilter.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 "cxDummyFilter.h"
34 #include "cxTypeConversions.h"
36 #include "cxData.h"
37 #include "cxDoubleProperty.h"
38 #include "cxStringProperty.h"
39 #include "cxBoolProperty.h"
40 #include "cxVisServices.h"
41 
42 namespace cx
43 {
44 
45 QString DummyFilter::getName() const
46 {
47  return "Dummy Filter";
48 }
49 
50 QString DummyFilter::getType() const
51 {
52  return "DummyFilter";
53 }
54 
55 QString DummyFilter::getHelp() const
56 {
57  return "A dummy implementation of the cx::Filter class,\n"
58  "intended for concept testing.\n"
59  "Can also be used as a template for new filters.";
60 }
61 
62 StringPropertyBasePtr DummyFilter::getStringOption(QDomElement root)
63 {
64  QStringList list;
65  list << "String0" << "String1";
66  return StringProperty::initialize("String", "", "dummy string option",
67  list[0], list, root);
68 }
69 
70 DoublePropertyBasePtr DummyFilter::getDoubleOption(QDomElement root)
71 {
72  return DoubleProperty::initialize("Value", "",
73  "dummy double value.", 1, DoubleRange(0.1, 10, 0.01), 2,
74  root);
75 }
76 
77 BoolPropertyBasePtr DummyFilter::getBoolOption(QDomElement root)
78 {
79  return BoolProperty::initialize("Bool0", "",
80  "Dummy bool value.", false, root);
81 }
82 
84 {
85  mOptionsAdapters.push_back(this->getStringOption(mOptions));
86  mOptionsAdapters.push_back(this->getDoubleOption(mOptions));
87  mOptionsAdapters.push_back(this->getBoolOption(mOptions));
88 }
89 
91 {
93 
94  temp = StringPropertySelectData::New(mServices->patient());
95  temp->setValueName("Input");
96  temp->setHelp("Dummy data input for a dummy algorithm");
97  mInputTypes.push_back(temp);
98 
99  temp = StringPropertySelectImage::New(mServices->patient());
100  temp->setValueName("Image");
101  temp->setHelp("Dummy image input for a dummy algorithm");
102  mInputTypes.push_back(temp);
103 
104  temp = StringPropertySelectMesh::New(mServices->patient());
105  temp->setValueName("Mesh");
106  temp->setHelp("Dummy mesh input for a dummy algorithm");
107  mInputTypes.push_back(temp);
108 }
109 
111 {
113 
114  temp = StringPropertySelectData::New(mServices->patient());
115  temp->setValueName("Output");
116  temp->setHelp("Dummy output from the dummy algorithm");
117  mOutputTypes.push_back(temp);
118 }
119 
121 {
122  StringPropertyBasePtr stringOption = this->getStringOption(mCopiedOptions);
123  DoublePropertyBasePtr doubleOption = this->getDoubleOption(mCopiedOptions);
124  BoolPropertyBasePtr boolOption = this->getBoolOption(mCopiedOptions);
125 
126  std::cout << "Running dummy algorithm..." << std::endl;
127  std::cout << QString(" String option [%1]: %2").arg(stringOption->getDisplayName()).arg(stringOption->getValue()) << std::endl;
128  std::cout << QString(" Double option [%1]: %2").arg(doubleOption->getDisplayName()).arg(doubleOption->getValue()) << std::endl;
129  std::cout << QString(" Bool option [%1]: %2").arg(boolOption->getDisplayName()).arg(boolOption->getValue()) << std::endl;
130 
131  for (unsigned i=0; i< mCopiedInput.size(); ++i)
132  std::cout << QString(" Input %1: %2").arg(mCopiedInput[i] ? mCopiedInput[i]->getName() : "NULL") << std::endl;
133 
134  std::cout << "Returning input as output." << std::endl;
135 
136  return true;
137 }
138 
140 {
141  //TODO: add stuff such as saving to dataManager here.
142  std::cout << "DummyFilter::postProcess " << mCopiedInput.size() << std::endl;
143 
144  if (mInputTypes.front()->getData())
145  mOutputTypes.front()->setValue(mInputTypes.front()->getData()->getUid());
146 
147  // return mInput;
148  return true;
149 }
150 
151 
152 
153 } // namespace cx
virtual void createOptions()
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:101
virtual QString getHelp() const
virtual bool postProcess()
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
std::vector< DataPtr > mCopiedInput
Definition: cxFilterImpl.h:100
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:96
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
boost::shared_ptr< class BoolPropertyBase > BoolPropertyBasePtr
virtual QString getName() const
QDomElement mOptions
Definition: cxFilterImpl.h:97
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
virtual bool execute()
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
virtual void createOutputTypes()
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:95
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
virtual void createInputTypes()
virtual QString getType() const