/usr/include/SurgSim/Collision/Representation.h is in libopensurgsim-dev 0.7.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | // This file is a part of the OpenSurgSim project.
// Copyright 2013-2015, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_COLLISION_REPRESENTATION_H
#define SURGSIM_COLLISION_REPRESENTATION_H
#include <boost/thread/mutex.hpp>
#include <list>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include "SurgSim/DataStructures/BufferedValue.h"
#include "SurgSim/Framework/Log.h"
#include "SurgSim/Framework/Representation.h"
#include "SurgSim/Math/Aabb.h"
#include "SurgSim/Math/Shape.h"
namespace SurgSim
{
namespace Math
{
class Shape;
};
namespace Physics
{
class Representation;
};
namespace Collision
{
struct Contact;
class Representation;
typedef std::unordered_map<std::shared_ptr<SurgSim::Collision::Representation>,
std::list<std::shared_ptr<SurgSim::Collision::Contact>>> ContactMapType;
/// The type of collision detection
enum CollisionDetectionType : SURGSIM_ENUM_TYPE;
/// Wrapper class to use for the collision operation, handles its enclosed shaped
/// and a possible local to global coordinate system transform, if the physics representation
/// is a nullptr or a has gone out of scope ASSERT's will be triggered.
/// Collision with other representations will be updated by CollisionPair::addContact() and
/// be cleared every time DcdCollision::updatePair() makes a new CollisionPair.
class Representation : public SurgSim::Framework::Representation
{
public:
/// Constructor
/// \param name Name of this collision representation
explicit Representation(const std::string& name);
/// Destructor
virtual ~Representation();
/// Get the shape type id
/// \return The unique type of the shape, used to determine which calculation to use.
virtual int getShapeType() const = 0;
/// Set the type of collision detection to use between this representation and other representations
/// \param type The collision detection type
void setCollisionDetectionType(CollisionDetectionType type);
/// Get the type of collision detection used between this representation and other representations
/// \return The collision detection type
CollisionDetectionType getCollisionDetectionType() const;
/// Set the type of collision detection to use between this representation and itself
/// \param type The collision detection type
void setSelfCollisionDetectionType(CollisionDetectionType type);
/// Get the type of collision detection used between this representation and itself
/// \return The collision detection type
CollisionDetectionType getSelfCollisionDetectionType() const;
/// Get the shape
/// \return The actual shape used for collision.
virtual const std::shared_ptr<SurgSim::Math::Shape> getShape() const = 0;
/// Get the shape, posed
/// \return The shape transformed by the pose of this representation
virtual std::shared_ptr<SurgSim::Math::Shape> getPosedShape();
/// \return the posed shape motion
const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& getPosedShapeMotion() const;
/// A map between collision representations and contacts.
/// For each collision representation, it gives the list of contacts registered against this instance.
/// \return A map with collision representations as keys and lists of contacts as the associated value.
SurgSim::DataStructures::BufferedValue<ContactMapType>& getCollisions();
/// Add a contact with another representation
/// \param other The other collision representation
/// \param contact The contact to be added
/// \note This method is thread-safe
void addContact(const std::shared_ptr<Representation>& other,
const std::shared_ptr<SurgSim::Collision::Contact>& contact);
/// Check whether this collision representation collided with another during the last update
/// \param other other collision representation to check against
/// \return true if there were contacts recorded, false otherwise
bool collidedWith(const std::shared_ptr<Representation>& other);
/// Update the representation.
/// \param dt the time passed from the last update.
virtual void update(const double& dt);
/// Update the basic Shape's state from the physics state, so that the bounding box can correctly be determined
virtual void updateShapeData();
/// Update the data (the shape) in preparation for a DCD contact calculation
virtual void updateDcdData();
/// Update the data (the motionShape) in preparation for a CCD contact calcul ation
/// \param timeOfImpact the last time of impact, the representation is responsible for managing
/// the time correctly
virtual void updateCcdData(double timeOfImpact);
/// Set a collision representation to ignore
/// Collisions with this collision representation will not be detected
/// This acts as the opposite of allow if the representation that is passed here was previously added via allow()
/// \param fullName The full name of the collision representation to ignore
bool ignore(const std::string& fullName);
/// Set a collision representation to ignore
/// Collisions with this collision representation will not be detected
/// This acts as the opposite of allow if the representation that is passed here was previously added via allow()
/// \param representation The collision representation to ignore
bool ignore(const std::shared_ptr<Representation>& representation);
/// Set the collision representations to ignore
/// Collisions with these collision representation will not be detected
/// \note This method conflicts with setAllowing. You can only set what
/// representations to ignore or allow collisions with, not both.
/// \param fullNames The collision representations (given by full name) to ignore
void setIgnoring(const std::vector<std::string>& fullNames);
/// Is the collision representation being ignored
/// \param fullName The full name of the collision representation to check
/// return True if the collision representation is being ignored
bool isIgnoring(const std::string& fullName) const;
/// Is the collision representation being ignored
/// \param representation The collision representation to check
/// return True if the collision representation is being ignored
bool isIgnoring(const std::shared_ptr<Representation>& representation) const;
/// Set a collision representation to allow
/// Only collisions with "allowed" collision representation will be detected
/// If the the representation is currently being "ignored" then it will be removed from that state and
/// collisions will be allowed again.
/// \note When both the allow and ignore lists are empty calling allow may cause a change of behavior that
/// might not be wanted (i.e. the representation will go from colliding with all others to just colliding with
/// one other representation). This might be caused by trying to revert an "ignore" that has already been reversed.
/// \param fullName The full name of the collision representation to allow
bool allow(const std::string& fullName);
/// Set a collision representation to allow
/// Only collisions with "allowed" collision representation will be detected
/// If the the representation is currently being "ignored" then it will be removed from that state and
/// collisions will be allowed again.
/// \note When both the allow and ignore lists are empty calling allow may cause a change of behavior that
/// might not be wanted (i.e. the representation will go from colliding with all others to just colliding with
/// one other representation). This might be caused by trying to revert an "ignore" that has already been reversed.
/// \param representation The collision representation to allow
bool allow(const std::shared_ptr<Representation>& representation);
/// Set the only collision representations to allow collisions with
/// Only Collisions with these collision representation will be detected
/// \note This method conflicts with ignore and setIgnoring. You can only set what
/// representations to ignore or allow collisions with, not both.
/// \param fullNames The collision representations (given by full name) to allow
void setAllowing(const std::vector<std::string>& fullNames);
/// Is the collision representation being allowed
/// \param fullName The full name of the collision representation to check
/// return True if the collision representation is being allowed
bool isAllowing(const std::string& fullName) const;
/// Is the collision representation being allowed
/// \param representation The collision representation to check
/// return True if the collision representation is being allowed
bool isAllowing(const std::shared_ptr<Representation>& representation) const;
/// \return the Bounding box for this object
Math::Aabbd getBoundingBox() const;
protected:
/// Invalidate the cached posed shape motion
void invalidatePosedShapeMotion();
/// Get the ignored collision representations
/// \return The full names of all the ignored collision representations
std::vector<std::string> getIgnoring() const;
/// Get the only collision representations that this representation is allowed to collide with
/// \return The full names of all the collision representations to allow
std::vector<std::string> getAllowing() const;
void doRetire() override;
/// \param posedShape the posed shape motion to be set
void setPosedShapeMotion(const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& posedShape);
std::shared_ptr<Framework::Logger> m_logger;
private:
/// The type of collision detection
CollisionDetectionType m_collisionDetectionType;
/// The type of self collision detection
CollisionDetectionType m_selfCollisionDetectionType;
/// A map which associates a list of contacts with each collision representation.
/// Every contact added to this map follows the convention of pointing the contact normal toward this
/// representation. And the first penetration point is on this representation.
SurgSim::DataStructures::BufferedValue<ContactMapType> m_collisions;
/// Mutex to lock write access to m_collisions
boost::mutex m_collisionsMutex;
/// The shape transformed in space and defined through time, i.e. with 2 differents configurations
Math::PosedShapeMotion<std::shared_ptr<Math::Shape>> m_posedShapeMotion;
/// Mutex to lock write access to m_posedShapeMotion
mutable boost::shared_mutex m_posedShapeMotionMutex;
/// Ignored collision representations
std::unordered_set<std::string> m_ignoring;
/// Allowed collision representations
std::unordered_set<std::string> m_allowing;
};
}; // namespace Collision
}; // namespace SurgSim
SURGSIM_SERIALIZABLE_ENUM(SurgSim::Collision::CollisionDetectionType,
(COLLISION_DETECTION_TYPE_NONE)
(COLLISION_DETECTION_TYPE_DISCRETE)
(COLLISION_DETECTION_TYPE_CONTINUOUS)
(MAX_COLLISION_DETECTION_TYPES))
#endif
|