00001
00002
00003
00004
00005
00006
00007
00008
00042 #ifdef _MSC_VER
00043 #pragma once
00044 #endif
00045
00046 #ifndef OGDF_EDGE_LABEL_H
00047 #define OGDF_EDGE_LABEL_H
00048
00049
00050 #include <ogdf/basic/geometry.h>
00051 #include <ogdf/basic/List.h>
00052 #include <ogdf/basic/BinaryHeap2.h>
00053 #include <ogdf/basic/Graph.h>
00054 #include <ogdf/basic/GraphCopy.h>
00055 #include <ogdf/planarity/PlanRepUML.h>
00056 #include <ogdf/basic/GridLayoutMapped.h>
00057 #include <ogdf/orthogonal/OrthoRep.h>
00058
00059 #include <ogdf/labeling/ELabelInterface.h>
00060
00061
00062
00063
00064
00065 namespace ogdf {
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 enum OutputParameter {opStandard, opOmitIntersect, opOmitFIntersect, opResult};
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 enum candStatus {csAssigned, csFIntersect, csActive, csUsed};
00109
00110
00111
00112
00113
00114
00115
00116
00117 template <class coordType>
00118 class ELabelPos {
00119
00120 public:
00121
00122 ELabelPos();
00123
00124 ~ELabelPos() {}
00125
00126
00127
00128 virtual void call(PlanRepUML& pru, GridLayoutMapped& L, ELabelInterface<coordType>& eli);
00129
00130 virtual void call(GraphAttributes& ug, ELabelInterface<coordType>& eli);
00131
00132
00133 void setDefaultDistance(coordType dist)
00134 {m_defaultDistance = dist;}
00135
00136 void setDistance(edge e, eLabelTyp elt, coordType dist)
00137 {(m_distance[elt])[e] = dist;}
00138
00139
00140 void setEndLabelPlacement(bool b) {m_endLabelPlacement = b;}
00141
00142 void writeGML(const char *filename="labelgraph.gml",
00143 OutputParameter sectOmit = opStandard);
00144 void writeUMLGML(const char *filename="labelgraphUML.gml",
00145 OutputParameter sectOmit = opStandard);
00146
00147 protected:
00148
00149
00150
00151
00152 struct SegmentInfo {
00153
00154
00155 coordType length;
00156 int number;
00157 coordType min_x, max_x, min_y, max_y;
00158 OrthoDir direction;
00159 };
00160
00161
00162 struct FeatureInfo {
00163 coordType min_x, max_x, min_y, max_y, size_x, size_y;
00164 };
00165
00166
00167
00168
00169
00170
00171
00172 struct PosInfo {
00173 GenericPoint<coordType> m_coord;
00174 List< PosInfo* > m_intersect;
00175 int m_numActive;
00176 int m_numFeatures;
00177 int m_posIndex;
00178
00179 edge m_edge;
00180 eLabelTyp m_typ;
00181 candStatus m_active;
00182
00183 double m_cost;
00184
00185 PosInfo() {m_edge = 0; m_active = csActive; m_posIndex = 0; m_numActive = 0;
00186 m_typ = elName;
00187 m_cost = 0.0;
00188 }
00189 PosInfo(edge e, eLabelTyp elt, GenericPoint<coordType> gp, int posIndex = -1)
00190 {
00191 m_edge = e;
00192 m_typ = elt;
00193 m_coord = gp;
00194 m_numActive = 0;
00195 m_numFeatures = 0;
00196 m_posIndex = posIndex;
00197 m_active = csActive;
00198 m_cost = 0.0;
00199 }
00200 PosInfo(edge e, eLabelTyp elt)
00201 {
00202 m_edge = e;
00203 m_typ = elt;
00204 m_numActive = 0;
00205 m_numFeatures = 0;
00206 m_posIndex = 0;
00207 m_active = csActive;
00208 m_cost = 0.0;
00209 }
00210
00211 bool active() {return (m_active == csActive) || (m_active == csUsed);}
00212
00213 void deactivate() {}
00214
00215 };
00216
00217
00218
00219 struct FeatureLink {
00220 FeatureInfo m_fi;
00221 edge m_edge;
00222 eLabelTyp m_elt;
00223 int m_index;
00224 node m_node;
00225 PosInfo* m_posInfo;
00226
00227 FeatureLink() {m_edge = 0; m_elt = (eLabelTyp)0; m_index = 0; m_node = 0; m_posInfo = 0;}
00228 FeatureLink(edge e, eLabelTyp elt, node v, FeatureInfo& fi, int index)
00229 {
00230 m_edge = e;
00231 m_elt = elt;
00232 m_node = v;
00233 m_fi = fi;
00234 m_index = index;
00235 m_posInfo = 0;
00236 }
00237 FeatureLink(edge e, eLabelTyp elt, node v, FeatureInfo& fi, int index, PosInfo& pi)
00238 {
00239 m_edge = e;
00240 m_elt = elt;
00241 m_node = v;
00242 m_fi = fi;
00243 m_index = index;
00244 m_posInfo = π
00245 }
00246
00247 };
00248
00249 struct LabelInfo {
00250 edge m_e;
00251 int m_labelTyp;
00252
00253 int m_index;
00254
00255 LabelInfo() {m_e = 0; m_labelTyp = m_index = 0;}
00256 LabelInfo(edge e, int l, int i) {m_e = e; m_labelTyp = l; m_index = i;}
00257 };
00258
00259
00260
00261
00262
00263
00264
00265
00266 double costFI() {return m_posNum*5.0;}
00267
00268 double costLI() {return 0.9;}
00269
00270 double costEI() {return 0.7;}
00271
00272 double costPos() {return 0.6;}
00273
00274 double costSym() {return 1.3;}
00275
00276 coordType segmentMargin() {return m_segMargin;}
00277
00278
00279 bool usePosCost() {return m_posCost;}
00280 bool useSymCost() {return m_symCost;}
00281
00282
00283
00284
00285 void initSegments();
00286 void initUMLSegments();
00287
00288
00289 void initFeatureRectangles();
00290 void initUMLFeatureRectangles();
00291
00292
00293 void computeCandidates();
00294 void computeUMLCandidates();
00295
00296
00297
00298 void initStructure();
00299
00300
00301 void testFeatureIntersect();
00302 void testUMLFeatureIntersect();
00303
00304
00305 void saveRecovery(EdgeArray< GenericPoint<coordType> > (&saveCandidate)[labelNum]);
00306 void saveUMLRecovery(EdgeArray< GenericPoint<coordType> > (&saveCandidate)[labelNum]);
00307
00308
00309 void testAllIntersect();
00310 void testUMLAllIntersect();
00311
00312
00313
00314 List< GenericPoint<coordType> >& posList(edge e, int lnum) {return (m_candPosList[lnum])[e];}
00315
00316 List< PosInfo >& candList(edge e, int lnum) {return (m_candList[lnum])[e];}
00317
00318
00319
00320
00321
00322 int segNumber(edge e) {return m_poly[e].size() - 1;}
00323
00324
00325 OrthoDir segDir(edge e, int segNum)
00326 {
00327 OrthoDir od;
00328 if (segNum > segNumber(e)) OGDF_THROW(Exception);
00329
00330 IPoint ip1 = (*m_poly[e].get(segNum - 1));
00331 IPoint ip2 = (*m_poly[e].get(segNum));
00332 bool isHor = (ip1.m_y == ip2.m_y);
00333 if (isHor)
00334 {
00335 if (ip1.m_x > ip2.m_x) od = odWest;
00336 else od = odEast;
00337 }
00338 else
00339 {
00340
00341 if (ip1.m_y < ip2.m_y) od = odNorth;
00342 else od = odSouth;
00343 }
00344
00345 return od;
00346 }
00347
00348
00349 private:
00350
00351
00352
00353 int m_numAssignment;
00354
00355 int m_candStyle;
00356 int m_placeHeuristic;
00357 bool m_endInsertion;
00358
00359 bool m_endLabelPlacement;
00360
00361 bool m_posCost;
00362 bool m_symCost;
00363
00364
00365
00366
00367 int m_posNum;
00368
00369
00370
00371 bool m_countFeatureIntersect;
00372
00373 coordType m_segMargin;
00374
00375
00376 PlanRepUML* m_prup;
00377 GridLayoutMapped* m_gl;
00378
00379
00380 GraphAttributes* m_ug;
00381
00382
00383 ELabelInterface<coordType>* m_eli;
00384
00385
00386
00387 EdgeArray< List<GenericPoint<coordType> > > m_candPosList[labelNum];
00388
00389 EdgeArray< List < PosInfo > > m_candList[labelNum];
00390
00391 List< PosInfo* > m_freeLabels;
00392
00393 List< PosInfo* > m_sectLabels;
00394
00395 BinaryHeap2<double, PosInfo*> m_candidateHeap;
00396
00397
00398 EdgeArray< List<GenericPoint<coordType> > > m_poly;
00399
00400
00401 EdgeArray< List<SegmentInfo> > m_segInfo;
00402 EdgeArray<coordType> m_edgeLength;
00403
00404
00405 NodeArray<FeatureInfo> m_featureInfo;
00406
00407
00408 EdgeArray< List< List<LabelInfo> > > m_intersect[labelNum];
00409
00410 EdgeArray<bool> m_assigned[labelNum];
00411
00412
00413 EdgeArray<coordType> m_distance[labelNum];
00414 coordType m_defaultDistance;
00415
00416 Graph m_intersectGraph;
00417
00418 void init(PlanRepUML& pru, GridLayoutMapped& L, ELabelInterface<coordType>& eli);
00419
00420 void initUML(GraphAttributes& ug, ELabelInterface<coordType>& eli);
00421
00422
00423
00424 class FeatureComparer;
00425 friend class FeatureComparer;
00426 class FeatureComparer
00427 {
00428 public:
00429
00430 static int compare(const FeatureLink &f1, const FeatureLink &f2) {
00431 coordType d1 = f1.m_fi.min_y;
00432 coordType d2 = f2.m_fi.min_y;
00433
00434 if (DIsLess(d1, d2)) return -1;
00435 else if (DIsGreater(d1, d2)) return 1;
00436 else
00437 {
00438 if (DIsLess(f1.m_fi.min_x, f2.m_fi.min_x)) return -1;
00439 else if (DIsGreater(f1.m_fi.min_x, f2.m_fi.min_x)) return 1;
00440
00441 return 0;
00442 }
00443 }
00444 OGDF_AUGMENT_STATICCOMPARER(FeatureLink)
00445 };
00446
00447
00448 };
00449
00450 }
00451
00452
00453 #include <src/orthogonal/EdgeLabel-impl.h>
00454
00455
00456 #endif