From 6acd6539fea2895422b2671f16c46a822a0bf342 Mon Sep 17 00:00:00 2001 From: Jiri Vlasak Date: Mon, 10 Dec 2018 10:01:23 +0100 Subject: [PATCH] Make `nn` procedure part of RRTBase --- CHANGELOG.md | 1 + CMakeLists.txt | 7 ---- README.md | 2 -- base/rrtbase.cc | 6 ++++ decision_control/rrtplanner.cc | 61 ++++------------------------------ incl/compile.h | 4 --- incl/rrtbase.h | 1 + incl/rrtplanner.h | 60 --------------------------------- 8 files changed, 15 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0e1fa..cdea360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog][] and this project adheres to ### Changed - Make `sample` procedure part of RRTBase. - Make `cost` function part of RRTBase. +- Make `nn` procedure part of RRTBase. ## 0.3.0 - 2018-12-03 ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f4d661..fc164d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,6 @@ ENDIF(PLANNER) IF(TMAX) ADD_DEFINITIONS(-DTMAX=${TMAX}) ENDIF(TMAX) -IF(NN) - ADD_DEFINITIONS(-DNN=${NN}) -ENDIF(NN) IF(NV) ADD_DEFINITIONS(-DNV=${NV}) ENDIF(NV) @@ -17,10 +14,6 @@ IF(ST) ADD_DEFINITIONS(-DST=${ST}) ENDIF(ST) -IF(NNVERSION) - ADD_DEFINITIONS(-DNNVERSION=${NNVERSION}) -ENDIF(NNVERSION) - IF(NVVERSION) ADD_DEFINITIONS(-DNVVERSION=${NVVERSION}) ENDIF(NVVERSION) diff --git a/README.md b/README.md index 7b18b73..0c76203 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,6 @@ The list of available macros with values: - `Kuwata2008` - RRT with changing cost and steering to goal. - `Karaman2011` - RRT* framework. - `TMAX` - Specify the upper time bound in seconds. -- `NN` - - `nn1` - Nearest neighbour basic DFS procedure. - `NV` - `nv1` - Near vertices basic DFS procedure. - `ST` diff --git a/base/rrtbase.cc b/base/rrtbase.cc index 8a05b3e..4725655 100644 --- a/base/rrtbase.cc +++ b/base/rrtbase.cc @@ -29,6 +29,7 @@ along with I am car. If not, see . #include "sample.h" #include "cost.h" #include "steer.h" +#include "nn.h" extern SDL_Window* gw; extern SDL_GLContext gc; @@ -685,3 +686,8 @@ float RRTBase::cost(RRTNode *init, RRTNode *goal) { return co2(init, goal); } + +RRTNode *RRTBase::nn(RRTNode *rs) +{ + return nn4(this->iy_, rs, nullptr); +} diff --git a/decision_control/rrtplanner.cc b/decision_control/rrtplanner.cc index 7c3e312..b88199c 100644 --- a/decision_control/rrtplanner.cc +++ b/decision_control/rrtplanner.cc @@ -33,7 +33,6 @@ along with I am car. If not, see . LaValle1998::LaValle1998(RRTNode *init, RRTNode *goal): RRTBase(init, goal), - nn(NN), steer(ST) { srand(static_cast(time(0))); @@ -51,13 +50,7 @@ bool LaValle1998::next() rs = this->sample(); #endif this->samples().push_back(rs); -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, '0'); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, &this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); RRTNode *pn = nn; bool en_add = true; for (auto ns: this->steer(nn, rs)) { @@ -87,7 +80,6 @@ bool LaValle1998::next() Kuwata2008::Kuwata2008(RRTNode *init, RRTNode *goal): RRTBase(init, goal), - nn(NN), steer(ST) { srand(static_cast(time(0))); @@ -114,13 +106,7 @@ bool Kuwata2008::next() else {}//this->cost = &KUWATA2008_DCOST; } -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, '0'); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); RRTNode *pn = nn; std::vector newly_added; bool en_add = true; @@ -181,7 +167,6 @@ bool Kuwata2008::next() Karaman2011::Karaman2011(RRTNode *init, RRTNode *goal): RRTBase(init, goal), - nn(NN), nv(NV), steer(ST) { @@ -200,13 +185,7 @@ bool Karaman2011::next() rs = this->sample(); #endif this->samples().push_back(rs); -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, '0'); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); RRTNode *pn = nn; std::vector nvs; bool en_add = true; @@ -332,7 +311,6 @@ bool Karaman2011::rewire(std::vector nvs, RRTNode *ns) T1::T1(RRTNode *init, RRTNode *goal): RRTBase(init, goal), - nn(NN), nv(NV), steer(ST) { @@ -347,13 +325,7 @@ bool T1::next() else rs = this->sample(); this->samples().push_back(rs); -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, '0'); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); RRTNode *pn = nn; std::vector nvs; bool connected; @@ -467,13 +439,7 @@ bool T2::next() rs = this->sample(); #endif this->samples().push_back(rs); -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, '0'); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); if (!nn) return false; RRTNode *pn = nn; @@ -705,7 +671,6 @@ bool T3::overlaptrees(RRTNode **ron, RRTNode **gon) Klemm2015::Klemm2015(RRTNode *init, RRTNode *goal): Karaman2011(init, goal), - nn(NN), nv(NV), steer(ST), orig_root_(init), @@ -779,13 +744,7 @@ int Klemm2015::extendstar1(RRTNode *rs, RRTNode **xn) // std::cerr << std::endl; // } //} -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, tree); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); //std::cerr << " - nn: " << nn->x() << ", " << nn->y() << std::endl; std::vector nvs; std::vector steered = this->steer(nn, rs); @@ -847,13 +806,7 @@ int Klemm2015::extendstarC(RRTNode *rs) //std::cerr << "extend*C" << std::endl; //std::cerr << "- tree is " << tree << std::endl; //std::cerr << " - rs: " << rs->x() << ", " << rs->y() << std::endl; -#if NNVERSION>2 - RRTNode *nn = this->nn(this->iy_, rs, this->cost, tree); -#elif NNVERSION>1 - RRTNode *nn = this->nn(this->iy_, rs, this->cost); -#else - RRTNode *nn = this->nn(this->nodes(), rs, this->cost); -#endif + RRTNode *nn = this->nn(rs); RRTNode *pn = nn; std::vector nvs; bool en_add = true; diff --git a/incl/compile.h b/incl/compile.h index e5f2b1d..75444b9 100644 --- a/incl/compile.h +++ b/incl/compile.h @@ -26,10 +26,6 @@ along with I am car. If not, see . #define TMAX 10 #endif -#ifndef NN -#define NN nn1 -#endif - #ifndef NV #define NV nv1 #endif diff --git a/incl/rrtbase.h b/incl/rrtbase.h index a1ee10c..7d82a58 100644 --- a/incl/rrtbase.h +++ b/incl/rrtbase.h @@ -103,6 +103,7 @@ class RRTBase { // RRT Framework RRTNode *sample(); float cost(RRTNode *init, RRTNode *goal); + RRTNode *nn(RRTNode *rs); // virtuals - implemented by child classes virtual bool next() = 0; diff --git a/incl/rrtplanner.h b/incl/rrtplanner.h index 53195db..25854e4 100644 --- a/incl/rrtplanner.h +++ b/incl/rrtplanner.h @@ -30,18 +30,6 @@ class LaValle1998: public RRTBase { LaValle1998(RRTNode *init, RRTNode *goal); // RRT framework - RRTNode *(*nn)( -#if NNVERSION>1 - std::vector (&nodes)[IYSIZE], -#else - std::vector &nodes, -#endif - RRTNode *node, - float (*cost)(RRTNode *, RRTNode *) -#if NNVERSION>2 - , char tree -#endif - ); std::vector (*steer)( RRTNode *init, RRTNode *goal); @@ -53,18 +41,6 @@ class Kuwata2008: public RRTBase { Kuwata2008(RRTNode *init, RRTNode *goal); // RRT framework - RRTNode *(*nn)( -#if NNVERSION>1 - std::vector (&nodes)[IYSIZE], -#else - std::vector &nodes, -#endif - RRTNode *node, - float (*cost)(RRTNode *, RRTNode *) -#if NNVERSION>2 - , char tree -#endif - ); std::vector (*steer)( RRTNode *init, RRTNode *goal); @@ -82,18 +58,6 @@ class Karaman2011: public RRTBase { Karaman2011(RRTNode *init, RRTNode *goal); // RRT framework - RRTNode *(*nn)( -#if NNVERSION>1 - std::vector (&nodes)[IYSIZE], -#else - std::vector &nodes, -#endif - RRTNode *node, - float (*cost)(RRTNode *, RRTNode *) -#if NNVERSION>2 - , char tree -#endif - ); std::vector (*nv)( #if NVVERSION>1 std::vector (&nodes)[IYSIZE], @@ -118,18 +82,6 @@ class T1: public RRTBase { T1(RRTNode *init, RRTNode *goal); // RRT framework - RRTNode *(*nn)( -#if NNVERSION>1 - std::vector (&nodes)[IYSIZE], -#else - std::vector &nodes, -#endif - RRTNode *node, - float (*cost)(RRTNode *, RRTNode *) -#if NNVERSION>2 - , char tree -#endif - ); std::vector (*nv)( #if NVVERSION>1 std::vector (&nodes)[IYSIZE], @@ -184,18 +136,6 @@ class Klemm2015: public Karaman2011 { Klemm2015(RRTNode *init, RRTNode *goal); // RRT framework - RRTNode *(*nn)( -#if NNVERSION>1 - std::vector (&nodes)[IYSIZE], -#else - std::vector &nodes, -#endif - RRTNode *node, - float (*cost)(RRTNode *, RRTNode *) -#if NNVERSION>2 - , char tree -#endif - ); std::vector (*nv)( #if NVVERSION>1 std::vector (&nodes)[IYSIZE], -- 2.39.2