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 #ifndef PLTOSP_H
00038 #define PLTOSP_H
00039
00040 #include <fstream>
00041 #include <vector>
00042 #include <algorithm>
00043 #include <math.h>
00044 #include <stdlib.h>
00045
00046 using namespace std;
00047
00048 namespace parquetfp
00049 {
00050 enum PL2SP_ALGO{NAIVE_ALGO, TCG_ALGO};
00051
00052 class Pl2SP
00053 {
00054 private:
00055 vector<double> _xloc;
00056 vector<double> _yloc;
00057 vector<double> _widths;
00058 vector<double> _heights;
00059
00060 vector<unsigned> _XX;
00061 vector<unsigned> _YY;
00062
00063 int _cnt;
00064 public:
00065 Pl2SP(vector<double>& xloc, vector<double>& yloc, vector<double>& widths,
00066 vector<double>& heights, PL2SP_ALGO whichAlgo);
00067
00068 ~Pl2SP() {}
00069
00070 void naiveAlgo(void);
00071 void TCGAlgo(void);
00072
00073
00074 void TCG_FM(vector< vector <bool> >& TCGMatrixHoriz,
00075 vector< vector <bool> >& TCGMatrixVert);
00076
00077
00078 void TCG_DP(vector< vector <bool> >& TCGMatrixHoriz,
00079 vector< vector <bool> >& TCGMatrixVert);
00080 void TCGDfs(vector< vector <bool> >& TCGMatrix,
00081 vector< vector <bool> >& adjMatrix, int v,
00082 vector<int>& pre);
00083
00084 const vector<unsigned>& getXSP(void) const
00085 { return _XX; }
00086
00087 const vector<unsigned>& getYSP(void) const
00088 { return _YY; }
00089
00090 void print(void) const;
00091
00092 };
00093
00094 struct RowElem
00095 {
00096 unsigned index;
00097 double xloc;
00098 };
00099
00100
00101 struct less_mag
00102 {
00103 bool operator()(const RowElem &elem1, const RowElem &elem2)
00104 { return(elem1.xloc < elem2.xloc); }
00105 };
00106
00107 class SPXRelation
00108 {
00109 vector< vector<bool> >& TCGMatrixHoriz;
00110 vector< vector<bool> >& TCGMatrixVert;
00111
00112 public:
00113 SPXRelation(vector< vector<bool> >& TCGMatrixHorizIP,
00114 vector< vector<bool> >& TCGMatrixVertIP) :
00115 TCGMatrixHoriz(TCGMatrixHorizIP), TCGMatrixVert(TCGMatrixVertIP)
00116 {}
00117
00118 bool operator()(unsigned i, unsigned j)
00119 {
00120 if(TCGMatrixHoriz[i][j] == 1)
00121 return 1;
00122 else if(TCGMatrixHoriz[j][i] == 1)
00123 return 0;
00124 else if(TCGMatrixVert[j][i] == 1)
00125 return 1;
00126 else if(TCGMatrixVert[i][j] == 1)
00127 return 0;
00128 else
00129 {
00130
00131 if(i<j)
00132 return 1;
00133 else
00134 return 0;
00135 }
00136 }
00137 };
00138
00139 class SPYRelation
00140 {
00141 vector< vector<bool> >& TCGMatrixHoriz;
00142 vector< vector<bool> >& TCGMatrixVert;
00143
00144 public:
00145 SPYRelation(vector< vector<bool> >& TCGMatrixHorizIP,
00146 vector< vector<bool> >& TCGMatrixVertIP) :
00147 TCGMatrixHoriz(TCGMatrixHorizIP), TCGMatrixVert(TCGMatrixVertIP)
00148 {}
00149 bool operator()(unsigned i, unsigned j)
00150 {
00151 if(TCGMatrixHoriz[i][j] == 1)
00152 return 1;
00153 else if(TCGMatrixHoriz[j][i] == 1)
00154 return 0;
00155 else if(TCGMatrixVert[j][i] == 1)
00156 return 0;
00157 else if(TCGMatrixVert[i][j] == 1)
00158 return 1;
00159 else
00160 {
00161
00162 if(i<j)
00163 return 1 ;
00164 else
00165 return 0;
00166 }
00167 }
00168 };
00169 }
00170
00171
00172 #endif