From 5a30638c78a47ebb3bf671485f1a1816d94ada88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Sol=C3=A0?= <jsola@iri.upc.edu>
Date: Wed, 26 Oct 2016 09:48:13 +0200
Subject: [PATCH] New macro GET_WOLF_ROOT

This loads the WOLF_ROOT environment variable to the local set of
variables.
---
 src/examples/test_constraint_AHP.cpp          |  8 +++----
 src/examples/test_image.cpp                   |  8 +++----
 .../test_processor_image_landmark.cpp         | 24 +++++++++----------
 src/examples/test_processor_odom_3D.cpp       | 19 ++++++++-------
 src/wolf.h                                    | 14 +++++++++++
 5 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/src/examples/test_constraint_AHP.cpp b/src/examples/test_constraint_AHP.cpp
index 040b95133..55215e8f3 100644
--- a/src/examples/test_constraint_AHP.cpp
+++ b/src/examples/test_constraint_AHP.cpp
@@ -16,8 +16,8 @@ int main()
     char const* tmp = std::getenv( "WOLF_ROOT" );
     if ( tmp == nullptr )
         throw std::runtime_error("WOLF_ROOT environment not loaded.");
-    std::string wolf_path( tmp );
-    std::cout << "Wolf path: " << wolf_path << std::endl;
+    std::string wolf_root( tmp );
+    std::cout << "Wolf root: " << wolf_root << std::endl;
 
     // Wolf problem
     ProblemPtr wolf_problem_ptr_ = Problem::create(FRM_PO_3D);
@@ -35,12 +35,12 @@ int main()
     const Eigen::VectorXs extr = extrinsic_cam;
     /* Do this while there aren't extrinsic parameters on the yaml */
 
-    SensorBasePtr sensor_ptr = wolf_problem_ptr_->installSensor("CAMERA", "PinHole", extr, wolf_path + "/src/examples/camera_params.yaml");
+    SensorBasePtr sensor_ptr = wolf_problem_ptr_->installSensor("CAMERA", "PinHole", extr, wolf_root + "/src/examples/camera_params.yaml");
     std::shared_ptr<SensorCamera> camera_ptr_ = std::static_pointer_cast<SensorCamera>(sensor_ptr);
 
     // PROCESSOR
     // one-liner API
-    wolf_problem_ptr_->installProcessor("IMAGE LANDMARK", "ORB", "PinHole", wolf_path + "/src/examples/processor_image_ORB.yaml");
+    wolf_problem_ptr_->installProcessor("IMAGE LANDMARK", "ORB", "PinHole", wolf_root + "/src/examples/processor_image_ORB.yaml");
 
 
     // create the current frame
diff --git a/src/examples/test_image.cpp b/src/examples/test_image.cpp
index c1cad9a1c..b18c60ff3 100644
--- a/src/examples/test_image.cpp
+++ b/src/examples/test_image.cpp
@@ -70,8 +70,8 @@ int main(int argc, char** argv)
     if ( tmp == nullptr )
         throw std::runtime_error("WOLF_ROOT environment not loaded.");
 
-    std::string wolf_path( tmp );
-    std::cout << "Wolf path: " << wolf_path << std::endl;
+    std::string wolf_root( tmp );
+    std::cout << "Wolf root: " << wolf_root << std::endl;
 
     ProblemPtr wolf_problem_ = Problem::create(FRM_PO_3D);
 
@@ -134,14 +134,14 @@ int main(int argc, char** argv)
 
     // SENSOR
     // one-liner API
-    SensorBasePtr sensor_ptr = wolf_problem_->installSensor("CAMERA", "PinHole", Eigen::VectorXs::Zero(7), wolf_path + "/src/examples/camera_params.yaml");
+    SensorBasePtr sensor_ptr = wolf_problem_->installSensor("CAMERA", "PinHole", Eigen::VectorXs::Zero(7), wolf_root + "/src/examples/camera_params.yaml");
     shared_ptr<SensorCamera> camera_ptr = static_pointer_cast<SensorCamera>(sensor_ptr);
     camera_ptr->setImgWidth(img_width);
     camera_ptr->setImgHeight(img_height);
 
     // PROCESSOR
     // one-liner API
-    ProcessorImageFeature::Ptr prc_img_ptr = std::static_pointer_cast<ProcessorImageFeature>( wolf_problem_->installProcessor("IMAGE FEATURE", "ORB", "PinHole", wolf_path + "/src/examples/processor_image_ORB.yaml") );
+    ProcessorImageFeature::Ptr prc_img_ptr = std::static_pointer_cast<ProcessorImageFeature>( wolf_problem_->installProcessor("IMAGE FEATURE", "ORB", "PinHole", wolf_root + "/src/examples/processor_image_ORB.yaml") );
     prc_img_ptr->setup(camera_ptr);
     std::cout << "sensor & processor created and added to wolf problem" << std::endl;
     //=====================================================
diff --git a/src/examples/test_processor_image_landmark.cpp b/src/examples/test_processor_image_landmark.cpp
index aae584df2..7f4f5829c 100644
--- a/src/examples/test_processor_image_landmark.cpp
+++ b/src/examples/test_processor_image_landmark.cpp
@@ -66,15 +66,15 @@ int main(int argc, char** argv)
     //=====================================================
 
 
