diff --git a/src/Mod/TechDraw/App/EdgeWalker.cpp b/src/Mod/TechDraw/App/EdgeWalker.cpp index e2a0e2148..4384e724b 100644 --- a/src/Mod/TechDraw/App/EdgeWalker.cpp +++ b/src/Mod/TechDraw/App/EdgeWalker.cpp @@ -88,11 +88,10 @@ void edgeVisitor::setGraph(TechDraw::graph& g) } //******************************************************* -//* EdgeWalker +//* EdgeWalker methods //******************************************************* -EdgeWalker::EdgeWalker() : - duplicateInput(false) +EdgeWalker::EdgeWalker() { } @@ -155,8 +154,6 @@ bool EdgeWalker::perform() const TechDraw::graph& m_g, graph_traits::edge_descriptor edge); - - bool isPlanar = boyer_myrvold_planarity_test(boyer_myrvold_params::graph = m_g, boyer_myrvold_params::embedding = &embedding[0], boyer_myrvold_params::kuratowski_subgraph = @@ -199,16 +196,6 @@ std::vector EdgeWalker::getResultWires() return fw; } - //convert from noduplicate index to duplicates index - for (auto& w:result.wires) { - for (auto& we:w.wedges) { - //we.idx is the edge index in the short list (no duplicates) - //saveIndex[we.idx] should be the index in the long list - we.idx = saveIndex[we.idx]; - } - } - - std::vector::iterator iWire = result.wires.begin(); // a WE within [WE] for (;iWire != result.wires.end(); iWire++) { std::vector::iterator iEdge = (*iWire).wedges.begin(); @@ -231,25 +218,15 @@ std::vector EdgeWalker::getResultNoDups() return fw; } - //convert from noduplicate index to duplicates index - for (auto& w:result.wires) { - for (auto& we:w.wedges) { - //we.idx is the edge index in the short list (no duplicates) - //saveIndex[we.idx] should be the index in the long list - we.idx = saveIndex[we.idx]; - } - } - result = result.removeDuplicates(); + result = result.removeDuplicateWires(); std::vector::iterator iWire = result.wires.begin(); - int edgeCount = 1; for (;iWire != result.wires.end(); iWire++) { std::vector::iterator iEdge = (*iWire).wedges.begin(); std::vector topoEdges; for (;iEdge != (*iWire).wedges.end(); iEdge++) { TopoDS_Edge e = saveInEdges.at((*iEdge).idx); topoEdges.push_back(e); - edgeCount++; } TopoDS_Wire w = makeCleanWire(topoEdges); //make 1 clean wire from its edges fw.push_back(w); @@ -312,30 +289,23 @@ std::vector EdgeWalker:: makeUniqueVList(std::vector } //!make WalkerEdges (unique Vertex index pairs) from edge list -//remove duplicate edges from input std::vector EdgeWalker::makeWalkerEdges(std::vector edges, std::vector verts) { saveInEdges = edges; - std::vector rawList; + std::vector walkerEdges; for (auto e:edges) { TopoDS_Vertex ev1 = TopExp::FirstVertex(e); TopoDS_Vertex ev2 = TopExp::LastVertex(e); int v1dx = findUniqueVert(ev1, verts); int v2dx = findUniqueVert(ev2, verts); - WalkerEdge rl; - rl.v1 = v1dx; - rl.v2 = v2dx; - rawList.push_back(rl); + WalkerEdge we; + we.v1 = v1dx; + we.v2 = v2dx; + walkerEdges.push_back(we); } - std::vector we = removeDuplicateInput(rawList); - for (auto& w:we) - { - saveIndex.push_back(w.idx); - } - - return we; + return walkerEdges; } int EdgeWalker::findUniqueVert(TopoDS_Vertex vx, std::vector &uniqueVert) @@ -352,107 +322,6 @@ int EdgeWalker::findUniqueVert(TopoDS_Vertex vx, std::vector &uni return result; } -//removes duplicates from input and sets idx to position in original list -std::vector EdgeWalker::removeDuplicateInput(std::vector input) -{ - std::vector result; - //std::vector ref; - if (input.empty()) { - return result; - } - - result.push_back(*(input.begin())); //save the first WE - result[0].idx = 0; - //ref.push_back(0); - std::vector::iterator iWE = (input.begin()) + 1; //starting with second - int i = 1; - for (; iWE != input.end(); iWE++, i++) { - bool addToResult = true; - for (auto& w:result) { - if ((*iWE).isEqual(w)) { //already in result? - addToResult = false; - Base::Console().Log("LOG - EW::removeDuplicateInput - input edge: %d is a duplicate\n",i); - break; - } - } - if (addToResult) { - (*iWE).idx = i; - result.push_back((*iWE)); - //ref.push_back(i); - } - } - return result; -} - -bool WalkerEdge::isEqual(WalkerEdge w) -{ - bool result = false; - if ((( v1 == w.v1) && (v2 == w.v2)) || - (( v1 == w.v2) && (v2 == w.v1)) ) { - result = true; - } - return result; -} - - -/*static*/ bool WalkerEdge::weCompare(WalkerEdge i, WalkerEdge j) //used for sorting -{ - return (i.idx < j.idx); -} - -bool ewWire::isEqual(ewWire w2) -{ - bool result = true; - if (wedges.size() != w2.wedges.size()) { - result = false; - } else { - std::sort(wedges.begin(),wedges.end(),WalkerEdge::weCompare); - std::sort(w2.wedges.begin(),w2.wedges.end(),WalkerEdge::weCompare); - for (unsigned int i = 0; i < w2.wedges.size(); i ++) { - if (wedges.at(i).idx != w2.wedges.at(i).idx) { - result = false; - break; - } - } - } - return result; -} - -void ewWire::push_back(WalkerEdge w) -{ - wedges.push_back(w); -} - -//check wirelist for wires that use the same set of edges, but maybe in a different order. -ewWireList ewWireList::removeDuplicates() -{ - ewWireList result; - if (wires.empty()) { - return result; - } - result.push_back(*(wires.begin())); //save the first ewWire - std::vector::iterator iWire = (wires.begin()) + 1; //starting with second - for (; iWire != wires.end(); iWire++) { - bool addToResult = true; - for (auto& w:result.wires) { - if ((*iWire).isEqual(w)) { //already in result? - addToResult = false; - break; - } - } - if (addToResult) { - result.push_back((*iWire)); - } - } - return result; -} - -void ewWireList::push_back(ewWire w) -{ - wires.push_back(w); -} - - std::vector EdgeWalker::sortStrip(std::vector fw, bool includeBiggest) { std::vector sortedWires = sortWiresBySize(fw,false); //biggest 1st @@ -551,3 +420,83 @@ std::vector EdgeWalker::sortWiresBySize(std::vector& w return box1.SquareExtent() > box2.SquareExtent(); } + + +//******************************************* +// WalkerEdge Methods +//******************************************* +bool WalkerEdge::isEqual(WalkerEdge w) +{ + bool result = false; + if ((( v1 == w.v1) && (v2 == w.v2)) || + (( v1 == w.v2) && (v2 == w.v1)) ) { + result = true; + } + return result; +} + + +/*static*/ bool WalkerEdge::weCompare(WalkerEdge i, WalkerEdge j) //used for sorting +{ + return (i.idx < j.idx); +} + + +//***************************************** +// ewWire Methods +//***************************************** +bool ewWire::isEqual(ewWire w2) +{ + bool result = true; + if (wedges.size() != w2.wedges.size()) { + result = false; + } else { + std::sort(wedges.begin(),wedges.end(),WalkerEdge::weCompare); + std::sort(w2.wedges.begin(),w2.wedges.end(),WalkerEdge::weCompare); + for (unsigned int i = 0; i < w2.wedges.size(); i ++) { + if (wedges.at(i).idx != w2.wedges.at(i).idx) { + result = false; + break; + } + } + } + return result; +} + +void ewWire::push_back(WalkerEdge w) +{ + wedges.push_back(w); +} + + +//*************************************** +// ewWireList methods +//*************************************** +//check wirelist for wires that use the same set of edges, but maybe in a different order. +ewWireList ewWireList::removeDuplicateWires() +{ + ewWireList result; + if (wires.empty()) { + return result; + } + result.push_back(*(wires.begin())); //save the first ewWire + std::vector::iterator iWire = (wires.begin()) + 1; //starting with second + for (; iWire != wires.end(); iWire++) { + bool addToResult = true; + for (auto& w:result.wires) { + if ((*iWire).isEqual(w)) { //already in result? + addToResult = false; + break; + } + } + if (addToResult) { + result.push_back((*iWire)); + } + } + return result; +} + +void ewWireList::push_back(ewWire w) +{ + wires.push_back(w); +} diff --git a/src/Mod/TechDraw/App/EdgeWalker.h b/src/Mod/TechDraw/App/EdgeWalker.h index 10095bb04..873579193 100644 --- a/src/Mod/TechDraw/App/EdgeWalker.h +++ b/src/Mod/TechDraw/App/EdgeWalker.h @@ -80,7 +80,7 @@ public: class ewWireList { public: - ewWireList removeDuplicates(); + ewWireList removeDuplicateWires(); std::vector wires; void push_back(ewWire e); @@ -121,7 +121,6 @@ public: std::vector makeUniqueVList(std::vector edges); std::vector makeWalkerEdges(std::vector edges, std::vector verts); - std::vector removeDuplicateInput(std::vector input); int findUniqueVert(TopoDS_Vertex vx, std::vector &uniqueVert); std::vector sortStrip(std::vector fw, bool includeBiggest); @@ -132,12 +131,10 @@ public: protected: static bool wireCompare(const TopoDS_Wire& w1, const TopoDS_Wire& w2); std::vector saveInEdges; - std::vector saveIndex; private: edgeVisitor m_eV; TechDraw::graph m_g; - bool duplicateInput; }; } //end namespace TechDraw