-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
105 lines (82 loc) · 2.48 KB
/
main.cpp
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
#include <iostream>
#include "Delaunay.h"
#include <igl/opengl/glfw/Viewer.h>
#include <igl/jet.h>
using namespace std ;
void writeObj(string st,vector<Vertex*>& vertexs,vector<tuple<Vertex*,Vertex*,Vertex*>> tris)
{
ofstream ou(st) ;
int k = 1 ;
for(int i = 0; i< vertexs.size();i++)
{
ou<<"v "<<setprecision(2)<<" "<<vertexs[i]->x()<<" "<<vertexs[i]->y()<<" "<<vertexs[i]->z()<<endl;
vertexs[i]->setallIndex(k++) ;
}
for(int i = 0 ;i< tris.size();i++)
{
ou<<"f "<<setprecision(2)
<<std::get<0>(tris[i])->getallIndex()<<" "
<<std::get<1>(tris[i])->getallIndex()<<" "
<<std::get<2>(tris[i])->getallIndex()<<endl ;
}
ou.close();
}
int main() {
Delaunay* a= new Delaunay("/Users/lidan/Desktop/数字高程模型/样例/resource2.node") ;
EdgePartition all = a->beginTriangulate(a->getVertexs() ) ;
VertexList vl_list = a->getVertexs() ;
VertexList vl ;
QuadList el = a->getEdges() ;
Edge* e= std::get<0>(all) ;
vector<Edge*> edges = {e};
while(!rightOf(e->Onext()->Des(),e))
{
e = e->Onext() ;
}
add(vl,e,edges) ;
vl.clear() ;
int k = 0 ;
while(k<edges.size())
{
if(!((e=edges[k++])->used))
{
add(vl,e,edges) ;
}
}
vector<tuple<Vertex*,Vertex*,Vertex*>> tris ;
for(int i = 0; i < (int)vl.size();i+=3)
{
tris.push_back(make_tuple(vl[i],vl[i+1],vl[i+2])) ;
}
for(int i = 0; i< el.size();i++)
{
cout<<el[i]->edges[0].org()->getallIndex()<<" "
<<el[i]->edges[0].Lnext()->org()->getallIndex()<<" "
<<el[i]->edges[0].Lnext()->Lnext()->org()->getallIndex()<<endl ;
}
string obj= "/Users/lidan/Desktop/数字高程模型/样例/resource.obj";
writeObj(obj,vl_list, tris);
// string obj = "/Users/lidan/Desktop/数字高程模型/数字高程模型代码/样例数据/another.obj";
// string obj = "/Users/lidan/CLionProjects/marchingcube/data.obj" ;
// Eigen::MatrixXd V;
// Eigen::MatrixXi F;
// Eigen::MatrixXd C;
//
// igl::readOBJ(obj, V, F);
//
// igl::opengl::glfw::Viewer viewer;
// viewer.data().set_mesh(V, F);
//
// // Use the z coordinate as a scalar field over the surface
//
// Eigen::VectorXd Z = V.col(2);
//
// // Compute per-vertex colors
// igl::jet(Z,true,C);
//
// // Add per-vertex colors
// viewer.data().set_colors(C);
//
// // Launch the viewer
// viewer.launch();
}