libLAS API Reference  1.8.1
chipper.hpp
Go to the documentation of this file.
1 #ifndef LIBLAS_CHIPPER_H
2 #define LIBLAS_CHIPPER_H
3 
4 #include <liblas/liblas.hpp>
5 #include <liblas/export.hpp>
6 #include <liblas/detail/opt_allocator.hpp>
7 
8 #include <vector>
9 
10 namespace liblas
11 {
12 
13 namespace chipper
14 {
15 
17 {
21 };
22 
24 {
25 public:
26  double m_pos;
27  uint32_t m_ptindex;
28  uint32_t m_oindex;
29 
30  bool operator < (const PtRef& pt) const
31  { return m_pos < pt.m_pos; }
32 };
33 typedef std::vector<PtRef, detail::opt_allocator<PtRef> > PtRefVec;
34 
36 {
37 public:
38  PtRefVec *m_vec_p;
40 
41  RefList(Direction dir = DIR_NONE) : m_vec_p(NULL), m_dir(dir)
42  {}
44  {
45  delete m_vec_p;
46  }
47 
48  PtRefVec::size_type size() const
49  { return m_vec_p->size(); }
50  void reserve(PtRefVec::size_type n)
51  { m_vec_p->reserve(n); }
52  void resize(PtRefVec::size_type n)
53  { m_vec_p->resize(n); }
54  void push_back(const PtRef& ref)
55  { m_vec_p->push_back(ref); }
56  PtRefVec::iterator begin()
57  { return m_vec_p->begin(); }
58  PtRefVec::iterator end()
59  { return m_vec_p->end(); }
60  PtRef& operator[](uint32_t pos)
61  { return (*m_vec_p)[pos]; }
62  std::string Dir()
63  {
64  if (m_dir == DIR_X)
65  return "X";
66  else if (m_dir == DIR_Y)
67  return "Y";
68  else
69  return "NONE";
70  }
71  void SortByOIndex(uint32_t left, uint32_t center,
72  uint32_t right);
73  void SetAllocator(detail::opt_allocator<PtRef> *alloc_p )
74  {
75  m_vec_p = new PtRefVec( *alloc_p );
76  }
77 };
78 
80 
82 {
83  friend class Chipper;
84 
85 private:
86  RefList *m_list_p;
87  uint32_t m_left;
88  uint32_t m_right;
89  liblas::Bounds<double> m_bounds;
90 
91 public:
92  std::vector<uint32_t> GetIDs() const;
93  Bounds<double> const& GetBounds() const
94  {return m_bounds;}
95  void SetBounds(liblas::Bounds<double> const& bounds)
96  {m_bounds = bounds;}
97 };
98 
99 // Options that can be used to modify the behavior of the chipper.
101 {
102 public:
103  Options() : m_threshold( 1000 ), m_use_sort( false ),
104  m_use_maps( false )
105  {}
106 
107  // Maximum number of pointer per output block.
108  uint32_t m_threshold;
109  // If true, use sorting instead of copying to reduce memory.
111  // If true, use memory mapped files instead of main memory
113  // Map file to use if m_use_maps is true.
114  std::string m_map_file;
115 };
116 
118 {
119 public:
120  Chipper(Reader *reader, Options *options );
121  Chipper(Reader *reader, uint32_t max_partition_size) :
122  m_reader(reader), m_xvec(DIR_X), m_yvec(DIR_Y), m_spare(DIR_NONE)
123  {
124  m_options.m_threshold = max_partition_size;
125  }
126 
127  void Chip();
128  std::vector<Block>::size_type GetBlockCount()
129  { return m_blocks.size(); }
130  const Block& GetBlock(std::vector<Block>::size_type i)
131  { return m_blocks[i]; }
132 
133 private:
134  int Allocate();
135  int Load();
136  void Partition(uint32_t size);
137  void Split(RefList& xvec, RefList& yvec, RefList& spare);
138  void DecideSplit(RefList& v1, RefList& v2, RefList& spare,
139  uint32_t left, uint32_t right);
140  void RearrangeNarrow(RefList& wide, RefList& narrow, RefList& spare,
141  uint32_t left, uint32_t center, uint32_t right);
142  void Split(RefList& wide, RefList& narrow, RefList& spare,
143  uint32_t left, uint32_t right);
144  void FinalSplit(RefList& wide, RefList& narrow,
145  uint32_t pleft, uint32_t pcenter);
146  void Emit(RefList& wide, uint32_t widemin, uint32_t widemax,
147  RefList& narrow, uint32_t narrowmin, uint32_t narrowmax);
148 
149  Reader *m_reader;
150  std::vector<Block> m_blocks;
151  std::vector<uint32_t> m_partitions;
152  // Note, order is important here, as the allocator must be destroyed
153  // after the RefLists.
154  boost::shared_ptr<detail::opt_allocator<PtRef> > m_allocator;
155  RefList m_xvec;
156  RefList m_yvec;
157  RefList m_spare;
158  Options m_options;
159 };
160 
161 } // namespace chipper
162 
163 } // namespace liblas
164 
165 #endif
~RefList()
Definition: chipper.hpp:43
std::string m_map_file
Definition: chipper.hpp:114
Definition: chipper.hpp:35
#define NULL
Definition: las_config.h:63
#define LAS_DLL
Definition: export.hpp:58
RefList(Direction dir=DIR_NONE)
Definition: chipper.hpp:41
Definition: chipper.hpp:20
PtRef & operator[](uint32_t pos)
Definition: chipper.hpp:60
void SetAllocator(detail::opt_allocator< PtRef > *alloc_p)
Definition: chipper.hpp:73
PtRefVec::size_type size() const
Definition: chipper.hpp:48
Chipper(Reader *reader, uint32_t max_partition_size)
Definition: chipper.hpp:121
void resize(PtRefVec::size_type n)
Definition: chipper.hpp:52
PtRefVec * m_vec_p
Definition: chipper.hpp:38
void push_back(const PtRef &ref)
Definition: chipper.hpp:54
Definition: chipper.hpp:100
Direction
Definition: chipper.hpp:16
bool m_use_maps
Definition: chipper.hpp:112
std::vector< PtRef, detail::opt_allocator< PtRef > > PtRefVec
Definition: chipper.hpp:33
Options()
Definition: chipper.hpp:103
void reserve(PtRefVec::size_type n)
Definition: chipper.hpp:50
uint32_t m_ptindex
Definition: chipper.hpp:27
PtRefVec::iterator begin()
Definition: chipper.hpp:56
Defines public interface to LAS reader implementation.
Definition: reader.hpp:66
void SetBounds(liblas::Bounds< double > const &bounds)
Definition: chipper.hpp:95
std::string Dir()
Definition: chipper.hpp:62
Namespace grouping all elements of libLAS public interface.
Definition: bounds.hpp:60
Definition: chipper.hpp:81
const Block & GetBlock(std::vector< Block >::size_type i)
Definition: chipper.hpp:130
uint32_t m_oindex
Definition: chipper.hpp:28
Definition: chipper.hpp:18
double m_pos
Definition: chipper.hpp:26
Definition: chipper.hpp:23
std::vector< Block >::size_type GetBlockCount()
Definition: chipper.hpp:128
PtRefVec::iterator end()
Definition: chipper.hpp:58
Definition: chipper.hpp:19
class LAS_DLL Chipper
Definition: chipper.hpp:79
Definition: chipper.hpp:117
uint32_t m_threshold
Definition: chipper.hpp:108
bool m_use_sort
Definition: chipper.hpp:110
Bounds< double > const & GetBounds() const
Definition: chipper.hpp:93
Direction m_dir
Definition: chipper.hpp:39