Representation.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2015, 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_REPRESENTATION_H
17 #define SURGSIM_PARTICLES_REPRESENTATION_H
18 
19 #include <memory>
20 #include <string>
21 
24 #include "SurgSim/Math/Vector.h"
26 
27 
28 namespace SurgSim
29 {
30 
31 namespace Framework
32 {
33 class Logger;
34 };
35 
36 namespace Particles
37 {
38 
41 {
42 public:
45  explicit Representation(const std::string& name);
46 
48  virtual ~Representation();
49 
53  void setMaxParticles(size_t maxParticles);
54 
56  size_t getMaxParticles() const;
57 
61  bool addParticle(const Particle& particle);
62 
68  bool addParticle(const Math::Vector3d& position, const Math::Vector3d& velocity, double lifetime);
69 
73  void removeParticle(size_t index);
74 
78 
81  void update(double dt);
82 
85  void handleCollisions(double dt);
86 
89  void setCollisionRepresentation(std::shared_ptr<SurgSim::Collision::Representation> representation);
90 
93  std::shared_ptr<SurgSim::Collision::Representation> getCollisionRepresentation() const;
94 
95 protected:
98  virtual bool doUpdate(double dt) = 0;
99 
102  virtual bool doHandleCollisions(double dt, const SurgSim::Collision::ContactMapType& collisions) = 0;
103 
104  bool doInitialize() override;
105 
108 
111 
113  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
114 
116  std::shared_ptr<SurgSim::Collision::Representation> m_collisionRepresentation;
117 };
118 
119 }; // namespace Particles
120 }; // namespace SurgSim
121 
122 #endif // SURGSIM_PARTICLES_REPRESENTATION_H
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Particles::Representation::getMaxParticles
size_t getMaxParticles() const
Definition: Representation.cpp:53
SurgSim::Particles::Representation::m_logger
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the particle system.
Definition: Representation.h:113
SurgSim::Particles::Representation::m_particles
SurgSim::DataStructures::BufferedValue< Particles > m_particles
BufferedValue of particles.
Definition: Representation.h:110
SurgSim::Collision::ContactMapType
std::unordered_map< std::shared_ptr< SurgSim::Collision::Representation >, std::list< std::shared_ptr< SurgSim::Collision::Contact > > > ContactMapType
Definition: Representation.h:47
SurgSim::Particles::Representation::handleCollisions
void handleCollisions(double dt)
Handle collisions with particle system.
Definition: Representation.cpp:121
SurgSim::Particles::Representation::m_maxParticles
size_t m_maxParticles
Maximum amount of particles allowed in this particle system.
Definition: Representation.h:107
SurgSim::Particles::Representation::getCollisionRepresentation
std::shared_ptr< SurgSim::Collision::Representation > getCollisionRepresentation() const
Get the collision representation for this Particle Representation.
Definition: Representation.cpp:133
SurgSim::Particles::Representation::setMaxParticles
void setMaxParticles(size_t maxParticles)
Set the maximum number of particles of this system.
Definition: Representation.cpp:47
SurgSim::Particles::Representation::removeParticle
void removeParticle(size_t index)
Remove a particle.
Definition: Representation.cpp:88
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Particles::Representation::m_collisionRepresentation
std::shared_ptr< SurgSim::Collision::Representation > m_collisionRepresentation
This entity's collision representation.
Definition: Representation.h:116
SurgSim::DataStructures::Vertex
Vertex structure for meshes.
Definition: Vertex.h:45
SurgSim::Particles::Representation::~Representation
virtual ~Representation()
Destructor.
Definition: Representation.cpp:37
Particles.h
SurgSim::Particles::Representation::addParticle
bool addParticle(const Particle &particle)
Add a particle.
Definition: Representation.cpp:63
SurgSim::Particles::Representation::Representation
Representation(const std::string &name)
Constructor.
Definition: Representation.cpp:28
SurgSim::Framework::Representation
Representations are manifestations of a SceneElement.
Definition: Representation.h:34
SurgSim::Particles::Representation::setCollisionRepresentation
void setCollisionRepresentation(std::shared_ptr< SurgSim::Collision::Representation > representation)
Set the collision representation for this Particle Representation.
Definition: Representation.cpp:138
SurgSim::DataStructures::BufferedValue
BufferedValue is a class to enable a representation of two values for one variable,...
Definition: BufferedValue.h:34
SurgSim::Particles::Representation::doHandleCollisions
virtual bool doHandleCollisions(double dt, const SurgSim::Collision::ContactMapType &collisions)=0
Implementation of the specific collision handling of the particle system.
SurgSim::Particles::Representation::getParticles
SurgSim::DataStructures::BufferedValue< Particles > & getParticles()
Get the particles.
Definition: Representation.cpp:58
Representation.h
SurgSim::Particles::Representation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: Representation.cpp:41
SurgSim::Particles::Representation
The Representation class defines the base class for all Particle System.
Definition: Representation.h:41
Representation.h
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Particles::Particles
DataStructures::Vertices< ParticleData > Particles
Definition: Particles.h:53
SurgSim::Particles::Representation::update
void update(double dt)
Update the particle system.
Definition: Representation.cpp:94
SurgSim::Particles::Representation::doUpdate
virtual bool doUpdate(double dt)=0
Implementation of the specific behavior of the particle system.