-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·93 lines (85 loc) · 2.6 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·93 lines (85 loc) · 2.6 KB
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
#include "STLmodel.h"
#include "Octree/Octree.h"
#define PI 3.1415926
#include <cmath>
int WinWidth;
int WinHeight;
STLmodel p;
Octree tree("0");
static int oldmy=-1,oldmx=-1;
static int angle=90;
static float heightz=0.0f;
static int depth = 7;
void drawSTL(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
p.setperspective(sin(angle*PI/180),cos(angle*PI/180),heightz,0,0,0,0,0,1);
p.drawSTL();
// p.drawAABB();
glTranslatef(p.xmin(),p.ymin(),p.zmin());
glScalef((p.xmax()-p.xmin())/pow(2,depth-1),(p.ymax()-p.ymin())/pow(2,depth-1),(p.zmax()-p.zmin())/pow(2,depth-1));
tree.Traverse();
// p.drawsliceequalllayers(30);
//p.drawslicefacet();
glutSwapBuffers();
}
void Reshape(int w, int h)
{
WinWidth = w;
WinHeight = h;
// //改变显示区域,起始位置为客户端窗口左下角(非坐标原点)
glViewport(0, 0, w, h);
// 开启更新深度缓冲区的功能
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//宽高比改为当前值,视线区域与屏幕大小一致;
gluPerspective(45, 1.0*WinWidth / WinHeight, 1, 1000);
glMatrixMode(GL_MODELVIEW);
}
void LeftMousePick( int button, int state, int x, int y)
{
if(button == GLUT_LEFT_BUTTON)
{
if(state == GLUT_DOWN)
oldmx=x,oldmy=y;
}
}
void onMouseMove( int x,int y)
{
angle+=x-oldmx;
heightz+=0.03f*(y-oldmy);
oldmx=x,oldmy=y;
}
int main(int argc, char *argv[])
{
if(argc<3)
{
cout<<"Please Input the file address and the depth"<<endl;
return -1;
}
p.ReadSTLFile(argv[1]);//读取地址
depth = atoi(argv[2]);
cout<<"xmax:"<<p.xmax()<<"\n"<<"xmin:"<<p.xmin()<<"\n"<<"ymax:"<<p.ymax()<<"\n"<<"ymin:"<<p.ymin()<<"\n"<<"zmax:"<<p.zmax()<<"\n"<<"zmin:"<<p.zmin()<<endl;
// p.sliceequalllayers(30);
// p.slicefacet(90);
tree.MakeOctree(depth);
tree.PointToOctree(p.m_VectorPoint,p.xmax(),p.xmin(),p.ymax(),p.ymin(),p.zmax(),p.zmin());
// tree.EdgeToOctree(p.m_VectorEdge,p.m_VectorPoint,p.xmax(),p.xmin(),p.ymax(),p.ymin(),p.zmax(),p.zmin());
tree.FacetToOctree_new(p.m_VectorFacet,p.m_VectorPoint,p.xmax(),p.xmin(),p.ymax(),p.ymin(),p.zmax(),p.zmin());
WinWidth = 800;
WinHeight = 800;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
//glutInitWindowPosition(100, 100);
glutInitWindowSize(WinWidth, WinHeight);
glutCreateWindow("ReadSTL");
glEnable(GL_DEPTH_TEST);
glutReshapeFunc(Reshape);
glutDisplayFunc(drawSTL);
glutIdleFunc(drawSTL);
glutMouseFunc(LeftMousePick);
glutMotionFunc(onMouseMove);
glutMainLoop();
return 0;
}