Fix over-aggressive input cleansing

This commit is contained in:
WandererFan 2016-09-10 19:37:03 -04:00
parent 4d7f00860e
commit 81472a5fd8
2 changed files with 90 additions and 144 deletions

View File

@ -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<TechDraw::graph>::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<TopoDS_Wire> 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<ewWire>::iterator iWire = result.wires.begin(); // a WE within [WE]
for (;iWire != result.wires.end(); iWire++) {
std::vector<WalkerEdge>::iterator iEdge = (*iWire).wedges.begin();
@ -231,25 +218,15 @@ std::vector<TopoDS_Wire> 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<ewWire>::iterator iWire = result.wires.begin();
int edgeCount = 1;
for (;iWire != result.wires.end(); iWire++) {
std::vector<WalkerEdge>::iterator iEdge = (*iWire).wedges.begin();
std::vector<TopoDS_Edge> 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<TopoDS_Vertex> EdgeWalker:: makeUniqueVList(std::vector<TopoDS_Edge>
}
//!make WalkerEdges (unique Vertex index pairs) from edge list
//remove duplicate edges from input
std::vector<WalkerEdge> EdgeWalker::makeWalkerEdges(std::vector<TopoDS_Edge> edges,
std::vector<TopoDS_Vertex> verts)
{
saveInEdges = edges;
std::vector<WalkerEdge> rawList;
std::vector<WalkerEdge> 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<WalkerEdge> we = removeDuplicateInput(rawList);
for (auto& w:we)
{
saveIndex.push_back(w.idx);
}
return we;
return walkerEdges;
}
int EdgeWalker::findUniqueVert(TopoDS_Vertex vx, std::vector<TopoDS_Vertex> &uniqueVert)
@ -352,107 +322,6 @@ int EdgeWalker::findUniqueVert(TopoDS_Vertex vx, std::vector<TopoDS_Vertex> &uni
return result;
}
//removes duplicates from input and sets idx to position in original list
std::vector<WalkerEdge> EdgeWalker::removeDuplicateInput(std::vector<WalkerEdge> input)
{
std::vector<WalkerEdge> result;
//std::vector<int> 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<WalkerEdge>::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<ewWire>::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<TopoDS_Wire> EdgeWalker::sortStrip(std::vector<TopoDS_Wire> fw, bool includeBiggest)
{
std::vector<TopoDS_Wire> sortedWires = sortWiresBySize(fw,false); //biggest 1st
@ -551,3 +420,83 @@ std::vector<TopoDS_Wire> EdgeWalker::sortWiresBySize(std::vector<TopoDS_Wire>& 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<ewWire>::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);
}

View File

@ -80,7 +80,7 @@ public:
class ewWireList
{
public:
ewWireList removeDuplicates();
ewWireList removeDuplicateWires();
std::vector<ewWire> wires;
void push_back(ewWire e);
@ -121,7 +121,6 @@ public:
std::vector<TopoDS_Vertex> makeUniqueVList(std::vector<TopoDS_Edge> edges);
std::vector<WalkerEdge> makeWalkerEdges(std::vector<TopoDS_Edge> edges,
std::vector<TopoDS_Vertex> verts);
std::vector<WalkerEdge> removeDuplicateInput(std::vector<WalkerEdge> input);
int findUniqueVert(TopoDS_Vertex vx, std::vector<TopoDS_Vertex> &uniqueVert);
std::vector<TopoDS_Wire> sortStrip(std::vector<TopoDS_Wire> fw, bool includeBiggest);
@ -132,12 +131,10 @@ public:
protected:
static bool wireCompare(const TopoDS_Wire& w1, const TopoDS_Wire& w2);
std::vector<TopoDS_Edge> saveInEdges;
std::vector<int> saveIndex;
private:
edgeVisitor m_eV;
TechDraw::graph m_g;
bool duplicateInput;
};
} //end namespace TechDraw