Line data Source code
1 : #include "data_types.h"
2 : #include "str_and_math.h"
3 : #include "file_handler.h"
4 : #include "vrml_parser.h"
5 : #include <iostream>
6 :
7 : using namespace std;
8 :
9 :
10 : /*************************************************************************************/
11 :
12 : /*************************************************************************************/
13 :
14 :
15 0 : void set_node_id(void *node, int id)
16 : {
17 0 : Info **info = NULL;
18 :
19 0 : info = (Info **)node;
20 0 : if (info) {
21 0 : (*info)->id = id;
22 0 : }
23 0 : }
24 :
25 :
26 : /*************************************************************************************/
27 :
28 : /*************************************************************************************/
29 :
30 :
31 6 : void set_node_type(void *node, DataType type)
32 : {
33 :
34 6 : Info **info = NULL;
35 :
36 6 : info = (Info **)node;
37 6 : if (info) {
38 6 : (*info)->type = type;
39 6 : }
40 6 : }
41 :
42 :
43 : /*************************************************************************************/
44 :
45 : /*************************************************************************************/
46 :
47 :
48 0 : int get_node_id(void *node)
49 : {
50 0 : Info **info = NULL;
51 0 : int value = -1;
52 :
53 0 : info = (Info **)node;
54 0 : if (info) {
55 0 : value = (*info)->id;
56 0 : }
57 0 : return value;
58 : }
59 :
60 :
61 : /*************************************************************************************/
62 :
63 : /*************************************************************************************/
64 :
65 :
66 0 : DataType get_node_type(void *node)
67 : {
68 0 : Info **info = NULL;
69 0 : DataType value = UNKNOWN;
70 :
71 0 : info = (Info **)node;
72 0 : if (info) {
73 0 : value = (*info)->type;
74 0 : }
75 0 : return value;
76 : }
77 :
78 :
79 : /*************************************************************************************/
80 :
81 : /*************************************************************************************/
82 :
83 2430 : void check_def_tokn(string tokn)
84 : {
85 :
86 2430 : if (tokn.find("DEF") != string::npos) {
87 :
88 0 : gvar->def_flag = 1;
89 0 : gvar->def_tokn = get_tokn();
90 :
91 :
92 0 : }
93 :
94 : // unset the def flag when you find the first opening bracket "{"
95 2430 : if (gvar->def_flag && tokn.find("{") != string::npos) {
96 0 : gvar->def_flag = 0;
97 0 : gvar->def_tokn = "";
98 :
99 0 : }
100 :
101 2430 : }
102 :
103 : /*************************************************************************************/
104 :
105 : /*************************************************************************************/
106 :
107 :
108 2430 : void check_use_tokn(string tokn)
109 : {
110 :
111 2430 : if (gvar->use_flag) {
112 0 : gvar->use_flag = 0;
113 0 : gvar->use_tokn = "";
114 0 : }
115 :
116 2430 : if (tokn.find("USE") != string::npos) {
117 : // prosoxi i seira pou exoun oi netoles einai poli simantiki
118 0 : gvar->use_tokn = get_tokn();
119 0 : gvar->use_flag = 1;
120 0 : }
121 :
122 2430 : }
123 :
124 :
125 : /*************************************************************************************/
126 :
127 : /*************************************************************************************/
128 :
129 :
130 0 : void add_to_def(string tokn, Container *container)
131 : {
132 : // eukolaki vazeis sto map perneis apo to map
133 : // o kwdika tha mpei mesa stin get_tokn opote
134 : // den tha mplexoume me ta alla
135 : // prepei na kanw kai ta alla na epistrefoun container
136 : // episi na kanw kai to group
137 : // poly testing para poly :)
138 :
139 0 : if (gvar->def_map) {
140 0 : (*(gvar->def_map))[tokn] = container;
141 0 : }
142 0 : gvar->def_flag = 0;
143 0 : gvar->def_tokn = "";
144 0 : }
145 :
146 : /*************************************************************************************/
147 :
148 : /*************************************************************************************/
149 :
150 :
151 0 : void add_to_def_map(string tokn, void *data)
152 : {
153 : // eukolaki vazeis sto map perneis apo to map
154 : // o kwdika tha mpei mesa stin get_tokn opote
155 : // den tha mplexoume me ta alla
156 : // prepei na kanw kai ta alla na epistrefoun container
157 : // episi na kanw kai to group
158 : // poly testing para poly :)
159 :
160 0 : if (gvar->def_map2) {
161 0 : (*(gvar->def_map2))[tokn] = data;
162 0 : }
163 0 : gvar->def_flag = 0;
164 0 : gvar->def_tokn = "";
165 0 : }
166 :
167 :
168 : /*************************************************************************************/
169 :
170 : /*************************************************************************************/
171 :
172 :
173 0 : void* get_from_def(string tokn)
174 : {
175 : //otan epistrefo to grafo amesws sto frame mesw tis global var
176 0 : Container *container = NULL;
177 0 : map<string, Container *>::iterator it;
178 :
179 0 : if (gvar->def_map) {
180 0 : it = gvar->def_map->find(tokn);
181 0 : if (it != gvar->def_map->end()) {
182 0 : container = it->second;
183 0 : }
184 0 : }
185 0 : gvar->use_flag = 0;
186 :
187 0 : return container;
188 : }
189 :
190 : /*************************************************************************************/
191 :
192 : /*************************************************************************************/
193 :
194 3 : Container *new_container()
195 : {
196 3 : Container *container = NULL;
197 :
198 3 : container = new Container;
199 :
200 3 : return container;
201 : }
202 :
203 : /*************************************************************************************/
204 :
205 : /*************************************************************************************/
206 :
207 0 : void delete_container(Container *container)
208 : {
209 0 : delete container;
210 0 : }
211 :
212 : /*************************************************************************************/
213 :
214 : /*************************************************************************************/
215 :
216 0 : void set_container_type(Container *container, DataType type)
217 : {
218 0 : if (container) {
219 0 : container->type = type;
220 0 : }
221 0 : }
222 :
223 : /*************************************************************************************/
224 :
225 : /*************************************************************************************/
226 :
227 0 : void set_container_data(Container *container, void *data)
228 : {
229 0 : if (container) {
230 0 : container->data = data;
231 0 : }
232 0 : }
233 :
234 : /*************************************************************************************/
235 :
236 : /*************************************************************************************/
237 :
238 6 : DataType get_container_type(Container *container)
239 : {
240 6 : DataType type = UNKNOWN;
241 :
242 6 : if (container) {
243 6 : type = container->type;
244 6 : }
245 6 : return type;
246 : }
247 :
248 : /*************************************************************************************/
249 :
250 : /*************************************************************************************/
251 :
252 0 : void *get_container_data(Container *container)
253 : {
254 0 : void *data = NULL;
255 :
256 0 : if (container) {
257 0 : data = container->data;
258 0 : }
259 0 : return data;
260 : }
261 :
262 : /*************************************************************************************/
263 :
264 : /*************************************************************************************/
265 :
266 3 : void init_node_type_map(map<string, DataType> **node_type_map)
267 : {
268 3 : if (*node_type_map == NULL) {
269 3 : *node_type_map = new map<string, DataType>;
270 3 : }
271 :
272 3 : (**node_type_map)["Shape"] = SHAPE;
273 3 : (**node_type_map)["Group"] = GROUP;
274 3 : (**node_type_map)["Coordinate"] = COORDINATE;
275 3 : (**node_type_map)["IndexedLineSet"] = INDEXED_LINE_SET;
276 3 : (**node_type_map)["IndexedFaceSet"] = INDEXED_FACE_SET;
277 3 : (**node_type_map)["Transform"] = TRANSFORM;
278 3 : (**node_type_map)["Material"] = MATERIAL;
279 3 : (**node_type_map)["PointSet"] = POINT_SET;
280 3 : (**node_type_map)["Appearance"] = APPEARANCE;
281 :
282 :
283 3 : }
284 :
285 : /*************************************************************************************/
286 :
287 : /*************************************************************************************/
288 :
289 :
290 3 : void init_field_type_map(map<string, DataType> **field_type_map)
291 : {
292 3 : if (*field_type_map == NULL) {
293 3 : *field_type_map = new map<string, DataType>;
294 3 : }
295 :
296 3 : (**field_type_map)["translation"] = TRANSLATION;
297 3 : (**field_type_map)["rotation"] = ROTATION;
298 3 : (**field_type_map)["scale"] = SCALE;
299 3 : (**field_type_map)["point"] = POINT;
300 3 : }
301 :
302 : /*************************************************************************************/
303 :
304 : /*************************************************************************************/
305 :
306 24 : DataSup *add_type_sup_map(string keyword, DataType type, READ_NODE_FUN read_node_fun,
307 : READ_FIELD_FUN read_field_fun, CREATE_FUN create_fun)
308 : {
309 24 : DataSup *data_sup = NULL;
310 :
311 24 : data_sup = new DataSup;
312 :
313 24 : if (data_sup) {
314 24 : data_sup->keyword = keyword;
315 24 : data_sup->type = type;
316 24 : data_sup->read_node_fun = read_node_fun;
317 24 : data_sup->read_field_fun = read_field_fun;
318 24 : data_sup->create_fun = create_fun;
319 24 : }
320 :
321 24 : return data_sup;
322 0 : }
323 :
324 :
325 : /*************************************************************************************/
326 :
327 : /*************************************************************************************/
328 :
329 3 : void init_type_sup_map(map<DataType, DataSup *> **type_sup_map)
330 : {
331 :
332 3 : if (*type_sup_map == NULL) {
333 3 : *type_sup_map = new map<DataType, DataSup *>;
334 3 : }
335 :
336 : /* NODE FUNCTIONS */
337 3 : (**type_sup_map)[COORDINATE] = add_type_sup_map("Coordinate", COORDINATE ,read_coordinate, NULL, NULL);
338 3 : (**type_sup_map)[POINT_SET] = add_type_sup_map("PointSet", POINT_SET ,read_point_set, NULL, NULL);
339 3 : (**type_sup_map)[SHAPE] = add_type_sup_map("Shape", SHAPE ,read_shape, NULL, NULL);
340 3 : (**type_sup_map)[TRANSFORM] = add_type_sup_map("Transform", TRANSFORM, read_transform, NULL, NULL);
341 :
342 : /* FIELD FUNCTIONS */
343 3 : (**type_sup_map)[TRANSLATION] = add_type_sup_map("translation", TRANSLATION, NULL, read_translation, NULL);
344 3 : (**type_sup_map)[ROTATION] = add_type_sup_map("rotation", ROTATION, NULL, read_rotation, NULL);
345 3 : (**type_sup_map)[SCALE] = add_type_sup_map("scale", SCALE, NULL, read_scale, NULL);
346 3 : (**type_sup_map)[POINT] = add_type_sup_map("point", POINT, NULL, read_point, NULL);
347 3 : }
348 :
349 :
350 :
351 :
352 : /*************************************************************************************/
353 :
354 : /*************************************************************************************/
355 :
356 9 : void init_frame(vector<Container *> **frame)
357 : {
358 9 : if (*frame == NULL) {
359 3 : *frame =new vector<Container *>;
360 3 : }
361 9 : }
362 :
363 : /*************************************************************************************/
364 :
365 : /*************************************************************************************/
366 :
367 3 : void init_def(map<string, Container *> **def)
368 : {
369 3 : if (*def == NULL) {
370 3 : *def = new map<string, Container *>;
371 3 : }
372 3 : }
373 :
374 :
375 : /*************************************************************************************/
376 :
377 : /*************************************************************************************/
378 :
379 3 : void init_def_map2(map<string, void *> **def_map2)
380 : {
381 3 : if (*def_map2 == NULL) {
382 3 : *def_map2 = new map<string, void *>;
383 3 : }
384 3 : }
385 :
386 :
387 : /*************************************************************************************/
388 :
389 : /* Point */
390 :
391 : /*************************************************************************************/
392 :
393 287 : Point *new_point()
394 : {
395 287 : Point *point = NULL;
396 :
397 287 : point = new Point;
398 287 : return point;
399 : }
400 :
401 : /*************************************************************************************/
402 :
403 : /*************************************************************************************/
404 :
405 0 : void delete_point(Point *point)
406 : {
407 0 : delete point;
408 0 : }
409 :
410 : /*************************************************************************************/
411 :
412 : /*************************************************************************************/
413 :
414 0 : void debug_read_point(vector<Point *> *coordinate_vec)
415 : {
416 0 : vector<Point *>::iterator it;
417 : Point *point;
418 :
419 0 : for (it = coordinate_vec->begin(); it != coordinate_vec->end(); ++it) {
420 0 : point = *it;
421 0 : if (point)
422 0 : cout << "value: x = " << point->x << " y = " << point->y << " z = " << point->z << endl;
423 0 : }
424 :
425 :
426 0 : }
427 :
428 : /*************************************************************************************/
429 :
430 : /*************************************************************************************/
431 :
432 3 : void *read_point(void *args)
433 : {
434 3 : Point *point = NULL;
435 3 : string tokn = "";
436 : double tmp;
437 : int valid_flag;
438 3 : int flag = 0;
439 3 : int count = 0;
440 : double x, y, z;
441 3 : vector<Point *> *coordinate_vec = NULL;
442 :
443 3 : cout << "Hello read point" << endl;
444 :
445 3 : coordinate_vec = new vector<Point *>;
446 :
447 2085 : while (tokn.find("]") == string::npos) {
448 :
449 2082 : tokn = get_tokn();
450 :
451 2082 : flag = 0;
452 :
453 2082 : if (find_comma_and_remove_it(&tokn) || tokn.find(",") != string::npos || count == 3) {
454 : //cout << "tokn " << tokn << endl;
455 287 : flag = 1;
456 287 : }
457 :
458 2082 : if (is_number(tokn)) {
459 906 : valid_flag = 1;
460 :
461 906 : tmp = str2double(tokn, &valid_flag);
462 :
463 906 : if (valid_flag) {
464 :
465 906 : if (count == 0) {
466 287 : x = tmp;
467 906 : } else if (count == 1) {
468 283 : y = tmp;
469 619 : } else if (count == 2) {
470 283 : z = tmp;
471 283 : }
472 906 : }
473 906 : count ++;
474 906 : }
475 :
476 2082 : if (flag == 1) {
477 287 : point = new_point();
478 287 : if (point) {
479 287 : point->x = x;
480 287 : point->y = y;
481 287 : point->z = z;
482 287 : count = 0;
483 287 : flag = 0;
484 : //cout << "read point value: x = " << point->x << " y = " << point->y << " z = " << point->z << endl;
485 287 : }
486 :
487 287 : if (coordinate_vec) {
488 :
489 287 : coordinate_vec->push_back(point);
490 :
491 287 : }
492 287 : point = NULL;
493 287 : }
494 : }
495 :
496 : //debug_read_point(coordinate_vec);
497 3 : return coordinate_vec;
498 3 : }
499 :
500 : /*************************************************************************************/
501 :
502 : /* CoordIndex */
503 :
504 : /*************************************************************************************/
505 :
506 0 : CoordIndex *new_coord_index()
507 : {
508 0 : CoordIndex *coord_index = NULL;
509 0 : vector<int> *coord_index_vec = NULL;
510 :
511 0 : coord_index = new CoordIndex;
512 :
513 0 : if (coord_index) {
514 0 : coord_index_vec = new vector<int>;
515 0 : coord_index->coord_index_vec = coord_index_vec;
516 0 : }
517 0 : return coord_index;
518 0 : }
519 :
520 : /*************************************************************************************/
521 :
522 : /*************************************************************************************/
523 :
524 0 : void delete_coord_index(CoordIndex *coord_index)
525 : {
526 0 : delete coord_index->coord_index_vec;
527 0 : delete coord_index;
528 0 : }
529 :
530 : /*************************************************************************************/
531 :
532 : /* Coordinate */
533 :
534 : /*************************************************************************************/
535 :
536 3 : Coordinate *new_coordinate()
537 : {
538 3 : Coordinate *coordinate = NULL;
539 3 : vector<Point *> *coordinate_vec = NULL;
540 :
541 3 : coordinate = new Coordinate;
542 :
543 3 : if (coordinate) {
544 : //coordinate_vec = new vector<Point *>;
545 3 : coordinate->info = new Info;
546 3 : coordinate->coordinate_vec = coordinate_vec;
547 3 : }
548 3 : return coordinate;
549 : }
550 :
551 : /*************************************************************************************/
552 :
553 : /*************************************************************************************/
554 :
555 0 : void delete_coordinate(Coordinate *coordinate)
556 : {
557 0 : vector<Point *>::iterator it;
558 : vector<Point *> *coordinate_vec;
559 :
560 0 : coordinate_vec = coordinate->coordinate_vec;
561 :
562 0 : for (it = coordinate_vec->begin(); it != coordinate_vec->end(); ++it) {
563 0 : delete_point(*it);
564 0 : }
565 :
566 0 : delete coordinate->coordinate_vec;
567 0 : delete coordinate;
568 0 : }
569 :
570 : /*************************************************************************************/
571 :
572 : /*************************************************************************************/
573 :
574 0 : void debug_read_coordinate(Coordinate *coordinate)
575 : {
576 0 : vector<Point *> *coordinate_vec = NULL;
577 0 : vector<Point *>::iterator it;
578 0 : Point *point = NULL;
579 :
580 0 : if (coordinate) {
581 0 : coordinate_vec = coordinate->coordinate_vec;
582 :
583 0 : if (coordinate_vec) {
584 0 : for (it = coordinate_vec->begin(); it != coordinate_vec->end(); ++it) {
585 0 : point = *it;
586 0 : if (point)
587 0 : cout << "read_coordinate value: x = " << point->x << " y = " << point->y << " z = " << point->z << endl;
588 0 : }
589 0 : }
590 0 : }
591 0 : }
592 :
593 : /*************************************************************************************/
594 :
595 : /*************************************************************************************/
596 :
597 :
598 3 : void *read_coordinate(void *data) {
599 :
600 3 : cout << "Hello coordinate" << endl;
601 :
602 3 : string tokn = "";
603 3 : Coordinate *coordinate = NULL;
604 :
605 3 : coordinate = new_coordinate();
606 :
607 3 : if (coordinate) {
608 :
609 12 : while (tokn.find("}") == string::npos) {
610 :
611 9 : tokn = get_tokn();
612 :
613 9 : if (tokn.find("point") != string::npos) {
614 :
615 3 : coordinate->coordinate_vec = (vector<Point *> *)read_point(coordinate);
616 3 : }
617 :
618 : }
619 3 : set_node_type(coordinate, COORDINATE);
620 3 : }
621 :
622 : //debug_read_coordinate(coordinate);
623 3 : return coordinate;
624 3 : }
625 :
626 :
627 : /*************************************************************************************/
628 :
629 : /* IndexedLineSet */
630 :
631 : /*************************************************************************************/
632 :
633 0 : IndexedLineSet *new_indexed_line_set()
634 : {
635 0 : IndexedLineSet *indexed_line_set = NULL;
636 0 : Coordinate *coordinate = NULL;
637 0 : vector<CoordIndex *> *indexed_line_set_vec = NULL;
638 :
639 0 : indexed_line_set = new IndexedLineSet;
640 :
641 0 : if (indexed_line_set) {
642 0 : coordinate = new_coordinate();
643 0 : indexed_line_set_vec = new vector<CoordIndex *>;
644 :
645 0 : indexed_line_set->coordinate = coordinate;
646 0 : indexed_line_set->indexed_line_set_vec = indexed_line_set_vec;
647 0 : }
648 0 : return indexed_line_set;
649 0 : }
650 :
651 : /*************************************************************************************/
652 :
653 : /*************************************************************************************/
654 :
655 0 : void delete_indexed_line_set(IndexedLineSet *indexed_line_set)
656 : {
657 0 : vector<CoordIndex *>::iterator it;
658 : vector<CoordIndex *> *indexed_line_set_vec;
659 :
660 0 : indexed_line_set_vec = indexed_line_set->indexed_line_set_vec;
661 :
662 0 : for (it = indexed_line_set_vec->begin(); it != indexed_line_set_vec->end(); ++it) {
663 0 : delete_coord_index(*it);
664 0 : }
665 :
666 0 : delete_coordinate(indexed_line_set->coordinate);
667 0 : delete indexed_line_set;
668 :
669 0 : }
670 :
671 : /*************************************************************************************/
672 :
673 : /* IndexedFaceSet */
674 :
675 : /*************************************************************************************/
676 :
677 0 : IndexedFaceSet *new_indexed_face_set()
678 : {
679 0 : IndexedFaceSet *indexed_face_set = NULL;
680 0 : Coordinate *coordinate = NULL;
681 0 : vector<CoordIndex *> *indexed_face_set_vec = NULL;
682 :
683 0 : indexed_face_set = new IndexedFaceSet;
684 :
685 0 : if (indexed_face_set) {
686 0 : coordinate = new_coordinate();
687 0 : indexed_face_set_vec = new vector<CoordIndex *>;
688 :
689 0 : indexed_face_set->coordinate = coordinate;
690 0 : indexed_face_set->indexed_face_set_vec = indexed_face_set_vec;
691 0 : }
692 0 : return indexed_face_set;
693 0 : }
694 :
695 : /*************************************************************************************/
696 :
697 : /*************************************************************************************/
698 :
699 0 : void delete_indexed_face_set(IndexedFaceSet *indexed_face_set)
700 : {
701 0 : vector<CoordIndex *>::iterator it;
702 : vector<CoordIndex *> *indexed_face_set_vec;
703 :
704 0 : indexed_face_set_vec = indexed_face_set->indexed_face_set_vec;
705 :
706 0 : for (it = indexed_face_set_vec->begin(); it != indexed_face_set_vec->end(); ++it) {
707 0 : delete_coord_index(*it);
708 0 : }
709 :
710 0 : delete_coordinate(indexed_face_set->coordinate);
711 0 : delete indexed_face_set;
712 0 : }
713 :
714 : /*************************************************************************************/
715 :
716 : /* Material */
717 :
718 : /*************************************************************************************/
719 :
720 0 : Material *new_material()
721 : {
722 0 : Material *material = NULL;
723 :
724 0 : material = new Material;
725 0 : return material;
726 : }
727 :
728 : /*************************************************************************************/
729 :
730 : /*************************************************************************************/
731 :
732 0 : void delete_material(Material *material)
733 : {
734 0 : delete material;
735 0 : }
736 :
737 : /*************************************************************************************/
738 :
739 : /* PointSet */
740 :
741 : /*************************************************************************************/
742 :
743 0 : PointSet *new_point_set()
744 : {
745 0 : PointSet *point_set = NULL;
746 0 : Coordinate *coordinate = NULL;
747 :
748 0 : point_set = new PointSet;
749 0 : if (point_set) {
750 : //coordinate = new_coordinate();
751 0 : point_set->info = new Info;
752 0 : point_set->coordinate = coordinate;
753 0 : }
754 0 : return point_set;
755 : }
756 :
757 : /*************************************************************************************/
758 :
759 : /*************************************************************************************/
760 :
761 0 : void delete_point_set(PointSet *point_set)
762 : {
763 0 : delete_coordinate(point_set->coordinate);
764 0 : delete point_set->coordinate;
765 0 : }
766 :
767 : /*************************************************************************************/
768 :
769 : /*************************************************************************************/
770 :
771 0 : void debug_read_point_set(PointSet *point_set)
772 : {
773 0 : Coordinate *coordinate = NULL;
774 0 : vector<Point *> *coordinate_vec = NULL;
775 0 : vector<Point *>::iterator it;
776 0 : Point *point = NULL;
777 :
778 0 : if (point_set) {
779 :
780 0 : coordinate = point_set->coordinate;
781 0 : if (coordinate) {
782 0 : coordinate_vec = coordinate->coordinate_vec;
783 0 : if (coordinate_vec) {
784 0 : for (it = coordinate_vec->begin(); it != coordinate_vec->end(); ++it) {
785 0 : point = *it;
786 0 : if (point)
787 0 : cout << "r_point_set value: x = " << point->x << " y = " << point->y << " z = " << point->z << endl;
788 0 : }
789 0 : }
790 0 : }
791 0 : }
792 0 : }
793 :
794 :
795 : /*************************************************************************************/
796 :
797 : /*************************************************************************************/
798 :
799 :
800 0 : void store_data_point_set(PointSet *point_set, void *data)
801 : {
802 0 : DataType type = UNKNOWN;
803 :
804 0 : if (data) {
805 :
806 0 : type = get_node_type(data);
807 :
808 0 : switch (type) {
809 : case COORDINATE:
810 0 : point_set->coordinate = (Coordinate *)data;
811 0 : break;
812 :
813 : }
814 0 : }
815 0 : }
816 :
817 :
818 : /*************************************************************************************/
819 :
820 : /*************************************************************************************/
821 :
822 0 : void *read_point_set(void *args)
823 : {
824 0 : cout << "Hello point set" << endl;
825 :
826 0 : PointSet *point_set = NULL;
827 0 : string tokn = "";
828 0 : void *data = NULL;
829 0 : int def_flag = 0;
830 0 : string def_tokn = "";
831 :
832 :
833 0 : point_set = new_point_set();
834 :
835 0 : if (point_set) {
836 :
837 0 : while (tokn.find("}") == string::npos) {
838 :
839 : // tokn = get_tokn();
840 :
841 : //------------------------------
842 :
843 : //Edw prepei na to ksanadw to vrady...
844 :
845 0 : if (gvar->use_flag) {
846 0 : data = (*gvar->def_map2)[gvar->use_tokn];
847 0 : store_data_point_set(point_set, data);
848 0 : }
849 :
850 :
851 :
852 0 : if (gvar->def_flag) {
853 0 : def_flag = 1;
854 0 : def_tokn = gvar->def_tokn;
855 0 : }
856 :
857 0 : data = NULL;
858 :
859 0 : tokn = get_tokn();
860 :
861 0 : data = call_node_read_function(tokn, NULL);
862 :
863 0 : store_data_point_set(point_set, data);
864 :
865 0 : if (def_flag && data !=NULL) {
866 0 : add_to_def_map(def_tokn, data);
867 0 : }
868 :
869 : //------------------------------
870 :
871 : /*if (tokn.find("Coordinate") != string::npos) {
872 :
873 : point_set->coordinate = (Coordinate *)read_coordinate(point_set);
874 :
875 : } else if (tokn.find("Color") != string::npos) {
876 : ;
877 : }*/
878 : }
879 0 : set_node_type(point_set, POINT_SET);
880 0 : }
881 :
882 0 : debug_read_point_set(point_set);
883 0 : return point_set;
884 0 : }
885 :
886 : /*************************************************************************************/
887 :
888 : /* Appearance */
889 :
890 : /*************************************************************************************/
891 :
892 0 : Appearance *new_appearance()
893 : {
894 0 : Appearance *appearance = NULL;
895 :
896 0 : appearance = new Appearance;
897 0 : return appearance;
898 : }
899 :
900 : /*************************************************************************************/
901 :
902 : /*************************************************************************************/
903 :
904 0 : void delete_appearance(Appearance *appearance)
905 : {
906 0 : delete appearance;
907 0 : }
908 :
909 : /*************************************************************************************/
910 :
911 : /* Shape */
912 :
913 : /*************************************************************************************/
914 :
915 3 : Shape *new_shape()
916 : {
917 3 : Shape *shape = NULL;
918 :
919 3 : shape = new Shape;
920 3 : if (shape) {
921 : //shape->appearance = new_appearance();
922 : //shape->point_set = new_point_set();
923 : //shape->indexed_line_set = new_indexed_line_set();
924 : //shape->indexed_face_set = new_indexed_face_set();
925 3 : shape->info = new Info;
926 3 : set_node_type(shape, SHAPE);
927 3 : shape->appearance = NULL;
928 3 : shape->point_set = NULL;
929 3 : shape->indexed_line_set = NULL;
930 3 : shape->indexed_face_set = NULL;
931 3 : }
932 3 : return shape;
933 : }
934 :
935 :
936 : /*************************************************************************************/
937 :
938 : /*************************************************************************************/
939 :
940 0 : void delete_shape(Shape *shape)
941 : {
942 : //delete_appearance(shape->appearance);
943 : //delete_point_set(shape->point_set);
944 : //delete_indexed_line_set(shape->indexed_line_set);
945 : //delete_indexed_face_set(shape->indexed_face_set);
946 0 : delete shape;
947 0 : }
948 :
949 :
950 : /*************************************************************************************/
951 :
952 : /*************************************************************************************/
953 :
954 :
955 0 : void debug_read_shape(void *args)
956 : {
957 0 : PointSet *point_set = NULL;
958 0 : Coordinate *coordinate = NULL;
959 0 : vector<Point *> *coordinate_vec = NULL;
960 0 : vector<Point *>::iterator it;
961 0 : Point *point = NULL;
962 0 : Shape *shape = NULL;
963 :
964 0 : shape = (Shape *) args;
965 :
966 0 : if (shape) {
967 :
968 0 : point_set = shape->point_set;
969 :
970 0 : if (point_set) {
971 :
972 0 : coordinate = point_set->coordinate;
973 0 : if (coordinate) {
974 0 : coordinate_vec = coordinate->coordinate_vec;
975 0 : if (coordinate_vec) {
976 0 : for (it = coordinate_vec->begin(); it != coordinate_vec->end(); ++it) {
977 0 : point = *it;
978 0 : if (point)
979 0 : cout << "r_shape value: x = " << point->x << " y = " << point->y << " z = "
980 0 : << point->z << endl;
981 0 : }
982 0 : }
983 0 : }
984 0 : }
985 0 : }
986 0 : }
987 :
988 :
989 : /*************************************************************************************/
990 :
991 : /*************************************************************************************/
992 :
993 54 : void store_data_shape(Shape *shape, void *data)
994 : {
995 54 : DataType type = UNKNOWN;
996 :
997 54 : if (data) {
998 :
999 0 : type = get_node_type(data);
1000 :
1001 0 : switch (type) {
1002 : case POINT_SET:
1003 0 : shape->point_set = (PointSet *)data;
1004 0 : break;
1005 : case INDEXED_LINE_SET:
1006 0 : break;
1007 : case INDEXED_FACE_SET:
1008 0 : break;
1009 :
1010 : }
1011 0 : }
1012 :
1013 54 : }
1014 :
1015 :
1016 : /*************************************************************************************/
1017 :
1018 : /*************************************************************************************/
1019 :
1020 3 : void *read_shape(void *args)
1021 : {
1022 3 : cout << "Hello Shape" << endl;
1023 :
1024 3 : Shape *shape = NULL;
1025 3 : Container *container = NULL;
1026 3 : string tokn = "";
1027 3 : void *data = NULL;
1028 3 : int def_flag = 0;
1029 3 : string def_tokn = "";
1030 :
1031 3 : shape = new_shape();
1032 3 : container = new_container();
1033 :
1034 3 : if (gvar->def_flag) {
1035 0 : add_to_def(gvar->def_tokn, container);
1036 0 : }
1037 :
1038 3 : if (shape) {
1039 :
1040 57 : while (tokn.find("}") == string::npos) {
1041 :
1042 : //------------------------------
1043 :
1044 : // (1) Thelw mia sinattisi pou na tsimpaei apo to def map to swsto data
1045 : // (2) Apo to data tha tsimpaei to type
1046 : // (3) Apo to type tha apofasizei pou tha to apothikevei -> store_data_shape() prepei na volevei kai edw
1047 : // (4) break gia na stamatisei i while, gia auto den eimai poly sigouros, mallon den xriazetai
1048 : // giati mporei na exeis kai alla pedia
1049 : //
1050 : // opote ta data exoun apothikeutei mia xara... elpizw
1051 :
1052 54 : if (gvar->use_flag) {
1053 0 : data = (*gvar->def_map2)[gvar->use_tokn];
1054 0 : store_data_shape(shape, data);
1055 0 : }
1056 :
1057 : //------------------------------
1058 :
1059 :
1060 :
1061 54 : if (gvar->def_flag) {
1062 0 : def_flag = 1;
1063 0 : def_tokn = gvar->def_tokn;
1064 0 : }
1065 :
1066 54 : data = NULL;
1067 :
1068 54 : tokn = get_tokn();
1069 :
1070 54 : data = call_node_read_function(tokn, NULL);
1071 :
1072 54 : store_data_shape(shape, data);
1073 :
1074 54 : if (def_flag && data !=NULL) {
1075 0 : add_to_def_map(def_tokn, data);
1076 0 : }
1077 :
1078 : }
1079 :
1080 : //set_node_type(shape, SHAPE);
1081 :
1082 :
1083 3 : }
1084 : //debug_read_shape(shape);
1085 3 : return shape;
1086 :
1087 3 : }
1088 :
1089 :
1090 : /*************************************************************************************/
1091 :
1092 : /* Transform */
1093 :
1094 : /*************************************************************************************/
1095 :
1096 0 : Transform *new_transform()
1097 : {
1098 0 : Transform *transform = NULL;
1099 :
1100 0 : transform = new Transform;
1101 0 : if (transform) {
1102 0 : transform->info = new Info;
1103 0 : transform->children = NULL;
1104 0 : }
1105 0 : return transform;
1106 : }
1107 :
1108 : /*************************************************************************************/
1109 :
1110 : /*************************************************************************************/
1111 :
1112 0 : void delete_transform(Transform *transform)
1113 : {
1114 0 : delete transform;
1115 0 : }
1116 :
1117 :
1118 : /*************************************************************************************/
1119 :
1120 : /*************************************************************************************/
1121 :
1122 0 : void *read_translation(void *args)
1123 : {
1124 0 : string tokn = "";
1125 0 : int valid_flag = 1;
1126 : double tmp;
1127 0 : int i = 0;
1128 0 : double *translation = NULL;
1129 0 : Transform *transform = NULL;
1130 :
1131 :
1132 0 : transform = (Transform *)args;
1133 :
1134 0 : if (transform) {
1135 0 : translation = transform->translation;
1136 0 : }
1137 :
1138 0 : if (translation) {
1139 0 : for (i = 0; i < 3; ++i) {
1140 0 : tokn = get_token();
1141 0 : if (is_number(tokn)) {
1142 0 : tmp = str2double(tokn, &valid_flag);
1143 0 : if (valid_flag) {
1144 0 : translation[i] = tmp;
1145 0 : }
1146 0 : }
1147 0 : }
1148 0 : }
1149 0 : return translation;
1150 0 : }
1151 :
1152 : /*************************************************************************************/
1153 :
1154 : /*************************************************************************************/
1155 :
1156 :
1157 0 : void *read_scale(void *args)
1158 : {
1159 0 : string tokn = "";
1160 0 : int valid_flag = 1;
1161 : double tmp;
1162 0 : int i = 0;
1163 0 : double *scale = NULL;
1164 0 : Transform *transform = NULL;
1165 :
1166 :
1167 0 : transform = (Transform *)args;
1168 :
1169 0 : if (transform) {
1170 0 : scale = transform->rotation;
1171 0 : }
1172 :
1173 0 : if (scale) {
1174 0 : for (i = 0; i < 3; ++i) {
1175 0 : tokn = get_token();
1176 0 : if (is_number(tokn)) {
1177 0 : tmp = str2double(tokn, &valid_flag);
1178 0 : if (valid_flag) {
1179 0 : scale[i] = tmp;
1180 0 : }
1181 0 : }
1182 0 : }
1183 0 : }
1184 0 : return scale;
1185 0 : }
1186 :
1187 : /*************************************************************************************/
1188 :
1189 : /*************************************************************************************/
1190 :
1191 :
1192 0 : void *read_rotation(void *args)
1193 : {
1194 0 : string tokn = "";
1195 0 : int valid_flag = 1;
1196 : double tmp;
1197 0 : int i = 0;
1198 0 : double *rotation = NULL;
1199 0 : Transform *transform = NULL;
1200 :
1201 :
1202 0 : transform = (Transform *)args;
1203 :
1204 0 : if (transform) {
1205 0 : rotation = transform->rotation;
1206 0 : }
1207 0 : if (rotation) {
1208 0 : for (i = 0; i < 4; ++i) {
1209 0 : tokn = get_token();
1210 0 : if (is_number(tokn)) {
1211 0 : tmp = str2double(tokn, &valid_flag);
1212 0 : if (valid_flag) {
1213 0 : rotation[i] = tmp;
1214 0 : }
1215 0 : }
1216 0 : }
1217 0 : }
1218 0 : return rotation;
1219 0 : }
1220 :
1221 : /*************************************************************************************/
1222 :
1223 : /*************************************************************************************/
1224 :
1225 0 : void debug_read_transform(void *args)
1226 : {
1227 :
1228 0 : void *data = NULL;
1229 :
1230 0 : int i = 0;
1231 :
1232 0 : data = args;
1233 :
1234 0 : if (data) {
1235 :
1236 0 : if (get_node_type(data) == SHAPE) {
1237 :
1238 0 : debug_read_shape(data);
1239 :
1240 0 : } else if (get_node_type(data) == TRANSFORM) {
1241 :
1242 0 : Transform *transform = (Transform *)data;
1243 :
1244 0 : if (transform) {
1245 :
1246 0 : for (i = 0; i < 3; i++) {
1247 0 : cout << "translation[" << i << "] -> " << transform->translation[i] << endl;
1248 0 : }
1249 :
1250 0 : for (i = 0; i < 3; i++) {
1251 0 : cout << "scale[" << i << "] -> " << transform->scale[i] << endl;
1252 0 : }
1253 :
1254 0 : for (i = 0; i < 4; i++) {
1255 0 : cout << "rotation[" << i << "] -> " << transform->rotation[i] << endl;
1256 0 : }
1257 0 : }
1258 :
1259 0 : data = transform->children;
1260 0 : debug_read_transform(data);
1261 :
1262 0 : }
1263 0 : }
1264 0 : }
1265 :
1266 :
1267 : /*************************************************************************************/
1268 :
1269 : /*************************************************************************************/
1270 :
1271 :
1272 0 : void store_data_transform(Transform *transform, void *data)
1273 : {
1274 0 : DataType type = UNKNOWN;
1275 :
1276 0 : if (data) {
1277 :
1278 0 : type = get_node_type(data);
1279 :
1280 0 : switch (type) {
1281 : case SHAPE:
1282 0 : transform->children = data;
1283 0 : break;
1284 : case TRANSFORM:
1285 0 : transform->children = data;
1286 0 : break;
1287 : case GROUP:
1288 0 : transform->children = data;
1289 0 : break;
1290 :
1291 :
1292 : }
1293 0 : }
1294 :
1295 0 : }
1296 :
1297 :
1298 : /*************************************************************************************/
1299 :
1300 : /*************************************************************************************/
1301 :
1302 0 : void *read_transform(void *args)
1303 : {
1304 0 : cout << "Hello Transform" << endl;
1305 :
1306 0 : Transform *transform = NULL;
1307 0 : string tokn = "";
1308 0 : void *data = NULL;
1309 0 : int def_flag = 0;
1310 0 : string def_tokn = "";
1311 :
1312 0 : transform = new_transform();
1313 :
1314 0 : if (transform) {
1315 :
1316 0 : while (tokn.find("children") == string::npos && tokn.find("}") == string::npos) {
1317 :
1318 0 : data = NULL;
1319 :
1320 0 : tokn = get_tokn();
1321 :
1322 0 : data = call_field_read_function(tokn, transform);
1323 :
1324 : }
1325 :
1326 0 : if (tokn.find("children") != string::npos) {
1327 :
1328 0 : while(tokn.find("]") == string::npos) {
1329 :
1330 0 : if (gvar->def_flag) {
1331 0 : def_flag = 1;
1332 0 : def_tokn = gvar->def_tokn;
1333 0 : }
1334 :
1335 0 : data = NULL;
1336 :
1337 0 : tokn = get_tokn();
1338 :
1339 0 : data = call_node_read_function(tokn, NULL);
1340 :
1341 0 : store_data_transform(transform, data);
1342 :
1343 0 : if (def_flag && data !=NULL) {
1344 0 : add_to_def_map(def_tokn, data);
1345 0 : }
1346 :
1347 : }
1348 :
1349 0 : }
1350 :
1351 0 : }
1352 0 : set_node_type(transform, TRANSFORM);
1353 :
1354 : //debug_read_transform(transform);
1355 0 : return transform;
1356 0 : }
1357 :
1358 : /*************************************************************************************/
1359 :
1360 : /* Group */
1361 :
1362 : /*************************************************************************************/
1363 :
1364 0 : Group *new_group()
1365 : {
1366 0 : Group *group = NULL;
1367 :
1368 0 : group = new Group;
1369 0 : if (group) {
1370 0 : group->children = NULL;
1371 0 : }
1372 0 : return group;
1373 : }
1374 :
1375 : /*************************************************************************************/
1376 :
1377 : /*************************************************************************************/
1378 :
1379 0 : void delete_group(Group *group)
1380 : {
1381 0 : delete group;
1382 0 : }
1383 :
1384 : /*************************************************************************************/
1385 :
1386 : /*************************************************************************************/
1387 :
1388 :
1389 :
1390 :
1391 :
|