Other operations

Name

Other operations -- 

Synopsis


#include <gfs.h>


FttDirection ftt_direction_from_name        (const gchar *name);
FttCell*    ftt_cell_locate                 (FttCell *root,
                                             FttVector target,
                                             gint max_depth);
enum        FttTraverseType;
enum        FttTraverseFlags;
void        (*FttCellTraverseFunc)          (FttCell *cell,
                                             gpointer data);
void        ftt_cell_traverse               (FttCell *root,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             FttCellTraverseFunc func,
                                             gpointer data);
void        ftt_cell_traverse_boundary      (FttCell *root,
                                             FttDirection d,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             FttCellTraverseFunc func,
                                             gpointer data);
void        ftt_cell_traverse_box           (FttCell *root,
                                             GtsBBox *box,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             FttCellTraverseFunc func,
                                             gpointer data);
struct      FttCellTraverse;
FttCellTraverse* ftt_cell_traverse_new      (FttCell *root,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth);
FttCell*    ftt_cell_traverse_next          (FttCellTraverse *t);
void        ftt_cell_traverse_rewind        (FttCellTraverse *t);
void        ftt_cell_traverse_destroy       (FttCellTraverse *t);

void        ftt_cell_write                  (const FttCell *root,
                                             gint max_depth,
                                             FILE *fp,
                                             FttCellWriteFunc write,
                                             gpointer data);
void        (*FttCellWriteFunc)             (const FttCell *cell,
                                             FILE *fp,
                                             gpointer data);
FttCell*    ftt_cell_read                   (GtsFile *fp,
                                             FttCellReadFunc read,
                                             gpointer data);
void        (*FttCellReadFunc)              (FttCell *cell,
                                             GtsFile *fp,
                                             gpointer data);
void        ftt_cell_draw                   (const FttCell *cell,
                                             FILE *fp);

Description

Details

ftt_direction_from_name ()

FttDirection ftt_direction_from_name        (const gchar *name);

name : a direction name.
Returns : the index of the direction name or FTT_NEIGHBORS if name is not a valid direction name.


ftt_cell_locate ()

FttCell*    ftt_cell_locate                 (FttCell *root,
                                             FttVector target,
                                             gint max_depth);

Locates the cell of the tree defined by root containing target. This is done efficiently in log(n) operations by using the topology of the tree.

root : a FttCell.
target : position of the point to look for.
max_depth : maximum depth to consider (-1 means no restriction).
Returns : a FttCell of the tree defined by root and containing (boundary included) the point defined by target or NULL if target is not contained in any cell of root.


enum FttTraverseType

typedef enum
{
  FTT_PRE_ORDER,
  FTT_POST_ORDER
} FttTraverseType;

Controls the sequence in which the traversal is performed.

FTT_PRE_ORDERVisits the parent cell and then its children.
FTT_POST_ORDERVisits each children and then their parent.


enum FttTraverseFlags

typedef enum
{
  FTT_TRAVERSE_LEAFS          = 1 << 0,
  FTT_TRAVERSE_NON_LEAFS      = 1 << 1,
  FTT_TRAVERSE_LEVEL          = 1 << 2,
  FTT_TRAVERSE_BOUNDARY_FACES = 1 << 3,
  FTT_TRAVERSE_ALL            = FTT_TRAVERSE_LEAFS | FTT_TRAVERSE_NON_LEAFS
} FttTraverseFlags;

Controls the type of cell to visit.

FTT_TRAVERSE_LEAFSVisits only the cells which are leaves of the cell tree.
FTT_TRAVERSE_NON_LEAFSVisits only the cells which are not leaves of the cell tree.
FTT_TRAVERSE_LEVELIf FTT_TRAVERSE_LEAFS is also set, visit the leafs of the cell tree and all the cells at level max_depth. If FTT_TRAVERSE_NON_LEAFS is also set, visits only the non-leaf cells at level max_depth. Otherwise, visits all the cells at level max_depth.
FTT_TRAVERSE_BOUNDARY_FACES 
FTT_TRAVERSE_ALLVisits all the cells of the cell tree.


FttCellTraverseFunc ()

void        (*FttCellTraverseFunc)          (FttCell *cell,
                                             gpointer data);

This functions is called by ftt_cell_traverse() for each of the visited cells.

cell :a FttCell.
data :user-data passed to the function.


ftt_cell_traverse ()

void        ftt_cell_traverse               (FttCell *root,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             FttCellTraverseFunc func,
                                             gpointer data);

