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)
435 catch (
const std::out_of_range &)
450 while (c !=
'\n' and c !=
EOF);
536 if (
strcasecmp(buffer,
"DASHED-CONNEXION") == 0)
571 if (parent_node ==
nullptr)
612 parent_node->insert_rightmost_child(new_node);
671 if (tgt->get_parent() != src)
740 if (tgt->get_parent() == src)
891 catch (exception & e)
918 p = p->get_left_sibling())
920 if (
LEVEL(p) == level)
956 p = p->get_right_sibling())
958 if (
LEVEL(p) == level)
1003 assert(p->get_left_sibling() !=
nullptr);
1026 int level =
LEVEL(p) + 1;
1052 while (
l !=
nullptr and r !=
nullptr)
1092 if (p->is_leaf()
and p->is_leftmost())
1094 else if (p->is_leaf()
and p->is_root())
1111 EepicNode *left_child = p->get_left_child();
1112 EepicNode *right_child = p->get_right_child();
1114 if (p->is_leftmost()
or p->is_root())
1116 PRE(p) = (
PRE(left_child) +
PRE(right_child)) / 2.0;
1123 MOD(p) =
PRE(p) - (
PRE(left_child) +
PRE(right_child)) / 2.0;
1132 if (
not p->is_root())
1138 if (
not p->is_leftmost()
and not p->is_root())
1254 if (
root ==
nullptr)
1265 if (
root ==
nullptr)
1277 if (
root ==
nullptr)
1292 output <<
"start-prefix ";
1310 <<
"% This LaTeX picture is a tree automatically" <<
endl
1311 <<
"% generated by ntreepic program" <<
endl
1313 <<
"% Copyright (C) 2002, 2003, 2004, 2007" <<
endl
1314 <<
"% UNIVERSITY of LOS ANDES (ULA)" <<
endl
1315 <<
"% Merida - REPUBLICA BOLIVARIANA DE VENEZUELA" <<
endl
1316 <<
"% Center of Studies in Microelectronics & Distributed Systems"
1317 <<
" (CEMISID)" <<
endl
1318 <<
"% ULA Computer Science Department" <<
endl
1320 <<
"% Created by Leandro Leon - lrleon@ula.ve" <<
endl
1322 <<
"% This program uses the Sugiyama variation of Walker" <<
endl
1323 <<
"% algorithm for general trees drawing" <<
endl
1325 <<
"% You must use epic and eepic latex packages" <<
endl
1326 <<
"% in your LaTeX application" <<
endl
1328 <<
"% epic Copyright by Sunil Podar" <<
endl
1329 <<
"% eepic Copyright by Conrad Kwok" <<
endl
1330 <<
"% LaTeX is a collection of TeX macros created by Leslie Lamport"
1332 <<
"% TeX was created by Donald Knuth" <<
endl
1334 <<
"% command line: " <<
endl
1340 <<
"% Creation date: " <<
ctime(&t) <<
endl
1344 output <<
"\\documentclass[11pt]{article}" <<
endl
1346 <<
"\\usepackage{epic}" <<
endl
1347 <<
"\\usepackage{eepic}" <<
endl
1349 <<
"\\begin{document}" <<
endl
1350 <<
"\\begin{center}" <<
endl;
1356 <<
"\\begin{picture}(" <<
h_size <<
"," <<
v_size <<
")"
1365 <<
"\\end{picture}" <<
endl;
1369 <<
"\\end{center}" <<
endl
1370 <<
"\\end{document}" <<
endl;
1413 const bool left =
false,
1414 const bool is_dashed =
true)
1416 const long double &
px =
X(p);
1417 const long double &
py =
Y(p);
1419 const long double &
qx =
X(q);
1420 const long double &
qy =
Y(q);
1536 <<
" inside a forest ";
1540 long double x =
X(p);
1541 long double y =
Y(p);
1546 <<
"% Node at level " << level <<
". It's the "
1547 << child_index <<
" child with key = " <<
STRING(p);
1555 <<
"\\put(" << x <<
"," <<
YPIC(
y) <<
")"
1556 << (
SHADOW(p) ?
"{\\ellipse*{" :
"{\\ellipse{") <<
WIDTH(p)
1557 <<
"}{" <<
HEIGHT(p) <<
"}}";
1560 <<
"\\path(" << x -
XR(p) <<
"," <<
YPIC(
y -
YR(p)) <<
")"
1561 <<
"(" << x +
XR(p) <<
"," <<
YPIC(
y -
YR(p)) <<
")"
1562 <<
"(" << x +
XR(p) <<
"," <<
YPIC(
y +
YR(p)) <<
")"
1563 <<
"(" << x -
XR(p) <<
"," <<
YPIC(
y +
YR(p)) <<
")"
1564 <<
"(" << x -
XR(p) <<
"," <<
YPIC(
y -
YR(p)) <<
")";
1589 comment =
"North tag: ";
1594 comment =
"South tag: ";
1599 comment =
"East tag: ";
1604 comment =
"West tag: ";
1609 comment =
"Northeast tag: ";
1614 comment =
"Northwest tag: ";
1619 comment =
"Southeast tag: ";
1624 comment =
"Southwest tag: ";
1664 <<
"% Additional arc to child with key " <<
1685 output <<
"\\curve(" << x - dx <<
"," <<
YPIC(
y + dy) <<
","
1686 <<
px + dx <<
"," <<
YPIC(
y +
h) <<
","
1687 <<
px + dx <<
"," <<
YPIC(
py + dy) <<
")";
1695 for (
EepicNode *c = p->get_left_child(); c !=
nullptr;
1696 c = c->get_right_sibling())
1700 long double lx =
X(c);
1701 long double ly =
Y(c);
1737 long double lx =
X(c);
1738 long double ly =
Y(c);
1771 long double rx =
X(
rs);
1772 long double ry =
Y(
rs);
1793 <<
"% link to right sibling " << child_index + 1
1819 "ntreepic 1.7 - ALEPH drawer for general rooted trees\n"
1820 "Copyright (C) 2004, 2007 UNIVERSITY of LOS ANDES (ULA)\n"
1821 "Merida - REPUBLICA BOLIVARIANA DE VENEZUELA\n"
1822 "Center of Studies in Microelectronics & Distributed Systems (CEMISID)\n"
1823 "ULA Computer Science Department\n"
1824 "This is free software; There is NO warranty; not even for MERCHANTABILITY\n"
1825 "or FITNESS FOR A PARTICULAR PURPOSE\n"
1832static char doc[] =
"ntreepic -- Aleph drawer for general rooted trees";
1835static char arg_doc[] =
"-f input-file [-o output-file]\n";
1839 "ALEPH drawer for general rooted trees\n"
1840 "Copyright (C) 2004, 2007 University of Los Andes (ULA)\n"
1841 "Merida - REPUBLICA BOLIVARIANA DE VENEZUELA\n"
1842 "Center of Studies in Microelectronics & Distributed Systems (CEMISID)\n"
1843 "ULA Computer Science Department\n"
1844 "This is free software; There is NO warranty; not even for MERCHANTABILITY\n"
1845 "or FITNESS FOR A PARTICULAR PURPOSE\n"
1850 "ALEPH drawer for general rooted trees. License & Copyright Note\n"
1851 "Copyright (C) 2004, 2007\n"
1852 "UNIVERSITY of LOS ANDES (ULA)\n"
1853 "Merida - REPUBLICA BOLIVARIANA DE VENEZUELA\n"
1854 "Center of Studies in Microelectronics & Distributed Systems (CEMISID)\n"
1855 "ULA Computer Science Department\n"
1856 "This is free software; There is NO warranty; not even for MERCHANTABILITY\n"
1857 "or FITNESS FOR A PARTICULAR PURPOSE\n"
1859 " PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE AND ITS \n"
1860 " DOCUMENTATION IS HEREBY GRANTED, PROVIDED THAT BOTH THE COPYRIGHT \n"
1861 " NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES OF THE \n"
1862 " SOFTWARE, DERIVATIVE WORKS OR MODIFIED VERSIONS, AND ANY PORTIONS \n"
1863 " THEREOF, AND THAT BOTH NOTICES APPEAR IN SUPPORTING DOCUMENTATION. \n"
1865 " This program is distributed in the hope that it will be useful,\n"
1866 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1867 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n"
1869 " ULA requests users of this software to return to \n"
1870 " Proyecto Aleph - CEMISID Software\n"
1871 " Nucleo Universitario La Hechicera. Ed Ingenieria\n"
1872 " 3er piso, ala Este \n"
1873 " Universidad de Los Andes \n"
1874 " Merida 5101 - REPUBLICA BOLIVARIANA DE VENEZUELA \n"
1876 " or to lrleon@ula.ve \n"
1878 " any improvements or extensions that they make and grant Universidad \n"
1879 " de Los Andes (ULA) the full rights to redistribute these changes. \n"
1881 " This program was granted by: \n"
1882 " - Consejo de Desarrollo Cientifico, Humanistico, Tecnico de la ULA\n"
1893 "generate binary tree", 0
1897 "horizontal radius", 0
1901 "vertical radius", 0
1908 "horizontal offset for keys", 0
1912 "vertical offset for keys", 0
1914 {
"input-file",
'i',
"input-file", 0,
"input file", 0},
1916 {
"output",
'o',
"output-file", 0,
"output file", 0},
1919 "x-picture-offset",
'O',
"horizontal-picture-offset",
1923 "y-picture-offset",
'P',
"vertical-picture-offset",
1930 "Print version information and then exit", 0
1938 "draw linked list representation", 0
1942 "draw normal tree representation (or turn off linked list form)", 0
1958# define TERMINATE(n) (save_parameters(), exit(n))
1990 <<
"Global horizontal node radius -x = " <<
hr <<
endl
1991 <<
"Global vertical node radius -y = " <<
vr <<
endl
1992 <<
"Global horizontal node diameter = " <<
hd <<
endl
1993 <<
"Global Vertical node diameter = " <<
vd <<
endl
1994 <<
"Horizontal sibling separation -w = " <<
xgap <<
endl
1995 <<
"Vertical children separation -h = " <<
ygap <<
endl
1998 <<
"Horizontal global offset for key -X = " <<
x_offset <<
endl
1999 <<
"Vertical global offset for key -Y = " <<
y_offset <<
endl
2011 AH_ERROR(
"Waiting for radius in command line");
2017 AH_ERROR(
"Waiting for sibling gap in command line");
2022 AH_ERROR(
"Waiting for sibling gap in command line");
2027 AH_ERROR(
"Waiting for tree gap in command line");
2032 AH_ERROR(
"Waiting for horizontal radius in command line");
2038 AH_ERROR(
"Waiting for vertical radius in command line");
2044 AH_ERROR(
"Waiting for resolution in command line");
2047 cout <<
"Warning: resolution too big" <<
endl;
2059 AH_ERROR(
"Waiting for horizontal offset in command line");
2064 AH_ERROR(
"Waiting for vertical offset in command line");
2069 AH_ERROR(
"Waiting for horizontal offset in command line");
2074 AH_ERROR(
"Waiting for vertical offset in command line");
2083 AH_ERROR(
"Waiting for input file name");
2089 AH_ERROR(
"Waiting for output file name");
2135 AH_ERROR(
"Waiting for arrow lenght in command line");
2141 AH_ERROR(
"Waiting for arrow width in command line");
2160 "ntreepic -- General rooted tree visualizer (LaTeX/eepic output)\n"
2162 "Reads a textual general rooted tree description (.Tree file) and emits\n"
2163 "LaTeX code using eepic drawing primitives, suitable for inclusion in\n"
2164 "publication-quality documents. Supports n-ary trees, forests, and\n"
2165 "linked-list representations.\n"
2168 " ntreepic -f <input.Tree> [-o <output.eepic>] [options]\n"
2169 " ntreepic -i <input.Tree> [-o <output.eepic>] [options]\n"
2172 " -f, -i <file> Input .Tree file\n"
2175 " -o <file> Output file (default: input name + .eepic)\n"
2176 " -r <double> Node circle radius (sets horizontal and vertical)\n"
2177 " -x <double> Horizontal radius of node ellipse\n"
2178 " -y <double> Vertical radius of node ellipse\n"
2179 " -w <double> Horizontal gap between siblings\n"
2180 " -h <double> Vertical gap between levels\n"
2181 " -t <double> Gap between subtrees\n"
2182 " -l <double> Resolution in mm\n"
2183 " -a Wrap output in a full LaTeX header\n"
2184 " -e Draw nodes as ellipses (default)\n"
2185 " -q Draw nodes as rectangles\n"
2186 " -n Minimum-radius mode (no node bodies, arcs only)\n"
2187 " -b Emit textual start-prefix/start-key representation of binary tree (via generate_bin_tree())\n"
2188 " -L Draw linked-list representation (with arrows)\n"
2189 " -T Draw forest layout (no linked-list representation)\n"
2190 " -A Draw arcs with arrows\n"
2191 " -B Fill nodes with black\n"
2192 " -S Fill nodes with shade\n"
2193 " -F Flip tree along the y axis\n"
2194 " -X <double> Horizontal label offset\n"
2195 " -Y <double> Vertical label offset\n"
2196 " -O <double> Horizontal global picture offset\n"
2197 " -P <double> Vertical global picture offset\n"
2198 " -R Print current parameters and exit\n"
2199 " -V Print version and exit\n"
2200 " -C Print license and exit\n"
2203 " ntreepic -f mytree.Tree -o mytree.eepic -a -e\n"
2205 "Run 'ntreepic --help' for the complete list of options.\n";
2231 if (pos != string::npos)
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define AH_ERROR(...)
Print an error message (always enabled).
bool has_curr() const noexcept
Return true if the iterator has current item.
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)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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.
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.
and
Check uniqueness with explicit hash + equality functors.
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.
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.
void parse_rectangle(ifstream &input_stream, EepicNode *root)
EepicNode * __advance_to_leftmost_in_level(EepicNode *root, const int level, long double &sum)
EepicNode * parse_deway_number(ifstream &input_stream, EepicNode *root)
void compute_coordinates_for_forest_and_set_picture_size(EepicNode *root)
bool draw_list_representation
const char * parameters_file_name
Token_Type get_token(ifstream &input_stream)
void generate_tree(ofstream &output, EepicNode *p, int level, int child_index)
void adjust_minimal_separation_with_letf_sibling(EepicNode *p)
void shift_tree_to_right(EepicNode *p, int, int)
void parse_xoffset(ifstream &input_stream, EepicNode *root)
void generate_forest(ofstream &output, EepicNode *root)
void precompute_x_for_node(EepicNode *p, const int level, const int child)
void parse_connexion(ifstream &input_stream, EepicNode *root)
static error_t parser_opt(int key, char *arg, struct argp_state *)
void precompute_x_coordinates_for_tree(EepicNode *root)
void generate_curve(ofstream &output, EepicNode *p, EepicNode *q, const bool left=false, const bool is_dashed=true)
EepicNode * parse_first_root_definition(ifstream &input_stream)
void parse_arc(ifstream &input_stream, EepicNode *root)
void parse_without_arc(ifstream &input_stream, EepicNode *root)
void generate_epilogue(ofstream &output)
void parse_shadow(ifstream &input_stream, EepicNode *root)
void generate_prefix_traversal(ofstream &output, EepicNode *root)
std::string input_file_name
void generate_infix_traversal(ofstream &output, EepicNode *root)
long double x_picture_offset
const char * argp_program_version
void parse_vradio(ifstream &input_stream, EepicNode *root)
Tree_Node< Tree_Data > EepicNode
EepicNode * read_input_and_build_tree(ifstream &input_stream)
void parse_ellipse(ifstream &input_stream, EepicNode *root)
bool generate_binary_tree
EepicNode * parse_key_node_and_allocate(ifstream &input_stream)
EepicNode * allocate_node(const string &str)
void parse_yoffset(ifstream &input_stream, EepicNode *root)
static const char license_text[]
std::string output_file_name
EepicNode * __advance_to_rightmost_in_level(EepicNode *root, const int level, long double &sum)
void parse_hradio(ifstream &input_stream, EepicNode *root)
EepicNode * advance_to_leftmost_in_level(EepicNode *root, const int level, long double &sum)
void parse_node_definition(ifstream &input_stream, EepicNode *root)
void parse_without_node(ifstream &input_stream, EepicNode *root)
const char * argp_program_bug_address
void compute_coordinates_for_tree(EepicNode *root)
void load_deway_number(ifstream &input_stream, int deway_array[], size_t deway_array_size)
static struct argp_option options[]
void parse_tag(ifstream &input_stream, EepicNode *root)
void generate_bin_tree(ofstream &output, EepicNode *root)
static const char * hello
void parse_dashed_arc(ifstream &input_stream, EepicNode *root)
void compute_definitive_coordinates_for_node(EepicNode *p, int, int)
long double y_picture_offset
void infix_tree(EepicNode *root)
void generate_prologue(ofstream &output)
EepicNode * advance_to_rightmost_in_level(EepicNode *root, const int level, long double &sum)
static struct argp arg_defs
void parse_root_definition(ifstream &input_stream, EepicNode *root)
Comprehensive parsing utilities for text processing and compiler construction.
Tag_Data(string str, const Tag_Option option)
DynDlist< Connexion_Data > connexion_list
DynDlist< Arc_Data > arc_list
DynDlist< Tag_Data > tag_list
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
General tree (n-ary tree) node.
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)
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)
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 font_height()
long double YPIC(long double y)
long double center_string(const std::string &str, long double window_size)