#ifndef DECOMP_H
#define DECOMP_H

/*
 * Binary tree image decomposition
 */

typedef struct
{
    u32_t depth;
    u32_t left, top, right, bottom;
    vec_t value;
} btdecomp_node_t, *btdecomp_node_p;

typedef struct btdecomp_leaf_info_s
{
    u32_t depth;
    u32_t left,top,right,bottom;
    u32_t area;
    vec_t value;
}   btdecomp_leaf_info_t, *btdecomp_leaf_info_p;

typedef struct bt_decomp_s
{
    btree_p     root;
    bstack_t    info_stack;
    u32_t       source_rows, source_cols;
    u32_t       min_depth, max_depth, depth_levels; /* max - min + 1 */
    u32_t       min_area, max_area;
    vec_t       min_value, max_value;
    u32_p       leafs_at_depth; /* leafs_at_depth[level] == num_leafs at this level */
    vector_p    *values_at_depth;
    vector_p    *histogram_at_depth;
    vector_p    *histogram_space_at_depth;
}   bt_decomp_t, *bt_decomp_p;

bt_decomp_p iplDecomposeImage(matrix_p m,vec_t threshold,
    u32_t histogram_divs);

void    iplSaveDecompositionDescription(char *fname,
    bt_decomp_p decomp,
    vboolean save_values, /* save leaf values; produces _large_ file */
    vboolean save_histograms,
    vboolean relative_frequencies);

void    iplDrawDecomposition(matrix_p surface,bt_decomp_p decomp);

void    iplDrawDecompositionScale(matrix_p surface,bt_decomp_p decomp,
    vector_p scale);

void    iplDrawDecompositionLinearScale(matrix_p surface,
    bt_decomp_p decomp,vec_t min_value,vec_t max_value);

void    iplFreeDecomposition(bt_decomp_p decomp);

#endif  /* !DECOMP_H */
