Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region/Edges/EdgePairs/Texts operators and filters #1601

Merged
merged 12 commits into from
Mar 9, 2024
18 changes: 18 additions & 0 deletions src/db/db/dbAsIfFlatEdgePairs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ void AsIfFlatEdgePairs::invalidate_bbox ()
m_bbox_valid = false;
}

EdgePairsDelegate *
AsIfFlatEdgePairs::processed (const EdgePairProcessorBase &filter) const
{
std::unique_ptr<FlatEdgePairs> edge_pairs (new FlatEdgePairs ());

std::vector<db::EdgePair> res_edge_pairs;

for (EdgePairsIterator e = begin (); ! e.at_end (); ++e) {
res_edge_pairs.clear ();
filter.process (*e, res_edge_pairs);
for (std::vector<db::EdgePair>::const_iterator er = res_edge_pairs.begin (); er != res_edge_pairs.end (); ++er) {
edge_pairs->insert (*er);
}
}

return edge_pairs.release ();
}

RegionDelegate *
AsIfFlatEdgePairs::processed_to_polygons (const EdgePairToPolygonProcessorBase &filter) const
{
Expand Down
10 changes: 8 additions & 2 deletions src/db/db/dbAsIfFlatEdgePairs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ class DB_PUBLIC AsIfFlatEdgePairs

virtual EdgePairsDelegate *filtered (const EdgePairFilterBase &) const;

virtual RegionDelegate *processed_to_polygons (const EdgePairToPolygonProcessorBase &filter) const;
virtual EdgesDelegate *processed_to_edges (const EdgePairToEdgeProcessorBase &filter) const;
virtual EdgePairsDelegate *process_in_place (const EdgePairProcessorBase &proc)
{
return processed (proc);
}

virtual EdgePairsDelegate *processed (const EdgePairProcessorBase &proc) const;
virtual RegionDelegate *processed_to_polygons (const EdgePairToPolygonProcessorBase &proc) const;
virtual EdgesDelegate *processed_to_edges (const EdgePairToEdgeProcessorBase &proc) const;

virtual EdgePairsDelegate *add_in_place (const EdgePairs &other)
{
Expand Down
18 changes: 18 additions & 0 deletions src/db/db/dbAsIfFlatTexts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ AsIfFlatTexts::filtered (const TextFilterBase &filter) const
return new_texts.release ();
}

TextsDelegate *
AsIfFlatTexts::processed (const TextProcessorBase &filter) const
{
std::unique_ptr<FlatTexts> texts (new FlatTexts ());

std::vector<db::Text> res_texts;

for (TextsIterator e = begin (); ! e.at_end (); ++e) {
res_texts.clear ();
filter.process (*e, res_texts);
for (std::vector<db::Text>::const_iterator er = res_texts.begin (); er != res_texts.end (); ++er) {
texts->insert (*er);
}
}

return texts.release ();
}

RegionDelegate *
AsIfFlatTexts::processed_to_polygons (const TextToPolygonProcessorBase &filter) const
{
Expand Down
6 changes: 6 additions & 0 deletions src/db/db/dbAsIfFlatTexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class DB_PUBLIC AsIfFlatTexts

virtual TextsDelegate *filtered (const TextFilterBase &) const;

virtual TextsDelegate *process_in_place (const TextProcessorBase &proc)
{
return processed (proc);
}

virtual TextsDelegate *processed (const TextProcessorBase &proc) const;
virtual RegionDelegate *processed_to_polygons (const TextToPolygonProcessorBase &filter) const;

virtual TextsDelegate *add_in_place (const Texts &other)
Expand Down
12 changes: 12 additions & 0 deletions src/db/db/dbDeepEdgePairs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ DeepEdgePairs::apply_filter (const EdgePairFilterBase &filter) const
return res.release ();
}

EdgePairsDelegate *DeepEdgePairs::process_in_place (const EdgePairProcessorBase &filter)
{
// TODO: implement to be really in-place
return processed (filter);
}

EdgePairsDelegate *
DeepEdgePairs::processed (const EdgePairProcessorBase &filter) const
{
return shape_collection_processed_impl<db::EdgePair, db::EdgePair, db::DeepEdgePairs> (deep_layer (), filter);
}

RegionDelegate *
DeepEdgePairs::processed_to_polygons (const EdgePairToPolygonProcessorBase &filter) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/db/db/dbDeepEdgePairs.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class DB_PUBLIC DeepEdgePairs

virtual EdgePairsDelegate *filter_in_place (const EdgePairFilterBase &filter);
virtual EdgePairsDelegate *filtered (const EdgePairFilterBase &) const;
virtual EdgePairsDelegate *process_in_place (const EdgePairProcessorBase &);
virtual EdgePairsDelegate *processed (const EdgePairProcessorBase &) const;
virtual RegionDelegate *processed_to_polygons (const EdgePairToPolygonProcessorBase &filter) const;
virtual EdgesDelegate *processed_to_edges (const EdgePairToEdgeProcessorBase &filter) const;

Expand Down
2 changes: 0 additions & 2 deletions src/db/db/dbDeepRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ class DB_PUBLIC DeepRegion
std::pair<DeepLayer, DeepLayer> and_and_not_with (const DeepRegion *other, PropertyConstraint property_constraint) const;
DeepRegion *apply_filter (const PolygonFilterBase &filter) const;

template <class Result, class OutputContainer> OutputContainer *processed_impl (const polygon_processor<Result> &filter) const;

template <class Proc>
void configure_proc (Proc &proc) const
{
Expand Down
12 changes: 12 additions & 0 deletions src/db/db/dbDeepTexts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,18 @@ DeepTexts *DeepTexts::apply_filter (const TextFilterBase &filter) const
return res.release ();
}

TextsDelegate *DeepTexts::process_in_place (const TextProcessorBase &filter)
{
// TODO: implement to be really in-place
return processed (filter);
}

TextsDelegate *
DeepTexts::processed (const TextProcessorBase &filter) const
{
return shape_collection_processed_impl<db::Text, db::Text, db::DeepTexts> (deep_layer (), filter);
}

RegionDelegate *
DeepTexts::processed_to_polygons (const TextToPolygonProcessorBase &filter) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/db/db/dbDeepTexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class DB_PUBLIC DeepTexts
virtual TextsDelegate *filter_in_place (const TextFilterBase &filter);
virtual TextsDelegate *filtered (const TextFilterBase &) const;

virtual TextsDelegate *process_in_place (const TextProcessorBase &);
virtual TextsDelegate *processed (const TextProcessorBase &) const;
virtual RegionDelegate *processed_to_polygons (const TextToPolygonProcessorBase &filter) const;

virtual TextsDelegate *add_in_place (const Texts &other);
Expand Down
13 changes: 9 additions & 4 deletions src/db/db/dbEdgePairs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,19 @@ EdgePairs::properties_repository ()
return *r;
}

void EdgePairs::processed (Region &output, const EdgePairToPolygonProcessorBase &filter) const
EdgePairs EdgePairs::processed (const EdgePairProcessorBase &proc) const
{
output = Region (mp_delegate->processed_to_polygons (filter));
return EdgePairs (mp_delegate->processed (proc));
}

void EdgePairs::processed (Edges &output, const EdgePairToEdgeProcessorBase &filter) const
void EdgePairs::processed (Region &output, const EdgePairToPolygonProcessorBase &proc) const
{
output = Edges (mp_delegate->processed_to_edges (filter));
output = Region (mp_delegate->processed_to_polygons (proc));
}

void EdgePairs::processed (Edges &output, const EdgePairToEdgeProcessorBase &proc) const
{
output = Edges (mp_delegate->processed_to_edges (proc));
}

void EdgePairs::polygons (Region &output, db::Coord e) const
Expand Down
22 changes: 20 additions & 2 deletions src/db/db/dbEdgePairs.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,39 @@ class DB_PUBLIC EdgePairs
return EdgePairs (mp_delegate->filtered (filter));
}

/**
* @brief Processes the edge pairs in-place
*
* This method will run the processor over all edge pairs and replace the collection by the results.
*/
EdgePairs &process (const EdgePairProcessorBase &proc)
{
set_delegate (mp_delegate->process_in_place (proc));
return *this;
}

/**
* @brief Processes the edge pairs
*
* This method will run the processor over all edge pairs return a new edge pair collection with the results.
*/
EdgePairs processed (const EdgePairProcessorBase &proc) const;