Traverses a cell tree starting at the given root FttCell. Calls the given function for each cell visited. */ void ftt_cell_traverse (FttCell * root, FttTraverseType order, FttTraverseFlags flags, gint max_depth, FttCellTraverseFunc func, gpointer data) { g_return_if_fail (root != NULL); g_return_if_fail (func != NULL);

if (max_depth >= 0 && ftt_cell_level (root) > max_depth) return;

if (flags == FTT_TRAVERSE_ALL) { if (order == FTT_PRE_ORDER) cell_traverse_pre_order_all (root, max_depth, func, data); else cell_traverse_post_order_all (root, max_depth, func, data); } else if ((flags & FTT_TRAVERSE_LEVEL) != 0) { if ((flags & FTT_TRAVERSE_LEAFS) != 0) cell_traverse_level_leafs (root, max_depth, func, data); else if ((flags & FTT_TRAVERSE_NON_LEAFS) != 0) cell_traverse_level_non_leafs (root, max_depth, func, data); else cell_traverse_level (root, max_depth, func, data); } else if ((flags & FTT_TRAVERSE_LEAFS) != 0) cell_traverse_leafs (root, max_depth, func, data); else { g_return_if_fail ((flags & FTT_TRAVERSE_NON_LEAFS) != 0);

if (order == FTT_PRE_ORDER) cell_traverse_pre_order_nonleafs (root, max_depth, func, data); else cell_traverse_post_order_nonleafs (root, max_depth, func, data); } }

static void cell_traverse_boundary_pre_order_all (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { FttCell * parent;

if (max_depth >= 0 && ftt_cell_level (cell) > max_depth) return;

parent = ftt_cell_parent (cell); (* func) (cell, data); /* check that cell has not been deallocated by func */ g_assert (parent == NULL || parent->children != NULL);

if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_pre_order_all (children.c[n], d, max_depth, func, data); } }

static void cell_traverse_boundary_post_order_all (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (max_depth >= 0 && ftt_cell_level (cell) > max_depth) return;

if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_post_order_all (children.c[n], d, max_depth, func, data); }

(* func) (cell, data); }

static void cell_traverse_boundary_leafs (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (max_depth >= 0 && ftt_cell_level (cell) > max_depth) return;

if (FTT_CELL_IS_LEAF (cell)) (* func) (cell, data); else { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_leafs (children.c[n], d, max_depth, func, data); } }

static void cell_traverse_boundary_pre_order_nonleafs (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (max_depth >= 0 && ftt_cell_level (cell) > max_depth) return;

if (!FTT_CELL_IS_LEAF (cell)) { FttCell * parent = ftt_cell_parent (cell);

(* func) (cell, data); /* check that cell has not been deallocated by func */ g_assert (parent == NULL || parent->children != NULL); if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_pre_order_nonleafs (children.c[n], d, max_depth, func, data); } } }

static void cell_traverse_boundary_post_order_nonleafs (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (max_depth >= 0 && ftt_cell_level (cell) > max_depth) return;

if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_post_order_nonleafs (children.c[n], d, max_depth, func, data); (* func) (cell, data); } }

static void cell_traverse_boundary_level (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (ftt_cell_level (cell) == max_depth) (* func) (cell, data); else if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_level (children.c[n], d, max_depth, func, data); } }

static void cell_traverse_boundary_level_leafs (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (ftt_cell_level (cell) == max_depth || FTT_CELL_IS_LEAF (cell)) (* func) (cell, data); else if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_level_leafs (children.c[n], d, max_depth, func, data); } }

static void cell_traverse_boundary_level_non_leafs (FttCell * cell, FttDirection d, gint max_depth, FttCellTraverseFunc func, gpointer data) { if (ftt_cell_level (cell) == max_depth && !FTT_CELL_IS_LEAF (cell)) (* func) (cell, data); else if (!FTT_CELL_IS_LEAF (cell)) { FttCellChildren children; guint n;

ftt_cell_children_direction (cell, d, &children); for (n = 0; n < FTT_CELLS/2; n++) if (children.c[n]) cell_traverse_boundary_level_non_leafs (children.c[n], d, max_depth, func, data); } }

