-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
1530 lines (1319 loc) · 52.6 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <GL/glut.h>
#include <GL/glui.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <opencv2/opencv.hpp>
#include "inc/inpaint/criminisi_inpainter.h"
using namespace std;
//////////////////////////////////////////////////////////
/* Tour Into the Picture, Copyright 2002 Ryoichi Mizuno */
/* ryoichi[at]mizuno.org */
/* Dept. of Complexity Science and Engineering */
/* at The University of Tokyo */
//////////////////////////////////////////////////////////
struct vector2D // 2次元ベクトルの構造体
{
float sx; // screen座標系のx座標
float sy; // screen座標系のy座標
};
struct vector5D // 5次元ベクトルの構造体
{
float x; // world座標系のx座標
float y; // world座標系のy座標
float z; // world座標系のz座標
float sx; // screen座標系のx座標
float sy; // screen座標系のy座標
};
struct vector3D // 3次元ベクトルの構造体
{
float x; // world座標系のx座標
float y; // world座標系のy座標
float z; // world座標系のz座標
};
struct color3D // 色の構造体
{
float r; // 赤
float g; // 緑
float b; // 青
};
struct ImageInfo {
cv::Mat originalImage;
cv::Mat targetMask;
cv::Mat sourceMask;
cv::Mat background;
};
/* 数学関係の定数 */
const float PI = 3.141592853f;
/* ファイルハンドリング関係の変数 */
const int maxnumberoffiles = 100; // 最大のファイル数
int currentfilenumber = 0; // 現在選択されているファイルの番号
typedef char FName_t[260]; // 長さ260の文字配列型
FName_t bmpfilename[maxnumberoffiles]; // ファイル名の配列(最大100)
/* bmpファイルハンドリング関係の変数 */
GLuint texture; // 元画像のデータへのポインタ
/* 3次元背景のモデリング関係の変数 */
vector2D ctrlPoint[5]; // 制御点のスクリーン座標
int selectedCtrlPointIndex = -1; // 選択された制御点のインデックス
float gradient[4]; // スパイダリーメッシュの傾き
struct vector5D estimatedVertex[13]; // 推定された頂点の座標
struct vector3D eye; // 視点のワールド座標
int resolutionnumber = 0; // 現在選択されている解像度の番号
int modenumber = 0;
bool on_press = false; //whether drawing the fg contour
float rough_coefficient = 0.05f; // 画像解析の細かさ(preview: 0.05f, lowresolution: 0.01f, normal:0.005, highresolution: 0.001f)
int deduceFlag = 0; // 現在の処理を示す旗
bool test_flag = false;
/* 透視投影関係の変数 */
float theta = 0.0f; // 方位角
float phi = 0.0f; // 仰角
float R, R0; // 視点と注視点の距離
float mat[9]; // 変換行列
float pbeginsx, pbeginsy; // マウスドラッグの始点
vector2D transferedEstimatedVertex[13]; // 透視変換後の推定された頂点のスクリーン座標
float oevminx, oevmaxx, oevminy, oevmaxy, oevdiffx, oevdiffy; // 透視変換の整合性のための変数
float tevminx, tevmaxx, tevminy, tevmaxy, tevdiffx, tevdiffy; // 透視変換の整合性のための変数
float tevminx0, tevmaxx0, tevminy0, tevmaxy0, tevdiffx0, tevdiffy0; // 透視変換の整合性のための変数
vector<vector<vector<vector5D>>> foreground_objects;
vector<vector<vector<vector2D>>> transfered_foreground_objects;
//vector<vector<vector5D>> foreground_objects;
//vector<map<int, vector<int>>> foreground_objects;
vector<vector5D> current_selection;
map<int, vector<int>, greater<int>> current_contour;
ImageInfo ii;
int last_x,last_y;
int start_x, start_y;
/* OpenGL関係の変数 */
//unsigned char * global_data;
int global_width, global_height;
int main_window;
GLUI *glui;
int wireframe = 0;
int segments = 8;
GLuint loadTexture(const char * filename)
{
GLuint texture = 0;
cv::Mat tmp = cv::imread(filename);
cv::Mat inputImage;
cv::flip(tmp, inputImage, 0);
ii.originalImage = inputImage.clone();
ii.background = ii.originalImage.clone();
ii.targetMask.create(ii.originalImage.size(), CV_8UC1);
ii.targetMask.setTo(0);
ii.sourceMask.create(ii.originalImage.size(), CV_8UC1);
ii.sourceMask.setTo(0);
global_width = ii.originalImage.cols;
global_height = ii.originalImage.rows;
return texture;
}
// 推定された頂点のスクリーン座標の取得
void getEstimatedVerticesScreenCoordinates(void)
{
int i;
for (i = 0; i<4; i++){
gradient[i] = (ctrlPoint[i + 1].sy - ctrlPoint[0].sy) / (ctrlPoint[i + 1].sx - ctrlPoint[0].sx);
}
// 消失点(0)
estimatedVertex[0].sx = ctrlPoint[0].sx;
estimatedVertex[0].sy = ctrlPoint[0].sy;
// インナーレクタングルの頂点(1, 2, 8, 7)
// 左下(1)
estimatedVertex[1].sx = ctrlPoint[1].sx;
estimatedVertex[1].sy = ctrlPoint[1].sy;
// 右下(2)
estimatedVertex[2].sx = ctrlPoint[2].sx;
estimatedVertex[2].sy = ctrlPoint[2].sy;
// 右上(8)
estimatedVertex[8].sx = ctrlPoint[3].sx;
estimatedVertex[8].sy = ctrlPoint[3].sy;
// 左上(7)
estimatedVertex[7].sx = ctrlPoint[4].sx;
estimatedVertex[7].sy = ctrlPoint[4].sy;
// (3, 5)
estimatedVertex[3].sx = -(ctrlPoint[0].sy + 1.0) / gradient[0] + ctrlPoint[0].sx;
estimatedVertex[3].sy = -1.0;
estimatedVertex[5].sx = -1.0;
estimatedVertex[5].sy = (-1.0 - ctrlPoint[0].sx)*gradient[0] + ctrlPoint[0].sy;
// (4, 6)
estimatedVertex[4].sx = (-1.0f - ctrlPoint[0].sy) / gradient[1] + ctrlPoint[0].sx;
estimatedVertex[4].sy = -1.0f;
estimatedVertex[6].sx = 1.0f;
estimatedVertex[6].sy = (1.0f - ctrlPoint[0].sx)*gradient[1] + ctrlPoint[0].sy;
// (10, 12)
estimatedVertex[10].sx = (1.0f - ctrlPoint[0].sy) / gradient[2] + ctrlPoint[0].sx;
estimatedVertex[10].sy = 1.0f;
estimatedVertex[12].sx = 1.0f;
estimatedVertex[12].sy = (1.0f - ctrlPoint[0].sx)*gradient[2] + ctrlPoint[0].sy;
// (9, 11)
estimatedVertex[9].sx = (1.0f - ctrlPoint[0].sy) / gradient[3] + ctrlPoint[0].sx;
estimatedVertex[9].sy = 1.0f;
estimatedVertex[11].sx = -1.0f;
estimatedVertex[11].sy = (-1.0f - ctrlPoint[0].sx)*gradient[3] + ctrlPoint[0].sy;
}
// 推定された頂点のワールド座標の取得
void getEstimatedVerticesWorldCoordinates()
{
float grad; // 傾き
float height; // 直方体の高さ
// 視点のワールド座標の取得
// (視点と消失点を結ぶ直線はスクリーン(z=-1.0f)に垂直である)
eye.x = ctrlPoint[0].sx; eye.y = ctrlPoint[0].sy; eye.z = 0.0f;
//printf("eye: %12f %12f %12f\n",eye.x,eye.y,eye.z);
// floor上(y=0.0f)の推定された頂点(1, 2, 3, 4, 5, 6)のワールド座標の取得
for (int i = 1; i <= 6; i++)
{
grad = -(1.0+eye.y) / (estimatedVertex[i].sy - eye.y);
estimatedVertex[i].x = grad * (estimatedVertex[i].sx - eye.x) + eye.x;
estimatedVertex[i].z = grad * (-1.0f - eye.z) + eye.z;
estimatedVertex[i].y = -1.0f;
}
// 消失点(注視点)のワールド座標の取得
estimatedVertex[0].x = ctrlPoint[0].sx;
estimatedVertex[0].y = ctrlPoint[0].sy;
estimatedVertex[0].z = estimatedVertex[1].z;
// 視点と消失点(注視点)との距離
R = R0 = -estimatedVertex[0].z;
// 直方体の高さの取得
height = (estimatedVertex[7].sy - estimatedVertex[1].sy) / (-1.0f)*estimatedVertex[1].z;
// rear wall上の推定された頂点(7,8)のワールド座標の取得
estimatedVertex[7].x = estimatedVertex[1].x; estimatedVertex[8].x = estimatedVertex[2].x;
estimatedVertex[7].y = estimatedVertex[8].y = height -1.0;
estimatedVertex[7].z = estimatedVertex[1].z; estimatedVertex[8].z = estimatedVertex[2].z;
// ceiling上の推定された頂点(9, 10, 11, 12)のワールド座標の取得
for (int i = 9; i <= 12; i++)
{
grad = (height - eye.y - 1.0) / (estimatedVertex[i].sy - eye.y);
estimatedVertex[i].x = grad * (estimatedVertex[i].sx - eye.x) + eye.x;
estimatedVertex[i].z = grad * (-1.0f - eye.z) + eye.z;
estimatedVertex[i].y = height - 1.0;
}
//for foreground objs
for(int i = 0; i < (int)foreground_objects.size(); i++){
//vector<vector<vector5D>>::iterator iter = foreground_objects[i].begin();
float ground = foreground_objects[i][0][0].sy;
grad = -(1.0+eye.y) / (ground - eye.y);
float z = grad * (-1.0f - eye.z) + eye.z;
for(int j = 0; j < (int)foreground_objects[i].size(); j++){
for(int k = 0; k < (int)foreground_objects[i][j].size(); k++){
height = (foreground_objects[i][j][k].sy - ground) / (-1.0)*z;
grad = (height - eye.y - 1.0) / (foreground_objects[i][j][k].sy - eye.y);
foreground_objects[i][j][k].x = grad * (foreground_objects[i][j][k].sx - eye.x) + eye.x;
foreground_objects[i][j][k].z = grad * (-1.0f - eye.z) + eye.z;
foreground_objects[i][j][k].y = height - 1.0;
}
}
}
// 透視変換の整合性のための変数の取得
oevminx = 0.0f, oevmaxx = 0.0f, oevminy = 0.0f, oevmaxy = 0.0f; //oevdiffx, oevdiffy;
for(int i=1;i<=12;i++)
{
if(estimatedVertex[i].sx<oevminx) oevminx=estimatedVertex[i].sx;
else if(estimatedVertex[i].sx>oevmaxx) oevmaxx=estimatedVertex[i].sx;
if(estimatedVertex[i].sy<oevminy) oevminy=estimatedVertex[i].sy;
else if(estimatedVertex[i].sy>oevmaxy) oevmaxy=estimatedVertex[i].sy;
}
oevdiffx = oevmaxx - oevminx; oevdiffy = oevmaxy - oevminy;
}
// 視点と透視変換行列の取得
void getPerspectiveTransferMatrix(void)
{
float st, ct, sp, cp;
st = (float)sin(theta); ct = (float)cos(theta);
sp = (float)sin(phi); cp = (float)cos(phi);
// 視点のワールド座標の取得
eye.x = R * st*cp + estimatedVertex[0].x;
eye.y = R * sp + estimatedVertex[0].y;
eye.z = R * ct*cp + estimatedVertex[0].z;
// 透視変換行列の取得
mat[0] = ct; mat[1] = st * sp; mat[2] = -st * cp;
mat[3] = 0.0f; mat[4] = cp; mat[5] = sp;
mat[6] = st; mat[7] = -ct * sp; mat[8] = ct * cp;
}
// 透視変換後の推定された頂点のスクリーン座標の取得
void getTransferedEstimatedVerticesScreenCoordinates(void)
{
int i;
struct vector3D inte;
struct vector3D diff;
for (i = 1; i <= 12; i++)
{
diff.x = estimatedVertex[i].x - estimatedVertex[0].x;
diff.y = estimatedVertex[i].y - estimatedVertex[0].y;
diff.z = estimatedVertex[i].z - estimatedVertex[0].z;
inte.x = diff.x*mat[0] + diff.y*mat[3] + diff.z*mat[6];
inte.y = diff.x*mat[1] + diff.y*mat[4] + diff.z*mat[7];
inte.z = diff.x*mat[2] + diff.y*mat[5] + diff.z*mat[8];
transferedEstimatedVertex[i].sx = R * inte.x / (R - inte.z);
transferedEstimatedVertex[i].sy = R * inte.y / (R - inte.z);
}
transferedEstimatedVertex[8].sy = 1.0;
transferedEstimatedVertex[7].sy = 1.0;
for(int i = 0; i < (int)foreground_objects.size(); i++){
for(int j = 0; j < (int)foreground_objects[i].size(); j++){
for(int k = 0; k < (int)foreground_objects[i][j].size(); k++){
diff.x = foreground_objects[i][j][k].x - estimatedVertex[0].x;
diff.y = foreground_objects[i][j][k].y - estimatedVertex[0].y;
diff.z = foreground_objects[i][j][k].z - estimatedVertex[0].z;
inte.x = diff.x*mat[0] + diff.y*mat[3] + diff.z*mat[6];
inte.y = diff.x*mat[1] + diff.y*mat[4] + diff.z*mat[7];
inte.z = diff.x*mat[2] + diff.y*mat[5] + diff.z*mat[8];
transfered_foreground_objects[i][j][k].sx = R * inte.x / (R - inte.z);
transfered_foreground_objects[i][j][k].sy = R * inte.y / (R - inte.z);
}
}
}
// 透視変換の整合性のための変数の取得
tevminx = 1.0f, tevmaxx = -1.0f, tevminy = 1.0f, tevmaxy = -1.0f; //tevdiffx, tevdiffy;
for (i = 1; i <= 12; i++)
{
if(transferedEstimatedVertex[i].sx<tevminx) tevminx=transferedEstimatedVertex[i].sx;
else if(transferedEstimatedVertex[i].sx>tevmaxx) tevmaxx=transferedEstimatedVertex[i].sx;
if(transferedEstimatedVertex[i].sy<tevminy) tevminy=transferedEstimatedVertex[i].sy;
else if(transferedEstimatedVertex[i].sy>tevmaxy) tevmaxy=transferedEstimatedVertex[i].sy;
}
tevdiffx = tevmaxx - tevminx; tevdiffy = tevmaxy - tevminy;
if (deduceFlag != 1)
{
tevminx0 = 1.0f, tevmaxx0 = -1.0f, tevminy0 = 1.0f, tevmaxy0 = -1.0f; //tevdiffx0, tevdiffy0;
for (i = 1; i <= 12; i++)
{
if(transferedEstimatedVertex[i].sx<tevminx0) tevminx0=transferedEstimatedVertex[i].sx;
else if(transferedEstimatedVertex[i].sx>tevmaxx0) tevmaxx0=transferedEstimatedVertex[i].sx;
if(transferedEstimatedVertex[i].sy<tevminy0) tevminy0=transferedEstimatedVertex[i].sy;
else if(transferedEstimatedVertex[i].sy>tevmaxy0) tevmaxy0=transferedEstimatedVertex[i].sy;
}
tevdiffx0 = tevmaxx0 - tevminx0; tevdiffy0 = tevmaxy0 - tevminy0;
}
// 透視変換の整合
for (i = 1; i <= 12; i++)
{
transferedEstimatedVertex[i].sx = (transferedEstimatedVertex[i].sx - tevminx) / tevdiffx;
transferedEstimatedVertex[i].sy = (transferedEstimatedVertex[i].sy - tevminy) / tevdiffy;
transferedEstimatedVertex[i].sx *= oevdiffx; transferedEstimatedVertex[i].sy *= oevdiffy;
transferedEstimatedVertex[i].sx += oevminx; transferedEstimatedVertex[i].sy += oevminy;
}
for(int i = 0; i < (int)foreground_objects.size(); i++){
for(int j = 0; j < (int)foreground_objects[i].size(); j++){
for(int k = 0; k < (int)foreground_objects[i][j].size(); k++){
transfered_foreground_objects[i][j][k].sx = (transfered_foreground_objects[i][j][k].sx - tevminx) / tevdiffx;
transfered_foreground_objects[i][j][k].sy = (transfered_foreground_objects[i][j][k].sy - tevminy) / tevdiffy;
transfered_foreground_objects[i][j][k].sx *= oevdiffx; transfered_foreground_objects[i][j][k].sy *= oevdiffy;
transfered_foreground_objects[i][j][k].sx += oevminx; transfered_foreground_objects[i][j][k].sy += oevminy;
}
}
}
}
// スクリーン座標の取得
vector2D getScreenCoordinates(struct vector3D input)
{
struct vector3D inte;
struct vector3D diff;
struct vector2D output;
diff.x = input.x - estimatedVertex[0].x; diff.y = input.y - estimatedVertex[0].y; diff.z = input.z - estimatedVertex[0].z;
inte.x = diff.x*mat[0] + diff.y*mat[3] + diff.z*mat[6];
inte.y = diff.x*mat[1] + diff.y*mat[4] + diff.z*mat[7];
inte.z = diff.x*mat[2] + diff.y*mat[5] + diff.z*mat[8];
output.sx = R * inte.x / (R - inte.z); output.sy = R * inte.y / (R - inte.z);
output.sx = (output.sx - tevminx) / tevdiffx; output.sy = (output.sy - tevminy) / tevdiffy;
output.sx *= oevdiffx; output.sy *= oevdiffy; output.sx += oevminx; output.sy += oevminy;
return output;
}
// 変形前のスクリーン座標の取得
vector2D getInitialScreenCoordinates(struct vector3D input)
{
struct vector3D inte;
struct vector3D diff;
struct vector2D output;
float st, ct, sp, cp;
float inv[9];
st = 0.0f; ct = 1.0f;
sp = 0.0f; cp = 1.0f;
// 視点のワールド座標の取得
eye.x = R * st*cp + estimatedVertex[0].x;
eye.y = R * sp + estimatedVertex[0].y;
eye.z = R * ct*cp + estimatedVertex[0].z;
// 透視変換行列の取得
inv[0] = ct; inv[1] = st * sp; inv[2] = -st * cp;
inv[3] = 0.0f; inv[4] = cp; inv[5] = sp;
inv[6] = st; inv[7] = -ct * sp; inv[8] = ct * cp;
diff.x = input.x - estimatedVertex[0].x; diff.y = input.y - estimatedVertex[0].y; diff.z = input.z - estimatedVertex[0].z;
inte.x = diff.x*inv[0] + diff.y*inv[3] + diff.z*inv[6];
inte.y = diff.x*inv[1] + diff.y*inv[4] + diff.z*inv[7];
inte.z = diff.x*inv[2] + diff.y*inv[5] + diff.z*inv[8];
output.sx = R * inte.x / (R - inte.z); output.sy = R * inte.y / (R - inte.z);
output.sx = (output.sx - tevminx0) / tevdiffx0; output.sy = (output.sy - tevminy0) / tevdiffy0;
output.sx *= oevdiffx; output.sy *= oevdiffy; output.sx += oevminx; output.sy += oevminy;
return output;
}
// スパイダリーメッシュの描画
void drawSpideryMesh()
{
glColor3f(0.0f, 0.2f, 1.0f);
glLineWidth(3.0f);
glBegin(GL_LINE_LOOP);
// floor(1, 2, 4, 3)
glVertex2f(estimatedVertex[1].sx, estimatedVertex[1].sy);
glVertex2f(estimatedVertex[2].sx, estimatedVertex[2].sy);
glVertex2f(estimatedVertex[4].sx, estimatedVertex[4].sy);
glVertex2f(estimatedVertex[3].sx, estimatedVertex[3].sy);
glEnd();
glBegin(GL_LINE_LOOP);
// ceiling (7, 9, 10, 8)
glVertex2f(estimatedVertex[7].sx, estimatedVertex[7].sy);
glVertex2f(estimatedVertex[9].sx, estimatedVertex[9].sy);
glVertex2f(estimatedVertex[10].sx, estimatedVertex[10].sy);
glVertex2f(estimatedVertex[8].sx, estimatedVertex[8].sy);
glEnd();
glBegin(GL_LINE_LOOP);
// left wall(1, 7, 11, 5)
glVertex2f(estimatedVertex[1].sx, estimatedVertex[1].sy);
glVertex2f(estimatedVertex[7].sx, estimatedVertex[7].sy);
glVertex2f(estimatedVertex[11].sx, estimatedVertex[11].sy);
glVertex2f(estimatedVertex[5].sx, estimatedVertex[5].sy);
glEnd();
glBegin(GL_LINE_LOOP);
// right wall(2, 8, 12, 6)
glVertex2f(estimatedVertex[2].sx, estimatedVertex[2].sy);
glVertex2f(estimatedVertex[8].sx, estimatedVertex[8].sy);
glVertex2f(estimatedVertex[12].sx, estimatedVertex[12].sy);
glVertex2f(estimatedVertex[6].sx, estimatedVertex[6].sy);
glEnd();
glLineWidth(2.5f);
glBegin(GL_LINES);
// rear wall (0, 1, 0, 2, 0, 8, 0, 7)
glVertex2f(estimatedVertex[0].sx, estimatedVertex[0].sy);
glVertex2f(estimatedVertex[1].sx, estimatedVertex[1].sy);
glVertex2f(estimatedVertex[0].sx, estimatedVertex[0].sy);
glVertex2f(estimatedVertex[2].sx, estimatedVertex[2].sy);
glVertex2f(estimatedVertex[0].sx, estimatedVertex[0].sy);
glVertex2f(estimatedVertex[8].sx, estimatedVertex[8].sy);
glVertex2f(estimatedVertex[0].sx, estimatedVertex[0].sy);
glVertex2f(estimatedVertex[7].sx, estimatedVertex[7].sy);
glEnd();
glColor3f(0.0f, 1.0f, 0.2f);
glPointSize(3.0f);
glBegin(GL_POINTS);
// control points(0, 1, 2, 7, 8)
glVertex2f(estimatedVertex[0].sx, estimatedVertex[0].sy);
glVertex2f(estimatedVertex[1].sx, estimatedVertex[1].sy);
glVertex2f(estimatedVertex[2].sx, estimatedVertex[2].sy);
glVertex2f(estimatedVertex[7].sx, estimatedVertex[7].sy);
glVertex2f(estimatedVertex[8].sx, estimatedVertex[8].sy);
glEnd();
glColor3f(1.0,1.0,1.0);
}
// 3次元背景の描画
void draw3Dbackground(void)
{
float k;
struct vector3D begin, end;
struct vector2D bpoint, epoint;
const float span = 0.1f;
glColor3f(0.0f, 0.2f, 1.0f);
/* boundary */
glLineWidth(2.0f);
glBegin(GL_LINE_LOOP);
// floor(1, 2, 4, 3)
glVertex2f(transferedEstimatedVertex[1].sx, transferedEstimatedVertex[1].sy);
glVertex2f(transferedEstimatedVertex[2].sx, transferedEstimatedVertex[2].sy);
glVertex2f(transferedEstimatedVertex[4].sx, transferedEstimatedVertex[4].sy);
glVertex2f(transferedEstimatedVertex[3].sx, transferedEstimatedVertex[3].sy);
glEnd();
glBegin(GL_LINE_LOOP);
// ceiling (7, 9, 10, 8)
glVertex2f(transferedEstimatedVertex[7].sx, transferedEstimatedVertex[7].sy);
glVertex2f(transferedEstimatedVertex[9].sx, transferedEstimatedVertex[9].sy);
glVertex2f(transferedEstimatedVertex[10].sx, transferedEstimatedVertex[10].sy);
glVertex2f(transferedEstimatedVertex[8].sx, transferedEstimatedVertex[8].sy);
glEnd();
glBegin(GL_LINE_LOOP);
// left wall(1, 7, 11, 5)
glVertex2f(transferedEstimatedVertex[1].sx, transferedEstimatedVertex[1].sy);
glVertex2f(transferedEstimatedVertex[7].sx, transferedEstimatedVertex[7].sy);
glVertex2f(transferedEstimatedVertex[11].sx, transferedEstimatedVertex[11].sy);
glVertex2f(transferedEstimatedVertex[5].sx, transferedEstimatedVertex[5].sy);
glEnd();
glBegin(GL_LINE_LOOP);
// right wall(2, 8, 12, 6)
glVertex2f(transferedEstimatedVertex[2].sx, transferedEstimatedVertex[2].sy);
glVertex2f(transferedEstimatedVertex[8].sx, transferedEstimatedVertex[8].sy);
glVertex2f(transferedEstimatedVertex[12].sx, transferedEstimatedVertex[12].sy);
glVertex2f(transferedEstimatedVertex[6].sx, transferedEstimatedVertex[6].sy);
glEnd();
/* mesh */
glLineWidth(1.0f);
glBegin(GL_LINES);
// floor横線(z: 1~3)
begin.x = estimatedVertex[1].x; end.x = estimatedVertex[2].x;
begin.y = end.y = estimatedVertex[1].y;
for (k = estimatedVertex[1].z; k <= estimatedVertex[3].z; k += span)
{
begin.z = end.z = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// floor縦線(x: 1~2)
begin.y = end.y = estimatedVertex[1].y;
begin.z = estimatedVertex[1].z; end.z = estimatedVertex[3].z;
for (k = estimatedVertex[1].x; k <= estimatedVertex[2].x; k += span)
{
begin.x = end.x = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// ceiling横線(z: 7~9)
begin.x = estimatedVertex[7].x; end.x = estimatedVertex[8].x;
begin.y = end.y = estimatedVertex[7].y;
for (k = estimatedVertex[7].z; k <= estimatedVertex[9].z; k += span)
{
begin.z = end.z = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// ceiling縦線(x: 7~8)
begin.y = end.y = estimatedVertex[7].y;
begin.z = estimatedVertex[7].z; end.z = estimatedVertex[9].z;
for (k = estimatedVertex[7].x; k <= estimatedVertex[8].x; k += span)
{
begin.x = end.x = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// left wall横線(y: 1~7)
begin.x = end.x = estimatedVertex[1].x;
begin.z = estimatedVertex[1].z; end.z = estimatedVertex[5].z;
for (k = estimatedVertex[1].y; k <= estimatedVertex[7].y; k += span)
{
begin.y = end.y = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
glEnd();
// left wall縦線(z: 1~5)
begin.x = end.x = estimatedVertex[1].x;
begin.y = estimatedVertex[1].y; end.y = estimatedVertex[7].y;
glBegin(GL_LINES);
for (k = estimatedVertex[1].z; k <= estimatedVertex[5].z; k += span)
{
begin.z = end.z = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// right wall横線(y: 2~8)
begin.x = end.x = estimatedVertex[2].x;
begin.z = estimatedVertex[2].z; end.z = estimatedVertex[6].z;
for (k = estimatedVertex[2].y; k <= estimatedVertex[8].y; k += span)
{
begin.y = end.y = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// right wall縦線(z: 2~6)
begin.x = end.x = estimatedVertex[2].x;
begin.y = estimatedVertex[2].y; end.y = estimatedVertex[8].y;
for (k = estimatedVertex[2].z; k <= estimatedVertex[6].z; k += span)
{
begin.z = end.z = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// rear wall横線(y: 1~7)
begin.x = estimatedVertex[1].x; end.x = estimatedVertex[2].x;
begin.z = end.z = estimatedVertex[1].z;
for (k = estimatedVertex[1].y; k <= estimatedVertex[7].y; k += span)
{
begin.y = end.y = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
// rear wall縦線(x: 1~2)
begin.y = estimatedVertex[1].y; end.y = estimatedVertex[7].y;
begin.z = end.z = estimatedVertex[1].z;
for (k = estimatedVertex[1].x; k <= estimatedVertex[2].x; k += span)
{
begin.x = end.x = k;
bpoint = getScreenCoordinates(begin); epoint = getScreenCoordinates(end);
glVertex2f(bpoint.sx, bpoint.sy);
glVertex2f(epoint.sx, epoint.sy);
}
glEnd();
glColor3f(1.0,1.0,1.0);
}
// 元画像の引数のスクリーン座標の色を返す関数
color3D screenCoordinates2sourceImageColor(vector2D input, bool is_bg)
{
color3D output;
int x, y; // 画像スケールでのx, y座標
//int headindex; // x, y座標のピクセルの色情報の先頭(赤)のインデックス
if (input.sx<-1.0f) output.r = output.g = output.b = 1.0f;
else if (input.sx>1.0f) output.r = output.g = output.b = 1.0f;
else if (input.sy<-1.0f) output.r = output.g = output.b = 1.0f;
else if (input.sy>1.0f) output.r = output.g = output.b = 1.0f;
else
{
// 画像スケールでのx, y座標の取得
x = (int)((input.sx+1)*global_width/2.0); y = (int)((input.sy+1)*global_height/2.0);
// x, y座標のピクセルの色情報の先頭(赤)のインデックスの取得
// 色の取
cv::Vec3b intensity;
if(is_bg)
intensity = ii.background.at<cv::Vec3b>(y, x);
else
intensity = ii.originalImage.at<cv::Vec3b>(y, x);
output.b = intensity.val[0] / 255.0;
output.g = intensity.val[1] / 255.0;
output.r = intensity.val[2] / 255.0;
}
return output;
}
// 生成画像の描画
void drawGeneratedImage()
{
int i;
float k,l;
struct vector3D worldVertex[4];
struct vector2D screenVertex[4];
struct vector3D worldGravityPoint;
struct vector2D screenGravityPoint;
struct color3D colorGravityPoint;
glDisable(GL_TEXTURE_2D);
glPolygonMode(GL_FRONT,GL_FILL); // CCWに塗りつぶし
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glBegin(GL_QUADS);
// floor(z: 1~3, x: 1~2)
worldVertex[0].y=worldVertex[1].y=worldVertex[2].y=worldVertex[3].y=estimatedVertex[1].y;
for(k=estimatedVertex[1].z;k<estimatedVertex[3].z;k+=rough_coefficient)
{
worldVertex[0].z=worldVertex[3].z=k;
worldVertex[1].z=worldVertex[2].z=k+rough_coefficient;
for(l=estimatedVertex[1].x;l<estimatedVertex[2].x;l+=rough_coefficient)
{
worldVertex[0].x=worldVertex[1].x=l;
worldVertex[2].x=worldVertex[3].x=l+rough_coefficient;
// 共通処理
// メッシュの各頂点の変形後のスクリーン座標の取得
for(i=0;i<4;i++) screenVertex[i]=getScreenCoordinates(worldVertex[i]);
// メッシュの重心のワールド座標の取得
worldGravityPoint.x=(worldVertex[0].x+worldVertex[2].x)/2.0f;
worldGravityPoint.y=(worldVertex[0].y+worldVertex[2].y)/2.0f;
worldGravityPoint.z=(worldVertex[0].z+worldVertex[2].z)/2.0f;
// メッシュの重心の変形前のスクリーン座標の取得
screenGravityPoint=getInitialScreenCoordinates(worldGravityPoint);
// メッシュの重心の変形前のスクリーン座標における元画像の色の取得
colorGravityPoint=screenCoordinates2sourceImageColor(screenGravityPoint, true);
glColor3f(colorGravityPoint.r,colorGravityPoint.g,colorGravityPoint.b);
// メッシュを重心の変形前のスクリーン座標における元画像の色で塗りつぶし
for(i=0;i<4;i++)glVertex2f(screenVertex[i].sx,screenVertex[i].sy);
}
}
// ceiling(z: 7~9, x: 7~8)
worldVertex[0].y=worldVertex[1].y=worldVertex[2].y=worldVertex[3].y=estimatedVertex[7].y;
for(k=estimatedVertex[7].z;k<estimatedVertex[9].z;k+=rough_coefficient)
{
worldVertex[0].z=worldVertex[1].z=k;
worldVertex[2].z=worldVertex[3].z=k+rough_coefficient;
for(l=estimatedVertex[7].x;l<estimatedVertex[8].x;l+=rough_coefficient)
{
worldVertex[0].x=worldVertex[3].x=l;
worldVertex[1].x=worldVertex[2].x=l+rough_coefficient;
// 共通処理
// メッシュの各頂点の変形後のスクリーン座標の取得
for(i=0;i<4;i++) screenVertex[i]=getScreenCoordinates(worldVertex[i]);
// メッシュの重心のワールド座標の取得
worldGravityPoint.x=(worldVertex[0].x+worldVertex[2].x)/2.0f;
worldGravityPoint.y=(worldVertex[0].y+worldVertex[2].y)/2.0f;
worldGravityPoint.z=(worldVertex[0].z+worldVertex[2].z)/2.0f;
// メッシュの重心の変形前のスクリーン座標の取得
screenGravityPoint=getInitialScreenCoordinates(worldGravityPoint);
// メッシュの重心の変形前のスクリーン座標における元画像の色の取得
colorGravityPoint=screenCoordinates2sourceImageColor(screenGravityPoint, true);
glColor3f(colorGravityPoint.r,colorGravityPoint.g,colorGravityPoint.b);
// メッシュを重心の変形前のスクリーン座標における元画像の色で塗りつぶし
for(i=0;i<4;i++)glVertex2f(screenVertex[i].sx,screenVertex[i].sy);
}
}
// left wall(y: 1~7, z: 1~5)
worldVertex[0].x=worldVertex[1].x=worldVertex[2].x=worldVertex[3].x=estimatedVertex[1].x;
for(k=estimatedVertex[1].y;k<estimatedVertex[7].y;k+=rough_coefficient)
{
worldVertex[0].y=worldVertex[3].y=k;
worldVertex[1].y=worldVertex[2].y=k+rough_coefficient;
for(l=estimatedVertex[1].z;l<estimatedVertex[5].z;l+=rough_coefficient)
{
worldVertex[0].z=worldVertex[1].z=l;
worldVertex[2].z=worldVertex[3].z=l+rough_coefficient;
// 共通処理
// メッシュの各頂点の変形後のスクリーン座標の取得
for(i=0;i<4;i++) screenVertex[i]=getScreenCoordinates(worldVertex[i]);
// メッシュの重心のワールド座標の取得
worldGravityPoint.x=(worldVertex[0].x+worldVertex[2].x)/2.0f;
worldGravityPoint.y=(worldVertex[0].y+worldVertex[2].y)/2.0f;
worldGravityPoint.z=(worldVertex[0].z+worldVertex[2].z)/2.0f;
// メッシュの重心の変形前のスクリーン座標の取得
screenGravityPoint=getInitialScreenCoordinates(worldGravityPoint);
// メッシュの重心の変形前のスクリーン座標における元画像の色の取得
colorGravityPoint=screenCoordinates2sourceImageColor(screenGravityPoint, true);
glColor3f(colorGravityPoint.r,colorGravityPoint.g,colorGravityPoint.b);
// メッシュを重心の変形前のスクリーン座標における元画像の色で塗りつぶし
for(i=0;i<4;i++)glVertex2f(screenVertex[i].sx,screenVertex[i].sy);
}
}
// right wall(y: 2~8, z: 2~6)
worldVertex[0].x=worldVertex[1].x=worldVertex[2].x=worldVertex[3].x=estimatedVertex[2].x;
for(k=estimatedVertex[2].y;k<estimatedVertex[8].y;k+=rough_coefficient)
{
worldVertex[0].y=worldVertex[1].y=k;
worldVertex[2].y=worldVertex[3].y=k+rough_coefficient;
for(l=estimatedVertex[2].z;l<estimatedVertex[6].z;l+=rough_coefficient)
{
worldVertex[0].z=worldVertex[3].z=l;
worldVertex[1].z=worldVertex[2].z=l+rough_coefficient;
// 共通処理
// メッシュの各頂点の変形後のスクリーン座標の取得
for(i=0;i<4;i++) screenVertex[i]=getScreenCoordinates(worldVertex[i]);
// メッシュの重心のワールド座標の取得
worldGravityPoint.x=(worldVertex[0].x+worldVertex[2].x)/2.0f;
worldGravityPoint.y=(worldVertex[0].y+worldVertex[2].y)/2.0f;
worldGravityPoint.z=(worldVertex[0].z+worldVertex[2].z)/2.0f;
// メッシュの重心の変形前のスクリーン座標の取得
screenGravityPoint=getInitialScreenCoordinates(worldGravityPoint);
// メッシュの重心の変形前のスクリーン座標における元画像の色の取得
colorGravityPoint=screenCoordinates2sourceImageColor(screenGravityPoint, true);
glColor3f(colorGravityPoint.r,colorGravityPoint.g,colorGravityPoint.b);
// メッシュを重心の変形前のスクリーン座標における元画像の色で塗りつぶし
for(i=0;i<4;i++)glVertex2f(screenVertex[i].sx,screenVertex[i].sy);
}
}
// rear wall(y: 1~7, x: 1~2)
worldVertex[0].z=worldVertex[1].z=worldVertex[2].z=worldVertex[3].z=estimatedVertex[1].z;
for(k=estimatedVertex[1].y;k<estimatedVertex[7].y;k+=rough_coefficient)
{
worldVertex[0].y=worldVertex[1].y=k;
worldVertex[2].y=worldVertex[3].y=k+rough_coefficient;
for(l=estimatedVertex[1].x;l<estimatedVertex[2].x;l+=rough_coefficient)
{
worldVertex[0].x=worldVertex[3].x=l;
worldVertex[1].x=worldVertex[2].x=l+rough_coefficient;
// 共通処理
// メッシュの各頂点の変形後のスクリーン座標の取得
for(i=0;i<4;i++) screenVertex[i]=getScreenCoordinates(worldVertex[i]);
// メッシュの重心のワールド座標の取得
worldGravityPoint.x=(worldVertex[0].x+worldVertex[2].x)/2.0f;
worldGravityPoint.y=(worldVertex[0].y+worldVertex[2].y)/2.0f;
worldGravityPoint.z=(worldVertex[0].z+worldVertex[2].z)/2.0f;
// メッシュの重心の変形前のスクリーン座標の取得
screenGravityPoint=getInitialScreenCoordinates(worldGravityPoint);
// メッシュの重心の変形前のスクリーン座標における元画像の色の取得
colorGravityPoint=screenCoordinates2sourceImageColor(screenGravityPoint, true);
glColor3f(colorGravityPoint.r,colorGravityPoint.g,colorGravityPoint.b);
// メッシュを重心の変形前のスクリーン座標における元画像の色で塗りつぶし
for(i=0;i<4;i++)glVertex2f(screenVertex[i].sx,screenVertex[i].sy);
}
}
/////////foreground obj
for(int m = 0; m < (int)foreground_objects.size(); m++){
worldVertex[0].z=worldVertex[1].z=worldVertex[2].z=worldVertex[3].z=foreground_objects[m][0][0].z;
for(int n = 0; n < (int)foreground_objects[m].size() - 1; n++){
for(k=foreground_objects[m][n][0].y;k<foreground_objects[m][n+1][0].y;k+=rough_coefficient)
{
worldVertex[0].y=worldVertex[1].y=k;
worldVertex[2].y=worldVertex[3].y=k+rough_coefficient;
for(int q = 0; q < (int)foreground_objects[m][n].size(); q += 2){
for(l=foreground_objects[m][n][q].x;l<foreground_objects[m][n][q+1].x;l+=rough_coefficient)
{
worldVertex[0].x=worldVertex[3].x=l;
worldVertex[1].x=worldVertex[2].x=l+rough_coefficient;
// 共通処理
// メッシュの各頂点の変形後のスクリーン座標の取得
for(i=0;i<4;i++) screenVertex[i]=getScreenCoordinates(worldVertex[i]);
// メッシュの重心のワールド座標の取得
worldGravityPoint.x=(worldVertex[0].x+worldVertex[2].x)/2.0f;
worldGravityPoint.y=(worldVertex[0].y+worldVertex[2].y)/2.0f;
worldGravityPoint.z=(worldVertex[0].z+worldVertex[2].z)/2.0f;
// メッシュの重心の変形前のスクリーン座標の取得
screenGravityPoint=getInitialScreenCoordinates(worldGravityPoint);
// メッシュの重心の変形前のスクリーン座標における元画像の色の取得
colorGravityPoint=screenCoordinates2sourceImageColor(screenGravityPoint, false);
glColor3f(colorGravityPoint.r,colorGravityPoint.g,colorGravityPoint.b);
// メッシュを重心の変形前のスクリーン座標における元画像の色で塗りつぶし
for(i=0;i<4;i++)glVertex2f(screenVertex[i].sx,screenVertex[i].sy);
}
}
}
}
}
glEnd();
glDisable(GL_CULL_FACE);
glColor3f(1.0,1.0,1.0);
}
/////////fore ground/////////////
void drawSelectedObj(){
glColor3f(0.9,0.1,0.1);
glLineWidth(0.8);
//for(int i = 0; i < foreground_objects.size(); i++){
glBegin(GL_LINES);
int j = 0;
int l = current_selection.size();
for(; j < l-1; j++){
glVertex2f(current_selection[j].sx, current_selection[j].sy);
glVertex2f(current_selection[j+1].sx, current_selection[j+1].sy);
}
if(on_press == false && l > 0){
glVertex2f(current_selection[j].sx, current_selection[j].sy);
glVertex2f(current_selection[0].sx, current_selection[0].sy);
}
glEnd();
//}
glColor3f(1.0,1.0,1.0);
}
void drawTest(){
map<int,vector<int>, greater<int>>::iterator iter = current_contour.begin();
glColor3f(0.9,0.1,0.1);
glLineWidth(0.8);
float midx = global_width/2.0;
float midy = global_height/2.0;
glBegin(GL_LINES);
while(iter != current_contour.end()){
if(current_contour[iter->first].size() > 1){
if((current_contour[iter->first].size() & 1) != 0){
cout << "ERROR" << endl;
//break;
iter++;
continue;
}
for(int i = 0; i < (int)current_contour[iter->first].size(); i += 2){
glVertex2f(current_contour[iter->first][i]/midx - 1.0, 1.0 - (iter->first)/ midy);
glVertex2f(current_contour[iter->first][i+1]/ midx - 1.0, 1.0 - (iter->first)/ midy);
}
}
iter++;
}
glEnd();
glColor3f(1.0,1.0,1.0);
test_flag = false;
}
/////////////////////////////////
void myDisplay()
{
if (glutGetWindow() != main_window)glutSetWindow(main_window);
// バッファクリア
glClear(GL_COLOR_BUFFER_BIT);
// 元画像の描
if (deduceFlag == 0){
glRasterPos2i(0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2i(-1, -1);
glTexCoord2f(1.0f, 0.0f);
glVertex2i(1, -1);
glTexCoord2f(1.0f, 1.0f);
glVertex2i(1, 1);
glTexCoord2f(0.0f, 1.0f);
glVertex2i(-1, 1);
glEnd();
}
// スパイダリーメッシュの描画
if (deduceFlag == 0 && modenumber == 0) drawSpideryMesh();
// 生成画像の描画
//cout << modenumber << endl;
if(deduceFlag == 0 && modenumber == 1) drawSelectedObj();
if (deduceFlag) drawGeneratedImage();
//i 3次元背景の描画
if (deduceFlag && resolutionnumber == 0) draw3Dbackground();
// 画像の表示
if(test_flag) drawTest();
glutSwapBuffers();
}
void myIdle(void)
{
if (glutGetWindow() != main_window)glutSetWindow(main_window);
// 画像の表示
glutSwapBuffers();
}
void myReshape(int x, int y)
{
// ウィンドウサイズの変更
glutReshapeWindow(global_width, global_height);
glutPostRedisplay();
}
void myKeyboard(unsigned char key, int x, int y)
{
switch (key)
{
//case 27:
case 'q':
exit(0);
break;
if (deduceFlag){
// move forward
case 'w':
if(estimatedVertex[0].z < -1)
estimatedVertex[0].z += 0.01;
// 視点と透視変換行列の取得
getPerspectiveTransferMatrix();
// 透視変換後の推定された頂点のスクリーン座標の取得
getTransferedEstimatedVerticesScreenCoordinates();
//glutPostRedisplay();
break;
// move background
case 's':
estimatedVertex[0].z -= 0.01;
// 視点と透視変換行列の取得
getPerspectiveTransferMatrix();
// 透視変換後の推定された頂点のスクリーン座標の取得
getTransferedEstimatedVerticesScreenCoordinates();
//glutPostRedisplay();
break;
case 't':
test_flag= true;
//for (int i = 0; i < 50000; i++)
// global_data[i] = 0;
//glutPostRedisplay();
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, 100, 100, GL_RGB, GL_UNSIGNED_BYTE, global_data);
//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, global_width, global_height, 0, GL_BGR, GL_UNSIGNED_BYTE, global_data);
break;
}