00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef LSL_LAZZY_GRID_HH
00036 #define LSL_LAZZY_GRID_HH
00037
00038 #include <ndt_map/spatial_index.h>
00039 #include <ndt_map/ndt_cell.h>
00040
00041 namespace lslgeneric
00042 {
00043
00047 class LazyGrid : public SpatialIndex
00048 {
00049 public:
00050 LazyGrid(double cellSize);
00051 LazyGrid(LazyGrid *prot);
00052 LazyGrid(double sizeXmeters, double sizeYmeters, double sizeZmeters,
00053 double cellSizeX, double cellSizeY, double cellSizeZ,
00054 double _centerX, double _centerY, double _centerZ,
00055 NDTCell *cellPrototype );
00056 virtual ~LazyGrid();
00057
00058 virtual NDTCell* getCellForPoint(const pcl::PointXYZ &point);
00059 virtual NDTCell* addPoint(const pcl::PointXYZ &point);
00060
00061
00063 virtual typename SpatialIndex::CellVectorItr begin();
00065 virtual typename SpatialIndex::CellVectorItr end();
00066 virtual int size();
00067
00069 virtual SpatialIndex* clone() const;
00070 virtual SpatialIndex* copy() const;
00071
00073 virtual void getNeighbors(const pcl::PointXYZ &point, const double &radius, std::vector<NDTCell*> &cells);
00074
00076 virtual void setCellType(NDTCell *type);
00077
00078 virtual void setCenter(const double &cx, const double &cy, const double &cz);
00079 virtual void setSize(const double &sx, const double &sy, const double &sz);
00080
00081 virtual NDTCell* getClosestNDTCell(const pcl::PointXYZ &pt, bool checkForGaussian=true);
00082 virtual std::vector<NDTCell*> getClosestNDTCells(const pcl::PointXYZ &pt, int &n_neigh, bool checkForGaussian=true);
00083 virtual std::vector<NDTCell*> getClosestCells(const pcl::PointXYZ &pt);
00084
00085 virtual inline void getCellAt(int indX, int indY, int indZ, NDTCell* &cell){
00086 if(indX < sizeX && indY < sizeY && indZ < sizeZ && indX >=0 && indY >=0 && indZ >=0){
00087 cell = dataArray[indX][indY][indZ];
00088 }else{
00089 cell = NULL;
00090
00091 }
00092 }
00093 virtual inline void getCellAt(const pcl::PointXYZ& pt, NDTCell* &cell){
00094 int indX,indY,indZ;
00095 this->getIndexForPoint(pt,indX,indY,indZ);
00096 this->getCellAt(indX,indY,indZ,cell);
00097 }
00098
00099 virtual inline void getNDTCellAt(int indX, int indY, int indZ, NDTCell* &cell){
00100 if(indX < sizeX && indY < sizeY && indZ < sizeZ && indX >=0 && indY >=0 && indZ >=0){
00101 cell = (dataArray[indX][indY][indZ]);
00102 }else{
00103 cell = NULL;
00104 }
00105 }
00106 virtual inline void getNDTCellAt(const pcl::PointXYZ& pt, NDTCell* &cell){
00107 int indX,indY,indZ;
00108 this->getIndexForPoint(pt,indX,indY,indZ);
00109 this->getNDTCellAt(indX,indY,indZ,cell);
00110 }
00111
00112 void getCellSize(double &cx, double &cy, double &cz);
00113 void getGridSize(int &cx, int &cy, int &cz);
00114 void getGridSizeInMeters(double &cx, double &cy, double &cz);
00115 void getCenter(double &cx, double &cy, double &cz);
00116 virtual void getIndexForPoint(const pcl::PointXYZ& pt, int &idx, int &idy, int &idz);
00117 NDTCell* getProtoType()
00118 {
00119 return protoType;
00120 }
00121
00122 virtual void initialize();
00123 virtual void initializeAll() ;
00124
00125 NDTCell ****getDataArrayPtr()
00126 {
00127 return dataArray;
00128 }
00129
00131 virtual int loadFromJFF(FILE * jffin);
00132 bool traceLine(const Eigen::Vector3d &origin, const pcl::PointXYZ &endpoint, const Eigen::Vector3d &diff, const double& maxz, std::vector<NDTCell*> &cells);
00133 bool traceLineWithEndpoint(const Eigen::Vector3d &origin, const pcl::PointXYZ &endpoint, const Eigen::Vector3d &diff, const double& maxz, std::vector<NDTCell*> &cells, Eigen::Vector3d &final_point);
00134 bool isInside(const pcl::PointXYZ& pt) {
00135 int indX,indY,indZ;
00136 this->getIndexForPoint(pt,indX,indY,indZ);
00137 return(indX < sizeX && indY < sizeY && indZ < sizeZ && indX >=0 && indY >=0 && indZ >=0);
00138 }
00139 protected:
00140 bool initialized;
00141 NDTCell ****dataArray;
00142
00143 NDTCell *protoType;
00144 std::vector<NDTCell*> activeCells;
00145 bool centerIsSet, sizeIsSet;
00146
00147 double sizeXmeters, sizeYmeters, sizeZmeters;
00148 double cellSizeX, cellSizeY, cellSizeZ;
00149 double centerX, centerY, centerZ;
00150 int sizeX,sizeY,sizeZ;
00151
00152 virtual bool checkCellforNDT(int indX, int indY, int indZ, bool checkForGaussian=true);
00153 public:
00154 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00155 };
00156
00157
00158 };
00159
00160
00161 #endif