collisiondetectors/CD_Swiftpp.h

Go to the documentation of this file.
00001 //=================================================================
00002 // CD_Swiftpp.h
00003 // Acts as the wrapper class to the collision detection package
00004 // SWIFT++ which provides distances measurements as well as
00005 // closest points calculations, both of which are needed in 
00006 // IK_Jacobian
00007 //=================================================================
00008 
00009 #ifndef CD_SWIFTPP_H
00010 #define CD_SWIFTPP_H
00011 
00012 #pragma warning( disable : 4250 )
00013 
00014 #include <set>
00015 #include <vector>
00016 
00017 // CD_BasicStyle
00018 #include "CollisionDetectors\CD_BasicStyle.h"
00019 #include "CollisionDetectors\CD_LinearDiscrete.h"
00020 #include "CollisionDetectors\CD_LinearContinuous.h"
00021 // Mesh
00022 #include "geometry\Mesh.h"
00023 #include "SWIFTpp\include\SWIFT.h"
00024 
00025 // string lengths (pretty much arbitrary)
00026 #define MAX_BUFFER_LENGTH       1024
00027 #define MAX_FILENAME_LENGTH     256
00028 #define MIN_FILENAME_LENGTH     11
00029 
00030 class Facet;
00031 class ObjectGroup;
00032 class LinkBase;
00033 class SWIFT_Scene;
00034 
00035 class CD_Swiftpp 
00036 : 
00037         public CD_BasicStyle,  
00038         public CD_LinearContinuous
00039 {
00040 public:
00041     CD_Swiftpp (const Universe& universe);
00042     CD_Swiftpp (const CD_Swiftpp& right);
00043 
00044     //## Destructor (generated)
00045     virtual ~CD_Swiftpp();
00046 
00047     //  this virtual function provides a copy of the object
00048     virtual CollisionDetectorBase* Clone () const;
00049 
00050     // returns -1 if error, else object id
00051     // bFixed indicates whether or not the object added is fixed or moving 
00052     // by default, they are moving.  If fixed, objects are not tested against 
00053     // each other for collision.  Also, once an object's status is set here
00054     // it cannot be changed, ie - an object cannot be declared fixed after it
00055     // was declared moving when it was first added here.
00056     int AddMeshToSwiftScene(const Mesh& mesh, const bool bFixed);                  
00057     bool AddEntityToSwiftScene(const Entity* entity);    
00058     
00059     // (De)Activate frames - if only one frame is given, then all pairs with that frame 
00060     // in it will be (de)activated
00061     void DeactivateFrames (const unsigned int frame1, const int frame2 = -1);
00062     void ActivateFrames (const unsigned int frame1, const int frame2 = -1);
00063 
00064     // QueryContactDetermination - Reports distance, nearest points and normals
00065     // of objects within the specified tolerance.  By default, nothing is reported.
00066     // Returns true if collision detected, false if none.
00067     // bEarlyExit - if true, function returns true when first intersection is detected
00068     //              and no information is reported.
00069     // tolerance  - specifies the distance within which the features must be to be reported.
00070     //              if SWIFT_INFINITY is used in the parameter, all features are reported
00071     // num_pairs  - number of object pairs reported. NOT the number of contacts, ie - one
00072     //              object pair can have more than one contacts.
00073     // oids       - array of object ids.  length = 2*num_pairs.  For example, if num_pairs is 
00074     //              2 then oids[0]&oids[1] is the first pair and oids[2]&oids[3] is the second
00075     //              pair
00076     // num_contacts-number of contacts reported per pair.  length = num_pairs.  For example, if 
00077     //              num_pairs = 2, and num_contacts is [9,4], then there are a total of 13 
00078     //              contacts reported: 9 for the pair oids[0]&oids[1], 4 for the pair
00079     //              oids[2]&oids[3]. If a pair is intersecting, the entry for that pair is -1.
00080     //              If a pair is intersecting, the number of contacts is considered 1 so the
00081     //              following arrays will need to be read appropriately according to this
00082     //              Entries are either -1, 1 or higher.  0 would be an invalid return.
00083     // distances  - distances between features.  length = sum of all the values in num_contacts
00084     //              In the above example, length of distances = 13.  The distances are ordered
00085     //              in descending order (farthest to closest) within one pair of objects. So
00086     //              to get the shortest distance between oids[0]&oids[1], read distances[8]
00087     //              and distances[12] for oids[2]&oids[3]. If a pair is intersecting, 
00088     //              only one distance entry (value of -1) is allocated for the pair.
00089     // nearest_pts- gives the coordinates of the points used to measure distances.  
00090     //              length = 6* length of distances.  for each distance given, the xyz of 
00091     //              the closest point on the first object in the pair is given before the xyz 
00092     //              of the closest point on the second object. (oids[0] would be the first 
00093     //              object and oids[1] would be the second and so forth). 
00094     // normals    - gives the normal vector pointing to object1 from object2 wrt world 
00095     //              coordinates, vectors returned are normalized.  
00096     //              length = 3*length of distance
00097     bool QueryContactDetermination( const Configuration& config, bool bEarlyExit, 
00098          SWIFT_Real tolerance, int& num_pairs, int** oids, int** num_contacts, 
00099          SWIFT_Real** distances = NO_DISTANCES, SWIFT_Real** nearest_pts = NO_NEAREST_PTS, 
00100          SWIFT_Real** normals = NO_NORMALS);
00101     bool IsInterfering (const Configuration& config);
00102 
00103     // returns the link number of the link the object belongs to
00104     int  GetRobotLinkBaseFrame(int objectId);
00105 
00106         // Set tolerance
00107         void SetObstacleTolerance(double tol) {m_dObsTol = tol;}
00108         
00109     // Data Members for Associations
00110     std::vector<Mesh*> m_vMeshes;
00111  
00112 protected:
00113 
00114     void UpdateMovedLink (const unsigned int linkNum) const;
00115 
00116     // Data Members for Class Attributes
00117     mutable SWIFT_Scene* m_pSwiftScene;
00118 
00119     //  this tells us which swiftpp indexes are owned by which links
00120     std::vector< std::set< unsigned int > > m_vLinkSwiftpp;
00121     std::vector< int > m_vSwiftppIndexes;       // object ids
00122 
00123 private:
00124     // Data Members for Class Attributes
00125         double                  m_dObsTol;
00126     Universe* m_pUniversePointer;
00127 
00128 };
00129 
00130 
00131 #endif

Generated on Sat Apr 1 21:30:37 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO