Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ntreepic.C
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
152# include <iostream>
153# include <fstream>
154# include <string>
155# include <tpl_dynArray.H>
156# include <tpl_dynDlist.H>
157# include <tpl_tree_node.H>
158#include <utility>
159
160# include <argp.h>
161
162# include "parse_utils.H"
163# include "treepic_utils.H"
164# include "ah-errors.H"
165
166/*
167
168 TODO:
169
170 opcion connexion complementaria a dashed-connexion
171
172 URGENTE:
173 -. Pasos de diferentes árboles
174 -. Notación de Deway pura
175
176 -. Mejorar heurística de cálculo de longitud string para que
177 considere saltos de línea
178 -. Conversión en representación árbol binario
179 -. Dibujar flecha
180 -. Opcion que dibuje lineas punteadas cuando se ejecute opcion que
181 dibuje reptresentacion con listas
182*/
183
184
185# define BLANK " "
186
187
188/* valores de distancias por omision */
189long double hr = 70; // radio horizontal de la elipse
190long double vr = 70; // radio vertical de la elipse
191long double hd = 2 * hr; // diametro horizontal de la elipse
192long double vd = 2 * vr; // diametro vertical de la elipse
193long double xgap = 70; // separacion horizontal entre nodos
194long double ygap = 100; // separacion vertical entre nodos
195long double tree_gap = 90; // separacion horizontal entre arboles
196long double h_size = 0; /* longitud horizontal de picture */
197double v_size = 0; /* longitud vertical de picture */
198long double x_offset = 0; /* offset horizontal etiqueta */
199long double y_offset = font_height() / 2.0; /* offset vertical etiqueta */
200long double x_picture_offset = 0; // offset horizontal para dibujo
201long double y_picture_offset = 0; // offset vertical para dibujo
202
203std::string command_line;
204std::string input_file_name;
206
207
208bool latex_header = false; // envolver salida con un latex header
209bool ellipses = true; // por omisión dibujar elipses
210bool rectangles = false;
213bool not_nodes = false;
214
215
216# include <cassert>
217using namespace std;
218
236
237
239
240struct Tree_Data; /* declaración adelantada */
241
243
244struct Tag_Data
245{
246 string tag; // el string a escribir
247 Tag_Option tag_option; // orientacion de tag en sentido horario
248 long double x_offset;
249 long double y_offset;
250
251 Tag_Data() = default;
252
253 Tag_Data(string str, const Tag_Option option)
254 : tag(std::move(str)), tag_option(option)
255 {
256 // empty
257 }
258};
259
260
261struct Arc_Data
262{
264 bool is_dashed;
265
266 Arc_Data() : target_node(nullptr), is_dashed(false)
267 { /* empty */
268 }
269};
270
271
273{
277
279 { /* empty */
280 }
281};
282
283
285{
286 long double x, y; /* coordenadas x,y definitivas del nodo */
287
288 long double pre, mod; /* valores x temporales empleados por algoritmo
289 dibujado */
290
291 long double sum_mod; /* acumulado de mod desde la raiz hasta el
292 nodo. Usado por el recorrido prefijo para colocar
293 los valores definitivos de x */
294
295 long double xr, yr; /* radios de elipse */
296
297 long double xd, yd; /* diametros de elipse */
298
299 long double max_child_yr; /* máximo radio vertical de sus hijos. Usado
300 para reajustar coordenadas y de los hijos si
301 algunos de los diametros son variables */
302
303 long double yr_gap; /* máximo radio entre los hermanos. Usado para
304 calcular separación vertical de los hijos de este
305 nodo de modo que queden alineados con el mayor
306 radio */
307
308 string str; /* cadena asociada al nodo */
309
310 long double xoffset, yoffset; /* offsets de posicion de cadena */
311
314
315 bool shadow;
317 bool with_arc; /* indica si hay arco desde el nodo padre */
318 bool dashed_arc; /* indica si el arco es punteado */
319
320 int position; /* posicion infija del nodo como si fuera un arbol binario */
321
323
325
327
328 int level;
329 int child_number; /* de izquierda a derecha */
330
332 : x(0), y(0), pre(0), mod(0), sum_mod(0),
333 xr(hr), yr(vr), xd(2 * xr), yd(2 * yr), max_child_yr(0),
334 xoffset(0), yoffset(0),
336 shadow(false), without_node(false), with_arc(true), dashed_arc(false)
337 {
338 assert(ellipse != rectangle);
339 }
340};
341
342
343# define X(p) ((p)->get_key().x)
344# define Y(p) ((p)->get_key().y)
345# define PRE(p) ((p)->get_key().pre)
346# define MOD(p) ((p)->get_key().mod)
347# define SUMMOD(p) ((p)->get_key().sum_mod)
348# define STRING(p) ((p)->get_key().str)
349# define ISELLIPSE(p) ((p)->get_key().ellipse)
350# define ISRECTANGLE(p) ((p)->get_key().rectangle)
351# define XOFFSET(p) ((p)->get_key().xoffset)
352# define YOFFSET(p) ((p)->get_key().yoffset)
353# define XR(p) ((p)->get_key().xr)
354# define YR(p) ((p)->get_key().yr)
355# define XD(p) ((p)->get_key().xd)
356# define YD(p) ((p)->get_key().yd)
357# define POS(p) ((p)->get_key().position)
358# define MAXCHILDYR(p) ((p)->get_key().max_child_yr)
359# define YRGAP(p) ((p)->get_key().yr_gap)
360# define LEVEL(p) ((p)->get_key().level)
361# define CHILDNUMBER(p) ((p)->get_key().child_number)
362# define WIDTH(p) ((p)->get_key().xd)
363# define HEIGHT(p) ((p)->get_key().yd)
364# define SHADOW(p) ((p)->get_key().shadow)
365# define WITHOUTNODE(p) ((p)->get_key().without_node)
366# define WITHARC(p) ((p)->get_key().with_arc)
367# define DASHEDARC(p) ((p)->get_key().dashed_arc)
368# define ARCS(p) ((p)->get_key().arc_list)
369# define CONNEXIONS(p) ((p)->get_key().connexion_list)
370# define TAGS(p) ((p)->get_key().tag_list)
371
372
373inline
374void load_deway_number(ifstream & input_stream,
375 int deway_array[], size_t deway_array_size)
376{
378 skip_white_spaces(input_stream);
379
380 int deway_index = 0;
381 char deway_string[Buffer_Size];
382 char *start_addr = &deway_string[0];
383 char *end_addr = &deway_string[Buffer_Size];
384 while (true)
385 {
386 const int c = read_char_from_stream(input_stream);
387
388 if (isdigit(c))
389 {
390 put_char_in_buffer(start_addr, end_addr, c);
391 continue;
392 }
393
394 if (c == '.' or isspace(c))
395 {
396 put_char_in_buffer(start_addr, end_addr, '\0');
397
398 if (deway_index >= deway_array_size)
399 {
400 ah_overflow_error_if(true) << "Deway number is too long";
401 }
402
403 deway_array[deway_index++] = atoi(deway_string);
404 start_addr = &deway_string[0];
405
406 if (isspace(c))
407 break;
408 else
409 continue;
410 }
411
412 input_stream.unget();
413 ah_invalid_argument_if(true) << "Unexpected character in deway number";
414 }
415
416 if (deway_index >= deway_array_size)
417 {
418 ah_overflow_error_if(true) << "Internal deway array size is not enough";
419 }
420 deway_array[deway_index] = -1;
421}
422
423
424Token_Type get_token(ifstream& input_stream)
425{
426 char buffer[Buffer_Size];
427 char * start_addr = buffer;
428 char * end_addr = buffer + Buffer_Size;
429
430 int c;
431
433
434 try
435 {
436 skip_white_spaces(input_stream);
437 c = read_char_from_stream(input_stream);
438 }
439 catch (const std::out_of_range &)
440 {
441 return END_FILE;
442 }
443
444 if (c == EOF)
445 return END_FILE;
446
447 if (not isprint(c))
448 return INVALID;
449
450 if (c == '%')
451 { /* comentario */
452 do
453 c = read_char_from_stream(input_stream);
454 while (c != '\n' and c != EOF);
455 return COMMENT;
456 }
457
458 do /* delimita una cadena de caracteres cualquiera delimitada por blancos */
459 {
460 put_char_in_buffer(start_addr, end_addr, c);
461 c = read_char_from_stream(input_stream);
462 }
463 while (isgraph(c) and c != '%' and c != EOF);
464
465 close_token_scanning(buffer, start_addr, end_addr);
466
467 if (c == '%') /* Se encontró comentario */
468 /* retroceda, así proxima llamada detectara comentario */
469 input_stream.unget();
470
471 if (strcasecmp(buffer, "ROOT") == 0)
472 return ROOT;
473
474 if (strcasecmp(buffer, "NODE") == 0)
475 return NODE;
476
477 if (strcasecmp(buffer, "TAG") == 0)
478 return TAG;
479
480 if (strcasecmp(buffer, "SHADOW") == 0)
481 return SHADOW;
482
483 if (strcasecmp(buffer, "WITHOUT-NODE") == 0)
484 return WITHOUT_NODE;
485
486 if (strcasecmp(buffer, "WITHOUT-ARC") == 0)
487 return WITHOUT_ARC;
488
489 if (strcasecmp(buffer, "ARC") == 0)
490 return ARC;
491
492 if (strcasecmp(buffer, "DASHED-ARC") == 0)
493 return DASHED_ARC;
494
495 if (strcasecmp(buffer, "HRADIO") == 0)
496 return HRADIO;
497
498 if (strcasecmp(buffer, "VRADIO") == 0)
499 return VRADIO;
500
501 if (strcasecmp(buffer, "XOFFSET") == 0)
502 return XOFFSET;
503
504 if (strcasecmp(buffer, "YOFFSET") == 0)
505 return YOFFSET;
506
507 if (strcasecmp(buffer, "N") == 0)
508 return NORTH;
509
510 if (strcasecmp(buffer, "S") == 0)
511 return SOUTH;
512
513 if (strcasecmp(buffer, "E") == 0)
514 return EAST;
515
516 if (strcasecmp(buffer, "L") == 0)
517 return LEFT;
518
519 if (strcasecmp(buffer, "R") == 0)
520 return RIGHT;
521
522 if (strcasecmp(buffer, "W") == 0)
523 return WEST;
524
525 if (strcasecmp(buffer, "NE") == 0)
526 return NORTH_EAST;
527
528 if (strcasecmp(buffer, "NW") == 0)
529 return NORTH_WEST;
530
531 if (strcasecmp(buffer, "SE") == 0)
532 return SOUTH_EAST;
533
534 if (strcasecmp(buffer, "SW") == 0)
535 return SOUTH_WEST;
536
537 if (strcasecmp(buffer, "ARC") == 0)
538 return ARC;
539
540 if (strcasecmp(buffer, "DASHED-CONNEXION") == 0)
541 return DASHED_CONNEXION;
542
543 if (strcasecmp(buffer, "ELLIPSE") == 0)
544 return ELLIPSE;
545
546 if (strcasecmp(buffer, "RECTANGLE") == 0)
547 return RECTANGLE;
548
549 return STRING;
550}
551
552/*
553 Aparta memoria para un nuevo nodo con string str
554*/
555EepicNode * allocate_node(const string & str)
556{
557 auto *node = new EepicNode;
558 STRING(node) = str;
559 return node;
560}
561
562
563/*
564 Lee un numero de deway y retorna el correspondiente nodo dentro del
565 árbol root. Retorna nullptr si el nodo no existe
566*/
567EepicNode * parse_deway_number(ifstream & input_stream, EepicNode *root)
568{
569 int deway_array[Buffer_Size];
570
571 load_deway_number(input_stream, deway_array, Buffer_Size);
572
573 EepicNode *parent_node = deway_search(root, deway_array, Buffer_Size);
574
575 if (parent_node == nullptr)
576 print_parse_error_and_exit("Deway number doesn't match an existing node");
577
578 return parent_node;
579}
580
581
582EepicNode * parse_key_node_and_allocate(ifstream & input_stream)
583{
584 const string str = load_string(input_stream);
585
586 return allocate_node(str);
587}
588
589
590EepicNode * parse_first_root_definition(ifstream & input_stream)
591{
592 if (get_token(input_stream) != ROOT)
593 print_parse_error_and_exit("Input file doesn't start with ROOT "
594 "definition");
595
596 return parse_key_node_and_allocate(input_stream);
597}
598
599
600void parse_root_definition(ifstream & input_stream, EepicNode *root)
601{
602 EepicNode *new_tree = parse_key_node_and_allocate(input_stream);
603
604 EepicNode *last_root = root->get_last_tree();
605
606 last_root->insert_tree_to_right(new_tree);
607}
608
609
610void parse_node_definition(ifstream & input_stream, EepicNode *root)
611{
612 EepicNode *parent_node = parse_deway_number(input_stream, root);
613
614 EepicNode *new_node = parse_key_node_and_allocate(input_stream);
615
616 parent_node->insert_rightmost_child(new_node);
617}
618
619/*
620 opcion HRADIO deway-number %-horizontal-radius-factor
621
622 El radio horizontal actual de la elipse se multiplica por
623 horizontal-radius-factor en porcentaje
624*/
625void parse_hradio(ifstream & input_stream, EepicNode *root)
626{
627 EepicNode *p = parse_deway_number(input_stream, root);
628
629 XR(p) *= load_number(input_stream) / 100.0;
630 XD(p) = 2 * XR(p);
631}
632
633
634/*
635 opcion VRADIO deway-number %-vertical-radius-factor
636
637 El radio vertical actual de la elipse se multiplica por
638 vertical-radius-factor en porcentaje
639*/
640void parse_vradio(ifstream & input_stream, EepicNode *root)
641{
642 EepicNode *p = parse_deway_number(input_stream, root);
643
644 YR(p) *= load_number(input_stream) / 100.0;
645 YD(p) = 2 * YR(p);
646}
647
648
649/*
650 opcion WITHOUT-NODE deway-number
651
652 El radio vertical actual de la elipse se multiplica por
653 vertical-radius-factor en porcentaje
654*/
655void parse_without_node(ifstream & input_stream, EepicNode *root)
656{
657 EepicNode *p = parse_deway_number(input_stream, root);
658
659 WITHOUTNODE(p) = true;
660}
661
662
663/*
664 opcion WITHOUT-NODE deway-number
665
666 El radio vertical actual de la elipse se multiplica por
667 vertical-radius-factor en porcentaje
668*/
669void parse_without_arc(ifstream & input_stream, EepicNode *root)
670{
671 const EepicNode *src = parse_deway_number(input_stream, root);
672
673 EepicNode *tgt = parse_deway_number(input_stream, root);
674
675 if (tgt->get_parent() != src)
676 print_parse_error_and_exit("target node does not match with parent in"
677 " WITHOUT-ARC");
678 WITHARC(tgt) = false;
679}
680
681
682/*
683 opcion XOFFSET deway-number offset
684*/
685void parse_xoffset(ifstream & input_stream, EepicNode *root)
686{
687 EepicNode *p = parse_deway_number(input_stream, root);
688
689 XOFFSET(p) = load_number(input_stream);
690}
691
692
693/*
694 opcion YOFFSET deway-number offset
695*/
696void parse_yoffset(ifstream & input_stream, EepicNode *root)
697{
698 EepicNode *p = parse_deway_number(input_stream, root);
699
700 YOFFSET(p) = load_number(input_stream);
701}
702
703/*
704 opcion SHADOW deway-number
705*/
706void parse_shadow(ifstream & input_stream, EepicNode *root)
707{
708 EepicNode *p = parse_deway_number(input_stream, root);
709
710 SHADOW(p) = true;
711}
712
713/*
714 TAG deway-number string orientation xoffset yoffset
715*/
716void parse_tag(ifstream & input_stream, EepicNode *root)
717{
718 EepicNode *p = parse_deway_number(input_stream, root);
719
720 Tag_Data tag_data;
721
722 tag_data.tag = load_string(input_stream);
723
724 tag_data.tag_option = get_token(input_stream);
725
726 if (tag_data.tag_option < NORTH or tag_data.tag_option > SOUTH_WEST)
727 print_parse_error_and_exit("Invalid tag option");
728
729 tag_data.x_offset = load_number(input_stream);
730 tag_data.y_offset = load_number(input_stream);
731
732 TAGS(p).append(tag_data);
733}
734
735
736void parse_arc(ifstream & input_stream, EepicNode *root)
737{
738 EepicNode *src = parse_deway_number(input_stream, root);
739 EepicNode *tgt = parse_deway_number(input_stream, root);
740
741 if (tgt == src) /* arco hacia si mismo */
742 print_parse_error_and_exit("an arc to itself");
743
744 if (tgt->get_parent() == src)
745 { /* arco natural (padre a hijo). Imprimimos warning y nos vamos */
746 print_parse_warning("declared an arc from parent to child");
747 return;
748 }
749
750 Arc_Data arc_data;
751
752 arc_data.target_node = tgt;
753 arc_data.is_dashed = false;
754
755 ARCS(src).append(arc_data);
756}
757
758
759void parse_dashed_arc(ifstream & input_stream, EepicNode *root)
760{
761 EepicNode *src = parse_deway_number(input_stream, root);
762 EepicNode *tgt = parse_deway_number(input_stream, root);
763
764 if (tgt == src) /* arco hacia si mismo */
765 print_parse_error_and_exit("an dashed arc to itself");
766
767 Arc_Data arc_data;
768
769 arc_data.target_node = tgt;
770 arc_data.is_dashed = true;
771
772 ARCS(src).append(arc_data);
773}
774
775
776void parse_connexion(ifstream & input_stream, EepicNode *root)
777{
778 EepicNode *src = parse_deway_number(input_stream, root);
779 EepicNode *tgt = parse_deway_number(input_stream, root);
780
781 const Token_Type token = get_token(input_stream);
782
783 if (token != LEFT and token != RIGHT)
784 print_parse_error_and_exit("Expected L or R");
785
786 Connexion_Data connexion_data;
787
788 connexion_data.target_node = tgt;
789 connexion_data.is_dashed = true;
790 connexion_data.is_left = token == LEFT;
791
792 CONNEXIONS(src).append(connexion_data);
793}
794
795
796void parse_ellipse(ifstream & input_stream, EepicNode *root)
797{
798 EepicNode *p = parse_deway_number(input_stream, root);
799
800 ISELLIPSE(p) = true;
801 ISRECTANGLE(p) = false;
802}
803
804
805void parse_rectangle(ifstream & input_stream, EepicNode *root)
806{
807 EepicNode *p = parse_deway_number(input_stream, root);
808
809 ISELLIPSE(p) = false;
810 ISRECTANGLE(p) = true;
811}
812
813
814EepicNode * read_input_and_build_tree(ifstream & input_stream)
815{
817
818 try
819 {
820 while (true)
821 switch (get_token(input_stream))
822 {
823 case ROOT:
824 parse_root_definition(input_stream, root);
825 break;
826
827 case NODE:
828 parse_node_definition(input_stream, root);
829 break;
830
831 case END_FILE:
832 return root;
833
834 case INVALID:
835 print_parse_error_and_exit("Unrecognized token");
836
837 case COMMENT: break;
838
839 case HRADIO:
840 parse_hradio(input_stream, root);
841 break;
842
843 case VRADIO:
844 parse_vradio(input_stream, root);
845 break;
846
847 case WITHOUT_NODE:
848 parse_without_node(input_stream, root);
849 break;
850
851 case WITHOUT_ARC:
852 parse_without_arc(input_stream, root);
853 break;
854
855 case XOFFSET:
856 parse_xoffset(input_stream, root);
857 break;
858
859 case YOFFSET:
860 parse_yoffset(input_stream, root);
861 break;
862
863 case SHADOW:
864 parse_shadow(input_stream, root);
865 break;
866
867 case TAG:
868 parse_tag(input_stream, root);
869 break;
870
871 case ARC:
872 parse_arc(input_stream, root);
873 break;
874
875 case DASHED_ARC:
876 parse_dashed_arc(input_stream, root);
877 break;
878
879 case DASHED_CONNEXION:
880 parse_connexion(input_stream, root);
881 break;
882
883 case ELLIPSE:
884 parse_ellipse(input_stream, root);
885 break;
886
887 case RECTANGLE:
888 parse_rectangle(input_stream, root);
889 break;
890
891 default:
892 print_parse_error_and_exit("Unknown token type");
893 }
894 }
895 catch (exception & e)
896 {
899 }
900 return nullptr; // nunca se alcanza
901}
902
903/* ***************************************************************
904
905 Las siguientes rutinas implantan la versión mejorada de Kozo
906 Sugiyama del algoritmo de Walker
907
908*/
909
910/*
911 Busca por profundidad en nodo más a la derecha en el nivel level a
912 partir del árbol con raíz root. Retorna en sum el acumulado de MOD
913 desde root hasta el padre del nodo encontrado.
914
915 Retorna el nodo más a la derecha o nullptr si no existe
916*/
918 long double & sum)
919{
920 sum += MOD(root);
921 for (EepicNode *p = root->get_right_child(); p != nullptr;
922 p = p->get_left_sibling())
923 {
924 if (LEVEL(p) == level)
925 return p;
926
928
929 if (q != nullptr)
930 return q;
931 }
932
933 sum -= MOD(root);
934
935 return nullptr;
936}
937
938/*
939 wrapper de iniciación para llamada recursiva
940*/
942 long double & sum)
943{
944 sum = 0;
945 if (LEVEL(root) == level)
946 return root;
947
949}
950
951
952/*
953 idem al anterior pero para el nodo más a la izquierda
954*/
956 long double & sum)
957{
958 sum += MOD(root);
959 for (EepicNode *p = root->get_left_child(); p != nullptr;
960 p = p->get_right_sibling())
961 {
962 if (LEVEL(p) == level)
963 return p;
964
966
967 if (q != nullptr)
968 return q;
969 }
970
971 sum -= MOD(root);
972
973 return nullptr;
974}
975
976/*
977 wrapper de iniciación para llamada recursiva
978*/
980 long double & sum)
981{
982 sum = 0;
983 if (LEVEL(root) == level)
984 return root;
985
987}
988
989
990/*
991 Esta rutina revisa los subarboles izquierdo de p y verifica que las
992 separaciones de los hermanos izquierdos sean correctas. Por cada nivel,
993 el algoritmo revisa la posicion de la hoja mas a la izquierda de p y la
994 compara con la hoja mas a la derecha de su hermano izquierdo
995 (left_sibling). Si no corresponden a la separacion minima, entonces se
996 realiza los ajustes sobre PRE(p) y MOD(p).
997
998 La rutina maneja el valor total de desplazamiento hacia la derecha
999 denominado compensated.
1000
1001 La rutina asume que los hermanos izquierdos de p y los descendientes
1002 de p ya fueron procesados. Esto es plausible porque los valores de
1003 PRE(p) y MOD(p) son calculados en sufijo.
1004*/
1006{
1007 assert(p->get_left_sibling() != nullptr);
1008 assert(not p->is_leftmost());
1009
1010 /* Procesar cada hermano izquierdo de p */
1011 for (EepicNode *left_sibling = p->get_left_sibling();
1012 left_sibling != nullptr;
1013 left_sibling = left_sibling->get_left_sibling())
1014 {
1015 assert(p->get_parent() == left_sibling->get_parent());
1016 assert(LEVEL(left_sibling) == LEVEL(p));
1017 /*
1018 Tenemos 2 subarboles en los cuales debemos verificar que su
1019 separacion no se sobrelape. El subarbol izquierdo es left_sibling
1020 y el subarbol derecho es p. Inspeccionaremos el extremo derecho de
1021 left_sibling con el extremo derecho de p. Si no estan
1022 adecuadamente separados, entonces alejamos MOD(p) de manera tal
1023 que el ajuste final no los sobrelape. r será el extremo derecho de
1024 left_sibling y l sera el extremo izquierdo en p. l y r siempre se
1025 corresponderan con el mismo nivel. La revision y eventual ajuste
1026 se realiza por cada nivel hasta que se alcance una hoja en
1027 cualquiera de los dos subarboles
1028 */
1029 /* valores acumulados parciales de MOD por cada extremo */
1030 int level = LEVEL(p) + 1;
1031 long double r_sum_mod; /* acumulado de mod del extremo derecho */
1032 long double l_sum_mod; /* acumulado de mod del extremo izquierdo */
1033
1034 /*
1035 Note que en posición r debe estar antes que l. Así que no
1036 confundir el sentido
1037
1038 root
1039 / \
1040 / \
1041 left_sibling p
1042 \ /
1043 \ /
1044 r l
1045 */
1046
1047 EepicNode *r = advance_to_rightmost_in_level(left_sibling, level,
1048 r_sum_mod);
1049 EepicNode *l = advance_to_leftmost_in_level(p, level, l_sum_mod);
1050
1051 /* coordenada x del extremo izquierdo */
1052 /* coordenada x del extremo derecho */
1053 /* distancia minima de separacion entre l
1054 y r */
1055
1056 while (l != nullptr and r != nullptr)
1057 {
1058 // calcula futuras coordenadas de los extremos
1059 const long double rx = PRE(r) + r_sum_mod; // coordenada x de r
1060 const long double lx = PRE(l) + l_sum_mod; // coordenada x de l
1061
1062 const long double current_separation = lx - rx;
1063
1064 if (const long double min_separation = tree_gap + XR(r) + XR(l); current_separation < min_separation)
1065 { /* l y r se están superponiendo */
1066 const long double compensation = min_separation - current_separation;
1067 PRE(p) += compensation;
1068 MOD(p) += compensation;
1069 }
1070
1071 /* avanza al siguiente nivel */
1072 level++; /* proximo nivel a comparar */
1073 r = advance_to_rightmost_in_level(left_sibling, level, r_sum_mod);
1074 l = advance_to_leftmost_in_level(p, level, l_sum_mod);
1075 }
1076 }
1077
1078 // TODO: Ajuste sugerido por Sigiyama causa colisiones entre nodos. Revisar
1079 /*
1080 si p fue desplazado en el paso anterior, entonces es posible que se
1081 forme una brecha desprorporcionada entre p y sus hermanos
1082 izquierdos. Esta fase se encarga de dispersar la brecha de la forma
1083 más uniforme posible entre los hermanos izquierdos de p sin
1084 incluir el más a la izquierda.
1085 */
1086}
1087
1088
1089/*
1090 Esta funcion es invocada por el recorrido sufijo cada vez se visita
1091 un nodo. El rol de la funcion es calcular los valores pre y mod
1092 segun el algoritmo de Walker variante de Sugiyama
1093*/
1094void precompute_x_for_node(EepicNode *p, const int level, const int child)
1095{
1096 if (p->is_leaf() and p->is_leftmost()) // hoja mas a la izquierda
1097 PRE(p) = MOD(p) = 0;
1098 else if (p->is_leaf() and p->is_root()) // p es un árbol de un solo nodo
1099 {
1100 PRE(p) = xgap + WIDTH(p) / 2.0;
1101 MOD(p) = 0;
1102 }
1103 else
1104 {
1105 EepicNode *left_sibling = p->get_left_sibling();
1106
1107 if (p->is_leaf()) // p es hoja y no es el mas izquierdo
1108 {
1109 PRE(p) =
1110 PRE(left_sibling) + xgap + (WIDTH(left_sibling) + WIDTH(p)) / 2.0;
1111 MOD(p) = 0;
1112 }
1113 else // p no es hoja
1114 {
1115 EepicNode *left_child = p->get_left_child();
1116 EepicNode *right_child = p->get_right_child();
1117
1118 if (p->is_leftmost() or p->is_root())
1119 {
1120 PRE(p) = (PRE(left_child) + PRE(right_child)) / 2.0;
1121 MOD(p) = 0;
1122 }
1123 else
1124 {
1125 PRE(p) = PRE(left_sibling) + xgap +
1126 (WIDTH(left_sibling) + WIDTH(p)) / 2.0;
1127 MOD(p) = PRE(p) - (PRE(left_child) + PRE(right_child)) / 2.0;
1128 }
1129 } // fin p no es una hoja
1130 } // fin p es hoja y no es el mas izquierdo */
1131
1132 // colocar numero de nivel e hijo
1133 LEVEL(p) = level;
1134 CHILDNUMBER(p) = child;
1135
1136 if (not p->is_root())
1137 { // guardar el mayor radio de elipse vertical
1138 EepicNode *pp = p->get_parent();
1139 MAXCHILDYR(pp) = std::max(MAXCHILDYR(pp), YR(p));
1140 }
1141
1142 if (not p->is_leftmost() and not p->is_root())
1144}
1145
1146/*
1147 Estos valores son calculados para luego determinar el tama~o del
1148 dibujo -del ambiente picture
1149*/
1150long double x_max = 0; /* maximo centro x visto */
1151long double y_max = 0; /* maximo centro y visto */
1152
1153
1154/*
1155 Esta funcion es invocada por el recorrido prefijo cada vez que se visita
1156 un nodo. Su rol es calcular las coordenadas definitivas x,y
1157
1158 X(P) = suma de MOD desde raíz hasta padre de p + PRE(p)
1159
1160 Y(p) = Y(pp) + YR(pp) + ygap + YR(p) excepto en raíz que es YR(root)
1161*/
1162void
1164{
1165 EepicNode *pp = p->get_parent();
1166
1167 long double parent_sum_mod; /* almacena sum MOD(ascendientes) */
1168
1169 if (pp == nullptr) /* p es la raiz */
1170 {
1171 parent_sum_mod = 0;
1172 YRGAP(p) = YR(p);
1173 Y(p) = YR(p);
1174 }
1175 else
1176 {
1177 parent_sum_mod = SUMMOD(pp);
1178 SUMMOD(p) += parent_sum_mod + MOD(p); /* acumulado para uso de los
1179 hijos de p */
1180 YRGAP(p) = MAXCHILDYR(pp);
1181 Y(p) = Y(pp) + YRGAP(pp) + ygap + MAXCHILDYR(pp);
1182 }
1183
1184 X(p) = PRE(p) + parent_sum_mod; /* posicion definitiva x */
1185
1186 /* verificacion de maxima coordenada x */
1187 if (X(p) + XR(p) > x_max)
1188 x_max = X(p) + XR(p);
1189
1190 /* verificacion de maxima coordenada y */
1191 if (Y(p) + YR(p) > y_max)
1192 y_max = Y(p) + YR(p);
1193}
1194
1195
1196inline
1201
1202
1209
1210
1211/*
1212 La siguiente rutina desplaza un árbol hacia la derecha en una
1213 distancia shift_size puntos
1214*/
1215long double shift_size = 0;
1216
1218{
1219 X(p) += shift_size;
1220}
1221
1222
1224{
1225 /* calcula coordenadas del primer árbol */
1227 h_size = x_max;
1228
1229 /* recorre el resto de arboles pertenecientes a la arborescencia */
1230 for (root = root->get_right_tree(); root != nullptr;
1231 root = root->get_right_tree())
1232 {
1233 /* Desplazamiento del siguiente arbol es respecto al ancho del
1234 arbol anterior */
1235 const long double increment =
1236 XR(root->get_left_tree()) + x_max + tree_gap + XR(root);
1237
1238 /* Desplazamiento es lo anterior mas incremento calculado */
1239 shift_size += increment;
1240
1241 // shift_size += XR(root->get_left_tree()) + x_max + tree_gap + XR(root);
1242
1244
1245 /* desplaza todos los nodos del arbol en shift_size */
1247
1248 h_size += increment;
1249 }
1250 v_size = y_max; /* el mayor entre todos los árboles */
1251}
1252
1253
1255{
1256 static int counter = 0;
1257
1258 if (root == nullptr)
1259 return;
1260
1261 infix_tree(root->get_left_child());
1262 POS(root) = counter++;
1263 infix_tree(root->get_right_sibling());
1264}
1265
1266
1268{
1269 if (root == nullptr)
1270 return;
1271
1272 output << POS(root) << " ";
1273
1274 generate_prefix_traversal(output, root->get_left_child());
1275 generate_prefix_traversal(output, root->get_right_sibling());
1276}
1277
1278
1280{
1281 if (root == nullptr)
1282 return;
1283
1284 generate_infix_traversal(output, root->get_left_child());
1285
1286 output << "\"" << STRING(root) << "\" ";
1287
1288 generate_infix_traversal(output, root->get_right_sibling());
1289}
1290
1291
1293{
1295
1296 output << "start-prefix ";
1297
1299
1300 output << endl
1301 << endl
1302 << "start-key ";
1303
1305
1306 output << endl;
1307}
1308
1310{
1311 time_t t;
1312 time(&t);
1313 output << endl
1314 << "% This LaTeX picture is a tree automatically" << endl
1315 << "% generated by ntreepic program" << endl
1316 << endl
1317 << "% Copyright (C) 2002, 2003, 2004, 2007" << endl
1318 << "% UNIVERSITY of LOS ANDES (ULA)" << endl
1319 << "% Merida - REPUBLICA BOLIVARIANA DE VENEZUELA" << endl
1320 << "% Center of Studies in Microelectronics & Distributed Systems"
1321 << " (CEMISID)" << endl
1322 << "% ULA Computer Science Department" << endl
1323 << endl
1324 << "% Created by Leandro Leon - lrleon@ula.ve" << endl
1325 << endl
1326 << "% This program uses the Sugiyama variation of Walker" << endl
1327 << "% algorithm for general trees drawing" << endl
1328 << endl
1329 << "% You must use epic and eepic latex packages" << endl
1330 << "% in your LaTeX application" << endl
1331 << endl
1332 << "% epic Copyright by Sunil Podar" << endl
1333 << "% eepic Copyright by Conrad Kwok" << endl
1334 << "% LaTeX is a collection of TeX macros created by Leslie Lamport"
1335 << endl
1336 << "% TeX was created by Donald Knuth" << endl
1337 << endl
1338 << "% command line: " << endl
1339 << "% " << command_line << endl
1340 << endl
1341 << "% input file: " << input_file_name << endl
1342 << "% output file: " << output_file_name << endl
1343 << endl
1344 << "% Creation date: " << ctime(&t) << endl
1345 << endl;
1346
1347 if (latex_header)
1348 output << "\\documentclass[11pt]{article}" << endl
1349 << endl
1350 << "\\usepackage{epic}" << endl
1351 << "\\usepackage{eepic}" << endl
1352 << endl
1353 << "\\begin{document}" << endl
1354 << "\\begin{center}" << endl;
1355
1356 output << endl
1357 << "\\setlength{\\unitlength}{" << resolution << "mm}" << endl
1358 << "\\filltype{" << fill_type << "}" << endl
1359 << endl
1360 << "\\begin{picture}(" << h_size << "," << v_size << ")"
1361 << "(" << x_picture_offset << "," << y_picture_offset << ")" << endl;
1362}
1363
1364
1366{
1367 output << endl
1368 << endl
1369 << "\\end{picture}" << endl;
1370
1371 if (latex_header)
1372 output << endl
1373 << "\\end{center}" << endl
1374 << "\\end{document}" << endl;
1375}
1376
1378
1379
1380/*
1381 Hay cuatro casos
1382
1383 x
1384
1385 (1) src ------- tgt
1386
1387 (2)
1388 tgt
1389 x /
1390 /
1391 /
1392 src
1393
1394 (3)
1395 src
1396 \
1397 \ x
1398 \
1399 tgt
1400
1401 (4) src
1402 |
1403 | x
1404 |
1405 tgt
1406
1407 La rutina genera una curva src--x--tgt. El punto x se determina según
1408 que el parámetro left sea true o false. En los casos pictorizados
1409 left==true
1410
1411 La primera parte de la rutina determina src y tgt
1412
1413*/
1414void generate_curve(ofstream & output,
1415 EepicNode *p,
1416 EepicNode *q,
1417 const bool left = false,
1418 const bool is_dashed = true)
1419{
1420 const long double & px = X(p); // coordenadas de p
1421 const long double & py = Y(p);
1422
1423 const long double & qx = X(q); // coordenadas de q
1424 const long double & qy = Y(q);
1425
1426 long double srcx, srcy, // punto origen
1427 mx, my, // punto intermedio
1428 tgtx, tgty; // punto destino
1429
1430 EepicNode *src, *tgt; // puntos origen y destino
1431
1432 // determinación de puntos inicial y final
1433 if (px < qx)
1434 {
1435 src = p;
1436 tgt = q;
1437 srcx = px;
1438 srcy = py;
1439 tgtx = qx;
1440 tgty = qy;
1441 }
1442 else
1443 {
1444 src = q;
1445 tgt = p;
1446 srcx = qx;
1447 srcy = qy;
1448 tgtx = px;
1449 tgty = py;
1450 }
1451
1452 // determinación de punto medio
1453 if (fabsl(srcx - tgtx) < hr) // caso (4) ?
1454 {
1455 my = (srcy + tgty) / 2.0;
1456
1457 if (left)
1458 {
1459 srcx -= XR(src);
1460 tgtx -= XR(tgt);
1461 mx = srcx - xgap / 2.5;
1462 }
1463 else
1464 {
1465 srcx += XR(src);
1466 tgtx += XR(tgt);
1467 mx = srcx + xgap / 2.5;
1468 }
1469 }
1470 else if (fabsl(srcy - tgty) < vr) // caso (1)
1471 {
1472 mx = (srcx + tgtx) / 2.0;
1473 srcx += XR(src);
1474 tgtx -= XR(tgt);
1475 my = srcy + (left ? -ygap : ygap) / 2.0;
1476 }
1477 else
1478 {
1479 srcx += XR(src);
1480 tgtx -= XR(tgt);
1481
1482 const long double xfourth = (tgtx - srcx) / 4.0;
1483
1484 if (tgty < srcy) // caso (2)
1485 {
1486 const long double yfourth = (srcy - tgty) / 4.0;
1487
1488 if (left)
1489 {
1490 mx = srcx + xfourth;
1491 my = tgty + 3.0 * yfourth;
1492 }
1493 else
1494 {
1495 mx = srcx + 3.0 * xfourth;
1496 my = tgty + yfourth;
1497 }
1498
1499 assert(my <= srcy and my >= tgty);
1500 }
1501 else // caso (3)
1502 {
1503 const long double yfourth = (tgty - srcy) / 4.0;
1504
1505 if (left)
1506 {
1507 mx = srcx + 3.0 * xfourth;
1508 my = srcy + 3.0 * yfourth;
1509 }
1510 else
1511 {
1512 mx = srcx + xfourth;
1513 my = srcy + yfourth;
1514 }
1515
1516 assert(my >= srcy and my <= tgty);
1517 }
1518
1519 assert(mx >= srcx and mx <= tgtx);
1520 }
1521
1522 output << "\\linethickness{0.05mm}" << endl;
1523
1524 if (is_dashed)
1525 output << "\\curvedashes[1mm]{1,1}" << endl;
1526
1527 output << "\\curve(" << srcx << "," << YPIC(srcy) << ","
1528 << mx << "," << YPIC(my) << ","
1529 << tgtx << "," << YPIC(tgty) << ")";
1530}
1531
1532void generate_tree(ofstream & output, EepicNode *p, int level, int child_index)
1533{
1534 if (p == nullptr)
1535 return;
1536
1537 if (p->is_root())
1538 output << endl
1539 << "% This the tree number " << tree_number++
1540 << " inside a forest ";
1541
1542 assert(LEVEL(p) == level and CHILDNUMBER(p) == child_index);
1543
1544 long double x = X(p);
1545 long double y = Y(p);
1546
1547 /* Imprimir comentario cabecera de nodo */
1548 output << endl
1549 << endl
1550 << "% Node at level " << level << ". It's the "
1551 << child_index << " child with key = " << STRING(p);
1552
1553 /* dibujar nodo */
1554 if (not not_nodes and not WITHOUTNODE(p))
1555 {
1556 output << endl;
1557 if (ISELLIPSE(p))
1558 output << "% Ellipse" << endl
1559 << "\\put(" << x << "," << YPIC(y) << ")"
1560 << (SHADOW(p) ? "{\\ellipse*{" : "{\\ellipse{") << WIDTH(p)
1561 << "}{" << HEIGHT(p) << "}}";
1562 else
1563 output << "% Rectangle" << endl
1564 << "\\path(" << x - XR(p) << "," << YPIC(y - YR(p)) << ")"
1565 << "(" << x + XR(p) << "," << YPIC(y - YR(p)) << ")"
1566 << "(" << x + XR(p) << "," << YPIC(y + YR(p)) << ")"
1567 << "(" << x - XR(p) << "," << YPIC(y + YR(p)) << ")"
1568 << "(" << x - XR(p) << "," << YPIC(y - YR(p)) << ")";
1569 } { /* imprimir el contenido del nodo */
1570 long double dx = center_string(STRING(p), WIDTH(p));
1571 put_string(output, x - dx + XOFFSET(p), y + y_offset + YOFFSET(p),
1572 "Key text= " + STRING(p), STRING(p));
1573 }
1574
1575 /* imprimir las etiquetas -TAGs- del nodo */
1576 if (not TAGS(p).is_empty())
1577 {
1578 long double tx, ty; /* coordenadas de la tag */
1579 Tag_Data tag_data;
1580 long double r = std::max(XR(p), YR(p)) + 2.0 / resolution; // 2mm
1581 long double dr = sin_45 * r; /* radius r at 45 degrees */
1582 long double dy = font_height();
1583 string comment;
1584
1585 for (DynDlist<Tag_Data>::Iterator itor(TAGS(p));
1586 itor.has_curr(); itor.next())
1587 {
1588 tag_data = itor.get_curr();
1589
1590 switch (tag_data.tag_option)
1591 {
1592 case NORTH:
1593 comment = "North tag: ";
1594 tx = x + tag_data.x_offset;
1595 ty = y - r + tag_data.y_offset;
1596 break;
1597 case SOUTH:
1598 comment = "South tag: ";
1599 tx = x + tag_data.x_offset;
1600 ty = y + r + tag_data.y_offset + dy;
1601 break;
1602 case EAST:
1603 comment = "East tag: ";
1604 tx = x + r + tag_data.x_offset;
1605 ty = y + tag_data.y_offset;
1606 break;
1607 case WEST:
1608 comment = "West tag: ";
1609 tx = x - r + tag_data.x_offset - string_width(tag_data.tag);
1610 ty = y + tag_data.y_offset;
1611 break;
1612 case NORTH_EAST:
1613 comment = "Northeast tag: ";
1614 tx = x + dr + tag_data.x_offset;
1615 ty = y - dr + tag_data.y_offset;
1616 break;
1617 case NORTH_WEST:
1618 comment = "Northwest tag: ";
1619 tx = x - dr + tag_data.x_offset - string_width(tag_data.tag);
1620 ty = y - dr + tag_data.y_offset;
1621 break;
1622 case SOUTH_EAST:
1623 comment = "Southeast tag: ";
1624 tx = x + dr + tag_data.x_offset;
1625 ty = y + dr + tag_data.y_offset;
1626 break;
1627 case SOUTH_WEST:
1628 comment = "Southwest tag: ";
1629 tx = x - dr + tag_data.x_offset - string_width(tag_data.tag);
1630 ty = y + dr + tag_data.y_offset;
1631 break;
1632 default:
1633 print_parse_error_and_exit("Fatal: unexpected tag option");
1634 }
1635 put_string(output, tx, ty, comment + tag_data.tag, tag_data.tag);
1636 }
1637 }
1638
1639 /* Dibujar arcos adicionales declarados con opción ARC o DASHED-ARC */
1640 for (DynDlist<Arc_Data>::Iterator itor(ARCS(p)); itor.has_curr();
1641 itor.next())
1642 {
1643 Arc_Data arc_data = itor.get_curr();
1644
1645 long double lx = X(arc_data.target_node);
1646 long double ly = Y(arc_data.target_node);
1647 long double src_dx, src_dy; // diferencias con nodo origen
1648 if (ISELLIPSE(p))
1649 intersection_ellipse_line(x, y, lx, ly, XR(p), YR(p),
1650 src_dx, src_dy);
1651 else
1652 intersection_rectangle_line(x, y, lx, ly, XR(p), YR(p),
1653 src_dx, src_dy);
1654 long double tgt_dx, tgt_dy; // diferencias con nodo destino
1655 if (ISELLIPSE(arc_data.target_node))
1656 intersection_ellipse_line(lx, ly, x, y, XR(arc_data.target_node),
1657 YR(arc_data.target_node), tgt_dx, tgt_dy);
1658 else
1659 intersection_rectangle_line(lx, ly, x, y, XR(arc_data.target_node),
1660 YR(arc_data.target_node), tgt_dx, tgt_dy);
1661 if (lx < x)
1662 src_dx = -src_dx;
1663 else
1664 tgt_dx = -tgt_dx;
1665
1666 /* dibujar arco adicional */
1667 output << endl
1668 << "% Additional arc to child with key " <<
1669 STRING(arc_data.target_node) << endl;
1670 draw_arc(output, x + src_dx, y + src_dy, lx + tgt_dx, ly - tgt_dy,
1671 arc_data.is_dashed, with_arrow);
1672 }
1673
1676
1677 // dibujar conexiones
1679 itor.has_curr(); itor.next())
1680 {
1681 Connexion_Data connexion_data = itor.get_curr();
1682
1683 generate_curve(output, p, connexion_data.target_node,
1684 connexion_data.is_left);
1685
1686# ifdef tmp
1687
1689 output << "\\curve(" << x - dx << "," << YPIC(y + dy) << ","
1690 << px + dx << "," << YPIC(y + h) << ","
1691 << px + dx << "," << YPIC(py + dy) << ")";
1692
1693# endif
1694 }
1695
1696
1698 /* dibujar arcos correspondientes a hijos y visitarlos */
1699 for (EepicNode *c = p->get_left_child(); c != nullptr;
1700 c = c->get_right_sibling())
1701 {
1702 if (WITHARC(c))
1703 { /* dibujar arco */
1704 long double lx = X(c);
1705 long double ly = Y(c);
1706 long double src_dx, src_dy; // diferencias con nodo origen
1707 if (ISELLIPSE(p))
1708 intersection_ellipse_line(x, y, lx, ly, XR(p), YR(p),
1709 src_dx, src_dy);
1710 else
1711 intersection_rectangle_line(x, y, lx, ly, XR(p), YR(p),
1712 src_dx, src_dy);
1713 long double tgt_dx, tgt_dy; // diferencias con nodo destino
1714 if (ISELLIPSE(c))
1715 intersection_ellipse_line(lx, ly, x, y, XR(c), YR(c),
1716 tgt_dx, tgt_dy);
1717 else
1718 intersection_rectangle_line(lx, ly, x, y, XR(c), YR(c),
1719 tgt_dx, tgt_dy);
1720 if (lx < x)
1721 src_dx = -src_dx;
1722 else
1723 tgt_dx = -tgt_dx;
1724
1725 output << endl
1726 << "% Arc to child " << CHILDNUMBER(c)
1727 << " with key " << STRING(c) << endl;
1728
1729 draw_arc(output, x + src_dx, y + src_dy, lx + tgt_dx, ly - tgt_dy,
1730 DASHEDARC(c), with_arrow);
1731 }
1732
1733 /* ahora dibuje recursivamente el proximo nodo */
1734 generate_tree(output, c, level + 1, CHILDNUMBER(c));
1735 }
1736 else
1737 {
1738 EepicNode *c = p->get_left_child();
1739 if (c != nullptr)
1740 {
1741 long double lx = X(c);
1742 long double ly = Y(c);
1743 long double src_dx, src_dy; // diferencias con nodo origen
1744 if (ISELLIPSE(p))
1745 intersection_ellipse_line(x, y, lx, ly, XR(p), YR(p),
1746 src_dx, src_dy);
1747 else
1748 intersection_rectangle_line(x, y, lx, ly, XR(p), YR(p),
1749 src_dx, src_dy);
1750 long double tgt_dx, tgt_dy; // diferencias con nodo destino
1751 if (ISELLIPSE(c))
1752 intersection_ellipse_line(lx, ly, x, y, XR(c), YR(c),
1753 tgt_dx, tgt_dy);
1754 else
1755 intersection_rectangle_line(lx, ly, x, y, XR(c), YR(c),
1756 tgt_dx, tgt_dy);
1757 if (lx < x)
1758 src_dx = -src_dx;
1759 else
1760 tgt_dx = -tgt_dx;
1761
1762 output << endl
1763 << "% link to leftmost child " << CHILDNUMBER(c)
1764 << " with key " << STRING(c) << endl;
1765
1766 draw_arc(output, x + src_dx, y + src_dy, lx + tgt_dx, ly - tgt_dy,
1767 DASHEDARC(c), with_arrow);
1768
1769 /* ahora dibuje recursivamente el proximo nodo */
1770 generate_tree(output, c, level + 1, CHILDNUMBER(c));
1771 }
1772
1773 if (EepicNode *rs = p->get_right_sibling(); rs != nullptr)
1774 {
1775 long double rx = X(rs);
1776 long double ry = Y(rs);
1777 long double src_dx, src_dy; // diferencias con nodo origen
1778 if (ISELLIPSE(p))
1779 intersection_ellipse_line(x, y, rx, ry, XR(p), YR(p),
1780 src_dx, src_dy);
1781 else
1782 intersection_rectangle_line(x, y, rx, ry, XR(p), YR(p),
1783 src_dx, src_dy);
1784 long double tgt_dx, tgt_dy; // diferencias con nodo destino
1785 if (ISELLIPSE(rs))
1786 intersection_ellipse_line(rx, ry, x, y, XR(rs), YR(rs),
1787 tgt_dx, tgt_dy);
1788 else
1789 intersection_rectangle_line(rx, ry, x, y, XR(rs), YR(rs),
1790 tgt_dx, tgt_dy);
1791 if (rx < x)
1792 src_dx = -src_dx;
1793 else
1794 tgt_dx = -tgt_dx;
1795
1796 output << endl
1797 << "% link to right sibling " << child_index + 1
1798 << " with key " << STRING(rs) << endl;
1799
1800 draw_arc(output, x + src_dx, y + src_dy, rx + tgt_dx, ry - tgt_dy,
1801 DASHEDARC(rs), with_arrow);
1802
1803 /* ahora dibuje recursivamente el proximo nodo */
1804 generate_tree(output, rs, level, CHILDNUMBER(rs));
1805 }
1806 }
1807
1808 if (p->is_root())
1809 /* avance al proximo arbol dentro de la arborescencia */
1810 generate_tree(output, p->get_right_tree(), 0, 0);
1811}
1812
1813
1820
1821
1823 "ntreepic 1.7 - ALEPH drawer for general rooted trees\n"
1824 "Copyright (C) 2004, 2007 UNIVERSITY of LOS ANDES (ULA)\n"
1825 "Merida - REPUBLICA BOLIVARIANA DE VENEZUELA\n"
1826 "Center of Studies in Microelectronics & Distributed Systems (CEMISID)\n"
1827 "ULA Computer Science Department\n"
1828 "This is free software; There is NO warranty; not even for MERCHANTABILITY\n"
1829 "or FITNESS FOR A PARTICULAR PURPOSE\n"
1830 "\n";
1831
1832
1833const char *argp_program_bug_address = "lrleon@ula.ve";
1834
1835
1836static char doc[] = "ntreepic -- Aleph drawer for general rooted trees";
1837
1838
1839static char arg_doc[] = "-f input-file [-o output-file]\n";
1840
1841
1842static const char *hello =
1843 "ALEPH drawer for general rooted trees\n"
1844 "Copyright (C) 2004, 2007 University of Los Andes (ULA)\n"
1845 "Merida - REPUBLICA BOLIVARIANA DE VENEZUELA\n"
1846 "Center of Studies in Microelectronics & Distributed Systems (CEMISID)\n"
1847 "ULA Computer Science Department\n"
1848 "This is free software; There is NO warranty; not even for MERCHANTABILITY\n"
1849 "or FITNESS FOR A PARTICULAR PURPOSE\n"
1850 "\n";
1851
1852
1853static const char license_text[] =
1854 "ALEPH drawer for general rooted trees. License & Copyright Note\n"
1855 "Copyright (C) 2004, 2007\n"
1856 "UNIVERSITY of LOS ANDES (ULA)\n"
1857 "Merida - REPUBLICA BOLIVARIANA DE VENEZUELA\n"
1858 "Center of Studies in Microelectronics & Distributed Systems (CEMISID)\n"
1859 "ULA Computer Science Department\n"
1860 "This is free software; There is NO warranty; not even for MERCHANTABILITY\n"
1861 "or FITNESS FOR A PARTICULAR PURPOSE\n"
1862 "\n"
1863 " PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE AND ITS \n"
1864 " DOCUMENTATION IS HEREBY GRANTED, PROVIDED THAT BOTH THE COPYRIGHT \n"
1865 " NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES OF THE \n"
1866 " SOFTWARE, DERIVATIVE WORKS OR MODIFIED VERSIONS, AND ANY PORTIONS \n"
1867 " THEREOF, AND THAT BOTH NOTICES APPEAR IN SUPPORTING DOCUMENTATION. \n"
1868 "\n"
1869 " This program is distributed in the hope that it will be useful,\n"
1870 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1871 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n"
1872 "\n"
1873 " ULA requests users of this software to return to \n"
1874 " Proyecto Aleph - CEMISID Software\n"
1875 " Nucleo Universitario La Hechicera. Ed Ingenieria\n"
1876 " 3er piso, ala Este \n"
1877 " Universidad de Los Andes \n"
1878 " Merida 5101 - REPUBLICA BOLIVARIANA DE VENEZUELA \n"
1879 "\n"
1880 " or to lrleon@ula.ve \n"
1881 "\n"
1882 " any improvements or extensions that they make and grant Universidad \n"
1883 " de Los Andes (ULA) the full rights to redistribute these changes. \n"
1884 "\n"
1885 " This program was granted by: \n"
1886 " - Consejo de Desarrollo Cientifico, Humanistico, Tecnico de la ULA\n"
1887 " (CDCHT)\n";
1888
1889
1890static struct argp_option options[] = {
1891 {"radius", 'r', "radius", OPTION_ARG_OPTIONAL, "fit radius for circles", 0},
1892 {"x-gap", 'w', "sibling gap", OPTION_ARG_OPTIONAL, "sibling separation", 0},
1893 {"y-gap", 'h', "children gap", OPTION_ARG_OPTIONAL, "child separation", 0},
1894 {"t-gap", 't', "tree gap", OPTION_ARG_OPTIONAL, "subtree separation", 0},
1895 {
1896 "bin-tree", 'b', "binary tree", OPTION_ARG_OPTIONAL,
1897 "generate binary tree", 0
1898 },
1899 {
1900 "h-radius", 'x', "horizontal-radius", OPTION_ARG_OPTIONAL,
1901 "horizontal radius", 0
1902 },
1903 {
1904 "v-radius", 'y', "vertical-radius", OPTION_ARG_OPTIONAL,
1905 "vertical radius", 0
1906 },
1907 {"resol", 'l', "resolution", OPTION_ARG_OPTIONAL, "resolution in mm", 0},
1908 {"latex", 'a', 0, OPTION_ARG_OPTIONAL, "add latex header", 0},
1909 {"no-node", 'n', 0, OPTION_ARG_OPTIONAL, "no draw nodes; only arcs", 0},
1910 {
1911 "key-x-offset", 'X', "offset", OPTION_ARG_OPTIONAL,
1912 "horizontal offset for keys", 0
1913 },
1914 {
1915 "key-y-offset", 'Y', "offset", OPTION_ARG_OPTIONAL,
1916 "vertical offset for keys", 0
1917 },
1918 {"input-file", 'i', "input-file", 0, "input file", 0},
1919 {"input-file", 'f', "input-file", OPTION_ALIAS, 0, 0},
1920 {"output", 'o', "output-file", 0, "output file", 0},
1921 {"license", 'C', 0, OPTION_ARG_OPTIONAL, "print license", 0},
1922 {
1923 "x-picture-offset", 'O', "horizontal-picture-offset",
1924 OPTION_ARG_OPTIONAL, "horizontal global picture offset", 0
1925 },
1926 {
1927 "y-picture-offset", 'P', "vertical-picture-offset",
1928 OPTION_ARG_OPTIONAL, "vertical global picture offset", 0
1929 },
1930 {"print", 'R', 0, OPTION_ARG_OPTIONAL, "print current parameters", 0},
1931 {"verbose", 'v', 0, OPTION_ARG_OPTIONAL, "verbose mode", 0},
1932 {
1933 "version", 'V', 0, OPTION_ARG_OPTIONAL,
1934 "Print version information and then exit", 0
1935 },
1936 {"black-fill", 'B', 0, OPTION_ARG_OPTIONAL, "Fill black ellipses", 0},
1937 {"shade-fill", 'S', 0, OPTION_ARG_OPTIONAL, "Fill shade ellipses", 0},
1938 {"ellipses", 'e', 0, OPTION_ARG_OPTIONAL, "draw ellipses as nodes", 0},
1939 {"rectangles", 'q', 0, OPTION_ARG_OPTIONAL, "draw rectangles as nodes", 0},
1940 {
1941 "draw-list", 'L', 0, OPTION_ARG_OPTIONAL,
1942 "draw linked list representation", 0
1943 },
1944 {
1945 "draw-tree", 'T', 0, OPTION_ARG_OPTIONAL,
1946 "draw normal tree representation (or turn off linked list form)", 0
1947 },
1948 {
1949 "arrow-len", 'K', "arrow lenght in points", OPTION_ARG_OPTIONAL,
1950 "arrow lenght", 0
1951 },
1952 {
1953 "arrow-width", 'I', "arrow width in points", OPTION_ARG_OPTIONAL,
1954 "arrow width", 0
1955 },
1956 {"arrows", 'A', 0, OPTION_ARG_OPTIONAL, "draw arcs with arrows", 0},
1957 {"vertical-flip", 'F', 0, OPTION_ARG_OPTIONAL, "Flip tree respect y axe", 0},
1958 {0, 0, 0, 0, 0, 0}
1959 };
1960
1961
1962# define TERMINATE(n) (save_parameters(), exit(n))
1963
1964
1965const char *parameters_file_name = "./.ntreepic";
1966
1967
1968inline
1970{
1971 ofstream output(parameters_file_name, ios::trunc);
1972
1973 output << hr << BLANK << vr << BLANK << hd << BLANK << vd << BLANK
1974 << xgap << BLANK << ygap << BLANK << tree_gap << BLANK
1975 << resolution << BLANK << x_offset << BLANK << y_offset << BLANK
1977}
1978
1979
1980inline
1982{
1983 ifstream input(parameters_file_name, ios::in);
1984
1985 input >> hr >> vr >> hd >> vd >> xgap >> ygap >> tree_gap >> resolution
1987}
1988
1989
1990inline
1992{
1993 cout
1994 << "Global horizontal node radius -x = " << hr << endl
1995 << "Global vertical node radius -y = " << vr << endl
1996 << "Global horizontal node diameter = " << hd << endl
1997 << "Global Vertical node diameter = " << vd << endl
1998 << "Horizontal sibling separation -w = " << xgap << endl
1999 << "Vertical children separation -h = " << ygap << endl
2000 << "Subtree separation -t = " << tree_gap << endl
2001 << "Resolution in mm -l = " << resolution << endl
2002 << "Horizontal global offset for key -X = " << x_offset << endl
2003 << "Vertical global offset for key -Y = " << y_offset << endl
2004 << "Horizontal offset for picture -O = " << x_picture_offset << endl
2005 << "Vertical offset for picture -P = " << y_picture_offset << endl;
2006}
2007
2008
2009static error_t parser_opt(int key, char *arg, struct argp_state *)
2010{
2011 switch (key)
2012 {
2013 case 'r': /* Especificacion de radio */
2014 if (arg == nullptr)
2015 AH_ERROR("Waiting for radius in command line");
2016 hr = vr = atof(arg);
2017 hd = vd = 2 * hr;
2018 break;
2019 case 'w': /* brecha entre hermanos */
2020 if (arg == nullptr)
2021 AH_ERROR("Waiting for sibling gap in command line");
2022 xgap = atof(arg);
2023 break;
2024 case 'h': /* brecha entre hermanos */
2025 if (arg == nullptr)
2026 AH_ERROR("Waiting for sibling gap in command line");
2027 ygap = atof(arg);
2028 break;
2029 case 't': /* brecha entre subárboles */
2030 if (arg == nullptr)
2031 AH_ERROR("Waiting for tree gap in command line");
2032 tree_gap = atof(arg);
2033 break;
2034 case 'x': /* radio horizontal de elipse */
2035 if (arg == nullptr)
2036 AH_ERROR("Waiting for horizontal radius in command line");
2037 hr = atof(arg);
2038 hd = 2 * hr;
2039 break;
2040 case 'y': /* radio vertical de elipse */
2041 if (arg == nullptr)
2042 AH_ERROR("Waiting for vertical radius in command line");
2043 vr = atof(arg);
2044 vd = 2 * vr;
2045 break;
2046 case 'l': /* resolucion en milimetros */
2047 if (arg == nullptr)
2048 AH_ERROR("Waiting for resolution in command line");
2049 resolution = atof(arg);
2050 if (resolution > 10)
2051 cout << "Warning: resolution too big" << endl;
2052 break;
2053 case 'a': /* colocar un encabezado latex */
2054 latex_header = true;
2055 break;
2056 case 'n': /* no dibuja nodos, solo arcos */
2057 hr = vr = resolution / 2;
2058 hd = vd = resolution;
2059 not_nodes = true;
2060 break;
2061 case 'X': /* offset horizontal para letras */
2062 if (arg == nullptr)
2063 AH_ERROR("Waiting for horizontal offset in command line");
2064 x_offset = atof(arg);
2065 break;
2066 case 'Y': /* offset vertical para letras */
2067 if (arg == nullptr)
2068 AH_ERROR("Waiting for vertical offset in command line");
2069 y_offset = atof(arg);
2070 break;
2071 case 'O': /* offset horizontal para dibujo */
2072 if (arg == nullptr)
2073 AH_ERROR("Waiting for horizontal offset in command line");
2074 x_picture_offset = atof(arg);
2075 break;
2076 case 'P': /* offset vertical para dibujo */
2077 if (arg == nullptr)
2078 AH_ERROR("Waiting for vertical offset in command line");
2079 y_picture_offset = atof(arg);
2080 break;
2081 case 'v': /* verbose mode (no implementado) */
2082 break;
2083 case 'i': /* archivo de entrada */
2084 case 'f':
2085 {
2086 if (arg == nullptr)
2087 AH_ERROR("Waiting for input file name");
2088 input_file_name = arg;
2089 break;
2090 }
2091 case 'o': /* archivo de salida */
2092 if (arg == nullptr)
2093 AH_ERROR("Waiting for output file name");
2094 output_file_name = arg;
2095 break;
2096 case 'b': /* generar árbol binario */
2097 generate_binary_tree = true;
2098 break;
2099 case 'C': /* imprime licencia */
2100 cout << license_text;
2101 TERMINATE(0);
2102 break;
2103 case 'R': /* imprime parametros */
2106 TERMINATE(0);
2107 break;
2108 case 'V': /* imprimir version */
2109 cout << argp_program_version;
2110 TERMINATE(0);
2111 break;
2112 case 'B': /* filltype == black */
2113 fill_type = "black";
2114 break;
2115 case 'S': /* filltype == shade */
2116 fill_type = "shade";
2117 break;
2118 case 'e': /* draw ellipses as nodes */
2119 ellipses = true;
2120 rectangles = false;
2121 break;
2122 case 'q': /* draw ellipses as nodes */
2123 ellipses = false;
2124 rectangles = true;
2125 break;
2126 case 'L': /* draw linked list representation */
2128 with_arrow = true;
2129 break;
2130 case 'T': /* draw forest (no list representation) */
2132 break;
2133 case 'A':
2134 with_arrow = true;
2135 break;
2136 case 'K':
2137 with_arrow = true;
2138 if (arg == nullptr)
2139 AH_ERROR("Waiting for arrow lenght in command line");
2140 arrow_lenght = atof(arg);
2141 break;
2142 case 'I':
2143 with_arrow = true;
2144 if (arg == nullptr)
2145 AH_ERROR("Waiting for arrow width in command line");
2146 arrow_width = atof(arg);
2147 break;
2148 case 'F':
2149 flip_y = true;
2150 break;
2151 default: return ARGP_ERR_UNKNOWN;
2152 }
2153 return 0;
2154}
2155
2156
2157static struct argp arg_defs = {options, parser_opt, arg_doc, doc, 0, 0, 0};
2158
2159int main(int argc, char *argv[])
2160{
2161 if (argc == 1)
2162 {
2163 cout <<
2164 "ntreepic -- General rooted tree visualizer (LaTeX/eepic output)\n"
2165 "\n"
2166 "Reads a textual general rooted tree description (.Tree file) and emits\n"
2167 "LaTeX code using eepic drawing primitives, suitable for inclusion in\n"
2168 "publication-quality documents. Supports n-ary trees, forests, and\n"
2169 "linked-list representations.\n"
2170 "\n"
2171 "Usage:\n"
2172 " ntreepic -f <input.Tree> [-o <output.eepic>] [options]\n"
2173 " ntreepic -i <input.Tree> [-o <output.eepic>] [options]\n"
2174 "\n"
2175 "Required:\n"
2176 " -f, -i <file> Input .Tree file\n"
2177 "\n"
2178 "Common options:\n"
2179 " -o <file> Output file (default: input name + .eepic)\n"
2180 " -r <double> Node circle radius (sets horizontal and vertical)\n"
2181 " -x <double> Horizontal radius of node ellipse\n"
2182 " -y <double> Vertical radius of node ellipse\n"
2183 " -w <double> Horizontal gap between siblings\n"
2184 " -h <double> Vertical gap between levels\n"
2185 " -t <double> Gap between subtrees\n"
2186 " -l <double> Resolution in mm\n"
2187 " -a Wrap output in a full LaTeX header\n"
2188 " -e Draw nodes as ellipses (default)\n"
2189 " -q Draw nodes as rectangles\n"
2190 " -n Minimum-radius mode (no node bodies, arcs only)\n"
2191 " -b Emit textual start-prefix/start-key representation of binary tree (via generate_bin_tree())\n"
2192 " -L Draw linked-list representation (with arrows)\n"
2193 " -T Draw forest layout (no linked-list representation)\n"
2194 " -A Draw arcs with arrows\n"
2195 " -B Fill nodes with black\n"
2196 " -S Fill nodes with shade\n"
2197 " -F Flip tree along the y axis\n"
2198 " -X <double> Horizontal label offset\n"
2199 " -Y <double> Vertical label offset\n"
2200 " -O <double> Horizontal global picture offset\n"
2201 " -P <double> Vertical global picture offset\n"
2202 " -R Print current parameters and exit\n"
2203 " -V Print version and exit\n"
2204 " -C Print license and exit\n"
2205 "\n"
2206 "Example:\n"
2207 " ntreepic -f mytree.Tree -o mytree.eepic -a -e\n"
2208 "\n"
2209 "Run 'ntreepic --help' for the complete list of options.\n";
2210 return 0;
2211 }
2212
2214
2216
2217 argp_parse(&arg_defs, argc, argv, ARGP_IN_ORDER, 0, nullptr);
2218
2219 if (input_file_name.size() == 0)
2220 AH_ERROR("Input file not given");
2221
2222 ifstream input_stream(input_file_name.c_str(), ios::in);
2223
2224 if (not input_stream)
2225 AH_ERROR("%s file does not exist", input_file_name.c_str());
2226
2227 cout << hello;
2228
2229 cout << "input from " << input_file_name << " file " << endl;
2230
2231 if (output_file_name.size() == 0)
2232 {
2234 const int pos = input_file_name.rfind(".");
2235 if (pos != string::npos)
2237 string(input_file_name).replace(pos, input_file_name.size() - pos,
2238 string(""));
2239 output_file_name = output_file_name + (tiny_keys ? ".eepicaux" : ".eepic");
2240 }
2241
2242 ofstream output_stream(output_file_name.c_str(), ios::out);
2243
2244 cout << "output sent to " << output_file_name << " file " << endl << endl;
2245
2246 EepicNode *root = read_input_and_build_tree(input_stream);
2247
2249 generate_bin_tree(output_stream, root);
2250 else
2251 {
2253
2254 generate_forest(output_stream, root);
2255 }
2256
2258
2260}
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:611
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Definition ah-errors.H:787
#define AH_ERROR(...)
Print an error message (always enabled).
Definition ahDefs.H:270
int main()
Token_Type
Definition btreepic.C:166
bool dash_threaded_trees
Definition btreepic.C:423
long double h
Definition btreepic.C:154
Iterator dynamic list.
Dynamic doubly linked list with O(1) size and bidirectional access.
Forward declaration used by CRTP helpers before the full node definition.
bool tiny_keys
Global flag to enable tiny font size for keys/labels.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Definition gmpfrxx.h:4138
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
void tree_postorder_traversal(Node *root, void(*visitFct)(Node *, int, int))
Postorder traversal of a tree.
void tree_preorder_traversal(Node *root, void(*visitFct)(Node *, int, int))
Preorder traversal of a tree.
Node * deway_search(Node *root, int path[], const size_t &size)
Returns a node of a forest given its Dewey number.
static mpfr_t y
Definition mpfr_mul_d.c:3
void init_token_scanning()
Initialize token scanning by recording current position.
void close_token_scanning(const char *buffer, char *&start_addr, const char *end_addr)
Finalize token scanning by null-terminating and saving the token.
int read_char_from_stream(std::ifstream &input_stream)
Read a single character from an input stream with position tracking.
void print_parse_error_and_exit(const std::string &str)
Print a parse error message and terminate the program.
and
Check uniqueness with explicit hash + equality functors.
void put_char_in_buffer(char *&start_addr, const char *end_addr, int c)
Append a character to a buffer with bounds checking.
std::string command_line_to_string(int argc, char *argv[])
Convert command line arguments to a single string.
void skip_white_spaces(std::ifstream &input_stream)
Skip whitespace characters in the input stream.
constexpr size_t Buffer_Size
Default buffer size for token parsing.
std::string load_string(std::ifstream &input_stream)
Load a string from the input stream.
void print_parse_warning(const std::string &str)
Print a parse warning message.
long load_number(std::ifstream &input_stream)
Load an integer number from the input stream.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
STL namespace.
void parse_rectangle(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:805
EepicNode * __advance_to_leftmost_in_level(EepicNode *root, const int level, long double &sum)
Definition ntreepic.C:955
EepicNode * parse_deway_number(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:567
#define YD(p)
Definition ntreepic.C:356
int tree_number
Definition ntreepic.C:1377
void save_parameters()
Definition ntreepic.C:1969
long double ygap
Definition ntreepic.C:194
void compute_coordinates_for_forest_and_set_picture_size(EepicNode *root)
Definition ntreepic.C:1223
bool draw_list_representation
Definition ntreepic.C:211
const char * parameters_file_name
Definition ntreepic.C:1965
#define MOD(p)
Definition ntreepic.C:346
Token_Type get_token(ifstream &input_stream)
Definition ntreepic.C:424
void generate_tree(ofstream &output, EepicNode *p, int level, int child_index)
Definition ntreepic.C:1532
void adjust_minimal_separation_with_letf_sibling(EepicNode *p)
Definition ntreepic.C:1005
void shift_tree_to_right(EepicNode *p, int, int)
Definition ntreepic.C:1217
#define TAGS(p)
Definition ntreepic.C:370
void parse_xoffset(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:685
bool rectangles
Definition ntreepic.C:210
void generate_forest(ofstream &output, EepicNode *root)
Definition ntreepic.C:1814
void precompute_x_for_node(EepicNode *p, const int level, const int child)
Definition ntreepic.C:1094
#define YRGAP(p)
Definition ntreepic.C:359
void parse_connexion(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:776
static error_t parser_opt(int key, char *arg, struct argp_state *)
Definition ntreepic.C:2009
void precompute_x_coordinates_for_tree(EepicNode *root)
Definition ntreepic.C:1197
#define ISRECTANGLE(p)
Definition ntreepic.C:350
#define SHADOW(p)
Definition ntreepic.C:364
#define DASHEDARC(p)
Definition ntreepic.C:367
@ ARC
Definition ntreepic.C:222
@ DASHED_CONNEXION
Definition ntreepic.C:222
@ NODE
Definition ntreepic.C:221
@ ELLIPSE
Definition ntreepic.C:222
@ HRADIO
Definition ntreepic.C:222
@ VRADIO
Definition ntreepic.C:222
@ SOUTH
Definition ntreepic.C:225
@ SOUTH_WEST
Definition ntreepic.C:231
@ DASHED_ARC
Definition ntreepic.C:222
@ END_FILE
Definition ntreepic.C:223
@ COMMENT
Definition ntreepic.C:223
@ TAG
Definition ntreepic.C:222
@ EAST
Definition ntreepic.C:226
@ NORTH_WEST
Definition ntreepic.C:229
@ WITHOUT_NODE
Definition ntreepic.C:221
@ NORTH
Definition ntreepic.C:224
@ ROOT
Definition ntreepic.C:221
@ NORTH_EAST
Definition ntreepic.C:228
@ SOUTH_EAST
Definition ntreepic.C:230
@ LEFT
Definition ntreepic.C:232
@ RECTANGLE
Definition ntreepic.C:223
@ WEST
Definition ntreepic.C:227
@ RIGHT
Definition ntreepic.C:233
@ INVALID
Definition ntreepic.C:234
@ WITHOUT_ARC
Definition ntreepic.C:221
void generate_curve(ofstream &output, EepicNode *p, EepicNode *q, const bool left=false, const bool is_dashed=true)
Definition ntreepic.C:1414
#define HEIGHT(p)
Definition ntreepic.C:363
#define XD(p)
Definition ntreepic.C:355
EepicNode * parse_first_root_definition(ifstream &input_stream)
Definition ntreepic.C:590
void parse_arc(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:736
void parse_without_arc(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:669
long double y_offset
Definition ntreepic.C:199
#define Y(p)
Definition ntreepic.C:344
long double h_size
Definition ntreepic.C:196
#define WITHOUTNODE(p)
Definition ntreepic.C:365
void generate_epilogue(ofstream &output)
Definition ntreepic.C:1365
void parse_shadow(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:706
void generate_prefix_traversal(ofstream &output, EepicNode *root)
Definition ntreepic.C:1267
long double hr
Definition ntreepic.C:189
std::string input_file_name
Definition ntreepic.C:204
#define YOFFSET(p)
Definition ntreepic.C:352
long double vr
Definition ntreepic.C:190
void generate_infix_traversal(ofstream &output, EepicNode *root)
Definition ntreepic.C:1279
#define X(p)
Definition ntreepic.C:343
#define CONNEXIONS(p)
Definition ntreepic.C:369
#define BLANK
Definition ntreepic.C:185
#define POS(p)
Definition ntreepic.C:357
bool latex_header
Definition ntreepic.C:208
long double x_picture_offset
Definition ntreepic.C:200
const char * argp_program_version
Definition ntreepic.C:1822
#define XOFFSET(p)
Definition ntreepic.C:351
void read_parameters()
Definition ntreepic.C:1981
#define LEVEL(p)
Definition ntreepic.C:360
void parse_vradio(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:640
Tree_Node< Tree_Data > EepicNode
Definition ntreepic.C:242
#define ARCS(p)
Definition ntreepic.C:368
EepicNode * read_input_and_build_tree(ifstream &input_stream)
Definition ntreepic.C:814
long double vd
Definition ntreepic.C:192
double v_size
Definition ntreepic.C:197
#define WIDTH(p)
Definition ntreepic.C:362
void parse_ellipse(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:796
bool generate_binary_tree
Definition ntreepic.C:212
long double shift_size
Definition ntreepic.C:1215
EepicNode * parse_key_node_and_allocate(ifstream &input_stream)
Definition ntreepic.C:582
EepicNode * allocate_node(const string &str)
Definition ntreepic.C:555
void parse_yoffset(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:696
static const char license_text[]
Definition ntreepic.C:1853
std::string output_file_name
Definition ntreepic.C:205
#define MAXCHILDYR(p)
Definition ntreepic.C:358
EepicNode * __advance_to_rightmost_in_level(EepicNode *root, const int level, long double &sum)
Definition ntreepic.C:917
#define PRE(p)
Definition ntreepic.C:345
void parse_hradio(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:625
EepicNode * advance_to_leftmost_in_level(EepicNode *root, const int level, long double &sum)
Definition ntreepic.C:979
void parse_node_definition(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:610
#define ISELLIPSE(p)
Definition ntreepic.C:349
long double y_max
Definition ntreepic.C:1151
void parse_without_node(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:655
const char * argp_program_bug_address
Definition ntreepic.C:1833
#define WITHARC(p)
Definition ntreepic.C:366
static char arg_doc[]
Definition ntreepic.C:1839
void compute_coordinates_for_tree(EepicNode *root)
Definition ntreepic.C:1203
long double hd
Definition ntreepic.C:191
void load_deway_number(ifstream &input_stream, int deway_array[], size_t deway_array_size)
Definition ntreepic.C:374
long double x_offset
Definition ntreepic.C:198
static struct argp_option options[]
Definition ntreepic.C:1890
void parse_tag(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:716
void generate_bin_tree(ofstream &output, EepicNode *root)
Definition ntreepic.C:1292
static const char * hello
Definition ntreepic.C:1842
#define XR(p)
Definition ntreepic.C:353
bool ellipses
Definition ntreepic.C:209
long double xgap
Definition ntreepic.C:193
long double tree_gap
Definition ntreepic.C:195
void print_parameters()
Definition ntreepic.C:1991
void parse_dashed_arc(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:759
void compute_definitive_coordinates_for_node(EepicNode *p, int, int)
Definition ntreepic.C:1163
long double y_picture_offset
Definition ntreepic.C:201
#define STRING(p)
Definition ntreepic.C:348
void infix_tree(EepicNode *root)
Definition ntreepic.C:1254
void generate_prologue(ofstream &output)
Definition ntreepic.C:1309
#define TERMINATE(n)
Definition ntreepic.C:1962
std::string command_line
Definition ntreepic.C:203
#define CHILDNUMBER(p)
Definition ntreepic.C:361
EepicNode * advance_to_rightmost_in_level(EepicNode *root, const int level, long double &sum)
Definition ntreepic.C:941
bool not_nodes
Definition ntreepic.C:213
static struct argp arg_defs
Definition ntreepic.C:2157
void parse_root_definition(ifstream &input_stream, EepicNode *root)
Definition ntreepic.C:600
Token_Type Tag_Option
Definition ntreepic.C:238
#define SUMMOD(p)
Definition ntreepic.C:347
static char doc[]
Definition ntreepic.C:1836
#define YR(p)
Definition ntreepic.C:354
long double x_max
Definition ntreepic.C:1150
Comprehensive parsing utilities for text processing and compiler construction.
EepicNode * target_node
Definition ntreepic.C:263
bool is_dashed
Definition btreepic.C:223
long target_node
Definition btreepic.C:222
EepicNode * target_node
Definition ntreepic.C:274
long double x_offset
Definition btreepic.C:194
string tag
Definition btreepic.C:192
Tag_Data(string str, const Tag_Option option)
Definition ntreepic.C:253
Tag_Option tag_option
Definition btreepic.C:193
long double y_offset
Definition btreepic.C:195
Tag_Data()=default
int level
Definition ntreepic.C:328
long double mod
Definition ntreepic.C:288
long double yd
Definition ntreepic.C:297
bool shadow
Definition ntreepic.C:315
long double xd
Definition ntreepic.C:297
long double max_child_yr
Definition ntreepic.C:299
long double xr
Definition ntreepic.C:295
int position
Definition ntreepic.C:320
bool rectangle
Definition ntreepic.C:313
long double yr_gap
Definition ntreepic.C:303
int child_number
Definition ntreepic.C:329
bool without_node
Definition ntreepic.C:316
long double x
Definition ntreepic.C:286
bool with_arc
Definition ntreepic.C:317
long double yoffset
Definition ntreepic.C:310
bool ellipse
Definition ntreepic.C:312
DynDlist< Connexion_Data > connexion_list
Definition ntreepic.C:326
long double pre
Definition ntreepic.C:288
DynDlist< Arc_Data > arc_list
Definition ntreepic.C:324
string str
Definition ntreepic.C:308
DynDlist< Tag_Data > tag_list
Definition ntreepic.C:322
bool dashed_arc
Definition ntreepic.C:318
long double y
Definition ntreepic.C:286
long double xoffset
Definition ntreepic.C:310
long double yr
Definition ntreepic.C:295
long double sum_mod
Definition ntreepic.C:291
static long counter
Definition test-splice.C:40
Gsl_Compatible_Rng r
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
General tree (n-ary tree) node.
DynList< int > l
Tree picture generation utilities.
void intersection_ellipse_line(long double lx0, long double ly0, long double lx1, long double ly1, long double a, long double b, long double &dx, long double &dy)
long double resolution
void put_string(std::ofstream &output, const long double &x, const long double &y, const std::string &comment, const std::string &str)
long double string_width(const std::string &str)
long double arrow_lenght
bool with_arrow
bool flip_y
void draw_arc(std::ofstream &output, long double src_x, long double src_y, long double tgt_x, long double tgt_y, bool is_dashed, bool with_arrow, bool thick=true)
void intersection_rectangle_line(long double lx0, long double ly0, long double lx1, long double ly1, long double a, long double b, long double &dx, long double &dy)
long double arrow_width
const char * fill_type
long double font_height()
long double YPIC(long double y)
long double center_string(const std::string &str, long double window_size)
const long double sin_45
ofstream output
Definition writeHeap.C:215