diff --git a/apps/sample/common.pri b/apps/sample/common.pri index dd976378..6cb16b15 100644 --- a/apps/sample/common.pri +++ b/apps/sample/common.pri @@ -1,11 +1,21 @@ -DEPENDPATH += . ../../.. -INCLUDEPATH += . ../../.. ../../../eigenlib +DEPENDPATH += \ + . \ + ../../.. + +INCLUDEPATH += \ + . \ + ../../.. \ + ../../../eigenlib + + CONFIG += console c++11 TEMPLATE = app + # Mac specific Config required to avoid to make application bundles CONFIG -= app_bundle QMAKE_CXXFLAGS += -std=c++11 + unix { CONFIG(release, debug|release) { DEFINES *= NDEBUG diff --git a/apps/sample/sample.pro b/apps/sample/sample.pro index b1c10547..38fcfcc5 100644 --- a/apps/sample/sample.pro +++ b/apps/sample/sample.pro @@ -1,48 +1,63 @@ +TEMPLATE = subdirs -TEMPLATE = subdirs -SUBDIRS = trimesh_allocate \ - trimesh_attribute \ - trimesh_attribute_saving \ - trimesh_ball_pivoting \ - trimesh_base \ - trimesh_closest \ - trimesh_clustering \ - trimesh_color \ - trimesh_copy \ - trimesh_create \ - trimesh_curvature \ - trimesh_cylinder_clipping \ - trimesh_disk_parametrization \ - trimesh_fitting \ - trimesh_geodesic \ - trimesh_harmonic \ - trimesh_hole \ - trimesh_implicit_smooth \ - trimesh_indexing \ - trimesh_inertia \ - trimesh_intersection_plane \ - trimesh_intersection_mesh \ - trimesh_isosurface \ - trimesh_join \ - trimesh_kdtree \ - trimesh_montecarlo_sampling \ - trimesh_normal \ - trimesh_optional \ - trimesh_pointmatching \ - trimesh_pointcloud_sampling \ - trimesh_ray \ - trimesh_refine \ - trimesh_remeshing \ - trimesh_sampling \ - trimesh_select \ - trimesh_smooth \ - trimesh_split_vertex \ - trimesh_texture \ - trimesh_texture_clean \ - trimesh_topology \ - trimesh_topological_cut \ - trimesh_voronoi \ - trimesh_voronoiatlas \ - trimesh_voronoiclustering \ - trimesh_voronoisampling \ - +SUBDIRS = \ + aabb_binary_tree \ + colorspace \ + #edgemesh_sampling \ + polygonmesh_base \ + polygonmesh_dual \ + polygonmesh_optimize \ + polygonmesh_polychord_collapse \ + #polygonmesh_quadsimpl \ + polygonmesh_smooth \ + polygonmesh_zonohedra \ + space_index_2d \ + #space_minimal \ + space_packer \ + space_rasterized_packer \ + trimesh_align_pair \ + trimesh_allocate \ + trimesh_attribute \ + trimesh_attribute_saving \ + trimesh_ball_pivoting \ + trimesh_base \ + trimesh_closest \ + trimesh_clustering \ + trimesh_color \ + trimesh_copy \ + trimesh_create \ + trimesh_curvature \ + trimesh_cylinder_clipping \ + trimesh_disk_parametrization \ + trimesh_fitting \ + trimesh_geodesic \ + trimesh_harmonic \ + trimesh_hole \ + trimesh_implicit_smooth \ + trimesh_indexing \ + trimesh_inertia \ + trimesh_intersection_plane \ + trimesh_intersection_mesh \ + trimesh_isosurface \ + trimesh_join \ + trimesh_kdtree \ + trimesh_montecarlo_sampling \ + trimesh_normal \ + trimesh_optional \ + trimesh_pointmatching \ + trimesh_pointcloud_sampling \ + trimesh_ray \ + trimesh_refine \ + trimesh_remeshing \ + trimesh_sampling \ + trimesh_select \ + trimesh_smooth \ + trimesh_split_vertex \ + trimesh_texture \ + trimesh_texture_clean \ + trimesh_topology \ + trimesh_topological_cut \ + trimesh_voronoi \ + trimesh_voronoiatlas \ + trimesh_voronoiclustering \ + trimesh_voronoisampling \ diff --git a/apps/sample/trimesh_align_pair/my_mesh.h b/apps/sample/trimesh_align_pair/my_mesh.h new file mode 100644 index 00000000..14a604ce --- /dev/null +++ b/apps/sample/trimesh_align_pair/my_mesh.h @@ -0,0 +1,151 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +#ifndef MY_MESH_H +#define MY_MESH_H + +#include + +typedef double Scalarm; +typedef vcg::Point2 Point2m; +typedef vcg::Point3 Point3m; +typedef vcg::Point4 Point4m; +typedef vcg::Plane3 Plane3m; +typedef vcg::Segment2 Segment2m; +typedef vcg::Segment3 Segment3m; +typedef vcg::Box3 Box3m; +typedef vcg::Matrix44 Matrix44m; +typedef vcg::Matrix33 Matrix33m; +typedef vcg::Shot Shotm; +typedef vcg::Similarity Similaritym; + +namespace vcg +{ + namespace vertex + { + template class Coord3m: public Coord, T> { + public: static void Name(std::vector & name){name.push_back(std::string("Coord3m"));T::Name(name);} + }; + + template class Normal3m: public Normal, T> { + public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} + }; + + template class CurvatureDirmOcf: public CurvatureDirOcf, T> { + public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);} + }; + + template class RadiusmOcf: public RadiusOcf { + public: static void Name(std::vector & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);} + }; + + }//end namespace vertex + namespace face + { + template class Normal3m: public NormalAbs, T> { + public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} + }; + + template class CurvatureDirmOcf: public CurvatureDirOcf, T> { + public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirdOcf"));T::Name(name);} + }; + + }//end namespace face +}//end namespace vcg + +// Forward declarations needed for creating the used types +class CVertexO; +class CEdgeO; +class CFaceO; + +// Declaration of the semantic of the used types +class CUsedTypesO: public vcg::UsedTypes < vcg::Use::AsVertexType, + vcg::Use::AsEdgeType, + vcg::Use::AsFaceType >{}; + + +// The Main Vertex Class +// Most of the attributes are optional and must be enabled before use. +// Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch. + +class CVertexO : public vcg::Vertex< CUsedTypesO, + vcg::vertex::InfoOcf, /* 4b */ + vcg::vertex::Coord3m, /* 12b */ + vcg::vertex::BitFlags, /* 4b */ + vcg::vertex::Normal3m, /* 12b */ + vcg::vertex::Qualityf, /* 4b */ + vcg::vertex::Color4b, /* 4b */ + vcg::vertex::VFAdjOcf, /* 0b */ + vcg::vertex::MarkOcf, /* 0b */ + vcg::vertex::TexCoordfOcf, /* 0b */ + vcg::vertex::CurvaturefOcf, /* 0b */ + vcg::vertex::CurvatureDirmOcf, /* 0b */ + vcg::vertex::RadiusmOcf /* 0b */ +>{ +}; + + +// The Main Edge Class +class CEdgeO : public vcg::Edge{ +}; + +// Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch. +class CFaceO : public vcg::Face< CUsedTypesO, + vcg::face::InfoOcf, /* 4b */ + vcg::face::VertexRef, /*12b */ + vcg::face::BitFlags, /* 4b */ + vcg::face::Normal3m, /*12b */ + vcg::face::QualityfOcf, /* 0b */ + vcg::face::MarkOcf, /* 0b */ + vcg::face::Color4bOcf, /* 0b */ + vcg::face::FFAdjOcf, /* 0b */ + vcg::face::VFAdjOcf, /* 0b */ + vcg::face::CurvatureDirmOcf, /* 0b */ + vcg::face::WedgeTexCoordfOcf /* 0b */ +> {}; + + +class MyMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > +{ +public : + int sfn; //The number of selected faces. + int svn; //The number of selected vertices. + + int pvn; //the number of the polygonal vertices + int pfn; //the number of the polygonal faces + + Matrix44m Tr; // Usually it is the identity. It is applied in rendering and filters can or cannot use it. (most of the filter will ignore this) + + const Box3m &trBB() + { + static Box3m bb; + bb.SetNull(); + bb.Add(Tr,bbox); + return bb; + } +}; + +#endif // MY_MESH_H diff --git a/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp b/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp new file mode 100644 index 00000000..c9876c76 --- /dev/null +++ b/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2016 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/*! \file trimesh_align_pair.cpp +\ingroup code_sample + +\brief the minimal example of using the lib + +This file contain a minimal example of the library + +*/ + +#include + +#include + +#include +#include + +#include "my_mesh.h" + +using namespace vcg; +using namespace std; + +std::vector* vcg::PointMatchingScale::fix; +std::vector* vcg::PointMatchingScale::mov; +vcg::Box3d vcg::PointMatchingScale::b; + +int main(int argc,char ** argv) +{ + if(argc<3) { + printf("Usage: trimesh_smooth \n"); + return 0; + } + + MyMesh m1, m2; + + //open first mesh + int err = tri::io::Importer::Open(m1,argv[1]); + if(err) { // all the importers return 0 in case of success + printf("Error in reading %s: '%s'\n", argv[1], tri::io::Importer::ErrorMsg(err)); + exit(-1); + } + + //open second mesh + err = tri::io::Importer::Open(m1,argv[2]); + if(err) { // all the importers return 0 in case of success + printf("Error in reading %s: '%s'\n", argv[2], tri::io::Importer::ErrorMsg(err)); + exit(-1); + } + + ////PARAMS + /////TODO + vcg::Matrix44d MovM; + vcg::AlignPair::Result result; + vcg::AlignPair::Param ap; + + //MovM + vcg::Matrix44d FixM=vcg::Matrix44d::Construct(m1.Tr); + MovM=vcg::Matrix44d::Construct(m2.Tr); + MovM = Inverse(FixM) * MovM; + + vcg::AlignPair::A2Mesh fix; + vcg::AlignPair aa; + + // 1) Convert fixed mesh and put it into the grid. + m1.face.EnableMark(); + aa.convertMesh(m1,fix); + + vcg::AlignPair::A2Grid UG; + vcg::AlignPair::A2GridVert VG; + + if(m1.fn==0 || ap.UseVertexOnly) { + fix.initVert(vcg::Matrix44d::Identity()); + vcg::AlignPair::InitFixVert(&fix,ap,VG); + } + else { + fix.init(vcg::Matrix44d::Identity()); + vcg::AlignPair::initFix(&fix, ap, UG); + } + + + // 2) Convert the second mesh and sample a points on it. + //MM(movId)->updateDataMask(MeshModel::MM_FACEMARK); + m2.face.EnableMark(); + std::vector tmpmv; + aa.convertVertex(m2.vert,tmpmv); + aa.sampleMovVert(tmpmv, ap.SampleNum, ap.SampleMode); + + aa.mov=&tmpmv; + aa.fix=&fix; + aa.ap = ap; + + vcg::Matrix44d In=MovM; + // Perform the ICP algorithm + aa.align(In,UG,VG,result); + + m2.Tr = result.Tr; + tri::UpdatePosition::Matrix(m2, m2.Tr, true); + tri::UpdateBounding::Box(m2); + m2.Tr.SetIdentity(); + + //result.FixName=fixId; + //result.MovName=movId; + //result.as.Dump(stdout); + + //saves the rotated mesh + tri::io::ExporterPLY::Save(m2 ,"out.ply"); + + return 0; +} + diff --git a/apps/sample/trimesh_align_pair/trimesh_align_pair.pro b/apps/sample/trimesh_align_pair/trimesh_align_pair.pro new file mode 100644 index 00000000..81c0969c --- /dev/null +++ b/apps/sample/trimesh_align_pair/trimesh_align_pair.pro @@ -0,0 +1,10 @@ +include(../common.pri) + +TARGET = trimesh_align_pair + +HEADERS += \ + my_mesh.h + +SOURCES += \ + trimesh_align_pair.cpp \ + ../../../wrap/ply/plylib.cpp diff --git a/vcg/math/matrix44.h b/vcg/math/matrix44.h index 2dca8aca..7ca46188 100644 --- a/vcg/math/matrix44.h +++ b/vcg/math/matrix44.h @@ -192,7 +192,8 @@ public: template static inline Matrix44 Construct( const Matrix44 & b ) { - Matrix44 tmp; tmp.FromMatrix(b); + Matrix44 tmp; + tmp.FromMatrix(b); return tmp; }