smoothers/SM_SuccessiveAndRandomSmoothing.cpp

Go to the documentation of this file.
00001 #include <assert.h>
00002 #include "CollisionDetectors\CD_BasicStyle.h"
00003 #include "SM_SuccessiveAndRandomSmoothing.h"
00004 
00005 //=============================================================================
00006 // Constructor
00007 //
00008 // Description: constructor
00009 //=============================================================================
00010 SM_SuccessiveAndRandomSmoothing::SM_SuccessiveAndRandomSmoothing()
00011         :
00012         SM_PathSmoothingSuccessiveNodePair(), SM_PathSmoothingRandomNodePair()
00013 {
00014 }
00015 
00016 //=============================================================================
00017 // Destructor
00018 //
00019 // Description: destructor
00020 //=============================================================================
00021 SM_SuccessiveAndRandomSmoothing::~SM_SuccessiveAndRandomSmoothing()
00022 {
00023 }
00024 
00025 //===============================================================================
00026 // Smooth
00027 //
00028 // Description: performs the smoothing operation based on cascading the
00029 //              graph smoothing method followed by the path smoothing method
00030 //===============================================================================
00031 void SM_SuccessiveAndRandomSmoothing::Smooth()
00032 {
00033         SM_PathSmoothingSuccessiveNodePair::Smooth();
00034         this->m_Interim = this->m_SmoothedPath;
00035         PathSmoothing();
00036 }
00037 
00038 void SM_SuccessiveAndRandomSmoothing::PathSmoothing()
00039 {
00040         bool pathInterfering = true;
00041         int      t1 = 0, t2 = 0, temp = 0, size = 0;
00042         double old_dist = 0.0, new_dist = 0.0;
00043         Configuration c1;
00044         Configuration c2;
00045 
00046         size = this->m_Interim.Size();
00047         // no filtering is needed
00048         if (size == 2)
00049         {
00050                 this->m_SmoothedPath.Clear();
00051                 this->m_SmoothedPath.AppendPoint(this->m_Interim.GetPoint(0));
00052                 this->m_SmoothedPath.AppendPoint(this->m_Interim.GetPoint(1));
00053                 return;
00054         }
00055 
00056         this->m_Points.clear();
00057         for (int i = 0; i < size; i++)
00058         {
00059                 this->m_Points.push_back(this->m_Interim.GetPoint(i));
00060         }
00061 
00062         // repeat n times
00063         for (int n = 0; n < 1000; n++)
00064         {
00065                 t1 = Random(0,this->m_Points.size());
00066                 t2 = Random(0,this->m_Points.size());
00067 
00068                 // ensure t1 < t2
00069                 if (t1 > t2)
00070                 {
00071                         temp = t1;
00072                         t1 = t2;
00073                         t2 = temp;
00074                 }
00075                 assert(t1 <= t2);
00076 
00077                 c1 = this->m_Points[t1];
00078                 c2 = this->m_Points[t2];
00079                 pathInterfering = this->m_CollisionDetector->IsInterferingLinear(c1,c2);
00080 
00081                 if (pathInterfering)
00082                         continue;
00083                 else
00084                 {
00085                         new_dist = Distance(c1,c2);
00086                         old_dist = 0.0;
00087                         for (int j = t1; j < t2; j++)
00088                         {
00089                                 old_dist += Distance(this->m_Points[j],this->m_Points[j+1]);
00090                         }
00091                         if (new_dist < old_dist)
00092                                 UpdatePoints(t1,t2);
00093                 }
00094         }
00095 
00096         this->m_SmoothedPath.Clear();
00097         for (int k = 0; k < this->m_Points.size(); k++)
00098         {
00099                 this->m_SmoothedPath.AppendPoint(this->m_Points[k]);
00100         }
00101 }

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