00001 #ifndef GRID_3D_HPP
00002 #define GRID_3D_HPP
00003
00004 #include "kernel/jafarException.hpp"
00005 #include "jmath/jblas.hpp"
00006 #include "model3d/point3D.hpp"
00007 #include "model3d/point3DVar.hpp"
00008 #include "model3d/Image3D.hpp"
00009 #include <iostream>
00010 #include <vector>
00011 #include <cfloat>
00012 #include <stdlib.h>
00013 #include "model3d/grid3DCell.hpp"
00014 #include "model3d/ransacPlane.hpp"
00015
00016 namespace jafar {
00018 namespace model3d {
00019
00027 class Grid3D
00028 {
00029 public:
00030 Grid3D();
00031 ~Grid3D();
00032
00034 void build(Image3D& im3d, double dbStep);
00035
00040 void initialize(int nX, int nY, int nZ,
00041 double minX_, double minY_, double minZ_,
00042 double stepX_, double stepY_, double stepZ_);
00043
00045 void fillGrid(::std::vector<Point3D>* ppoints);
00046
00047 #ifdef HAVE_OPENGL
00048
00051 void display(int nOnlyRectangle=0);
00052 #endif // HAVE_OPENGL
00053
00054 #ifdef HAVE_OPENGL
00055 void displayCloud3D();
00056 void displayGrayCloud3D();
00057 void TestOpenGL();
00058 #endif // HAVE_OPENGL
00059
00060 void colorizeImage3D(char* fileName, char* outputIndeces);
00061
00062
00063 std::vector<float> m_vColor;
00064 unsigned char* pImage_BRUT;
00065 int m_nWidth_BRUT, m_nHeight_BRUT;
00066 void loadBrutImage(char* fileName);
00067
00068 void extractFloor(double delta, bool removeInnerPoints);
00069 Plane3D m_plane3dFloor;
00070 #ifdef HAVE_OPENGL
00071 void displayFloorPlane();
00072 #endif // HAVE_OPENGL
00073
00074
00075 int*** m_pAccumulator;
00076 int m_nRho, m_nPhi, m_nTheta, m_nMaxVote;
00077 void prepareHoughAccumulator(float fRhoMax,
00078 float rhoStep,
00079 float angleStep,
00080 bool withSave = false,
00081 char * fileName = NULL);
00082
00083 #ifdef HAVE_OPENGL
00084
00085 void displayHoughAccumulator();
00086 #endif // HAVE_OPENGL
00087
00088 void extractBigerHoughPlane3D(int maxRho=25,
00089 float rhoStep=0.02,
00090 float angleStep=5);
00091
00092 Plane3D m_BiggerPlane3D;
00093 #ifdef HAVE_OPENGL
00094 void displayWithBiggerPlane();
00095 #endif // HAVE_OPENGL
00096
00097
00098
00099 void extractHoughPlanes3D(int maxRho=25,
00100 float rhoStep=0.02,
00101 float angleStep=5,
00102 float fThresholdOfMaxVote=0.5,
00103 float fMinDistanceOfTowPlane=0.10,
00104 float fMinCosDihedralAngle=0.975,
00105 int nMaxPlaneNumber=30);
00106
00107 void extractProgProbHoughPlanes3D(int maxRho=25,
00108 float rhoStep=0.02,
00109 float angleStep=5,
00110 float fThresholdOfMaxVote=0.5,
00111 float fMinDistanceOfTowPlane=0.10,
00112 float fMinCosDihedralAngle=0.025,
00113 int nMaxPlaneNumber=30,
00114 int minPointNumberThreshold=50,
00115 int minFinalVoteThreshold=100,
00116 char* planeFileName="plane.txt");
00117
00118
00119 void savePlanesCornersToFile(char* fileName);
00120 void savePlanesEquations(std::vector<Plane3D>& vPlane3D,
00121 int nMaxPlaneNumber,
00122 char* fileName);
00123
00124
00125 std::vector<Point3D> vP1;
00126 std::vector<Point3D> vP2;
00127 std::vector<Point3D> vP3;
00128 std::vector<Point3D> vP4;
00129 #ifdef HAVE_OPENGL
00130 void displayPlanes();
00131 #endif // HAVE_OPENGL
00132
00138 inline Grid3DCell* operator()(int i, int j, int k)
00139 {
00140 return &m_vCells[(i*m_nNY*m_nNZ)+(j*m_nNZ)+k];
00141 }
00142
00143
00147 void savePlanesToFile(char* fileName);
00148
00149
00150
00151 void reducePlanesNumber(double distThreshold,
00152 double cosDihedralThreshold,
00153 int nPower);
00154
00159 void extractPlaneInCellsMLSE();
00160
00165 void extractPlaneInCellsEKFI();
00166
00173 void bestPlaneMinLeastSquares(std::vector<int>& pointIndex,
00174 Plane3D& plane3D);
00175
00176
00180 void bestPlaneEKFI(std::vector<int>& pointIndex,
00181 Plane3D& plane3D);
00182
00186 void planeEKFI(std::vector<int>& pointIndex,
00187 double abcE[5],
00188 int nPlaneType);
00189
00209 void planeMinLeastSquares(std::vector<int>& pointIndex,
00210 double abcE[5],
00211 int type);
00212
00216 void info();
00217
00219 RansacPlane* getRansac()
00220 { return &m_RansacPlane;}
00221
00222
00223
00225 ::std::vector<Grid3DCell> m_vCells;
00226
00228 ::std::vector<Point3D>* m_pPoints;
00229
00231 RansacPlane m_RansacPlane;
00232
00234 int m_nNX;
00235 int m_nNY;
00236 int m_nNZ;
00237
00239 double m_dbStepX;
00240 double m_dbStepY;
00241 double m_dbStepZ;
00242
00246 double m_dbMinX;
00247 double m_dbMinY;
00248 double m_dbMinZ;
00249 };
00250
00251
00252 }
00253 }
00254
00255 #endif // GRID_3D_HPP