Emitter.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, 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_PARTICLES_EMITTER_H
17 #define SURGSIM_PARTICLES_EMITTER_H
18 
19 #include <cmath>
20 #include <memory>
21 #include <random>
22 
25 #include "SurgSim/Math/Vector.h"
27 
28 
29 namespace SurgSim
30 {
31 
32 namespace Framework
33 {
34 class Logger;
35 };
36 
37 namespace Math
38 {
39 class Shape;
40 };
41 
42 namespace Particles
43 {
44 
45 class Representation;
46 
49 {
56 };
57 
58 SURGSIM_STATIC_REGISTRATION(Emitter);
59 
62 {
63 public:
66  explicit Emitter(const std::string& name);
67 
69  virtual ~Emitter();
70 
72 
73  void update(double dt) override;
74 
75  int getTargetManagerType() const override;
76 
79  void setTarget(const std::shared_ptr<SurgSim::Framework::Component> target);
80 
83  const std::shared_ptr<SurgSim::Framework::Component> getTarget();
84 
87  void setShape(std::shared_ptr<SurgSim::Math::Shape> shape);
88 
91  std::shared_ptr<SurgSim::Math::Shape> getShape() const;
92 
95  void setMode(int mode);
96 
99  int getMode() const;
100 
103  void setRate(double rate);
104 
107  double getRate() const;
108 
112  void setLifetimeRange(const std::pair<double, double>& range);
113 
116  std::pair<double, double> getLifetimeRange() const;
117 
121  void setVelocityRange(const std::pair<SurgSim::Math::Vector3d, SurgSim::Math::Vector3d>& range);
122 
124  const std::pair<SurgSim::Math::Vector3d, SurgSim::Math::Vector3d>& getVelocityRange() const;
125 
128  virtual void setLocalPose(const SurgSim::Math::RigidTransform3d& pose);
129 
133 
137 
138 private:
139  bool doInitialize() override;
140  bool doWakeUp() override;
141 
144 
146  int m_mode;
147 
149  double m_rate;
150 
152  std::pair<double, double> m_lifetimeRange;
153 
155  std::pair<SurgSim::Math::Vector3d, SurgSim::Math::Vector3d> m_velocityRange;
156 
159 
162  std::mt19937 m_generator;
163  std::uniform_real_distribution<double> m_zeroOneDistribution;
165 
167  std::shared_ptr<SurgSim::Math::Shape> m_shape;
168 
170  std::shared_ptr<SurgSim::Particles::Representation> m_target;
171 
174 
176  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
177 };
178 
179 }; // namespace Particles
180 }; // namespace SurgSim
181 
182 #endif // SURGSIM_PARTICLES_EMITTER_H
SurgSim::Particles::Emitter::getPose
virtual SurgSim::Math::RigidTransform3d getPose() const
Get the pose of the Emitter in world coordinates.
Definition: Emitter.cpp:199
SurgSim::Particles::Emitter::m_logger
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the Emitter.
Definition: Emitter.h:176
SurgSim::Particles::EMIT_MODE_SURFACE
Emit particles only from the surface.
Definition: Emitter.h:53
Vector.h
SurgSim::Particles::Emitter::m_velocityRange
std::pair< SurgSim::Math::Vector3d, SurgSim::Math::Vector3d > m_velocityRange
The range of velocities of the emitted particles.
Definition: Emitter.h:155
SurgSim::Particles::EMIT_MODE_VOLUME
Emit particles from within the shapes volume.
Definition: Emitter.h:51
SurgSim::Particles::Emitter::setTarget
void setTarget(const std::shared_ptr< SurgSim::Framework::Component > target)
Set the target to emit to.
Definition: Emitter.cpp:138
SurgSim::Particles::Emitter::m_target
std::shared_ptr< SurgSim::Particles::Representation > m_target
Representation to emit to.
Definition: Emitter.h:170
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Particles::Emitter::~Emitter
virtual ~Emitter()
Destructor.
Definition: Emitter.cpp:67
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim::Particles::Emitter::m_localPose
SurgSim::Math::RigidTransform3d m_localPose
Local Pose of the Representation with respect to the SceneElement.
Definition: Emitter.h:173
SurgSim::Particles::Emitter::m_zeroOneDistribution
std::uniform_real_distribution< double > m_zeroOneDistribution
Definition: Emitter.h:163
SurgSim::Particles::Emitter::getTargetManagerType
int getTargetManagerType() const override
Specifies which manger will handle this behavior.
Definition: Emitter.cpp:123
SurgSim::Particles::Emitter::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Particles::Emitter)
SurgSim::Particles::Emitter::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: Emitter.cpp:71
SurgSim::Particles::Emitter::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: Emitter.cpp:76
SurgSim::Particles::Emitter::getShape
std::shared_ptr< SurgSim::Math::Shape > getShape() const
Get the shape of this emitter.
Definition: Emitter.cpp:133
SurgSim::Particles::Emitter::Emitter
Emitter(const std::string &name)
Constructor.
Definition: Emitter.cpp:38
SurgSim::Particles::RandomPointGenerator
RandomPointGenerator will generate points based on the shape passed.
Definition: RandomPointGenerator.h:35
ObjectFactory.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Particles::Emitter::setLifetimeRange
void setLifetimeRange(const std::pair< double, double > &range)
Set the range of lifetimes of emitted particles.
Definition: Emitter.cpp:171
SurgSim::Particles::Emitter::m_rate
double m_rate
The emit rate of this emitter.
Definition: Emitter.h:149
SurgSim::Particles::Emitter::getLifetimeRange
std::pair< double, double > getLifetimeRange() const
Get the range of lifetimes of emitted particles.
Definition: Emitter.cpp:178
SurgSim::Particles::Emitter::m_shape
std::shared_ptr< SurgSim::Math::Shape > m_shape
Shape of emitter.
Definition: Emitter.h:167
SurgSim::Particles::Emitter::m_particlesNotAdded
double m_particlesNotAdded
Number of particles not added during last update.
Definition: Emitter.h:158
SurgSim::Particles::Emitter::m_generator
std::mt19937 m_generator
Definition: Emitter.h:162
SurgSim::Particles::Emitter::getRate
double getRate() const
Get the emit rate of this emitter.
Definition: Emitter.cpp:166
SurgSim::Particles::Emitter::setVelocityRange
void setVelocityRange(const std::pair< SurgSim::Math::Vector3d, SurgSim::Math::Vector3d > &range)
Set the range of velocities of the emitted particles.
Definition: Emitter.cpp:183
SurgSim::Particles::EmitMode
EmitMode
Emitting modes of the Emitter.
Definition: Emitter.h:48
SurgSim::Particles::EMIT_MODE_COUNT
The number of EmitModes.
Definition: Emitter.h:55
SurgSim::Particles::Emitter::getLocalPose
virtual SurgSim::Math::RigidTransform3d getLocalPose() const
Get the pose of the Emitter with respect to the Scene Element.
Definition: Emitter.cpp:211
SurgSim::Particles::Emitter::update
void update(double dt) override
Update the behavior.
Definition: Emitter.cpp:91
SurgSim::Particles::Emitter::setRate
void setRate(double rate)
Set the emit rate of this emitter.
Definition: Emitter.cpp:160
SurgSim::Particles::Emitter::setMode
void setMode(int mode)
Set the emit mode of this emitter.
Definition: Emitter.cpp:149
SurgSim::Particles::Emitter::setShape
void setShape(std::shared_ptr< SurgSim::Math::Shape > shape)
Set the shape of this emitter.
Definition: Emitter.cpp:128
SurgSim::Particles::Emitter::getVelocityRange
const std::pair< SurgSim::Math::Vector3d, SurgSim::Math::Vector3d > & getVelocityRange() const
Get the range of velocities of the emitted particles.
Definition: Emitter.cpp:189
SurgSim::Particles::Emitter::m_pointGenerator
RandomPointGenerator m_pointGenerator
PointGenerator for generating random points within or on the emitter shape.
Definition: Emitter.h:143
SurgSim::Particles::Emitter::m_lifetimeRange
std::pair< double, double > m_lifetimeRange
The range of lifetimes of emitted particles.
Definition: Emitter.h:152
RandomPointGenerator.h
SurgSim::Particles::Emitter::getMode
int getMode() const
Get the emit mode of this emitter.
Definition: Emitter.cpp:155
SurgSim::Particles::Emitter::setLocalPose
virtual void setLocalPose(const SurgSim::Math::RigidTransform3d &pose)
Set the pose of the Emitter with respect to the Scene Element.
Definition: Emitter.cpp:194
SurgSim::Particles::Emitter::m_mode
int m_mode
The emit mode of this emitter.
Definition: Emitter.h:146
SurgSim::Particles::Particles
DataStructures::Vertices< ParticleData > Particles
Definition: Particles.h:53
SurgSim::Particles::Emitter
Emitter emits particles into a ParticleSystem.
Definition: Emitter.h:61
Behavior.h
SurgSim::Particles::Emitter::getTarget
const std::shared_ptr< SurgSim::Framework::Component > getTarget()
Get the target to emit to.
Definition: Emitter.cpp:144