00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "synchronization/semaphore.h"
00015 #include "color/colorf.h"
00016 #include "Planners\PL_GraphBase.h"
00017
00018 #include <assert.h>
00019 #include <math.h>
00020 #include <math/math2.h>
00021 #include <iosfwd>
00022 #include <iostream>
00023
00024
00025
00026
00027 #include "opengl/glos.h"
00028 #include <gl/gl.h>
00029
00030 using std::endl;
00031
00032
00033
00034 static const char FILEEXT[] = ".gph";
00035 static const char FILEHEADER[] = "GRAPHBASE";
00036 const int PL_GraphBase::NIL_ID = -1;
00037
00038 const double COMPTOL = 1e-8;
00039
00040
00041
00042
00043 PL_GraphBase::PL_GraphBase()
00044 {
00045
00046 strcpy( fileext, FILEEXT );
00047 strcpy( fileheader, FILEHEADER );
00048
00049
00050 ClearGraph();
00051
00052
00053 NormDistWeight();
00054
00055
00056 TRACE("PL_GraphBase Default constructor completed.\n");
00057
00058
00059 }
00060
00061
00062 PL_GraphBase::~PL_GraphBase()
00063 {
00064
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 bool PL_GraphBase::DrawExplicit () const
00074 {
00075 double Xcor;
00076 double Ycor;
00077 double Zcor;
00078 node n1;
00079 edge e1;
00080
00081
00082 Semaphore semaphore( this->guid );
00083 semaphore.Lock();
00084
00085
00086 glClearColor( 0.0f, 0.0f, 0.2f, 1.0f );
00087 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00088 BOOL lightingState = glIsEnabled( GL_LIGHTING );
00089 glDisable( GL_LIGHTING );
00090
00091
00092
00093
00094 glShadeModel( GL_SMOOTH );
00095
00096
00097
00098
00099
00100
00101 DrawSpecific();
00102
00103
00104
00105 glPointSize( 5.0f );
00106
00107
00108 glBegin( GL_POINTS );
00109
00110 if ( startNode != nil )
00111 {
00112 Color::yellow.GlDraw();
00113 GetCoords( startNode, Xcor, Ycor, Zcor );
00114 glVertex3d( Xcor, Ycor, Zcor );
00115 }
00116
00117
00118 if ( goalNode != nil )
00119 {
00120 Color::cyan.GlDraw();
00121 GetCoords( goalNode, Xcor, Ycor, Zcor );
00122 glVertex3d( Xcor, Ycor, Zcor );
00123 }
00124 glEnd();
00125
00126
00127 glBegin(GL_POINTS);
00128
00129 Color::red.GlDraw();
00130 forall_nodes( n1, G )
00131 {
00132 if ( ( n1 != startNode ) && ( n1 != goalNode ) )
00133 {
00134 GetCoords( n1, Xcor, Ycor, Zcor );
00135 glVertex3d( Xcor, Ycor, Zcor );
00136 }
00137 }
00138 glEnd();
00139
00140
00141
00142
00143
00144 if ( !graphPath.empty() )
00145 {
00146 glLineWidth( 3.0f );
00147 glBegin(GL_LINES);
00148 node n1 = graphPath.tail();
00149
00150
00151
00152 node firstNode = graphPath.head();
00153 while ( n1 != firstNode )
00154 {
00155
00156 GetCoords( n1, Xcor, Ycor, Zcor );
00157 Color::orange.GlDraw();
00158 glVertex3d( Xcor, Ycor, Zcor );
00159
00160
00161 n1 = graphPath.pred( n1 );
00162
00163
00164 GetCoords( n1, Xcor, Ycor, Zcor );
00165 Color::yellow.GlDraw();
00166 glVertex3d( Xcor, Ycor, Zcor );
00167
00168
00169
00170
00171 }
00172
00173 glEnd();
00174 }
00175
00176
00177
00178 glLineWidth( 1.0f );
00179 glBegin(GL_LINES);
00180
00181 forall_edges(e1,G)
00182 {
00183 GetCoords( G.source(e1), Xcor, Ycor, Zcor );
00184 Color::blue.GlDraw();
00185 glVertex3d( Xcor, Ycor, Zcor );
00186
00187 GetCoords( G.target(e1), Xcor, Ycor, Zcor );
00188 Color::white.GlDraw();
00189 glVertex3d( Xcor, Ycor, Zcor );
00190 }
00191 glEnd();
00192
00193
00194 if( lightingState != FALSE )
00195 {
00196 glEnable( GL_LIGHTING );
00197 }
00198
00199
00200 semaphore.Unlock();
00201
00202 return true;
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 bool PL_GraphBase::Load (const char *filename)
00212 {
00213 Semaphore semaphore( this->guid );
00214 semaphore.Lock();
00215
00216
00217 char tempstring[ 256 ] = "" ;
00218 strcpy( tempstring, filename ) ;
00219 strcat( tempstring, fileext ) ;
00220
00221
00222 std::ifstream infile( tempstring, std::ios::in );
00223 if( infile.good() == false )
00224 {
00225 semaphore.Unlock();
00226 MessageBox( NULL, "Could not open filename specified", "ERROR", MB_OK );
00227 return false;
00228 }
00229
00230
00231 infile >> tempstring;
00232 if ( strcmp( tempstring, fileheader ) != 0 )
00233 {
00234 infile.close();
00235 semaphore.Unlock();
00236 MessageBox( NULL, "Incompatible Base Graph File Loaded", "ERROR", MB_OK );
00237 return false;
00238 }
00239
00240
00241 this->ClearGraph();
00242
00243
00244 bool success = this->LoadContents( infile );
00245 if ( !success )
00246 {
00247 infile.close();
00248 semaphore.Unlock();
00249 MessageBox( NULL, "Could not load graph or parameters from file", "ERROR", MB_OK );
00250 return false;
00251 }
00252
00253
00254 infile.close();
00255
00256 semaphore.Unlock();
00257 return true;
00258 }
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 bool PL_GraphBase::LoadContents( std::ifstream& infile )
00269 {
00270
00271 int result = G.read( infile );
00272 if ( result != 0 )
00273 {
00274 MessageBox( NULL, "Graph Load Error", "ERROR", MB_OK );
00275 return false;
00276 }
00277
00278
00279 int nodeID;
00280 Configuration newStartConfig;
00281 infile >> nodeID >> newStartConfig;
00282 SetStartConfig( newStartConfig );
00283
00284
00285
00286 startNode = FindConfig( GetStartConfig() );
00287
00288
00289 Configuration newGoalConfig;
00290 infile >> nodeID >> newGoalConfig;
00291 SetGoalConfig( newGoalConfig );
00292
00293 goalNode = FindConfig( GetGoalConfig() );
00294
00295
00296 infile >> distWeight;
00297
00298 return true;
00299
00300 }
00301
00302
00303
00304
00305
00306
00307
00308 bool PL_GraphBase::Plan ()
00309 {
00310 assert( false );
00311 return false;
00312 }
00313
00314
00315
00316
00317
00318
00319 bool PL_GraphBase::Save (const char *filename) const
00320 {
00321 Semaphore semaphore( this->guid );
00322 semaphore.Lock();
00323
00324
00325 char filenameWithExtension[ 256 ] = "" ;
00326 strcpy( filenameWithExtension, filename ) ;
00327 strcat( filenameWithExtension, fileext ) ;
00328
00329
00330 std::ofstream outfile( filenameWithExtension, std::ios::out );
00331 if( outfile.good() == false )
00332 {
00333 semaphore.Unlock();
00334 MessageBox( NULL, "Could not open filename specified", "ERROR", MB_OK );
00335 return false;
00336 }
00337
00338
00339 outfile << fileheader << endl;
00340
00341
00342
00343 bool success = this->SaveContents( outfile );
00344 ASSERT ( success );
00345
00346
00347 outfile.close();
00348
00349 semaphore.Unlock();
00350 return true;
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 bool PL_GraphBase::SaveContents ( std::ofstream& outfile ) const
00362 {
00363
00364 G.write( outfile );
00365
00366 int nodeID;
00367
00368
00369 if ( startNode == nil )
00370 {
00371 nodeID = NIL_ID;
00372 }
00373 else
00374 {
00375 nodeID = startNode->id();
00376 }
00377 outfile << nodeID << " " << GetStartConfig() << endl;
00378 if ( goalNode == nil )
00379 {
00380 nodeID = NIL_ID;
00381 }
00382 else
00383 {
00384 nodeID = goalNode->id();
00385 }
00386 outfile << nodeID << " " << GetGoalConfig() << endl;
00387
00388
00389 outfile << distWeight << endl;
00390
00391 return true;
00392 }
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 void PL_GraphBase::ClearGraph()
00403 {
00404
00405 if ( !G.empty() )
00406 {
00407 G.clear();
00408 }
00409
00410
00411 startNode = nil;
00412 goalNode = nil;
00413
00414
00415 ClearGraphPath();
00416
00417 }
00418
00419 void PL_GraphBase::ClearGraphPath()
00420 {
00421
00422 if ( !graphPath.empty() )
00423 {
00424 graphPath.clear();
00425 }
00426 }
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 double PL_GraphBase::Distance ( const node& a, const node& b ) const
00438
00439 {
00440 return this->Distance( G.inf(a), G.inf(b) );
00441 }
00442
00443
00444 double PL_GraphBase::Distance ( const node& a, const node& b, const VectorN& weight ) const
00445
00446 {
00447 return this->Distance( G.inf(a), G.inf(b), weight );
00448 }
00449
00450
00451 double PL_GraphBase::Distance ( const Configuration& a, const Configuration& b ) const
00452
00453 {
00454 return this->Distance( a, b, distWeight );
00455 }
00456
00457
00458 double PL_GraphBase::Distance ( const Configuration& a, const Configuration& b, const VectorN& weight ) const
00459
00460 {
00461
00462 VectorN jointDiff;
00463 jointDiff = DiffV( a, b );
00464
00465
00466 ASSERT( weight.Length() >= jointDiff.Length() );
00467
00468
00469 double distance = 0;
00470 for( int i = 0; i < jointDiff.Length(); i++ )
00471 {
00472 distance += Sqr( weight[i]*jointDiff[i] );
00473 }
00474
00475
00476 return distance;
00477 }
00478
00479
00480 VectorN PL_GraphBase::DiffV ( const node& a, const node& b ) const
00481
00482 {
00483 return this->DiffV( G.inf(a), G.inf(b) );
00484 }
00485
00486
00487 VectorN PL_GraphBase::DiffV ( const Configuration& a, const Configuration& b ) const
00488
00489 {
00490
00491 return collisionDetector->JointDisplacement( a, b );
00492
00493 }
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 double PL_GraphBase::Length( const edge& e1 ) const
00504
00505 {
00506 return G.inf(e1);
00507 }
00508
00509 double PL_GraphBase::Measure( const edge& e1, const VectorN& weight ) const
00510
00511 {
00512 return Distance( G.target(e1), G.source(e1), weight );
00513 }
00514
00515 double PL_GraphBase::Measure( const edge& e1 ) const
00516
00517 {
00518 return Distance( G.target(e1), G.source(e1) );
00519 }
00520
00521
00522
00523
00524
00525
00526
00527
00528 void PL_GraphBase::NormDistWeight()
00529 {
00530
00531 int dof = 0;
00532 if ( collisionDetector != NULL )
00533 {
00534 dof = collisionDetector->DOF();
00535 }
00536
00537 distWeight.SetLength( dof );
00538
00539 for ( int i = 0; i < dof; i++ )
00540 {
00541 distWeight[i] = 1;
00542 }
00543
00544 }
00545
00546
00547
00548
00549
00550
00551
00552 double PL_GraphBase::GetCspaceRange( const VectorN& weight ) const
00553 {
00554
00555
00556 int dof = 0;
00557 if ( collisionDetector != NULL )
00558 {
00559 dof = collisionDetector->DOF();
00560 }
00561
00562
00563 Configuration minConfig;
00564 minConfig.SetNumDOF( dof );
00565
00566
00567 Configuration maxConfig;
00568 maxConfig.SetNumDOF( dof );
00569
00570
00571 for (int i=0; i < dof; i++ )
00572 {
00573 double jmin = collisionDetector->JointMin( i );
00574 double jmax = collisionDetector->JointMax( i );
00575
00576 if ( collisionDetector->JointWraps( i ) )
00577 {
00578
00579 jmax = ( jmax + jmin ) / 2;
00580 }
00581
00582
00583 minConfig[i] = jmin;
00584 maxConfig[i] = jmax;
00585 }
00586
00587
00588 return Distance( minConfig, maxConfig, weight );
00589
00590 }
00591
00592 double PL_GraphBase::GetCspaceRange() const
00593
00594 {
00595 return GetCspaceRange( distWeight );
00596 }
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 node PL_GraphBase::FindConfig( const Configuration& c1 ) const
00609
00610 {
00611 node n1;
00612
00613
00614
00615
00616 forall_rev_nodes( n1, G )
00617 {
00618 if ( c1.Compare( G.inf(n1) , COMPTOL) )
00619 {
00620
00621 return n1;
00622 }
00623 }
00624
00625
00626 return nil;
00627 }
00628
00629 edge PL_GraphBase::FindEdge( const node& n1, const node& n2 ) const
00630
00631 {
00632 edge e1;
00633
00634
00635 forall_inout_edges( e1, n1 )
00636 {
00637
00638 node othernode = G.target(e1);
00639
00640
00641 if ( othernode == n1 )
00642 {
00643
00644 othernode = G.source(e1);
00645 }
00646
00647 if ( othernode == n2 )
00648 {
00649
00650
00651 return e1;
00652 }
00653 }
00654
00655
00656 return nil;
00657 }
00658
00659
00660
00661
00662
00663
00664
00665 Configuration PL_GraphBase::GenerateRandomConfig ()
00666 {
00667 int dof = collisionDetector->DOF() ;
00668
00669 Configuration returnme ;
00670 returnme.SetLength( dof ) ;
00671
00672 for( int i = 0; i < dof; i++ )
00673 {
00674 double max = collisionDetector->JointMax( i ) ;
00675 double min = collisionDetector->JointMin( i ) ;
00676 double random = 2*( double( rand() ) / RAND_MAX ) - 1;
00677 double jointvalue = ( max - min ) * random;
00678
00679
00680 if ( jointvalue < min )
00681 {
00682 jointvalue += (max - min);
00683 }
00684 else if ( jointvalue > max )
00685 {
00686 jointvalue -= (max - min);
00687 }
00688
00689 returnme[ i ] = jointvalue;
00690 }
00691
00692 return returnme ;
00693 }
00694
00695
00696
00697
00698
00699
00700
00701 Configuration PL_GraphBase::GenerateRandomConfig ( const Configuration& centre )
00702 {
00703 enum LimitExceeded
00704 {
00705 MAXLIMIT = 1,
00706 MINLIMIT = -1,
00707 NEITHER = 0
00708 };
00709
00710 int dof = collisionDetector->DOF() ;
00711
00712 Configuration newconfig;
00713 newconfig.SetLength( dof );
00714
00715 bool limits_exceeded = false;
00716 LimitExceeded* joint_limit_exceeded = new LimitExceeded[dof];
00717 assert ( joint_limit_exceeded != NULL );
00718
00719 for( int i = 0; i < dof; i++ )
00720 {
00721 double max = collisionDetector->JointMax( i ) ;
00722 double min = collisionDetector->JointMin( i ) ;
00723 double random = ( double( rand() ) / RAND_MAX );
00724 double jointvalue = ( max - min ) * random + min;
00725
00726
00727 jointvalue += centre[ i ];
00728
00729
00730 if ( jointvalue < min )
00731 {
00732 limits_exceeded = true;
00733 joint_limit_exceeded[i] = MINLIMIT;
00734 }
00735 else if ( jointvalue > max )
00736 {
00737 limits_exceeded = true;
00738 joint_limit_exceeded[i] = MAXLIMIT;
00739 }
00740 else
00741 {
00742 joint_limit_exceeded[i] = NEITHER;
00743 }
00744
00745 newconfig[ i ] = jointvalue;
00746 }
00747
00748
00749 if ( limits_exceeded )
00750 {
00751
00752 VectorN slope = ( newconfig - centre );
00753 double t = 1;
00754
00755
00756 for ( int i = 0; i < dof; i++ )
00757 {
00758 double limit;
00759 if ( joint_limit_exceeded[i] == NEITHER )
00760 {
00761
00762 continue;
00763 }
00764 else if ( joint_limit_exceeded[i] == MINLIMIT )
00765 {
00766 limit = collisionDetector->JointMin(i);
00767 }
00768 else
00769 {
00770 limit = collisionDetector->JointMax(i);
00771 }
00772
00773 double s = ( limit - centre[i] ) / slope[i];
00774
00775
00776 if ( s < t )
00777 {
00778
00779 t = s;
00780 }
00781 }
00782
00783
00784
00785 newconfig = (slope * t) + centre;
00786 }
00787
00788 delete [] joint_limit_exceeded;
00789 return newconfig ;
00790 }
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 Configuration PL_GraphBase::GenerateRandomConfig( const Configuration& seed, const double& std_dev )
00801 {
00802 int dof = seed.DOF() ;
00803
00804 Configuration returnMe;
00805 returnMe.SetLength( dof );
00806
00807 for( int i=0; i < dof; i++ )
00808 {
00809 double jointvalue = RandNorm( seed[i], std_dev/distWeight[i] );
00810
00811 double jmax = collisionDetector->JointMax( i );
00812 double jmin = collisionDetector->JointMin( i );
00813
00814
00815 double jrange = jmax - jmin;
00816 assert( jrange > 0 );
00817 if ( jrange == 0 )
00818 {
00819 jointvalue = jmax;
00820 }
00821 while ( jointvalue > jmax )
00822 {
00823 jointvalue -= jrange;
00824 }
00825 while ( jointvalue < jmin )
00826 {
00827 jointvalue += jrange;
00828 }
00829
00830 returnMe[i] = jointvalue;
00831 }
00832
00833 return returnMe;
00834
00835 }
00836
00837
00838
00839
00840
00841
00842
00843
00844 bool PL_GraphBase::IsInterfering( const edge& e1 )
00845
00846 {
00847 return this->IsInterfering( G.target(e1), G.source(e1) );
00848 }
00849
00850 bool PL_GraphBase::IsInterfering( const node& n1, const node& n2 )
00851
00852 {
00853 return this->IsInterfering( G.inf(n1), G.inf(n2) );
00854 }
00855
00856 bool PL_GraphBase::IsInterfering( const Configuration& c1, const Configuration& c2 )
00857
00858 {
00859 return collisionDetector->IsInterferingLinear( c1, c2 );
00860 }
00861
00862 bool PL_GraphBase::IsInterfering( const node& n1 )
00863
00864 {
00865 return this->IsInterfering( G.inf(n1) );
00866 }
00867
00868 bool PL_GraphBase::IsInterfering( const Configuration& c1 )
00869
00870 {
00871 return this->collisionDetector->IsInterfering( c1 );
00872 }
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884 bool PL_GraphBase::DrawSpecific() const
00885 {
00886 return false;
00887 }
00888
00889
00890
00891
00892
00893
00894
00895 void PL_GraphBase::GetCoords( const node n1, double& Xcor, double& Ycor, double& Zcor ) const
00896
00897 {
00898 GetCoords( G.inf(n1), Xcor, Ycor, Zcor);
00899 }
00900
00901 void PL_GraphBase::GetCoords( const Configuration& c1, double& Xcor, double& Ycor, double& Zcor ) const
00902
00903 {
00904
00905 int dof = c1.DOF();
00906
00907
00908 if ( dof > 0 )
00909 {
00910 Xcor = c1[0];
00911 }
00912 else
00913 {
00914 Xcor = 0;
00915 }
00916
00917 if ( dof > 1 )
00918 {
00919 Ycor = c1[1];
00920 }
00921 else
00922 {
00923 Ycor = 0;
00924 }
00925
00926 if ( dof > 2 )
00927 {
00928 Zcor = c1[2];
00929 }
00930 else
00931 {
00932 Zcor = 0;
00933 }
00934
00935 return;
00936 }
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967 void PL_GraphBase::SetStartConfig( const Configuration& config )
00968 {
00969
00970 PL_Boolean_Output::SetStartConfig( config );
00971
00972
00973 startNode = FindConfig( config );
00974
00975
00976 if ( startNode == nil )
00977 {
00978 startNode = G.new_node( config );
00979 }
00980
00981 }
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992 void PL_GraphBase::SetGoalConfig( const Configuration& config )
00993 {
00994
00995 PL_Boolean_Output::SetGoalConfig( config );
00996
00997
00998 goalNode = FindConfig( config );
00999
01000
01001 if ( goalNode == nil )
01002 {
01003 goalNode = G.new_node( config );
01004 }
01005
01006 }
01007
01008
01009
01010
01011
01012
01013
01014 void PL_GraphBase::SetCollisionDetector (CD_BasicStyle* collisionDetector)
01015 {
01016
01017 PL_Boolean_Output::SetCollisionDetector( collisionDetector );
01018
01019
01020 int dof = collisionDetector->DOF();
01021
01022
01023
01024
01025
01026
01027
01028 if ( distWeight.Length() != dof )
01029 {
01030 NormDistWeight();
01031 }
01032
01033 }
01034
01035
01036
01037
01038
01039
01040
01041 void PL_GraphBase::SetDistWeight( const VectorN& weights )
01042 {
01043 if ( distWeight == weights )
01044 {
01045 return;
01046 }
01047
01048
01049
01050 distWeight = weights;
01051
01052
01053 this->ClearGraph();
01054
01055 }
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068 bool PL_GraphBase::PrioritizeEdge(node sourcenode, edge e1)
01069
01070
01071
01072
01073 {
01074 node targetnode = G.target(e1);
01075
01076
01077 if (targetnode == sourcenode)
01078 {
01079 targetnode = G.source(e1);
01080
01081
01082 if (targetnode == sourcenode)
01083 {
01084 return FALSE;
01085 }
01086 }
01087
01088
01089 edge e2 = G.first_adj_edge(sourcenode);
01090 if (e2 == nil)
01091 {
01092
01093 G.move_edge( e1, sourcenode, targetnode );
01094 }
01095 else if (e1 != e2)
01096 {
01097
01098 G.move_edge( e1, e2, targetnode, LEDA::before);
01099
01100 }
01101
01102 return TRUE;
01103
01104 }
01105
01106 bool PL_GraphBase::PrioritizeEdge(node prev, node curr)
01107
01108
01109
01110 {
01111 edge e1;
01112 edge e2;
01113
01114 if (prev == curr)
01115 {
01116
01117 return FALSE;
01118 }
01119
01120
01121
01122 forall_inout_edges(e1, curr)
01123 {
01124 if (( G.target(e1) == prev ) || ( G.source(e1) == prev ))
01125 {
01126
01127 e2 = G.first_adj_edge(curr);
01128 if (e2 == nil)
01129 {
01130
01131 G.move_edge( e1, curr, prev );
01132 }
01133 else if (e1 != e2)
01134 {
01135
01136 G.move_edge( e1, e2, prev, LEDA::before);
01137
01138 }
01139 return TRUE;
01140 }
01141 }
01142
01143
01144 return FALSE;
01145 }
01146
01147
01148
01149
01150
01151
01152 Configuration PL_GraphBase::GetMidPoint( const Configuration& a, const Configuration& b ) const
01153 {
01154 VectorN jointdisp = collisionDetector->JointDisplacement( a, b );
01155
01156 Configuration midpt = a + ( jointdisp / 2 );
01157
01158 return midpt;
01159 }
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170 SuccessResultType PL_GraphBase::TranslatePath()
01171 {
01172
01173 path.Clear();
01174
01175
01176 if ( graphPath.empty() )
01177 {
01178
01179 path.AppendPoint( GetStartConfig() );
01180
01181
01182 return FAIL;
01183 }
01184
01185
01186
01187
01188 node n1;
01189 forall( n1, graphPath )
01190 {
01191 path.AppendPoint( G.inf(n1) );
01192 }
01193
01194
01195
01196 return PASS;
01197 }
01198
01199
01200
01201
01202
01203
01204 void PL_GraphBase::CopySettings( PlannerBase* original )
01205 {
01206 PL_GraphBase* originalGraphBase = dynamic_cast< PL_GraphBase* >( original );
01207 if( originalGraphBase == NULL )
01208 {
01209 return;
01210 }
01211 this->distWeight = originalGraphBase->distWeight;
01212 }
01213
01214
01215
01216
01217
01218
01219
01220 node PL_GraphBase::TranslateNodeID( const int& nodeID ) const
01221 {
01222
01223 if ( ( nodeID == NIL_ID ) ||
01224 ( G.empty() ) ||
01225 ( nodeID > G.number_of_nodes() ) )
01226 {
01227 return nil;
01228 }
01229
01230
01231 if ( nodeID < (G.number_of_nodes()/2) )
01232 {
01233
01234 node n1;
01235 forall_nodes( n1, G )
01236 {
01237 if ( n1->id() == nodeID )
01238 {
01239 return n1;
01240 }
01241 }
01242 }
01243 else
01244 {
01245
01246 node n1;
01247 forall_rev_nodes( n1, G )
01248 {
01249 if ( n1->id() == nodeID )
01250 {
01251 return n1;
01252 }
01253 }
01254 }
01255
01256
01257 ASSERT( FALSE );
01258
01259 return nil;
01260 }