M/c++_api/inc/DM/IO/IImport.hpp
1 #ifndef DM_IO_IIMPORT_HPP_INCLUDED
2 #define DM_IO_IIMPORT_HPP_INCLUDED
3 
4 #ifdef _MSC_VER
5  #pragma once
6 #endif
7 
8 #include "DM/config.hpp"
9 #include "DM/AutoLink.hpp" //enable autolink
10 
11 #include "DM/IControlObject.hpp"
12 #include "DM/IFilter.hpp"
13 #include "DM/IAddInfoLayout.hpp"
14 
15 #include "DM/IO/IFileHeader.hpp"
16 
17 #include "DM/Log.hpp"
18 #include "DM/IO/DataFormat.hpp"
19 
20 DM_NAMESPACE_BEGIN
21 
22 namespace ImportError {
23  enum Type {
24  demoLimitExceeded = -9, ///< demo limit of the DM exceeded
25  unknownFormat, ///< unknown import file format
26  memoryOverflow, ///< memory overflow occurred
27  importStreamNotAccessible, ///< import stream is not accessible
28  headerContentsErroneous, ///< the file header content is erroneous
29  readingData, ///< general error while reading data
30  importStreamClosed, ///< import stream was already closed
31  endOfStreamReached, ///< end of input stream is reached
32  interrupted, ///< import was interrupted
33  successful = 1 ///< no error occured
34  };
35 
36  DM_API const char* toString(Type error); ///< get a textual description of an import error (this function is not thread safe)
37 }
38 
39 namespace PolygonMerging {
40  enum Type {
41  safe = 0, ///< incremental merge of polygon parts (slow but robust)
42  fast = 1 ///< build polygon object at once (fast but fails in case of topological incorrect polygon parts)
43  };
44 }
45 
46 class DM_API IDatamanager;
47 
48 class DM_API IImport : public ObjectBase
49 {
50 public:
51  static IImport* New( void *instance, const char *file, DataFormat::Type format, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
52  bool collectHdrContents = false, unsigned maxBulkPoints = 1000, AddInfoLayoutHandle defaultLayout = AddInfoLayoutHandle() );
53 
54  static IImport* New( const char *file, DataFormat::Type format, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
55  bool collectHdrContents = false, unsigned maxBulkPoints = 1000, AddInfoLayoutHandle defaultLayout = AddInfoLayoutHandle() );
56 
57  /// deprecated odm import creation functions (use IImportODM::New instead)
58  static IImport* NewODM( Handle< IDatamanager > manager, bool restoreOrder, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
59  bool collectHdrContents = false, unsigned maxBulkPoints = 1000 );
60  /// deprecated odm import creation functions (use IImportODM::New instead)
61  static IImport* NewODM( IDatamanager &manager, bool restoreOrder, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
62  bool collectHdrContents = false, unsigned maxBulkPoints = 1000 );
63 
64  static IImport* NewGDAL( const char *file, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
65  bool collectHdrContents = false, unsigned maxBulkPoints = 1000,
66  unsigned bandNumber = 1, const char *driver = 0 );
67 
68  static IImport* NewWinput( const char *file, bool binary, DM::ColumnSemantic::Type structIdAddInfoCol = DM::ColumnSemantic::null,
71  bool collectHdrContents = false, unsigned maxBulkPoints = 1000,
73 
74 
76  long long polygonsInvalidOrientation; ///< number of polygons that are orientated incorrectly
77  long long polygonsSelfIntersecting; ///< number of polygons that are self intersecting
78  };
79 
80  /// Store the string representation of the import object in representation and return the length of representation.
81  /// Memory for representation must be allocated externally.
82  /// Pass a null pointer to query the length of representation only.
83  /// Note that the stored representation may contain null bytes.
84  virtual unsigned serialize( char *representation = 0 ) const = 0;
85 
86  /// Restore an import object from its string representation. Since the representation may contain null bytes, its size must also be specified.
87  static IImport* unserialize( const char *representation, unsigned repSize );
88 
89 protected:
90  virtual ~IImport() {}
91 
92 public:
93  virtual void setControlObject(ControlObjectHandle control) = 0;
94  virtual ControlObjectHandle getControlObject() const = 0;
95 
96  //get the file header object
97  virtual FileHeaderHandle getHeader() const = 0;
98 
99  virtual void setFilter( FilterHandle filter ) = 0;
100  virtual FilterHandle getFilter() const = 0;
101 
102  virtual void setPolygonMerging(PolygonMerging::Type mode) = 0;
103  virtual PolygonMerging::Type getPolygonMerging() const = 0;
104 
105  /// Retuns the filename
106  virtual const char* getFilename() const = 0;
107 
108  /// Retuns the file format
109  virtual DataFormat::Type getFileFormat() const = 0;
110 
111  /// Set logging call back function
112  virtual void logTo( LogFn logFn ) = 0;
113 
114  /// read the header in advance
115  virtual bool readHeaderSeparately() = 0;
116 
117  /// read next object from import object
118  virtual ImportError::Type readNext(GeometryHandle &obj) = 0;
119 
120  /// get a statistic of invalid geometries (after import)
121  virtual InvalidObjectStatistic getInvalidGeometries() const = 0;
122 };
123 
124 typedef Handle<IImport> ImportHandle;
125 
126 DM_NAMESPACE_END
127 
128 #endif //DM_IO_IIMPORT_HPP_INCLUDED