From bb5d30e0c077e7d9db9dd7156f276e4b54fe241b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 1 Oct 2020 01:12:12 +0200 Subject: [PATCH] WIP: more generalization --- src/db/db/dbAsIfFlatRegion.cc | 67 +++++++++++++++++++++ src/db/db/dbHierProcessor.cc | 6 ++ src/db/db/dbRegionLocalOperations.cc | 88 ++++++++++++++++------------ src/db/db/dbRegionLocalOperations.h | 50 +++++++++------- 4 files changed, 153 insertions(+), 58 deletions(-) diff --git a/src/db/db/dbAsIfFlatRegion.cc b/src/db/db/dbAsIfFlatRegion.cc index 0e8d42386..e6faa10c0 100644 --- a/src/db/db/dbAsIfFlatRegion.cc +++ b/src/db/db/dbAsIfFlatRegion.cc @@ -388,6 +388,27 @@ AsIfFlatRegion::selected_interacting_generic (const Edges &other, bool inverse, bool counting = !(min_count == 1 && max_count == std::numeric_limits::max ()); +#if defined(USE_LOCAL_PROCESSOR) + + db::RegionIterator polygons (begin_merged ()); + + db::interacting_with_edge_local_operation op (inverse, min_count, max_count); + + db::local_processor proc; + proc.set_base_verbosity (base_verbosity ()); + + std::vector > others; + others.push_back (counting ? other.begin_merged () : other.begin ()); + + std::auto_ptr output (new FlatRegion (merged_semantics ())); + std::vector results; + results.push_back (&output->raw_polygons ()); + + proc.run_flat (polygons, others, &op, results); + + return output.release (); + +#else std::unordered_map > counted_results; ResultCountingInserter inserter (counted_results); @@ -425,6 +446,7 @@ AsIfFlatRegion::selected_interacting_generic (const Edges &other, bool inverse, } return output.release (); +#endif } RegionDelegate * @@ -643,6 +665,28 @@ AsIfFlatRegion::pull_generic (const Edges &other) const return new EmptyEdges (); } +#if 0 // @@@ defined(USE_LOCAL_PROCESSOR) + + db::RegionIterator polygons (begin_merged ()); + + db::pull_local_operation ( op (inverse, min_count, max_count); + + db::local_processor proc; + proc.set_base_verbosity (base_verbosity ()); + + std::vector > others; + others.push_back (other.begin ()); + + std::auto_ptr output (new FlatRegion (merged_semantics ())); + std::vector results; + results.push_back (&output->raw_polygons ()); + + proc.run_flat (polygons, others, &op, results); + + return output.release (); + +#else + db::box_scanner2 scanner (report_progress (), progress_desc ()); scanner.reserve1 (size ()); scanner.reserve2 (other.size ()); @@ -665,6 +709,7 @@ AsIfFlatRegion::pull_generic (const Edges &other) const scanner.process (filter, 1, db::box_convert (), db::box_convert ()); return output.release (); +#endif } TextsDelegate * @@ -703,6 +748,27 @@ AsIfFlatRegion::pull_generic (const Texts &other) const RegionDelegate * AsIfFlatRegion::pull_generic (const Region &other, int mode, bool touching) const { +#if defined(USE_LOCAL_PROCESSOR) + + db::RegionIterator polygons (begin ()); + + db::pull_local_operation op (mode, touching); + + db::local_processor proc; + proc.set_base_verbosity (base_verbosity ()); + + std::vector > others; + others.push_back (other.begin_merged ()); + + std::auto_ptr output (new FlatRegion (merged_semantics ())); + std::vector results; + results.push_back (&output->raw_polygons ()); + + proc.run_flat (polygons, others, &op, results); + + return output.release (); + +#else db::EdgeProcessor ep (report_progress (), progress_desc ()); ep.set_base_verbosity (base_verbosity ()); @@ -751,6 +817,7 @@ AsIfFlatRegion::pull_generic (const Region &other, int mode, bool touching) cons } return output.release (); +#endif } template diff --git a/src/db/db/dbHierProcessor.cc b/src/db/db/dbHierProcessor.cc index 64a79dcec..e07eb2f9f 100644 --- a/src/db/db/dbHierProcessor.cc +++ b/src/db/db/dbHierProcessor.cc @@ -341,6 +341,7 @@ local_processor_cell_context::propagate (unsigned int output_layer, template class DB_PUBLIC local_processor_cell_context; template class DB_PUBLIC local_processor_cell_context; template class DB_PUBLIC local_processor_cell_context; +template class DB_PUBLIC local_processor_cell_context; template class DB_PUBLIC local_processor_cell_context; template class DB_PUBLIC local_processor_cell_context; template class DB_PUBLIC local_processor_cell_context; @@ -587,6 +588,7 @@ local_processor_cell_contexts::compute_results (const local_processo template class DB_PUBLIC local_processor_cell_contexts; template class DB_PUBLIC local_processor_cell_contexts; +template class DB_PUBLIC local_processor_cell_contexts; template class DB_PUBLIC local_processor_cell_contexts; template class DB_PUBLIC local_processor_cell_contexts; template class DB_PUBLIC local_processor_cell_contexts; @@ -688,6 +690,7 @@ template class DB_PUBLIC shape_interactions; template class DB_PUBLIC shape_interactions; template class DB_PUBLIC shape_interactions; template class DB_PUBLIC shape_interactions; +template class DB_PUBLIC shape_interactions; template class DB_PUBLIC shape_interactions; template class DB_PUBLIC shape_interactions; template class DB_PUBLIC shape_interactions; @@ -1043,6 +1046,7 @@ local_processor_context_computation_task::perform () template class DB_PUBLIC local_processor_context_computation_task; template class DB_PUBLIC local_processor_context_computation_task; template class DB_PUBLIC local_processor_context_computation_task; +template class DB_PUBLIC local_processor_context_computation_task; template class DB_PUBLIC local_processor_context_computation_task; template class DB_PUBLIC local_processor_context_computation_task; template class DB_PUBLIC local_processor_context_computation_task; @@ -1092,6 +1096,7 @@ local_processor_result_computation_task::perform () template class DB_PUBLIC local_processor_result_computation_task; template class DB_PUBLIC local_processor_result_computation_task; template class DB_PUBLIC local_processor_result_computation_task; +template class DB_PUBLIC local_processor_result_computation_task; template class DB_PUBLIC local_processor_result_computation_task; template class DB_PUBLIC local_processor_result_computation_task; template class DB_PUBLIC local_processor_result_computation_task; @@ -2036,6 +2041,7 @@ local_processor::run_flat (const generic_shape_iterator &subject template class DB_PUBLIC local_processor; template class DB_PUBLIC local_processor; +template class DB_PUBLIC local_processor; template class DB_PUBLIC local_processor; template class DB_PUBLIC local_processor; template class DB_PUBLIC local_processor; diff --git a/src/db/db/dbRegionLocalOperations.cc b/src/db/db/dbRegionLocalOperations.cc index ce226e1a5..8c84273c9 100644 --- a/src/db/db/dbRegionLocalOperations.cc +++ b/src/db/db/dbRegionLocalOperations.cc @@ -331,41 +331,44 @@ template class interacting_local_operation +pull_local_operation::pull_local_operation (int mode, bool touching) : m_mode (mode), m_touching (touching) { // .. nothing yet .. } -db::Coord PullLocalOperation::dist () const +template +db::Coord pull_local_operation::dist () const { return m_touching ? 1 : 0; } -void PullLocalOperation::compute_local (db::Layout * /*layout*/, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const +template +void pull_local_operation::compute_local (db::Layout * /*layout*/, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const { tl_assert (results.size () == 1); - std::unordered_set &result = results.front (); + std::unordered_set &result = results.front (); db::EdgeProcessor ep; - std::set others; - for (shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { - for (shape_interactions::iterator2 j = i->second.begin (); j != i->second.end (); ++j) { + std::set others; + for (typename shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { + for (typename shape_interactions::iterator2 j = i->second.begin (); j != i->second.end (); ++j) { others.insert (interactions.intruder_shape (*j).second); } } - for (shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { - const db::PolygonRef &subject = interactions.subject_shape (i->first); - for (db::PolygonRef::polygon_edge_iterator e = subject.begin_edge (); ! e.at_end(); ++e) { + for (typename shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { + const TS &subject = interactions.subject_shape (i->first); + for (typename TS::polygon_edge_iterator e = subject.begin_edge (); ! e.at_end(); ++e) { ep.insert (*e, 0); } } size_t n = 1; - for (std::set::const_iterator o = others.begin (); o != others.end (); ++o, ++n) { - for (db::PolygonRef::polygon_edge_iterator e = o->begin_edge (); ! e.at_end(); ++e) { + for (typename std::set::const_iterator o = others.begin (); o != others.end (); ++o, ++n) { + for (typename TI::polygon_edge_iterator e = o->begin_edge (); ! e.at_end(); ++e) { ep.insert (*e, n); } } @@ -382,50 +385,58 @@ void PullLocalOperation::compute_local (db::Layout * /*layout*/, const shape_int } n = 1; - for (std::set::const_iterator o = others.begin (); o != others.end (); ++o, ++n) { + for (typename std::set::const_iterator o = others.begin (); o != others.end (); ++o, ++n) { if (selected.find (n) != selected.end ()) { result.insert (*o); } } } -PullLocalOperation::on_empty_intruder_mode PullLocalOperation::on_empty_intruder_hint () const +template +typename local_operation::on_empty_intruder_mode pull_local_operation::on_empty_intruder_hint () const { - return Drop; + return local_operation::Drop; } -std::string PullLocalOperation::description () const +template +std::string pull_local_operation::description () const { return tl::to_string (tr ("Pull regions by their geometrical relation to first")); } +template class pull_local_operation; +template class pull_local_operation; + // --------------------------------------------------------------------------------------------------------------- -InteractingWithEdgeLocalOperation::InteractingWithEdgeLocalOperation (bool inverse, size_t min_count, size_t max_count) +template +interacting_with_edge_local_operation::interacting_with_edge_local_operation (bool inverse, size_t min_count, size_t max_count) : m_inverse (inverse), m_min_count (std::max (size_t (1), min_count)), m_max_count (max_count) { // .. nothing yet .. } -db::Coord InteractingWithEdgeLocalOperation::dist () const +template +db::Coord interacting_with_edge_local_operation::dist () const { // touching is sufficient return 1; } -void InteractingWithEdgeLocalOperation::compute_local (db::Layout *layout, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const +template +void interacting_with_edge_local_operation::compute_local (db::Layout *layout, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const { - std::unordered_map counted_results; + std::unordered_map counted_results; bool counting = !(m_min_count == 1 && m_max_count == std::numeric_limits::max ()); - db::box_scanner2 scanner; + db::box_scanner2 scanner; - result_counting_inserter inserter (counted_results); - region_to_edge_interaction_filter > filter (inserter, false, counting /*get all in counting mode*/); + result_counting_inserter inserter (counted_results); + region_to_edge_interaction_filter > filter (inserter, false, counting /*get all in counting mode*/); std::set intruder_ids; - for (shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { - for (shape_interactions::iterator2 j = i->second.begin (); j != i->second.end (); ++j) { + for (typename shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { + for (typename shape_interactions::iterator2 j = i->second.begin (); j != i->second.end (); ++j) { intruder_ids.insert (*j); } } @@ -434,12 +445,12 @@ void InteractingWithEdgeLocalOperation::compute_local (db::Layout *layout, const scanner.insert2 (& interactions.intruder_shape (*j).second, 0); } - std::list heap; - for (shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { + std::list heap; + for (typename shape_interactions::iterator i = interactions.begin (); i != interactions.end (); ++i) { - const db::PolygonRef &subject = interactions.subject_shape (i->first); + const TS &subject = interactions.subject_shape (i->first); - const db::PolygonRef *addressable = push_polygon_to_heap (layout, subject, heap); + const TR *addressable = push_polygon_to_heap (layout, subject, heap); scanner.insert1 (addressable, 0); if (m_inverse) { @@ -448,14 +459,14 @@ void InteractingWithEdgeLocalOperation::compute_local (db::Layout *layout, const } - scanner.process (filter, 1, db::box_convert (), db::box_convert ()); + scanner.process (filter, 1, db::box_convert (), db::box_convert ()); // select hits based on their count tl_assert (results.size () == 1); - std::unordered_set &result = results.front (); + std::unordered_set &result = results.front (); - for (std::unordered_map::const_iterator r = counted_results.begin (); r != counted_results.end (); ++r) { + for (typename std::unordered_map::const_iterator r = counted_results.begin (); r != counted_results.end (); ++r) { bool hit = r->second >= m_min_count && r->second <= m_max_count; if (hit != m_inverse) { result.insert (r->first); @@ -463,20 +474,25 @@ void InteractingWithEdgeLocalOperation::compute_local (db::Layout *layout, const } } -InteractingWithEdgeLocalOperation::on_empty_intruder_mode InteractingWithEdgeLocalOperation::on_empty_intruder_hint () const +template +typename local_operation::on_empty_intruder_mode interacting_with_edge_local_operation::on_empty_intruder_hint () const { if (!m_inverse) { - return Drop; + return local_operation::Drop; } else { - return Copy; + return local_operation::Copy; } } -std::string InteractingWithEdgeLocalOperation::description () const +template +std::string interacting_with_edge_local_operation::description () const { return tl::to_string (tr ("Select regions by their geometric relation to edges")); } +template class interacting_with_edge_local_operation; +template class interacting_with_edge_local_operation; + // --------------------------------------------------------------------------------------------------------------- PullWithEdgeLocalOperation::PullWithEdgeLocalOperation () diff --git a/src/db/db/dbRegionLocalOperations.h b/src/db/db/dbRegionLocalOperations.h index 4713a63d0..d653d4a45 100644 --- a/src/db/db/dbRegionLocalOperations.h +++ b/src/db/db/dbRegionLocalOperations.h @@ -71,15 +71,16 @@ private: typedef interacting_local_operation InteractingLocalOperation; -class PullLocalOperation - : public local_operation +template +class pull_local_operation + : public local_operation { public: - PullLocalOperation (int mode, bool touching); + pull_local_operation (int mode, bool touching); virtual db::Coord dist () const; - virtual void compute_local (db::Layout * /*layout*/, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const; - virtual on_empty_intruder_mode on_empty_intruder_hint () const; + virtual void compute_local (db::Layout * /*layout*/, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const; + virtual typename local_operation::on_empty_intruder_mode on_empty_intruder_hint () const; virtual std::string description () const; private: @@ -87,15 +88,18 @@ private: bool m_touching; }; -class InteractingWithEdgeLocalOperation - : public local_operation +typedef pull_local_operation PullLocalOperation; + +template +class interacting_with_edge_local_operation + : public local_operation { public: - InteractingWithEdgeLocalOperation (bool inverse, size_t min_count, size_t max_count); + interacting_with_edge_local_operation (bool inverse, size_t min_count, size_t max_count); virtual db::Coord dist () const; - virtual void compute_local (db::Layout *layout, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const; - virtual on_empty_intruder_mode on_empty_intruder_hint () const; + virtual void compute_local (db::Layout *layout, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const; + virtual typename local_operation::on_empty_intruder_mode on_empty_intruder_hint () const; virtual std::string description () const; private: @@ -103,6 +107,8 @@ private: size_t m_min_count, m_max_count; }; +typedef interacting_with_edge_local_operation InteractingWithEdgeLocalOperation; + class PullWithEdgeLocalOperation : public local_operation { @@ -115,18 +121,6 @@ public: virtual std::string description () const; }; -class PullWithTextLocalOperation - : public local_operation -{ -public: - PullWithTextLocalOperation (); - - virtual db::Coord dist () const; - virtual void compute_local (db::Layout *, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const; - virtual on_empty_intruder_mode on_empty_intruder_hint () const; - virtual std::string description () const; -}; - template class interacting_with_text_local_operation : public local_operation @@ -146,6 +140,18 @@ private: typedef interacting_with_text_local_operation InteractingWithTextLocalOperation; +class PullWithTextLocalOperation + : public local_operation +{ +public: + PullWithTextLocalOperation (); + + virtual db::Coord dist () const; + virtual void compute_local (db::Layout *, const shape_interactions &interactions, std::vector > &results, size_t /*max_vertex_count*/, double /*area_ratio*/) const; + virtual on_empty_intruder_mode on_empty_intruder_hint () const; + virtual std::string description () const; +}; + } // namespace db #endif