-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer.cpp
160 lines (138 loc) · 4.48 KB
/
viewer.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
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
/*
* main.cpp
*
* Created on: Mar 4, 2010
* Author: pushkar
*/
#include <stdio.h>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <map>
#include <time.h>
#include "gl/main.h"
#include "gl/view.h"
#include "xml_parser.h"
#include "packlist.h"
#include "response.h"
#define SCALE 1000.0f
// Global Variables
PackList list;
OrderXML oxml;
uint c;
uint ct;
uint weight;
uint volume, tvolume;
double f_volume, f_tvolume, f_theight;
int theight;
struct col {
float r, g, b;
};
std::map <int, col> color;
PackPallet cpallet; // current packpallet from Response XML
Pallet pallet; // current pallet from Order XML
void pallet_draw_vector() {
volume = 0;
weight = 0;
theight = 1;
tvolume = 305*406;
f_tvolume = (double)tvolume/SCALE;
double density;
char str[100] = "";
for(unsigned int i = 0; i < c; i++) {
glPushMatrix();
Article art = cpallet.package[i].article;
int orient = cpallet.package[i].orientation;
col nc = color[art.id];
Point pos = cpallet.package[i].place_position;
Point pos_a1 = cpallet.package[i].approach_point_1.add(pos);
Point pos_a2 = cpallet.package[i].approach_point_2.add(pos);
Point pos_a3 = cpallet.package[i].approach_point_3.add(pos);
if(i == c-1) {
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_LINES);
glVertex3f(pos_a1.x, pos_a1.y, pos_a1.z);
glVertex3f(pos_a2.x, pos_a2.y, pos_a2.z);
glEnd();
glBegin(GL_LINES);
glVertex3f(pos_a2.x, pos_a2.y, pos_a2.z);
glVertex3f(pos_a3.x, pos_a3.y, pos_a3.z);
glEnd();
glBegin(GL_LINES);
glVertex3f(pos_a3.x, pos_a3.y, pos_a3.z);
glVertex3f(pos.x, pos.y, pos.z);
glEnd();
}
pos.z = pos.z - art.height/2.0f;
glColor3f(nc.r, nc.g, nc.b);
glTranslatef(pos.x, pos.y, pos.z);
if(orient == 1) { glScalef((float)art.length/1.0f, (float)art.width/1.0f, (float)art.height/1.0f); }
else { glScalef((float)art.width/1.0f, (float)art.length/1.0f, (float)art.height/1.0f); }
glutSolidCube(1.0f);
glColor3f(0.0f, 0.0f, 0.0f);
glutWireCube(1.0f);
glPopMatrix();
if(theight < pos.z) theight = pos.z;
weight += art.weight;
volume += (art.height*art.width*art.length);
glColor3f(0.7f, 0.7f, 0.7f);
//sprintf(str, "Force on Package %d: %.2lf\n", c-1, cpallet.package[c-1].normal_force);
//draw_string(20.0f, 100.0f, GLUT_BITMAP_HELVETICA_10, str);
//sprintf(str, "Package %d is connected to %d packages\n", c-1, cpallet.package[c-1].connect.size());
//draw_string(20.0f, 120.0f, GLUT_BITMAP_HELVETICA_10, str);
}
f_volume = (double)volume/SCALE;
f_theight = (double)theight;
f_tvolume *= f_theight;
density = f_volume/f_tvolume;
glColor3f(0.7f, 0.7f, 0.7f);
sprintf(str, "Weight: %d\n", weight); draw_string(20.0f, 20.0f, GLUT_BITMAP_HELVETICA_10, str);
sprintf(str, "Height: %.4lf\n", f_theight); draw_string(20.0f, 35.0f, GLUT_BITMAP_HELVETICA_10, str);
sprintf(str, "Volume: %.4lf\n", f_volume); draw_string(20.0f, 50.0f, GLUT_BITMAP_HELVETICA_10, str);
sprintf(str, "Total Volume: %.4lf\n", f_tvolume); draw_string(20.0f, 65.0f, GLUT_BITMAP_HELVETICA_10, str);
sprintf(str, "Density: %.12lf\n", density); draw_string(20.0f, 80.0f, GLUT_BITMAP_HELVETICA_10, str);
}
void pallet_vector_key_control(int key) {
if(key == -1 && c > 1) c--;
else if(key == 1 && c < cpallet.n_package()) c++;
}
using namespace std;
int main(int argc, char* argv[]) {
char order_file[100] = "";
char packlist_file[100] = "";
if(argc < 5) {
printf("usage: %s -o Example.order.xml -p Example.packlist.xml\n", argv[0]);
printf("check: man pallet_viewer for more information.\n");
if(argc < 3) {
printf("Did you try the example xml's in /usr/share/vmac/?\n\n");
}
exit(0);
}
for(int i = 1; i < argc; i+=2) {
if(strcmp(argv[i], "-o") == 0) strcpy(order_file, argv[i+1]);
if(strcmp(argv[i], "-p") == 0) strcpy(packlist_file, argv[i+1]);
}
c = 0;
ct = 0;
pair<map<int, col>::iterator, bool> ret;
oxml.parse(order_file, 0, 0);
list = read_response(packlist_file, 0);
cpallet = list.packpallet[0];
pallet = oxml.pallet[0];
cpallet.find_normals();
srand(time(NULL));
for (uint i = 0; i < oxml.order.n_orderline(); i++) {
col nc;
nc.r = (float)(rand() % 1000 + 1)/1000.0f;
nc.g = (float)(rand() % 1000 + 1)/1000.0f;
nc.b = (float)(rand() % 1000 + 1)/1000.0f;
color.insert(pair<int, col> (i/*oxml.order.orderline[i].article.id*/, nc));
//TODO: Find ids
}
printf("Press g/f to spawn boxes...\n");
printf("Press w/a/s/d and mouse to move...\n");
printf("Press z to exit...\n");
gl_init(argc, argv, "Pallet Viewer", 800, 600);
glutMainLoop();
return 0;
}