/**
* @brief Processes the edge pairs into polygons
*
* This method will run the processor over all edge pairs and return a region
* with the outputs of the processor.
*/
void processed (Region &output, const EdgePairToPolygonProcessorBase &filter) const;
void processed (Region &output, const EdgePairToPolygonProcessorBase &proc) const;

/**
* @brief Processes the edge pairs into edges
*
* This method will run the processor over all edge pairs and return a edge collection
* with the outputs of the processor.
*/
void processed (Edges &output, const EdgePairToEdgeProcessorBase &filter) const;
void processed (Edges &output, const EdgePairToEdgeProcessorBase &proc) const;

/**
* @brief Transforms the edge pair set
Expand Down
7 changes: 5 additions & 2 deletions src/db/db/dbEdgePairsDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RegionDelegate;
class EdgesDelegate;
class Layout;

typedef shape_collection_processor<db::EdgePair, db::EdgePair> EdgePairProcessorBase;
typedef shape_collection_processor<db::EdgePair, db::Polygon> EdgePairToPolygonProcessorBase;
typedef shape_collection_processor<db::EdgePair, db::Edge> EdgePairToEdgeProcessorBase;

Expand Down Expand Up @@ -194,8 +195,10 @@ class DB_PUBLIC EdgePairsDelegate

virtual EdgePairsDelegate *filter_in_place (const EdgePairFilterBase &filter) = 0;
virtual EdgePairsDelegate *filtered (const EdgePairFilterBase &filter) const = 0;
virtual RegionDelegate *processed_to_polygons (const EdgePairToPolygonProcessorBase &filter) const = 0;
virtual EdgesDelegate *processed_to_edges (const EdgePairToEdgeProcessorBase &filter) const = 0;
virtual EdgePairsDelegate *process_in_place (const EdgePairProcessorBase &proc) = 0;
virtual EdgePairsDelegate *processed (const EdgePairProcessorBase &proc) const = 0;
virtual RegionDelegate *processed_to_polygons (const EdgePairToPolygonProcessorBase &proc) const = 0;
virtual EdgesDelegate *processed_to_edges (const EdgePairToEdgeProcessorBase &proc) const = 0;

virtual RegionDelegate *polygons (db::Coord e) const = 0;
virtual EdgesDelegate *edges () const = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/db/db/dbEmptyEdgePairs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class DB_PUBLIC EmptyEdgePairs

virtual EdgePairsDelegate *filter_in_place (const EdgePairFilterBase &) { return this; }
virtual EdgePairsDelegate *filtered (const EdgePairFilterBase &) const { return new EmptyEdgePairs (); }
virtual EdgePairsDelegate *process_in_place (const EdgePairProcessorBase &) { return this; }
virtual EdgePairsDelegate *processed (const EdgePairProcessorBase &) const { return new EmptyEdgePairs (); }
virtual RegionDelegate *processed_to_polygons (const EdgePairToPolygonProcessorBase &filter) const;
virtual EdgesDelegate *processed_to_edges (const EdgePairToEdgeProcessorBase &filter) const;

Expand Down
2 changes: 2 additions & 0 deletions src/db/db/dbEmptyTexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class DB_PUBLIC EmptyTexts
virtual TextsDelegate *filter_in_place (const TextFilterBase &) { return this; }
virtual TextsDelegate *filtered (const TextFilterBase &) const { return new EmptyTexts (); }

virtual TextsDelegate *process_in_place (const TextProcessorBase &) { return this; }
virtual TextsDelegate *processed (const TextProcessorBase &) const { return new EmptyTexts (); }
virtual RegionDelegate *processed_to_polygons (const TextToPolygonProcessorBase &) const;

virtual RegionDelegate *polygons (db::Coord e) const;
Expand Down
56 changes: 0 additions & 56 deletions src/db/db/dbRegionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,62 +106,6 @@ class DB_PUBLIC PolygonFilterBase
virtual bool wants_variants () const = 0;
};

/**
* @brief A template base class for polygon processors
*
* A polygon processor can turn a polygon into something else.
*/
template <class Result>
class DB_PUBLIC polygon_processor
{
public:
/**
* @brief Constructor
*/
polygon_processor () { }

/**
* @brief Destructor
*/
virtual ~polygon_processor () { }

/**
* @brief Performs the actual processing
* This method will take the input polygon from "polygon" and puts the results into "res".
* "res" can be empty - in this case, the polygon will be skipped.
*/
virtual void process (const db::Polygon &polygon, std::vector<Result> &res) const = 0;

/**
* @brief Returns the transformation reducer for building cell variants
* This method may return 0. In this case, not cell variants are built.
*/
virtual const TransformationReducer *vars () const = 0;

/**
* @brief Returns true, if the result of this operation can be regarded "merged" always.
*/
virtual bool result_is_merged () const = 0;

/**
* @brief Returns true, if the result of this operation must not be merged.
* This feature can be used, if the result represents "degenerated" objects such
* as point-like edges. These must not be merged. Otherwise they disappear.
*/
virtual bool result_must_not_be_merged () const = 0;

/**
* @brief Returns true, if the processor wants raw (not merged) input
*/
virtual bool requires_raw_input () const = 0;

/**
* @brief Returns true, if the processor wants to build variants
* If not true, the processor accepts shape propagation as variant resolution.
*/
virtual bool wants_variants () const = 0;
};

