-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
210 lines (178 loc) · 5.49 KB
/
main.cpp
File metadata and controls
210 lines (178 loc) · 5.49 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//Copyright © 2014 Fred Mariowitsch Flügge <fmfluegge@gmail.com>
//This program is free software. It comes without any warranty, to
//the extent permitted by applicable law. You can redistribute it
//and/or modify it under the terms of the Do What The Fuck You Want
//To Public License, Version 2, as published by Sam Hocevar. See
//http://www.wtfpl.net/ for more details.
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <fstream>
#include <iostream>
#include <cmath>
#include <cstdint>
#include <cstdio>
#define size32 1024
#define scale32 64
#define size16 256
int mode;
unsigned int container32[size32][size32];
unsigned int container16[size16][size16];
unsigned int maxCount16;
unsigned int maxCount32;
float toScale(unsigned int in){
float ret = 0.0f;
if (mode==0) {
ret = (((double)in * (0.98084291187739f/1024.0f))+10*(0.98084291187739f/1024.0f));
}
if (mode==1) {
ret = (((double)in * (0.92753623188406f/256.0f)))+10*(0.92753623188406f/256.0f);
}
return ret;
}
void process_Keys(unsigned char key, int x, int y)
{
switch(key){
case 27:exit(EXIT_SUCCESS);break;//esc
case 49:
mode=0;
glutSetWindowTitle("fvis 32");
glutReshapeWindow(1044, 1044);
break;//key 1
case 50:
mode=1;
glutSetWindowTitle("fvis 16");
glutReshapeWindow(276, 276);
break;//key 2
default:
printf("key_code =%d \n",key);
break;
}
}
void draw(void){
float ratio;
int width= glutGet(GLUT_WINDOW_WIDTH);
int height= glutGet(GLUT_WINDOW_HEIGHT);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
glMatrixMode(GL_MODELVIEW);
if (mode==0) { //32 bit scatterplott
glBegin(GL_POINTS);
for (unsigned int i = 0; i<size32; i++) {
for (unsigned int j = 0;j<size32;j++){
if (container32[i][j]!=0) {
float colval=container32[i][j];
colval = colval * (0.8f/maxCount32);
glColor3f(0.2f, 0.2f+colval, 0.2f);
glVertex3f(toScale(i), toScale(j), 1.0f);
}
}
}
glEnd();
}
if (mode==1) { //16 bit scatterplott
glBegin(GL_POINTS);
for (unsigned int i = 0; i<size16; i++) {
for (unsigned int j = 0;j<size16;j++){
if (container16[i][j]!=0) {
float colval=container16[i][j];
colval = colval * (0.8f/maxCount16);
glColor3f(0.2f, 0.2f+colval, 0.2f);
glVertex3f(toScale(i), toScale(j), 1.0f);
}
}
}
glEnd();
}
glFlush();
}
int main(int argc, char *argv[])
{
mode = 0;
if (argc < 2) {
std::cout << "please give a file path" << std::endl;
return 1;
}
/*if (argc > 2) {
std::cout << "to many arguments" << std::endl;
return 1;
}*/
std::cout << "plotting " << argv[1] << std::endl;
//////////32bit
for (int i=0;i<size32;i++) {
for (int j=0;j<size32;j++){
container32[i][j]=0;
}
}
unsigned short buff32_1;
unsigned short buff32_2;
//Load File Stuff
std::ifstream myfile32 (argv[1], std::ios::binary);
//std::ifstream myfile32 ("testfile", std::ios::binary);
if(myfile32.is_open()){
while(!myfile32.eof()){
myfile32.read((char*)&buff32_1,sizeof(buff32_1));
myfile32.read((char*)&buff32_2,sizeof(buff32_2));
container32[buff32_1/scale32][buff32_2/scale32]++;
}
myfile32.close();
}else{
std::cout << "file not found";
}
maxCount32=0;
for (unsigned int i=0; i<size32; i++) {
for (unsigned int j=0; j<size32; j++) {
if (maxCount32<container32[i][j]) {
maxCount32=container32[i][j];
}
}
}
/////////
//////////16bit
for (int i=0; i<(size16); i++) {
for (int j=0; j<(size16); j++) {
container16[i][j]=0;
}
}
unsigned char buff16_1;
unsigned char buff16_2;
//Load File Stuff
std::ifstream myfile16 (argv[1], std::ios::binary);
//std::ifstream myfile16 ("testfile", std::ios::binary);
if(myfile16.is_open()){
while(!myfile16.eof()){
myfile16.read((char*)&buff16_1,sizeof(buff16_1));
myfile16.read((char*)&buff16_2,sizeof(buff16_2));
container16[buff16_1][buff16_2]++;
}
myfile16.close();
}else{
std::cout << "file not found";
}
maxCount16=0;
for (int i=0; i<(size16); i++) {
for (int j=0; j<(size16); j++) {
if (maxCount16<container16[i][j]) {
maxCount16=container16[i][j];
}
}
}
/////////
/* Initialize GLUT */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
glutInitWindowPosition(50, 25);
glutInitWindowSize(1044,1044);
glutCreateWindow("fvis32");
glutKeyboardFunc( process_Keys );
glutDisplayFunc(draw);
glutMainLoop();
exit(EXIT_FAILURE);
}