00001 #ifndef MODELER_MODELER_HPP
00002 #define MODELER_MODELER_HPP
00003
00004 #include "bundler/viewsManager2.hpp"
00005 #include "fdetect/DetectionResult.hpp"
00006 #include "fdetect/Detector.hpp"
00007 #include "fdetect/FloatDescriptor.hpp"
00008 #include "fdetect/SURFDetector.hpp"
00009 #include "geom/t3d.hpp"
00010 #include "gfm/EngineTracking.hpp"
00011 #include "gfm/GroupsMatcher.hpp"
00012 #include "gfm/MatchingResult.hpp"
00013 #include "image/Image.hpp"
00014 #include "jmath/jblas.hpp"
00015 #include "modeler/mesher.hpp"
00016 #include "modeler/bpa.hpp"
00017 #include "modeler/vcgDeclarations.hpp"
00018 #include <boost/bimap.hpp>
00019
00020 namespace jafar {
00021 namespace modeler {
00022
00037 class Modeler {
00038 protected:
00039 typedef fdetect_v2::InterestFeature<fdetect_v2::FloatDescriptor> Feature;
00040 typedef std::vector< Feature* >::const_iterator features_iterator;
00041 typedef fdetect_v2::DetectionResult<Feature> DR;
00042 typedef gfm_v2::MatchingResult<Feature> MR;
00044 fdetect_v2::Detector<Feature> *detector;
00046 gfm_v2::Matcher<Feature> *matcher;
00048 gfm_v2::EngineTracking<Feature> *tracker;
00050 modeler::Mesher* mesher;
00052 std::map<unsigned int, bundler::ViewsManager2*> bundlers;
00053 typedef boost::bimap<Feature*, unsigned int> bm_type;
00054 bm_type features_indices;
00055 typedef bm_type::left_map::const_iterator features_citerator;
00056 typedef bm_type::right_map::const_iterator indices_citerator;
00058 std::map<unsigned int, fdetect_v2::DetectionResult<Feature> > sequence_detect;
00059 unsigned int index;
00061 struct vertex
00062 {
00064 JfrMesh::CoordType p;
00066 unsigned int pos;
00068 std::vector<unsigned int> origine;
00069 vertex() {};
00070 vertex(const JfrMesh::CoordType& _p,
00071 unsigned int _pos,
00072 const std::vector<unsigned int>& _origine) :
00073 p(_p), pos(_pos), origine(_origine) {};
00074 void setP(const jblas::vec3& c) { p[0] = c[0]; p[1] = c[1]; p[2] = c[2]; }
00075 };
00077 std::map<unsigned int, vertex> vertices;
00079 struct shot{
00081 camera::CameraType type;
00083 jblas::vec intra;
00085 geom::T3D* extra;
00086 shot() {};
00087 shot(camera::CameraType _type,const jblas::vec& _intra, geom::T3D* _extra) :
00088 type(_type), intra(_intra), extra(_extra) {};
00089 };
00091 std::map<unsigned int, shot> shots;
00093 unsigned int global;
00095 unsigned int counter;
00097 std::string calibration;
00099 bool one_camera;
00101 std::pair<camera::CameraType, jblas::vec> camera;
00103 MR result;
00104 public:
00105 Modeler() :
00106 detector(new fdetect_v2::SURFDetector()),
00107 matcher(new gfm_v2::GroupsMatcher<Feature>( new gfm::WindowMatchFocus(100000, 100000), 10, 10, 2, 20.0, 0.6, 0.6, 0.1, 0.2, 10000, 10, 0.4, 0.0)),
00108 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00109 mesher(new modeler::BPA()), index(0), global(0), counter(0), one_camera(false) {}
00110
00115 Modeler(camera::CameraType type, const jblas::vec& intrinsics) :
00116 detector(new fdetect_v2::SURFDetector()),
00117 matcher(new gfm_v2::GroupsMatcher<Feature>( new gfm::WindowMatchFocus(100000, 100000), 10, 10, 2, 20.0, 0.6, 0.6, 0.1, 0.2, 10000, 10, 0.4, 0.0)),
00118 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00119 mesher(new modeler::BPA()), index(0), global(0), counter(0), one_camera(true)
00120 {
00121 camera = make_pair(type, intrinsics);
00122 }
00123
00125 Modeler(camera::CameraType type, const jblas::vec& intrinsics,
00126 fdetect_v2::Detector<Feature> *_detector,
00127 gfm_v2::Matcher<Feature> *_matcher) :
00128 detector(_detector), matcher(_matcher),
00129 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00130 mesher(new modeler::BPA()), index(0), global(0), counter(0), one_camera(true)
00131 {
00132 camera = make_pair(type, intrinsics);
00133 }
00134
00136 Modeler(fdetect_v2::Detector<Feature> *_detector,
00137 gfm_v2::Matcher<Feature> *_matcher) :
00138 detector(_detector), matcher(_matcher),
00139 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00140 mesher(new modeler::BPA()), index(0), global(0), counter(0), one_camera(false) {}
00141 protected:
00143 Modeler(JfrMesh& _mesh) :
00144 detector(new fdetect_v2::SURFDetector()),
00145 matcher(new gfm_v2::GroupsMatcher<Feature>( new gfm::WindowMatchFocus(100000, 100000), 10, 10, 2, 20.0, 0.6, 0.6, 0.1, 0.2, 10000, 10, 0.4, 0.0)),
00146 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00147 mesher(new modeler::BPA(_mesh)), index(0), global(0), counter(0), one_camera(false) { }
00148
00154 Modeler(JfrMesh& _mesh, camera::CameraType type, const jblas::vec& intrinsics) :
00155 detector(new fdetect_v2::SURFDetector()),
00156 matcher(new gfm_v2::GroupsMatcher<Feature>( new gfm::WindowMatchFocus(100000, 100000), 10, 10, 2, 20.0, 0.6, 0.6, 0.1, 0.2, 10000, 10, 0.4, 0.0)),
00157 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00158 mesher(new modeler::BPA(_mesh)), index(0), global(0), counter(0), one_camera(true)
00159 {
00160 camera = make_pair(type, intrinsics);
00161 }
00162
00171 Modeler(JfrMesh& _mesh, camera::CameraType type, const jblas::vec& intrinsics,
00172 fdetect_v2::Detector<Feature> *_detector,
00173 gfm_v2::Matcher<Feature> *_matcher) :
00174 detector(_detector), matcher(_matcher),
00175 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00176 mesher(new modeler::BPA(_mesh)), index(0), global(0), counter(0), one_camera(true)
00177 {
00178 camera = make_pair(type, intrinsics);
00179 }
00180
00187 Modeler(JfrMesh& _mesh,
00188 fdetect_v2::Detector<Feature> *_detector,
00189 gfm_v2::Matcher<Feature> *_matcher) :
00190 detector(_detector), matcher(_matcher),
00191 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00192 mesher(new modeler::BPA(_mesh)), index(0), global(0), counter(0), one_camera(false) {}
00193
00199 Modeler(const std::string& ply_mesh_file,
00200 camera::CameraType type, const jblas::vec& intrinsics) :
00201 detector(new fdetect_v2::SURFDetector()),
00202 matcher(new gfm_v2::GroupsMatcher<Feature>( new gfm::WindowMatchFocus(100000, 100000), 10, 10, 2, 20.0, 0.6, 0.6, 0.1, 0.2, 10000, 10, 0.4, 0.0)),
00203 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00204 mesher(new modeler::BPA(ply_mesh_file)), index(0), global(0), counter(0), one_camera(true)
00205 {
00206 camera = make_pair(type, intrinsics);
00207 }
00208
00217 Modeler(const std::string& ply_mesh_file,
00218 camera::CameraType type, const jblas::vec& intrinsics,
00219 fdetect_v2::Detector<Feature> *_detector,
00220 gfm_v2::Matcher<Feature> *_matcher) :
00221 detector(_detector), matcher(_matcher),
00222 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00223 mesher(new modeler::BPA(ply_mesh_file)), index(0), global(0), counter(0), one_camera(true)
00224 {
00225 camera = make_pair(type, intrinsics);
00226 }
00227
00234 Modeler(const std::string& ply_mesh_file,
00235 fdetect_v2::Detector<Feature> *_detector,
00236 gfm_v2::Matcher<Feature> *_matcher) :
00237 detector(_detector), matcher(_matcher),
00238 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00239 mesher(new modeler::BPA(ply_mesh_file)),
00240 index(0), global(0), counter(0), one_camera(false) {}
00241
00245 Modeler(const std::string& ply_mesh_file) :
00246 detector(new fdetect_v2::SURFDetector()),
00247 matcher(new gfm_v2::GroupsMatcher<Feature>( new gfm::WindowMatchFocus(100000, 100000), 10, 10, 2, 20.0, 0.6, 0.6, 0.1, 0.2, 10000, 10, 0.4, 0.0)),
00248 tracker(new gfm_v2::EngineTracking<Feature>(detector, matcher)),
00249 mesher(new modeler::BPA(ply_mesh_file)),
00250 index(0), global(0), counter(0), one_camera(false) { }
00251
00252 public:
00259 int add(const image::Image &img, geom::T3D* pose);
00260
00267 int add(camera::CameraType type, const jblas::vec& intrinsics, geom::T3D* pose,
00268 const image::Image &img);
00269
00271 void build();
00273 void save(const std::string& file_name, bool is_binary = false)
00274 {
00275 mesher->save(file_name, is_binary);
00276 }
00277
00278 };
00279 }
00280 }
00281
00282 #endif