planners/PL_GraphBase.h

Go to the documentation of this file.
00001 //=========================================================================
00002 //
00003 //  File:  PL_GraphBase.h
00004 //
00005 //  Created 07-Feb-01 by Shane Schneider
00006 //
00007 //              Planner Base for planners requiring a graph data structure
00008 //              Contains the actual graph structure as well as several draw and
00009 //              computation functions.
00010 
00011 #ifndef PL_GraphBase_h
00012 #define PL_GraphBase_h 1
00013 
00014 #pragma warning( disable : 4250 )
00015 
00016 // Graph Include Files
00017 #include <LEDA/graph.h>
00018 #include <LEDA/node_list.h>
00019 #include "kinematics/Configuration.h"
00020 
00021 
00022 // PL_Boolean_Output
00023 #include "Planners\PL_Boolean_Output.h"
00024 #include "Planners\PL_OpenGL.h"
00025 
00026 //----------- Forward Declarations -----------------
00027 enum SuccessResultType;
00028 
00029 //## Class: PL_GraphBase%3921BC600296
00030 //## Category: Planners%36FB140B003C
00031 //## Persistence: Transient
00032 //## Cardinality/Multiplicity: n
00033 
00034 class PL_GraphBase : 
00035         virtual public PL_Boolean_Output,  //## Inherits: <unnamed>%3921BC73013F
00036         virtual public PL_OpenGL
00037 {
00038 
00039   public:
00040           // Default Constructor
00041           PL_GraphBase();
00042 
00043     //## Destructor (generated)
00044       virtual ~PL_GraphBase();
00045 
00046       virtual bool DrawExplicit () const;
00047 
00048           virtual bool Load (const char *filename);
00049 
00050       virtual bool Plan ();
00051 
00052           bool Save (const char *filename) const;
00053 
00054           virtual void SetStartConfig( const Configuration& configuration );
00055           virtual void SetGoalConfig( const Configuration& config ); 
00056 
00057           virtual void SetCollisionDetector (CD_BasicStyle* collisionDetector);
00058 
00059     // Additional Public Declarations
00060 
00061           // Graph Stats Functions
00062           //    Returns the number of nodes and edges in the current graph.
00063           inline int NodeCount() const { return G.number_of_nodes(); };
00064           inline int EdgeCount() const { return G.number_of_edges(); };
00065 
00066           virtual void ClearGraph();
00067           void ClearGraphPath();
00068 
00069           // NormDistWeight
00070           //    Normalizes the default distance weight used in calculating the distance between two configurations.
00071           void NormDistWeight();
00072           virtual void SetDistWeight( const VectorN& weights );
00073           VectorN GetDistWeight() const { return distWeight; };
00074 
00075           void CopySettings( PlannerBase* original );
00076           
00077   protected:
00078         // Additional Implementation Declarations
00079 
00080           // Distance Functions...
00081           //    Computes the squared Euclidean distance between two nodes (or configurations) and returns it.
00082           //    Used for determining the neighbour nodes and which node is closest.
00083           //    Functions either return a weighted squared sum or absoulte joint differences.
00084           virtual double Distance ( const node& a, const node& b ) const;
00085           virtual double Distance ( const Configuration& a, const Configuration& b ) const;
00086           virtual double Distance ( const node& a, const node& b, const VectorN& weight ) const;
00087           virtual double Distance ( const Configuration& a, const Configuration& b, const VectorN& weight ) const;
00088           virtual VectorN DiffV ( const node& a, const node& b ) const;
00089           virtual VectorN DiffV ( const Configuration& a, const Configuration& b ) const;
00090 
00091           // Length
00092           //    Returns the weighted length (cost) recorded for specified edge.
00093           double Length ( const edge& e1 ) const;
00094 
00095           // Measure
00096           //    Calculates the weighted length (cost) recorded for the specified edge by applying
00097           //    the appropriate Distance function on the end points (nodes) of the edge.
00098           double Measure ( const edge& e1 ) const;
00099           double Measure ( const edge& e1, const VectorN& weight ) const;
00100 
00101 
00102           // GetCspaceRange
00103           //    Computes the length of the diagonal of the Cspace using the given distance weights.  
00104           //    Used as an indication of the range of distances that can acheived within the Cspace.
00105           double GetCspaceRange( const VectorN& weight ) const;
00106           double GetCspaceRange() const ; 
00107           
00108 
00109           // FindConfig 
00110           //    Searches ALL the nodes in the graph and returns the node containning the given configuration.
00111           //    Returns nil if no node that matches the configuration is found
00112           node FindConfig( const Configuration& c1 ) const;
00113           
00114           // FindEdge
00115           //    Searches all edges associated with one of the nodes and returns the first edge found that 
00116           //    connects the two specified nodes.  Returns nil if no edge connecting the two nodes exists.
00117           edge FindEdge( const node& n1, const node& n2 ) const;
00118 
00119           // Create the Random Configurations of the C-space.
00120           virtual Configuration GenerateRandomConfig ();
00121           virtual Configuration GenerateRandomConfig ( const Configuration& seed, const double& std_dev );
00122           virtual Configuration GenerateRandomConfig ( const Configuration& centre );
00123 
00124           // IsInterfering
00125           //    Calls the associated collision detector to determine if node(s)/configuration(s)/edge
00126           //    are interfering.  Returns TRUE if the associated paremeters are interfering.
00127           virtual bool IsInterfering ( const edge& e1 );
00128           virtual bool IsInterfering ( const node& n1 );
00129           virtual bool IsInterfering ( const Configuration& c1 );
00130           virtual bool IsInterfering ( const node& n1, const node& n2 );
00131           virtual bool IsInterfering ( const Configuration& c1, const Configuration& c2 );
00132 
00133           // Drawing Functions
00134           //    Various Functions used by the Drawing Routines for creating the OpenGL C-space display.
00135           //    GetCoords:  Returns the given parameters with appropriate coordinates based on configuration
00136           //                        stored in the given node.
00137           void GetCoords( const node n1, double& Xcor, double& Ycor, double& Zcor ) const;
00138           void GetCoords( const Configuration& c1, double& Xcor, double& Ycor, double& Zcor ) const;
00139           //    DrawSpecific:  Virtual function to be implemented in child planners that allow the planner
00140           //                               to draw additional planner specific OpenGL information.
00141           virtual bool DrawSpecific() const;
00142 
00143           // PrioritizeEdge
00144           //    Rearranges the order of the of edges assigned to the source node so the edge connecting
00145           //    the source and target nodes is made the first adj_edge.  This allows easy trace back along first
00146           //    adj_edges from the goal to the start node.
00147           bool PrioritizeEdge(node prev, node curr);  // Makes first adj_edge to point from curr node to the prev node.
00148           bool PrioritizeEdge(node source, edge e1);  // Makes first adj_edge point from source node to G.target(e1).
00149 
00150           // GetMidPoint
00151           //    Finds the Midpoint between two configurations
00152           Configuration GetMidPoint( const Configuration& a, const Configuration& b ) const;
00153 
00154           // TranslatePath
00155           //    Converts the path stored in graphPath and converts it to PA_Path for server to animate.
00156           virtual SuccessResultType TranslatePath();
00157 
00158           // SaveContents
00159           //    Saves the graph and other relevent PL_GraphPath parameters to the given ostream pointer
00160           virtual bool SaveContents( std::ofstream& outfile ) const;
00161 
00162           // LoadContents
00163           //    Load the graph and other relevent PL_GraphPath parameters to the given ostream pointer
00164           virtual bool LoadContents( std::ifstream& infile );
00165 
00166           // TranslateNodeID
00167           //    Searches the entire graph structure, returning the node (ptr) associated with the given index.
00168           node TranslateNodeID( const int& nodeID ) const;
00169 
00170 
00171     // Additional Protected Declarations
00172 
00173           // Actual Graph Structure to be used
00174           //    Nodes are of type Configuration and record different configurations at that point.
00175           //    Edges are of type double and record the squared euclidean distance between joinning nodes (configurations).
00176           GRAPH<Configuration,double> G;
00177 
00178           // Path Planning Nodes
00179           //     Keeps track which nodes in the graph contain the start and goal configurations
00180           node startNode;
00181           node goalNode;
00182 
00183           // Interm Path
00184           node_list graphPath;  // records current path through the nodes.
00185 
00186          
00187           // Vector containning the distance Weights
00188           VectorN distWeight;
00189 
00190 
00191           // ------- File Parameters -------------
00192           char fileext[10];                                             // File extension the graph planner  ( set in respective constructors )
00193           char fileheader[20];                                  // File Header for the Graph Planner  ( set in respective constructors )
00194       static const int NIL_ID;                          // Integer indicating an empty or nil pointer is currently saved.
00195 
00196   private:
00197     // Additional Private Declarations
00198 
00199   private: //## implementation
00200     // Additional Implementation Declarations
00201 
00202 };
00203 
00204 
00205 // Class PL_GraphBase 
00206 
00207 enum SuccessResultType
00208 {
00209         TIMER_EXPIRED = -1,
00210         FAIL = 0,
00211         PASS = 1
00212 };
00213 
00214 
00215 #endif

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