opensurgsim
Emitter.h
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 
23 #include "SurgSim/Framework/ObjectFactory.h"
24 #include "SurgSim/Framework/Behavior.h"
25 #include "SurgSim/Math/Vector.h"
26 #include "SurgSim/Particles/RandomPointGenerator.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 
48 enum EmitMode
49 {
51  EMIT_MODE_VOLUME = 0,
53  EMIT_MODE_SURFACE,
55  EMIT_MODE_COUNT
56 };
57 
58 SURGSIM_STATIC_REGISTRATION(Emitter);
59 
62 {
63 public:
66  explicit Emitter(const std::string& name);
67 
69  virtual ~Emitter();
70 
71  SURGSIM_CLASSNAME(SurgSim::Particles::Emitter);
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 
132  virtual SurgSim::Math::RigidTransform3d getLocalPose() const;
133 
136  virtual SurgSim::Math::RigidTransform3d getPose() const;
137 
138 private:
139  bool doInitialize() override;
140  bool doWakeUp() override;
141 
143  RandomPointGenerator m_pointGenerator;
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 
158  double m_particlesNotAdded;
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
RandomPointGenerator will generate points based on the shape passed.
Definition: RandomPointGenerator.h:35
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Emitter emits particles into a ParticleSystem.
Definition: Emitter.h:61
Definitions of small fixed-size vector types.
Behaviors perform actions.
Definition: Behavior.h:40