File: trimesh_join.cpp

package info (click to toggle)
meshlab 1.3.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,900 kB
  • ctags: 33,325
  • sloc: cpp: 224,813; ansic: 8,170; xml: 119; makefile: 78
file content (111 lines) | stat: -rw-r--r-- 3,484 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <vector>

#include<vcg/simplex/vertex/base.h>
#include<vcg/simplex/face/base.h>
#include<vcg/simplex/face/topology.h>

#include<vcg/complex/complex.h>
#include<vcg/complex/allocate.h>
#include<vcg/complex/append.h>
#include<vcg/complex/algorithms/clean.h>
#include<vcg/complex/algorithms/clip.h>
#include<vcg/complex/algorithms/update/bounding.h>


// input output
#include <wrap/io_trimesh/import_ply.h>
#include <wrap/io_trimesh/export_ply.h>

// std
#include <vector>

using namespace vcg;
using namespace std;

class MyFace;
class MyVertex;

struct MyUsedTypes : public UsedTypes<	Use<MyVertex>		::AsVertexType,
																				Use<MyFace>			::AsFaceType>{};

class MyVertex  : public Vertex <MyUsedTypes, vertex::Coord3f, vertex::BitFlags  >{};
class MyFace    : public Face   < MyUsedTypes, face::VertexRef, face::BitFlags > {};
class MyMesh    : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};



int main(int argc,char **argv )
{
 if(argc<2)
	{
		printf(		"\n trimesh_join ("__DATE__")\n"
		        	  "Visual Computing Group I.S.T.I. C.N.R.\n"
                "Usage: trimesh_join [opt] filename.ply [filename.ply | *] \n"
                "where opt can be:\n"
                "   -b xmin ymin zmin xmax ymax zmax  : \n"
                "      Returns only mesh composed by faces inside specified bbox\n"
                "   -t Just scan all the input files computing the total bbox\n"
			);
		exit(0);
	}

  MyMesh ml,mr;
  Box3f ClipBB,TotBB;
  bool ClipFlag=false,MergeFlag=true;
	int i=1; 
  // Parsing option loop
  while(argv[i][0]=='-')
  {
    switch(argv[i][1])
    {
      case 'b': { 
              if(argc<i+7) {
                printf("Error in parsing bbox option");
  		          exit(0);
              }
              ClipBB.min=Point3f::Construct(atof(argv[i+1]),atof(argv[i+2]),atof(argv[i+3]));
              ClipBB.max=Point3f::Construct(atof(argv[i+4]),atof(argv[i+5]),atof(argv[i+6]));
              i+=6;
              printf("Clipping incoming meshes with box:\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
                    ClipBB.min[0],ClipBB.min[1],ClipBB.min[2],
                    ClipBB.max[0],ClipBB.max[1],ClipBB.max[2]);
              ClipFlag=true;
          } break;
    case 't': MergeFlag=false; break;
    default : printf("Unknown option '%s'\n",argv[i]);
    }
  ++i;
  }
	while(i<argc)
		{
		  if(vcg::tri::io::ImporterPLY<MyMesh>::Open(mr,argv[i])!=0)
		  {
        printf("Error reading file  %s\n",argv[1]);
			  exit(0);
		  }
      printf("Input mesh %3i           vn:%9i fn:%9i\n",i, mr.vn, mr.fn);
      if(ClipFlag) 
      { 
        tri::GenericVertexInterpolator<MyMesh> interp(mr);
        tri::TriMeshClipper<MyMesh>::Box(ClipBB,interp,mr);
        printf("              clipped to vn:%9i fn:%9i\n", mr.vn, mr.fn);
      }
      tri::UpdateBounding<MyMesh>::Box(mr);
      TotBB.Add(mr.bbox);
      
      if(MergeFlag) tri::Append<MyMesh,MyMesh>::Mesh(ml,mr); // append mesh mr to ml
  		++i;
		}
  
  printf("Output mesh vn:%i fn:%i\n",ml.vn,ml.fn);
	
  tri::io::ExporterPLY<MyMesh>::Save(ml,"joined.ply");
  int dv=tri::Clean<MyMesh>::RemoveDuplicateVertex(ml); 
  printf("Removed %i duplicated vertices\n",dv);
  tri::io::ExporterPLY<MyMesh>::Save(ml,"joined_unif.ply");
  printf("Final BBox of mesh :\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
                    TotBB.min[0],TotBB.min[1],TotBB.min[2],
                    TotBB.max[0],TotBB.max[1],TotBB.max[2]);
       
}