libLAS API Reference (svn-trunk)
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
10namespace liblas
11{
12
13namespace chipper
14{
15
22
24{
25public:
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};
33typedef std::vector<PtRef, detail::opt_allocator<PtRef> > PtRefVec;
34
36{
37public:
40
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
85private:
86 RefList *m_list_p;
87 uint32_t m_left;
88 uint32_t m_right;
90
91public:
92 std::vector<uint32_t> GetIDs() const;
94 {return m_bounds;}
96 {m_bounds = bounds;}
97};
98
99// Options that can be used to modify the behavior of the chipper.
101{
102public:
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{
119public:
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
133private:
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
Definition bounds.hpp:176
Defines public interface to LAS reader implementation.
Definition reader.hpp:67
Definition chipper.hpp:82
Bounds< double > const & GetBounds() const
Definition chipper.hpp:93
friend class Chipper
Definition chipper.hpp:83
void SetBounds(liblas::Bounds< double > const &bounds)
Definition chipper.hpp:95
std::vector< uint32_t > GetIDs() const
Definition chipper.hpp:118
std::vector< Block >::size_type GetBlockCount()
Definition chipper.hpp:128
Chipper(Reader *reader, uint32_t max_partition_size)
Definition chipper.hpp:121
const Block & GetBlock(std::vector< Block >::size_type i)
Definition chipper.hpp:130
Chipper(Reader *reader, Options *options)
Definition chipper.hpp:101
std::string m_map_file
Definition chipper.hpp:114
bool m_use_sort
Definition chipper.hpp:110
uint32_t m_threshold
Definition chipper.hpp:108
Options()
Definition chipper.hpp:103
bool m_use_maps
Definition chipper.hpp:112
Definition chipper.hpp:24
uint32_t m_ptindex
Definition chipper.hpp:27
uint32_t m_oindex
Definition chipper.hpp:28
double m_pos
Definition chipper.hpp:26
#define LAS_DLL
Definition export.hpp:58
#define NULL
Definition las_config.h:63
Definition chipper.hpp:14
Direction
Definition chipper.hpp:17
@ DIR_Y
Definition chipper.hpp:19
@ DIR_X
Definition chipper.hpp:18
@ DIR_NONE
Definition chipper.hpp:20
std::vector< PtRef, detail::opt_allocator< PtRef > > PtRefVec
Definition chipper.hpp:33
Namespace grouping all elements of libLAS public interface.
Definition bounds.hpp:60
Definition chipper.hpp:36
void resize(PtRefVec::size_type n)
Definition chipper.hpp:52
RefList(Direction dir=DIR_NONE)
Definition chipper.hpp:41
void SortByOIndex(uint32_t left, uint32_t center, uint32_t right)
~RefList()
Definition chipper.hpp:43
PtRefVec::iterator begin()
Definition chipper.hpp:56
PtRefVec::size_type size() const
Definition chipper.hpp:48
PtRef & operator[](uint32_t pos)
Definition chipper.hpp:60
Direction m_dir
Definition chipper.hpp:39
std::string Dir()
Definition chipper.hpp:62
void push_back(const PtRef &ref)
Definition chipper.hpp:54
void SetAllocator(detail::opt_allocator< PtRef > *alloc_p)
Definition chipper.hpp:73
PtRefVec::iterator end()
Definition chipper.hpp:58
PtRefVec * m_vec_p
Definition chipper.hpp:38
void reserve(PtRefVec::size_type n)
Definition chipper.hpp:50