File: trimesh_optional.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 (92 lines) | stat: -rw-r--r-- 2,378 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
#include <stdio.h>
#include <time.h>

#include "mesh_definition.h"
#include<vcg/complex/allocate.h>
#include<vcg/complex/algorithms/create/platonic.h>
#include<vcg/complex/algorithms/update/topology.h>
#include<vcg/complex/algorithms/update/flag.h>
#include<vcg/complex/algorithms/update/normal.h>
#include<vcg/complex/algorithms/update/bounding.h>
#include <vcg/complex/algorithms/refine.h>

using namespace vcg;
using namespace std;

int main(int , char **)
{



	CMesh cm;
	CMeshOcf cmof;
 


  tri::Tetrahedron(cm);
  tri::Tetrahedron(cmof);
 
  printf("Generated mesh has %i vertices and %i triangular faces\n",cm.vn,cm.fn);
  
  /// Calculates both vertex and face normals.
  /// The normal of a vertex v is the weigthed average of the normals of the faces incident on v.
  /// normals are not normalized
cmof.face.EnableFFAdjacency();

  vcg::tri::UpdateTopology<CMesh   >::FaceFace(cm);
  vcg::tri::UpdateTopology<CMeshOcf>::FaceFace(cmof);
	
  vcg::tri::UpdateFlags<CMesh   >::FaceBorderFromFF(cm);
	vcg::tri::UpdateFlags<CMeshOcf>::FaceBorderFromFF(cmof);

	vcg::tri::UpdateNormals<CMesh   >::PerVertexNormalized(cm);
	vcg::tri::UpdateNormals<CMeshOcf>::PerVertexNormalized(cmof);


  printf("Normal of face 0 is %f %f %f\n\n",cm.face[0].N()[0],cm.face[0].N()[1],cm.face[0].N()[2]);
  int t0=0,t1=0;
  while(t1-t0<200)
  {
    t0=clock();
    Refine(cm,MidPointButterfly<CMesh>(),0); 
    t1=clock();
    Refine(cmof,MidPointButterfly<CMeshOcf>(),0); 
  }


	cmof.vert.EnableRadius();
	cmof.vert.EnableQuality();

	unsigned int hh = 0;
	for(CMeshOcf::VertexIterator vi = cmof.vert.begin(); vi!=cmof.vert.end();++vi,++hh){
		if(hh%3==0)
			vcg::tri::Allocator<CMeshOcf>::DeleteVertex(cmof,*vi);
	}

  for(CMeshOcf::VertexIterator vi = cmof.vert.begin(); vi!=cmof.vert.end();++vi)
      {
        if(!(*vi).IsD())
        {
          float q =vi->Q();
          float r =vi->R();
//          int ii = vcg::tri::Index(cmof, *vi);
          assert(q==r);
        }
      }

      tri::Allocator<CMeshOcf>::CompactVertexVector(cmof);
      tri::UpdateBounding<CMeshOcf>::Box(cmof);
      for(CMeshOcf::VertexIterator vi = cmof.vert.begin(); vi!=cmof.vert.end();++vi)
      {
        if(!(*vi).IsD())
        {
          float q =vi->Q();
          float r =vi->R();
//          int ii = vcg::tri::Index(cmof, *vi);
          assert(q==r);
        }
      }


  return 0;
}