-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.cpp
368 lines (312 loc) · 8.14 KB
/
main.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/**************************
* Includes
*
**************************/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include "topol.h"
//#define GRAPHICS
#ifdef GRAPHICS
#include <windows.h>
#include <Windows.h>
#include "graphics.h"
#endif // GRAPHICS
using namespace std;
string getFile(string prompt, string errorPrompt)
{
string fname;
cout << prompt << endl;
cin >> fname;
ifstream isfile;
isfile.open(fname.c_str());
if (!isfile.is_open())
{
isfile.close();
cout << errorPrompt << endl;
fname = getFile(prompt, errorPrompt);
}
isfile.close();
return fname;
}
//--------------------------------------------
void printv(vector<int> v)
{
UINT i;
for (i = 0; i < v.size(); i++)
{
cout << v[i];
}
cout << " ";
}
//--------------------------------------------
borderLine getFileInfo(string fname, string outputFile){
ifstream vFile;
string header;
vector<string> groupNames;
vector<int> temp;
vector<float> weights;
vector<string> labels;
int i;
vFile.open(fname.c_str());
getline(vFile, header);
cout << header;
getline(vFile, header);
int number = atoi(header.c_str());
cout << endl << number << " groups:" << endl;
for (i = 0; i < number; i++){
getline(vFile, header);
groupNames.insert(groupNames.end(), header);
cout << header << endl;
}
int n = twoPow(number);
for (i = 0; i < n; i++){
getline(vFile, header); // get the whole line
string w = header.substr(0,header.find_first_of(" "));
weights.insert (weights.end(), atoi(w.c_str())); // it take the first number
string label;
try
{
label = header.substr(header.find_first_of(" "));
}
catch (const std::exception& e)
{
cout << i << endl;
label = "";
}
labels.insert (labels.end(), label);
cout << "w=" << w << " label:" << label << endl;
//getline(vFile, header, ' '); /// get the number
//weights.insert (weights.end(), atoi(header.c_str()));
//getline(vFile, header) ; /// get the rest of the line with the labels
//labels.insert (labels.end(), header);
temp = toBin(i, number);
printv(temp);
cout << ".- " << weights[i] << " : " << labels[i] << endl;
}
vFile.close();
binMap mymap(number);
string dataFile = outputFile + ".data";
borderLine lines(&mymap, groupNames, weights, labels, fname, outputFile);
vFile.open(dataFile.c_str());
if (vFile.good() == true){ // Unfinished
vFile.close();
lines.setCoords(dataFile);
}
return lines;
}
#ifndef GRAPHICS
int main(int argc, char** argv)
{
string fname;
string outputFile;
ofstream result;
fileText psfile;
fileText svgfile;
if (argc > 1){
fname = argv[1];
}
else{
fname = getFile("Name of the Venn data file?", "File not found!");
}
if (argc > 2){
outputFile = argv[2];
}
else{
outputFile = "result.svg";
}
borderLine lines = getFileInfo(fname, outputFile);
lines.interpolate(50);
lines.simulate(7);
//mymap.textOut();
//psfile = lines.toPS();
//result.open("result.ps");
//result.write(psfile.getText().c_str(), psfile.getText().size());
//result.close();
svgfile = lines.toSVG();
result.open(outputFile.c_str());
result.write(svgfile.getText().c_str(), svgfile.getText().size());
result.close();
return 0;
}
#else
HWND publich;
void temp(int n, string a="")
{
char t[200];
string temp;
sprintf(t, "%d", n);
temp = t;
MessageBox(publich, temp.c_str(), a.c_str(), MB_ICONINFORMATION | MB_OK);
}
void showText(char* n, string a="")
{
MessageBox(publich, n, a.c_str(), MB_ICONINFORMATION | MB_OK);
}
/**************************
* Function Declarations
*
**************************/
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
/**************************
* WinMain
*
**************************/
int WINAPI
WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
string fname;
ofstream result;
fileText psfile;
fileText svgfile;
fname = "venn.txt";
string outputFile = "result.svg";
borderLine lines = getFileInfo(fname, outputFile);
/* register window class */
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass (&wc);
/* create main window */
hWnd = CreateWindow (
"GLSample", "nVenn",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 800, 600,
NULL, NULL, hInstance, NULL);
publich = hWnd;
//MessageBox(hWnd, "hi", "yo", MB_ICONINFORMATION | MB_OK);
/* enable OpenGL for the window */
EnableOpenGL (hWnd, &hDC, &hRC);
init(); // Init bitmap font
lines.interpolate(8);
glGraphics mygl;
borderLine lres = mygl.gsimulate(&lines, 1000, hDC);
//mymap.textOut();
psfile = lres.toPS();
result.open("result.ps");
result.write(psfile.getText().c_str(), psfile.getText().size());
result.close();
svgfile = lres.toSVG();
result.open("result.svg");
result.write(svgfile.getText().c_str(), svgfile.getText().size());
result.close();
/* program main loop */
while (!bQuit)
{
/* check for messages */
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{
}
}
/* shutdown OpenGL */
DisableOpenGL (hWnd, hDC, hRC);
/* destroy the window explicitly */
DestroyWindow (hWnd);
return msg.wParam;
}
/********************
* Window Procedure
*
********************/
LRESULT CALLBACK
WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
}
/*******************
* Enable OpenGL
*
*******************/
void
EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* get the device context (DC) */
*hDC = GetDC (hWnd);
/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);
/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}
/******************
* Disable OpenGL
*
******************/
void
DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}
#endif