diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALEvaluator.cc | 78 | ||||
-rw-r--r-- | src/cgalutils.cc | 4 |
2 files changed, 41 insertions, 41 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 797434f..3646af2 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -28,6 +28,7 @@ #include <QRegExp> #include <boost/foreach.hpp> +#include <boost/unordered_map.hpp> CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const AbstractNode &node) { @@ -392,9 +393,10 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) struct PolyReducer { Grid2d<int> grid; - QHash< QPair<int,int>, QPair<int,int> > egde_to_poly; - QHash< int, CGAL_Nef_polyhedron2::Point > points; - QHash< int, QList<int> > polygons; + boost::unordered_map<std::pair<int,int>, std::pair<int,int> > edge_to_poly; + boost::unordered_map<int, CGAL_Nef_polyhedron2::Point> points; + typedef boost::unordered_map<int, std::vector<int> > PolygonMap; + PolygonMap polygons; int poly_n; void add_edges(int pn) @@ -403,10 +405,10 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) int a = this->polygons[pn][j-1]; int b = this->polygons[pn][j % this->polygons[pn].size()]; if (a > b) { a = a^b; b = a^b; a = a^b; } - if (this->egde_to_poly[QPair<int,int>(a, b)].first == 0) - this->egde_to_poly[QPair<int,int>(a, b)].first = pn; - else if (this->egde_to_poly[QPair<int,int>(a, b)].second == 0) - this->egde_to_poly[QPair<int,int>(a, b)].second = pn; + if (this->edge_to_poly[std::pair<int,int>(a, b)].first == 0) + this->edge_to_poly[std::pair<int,int>(a, b)].first = pn; + else if (this->edge_to_poly[std::pair<int,int>(a, b)].second == 0) + this->edge_to_poly[std::pair<int,int>(a, b)].second = pn; else abort(); } @@ -418,12 +420,12 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) int a = this->polygons[pn][j-1]; int b = this->polygons[pn][j % this->polygons[pn].size()]; if (a > b) { a = a^b; b = a^b; a = a^b; } - if (this->egde_to_poly[QPair<int,int>(a, b)].first == pn) - this->egde_to_poly[QPair<int,int>(a, b)].first = 0; - if (this->egde_to_poly[QPair<int,int>(a, b)].second == pn) - this->egde_to_poly[QPair<int,int>(a, b)].second = 0; + if (this->edge_to_poly[std::pair<int,int>(a, b)].first == pn) + this->edge_to_poly[std::pair<int,int>(a, b)].first = 0; + if (this->edge_to_poly[std::pair<int,int>(a, b)].second == pn) + this->edge_to_poly[std::pair<int,int>(a, b)].second = 0; } - this->polygons.remove(pn); + this->polygons.erase(pn); } PolyReducer(const PolySet &ps) : grid(GRID_COARSE), poly_n(1) @@ -438,12 +440,13 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) // Filter away two vertices with the same index (due to grid) // This could be done in a more general way, but we'd rather redo the entire // grid concept instead. - if (this->polygons[this->poly_n].indexOf(idx) == -1) { - this->polygons[this->poly_n].append(this->grid.data(x, y)); + std::vector<int> &poly = this->polygons[this->poly_n]; + if (std::find(poly.begin(), poly.end(), idx) == poly.end()) { + poly.push_back(this->grid.data(x, y)); } } else { this->grid.align(x, y) = point_n; - this->polygons[this->poly_n].append(point_n); + this->polygons[this->poly_n].push_back(point_n); this->points[point_n] = CGAL_Nef_polyhedron2::Point(x, y); point_n++; } @@ -453,7 +456,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) this->poly_n++; } else { - this->polygons.remove(this->poly_n); + this->polygons.erase(this->poly_n); } } } @@ -462,11 +465,11 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) { for (int i = 1; i < this->polygons[p1].size(); i++) { int j = (p1e + i) % this->polygons[p1].size(); - this->polygons[this->poly_n].append(this->polygons[p1][j]); + this->polygons[this->poly_n].push_back(this->polygons[p1][j]); } for (int i = 1; i < this->polygons[p2].size(); i++) { int j = (p2e + i) % this->polygons[p2].size(); - this->polygons[this->poly_n].append(this->polygons[p2][j]); + this->polygons[this->poly_n].push_back(this->polygons[p2][j]); } del_poly(p1); del_poly(p2); @@ -476,25 +479,22 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) void reduce() { - QList<int> work_queue; - QHashIterator< int, QList<int> > it(polygons); - while (it.hasNext()) { - it.next(); - work_queue.append(it.key()); + std::deque<int> work_queue; + BOOST_FOREACH(const PolygonMap::value_type &i, polygons) { + work_queue.push_back(i.first); } - while (!work_queue.isEmpty()) { - int poly1_n = work_queue.first(); - work_queue.removeFirst(); - if (!this->polygons.contains(poly1_n)) - continue; + while (!work_queue.empty()) { + int poly1_n = work_queue.front(); + work_queue.pop_front(); + if (this->polygons.find(poly1_n) == this->polygons.end()) continue; for (int j = 1; j <= this->polygons[poly1_n].size(); j++) { int a = this->polygons[poly1_n][j-1]; int b = this->polygons[poly1_n][j % this->polygons[poly1_n].size()]; if (a > b) { a = a^b; b = a^b; a = a^b; } - if (this->egde_to_poly[QPair<int,int>(a, b)].first != 0 && - this->egde_to_poly[QPair<int,int>(a, b)].second != 0) { - int poly2_n = this->egde_to_poly[QPair<int,int>(a, b)].first + - this->egde_to_poly[QPair<int,int>(a, b)].second - poly1_n; + if (this->edge_to_poly[std::pair<int,int>(a, b)].first != 0 && + this->edge_to_poly[std::pair<int,int>(a, b)].second != 0) { + int poly2_n = this->edge_to_poly[std::pair<int,int>(a, b)].first + + this->edge_to_poly[std::pair<int,int>(a, b)].second - poly1_n; int poly2_edge = -1; for (int k = 1; k <= this->polygons[poly2_n].size(); k++) { int c = this->polygons[poly2_n][k-1]; @@ -504,14 +504,14 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) poly2_edge = k-1; continue; } - int poly3_n = this->egde_to_poly[QPair<int,int>(c, d)].first + - this->egde_to_poly[QPair<int,int>(c, d)].second - poly2_n; + int poly3_n = this->edge_to_poly[std::pair<int,int>(c, d)].first + + this->edge_to_poly[std::pair<int,int>(c, d)].second - poly2_n; if (poly3_n < 0) continue; if (poly3_n == poly1_n) goto next_poly1_edge; } - work_queue.append(merge(poly1_n, j-1, poly2_n, poly2_edge)); + work_queue.push_back(merge(poly1_n, j-1, poly2_n, poly2_edge)); goto next_poly1; } next_poly1_edge:; @@ -524,12 +524,10 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) { CGAL_Nef_polyhedron2 *N = new CGAL_Nef_polyhedron2; - QHashIterator< int, QList<int> > it(polygons); - while (it.hasNext()) { - it.next(); + BOOST_FOREACH(const PolygonMap::value_type &i, polygons) { std::list<CGAL_Nef_polyhedron2::Point> plist; - for (int j = 0; j < it.value().size(); j++) { - int p = it.value()[j]; + for (int j = 0; j < i.second.size(); j++) { + int p = i.second[j]; plist.push_back(points[p]); } *N += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED); diff --git a/src/cgalutils.cc b/src/cgalutils.cc index bef873c..e77f5dd 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -8,6 +8,8 @@ #include <CGAL/assertions_behaviour.h> #include <CGAL/exceptions.h> +#include <map> + PolySet *createPolySetFromPolyhedron(const CGAL_Polyhedron &p) { PolySet *ps = new PolySet(); @@ -87,7 +89,7 @@ public: for (size_t i = 0; i < ps.polygons.size(); i++) { const PolySet::Polygon *poly = &ps.polygons[i]; - QHash<int,int> fc; + std::map<int,int> fc; bool facet_is_degenerated = false; for (size_t j = 0; j < poly->size(); j++) { const Vector3d &p = poly->at(j); |