/** ftt_cell_traverse_boundary: root: the root FttCell of the tree to traverse. d: the direction of the boundary to traverse. order: the order in which the cells are visited - FTT_PRE_ORDER, FTT_POST_ORDER. flags: which types of children are to be visited. max_depth: the maximum depth of the traversal. Cells below this depth will not be traversed. If max_depth is -1 all cells in the tree are visited. func: the function to call for each visited FttCell. data: user data to pass to func.

Traverses the boundary of a cell tree in direction d starting at the given root FttCell. Calls the given function for each node visited.

root : the root FttCell of the tree to traverse.
order : the order in which the cells are visited - FTT_PRE_ORDER, FTT_POST_ORDER.
flags : which types of children are to be visited.
max_depth : the maximum depth of the traversal. Cells below this depth will not be traversed. If max_depth is -1 all cells in the tree are visited.
func : the function to call for each visited FttCell.
data : user data to pass to func.


ftt_cell_traverse_boundary ()

void        ftt_cell_traverse_boundary      (FttCell *root,
                                             FttDirection d,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             FttCellTraverseFunc func,
                                             gpointer data);

root : 
d : 
order : 
flags : 
max_depth : 
func : 
data : 


ftt_cell_traverse_box ()

void        ftt_cell_traverse_box           (FttCell *root,
                                             GtsBBox *box,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             FttCellTraverseFunc func,
                                             gpointer data);

Traverses a cell tree starting at the given root FttCell. Calls the given function for each cell visited. Only the cells partly or totally contained within box are visited.

root : the root FttCell of the tree to traverse.
box : a GtsBBox.
order : the order in which the cells are visited - FTT_PRE_ORDER, FTT_POST_ORDER.
flags : which types of children are to be visited.
max_depth : the maximum depth of the traversal. Cells below this depth will not be traversed. If max_depth is -1 all cells in the tree are visited.
func : the function to call for each visited FttCell.
data : user data to pass to func.


struct FttCellTraverse

struct FttCellTraverse {
  FttCell ** cells;
  FttCell ** current;
};


ftt_cell_traverse_new ()

FttCellTraverse* ftt_cell_traverse_new      (FttCell *root,
                                             FttTraverseType order,
                                             FttTraverseFlags flags,
                                             gint max_depth);

root : the root FttCell of the tree to traverse.
order : the order in which the cells are visited - FTT_PRE_ORDER, FTT_POST_ORDER.
flags : which types of children are to be visited.
max_depth : the maximum depth of the traversal. Cells below this depth will not be traversed. If max_depth is -1 all cells in the tree are visited.
Returns : a new FttCellTraverse.


ftt_cell_traverse_next ()

FttCell*    ftt_cell_traverse_next          (FttCellTraverse *t);

t : a FttCellTraverse.
Returns : the next cell to visit or NULL if all the cells have been visited.


ftt_cell_traverse_rewind ()

void        ftt_cell_traverse_rewind        (FttCellTraverse *t);

Sets t at the begining of the traversal.


ftt_cell_traverse_destroy ()

void        ftt_cell_traverse_destroy       (FttCellTraverse *t);

Frees all the memory associated with t.


ftt_cell_write ()

void        ftt_cell_write                  (const FttCell *root,
                                             gint max_depth,
                                             FILE *fp,
                                             FttCellWriteFunc write,
                                             gpointer data);

Writes in the file pointed to by fp a text representation of the cell tree starting at root. If not NULL, the user-defined function write is used to write the extra user data associated with each cell.

root : a FttCell.
max_depth : the maximum depth at which to stop writing (-1 means no limit).
fp : a file pointer.
write : a FttCellWriteFunc function or NULL.
data : user data to pass to write.


FttCellWriteFunc ()

void        (*FttCellWriteFunc)             (const FttCell *cell,
                                             FILE *fp,
                                             gpointer data);

Writes in fp any user data associated with cell. It is important that this function does not output any newline caracter ('\n').

cell :a FttCell.
fp :a file pointer.
data : 


ftt_cell_read ()

FttCell*    ftt_cell_read                   (GtsFile *fp,
                                             FttCellReadFunc read,
                                             gpointer data);

If an error occurs (i.e. corrupted file or file format incorrect), the error field of fp is set. A possibly incomplete tree is then returned.

fp : a GtsFile.
read : a FttCellReadFunc function or NULL.
data : user data to pass to read.
Returns : the root cell of the tree contained in the file pointed to by fp. If not NULL, the user-defined function read is used to read the extra user data associated with each cell.


FttCellReadFunc ()

void        (*FttCellReadFunc)              (FttCell *cell,
                                             GtsFile *fp,
                                             gpointer data);

Reads in any user data associated with cell from file fp and initializes the corresponding fields.

cell :a FttCell.
fp :a file pointer.
data : 


ftt_cell_draw ()

void        ftt_cell_draw                   (const FttCell *cell,
                                             FILE *fp);

Outputs in fp an OOGL (geomview) representation of cell.

cell : a FttCell.
fp : a file pointer.