85 int costGen = 1,
int costAssoc = 1,
bool align =
false);
119 template<
class ATYPE>
124 int costGen = 1,
int costAssoc = 1,
bool align =
false)
231 ATYPE d = (*m_pPos)[x] - (*m_pPos)[y];
237 return (*
m_pSec)[x] - (*m_pSec)[y];
313 template<
class ATYPE>
315 template<
class ATYPE>
317 template<
class ATYPE>
321 template<
class ATYPE>
325 template<
class ATYPE>
331 if ((m_pOR->direction(adj) == m_arcDir || m_pOR->direction(adj) == m_oppArcDir)
334 m_length[m_edgeToBasicArc[adj]] = 0;
339 }
while (adj != adjFirst);
345 && (m_pOR->direction(adjFirst) == m_arcDir || m_pOR->direction(adjFirst) == m_oppArcDir)) {
346 int numIncoming = faceSize - 3;
347 int median = (numIncoming / 2) + 1;
356 if (m_pOR->direction(adjFirst) == m_arcDir) {
363 for (
int i = 0; i < median; i++) {
368 node vCenter = newNode();
369 setExtra(vCenter, vMin, 0);
374 edge helper = newEdge(m_pathNode[vMin], vCenter);
375 m_length[helper] = 0;
380 edge e1 = newEdge(vCenter, upper);
382 m_cost[e1] = m_MedianArcCost;
385 edge e2 = newEdge(vCenter, lower);
387 m_cost[e2] = m_MedianArcCost;
393 template<
class ATYPE>
397 for (adj = cornerDir; m_pOR->direction(adj) == m_arcDir; adj = adj->
faceCycleSucc())
398 m_cost[m_edgeToBasicArc[adj]] = 0;
399 for (adj = cornerOppDir; m_pOR->direction(adj) == m_oppArcDir; adj = adj->
faceCycleSucc())
400 m_cost[m_edgeToBasicArc[adj]] = 0;
404 for (adj = cornerDir; m_pOR->direction(adj) == m_arcDir; adj = adj->
faceCycleSucc()) {
405 m_cost[m_edgeToBasicArc[adj]] = 0;
413 for (adj = cornerOppDir; m_pOR->direction(adj) == m_oppArcDir; adj = adj->
faceCycleSucc()) {
414 m_cost[m_edgeToBasicArc[adj]] = 0;
427 template<
class ATYPE>
436 const ATYPE overhang = rc.
overhang();
444 resetGenMergerLengths(PG, PG.
expandAdj(v));
448 ATYPE size = sizeOrig[v];
453 ATYPE rcMin = overhang + rc(v, dirMin);
454 ATYPE rcMax = overhang + rc(v, dirMax);
462 setBoundaryCosts(cornerDir, cornerOppDir);
469 m_length[m_edgeToBasicArc[cornerDir]] = rcMin;
470 m_length[m_edgeToBasicArc[cornerMax->
faceCyclePred()]] = rcMax;
473 m_length[m_edgeToBasicArc[cornerDir]] = 0;
474 delEdge(m_edgeToBasicArc[cornerDir]);
478 m_length[m_edgeToBasicArc[cornerOppDir]] = rcMax;
479 m_length[m_edgeToBasicArc[cornerMin->
faceCyclePred()]] = rcMin;
482 m_length[m_edgeToBasicArc[cornerOppDir]] = 0;
483 delEdge(m_edgeToBasicArc[cornerOppDir]);
494 edge e = newEdge(vMin, vMax);
495 m_length[e] = rcMin + size + rcMax - 2 * overhang;
496 m_cost[e] = 2 * m_vertexArcCost;
501 ATYPE minHalf = size / 2;
502 ATYPE maxHalf = size - minHalf;
503 ATYPE lenMin = rcMin + minHalf - overhang;
504 ATYPE lenMax = maxHalf + rcMax - overhang;
508 edge e1 = newEdge(vMin, vCenter);
509 m_length[e1] = lenMin;
510 m_cost[e1] = m_vertexArcCost;
512 edge e2 = newEdge(vCenter, vMax);
513 m_length[e2] = lenMax;
514 m_cost[e2] = m_vertexArcCost;
520 edge e1 = newEdge(vMin, vCenter);
521 m_length[e1] = lenMin;
522 m_cost[e1] = m_vertexArcCost;
524 edge e2 = newEdge(vCenter, vMax);
525 m_length[e2] = lenMax;
526 m_cost[e2] = m_vertexArcCost;
534 template<
class ATYPE>
537 edge arc = m_edgeToBasicArc[e];
538 if (arc ==
nullptr) {
551 m_cost[arc] = m_doubleBendCost;
560 template<
class ATYPE>
565 setBasicArcsZeroLength(PG);
579 resetGenMergerLengths(PG, PG.
expandAdj(v));
583 ATYPE size = sizeOrig[v];
593 m_length[m_edgeToBasicArc[adj]] = minDist.
epsilon(v, m_arcDir, 0);
594 m_length[m_edgeToBasicArc[last]] = minDist.
epsilon(v, m_arcDir, 1);
600 m_length[m_edgeToBasicArc[adj]] = minDist.
delta(v, m_arcDir, i);
606 m_length[m_edgeToBasicArc[adj]] = minDist.
epsilon(v, m_oppArcDir, 0);
607 m_length[m_edgeToBasicArc[last]] = minDist.
epsilon(v, m_oppArcDir, 1);
613 m_length[m_edgeToBasicArc[adj]] = minDist.
delta(v, m_oppArcDir, i);
632 ATYPE lenMin = size / 2;
633 ATYPE lenMax = size - lenMin;
634 node vCenter = newNode();
635 setExtra(vCenter, cornerDir->
theNode(), lenMin);
637 edge e1 = newEdge(vMin, vCenter);
638 m_length[e1] = lenMin;
639 m_cost[e1] = m_vertexArcCost;
641 edge e2 = newEdge(vCenter, vMax);
642 m_length[e2] = lenMax;
643 m_cost[e2] = m_vertexArcCost;
649 node vBungee = newNode();
651 setExtra(vBungee, cornerDir->
theNode(), minDist.
epsilon(v, m_arcDir, 0));
653 edge eToBungee = newEdge(vMin, vBungee);
656 m_cost[eToBungee] = 0;
657 m_length[eToBungee] = minDist.
epsilon(v, m_arcDir, 0);
659 edge eBungeeCenter = newEdge(vBungee, vCenter);
662 m_cost[eBungeeCenter] = m_bungeeCost;
663 m_length[eBungeeCenter] = 0;
666 edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerDir->
twinNode()]);
669 m_cost[eBungeeOut] = m_bungeeCost;
670 m_length[eBungeeOut] = 0;
673 edge eFromOut = newEdge(m_pathNode[cornerDir->
twinNode()], vMax);
675 m_cost[eFromOut] = 0;
676 m_length[eFromOut] = minDist.
epsilon(v,m_arcDir,1);
682 node vBungee = newNode();
684 setExtra(vBungee, cornerDir->
theNode(), minDist.
epsilon(v, m_oppArcDir, 0));
686 edge eToBungee = newEdge(vMin, vBungee);
689 m_cost[eToBungee] = 0;
690 m_length[eToBungee] = minDist.
epsilon(v, m_oppArcDir, 0);
692 edge eBungeeCenter = newEdge(vBungee, vCenter);
695 m_cost[eBungeeCenter] = m_bungeeCost;
696 m_length[eBungeeCenter] = 0;
699 edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerOppDir->
twinNode()]);
702 m_cost[eBungeeOut] = m_bungeeCost;
703 m_length[eBungeeOut] = 0;
706 edge eFromOut = newEdge(m_pathNode[cornerOppDir->
twinNode()], vMax);
708 m_cost[eFromOut] = 0;
709 m_length[eFromOut] = minDist.
epsilon(v,m_oppArcDir,0);
714 edge e = newEdge(vMin, vMax);
716 m_cost[e] = 2 * m_vertexArcCost;
721 ATYPE lenMin = size / 2;
722 ATYPE lenMax = size - lenMin;
730 edge e1 = newEdge(vMin, vCenter);
731 m_length[e1] = lenMin;
732 m_cost[e1] = m_vertexArcCost;
734 edge e2 = newEdge(vCenter, vMax);
735 m_length[e2] = lenMax;
736 m_cost[e2] = m_vertexArcCost;
740 node vCenter = newNode();
742 setExtra(vCenter, cornerDir->
theNode(), lenMin);
744 edge e1 = newEdge(vMin, vCenter);
745 m_length[e1] = lenMin;
746 m_cost[e1] = m_vertexArcCost;
748 edge e2 = newEdge(vCenter, vMax);
749 m_length[e2] = lenMax;
750 m_cost[e2] = m_vertexArcCost;
755 node vBungee = newNode();
757 setExtra(vBungee, cornerDir->
theNode(), minDist.
epsilon(v, m_arcDir, 0));
759 edge eToBungee = newEdge(vMin, vBungee);
762 m_cost[eToBungee] = 0;
763 m_length[eToBungee] = minDist.
epsilon(v, m_arcDir, 0);
765 edge eBungeeCenter = newEdge(vBungee, vCenter);
768 m_cost[eBungeeCenter] = m_bungeeCost;
769 m_length[eBungeeCenter] = 0;
772 edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerDir->
twinNode()]);
775 m_cost[eBungeeOut] = m_bungeeCost;
776 m_length[eBungeeOut] = 0;
781 edge e1 = newEdge(vMin, vCenter);
782 m_length[e1] = lenMin;
783 m_cost[e1] = m_vertexArcCost;
785 edge e2 = newEdge(vCenter, vMax);
786 m_length[e2] = lenMax;
787 m_cost[e2] = m_vertexArcCost;
792 node vCenter = newNode();
794 setExtra(vCenter, cornerDir->
theNode(), lenMin);
796 edge e1 = newEdge(vMin, vCenter);
797 m_length[e1] = lenMin;
798 m_cost[e1] = m_vertexArcCost;
800 edge e2 = newEdge(vCenter, vMax);
801 m_length[e2] = lenMax;
802 m_cost[e2] = m_vertexArcCost;
806 node vBungee = newNode();
808 setExtra(vBungee, cornerDir->
theNode(), minDist.
epsilon(v, m_oppArcDir, 0));
810 edge eToBungee = newEdge(vMin, vBungee);
813 m_cost[eToBungee] = 0;
814 m_length[eToBungee] = minDist.
epsilon(v, m_oppArcDir, 0);
816 edge eBungeeCenter = newEdge(vBungee, vCenter);
819 m_cost[eBungeeCenter] = m_bungeeCost;
820 m_length[eBungeeCenter] = 0;
823 edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerOppDir->
twinNode()]);
826 m_cost[eBungeeOut] = m_bungeeCost;
827 m_length[eBungeeOut] = 0;
833 setBoundaryCosts(cornerDir, cornerOppDir);
838 writeGML(
"eastvertexsizeinserted.gml");
840 writeGML(
"northvertexsizeinserted.gml");
847 template<
class ATYPE>
850 for (
edge e : edges) {
851 c += cost(e) * (pos[e->target()] - pos[e->source()]);
861 template<
class ATYPE>
863 if (sweepLine.empty()) {
869 if ((*it).m_high < (*it).m_low) {
873 ATYPE x = (*it).m_low;
875 for (++it; it.
valid(); ++it) {
876 if ((*it).m_high < (*it).m_low) {
879 if ((*it).m_high > x) {
888 template<
class ATYPE>
898 for (
int d = 0; d < 4; ++d) {
904 insertVisibilityArcs(PG, posDir, posOrthDir, minDist);
912 template<
class ATYPE>
938 for (
node v : nodes) {
940 if (m_path[v].empty()) {
946 segPos[v] = posDir[*it];
947 low[v] = high[v] = posOrthDir[*it];
949 for (++it; it.
valid(); ++it) {
950 ATYPE x = posOrthDir[*it];
963 bool subtractSep =
true;
964 if (nodeLow->
degree() == 2) {
967 if(m_pOR->direction(adj) == m_arcDir || m_pOR->direction(adj) == m_oppArcDir) {
974 m_pOR->direction(adj2) == m_pOR->direction(adjFound);
976 if(posDir[adjFound->
theNode()] == posDir[adj2->twinNode()])
1005 : vi.
m_corner[
static_cast<int>(dirMin)]->faceCycleSucc();
1013 ATYPE delta = (isCaseA)
1014 ? min(abs(posOrthDir[adjPred->
theNode()] - posOrthDir[adjPred->
twinNode()]), m_sep)
1015 : min(abs(posOrthDir[adj->
theNode()] - posOrthDir[adj->
twinNode()]), m_sep);
1016 ATYPE boundary = (isCaseA)
1017 ? min(posOrthDir[adjPred->
theNode()], posOrthDir[adjPred->
twinNode()])
1023 && m_pOR->angle(adjTwin) == 2) {
1026 low[s1] = lowReal[s1] - delta;
1027 low[s2] = lowReal[s2] - delta;
1033 && m_pOR->angle(adjTwin->
cyclicPred()) == 2) {
1036 low[s1] = lowReal[s1] - delta;
1037 low[s2] = lowReal[s2] - delta;
1044 OrthoDir runDir = m_pOR->direction(adjCross);
1047 && adjTwin->
theNode()->
degree() == 2 && m_pOR->angle(adjTwin) == angleAtMin) {
1050 node s = m_edgeToBasicArc[adjCross]->source();
1051 if (lowReal[s] != low[s]) {
1052 if (low[s] >= boundary) {
1057 low[s] += m_sep - delta;
1070 }
while (m_pOR->direction(adjCross) == segDir
1071 || m_pOR->direction(adjCross) == segOppDir);
1077 node sNext = m_edgeToBasicArc[adjCross]->opposite(s);
1079 if (segPos[sNext] != segPos[s]) {
1083 low[sNext] = lowReal[sNext];
1088 adjTwin = adjCross->
twin();
1090 if (runDir != m_pOR->direction(adjCross)) {
1106 ATYPE delta = -posOrthDir[adj->
twinNode()] + posOrthDir[adj->
theNode()];
1109 ATYPE delta = (isCaseA)
1110 ? min(abs(posOrthDir[adj->
twinNode()] - posOrthDir[adj->
theNode()]), m_sep)
1111 : min(abs(posOrthDir[adjPred->
theNode()] - posOrthDir[adjPred->
twinNode()]),
1113 ATYPE boundary = (isCaseA)
1115 : min(posOrthDir[adjPred->
theNode()], posOrthDir[adjPred->
twinNode()]);
1121 && m_pOR->angle(adjTwin->
cyclicPred()) == 2) {
1124 low[s1] = lowReal[s1] - delta;
1125 low[s2] = lowReal[s2] - delta;
1129 && m_pOR->angle(adjTwin) == 2) {
1132 low[s1] = lowReal[s1] - delta;
1133 low[s2] = lowReal[s2] - delta;
1142 OrthoDir runDir = m_pOR->direction(adjCross);
1145 && adjTwin->
theNode()->
degree() == 2 && m_pOR->angle(adjTwin) == angleAtMax) {
1146 node s = m_edgeToBasicArc[adjCross]->target();
1147 if (lowReal[s] != low[s]) {
1148 if (low[s] >= boundary) {
1153 low[s] += m_sep - delta;
1167 }
while (m_pOR->direction(adjCross) == segDir
1168 || m_pOR->direction(adjCross) == segOppDir);
1174 node sNext = m_edgeToBasicArc[adjCross]->opposite(s);
1176 if (segPos[sNext] != segPos[s]) {
1180 low[sNext] = lowReal[sNext];
1185 adjTwin = adjCross->
twin();
1188 if (runDir != m_pOR->direction(adjCross)) {
1198 computeTopologicalSegmentNum(topNum);
1204 allNodes(sortedPathNodes);
1205 sortedPathNodes.quicksort(cmpBySegPos);
1211 for (itV = sortedPathNodes.begin(); itV.
valid(); ++itV) {
1213 if (m_path[*itV].empty()) {
1220 for (it = sweepLine.begin(); it.
valid(); ++it) {
1221 if ((*it).m_low < high[v]) {
1231 if ((*it).m_high <= low[v]) {
1239 bool isItUpDel = (((*itUp).m_low >= low[v]) && ((*itUp).m_high <= high[v]));
1241 for (; it.
valid() && (*it).m_low >= low[v]; it = itSucc) {
1243 if ((*it).m_high <= high[v]) {
1249 if (it == itUp && (*it).m_high > high[v]) {
1250 node w = (*it).m_pathNode;
1252 (*it).m_low = high[v];
1257 if ((!isItUpDel) && itUp != it && (*itUp).m_low < high[v]) {
1258 (*itUp).m_low = high[v];
1262 if ((*it).m_high > low[v]) {
1263 (*it).m_high = low[v];
1275 removeRedundantVisibArcs(visibArcs);
1285 node seg = m_pathNode[v];
1287 if (m_pOR->direction(adj) != segDir) {
1292 if (eOrig ==
nullptr) {
1305 for (itT = visibArcs.
begin(); itT.
valid(); itT = itTSucc) {
1306 itTSucc = itT.
succ();
1307 node v = (*itT).x1(), w = (*itT).x2();
1310 if (correspEdge[v] && (correspEdge[v] == correspEdge[w])) {
1311 if (itTPred.
valid()) {
1324 for (itT = visibArcs.
begin(); itT.
valid(); ++itT) {
1326 node v = (*itT).x1(), w = (*itT).x2();
1327 if (!(m_extraNode[v] || m_extraNode[w])) {
1329 node boundRepresentant1 = m_path[v].front();
1330 node boundRepresentant2 = m_path[w].front();
1331 node en1 = m_pPR->expandedNode(boundRepresentant1);
1332 node en2 = m_pPR->expandedNode(boundRepresentant2);
1334 if (!((en1 && en2) && (en1 == en2))) {
1335 edge e = newEdge(v, w);
1339 m_length[e] = max(m_sep, minDist.
separation());
1343 writeGML(
"visibilityinserted.gml");
1355 template<
class ATYPE>
1357 for (
edge e : getGraph().edges) {
1358 node v = m_path[e->source()].front();
1359 node w = m_path[e->target()].front();
1360 if (pos[w] - pos[v] < length(e)) {
1361 std::cout <<
"feasibility check failed for edge " << e << std::endl;
1362 std::cout <<
" representatives: " << v <<
", " << w << std::endl;
1363 std::cout <<
" length: " << length(e) << std::endl;
1364 std::cout <<
" actual distance: " << pos[w] - pos[v] << std::endl;
1365 std::cout <<
" type of " << e <<
": ";
1366 switch (m_type[e]) {
1368 std::cout <<
"basic arc" << std::endl;
1371 std::cout <<
"vertex-size arc" << std::endl;
1374 std::cout <<
"visibility arc" << std::endl;
1377 std::cout <<
"median arc" << std::endl;
1380 std::cout <<
"reducible arc" << std::endl;
1383 std::cout <<
"fixtozero arc" << std::endl;