IFilter.hpp
1 #ifndef DM_IFILTER_HPP_INCLUDED
2 #define DM_IFILTER_HPP_INCLUDED
3 
4 #ifdef _MSC_VER
5  #pragma once
6 #endif
7 
8 #include "DM/config.hpp"
9 #include "DM/Handle.hpp"
10 #include "DM/ObjectBase.hpp"
11 #include "DM/IGeometry.hpp"
12 #include "DM/IBox.hpp"
13 #include "DM/IAddInfoStatistics.hpp"
14 #include "DM/IFilterStats.hpp"
15 #include "DM/AutoLink.hpp" //enable autolink
16 
17 #include <vector>
18 #include <string>
19 
20 DM_NAMESPACE_BEGIN
21 
22 class DM_API IFilter : public ObjectBase
23 {
24 public:
25  /// Choose the level of write access:
26  struct WriteAccess
27  {
28  enum Type
29  {
30  none, ///< support no write access at all
31  coordinates, ///< support write access to coordinates
32  attributes = coordinates << 1, ///< support write access to attributes
33  delayedResults = attributes << 1, ///< support filters that provide delayed results; use IFilter::submit(.) / IFilter::fetch() instead of IFilter::validate(.)
34  full = (delayedResults<<1)-1 ///< full write access
35  };
36  };
37 
38  static IFilter* New();
39  // Returns nullptr if stringRepresentation contains white space only.
40  static IFilter* New( const char *stringRepresentation, WriteAccess::Type writeAccess = WriteAccess::none );
41 
42  virtual IFilter* clone() const = 0;
43 
44  // Only applicable for filters (filter trees) that don't use caching. Otherwise: throw
45  virtual bool validate( IGeometry &geom ) const = 0;
46  virtual bool validate( const IGeometry &geom ) const = 0;
47 
48  // Also applicable for filters (filter trees) that use caching
49  virtual void submit( GeometryHandle geo, const void * userData = 0 ) const = 0;
50 
51  // Indicate that no more data will be submitted. The rest of the already submitted geometries will be returned by subsequent calls to fetch()
52  // Do not call submit() after flush() has been called.
53  virtual void flush() const = 0;
54 
55  struct IResult : public ObjectBase
56  {
57  // Is true, if *this considers filtered as valid. Meaningless, if filtered is NULL
58  virtual bool valid() const = 0;
59  // The filtered object (changed from original submitted object, if modifiesObjects()==true); if NULL, then there is no result yet, or no result left
60  virtual GeometryHandle filtered() const = 0;
61  // If provideOrigObjects(true), then this is the original, unchanged object as submitted; otherwise orig==filtered
62  virtual GeometryHandle orig() const = 0;
63  // Arbitrary data set by users, kept together untouched with submitted geometries.
64  virtual const void * userData() const = 0;
65  };
67  // return the next available result.
68  // Performance note: call fetch() alternately with submit(), to keep the (eventual) internal cache size small
69  // Note that a single submission yields an arbitrary number of results, including zero.
70  // Thus, call submit once, and call fetch repeatedly until it returns an empty pointer in Result::filtered
71  virtual ResultHandle fetch() const = 0;
72 
73  // return false if data inside box having statistics of addInfoStats will surely not pass through (-> e.g. skip this ODM tile)
74  virtual bool mayBeValid( const IBox &box, const IAddInfoStatistics &addInfoStats ) const = 0;
75 
76  struct TriBool { enum Type { indeterminate = -1, false_, true_ }; };
77  // return true_ if surely all data within box having addInfoStats would pass through the filter.
78  // return false_ if surely none of the data within box having addInfoStats would pass through the filter.
79  // return indeterminate_ otherwise.
80  virtual TriBool::Type validateRange( const IBox &box, const IAddInfoStatistics &addInfoStats ) const = 0;
81 
82  // Provide the original, unchanged geometries and attributes in Result::orig and FilterStats::accumulate
83  virtual void provideOrigObjects( bool val = true ) = 0;
84 
85  /// accumulate statistical information about the results of filtering
86  virtual void stats( FilterStatsHandle obj ) = 0;
87  virtual FilterStatsHandle stats() = 0;
88 
89  virtual std::vector<std::string> accessedAttributeNames() const = 0;
90  virtual void print(std::ostream&) const = 0;
91 };
92 
94 
95 DM_API FilterHandle operator||( const IFilter&, const IFilter& );
96 DM_API FilterHandle operator&&( const IFilter&, const IFilter& );
97 
98 DM_API IFilter::WriteAccess::Type operator| ( const IFilter::WriteAccess::Type &left, const IFilter::WriteAccess::Type &right );
99 
100 DM_NAMESPACE_END
101 
102 #endif //DM_IFILTER_HPP_INCLUDED