-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathosg_triangle_plotter.cpp
121 lines (96 loc) · 3.81 KB
/
osg_triangle_plotter.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/******************************************************************************
* BRICS_3D - 3D Perception and Modeling Library
* Copyright (c) 2011, GPS GmbH
*
* Author: Sebastian Blumenthal
*
*
* This software is published under a dual-license: GNU Lesser General Public
* License LGPL 2.1 and Modified BSD license. The dual-license implies that
* users of this code may choose which terms they prefer.
*
* 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 Lesser General Public License LGPL and the BSD license for
* more details.
*
******************************************************************************/
#include <iostream>
#include <brics_3d/core/TriangleMeshImplicit.h>
#include <brics_3d/core/TriangleMeshExplicit.h>
#include <brics_3d/util/OSGTriangleMeshVisualizer.h>
using namespace std;
using namespace brics_3d;
int main(int argc, char **argv) {
/* check argument */
// string filename;
// if (argc == 1) {
// cout << "Usage: " << argv[0] << " <filename>" << endl;
//
// char defaultFilename[255] = { BRICS_IMGAGES_DIR };
// strcat(defaultFilename, "/zcam_param1c.pgm\0");
// filename = defaultFilename;
//
// cout << "Trying to get default file: " << filename << endl;
// } else if (argc == 2) {
// filename = argv[1];
// cout << filename << endl;
// } else {
// cerr << "Usage: " << argv[0] << " <filename>" << endl;
// return -1;
// }
/* create triangle mesh */
Point3D* vertex000 = new Point3D(0,0,0);
Point3D* vertex100 = new Point3D(1,0,0);
Point3D* vertex101 = new Point3D(1,0,1);
// Point3D* vertex001 = new Point3D(0,0,1);
Point3D* vertex001 = new Point3D(0,0.2,1);
Point3D* vertex110 = new Point3D(1,1,0);
// Point3D* vertex111 = new Point3D(1,1,1);
Point3D* vertex111 = new Point3D(0.8,1,1);
Triangle* testTriangle1 = new Triangle(*vertex000, *vertex100, *vertex101);
Triangle* testTriangle2 = new Triangle(*vertex101, *vertex001, *vertex000);
Triangle* testTriangle3 = new Triangle(*vertex100, *vertex110, *vertex101); //...
Triangle* testTriangle4 = new Triangle(*vertex101, *vertex110, *vertex111);
TriangleMeshExplicit* meshExplicit = new TriangleMeshExplicit();
meshExplicit->addTriangle(testTriangle1);
meshExplicit->addTriangle(testTriangle2);
meshExplicit->addTriangle(testTriangle3);
meshExplicit->addTriangle(testTriangle4);
TriangleMeshImplicit* meshImplicit = new TriangleMeshImplicit();
// index
(*meshImplicit->getVertices()).push_back(vertex000); // 0
(*meshImplicit->getVertices()).push_back(vertex100); // 1
(*meshImplicit->getVertices()).push_back(vertex101); // 2
(*meshImplicit->getVertices()).push_back(vertex001); // 3
(*meshImplicit->getVertices()).push_back(vertex110); // 4
(*meshImplicit->getVertices()).push_back(vertex111); // 5
(*meshImplicit->getIndices()).push_back(0);
(*meshImplicit->getIndices()).push_back(1);
(*meshImplicit->getIndices()).push_back(2);
(*meshImplicit->getIndices()).push_back(2);
(*meshImplicit->getIndices()).push_back(3);
(*meshImplicit->getIndices()).push_back(0);
(*meshImplicit->getIndices()).push_back(2);
(*meshImplicit->getIndices()).push_back(1);
(*meshImplicit->getIndices()).push_back(4);
(*meshImplicit->getIndices()).push_back(2);
(*meshImplicit->getIndices()).push_back(4);
(*meshImplicit->getIndices()).push_back(5);
/* visualize triangle mesh */
OSGTriangleMeshVisualizer* visualizer = new OSGTriangleMeshVisualizer();
// visualizer->addTriangleMesh(meshImplicit);
visualizer->addTriangleMesh(meshExplicit);
visualizer->visualize();
delete visualizer;
delete meshImplicit;
delete meshExplicit;
delete vertex000;
delete vertex100;
delete vertex101;
delete vertex001;
delete vertex110;
delete vertex111;
return 0;
}