BoolToScalar.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DEVICES_DEVICEFILTERS_BOOLTOSCALAR_H
17 #define SURGSIM_DEVICES_DEVICEFILTERS_BOOLTOSCALAR_H
18 
21 
22 namespace SurgSim
23 {
24 namespace DataStructures
25 {
26 class DataGroupCopier;
27 }
28 
29 namespace Devices
30 {
31 
32 SURGSIM_STATIC_REGISTRATION(BoolToScalar);
33 
37 class BoolToScalar : public DeviceFilter
38 {
39 public:
41  explicit BoolToScalar(const std::string& name);
42 
44  ~BoolToScalar();
45 
47 
48  void initializeInput(const std::string& device, const DataStructures::DataGroup& inputData) override;
49 
50  void filterInput(const std::string& device, const DataStructures::DataGroup& dataToFilter,
51  DataStructures::DataGroup* result) override;
52 
55  void setScale(double val);
56 
58  double getScale() const;
59 
62  void setRange(const std::pair<double, double>& val);
63 
65  std::pair<double, double> getRange() const;
66 
69  void setClamping(bool val);
70 
72  bool isClamping();
73 
76  void setIncreaseField(const std::string& val);
77 
79  std::string getIncreaseField() const;
80 
83  void setDecreaseField(const std::string& val);
84 
86  std::string getDecreaseField() const;
87 
90  void setScalar(double val);
91 
93  double getScalar() const;
94 
98  void setTargetField(const std::string& val);
99 
101  std::string getTargetField() const;
102 
103 private:
105 
106  double m_value;
107 
108  double m_scale;
109 
110  std::pair<double, double> m_range;
111 
112  std::string m_increaseField;
113  std::string m_decreaseField;
114  std::string m_targetField;
115 
117 
118  std::shared_ptr<DataStructures::DataGroupCopier> m_copier;
119 
120 };
121 
122 }; // namespace Devices
123 }; // namespace SurgSim
124 
125 #endif
SurgSim::Devices::BoolToScalar::setDecreaseField
void setDecreaseField(const std::string &val)
Set the field this is read to decrease the scalar value, needs to be a bool.
Definition: BoolToScalar.cpp:175
SurgSim::Devices::BoolToScalar::initializeInput
void initializeInput(const std::string &device, const DataStructures::DataGroup &inputData) override
Set the initial input data group.
Definition: BoolToScalar.cpp:58
SurgSim::Devices::BoolToScalar::setRange
void setRange(const std::pair< double, double > &val)
Set the range of values that should be produced by this.
Definition: BoolToScalar.cpp:130
SurgSim::Devices::BoolToScalar::getTargetField
std::string getTargetField() const
Definition: BoolToScalar.cpp:195
SurgSim::Devices::BoolToScalar::setScale
void setScale(double val)
Sets the value that gets used, the actual value to be added is scale * dt per call to filterInput.
Definition: BoolToScalar.cpp:154
SurgSim::Devices::BoolToScalar::setScalar
void setScalar(double val)
Set the value of the mapped field, can also be used to set a starting value for the field.
Definition: BoolToScalar.cpp:185
SurgSim::Framework::Timer
Timer class, measures execution times.
Definition: Timer.h:30
SurgSim::Devices::BoolToScalar::getScalar
double getScalar() const
Definition: BoolToScalar.cpp:180
SurgSim::Devices::DeviceFilter
A device filter can be connected between a device and the InputConsumerInterface (e....
Definition: DeviceFilter.h:37
SurgSim::Devices::BoolToScalar::m_range
std::pair< double, double > m_range
Definition: BoolToScalar.h:110
SurgSim::Devices::BoolToScalar::~BoolToScalar
~BoolToScalar()
Destructor.
Definition: BoolToScalar.cpp:54
SurgSim::Devices::BoolToScalar::getDecreaseField
std::string getDecreaseField() const
Definition: BoolToScalar.cpp:170
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::DataGroup
A collection of NamedData objects.
Definition: DataGroup.h:68
SurgSim::Devices::BoolToScalar::m_value
double m_value
Definition: BoolToScalar.h:106
SurgSim::Devices::BoolToScalar::m_timer
Framework::Timer m_timer
Definition: BoolToScalar.h:116
SurgSim::Devices::BoolToScalar::isClamping
bool isClamping()
Definition: BoolToScalar.cpp:149
Timer.h
SurgSim::Devices::BoolToScalar::setTargetField
void setTargetField(const std::string &val)
Set the name of the target field that carries the scalar value, will be created in the datagroup if i...
Definition: BoolToScalar.cpp:200
SurgSim::Devices::BoolToScalar::getIncreaseField
std::string getIncreaseField() const
Definition: BoolToScalar.cpp:159
SurgSim::Devices::BoolToScalar::setIncreaseField
void setIncreaseField(const std::string &val)
Set the field that is read to increase the scalar value, needs to be a bool.
Definition: BoolToScalar.cpp:165
SurgSim::Devices::BoolToScalar
Maps the on and off state of two boolean values to the increase and decrease of a scalar field,...
Definition: BoolToScalar.h:37
SurgSim::Devices::BoolToScalar::setClamping
void setClamping(bool val)
Enables or disables clamping on the output value (default true)
Definition: BoolToScalar.cpp:144
SurgSim::Devices::BoolToScalar::BoolToScalar
BoolToScalar(const std::string &name)
Constructor.
Definition: BoolToScalar.cpp:29
SurgSim::Devices::BoolToScalar::m_copier
std::shared_ptr< DataStructures::DataGroupCopier > m_copier
Definition: BoolToScalar.h:118
SurgSim::Devices::BoolToScalar::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Devices::BoolToScalar)
SurgSim::Devices::BoolToScalar::m_targetField
std::string m_targetField
Definition: BoolToScalar.h:114
SurgSim::Devices::BoolToScalar::filterInput
void filterInput(const std::string &device, const DataStructures::DataGroup &dataToFilter, DataStructures::DataGroup *result) override
Filter the input data.
Definition: BoolToScalar.cpp:90
SurgSim::Devices::BoolToScalar::m_scale
double m_scale
Definition: BoolToScalar.h:108
SurgSim::Devices::BoolToScalar::getRange
std::pair< double, double > getRange() const
Definition: BoolToScalar.cpp:139
SurgSim::Devices::BoolToScalar::m_isClamping
bool m_isClamping
Definition: BoolToScalar.h:104
DeviceFilter.h
SurgSim::Devices::BoolToScalar::getScale
double getScale() const
Definition: BoolToScalar.cpp:125
SurgSim::Devices::BoolToScalar::m_increaseField
std::string m_increaseField
Definition: BoolToScalar.h:112
SurgSim::Devices::BoolToScalar::m_decreaseField
std::string m_decreaseField
Definition: BoolToScalar.h:113