Dear Sir;
Could you help me to print a tree to a text file?
If I have a tree, I want to convert to string to be able to print to a file.
Regards;
AHMED NADY
- Thomas Linder Puls
- VIP Member
- Posts: 1410
- Joined: 28 Feb 2000 0:01
It is not completely clear what you mean by a tree or what your expect from the print.
In its simplest form you can simply write the tree to the file:
In its simplest form you can simply write the tree to the file:
Code: Select all
class predicates
writeTree : (string Filename, tree Tree).
clauses
writeTree(Filename, Tree) :-
S = outputStream_file::createUtf8_bom(Filename), % there are lots of text format choices
S:write(Tree),
S:close().
Regards Thomas Linder Puls
PDC
PDC
- Thomas Linder Puls
- VIP Member
- Posts: 1410
- Joined: 28 Feb 2000 0:01
- Thomas Linder Puls
- VIP Member
- Posts: 1410
- Joined: 28 Feb 2000 0:01
That is rather complex and large task, so a mail can only give hints. There are two things you have to solve:
When drawing binary trees a relatively obvious algorithm is to draw the root in the top middle of the image and then split the image vertically in two halfs, recursively drawing the left sub tree in the left part and the right sub tree in the right part connecting left and then connect the sub trees o the root.
You will how ever soon realize that the trees often look bad. If you should draw a tree by hand you would for example not place the root in the middle if one of the sub trees were empty, because that would leave the image half empty.
Better algorithms will first calculate the size of the two sub images and the placement of their root (recursively) and from that decide the placement of the two sub graphs and the root.
Handling graphs that does not fit the image (which typically have a max size) is a large problem on its own.[/list]
- How to create a picture file
- How to draw a tree
When drawing binary trees a relatively obvious algorithm is to draw the root in the top middle of the image and then split the image vertically in two halfs, recursively drawing the left sub tree in the left part and the right sub tree in the right part connecting left and then connect the sub trees o the root.
You will how ever soon realize that the trees often look bad. If you should draw a tree by hand you would for example not place the root in the middle if one of the sub trees were empty, because that would leave the image half empty.
Better algorithms will first calculate the size of the two sub images and the placement of their root (recursively) and from that decide the placement of the two sub graphs and the root.
Handling graphs that does not fit the image (which typically have a max size) is a large problem on its own.[/list]
Regards Thomas Linder Puls
PDC
PDC
-
- Active Member
- Posts: 36
- Joined: 6 Feb 2003 0:01
I don't know if this will help or not but if I understand what you're trying to do you can create/expand the tree in an invisible window and use the following to obtain and save an image file of the tree;
Although this will give you the image file it may be best to find the equivalent in GDIPlus as I suspect the vpi::pict routines will eventually become obsolete.
Regards,
David Snook
Code: Select all
PIC = vpi::pictGetfromWin(Win,RCT),
vpi::pictSave(PIC,"picName"),
Regards,
David Snook