typedef shape_collection_processor<db::Polygon, db::Polygon> PolygonProcessorBase;
typedef shape_collection_processor<db::Polygon, db::Edge> PolygonToEdgeProcessorBase;
typedef shape_collection_processor<db::Polygon, db::EdgePair> PolygonToEdgePairProcessorBase;
Expand Down
3 changes: 3 additions & 0 deletions src/db/db/dbShapeCollectionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class DB_PUBLIC_TEMPLATE shape_collection_processor
: public tl::Object
{
public:
typedef Shape shape_type;
typedef Result result_type;

/**
* @brief Constructor
*/
Expand Down
5 changes: 5 additions & 0 deletions src/db/db/dbTexts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ MutableTexts *Texts::mutable_texts ()
return texts;
}

Texts Texts::processed (const TextProcessorBase &proc) const
{
return Texts (mp_delegate->processed (proc));
}

void Texts::processed (Region &output, const TextToPolygonProcessorBase &filter) const
{
output = Region (mp_delegate->processed_to_polygons (filter));
Expand Down
20 changes: 19 additions & 1 deletion src/db/db/dbTexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,25 @@ class DB_PUBLIC Texts
}

/**
* @brief Processes the edges into polygons
* @brief Processes the edge pairs in-place
*
* This method will run the processor over all texts and replace the collection by the results.
*/
Texts &process (const TextProcessorBase &proc)
{
set_delegate (mp_delegate->process_in_place (proc));
return *this;
}

/**
* @brief Processes the texts
*
* This method will run the processor over all texts and return a new text collection with the results.
*/
Texts processed (const TextProcessorBase &proc) const;

/**
* @brief Processes the texts into polygons
*
* This method will run the processor over all edges and return a region
* with the outputs of the processor.
Expand Down
5 changes: 4 additions & 1 deletion src/db/db/dbTextsDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RegionDelegate;
class EdgesDelegate;
class Layout;

typedef shape_collection_processor<db::Text, db::Text> TextProcessorBase;
typedef shape_collection_processor<db::Text, db::Polygon> TextToPolygonProcessorBase;

typedef db::generic_shape_iterator_delegate_base <db::Text> TextsIteratorDelegate;
Expand Down Expand Up @@ -94,7 +95,9 @@ class DB_PUBLIC TextsDelegate

virtual TextsDelegate *filter_in_place (const TextFilterBase &filter) = 0;
virtual TextsDelegate *filtered (const TextFilterBase &filter) const = 0;
virtual RegionDelegate *processed_to_polygons (const TextToPolygonProcessorBase &filter) const = 0;
virtual TextsDelegate *process_in_place (const TextProcessorBase &proc) = 0;
virtual TextsDelegate *processed (const TextProcessorBase &proc) const = 0;
virtual RegionDelegate *processed_to_polygons (const TextToPolygonProcessorBase &proc) const = 0;

virtual RegionDelegate *polygons (db::Coord e) const = 0;
virtual EdgesDelegate *edges () const = 0;
Expand Down
Loading
Loading