GridMap.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Fraunhofer FKIE
00003  *
00004  * Authors: Bastian Gaspers
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * * Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * * Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * * Neither the name of the Fraunhofer FKIE nor the names of its
00015  *   contributors may be used to endorse or promote products derived from
00016  *   this software without specific prior written permission.
00017  *
00018  * This file is part of the StructureColoring ROS package.
00019  *
00020  * The StructureColoring ROS package is free software:
00021  * you can redistribute it and/or modify it under the terms of the
00022  * GNU Lesser General Public License as published by the Free
00023  * Software Foundation, either version 3 of the License, or
00024  * (at your option) any later version.
00025  *
00026  * The StructureColoring ROS package is distributed in the hope that it will be useful,
00027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029  * GNU Lesser General Public License for more details.
00030  *
00031  * You should have received a copy of the GNU Lesser General Public License
00032  * along with The StructureColoring ROS package.
00033  * If not, see <http://www.gnu.org/licenses/>.
00034  */
00035 
00036 #ifndef GRIDMAP_H_
00037 #define GRIDMAP_H_
00038 
00039 #include "PositionedGrid2D.h"
00040 #include "NodeGridCell.h"
00041 #include "ConnectedComponent.h"
00042 #include <structureColoring/OcTree.h>
00043 #include <pcl/point_types.h>
00044 #include <assert.h>
00045 #include <queue>
00046 
00047 class GridMap: public PositionedGrid2D<NodeGridCell>{
00048 public:
00049         typedef NodeGridCell Cell;
00050         typedef std::vector<int> PointIndices;
00051         typedef OcTree::NodePointers NodePointers;
00052         typedef std::vector<NodePointers> NodePointersVec;
00053         typedef std::vector<int> NodeIndices;
00054         typedef std::vector<unsigned int> uints;
00055 
00056 //constructors
00057         GridMap() : mGridCCStartPos(std::make_pair(0, 0)){}
00058 
00059         GridMap(const Plane3D& plane, float xMin, float xMax, float yMin, float yMax, float cellSize)
00060                 : PositionedGrid2D<Cell>(plane, xMin, xMax, yMin, yMax, cellSize){}
00061 
00062         //get new x/y Min/Max from "getNewExtremes"-method!
00063         GridMap(const GridMap& gridMap, float xMin, float xMax, float yMin, float yMax,
00064                         unsigned int xOff, unsigned int xAdd, unsigned int yOff, unsigned int yAdd,
00065                         float cellSize);
00066 
00067 //getter
00068         bool isPopulated(Vec3 pos){
00069                 return (*this)(pos).populated();
00070         }
00071         const Indices& getStartPos() const {return mGridCCStartPos;}
00072 
00073         using Grid2D<NodeGridCell>::operator();
00074         using PositionedGrid2D<NodeGridCell>::operator();
00075 
00076 //setter
00077         void populate(const unsigned int& index, Vec3 pos){ (*this)(pos).populate(index); }
00078 
00079         template<typename PointCloudType>
00080         void populate(const PointIndices& pointIndices, const PointCloudType& pointCloud);
00081 
00082         void populate(const NodePointers& nodePointers);
00083 
00084         void blindPopulate(Vec3 pos){ (*this)(pos).blindPopulate(); }
00085 
00086         template<typename PointCloudType>
00087         void blindPopulate(const PointIndices& pointIndices, const PointCloudType& pointCloud);
00088 
00089         void clearIndices();
00090         void clear();
00091 
00092         void pushPopulatedUnvisitedNeighbors(std::queue<std::pair<unsigned int, unsigned int> >& neighbors, const unsigned int& width, const unsigned int& height) const;
00093 
00094         void print() const;
00095         void print(const std::pair<unsigned int, unsigned int>& coords) const;
00096 
00097 //calculations
00098         void startConnectedComponentAt(ConnectedComponent& ccc, const Indices& startPos);
00099         void checkNodesAgainstGridConnection(NodeIndices& outNodeIndices, const NodePointers& inNodeCandidates, float newCellSize,
00100                         unsigned int minNodesCount) const;
00101         void gatherNodesInCC(NodePointers& outputNodes, const ConnectedComponent& conComp, const NodePointers& octreeNodes) const;
00102         void gatherNodesInCC(NodeIndices& outputIndices, const ConnectedComponent& conComp) const;
00103         void getConnectedComponentsAndNotConnectedNodes(NodePointersVec& nodesInCC, const NodePointers& inputOctreeNodes, float cellSize,
00104                         unsigned int minPlaneNodes, unsigned int minCCNodes, NodePointers* notConnectedNodesOutput = NULL);
00105 
00106         void getNewExtremes(float& xMinOut, float& xMaxOut, float& yMinOut, float& yMaxOut,
00107                         unsigned int& xOff, unsigned int& xAdd, unsigned int& yOff, unsigned int& yAdd,
00108                         float xMinIn, float xMaxIn, float yMinIn, float yMaxIn, float stepsize) const;
00109 
00110         bool checkPointConnection(const Vec3& p, const int& connectionNeighbors) const;
00111 
00112         void calculateStartPos();
00113 
00114 protected:
00115 //members
00116         Indices mGridCCStartPos;
00117 };
00118 
00119 /*****************************************************************************/
00120 
00121 template<typename PointCloudType>
00122 void GridMap::populate(const PointIndices& pointIndices, const PointCloudType& pointCloud){
00123         for(PointIndices::const_iterator pi_it = pointIndices.begin(); pi_it != pointIndices.end(); ++pi_it){
00124                 populate((unsigned int)(*pi_it), pointCloud.points[*pi_it].getVector3fMap());
00125         }
00126 }
00127 
00128 /*****************************************************************************/
00129 
00130 inline void GridMap::populate(const NodePointers& nodePointers){
00131         for(unsigned int i = 0; i < nodePointers.size(); ++i){
00132                 populate(i, nodePointers[i]->value_.meanPos);
00133         }
00134 }
00135 
00136 /*****************************************************************************/
00137 
00138 template<typename PointCloudType>
00139 void GridMap::blindPopulate(const PointIndices& pointIndices, const PointCloudType& pointCloud){
00140         for(PointIndices::const_iterator pi_it = pointIndices.begin(); pi_it != pointIndices.end(); ++pi_it){
00141                 blindPopulate(pointCloud.points[*pi_it].getVector3fMap());
00142         }
00143 }
00144 
00145 /*****************************************************************************/
00146 
00147 inline void GridMap::clearIndices(){
00148         for (Cells::iterator cell_iter = mGrid.begin(); cell_iter != mGrid.end(); ++cell_iter){
00149                 cell_iter->clearIndices();
00150         }
00151 }
00152 
00153 /*****************************************************************************/
00154 
00155 inline void GridMap::clear(){
00156         for (Cells::iterator cell_iter = mGrid.begin(); cell_iter != mGrid.end(); ++cell_iter){
00157                         *cell_iter = Cell();
00158         }
00159 }
00160 
00161 /*****************************************************************************/
00162 
00163 inline bool GridMap::checkPointConnection(const Vec3& p, const int& connectionNeighbors) const {
00164         Cells cells;
00165         getNeighbors(cells, p, connectionNeighbors);
00166         for(Cells::const_iterator cit = cells.begin(); cit != cells.end(); ++cit){
00167                 if (cit->populated()){
00168 //                      std::cout << "connection found in grid, point/node ist connected!" << std::endl;
00169                         return true;
00170                 }
00171         }
00172 //      std::cout << "no connection found in grid" << std::endl;
00173         return false;
00174 }
00175 
00176 /*****************************************************************************/
00177 
00178 #endif /* GRIDMAP_H_ */


structure_coloring_fkie
Author(s): Bastian Gaspers
autogenerated on Sun Jan 5 2014 11:38:09