Skip to content

Commit

Permalink
two bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy84 committed Jan 22, 2024
1 parent 72560d5 commit 3d0d954
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 36 deletions.
76 changes: 45 additions & 31 deletions vtkPolyDataBooleanFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int vtkPolyDataBooleanFilter::RequestData(vtkInformation *request, vtkInformatio

times.push_back(clock::now()-start);

// #ifdef DEBUG
#ifdef DEBUG
double sum = std::chrono::duration_cast<std::chrono::duration<double>>(std::accumulate(times.begin(), times.end(), clock::duration())).count();

std::vector<clock::duration>::const_iterator itr;
Expand All @@ -343,7 +343,7 @@ int vtkPolyDataBooleanFilter::RequestData(vtkInformation *request, vtkInformatio
<< ": " << time << "s (" << (time/sum*100) << "%)"
<< std::endl;
}
// #endif
#endif

}

Expand Down Expand Up @@ -1159,6 +1159,12 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt

strips.erase(std::remove_if(strips.begin(), strips.end(), fct), strips.end());

std::map<vtkIdType, std::reference_wrapper<StripType>> stripsM;

for (auto &strip : strips) {
stripsM.emplace(strip.front().strip, strip);
}

// init

for (auto &strip : strips) {
Expand All @@ -1167,7 +1173,7 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt
for (auto &p : strip) {
std::cout << p.ind << ", ";
}
std::cout << "]" << std::endl;
std::cout << "] :: " << strip.front().strip << std::endl;
#endif

// enden auf gleichem edge
Expand Down Expand Up @@ -1454,16 +1460,16 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt
if (a.strip != b.strip) {
// gehören nicht dem gleichen strip an

StripType &stripA = strips[a.strip],
&stripB = strips[b.strip];
StripType &stripA = stripsM.at(a.strip),
&stripB = stripsM.at(b.strip);

// andere enden ermitteln

const StripPtR &eA = (&a == &(stripA.front())) ? stripA.back() : stripA.front(),
&eB = (&b == &(stripB.front())) ? stripB.back() : stripB.front();
const vtkIdType eA = a.ind == stripA.front().ind ? stripA.back().ind : stripA.front().ind,
eB = b.ind == stripB.front().ind ? stripB.back().ind : stripB.front().ind;

const StripPt &eA_ = pts[eA.ind],
&eB_ = pts[eB.ind];
const StripPt &eA_ = pts[eA],
&eB_ = pts[eB];

if (eA_.ind != eB_.ind) {
r = absoluteT[id]+a_.t;
Expand Down Expand Up @@ -1499,7 +1505,7 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt
} else {
// gleicher strip

StripType &strip = strips[a.strip];
StripType &strip = stripsM.at(a.strip);

if (HasArea(strip)) {
RefsType poly_(strip.begin(), strip.end()-1);
Expand Down Expand Up @@ -1527,7 +1533,7 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt

#ifdef DEBUG
for (auto& e : edge) {
std::cout << e << std::endl;
std::cout << e << ", t " << pts[e.get().ind].t << std::endl;
}
#endif

Expand All @@ -1546,7 +1552,7 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt

#ifdef DEBUG
std::cout << "strip " << start.strip
<< " , refs (" << start.ref << ", " << end.ref << ")"
<< ", refs (" << start.ref << ", " << end.ref << ")"
<< std::endl;
#endif

Expand Down Expand Up @@ -1660,28 +1666,32 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt

if (p.strip != sp.strip) {
if (p.strip <= start.strip) {
#ifdef DEBUG
std::cout << "*1 ref " << sp.ref;
#endif
vtkIdType _ref;

if (p.side == Side::END) {
sp.ref = p.desc[0];
_ref = p.desc[0];
} else {
sp.ref = p.desc[1];
_ref = p.desc[1];
}

#ifdef DEBUG
std::cout << " -> " << sp.ref << " (from strip " << p.strip << ", ind " << p.ind << ")" << std::endl;
if (sp.ref != _ref) {
std::cout << "*1 ref " << sp.ref << " -> " << _ref << " (from strip " << p.strip << ", ind " << p.ind << ")" << std::endl;
}
#endif

sp.ref = _ref;

_p = std::make_shared<StripPtR>(p);

break;

}
} else {
#ifdef DEBUG
std::cout << "*2 ref " << sp.ref << " -> " << p.ref << " (from strip " << p.strip << ", ind " << p.ind << ")" << std::endl;
if (sp.ref != p.ref) {
std::cout << "*2 ref " << sp.ref << " -> " << p.ref << " (from strip " << p.strip << ", ind " << p.ind << ")" << std::endl;
}
#endif

sp.ref = p.ref;
Expand All @@ -1705,20 +1715,22 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt
break;
}

#ifdef DEBUG
std::cout << "*3 ref " << sp.ref;
#endif
vtkIdType _ref;

if (p.side == Side::START) {
sp.ref = p.desc[0];
_ref = p.desc[0];
} else {
sp.ref = p.desc[1];
_ref = p.desc[1];
}

#ifdef DEBUG
std::cout << " -> " << sp.ref << " (from strip " << p.strip << ", ind " << p.ind << ")" << std::endl;
if (sp.ref != _ref) {
std::cout << "*3 ref " << sp.ref << " -> " << _ref << " (from strip " << p.strip << ", ind " << p.ind << ")" << std::endl;
}
#endif

sp.ref = _ref;

break;
}

Expand All @@ -1735,20 +1747,22 @@ bool vtkPolyDataBooleanFilter::CutCells (vtkPolyData *pd, PolyStripsType &polySt
&& b.strip == start.strip
&& pts[a.ind].capt == Capt::A) { // sollte weg

#ifdef DEBUG
std::cout << "*4 ref " << a.ref;
#endif
vtkIdType _ref;

if (b.side == Side::START) {
a.ref = b.desc[0];
_ref = b.desc[0];
} else {
a.ref = b.desc[1];
_ref = b.desc[1];
}

#ifdef DEBUG
std::cout << " -> " << a.ref << " (from strip " << b.strip << ", ind " << b.ind << ")" << std::endl;
if (a.ref != _ref) {
std::cout << "*4 ref " << a.ref << " -> " << _ref << " (from strip " << b.strip << ", ind " << b.ind << ")" << std::endl;
}
#endif

a.ref = _ref;

}
}

Expand Down
19 changes: 14 additions & 5 deletions vtkPolyDataContactFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,27 @@ bool vtkPolyDataContactFilter::InterPolyLine (InterPtsType &interPts, vtkPolyDat
}

struct Cmp {
bool operator() (const double &l, const double &r) const {
long a = std::lround(l*1e5),
b = std::lround(r*1e5);
bool operator() (const InterPt &lhs, const InterPt &rhs) const {
if (lhs.end != End::NONE && rhs.end != End::NONE) {
const vtkIdType indA = lhs.end == End::BEGIN ? lhs.edge.f : lhs.edge.g,
indB = rhs.end == End::BEGIN ? rhs.edge.f : rhs.edge.g;

if (indA == indB) {
return indA < indB;
}
}

const long a = std::lround(lhs.t*1e5),
b = std::lround(rhs.t*1e5);

return a < b;
}
};

std::map<double, InterPtsType, Cmp> paired;
std::map<InterPt, InterPtsType, Cmp> paired;

for (auto &p : interPts) {
paired[p.t].push_back(p);
paired[p].push_back(p);
}

std::vector<InterPtsType> sortedPts;
Expand Down

0 comments on commit 3d0d954

Please sign in to comment.