-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolylineRender.cpp
More file actions
173 lines (149 loc) · 4.48 KB
/
polylineRender.cpp
File metadata and controls
173 lines (149 loc) · 4.48 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// ----------------------------------------------------------------------------
// tubeRender.cpp : load geometry in the format of "tgdata" and render directly
// through the legacy openGL pipeline
//
// ----------- when being imposed with modeling transformations, stay in the
// fixed grand coordinate system.
//
// Creation : Feb. 6th 2011
//
// Copyright(C) 2011-2012 Haipeng Cai
//
// ----------------------------------------------------------------------------
#include "GLcppmoth.h"
#include "GLoader.h"
#include "glrand.h"
using namespace std;
class CpolylineRender: public CGLApp {
public:
CpolylineRender(int argc, char **argv) : CGLApp(argc, argv),
m_bUseOrgColor(true),
m_loader(),
m_strfn("") {
setVerinfo("polylineRender");
addOption('f', true, "input-file-name", "the name of source file"
" containing geometry and in the format of tgdata");
}
void genColors() {
glrand::genFloatvector<GLfloat> (3, m_colors,
ARRAY_SIZE(m_colors), 0, 1);
if ( m_cout.isswitchon() ) {
cout << "colors: ";
copy (m_colors, m_colors + ARRAY_SIZE(m_colors),
ostream_iterator<GLfloat> (cout, " "));
cout << "\n";
}
}
void glInit(void) {
CGLApp::glInit();
// dis/en -abling primitive arrays
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
// force normalization when normals are designated
glEnable(GL_NORMALIZE);
}
int handleOptions(int optv) {
switch( optv ) {
case 'f':
m_strfn = optarg;
return 0;
default:
return CGLApp::handleOptions( optv );
}
return 1;
}
void keyResponse(unsigned char key, int x, int y) {
switch (key) {
case 'c': // randomly seeding vertices
m_bUseOrgColor = ! m_bUseOrgColor;
break;
case 'g': // generate different colors
if (!m_bUseOrgColor) {
genColors();
glColor3fv( m_colors );
}
break;
default:
return CGLApp::keyResponse(key, x, y);
}
glutPostRedisplay();
}
int loadGeometry() {
if ( 0 != m_loader.load(m_strfn) ) {
m_cout << "Loading geometry failed - GLApp aborted abnormally.\n";
return -1;
}
return 0;
}
int mainstay() {
// geometry must be loaded successfully in the first place in order the
// openGL pipeline could be launched.
if ( 0 != loadGeometry() ) {
return -1;
}
setPrjInfo(60.0f,
30,
//ABS(m_loader.getMaxCoord(2)) + ABS(m_loader.getMinCoord(2)),
//( ABS(m_loader.getMaxCoord(2)) + ABS(m_loader.getMinCoord(2)) )*2 );
(ABS(m_loader.getMaxCoord(2)) + ABS(m_loader.getMinCoord(2)))*4 + 30);
setViewInfo(
(m_loader.getMaxCoord(0) + m_loader.getMinCoord(0))/2,
(m_loader.getMaxCoord(1) + m_loader.getMinCoord(1))/2,
//m_loader.getMaxCoord(2) + 10.0,
( ABS(m_loader.getMaxCoord(2)) + ABS(m_loader.getMinCoord(2)) )*2 + 40 ,
(m_loader.getMaxCoord(0) + m_loader.getMinCoord(0))/2,
(m_loader.getMaxCoord(1) + m_loader.getMinCoord(1))/2,
(m_loader.getMaxCoord(2) + m_loader.getMinCoord(2))/2,
//0,
0, 1, 0);
setGlutInfo(" DTI fiber polylines ");
return CGLApp::mainstay();
}
void draw() {
/* load polyline by means of vertex buffer one by one, assuming the
* loader has already got the vertices and colors all well-prepared
*/
unsigned long szTotal = m_loader.getSize();
for (unsigned long idx = 0; idx < szTotal; ++idx) {
vector<GLfloat> & curLine = m_loader.getElement( idx );
/*
cout << "curline No." << idx << " : [" << curLine.size() << " elements, " <<
( curLine.size()/6 ) << " points ]" << endl;
copy(curLine.begin(), curLine.end(), ostream_iterator< GLfloat > (cout, " "));
cout << endl;
*/
if ( m_bUseOrgColor ) {
glInterleavedArrays(GL_C3F_V3F, 0, &curLine[0]);
//glEnableClientState( GL_VERTEX_ARRAY );
//glVertexPointer(3, GL_FLOAT, 0, &curLine[0]);
//ofs << (curLine.size()/3) << fixed << setprecision(6) << endl;
/*
glBegin(GL_LINE_STRIP);
for (int j = 0; j<curLine.size();j+=3) {
glVertex3f( curLine[j], curLine[j+1], curLine[j+2] );
//ofs << curLine[j] << " " << curLine[j+1] << " " << curLine[j+2] << endl;
}
glEnd();
*/
}
else {
glInterleavedArrays(GL_V3F, 6*sizeof(GLfloat), &curLine[3]);
}
glDrawArrays(GL_LINE_STRIP, 0, curLine.size()/6);
}
//ofs.close();
}
private:
GLfloat m_colors[3];
GLboolean m_bUseOrgColor;
CTgdataLoader m_loader;
string m_strfn;
};
int main(int argc, char** argv)
{
CpolylineRender pr(argc, argv);
pr.run();
return 0;
}
/* set ts=4 sts=4 tw=80 sw=4 */