MRXT: The Multi-Robot eXploration Tool
Multi-Robot autonomous exploration and mapping simulator.
src/architecture/slam/mapdata/visualMap.cpp
00001 /*
00002 *
00003 * Author: Miguel Julia <mjulia@umh.es> 
00004 * 
00005 * Date:   2008
00006 * 
00007 * Class visualMap
00008 *
00009 * Implements a visual landmark 3d map
00010 *
00011 */
00012 
00013 #include "visualMap.h"
00014 #include <stdlib.h>
00015 #include <stdio.h>
00016 #include <assert.h>
00017 #include "matFuns.h"
00018 
00019 // Constructor
00020 visualMap::visualMap():
00021         nlandmarks              (0),
00022         camx                    (0.0f),
00023         camy                    (0.0f),
00024         camz                    (0.0f),
00025         rx                      (0.0f),
00026         ry                      (0.0f),
00027         rz                      (0.0f),
00028 //      range                   (0.0f),
00029         mahTh                   (0.0f),
00030         descTh                  (0.0f)
00031 {
00032 
00033 }
00034 
00035 // Constructor
00036 visualMap::visualMap(int n, const ConfigFile& configFile):
00037         nlandmarks              (0),
00038         camx                    (configFile.read<float>("camx")),
00039         camy                    (configFile.read<float>("camy")),
00040         camz                    (configFile.read<float>("camz")),
00041         rx                      (configFile.read<float>("rx")),
00042         ry                      (configFile.read<float>("ry")),
00043         rz                      (configFile.read<float>("rz")),
00044 //      range                   (configFile.read<float>("SEARCHRANGE")),
00045         mahTh                   (configFile.read<float>("MAHALANOBISTH")),
00046         descTh                  (configFile.read<float>("DESCRIPTORTH"))
00047 {
00048 
00049 }
00050 
00051 // copy constructor
00052 visualMap::visualMap(const visualMap &map):
00053         nlandmarks              (map.nlandmarks),
00054         camx                    (map.camx),
00055         camy                    (map.camy),
00056         camz                    (map.camz),
00057         rx                      (map.rx),
00058         ry                      (map.ry),
00059         rz                      (map.rz),
00060 //      range                   (map.range),
00061         mahTh                   (map.mahTh),
00062         descTh                  (map.descTh)
00063 {
00064 
00065 }
00066 
00067 
00068 // destructor
00069 visualMap::~visualMap(){
00070 
00071 }
00072 
00073 // initializer
00074 void visualMap::initialize(int n, const ConfigFile& configFile){
00075         nlandmarks              = 0;
00076         camx                    = configFile.read<double>("camx");
00077         camy                    = configFile.read<double>("camy");
00078         camz                    = configFile.read<double>("camz");
00079         rx                      = configFile.read<double>("rx");
00080         ry                      = configFile.read<double>("ry");
00081         rz                      = configFile.read<double>("rz");
00082 //      range                   = configFile.read<float>("SEARCHRANGE");
00083         mahTh                   = configFile.read<float>("MAHALANOBISTH");
00084         descTh                  = configFile.read<float>("DESCRIPTORTH");
00085 }
00086 
00087 // assignment operator
00088 visualMap& visualMap::operator=(const visualMap& map){
00089         nlandmarks              = map.nlandmarks;
00090         camx                    = map.camx;
00091         camy                    = map.camy;
00092         camz                    = map.camz;
00093         rx                      = map.rx;
00094         ry                      = map.ry;
00095         rz                      = map.rz;
00096 //      range                   = map.range;
00097         mahTh                   = map.mahTh;
00098         descTh                  = map.descTh;
00099         return *this;
00100 }
00101 
00102 
00103 // distance between descriptors
00104 float visualMap::descDist(const float* desc1, const float* desc2, int desclength){
00105         float dist_sq=0, tmp_val;
00106         for (int i = 0; i< desclength; i++){
00107                 tmp_val = desc1[i] - desc2[i];
00108                 dist_sq += tmp_val*tmp_val;
00109         }
00110         return sqrt(dist_sq);
00111 }
00112 
00113 // mahalanobis distance
00114 float visualMap::mahalanobis(const pos3d& pos, const matrix& sigma){
00115 //      float det = (sigma(0,0)*sigma(1,1)-sigma(1,0)*sigma(0,1));
00116 //      return( (( (sigma(1,1)*pos.getX()-pos.getY()*sigma(0,1))*pos.getX() + (-pos.getX()*sigma(1,0)+sigma(0,0)*pos.getY())*pos.getY())/det + 1/(sigma(2,2))*pos.getZ()*pos.getZ() ));
00117         matrix x = pos;
00118         return (x.transpose()*((sigma.inverse())*x)).get(0,0);
00119 }
00120 
00121 
00122 // translates a position in the robot's frame of reference to the camera frame of reference
00123 pos3d visualMap::base2cam(const pos3d& p) const{
00124         return pos3d(p.getX() - camx,
00125                                  p.getY() - camy,
00126                                  p.getZ() - camz);
00127 }
00128 
00129 // TODO: use calibration rx, ry, rz
00130 // translates a position in the camera frame of reference to the robot's frame of reference
00131 pos3d visualMap::cam2base(const pos3d& p) const{
00132         return pos3d(p.getX()+ camx,
00133                                  p.getY()+ camy,
00134                                  p.getZ()+ camz);
00135 }
 All Classes Functions Variables Typedefs