More efficient shape counts on OriginalLayer

This commit is contained in:
Matthias Koefferlein 2021-05-23 12:21:18 +02:00
parent 93f9b693d3
commit 2fc301a0b6
5 changed files with 89 additions and 18 deletions

View File

@ -167,22 +167,6 @@ AsIfFlatRegion::in (const Region &other, bool invert) const
return new_region.release (); return new_region.release ();
} }
size_t
AsIfFlatRegion::count () const
{
size_t n = 0;
for (RegionIterator p (begin ()); ! p.at_end (); ++p) {
++n;
}
return n;
}
size_t
AsIfFlatRegion::hier_count () const
{
return count ();
}
bool bool
AsIfFlatRegion::is_box () const AsIfFlatRegion::is_box () const
{ {

View File

@ -47,8 +47,6 @@ public:
virtual ~AsIfFlatRegion (); virtual ~AsIfFlatRegion ();
virtual bool is_box () const; virtual bool is_box () const;
virtual size_t count () const;
virtual size_t hier_count () const;
virtual area_type area (const db::Box &box) const; virtual area_type area (const db::Box &box) const;
virtual perimeter_type perimeter (const db::Box &box) const; virtual perimeter_type perimeter (const db::Box &box) const;

View File

@ -29,6 +29,7 @@
#include "dbDeepEdges.h" #include "dbDeepEdges.h"
#include "dbDeepRegion.h" #include "dbDeepRegion.h"
#include "dbDeepShapeStore.h" #include "dbDeepShapeStore.h"
#include "dbCellGraphUtils.h"
#include "tlGlobPattern.h" #include "tlGlobPattern.h"
namespace db namespace db
@ -186,6 +187,78 @@ OriginalLayerRegion::min_coherence_changed ()
m_merged_polygons_valid = false; m_merged_polygons_valid = false;
} }
size_t
OriginalLayerRegion::count () const
{
if (m_iter.has_complex_region () || m_iter.region () != db::Box::world ()) {
// complex case with a search region - use the iterator to determine the count (expensive)
size_t n = 0;
for (db::RecursiveShapeIterator i = m_iter; ! i.at_end (); ++i) {
++n;
}
return n;
} else {
// otherwise we can utilize the CellCounter
size_t n = 0;
const db::Layout &layout = *m_iter.layout ();
std::set<db::cell_index_type> cells;
m_iter.top_cell ()->collect_called_cells (cells);
db::CellCounter cc (&layout);
for (db::Layout::top_down_const_iterator c = layout.begin_top_down (); c != layout.end_top_down (); ++c) {
if (cells.find (*c) == cells.end ()) {
continue;
}
size_t nn = 0;
for (std::vector<unsigned int>::const_iterator l = m_iter.layers ().begin (); l != m_iter.layers ().end (); ++l) {
nn += layout.cell (*c).shapes (*l).size (m_iter.shape_flags ());
}
n += cc.weight (*c) * nn;
}
return n;
}
}
size_t
OriginalLayerRegion::hier_count () const
{
if (m_iter.has_complex_region () || m_iter.region () != db::Box::world ()) {
// TODO: how to establish a "hierarchical" interpretation in this case?
return count ();
} else {
size_t n = 0;
const db::Layout &layout = *m_iter.layout ();
std::set<db::cell_index_type> cells;
m_iter.top_cell ()->collect_called_cells (cells);
for (db::Layout::top_down_const_iterator c = layout.begin_top_down (); c != layout.end_top_down (); ++c) {
if (cells.find (*c) == cells.end ()) {
continue;
}
for (std::vector<unsigned int>::const_iterator l = m_iter.layers ().begin (); l != m_iter.layers ().end (); ++l) {
n += layout.cell (*c).shapes (*l).size (m_iter.shape_flags ());
}
}
return n;
}
}
RegionIteratorDelegate * RegionIteratorDelegate *
OriginalLayerRegion::begin () const OriginalLayerRegion::begin () const
{ {

View File

@ -58,6 +58,8 @@ public:
virtual bool empty () const; virtual bool empty () const;
virtual bool is_merged () const; virtual bool is_merged () const;
virtual size_t count () const;
virtual size_t hier_count () const;
virtual const db::Polygon *nth (size_t n) const; virtual const db::Polygon *nth (size_t n) const;
virtual bool has_valid_polygons () const; virtual bool has_valid_polygons () const;

View File

@ -1250,6 +1250,20 @@ public:
return n; return n;
} }
/**
* @brief Report the number of shapes stored for a given type mask
*/
size_t size (unsigned int flags) const
{
size_t n = 0;
for (tl::vector<LayerBase *>::const_iterator l = m_layers.begin (); l != m_layers.end (); ++l) {
if ((flags & (*l)->type_mask ()) != 0) {
n += (*l)->size ();
}
}
return n;
}
/** /**
* @brief Report the shape count for a certain type * @brief Report the shape count for a certain type
*/ */