Representation.h
Go to the documentation of this file.
// 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;
enum CollisionDetectionType : SURGSIM_ENUM_TYPE;
class Representation : public SurgSim::Framework::Representation
{
public:
explicit Representation(const std::string& name);
virtual ~Representation();
virtual int getShapeType() const = 0;
void setCollisionDetectionType(CollisionDetectionType type);
CollisionDetectionType getCollisionDetectionType() const;
void setSelfCollisionDetectionType(CollisionDetectionType type);
CollisionDetectionType getSelfCollisionDetectionType() const;
virtual const std::shared_ptr<SurgSim::Math::Shape> getShape() const = 0;
virtual std::shared_ptr<SurgSim::Math::Shape> getPosedShape();
const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& getPosedShapeMotion() const;
SurgSim::DataStructures::BufferedValue<ContactMapType>& getCollisions();
void addContact(const std::shared_ptr<Representation>& other,
const std::shared_ptr<SurgSim::Collision::Contact>& contact);
bool collidedWith(const std::shared_ptr<Representation>& other);
virtual void update(const double& dt);
virtual void updateShapeData();
virtual void updateDcdData();
virtual void updateCcdData(double timeOfImpact);
bool ignore(const std::string& fullName);
bool ignore(const std::shared_ptr<Representation>& representation);
void setIgnoring(const std::vector<std::string>& fullNames);
bool isIgnoring(const std::string& fullName) const;
bool isIgnoring(const std::shared_ptr<Representation>& representation) const;
bool allow(const std::string& fullName);
bool allow(const std::shared_ptr<Representation>& representation);
void setAllowing(const std::vector<std::string>& fullNames);
bool isAllowing(const std::string& fullName) const;
bool isAllowing(const std::shared_ptr<Representation>& representation) const;
Math::Aabbd getBoundingBox() const;
protected:
void invalidatePosedShapeMotion();
std::vector<std::string> getIgnoring() const;
std::vector<std::string> getAllowing() const;
void doRetire() override;
void setPosedShapeMotion(const Math::PosedShapeMotion<std::shared_ptr<Math::Shape>>& posedShape);
std::shared_ptr<Framework::Logger> m_logger;
private:
CollisionDetectionType m_collisionDetectionType;
CollisionDetectionType m_selfCollisionDetectionType;
SurgSim::DataStructures::BufferedValue<ContactMapType> m_collisions;
boost::mutex m_collisionsMutex;
Math::PosedShapeMotion<std::shared_ptr<Math::Shape>> m_posedShapeMotion;
mutable boost::shared_mutex m_posedShapeMotionMutex;
std::unordered_set<std::string> m_ignoring;
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
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Collision::Representation::m_posedShapeMotionMutex
boost::shared_mutex m_posedShapeMotionMutex
Mutex to lock write access to m_posedShapeMotion.
Definition: Representation.h:240
BufferedValue.h
Aabb.h
SurgSim::DataStructures::BufferedValue< ContactMapType >
SurgSim::Collision::Representation::m_logger
std::shared_ptr< Framework::Logger > m_logger
Definition: Representation.h:219
SurgSim::Collision::Representation::m_collisionsMutex
boost::mutex m_collisionsMutex
Mutex to lock write access to m_collisions.
Definition: Representation.h:234
Log.h
The convenience header that provides the entirety of the logging API.
Representation.h
SurgSim::Collision::Representation::m_collisionDetectionType
CollisionDetectionType m_collisionDetectionType
The type of collision detection.
Definition: Representation.h:223
SurgSim::Collision::Representation::m_ignoring
std::unordered_set< std::string > m_ignoring
Ignored collision representations.
Definition: Representation.h:243
SurgSim::Math::Aabbd
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
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_SERIALIZABLE_ENUM
SURGSIM_SERIALIZABLE_ENUM(SurgSim::Devices::HandType,(HANDTYPE_LEFT)(HANDTYPE_RIGHT))
SurgSim::Collision::Representation::m_selfCollisionDetectionType
CollisionDetectionType m_selfCollisionDetectionType
The type of self collision detection.
Definition: Representation.h:226
SurgSim::Collision::Representation::m_collisions
SurgSim::DataStructures::BufferedValue< ContactMapType > m_collisions
A map which associates a list of contacts with each collision representation.
Definition: Representation.h:231
SurgSim::Collision::Representation
The type of collision detection.
Definition: Representation.h:60
SurgSim::Collision::Representation::m_posedShapeMotion
Math::PosedShapeMotion< std::shared_ptr< Math::Shape > > m_posedShapeMotion
The shape transformed in space and defined through time, i.e. with 2 differents configurations.
Definition: Representation.h:237
SURGSIM_ENUM_TYPE
#define SURGSIM_ENUM_TYPE
Required type of enums used by SURGSIM_SERIALIZABLE_ENUM.
Definition: Accessible.h:261
SurgSim::Math::PosedShapeMotion
PosedShapeMotion is embedding the motion of a PosedShape, providing a posed shape at 2 different inst...
Definition: Shape.h:145
SurgSim::Framework::Representation
Representations are manifestations of a SceneElement.
Definition: Representation.h:33
SurgSim::Collision::Representation::m_allowing
std::unordered_set< std::string > m_allowing
Allowed collision representations.
Definition: Representation.h:246
Shape.h