Geons3D.H
Go to the documentation of this file.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
00037
00038 #ifndef Geons3D_H_DEFINED
00039 #define Geons3D_H_DEFINED
00040
00041 #include "plugins/SceneUnderstanding/TwoHalfDSketch.H"
00042 #include "Image/Image.H"
00043 #include "Image/ImageSet.H"
00044 #include "Image/Pixels.H"
00045 #include "Image/Layout.H"
00046 #include "Transport/World3DInput.H"
00047 #include "plugins/SceneUnderstanding/LGN.H"
00048 #include "plugins/SceneUnderstanding/SMap.H"
00049 #include "Simulation/SimEvents.H"
00050 #include "Simulation/SimModule.H"
00051 #include "FeatureMatching/GeometricHashing.H"
00052 #include "FeatureMatching/GHough.H"
00053 #include "GUI/ViewPort3D.H"
00054 #include "GUI/SuperQuadric.H"
00055
00056 #include "Util/CpuTimer.H"
00057 #include "Util/JobServer.H"
00058 #include "Util/JobWithSemaphore.H"
00059 #include "Util/WorkThreadServer.H"
00060
00061 #include <fcntl.h>
00062 #include <vector>
00063 #include <string>
00064 #include <map>
00065
00066 class SimEventGeons3DPrior;
00067
00068 class Geons3D : public SimModule
00069 {
00070 public:
00071
00072 struct GeonState
00073 {
00074 Point3D<float> pos;
00075 Point3D<float> rot;
00076 PixRGB<byte> color;
00077 SuperQuadric superQuadric;
00078 double prob;
00079 };
00080
00081 Geons3D(OptionManager& mgr, const std::string& descrName = "Geons3D",
00082 const std::string& tagName = "Geons3D");
00083
00084
00085 ~Geons3D();
00086
00087 void evolve(SimEventQueue& q);
00088
00089 std::vector<GeonState> proposeGeons(Rectangle& attenLoc);
00090
00091 void calcGeonLikelihood(GeonState& geon);
00092 double calcGeonEdgeLikelihood(GeonState& geon, Image<float>& edges, Image<float>& surface);
00093 double calcGeonSurfaceLikelihood(GeonState& geon, Image<float>& edges, Image<float>& surface);
00094
00095
00096
00097 double getEdgeProb(Image<float>& mag, Image<float>& modelOri, Image<float>& modelMag);
00098
00099
00100 double getSurfaceProb(Image<float>& data, Image<float>& model);
00101
00102
00103
00104 void testLikelihood();
00105
00106
00107 Image<PixRGB<byte> > getGeonImage(GeonState& geon);
00108
00109 void drawGeon(const GeonState& geon);
00110 void renderScene(const GeonState& geon, std::vector<ViewPort3D::Line>& lines, Image<PixRGB<byte> >& frame);
00111
00112 Layout<PixRGB<byte> > getDebugImage(SimEventQueue& q);
00113
00114 protected:
00115
00116
00117 SIMCALLBACK_DECLARE(Geons3D, SimEventTwoHalfDSketchOutput);
00118
00119
00120 SIMCALLBACK_DECLARE(Geons3D, SimEventSaveOutput);
00121
00122
00123 SIMCALLBACK_DECLARE(Geons3D, SimEventUserInput);
00124
00125
00126 SIMCALLBACK_DECLARE(Geons3D, SimEventGeons3DPrior);
00127
00128
00129 OModelParam<bool> itsShowDebug;
00130
00131
00132 private:
00133 ViewPort3D *itsViewPort;
00134 ImageSet<float> itsLGNInput;
00135 Image<float> itsEdges;
00136 Image<float> itsLinesMag;
00137 Image<float> itsLinesOri;
00138 Image<float> itsEdgesDT;
00139 ImageSet<float> itsOriEdgesDT;
00140 Image<float> itsTableDepth;
00141 Image<byte> itsSMap;
00142 rutz::shared_ptr<World3DInput::ObjectsData> itsObjectsData;
00143 std::vector<TwoHalfDSketch::SurfaceState> itsSurfaces;
00144 std::vector<GeonState> itsGeonsState;
00145 std::vector<GeonState> itsProposals;
00146 Point3D<double> itsGlobalRotation;
00147 Point3D<double> itsGlobalPos;
00148 Image<PixRGB<byte> > itsCurrentFrame;
00149 GeometricHashing itsGHash;
00150 GHough itsGHough;
00151 GHough itsGHough2;
00152 bool itsLearn;
00153
00154 double itsTotalProb;
00155
00156 float itsTrainingThreshold;
00157
00158 rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00159
00160
00161 };
00162
00163
00164 class SimEventGeons3DOutput : public SimEvent
00165 {
00166 public:
00167 SimEventGeons3DOutput(SimModule* src,
00168 std::vector<Geons3D::GeonState>& geons, double prob) :
00169 SimEvent(src), itsGeons(geons), itsProb(prob)
00170 {}
00171
00172 virtual ~SimEventGeons3DOutput(){}
00173 std::vector<Geons3D::GeonState> getGeons() { return itsGeons; }
00174 double getProb() { return itsProb; }
00175
00176 private:
00177 const std::vector<Geons3D::GeonState>& itsGeons;
00178 double itsProb;
00179 };
00180
00181
00182 class SimEventGeons3DPrior : public SimEvent
00183 {
00184 public:
00185 SimEventGeons3DPrior(SimModule* src,
00186 std::vector<Geons3D::GeonState>& geons,
00187 Point3D<double>& pos, Point3D<double>& rotation) :
00188 SimEvent(src), itsGeons(geons),
00189 itsPos(pos), itsRotation(rotation)
00190 {}
00191
00192 virtual ~SimEventGeons3DPrior(){}
00193 std::vector<Geons3D::GeonState> getGeons() { return itsGeons; }
00194 Point3D<double> getRotation() { return itsRotation; }
00195 Point3D<double> getPos() { return itsPos; }
00196
00197 private:
00198 const std::vector<Geons3D::GeonState>& itsGeons;
00199 Point3D<double> itsPos;
00200 Point3D<double> itsRotation;
00201 };
00202
00203
00204
00205
00206
00207
00208
00209 #endif //