Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

btreecompact.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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; // start with first block
00050    while (tree_curr != NUM_BLOCKS) // until reach the root again
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; // begins of cPtr/tPtr match
00111    orth_tree_parent = contour_ptr;       // initialize necessary
00112    maxCTL = in_contour[contour_ptr].CTL; // since width/height may be 0
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    // edit "in_orth_tree", the orthogonal tree
00155    if (in_orth_tree[orth_tree_parent].left == UNDEFINED)
00156    {
00157       // left-child of the parent
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       // sibling fo the left-child of the parent
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 // --------------------------------------------------------

Generated on Mon Apr 25 01:09:24 2005 for Parquete by doxygen 1.3.2