00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "btreecompact.h"
00038
00039 #include <vector>
00040 using namespace std;
00041
00042
00043 void BTreeCompactor::build_orth_tree()
00044 {
00045 clean_contour(in_contour);
00046 clean_tree(in_orth_tree);
00047
00048 int tree_prev = NUM_BLOCKS;
00049 int tree_curr = in_tree[NUM_BLOCKS].left;
00050 while (tree_curr != NUM_BLOCKS)
00051 {
00052 if (tree_prev == in_tree[tree_curr].parent)
00053 {
00054 build_orth_tree_add_block(tree_curr);
00055 tree_prev = tree_curr;
00056 if (in_tree[tree_curr].left != UNDEFINED)
00057 tree_curr = in_tree[tree_curr].left;
00058 else if (in_tree[tree_curr].right != UNDEFINED)
00059 tree_curr = in_tree[tree_curr].right;
00060 else
00061 tree_curr = in_tree[tree_curr].parent;
00062 }
00063 else if (tree_prev == in_tree[tree_curr].left)
00064 {
00065 tree_prev = tree_curr;
00066 if (in_tree[tree_curr].right != UNDEFINED)
00067 tree_curr = in_tree[tree_curr].right;
00068 else
00069 tree_curr = in_tree[tree_curr].parent;
00070 }
00071 else
00072 {
00073 tree_prev = tree_curr;
00074 tree_curr = in_tree[tree_curr].parent;
00075 }
00076 }
00077 in_totalWidth = in_contour[NUM_BLOCKS+1].begin;
00078
00079 int contour_ptr = in_contour[NUM_BLOCKS].next;
00080 in_totalHeight = 0;
00081 while (contour_ptr != NUM_BLOCKS+1)
00082 {
00083 in_totalHeight = max(in_totalHeight, in_contour[contour_ptr].CTL);
00084 contour_ptr = in_contour[contour_ptr].next;
00085 }
00086 in_totalArea = in_totalWidth * in_totalHeight;
00087
00088 fix_orth_tree(in_orth_tree);
00089 }
00090
00091 void BTreeCompactor::build_orth_tree_add_block(int tree_ptr)
00092 {
00093 int tree_parent = in_tree[tree_ptr].parent;
00094 int orth_tree_parent = NUM_BLOCKS;
00095
00096 double maxCTL = -1;
00097 int contour_ptr = UNDEFINED;
00098 int contour_prev = UNDEFINED;
00099
00100 if (tree_ptr == in_tree[in_tree[tree_ptr].parent].left)
00101 {
00102 in_contour[tree_ptr].begin = in_contour[tree_parent].end;
00103 contour_ptr = in_contour[tree_parent].next;
00104 }
00105 else
00106 {
00107 in_contour[tree_ptr].begin = in_contour[tree_parent].begin;
00108 contour_ptr = tree_parent;
00109 }
00110 contour_prev = in_contour[contour_ptr].prev;
00111 orth_tree_parent = contour_ptr;
00112 maxCTL = in_contour[contour_ptr].CTL;
00113
00114 int block = in_tree[tree_ptr].block_index;
00115 int theta = in_tree[tree_ptr].orient;
00116 in_contour[tree_ptr].end =
00117 in_contour[tree_ptr].begin + in_blockinfo[block].width[theta];
00118
00119 while (in_contour[contour_ptr].end <=
00120 in_contour[tree_ptr].end + TOLERANCE)
00121 {
00122 if (in_contour[contour_ptr].CTL > maxCTL)
00123 {
00124 maxCTL = in_contour[contour_ptr].CTL;
00125 orth_tree_parent = contour_ptr;
00126 }
00127 contour_ptr = in_contour[contour_ptr].next;
00128 }
00129
00130 if (in_contour[contour_ptr].begin + TOLERANCE <
00131 in_contour[tree_ptr].end)
00132 {
00133 if (in_contour[contour_ptr].CTL > maxCTL)
00134 {
00135 maxCTL = in_contour[contour_ptr].CTL;
00136 orth_tree_parent = contour_ptr;
00137 }
00138 }
00139
00140 in_xloc[tree_ptr] = in_contour[tree_ptr].begin;
00141 in_yloc[tree_ptr] = maxCTL;
00142 in_width[tree_ptr] = in_blockinfo[block].width[theta];
00143 in_height[tree_ptr] = in_blockinfo[block].height[theta];
00144
00145 in_contour[tree_ptr].CTL = maxCTL + in_blockinfo[block].height[theta];
00146 in_contour[tree_ptr].next = contour_ptr;
00147 in_contour[contour_ptr].prev = tree_ptr;
00148 in_contour[contour_ptr].begin = in_contour[tree_ptr].end;
00149
00150 in_contour[tree_ptr].prev = contour_prev;
00151 in_contour[contour_prev].next = tree_ptr;
00152 in_contour[tree_ptr].begin = in_contour[contour_prev].end;
00153
00154
00155 if (in_orth_tree[orth_tree_parent].left == UNDEFINED)
00156 {
00157
00158 in_orth_tree[orth_tree_parent].left = tree_ptr;
00159 in_orth_tree[tree_ptr].parent = orth_tree_parent;
00160 }
00161 else
00162 {
00163
00164 int orth_tree_ptr = in_orth_tree[orth_tree_parent].left;
00165 while (in_orth_tree[orth_tree_ptr].right != UNDEFINED)
00166 orth_tree_ptr = in_orth_tree[orth_tree_ptr].right;
00167
00168 in_orth_tree[orth_tree_ptr].right = tree_ptr;
00169 in_orth_tree[tree_ptr].parent = orth_tree_ptr;
00170 }
00171 }
00172