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
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
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
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
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
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
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
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
00169 return true;
00170 }
00171 }
00172
00173 return false;
00174 }
00175
00176
00177
00178 #endif