Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
vcgDeclarations.hpp
00001 
00002 
00003 /* $Id$ */
00004 
00005 #ifndef VCG_DECLARATIONS_HPP
00006 #define VCG_DECLARATIONS_HPP
00007 
00008 #include <vcg/simplex/vertex/base.h>
00009 #include <vcg/simplex/vertex/component_ocf.h>
00010 #include <vcg/simplex/edge/base.h>
00011 #include <vcg/simplex/face/base.h>
00012 #include <vcg/simplex/face/component_ocf.h>
00013 #include <vcg/complex/used_types.h>
00014 #include <vcg/complex/trimesh/base.h>
00015 #include <vcg/complex/trimesh/allocate.h>
00016 #include <vcg/complex/trimesh/append.h>
00017 #include <vcg/math/shot.h>
00018 #include <vcg/space/point3.h>
00019 #include <vcg/math/matrix44.h>
00020 
00021 #include "geom/t3d.hpp"
00022 #include "fdetect/InterestFeature.hpp"
00023 #include "fdetect/RealDescriptor.hpp"
00024 #include "jmath/jblas.hpp"
00025 #include "modeler/modelerException.hpp"
00026 
00027 namespace jafar {
00028   namespace modeler {
00029     // Forward declarations needed for creating the used types
00030     class JfrVertex;
00031     class JfrEdge;
00032     class JfrFace;
00033 
00034     // Declaration of the semantic of the used types
00035     class JfrUsedTypes: public vcg::UsedTypes < vcg::Use<JfrVertex>::AsVertexType,
00036             vcg::Use<JfrEdge  >::AsEdgeType,
00037             vcg::Use<JfrFace  >::AsFaceType >{};
00038 
00039 
00040     // The Main Vertex Class
00041     // Most of the attributes are optional and must be enabled before use.
00042     // Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch.
00043     
00044     class JfrVertex  : public vcg::Vertex< JfrUsedTypes,
00045              vcg::vertex::InfoOcf,           /*  4b */
00046              vcg::vertex::Coord3f,           /* 12b */
00047              vcg::vertex::BitFlags,          /*  4b */
00048              vcg::vertex::Normal3f,          /* 12b */
00049              vcg::vertex::Qualityf,          /*  4b */
00050              vcg::vertex::Color4b,           /*  4b */
00051              vcg::vertex::VFAdjOcf,          /*  0b */
00052              vcg::vertex::MarkOcf,           /*  0b */
00053              vcg::vertex::TexCoordfOcf,      /*  0b */
00054              vcg::vertex::CurvaturefOcf,     /*  0b */
00055              vcg::vertex::CurvatureDirfOcf,  /*  0b */
00056              vcg::vertex::RadiusfOcf         /*  0b */
00057              >{
00058     };
00059 
00060 
00061     // The Main Edge Class
00062     // Currently it does not contains anything.
00063     class JfrEdge : public vcg::Edge<JfrUsedTypes, vcg::edge::EVAdj> {
00064     public:
00065       inline JfrEdge(){};
00066       inline JfrEdge( JfrVertex * v0, JfrVertex * v1){ V(0)= v0 ; V(1)= v1;};
00067       static inline JfrEdge OrderedEdge(JfrVertex* v0,JfrVertex* v1){
00068   if(v0<v1) return JfrEdge(v0,v1);
00069   else return JfrEdge(v1,v0);
00070       }
00071     };
00072     
00073     // Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch.
00074     class JfrFace    : public vcg::Face<  JfrUsedTypes,
00075             vcg::face::InfoOcf,              /* 4b */
00076             vcg::face::VertexRef,            /*12b */
00077             vcg::face::BitFlags,             /* 4b */
00078             vcg::face::Normal3f,             /*12b */
00079             vcg::face::QualityfOcf,          /* 0b */
00080             vcg::face::MarkOcf,              /* 0b */
00081             vcg::face::Color4bOcf,           /* 0b */
00082             vcg::face::FFAdjOcf,             /* 0b */
00083             vcg::face::VFAdjOcf,             /* 0b */
00084             vcg::face::WedgeTexCoordfOcf     /* 0b */
00085             > {};
00086 
00087     class JfrMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<JfrVertex>, 
00088                 vcg::face::vector_ocf<JfrFace> > 
00089     { 
00090     public:
00092       typedef vcg::tri::TriMesh< vcg::vertex::vector_ocf<JfrVertex>, vcg::face::vector_ocf<JfrFace> >::ScalarType     ScalarType;
00093       typedef vcg::Shot<ScalarType> Shot;
00094 
00095       //features stuff
00097       unsigned int ftn;
00099       std::vector<fdetect_v2::InterestFeature<fdetect_v2::FloatDescriptor>* > features;
00101       JfrMesh::PerVertexAttributeHandle< std::vector<unsigned int> > origines_setter, origines_getter;
00103       JfrMesh::PerVertexAttributeHandle< unsigned int>  id_setter, id_getter;
00104       //shots stuff
00106       unsigned int sn;
00108       std::map<unsigned int, vcg::Shot<ScalarType> > shots;
00109       inline JfrMesh() : 
00110   vcg::tri::TriMesh < vcg::vertex::vector_ocf<JfrVertex>, vcg::face::vector_ocf<JfrFace> >(),
00111   ftn(0), sn(0)
00112       {
00113   using namespace fdetect_v2;
00114   origines_setter = vcg::tri::Allocator<JfrMesh>::AddPerVertexAttribute<std::vector<unsigned int> >  (*this,std::string("Origines")); 
00115   id_setter = vcg::tri::Allocator<JfrMesh>::AddPerVertexAttribute< unsigned int >  (*this,std::string("Id"));
00116   origines_getter = vcg::tri::Allocator<JfrMesh>::GetPerVertexAttribute<std::vector<unsigned int> >  (*this,std::string("Origines")); 
00117   id_getter = vcg::tri::Allocator<JfrMesh>::GetPerVertexAttribute< unsigned int >  (*this,std::string("Id"));
00118 
00119       };
00120       inline JfrMesh(JfrMesh& mesh) :
00121   ftn(mesh.ftn), sn(mesh.sn)
00122       {
00123   vcg::tri::Append<JfrMesh, JfrMesh>::Mesh(*this, mesh);
00124 
00125   using namespace fdetect_v2;
00126   origines_setter = vcg::tri::Allocator<JfrMesh>::AddPerVertexAttribute<std::vector<unsigned int> >  (*this,std::string("Origines")); 
00127   id_setter = vcg::tri::Allocator<JfrMesh>::AddPerVertexAttribute< unsigned int >  (*this,std::string("Id"));
00128   origines_getter = vcg::tri::Allocator<JfrMesh>::GetPerVertexAttribute<std::vector<unsigned int> >  (*this,std::string("Origines")); 
00129   id_getter = vcg::tri::Allocator<JfrMesh>::GetPerVertexAttribute< unsigned int >  (*this,std::string("Id"));
00130       };
00131     
00132       inline void addFeature(fdetect_v2::InterestFeature<fdetect_v2::FloatDescriptor>* ft)
00133       {
00134   features.push_back(ft);
00135   ++ftn;
00136       }
00137     
00138       inline void addShot(unsigned int id, 
00139         const geom::T3D* frame,
00140         int width, int height, 
00141         double u0, double v0, 
00142         double alphaU, double alphaV,
00143         double focal = 1.,
00144         double k1 = 0., double k2 = 0., double k3 = 0., double k4 = 0.)
00145       {
00146   std::map<unsigned int, vcg::Shot<ScalarType> >::iterator shit = shots.find(id);
00147   JFR_PRED_ERROR(shit == shots.end(),
00148            ModelerException,
00149            ModelerException::EXISTING_ID,
00150            "a shot with id "<< id << " was already defined")
00151     jblas::vec3 t = frame->getT();
00152   jblas::mat33 r = frame->getR();
00153   // extrinsic
00154   shots[id].Extrinsics.SetIdentity();
00155   // view point
00156   shots[id].Extrinsics.SetTra(vcg::Point3<ScalarType>((ScalarType)t[0],
00157                   (ScalarType)t[1],
00158                   (ScalarType)t[2]));
00159       
00160   // axis (i.e. rotation).
00161   vcg::Matrix44<ScalarType> rm;
00162   rm.SetIdentity();
00163   rm[0][0] = (ScalarType)r(0,0);
00164   rm[0][1] = (ScalarType)r(0,1);
00165   rm[0][2] = (ScalarType)r(0,2);
00166       
00167   rm[1][0] = (ScalarType)r(1,0);
00168   rm[1][1] = (ScalarType)r(1,1);
00169   rm[1][2] = (ScalarType)r(1,2);
00170       
00171   rm[2][0] = (ScalarType)r(2,0);
00172   rm[2][1] = (ScalarType)r(2,1);
00173   rm[2][2] = (ScalarType)r(2,2);
00174       
00175   shots[sn].Extrinsics.SetRot(rm);
00176 
00177   shots[id].Intrinsics.FocalMm        = (ScalarType)focal;
00178   shots[id].Intrinsics.PixelSizeMm[0] = (ScalarType)alphaU;
00179   shots[id].Intrinsics.PixelSizeMm[1] = (ScalarType)alphaV;
00180   shots[id].Intrinsics.CenterPx[0]    = (ScalarType)u0;
00181   shots[id].Intrinsics.CenterPx[1]    = (ScalarType)v0;
00182   shots[id].Intrinsics.ViewportPx[0]  = (ScalarType)width;
00183   shots[id].Intrinsics.ViewportPx[1]  = (ScalarType)height;
00184   shots[id].Intrinsics.k[0]           = (ScalarType)k1;
00185   shots[id].Intrinsics.k[1]           = (ScalarType)k2;
00186   shots[id].Intrinsics.k[2]           = (ScalarType)k3;
00187   shots[id].Intrinsics.k[3]           = (ScalarType)k4;
00188   ++sn;
00189       }
00190     };
00191 
00192   }
00193 }
00194 
00195 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:25 for Jafar by doxygen 1.7.6.1
LAAS-CNRS