2017-03-14 07:49:15 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2011-04-01 19:07:57 +02:00
|
|
|
#include<vcg/complex/complex.h>
|
2005-09-21 12:29:33 +02:00
|
|
|
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/algorithms/refine.h>
|
|
|
|
#include <vcg/complex/algorithms/refine_loop.h>
|
2010-04-27 16:59:12 +02:00
|
|
|
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/algorithms/bitquad_creation.h>
|
2005-09-21 12:29:33 +02:00
|
|
|
|
|
|
|
// input output
|
|
|
|
#include <wrap/io_trimesh/import_ply.h>
|
2010-04-29 17:08:18 +02:00
|
|
|
#include <wrap/io_trimesh/export.h>
|
2005-09-21 12:29:33 +02:00
|
|
|
|
|
|
|
using namespace vcg;
|
|
|
|
using namespace std;
|
|
|
|
|
2005-12-02 01:46:12 +01:00
|
|
|
|
|
|
|
class MyEdge; // dummy prototype never used
|
|
|
|
class MyFace;
|
|
|
|
class MyVertex;
|
|
|
|
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType,
|
|
|
|
Use<MyFace>::AsFaceType>{};
|
|
|
|
|
|
|
|
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
|
2010-04-27 16:59:12 +02:00
|
|
|
class MyFace : public Face < MyUsedTypes, face::InfoOcf, face::FFAdjOcf, face::VertexRef, face::BitFlags > {};
|
|
|
|
class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, face::vector_ocf<MyFace> > {};
|
2005-12-02 01:46:12 +01:00
|
|
|
|
|
|
|
|
2005-09-21 12:29:33 +02:00
|
|
|
|
|
|
|
#define FLAT 0
|
2010-04-27 16:59:12 +02:00
|
|
|
#define LOOP 1
|
|
|
|
#define CATMULL 2
|
|
|
|
#define BUTTERFLY 3
|
2010-04-29 17:08:18 +02:00
|
|
|
#define ONE_QUAD_X_EDGE 4
|
2005-09-21 12:29:33 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if(argc<4)
|
|
|
|
{
|
|
|
|
printf(
|
2016-01-25 15:47:06 +01:00
|
|
|
"\n PlyRefine (" __DATE__ ")\n"
|
2005-09-21 12:29:33 +02:00
|
|
|
" Visual Computing Group I.S.T.I. C.N.R.\n"
|
2010-04-29 17:08:18 +02:00
|
|
|
"Usage: PlyRefine filein.ply fileout.[ply|off|obj|...] ref_step [opt] \n"
|
2005-09-21 12:29:33 +02:00
|
|
|
"Commands: \n"
|
|
|
|
" Refinement rules:\n"
|
|
|
|
" -m use simple midpoint subdivision (default) \n"
|
2010-04-27 16:59:12 +02:00
|
|
|
" -b use butterfly subdivision scheme \n"
|
2010-04-29 17:08:18 +02:00
|
|
|
" -l use loop subdivision scheme \n"
|
|
|
|
" -o use one-quad-per-edge schema (*) \n"
|
|
|
|
" -c use Catmull-Clark (*) \n"
|
2010-04-27 16:59:12 +02:00
|
|
|
" -e# refine only if the the edge is longer than #(default 0.0)\n"
|
2010-04-29 17:08:18 +02:00
|
|
|
"Info:\n"
|
|
|
|
" (*) produces quad-only meshes, but updates topology only, \n"
|
|
|
|
" and leaves geometry unaffected \n"
|
|
|
|
);
|
|
|
|
exit(2);
|
2005-09-21 12:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int RefMode = FLAT ;
|
|
|
|
int i=4; int n_steps; float length=0;
|
|
|
|
while(i<argc)
|
|
|
|
{
|
|
|
|
if(argv[i][0]!='-')
|
2010-04-29 17:08:18 +02:00
|
|
|
{printf("Error unable to parse option '%s'\n",argv[i]); exit(5);}
|
2005-09-21 12:29:33 +02:00
|
|
|
switch(argv[i][1])
|
|
|
|
{
|
|
|
|
case 'm' : RefMode=FLAT; break;
|
|
|
|
case 'b' : RefMode=BUTTERFLY; break;
|
2010-04-29 17:08:18 +02:00
|
|
|
case 'l' : RefMode=LOOP; break;
|
|
|
|
case 'c' : RefMode=CATMULL; break;
|
|
|
|
case 'o' : RefMode=ONE_QUAD_X_EDGE; break;
|
2010-04-27 16:59:12 +02:00
|
|
|
case 'e' : length=(float)atof(argv[i]+2); break;
|
2005-09-21 12:29:33 +02:00
|
|
|
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyMesh m;
|
2010-04-29 17:08:18 +02:00
|
|
|
|
|
|
|
if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0) {
|
2005-09-21 12:29:33 +02:00
|
|
|
printf("Error reading file %s\n",argv[1]);
|
2010-04-29 17:08:18 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-04-27 16:59:12 +02:00
|
|
|
m.face.EnableFFAdjacency();
|
|
|
|
tri::UpdateTopology<MyMesh>::FaceFace(m);
|
|
|
|
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
|
2012-10-09 09:12:31 +02:00
|
|
|
tri::UpdateNormal<MyMesh>::PerVertexNormalized(m);
|
2012-10-15 09:52:40 +02:00
|
|
|
printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
|
2005-09-21 12:29:33 +02:00
|
|
|
|
|
|
|
n_steps=atoi(argv[3]);
|
|
|
|
|
|
|
|
for(i=0;i < n_steps;++i)
|
|
|
|
{
|
2010-04-27 16:59:12 +02:00
|
|
|
switch(RefMode)
|
|
|
|
{
|
|
|
|
case FLAT:
|
2012-10-09 09:12:31 +02:00
|
|
|
tri::Refine<MyMesh, tri::MidPoint<MyMesh> >(m,tri::MidPoint<MyMesh>(&m),length);
|
2010-04-27 16:59:12 +02:00
|
|
|
break;
|
|
|
|
case LOOP:
|
2012-10-09 09:12:31 +02:00
|
|
|
tri::RefineOddEven<MyMesh, tri::OddPointLoop<MyMesh>, tri::EvenPointLoop<MyMesh> >(m, tri::OddPointLoop<MyMesh>(m), tri::EvenPointLoop<MyMesh>(), length);
|
2010-04-27 16:59:12 +02:00
|
|
|
break;
|
|
|
|
case CATMULL:
|
2010-04-29 17:08:18 +02:00
|
|
|
tri::BitQuadCreation<MyMesh>::MakePureByCatmullClark(m);
|
2012-10-09 09:12:31 +02:00
|
|
|
tri::UpdateNormal<MyMesh>::PerBitQuadFaceNormalized(m);
|
2010-04-29 17:08:18 +02:00
|
|
|
break;
|
|
|
|
case ONE_QUAD_X_EDGE:
|
2010-04-27 16:59:12 +02:00
|
|
|
tri::BitQuadCreation<MyMesh>::MakePureByRefine(m);
|
2012-10-09 09:12:31 +02:00
|
|
|
tri::UpdateNormal<MyMesh>::PerBitQuadFaceNormalized(m);
|
2010-04-27 16:59:12 +02:00
|
|
|
break;
|
|
|
|
case BUTTERFLY:
|
2012-10-09 09:12:31 +02:00
|
|
|
tri::Refine<MyMesh, tri::MidPointButterfly<MyMesh> >(m,tri::MidPointButterfly<MyMesh>(m),length);
|
2010-04-27 16:59:12 +02:00
|
|
|
break;
|
2005-09-21 12:29:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:52:40 +02:00
|
|
|
printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
|
2010-04-29 17:08:18 +02:00
|
|
|
|
2018-02-13 19:40:56 +01:00
|
|
|
vcg::tri::io::Exporter<MyMesh>::Save(m,argv[2],vcg::tri::io::Mask::IOM_BITPOLYGONAL);
|
2010-04-29 17:08:18 +02:00
|
|
|
return 0;
|
|
|
|
}
|