-    //=====================================================
-    // Environment variable for configuration files
-    char const* tmp = std::getenv( "WOLF_ROOT" );
-    if ( tmp == nullptr )
-        throw std::runtime_error("WOLF_ROOT environment not loaded.");
-    std::string wolf_path( tmp );
-    std::cout << "Wolf path: " << wolf_path << std::endl;
-    //=====================================================
-
+//    //=====================================================
+//    // Environment variable for configuration files
+//    char const* tmp = std::getenv( "WOLF_ROOT" );
+//    if ( tmp == nullptr )
+//        throw std::runtime_error("WOLF_ROOT environment not loaded.");
+//    std::string wolf_root( tmp );
+//    std::cout << "Wolf root: " << wolf_root << std::endl;
+//    //=====================================================
+    GET_WOLF_ROOT
 
 
     //=====================================================
@@ -82,16 +82,16 @@ int main(int argc, char** argv)
     ProblemPtr wolf_problem_ptr_ = Problem::create(FRM_PO_3D);
 
     // CAMERA SENSOR
-    SensorBasePtr sensor_ptr = wolf_problem_ptr_->installSensor("CAMERA", "PinHole", (Vector7s()<<0,0,0,0,0,0,1).finished(), wolf_path + "/src/examples/camera_params.yaml");
+    SensorBasePtr sensor_ptr = wolf_problem_ptr_->installSensor("CAMERA", "PinHole", (Vector7s()<<0,0,0,0,0,0,1).finished(), wolf_root + "/src/examples/camera_params.yaml");
     SensorCamera::Ptr camera_ptr = std::static_pointer_cast<SensorCamera>(sensor_ptr);
     camera_ptr->setImgWidth(img_width);
     camera_ptr->setImgHeight(img_height);
 
     // IMAGE PROCESSOR
-    wolf_problem_ptr_->installProcessor("IMAGE LANDMARK", "ORB", "PinHole", wolf_path + "/src/examples/processor_image_ORB.yaml");
+    wolf_problem_ptr_->installProcessor("IMAGE LANDMARK", "ORB", "PinHole", wolf_root + "/src/examples/processor_image_ORB.yaml");
 
     // ODOM SENSOR AND PROCESSOR
-    SensorBasePtr sen_ptr = wolf_problem_ptr_->installSensor("ODOM 3D", "odom", (Vector7s()<<0,0,0,0,0,0,1).finished(), wolf_path + "/src/examples/odom_3D.yaml");
+    SensorBasePtr sen_ptr = wolf_problem_ptr_->installSensor("ODOM 3D", "odom", (Vector7s()<<0,0,0,0,0,0,1).finished(), wolf_root + "/src/examples/odom_3D.yaml");
     ProcessorBasePtr prc_ptr = wolf_problem_ptr_->installProcessor("ODOM 3D", "odometry integrator", "odom");
     SensorOdom3D::Ptr sen_odo_ptr = std::static_pointer_cast<SensorOdom3D>(sen_ptr);
     //=====================================================
diff --git a/src/examples/test_processor_odom_3D.cpp b/src/examples/test_processor_odom_3D.cpp
index 464760f2a..89646f3b5 100644
--- a/src/examples/test_processor_odom_3D.cpp
+++ b/src/examples/test_processor_odom_3D.cpp
@@ -31,14 +31,15 @@ int main (int argc, char** argv)
 {
     cout << "\n========= Test ProcessorOdom3D ===========" << endl;
 
-    //=====================================================
-    // Environment variable for configuration files
-    char const* tmp = std::getenv( "WOLF_ROOT" );
-    if ( tmp == nullptr )
-        throw std::runtime_error("WOLF_ROOT environment not loaded.");
-    std::string wolf_path( tmp );
-    std::cout << "Wolf path: " << wolf_path << std::endl;
-    //=====================================================
+//    //=====================================================
+//    // Environment variable for configuration files
+//    char const* tmp = std::getenv( "WOLF_ROOT" );
+//    if ( tmp == nullptr )
+//        throw std::runtime_error("WOLF_ROOT environment not loaded.");
+//    std::string wolf_root( tmp );
+//    std::cout << "Wolf root: " << wolf_root << std::endl;
+//    //=====================================================
+    GET_WOLF_ROOT
 
 
     TimeStamp tf;
@@ -54,7 +55,7 @@ int main (int argc, char** argv)
     ProblemPtr problem = Problem::create(FRM_PO_3D);
     CeresManager ceres_manager(problem);
 
-    SensorBasePtr sen = problem->installSensor("ODOM 3D", "odom", (Vector7s()<<0,0,0,0,0,0,1).finished(), wolf_path + "/src/examples/odom_3D.yaml");
+    SensorBasePtr sen = problem->installSensor("ODOM 3D", "odom", (Vector7s()<<0,0,0,0,0,0,1).finished(), wolf_root + "/src/examples/odom_3D.yaml");
     problem->installProcessor("ODOM 3D", "odometry integrator", "odom");
     problem->getProcessorMotionPtr()->setOrigin((Vector7s()<<0,0,0,0,0,0,1).finished(), TimeStamp(0));
 
diff --git a/src/wolf.h b/src/wolf.h
index 510ea843e..7d1bfd7ed 100644
--- a/src/wolf.h
+++ b/src/wolf.h
@@ -415,6 +415,20 @@ inline const Eigen::Vector3s gravity(void) {
     return Eigen::Vector3s(0,0,-9.8);
 }
 
+//===================================================
+// Some macros
+
+//=====================================================
+// Environment variable for configuration files
+// this sets the local variable wolf_root from the environment variable WOLF_ROOT
+#define GET_WOLF_ROOT \
+char const* tmp = std::getenv( "WOLF_ROOT" ); \
+if ( tmp == nullptr ) \
+    throw std::runtime_error("WOLF_ROOT environment not loaded."); \
+std::string wolf_root( tmp ); \
+std::cout << "Wolf root: " << wolf_root << " set at variable 'wolf_root'." << std::endl;
+//=====================================================
+
 
 } // namespace wolf
 
-- 
GitLab