RayModel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_COLLISION_RAYMODEL_H
00026 #define SOFA_COMPONENT_COLLISION_RAYMODEL_H
00027
00028 #include <sofa/core/CollisionModel.h>
00029 #include <sofa/component/MechanicalObject.h>
00030 #include <sofa/defaulttype/Vec3Types.h>
00031 #include <set>
00032
00033
00034 namespace sofa
00035 {
00036
00037 namespace component
00038 {
00039
00040 namespace collision
00041 {
00042
00043 using namespace sofa::defaulttype;
00044
00045 class RayModel;
00046
00047 class Ray : public core::TCollisionElementIterator<RayModel>
00048 {
00049 public:
00050 Ray(RayModel* model, int index);
00051
00052 explicit Ray(core::CollisionElementIterator& i);
00053
00054 const Vector3& origin() const;
00055 const Vector3& direction() const;
00056 SReal l() const;
00057
00058 Vector3& origin();
00059 Vector3& direction();
00060 SReal& l();
00061 };
00062
00063 class BaseRayContact;
00064
00065 class RayModel : public component::MechanicalObject<Vec3Types>, public core::CollisionModel
00066 {
00067 protected:
00068 sofa::helper::vector<SReal> length;
00069
00070 Data<SReal> defaultLength;
00071
00072 std::set<BaseRayContact*> contacts;
00073 public:
00074 typedef Vec3Types InDataTypes;
00075 typedef Vec3Types DataTypes;
00076 typedef Ray Element;
00077 friend class Ray;
00078
00079 RayModel(SReal defaultLength=1);
00080
00081 int addRay(const Vector3& origin, const Vector3& direction, SReal length);
00082
00083 int getNbRay() const { return size; }
00084
00085 void setNbRay(int n) { resize(2*n); }
00086
00087 Ray getRay(int index) { return Ray(this, index); }
00088
00089 virtual void addContact(BaseRayContact* contact) { contacts.insert(contact); }
00090
00091 virtual void removeContact(BaseRayContact* contact) { contacts.erase(contact); }
00092
00093 virtual void resize(int size);
00094
00095
00096
00097 virtual void computeBoundingTree(int maxDepth);
00098
00099 void draw(int index);
00100
00101 void applyTranslation(const double dx,const double dy,const double dz);
00102
00103 void draw();
00104 };
00105
00106 inline Ray::Ray(RayModel* model, int index)
00107 : core::TCollisionElementIterator<RayModel>(model, index)
00108 {}
00109
00110 inline Ray::Ray(core::CollisionElementIterator& i)
00111 : core::TCollisionElementIterator<RayModel>(static_cast<RayModel*>(i.getCollisionModel()), i.getIndex())
00112 {
00113 }
00114
00115 inline const Vector3& Ray::origin() const
00116 {
00117 return (*model->getX())[2*index+0];
00118 }
00119
00120 inline const Vector3& Ray::direction() const
00121 {
00122 return (*model->getX())[2*index+1];
00123 }
00124
00125 inline Vector3::value_type Ray::l() const
00126 {
00127 return model->length[index];
00128 }
00129
00130 inline Vector3& Ray::origin()
00131 {
00132 return (*model->getX())[2*index+0];
00133 }
00134
00135 inline Vector3& Ray::direction()
00136 {
00137 return (*model->getX())[2*index+1];
00138 }
00139
00140 inline Vector3::value_type& Ray::l()
00141 {
00142 return model->length[index];
00143 }
00144
00145 }
00146
00147 }
00148
00149 }
00150
00151 #endif