1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
5  * Purpose:  LAS transform class
6  * Author:   Howard Butler, hobu.inc@gmail.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2010, Howard Butler
10  *
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following
15  * conditions are met:
16  *
17  *     * Redistributions of source code must retain the above copyright
18  *       notice, this list of conditions and the following disclaimer.
19  *     * Redistributions in binary form must reproduce the above copyright
20  *       notice, this list of conditions and the following disclaimer in
21  *       the documentation and/or other materials provided
22  *       with the distribution.
23  *     * Neither the name of the Martin Isenburg or Iowa Department
24  *       of Natural Resources nor the names of its contributors may be
25  *       used to endorse or promote products derived from this software
26  *       without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
35  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
39  * OF SUCH DAMAGE.
40  ****************************************************************************/
41 
42 #ifndef LIBLAS_LASTRANSFORM_HPP_INCLUDED
43 #define LIBLAS_LASTRANSFORM_HPP_INCLUDED
44 
45 #include <liblas/version.hpp>
46 #include <liblas/point.hpp>
47 #include <liblas/spatialreference.hpp>
48 #include <liblas/export.hpp>
49 // boost
50 #include <boost/shared_ptr.hpp>
51 #include <boost/array.hpp>
52 // std
53 #include <vector>
54 #include <string>
55 
56 namespace liblas {
57 
58 /// Defines public interface to LAS transform implementation.
59 class LAS_DLL TransformI
60 {
61 public:
62 
63     virtual bool transform(Point& point) = 0;
64     virtual bool ModifiesHeader() = 0;
~TransformI()65     virtual ~TransformI() {}
66 };
67 
68 typedef boost::shared_ptr<liblas::TransformI> TransformPtr;
69 
70 class LAS_DLL ReprojectionTransform: public TransformI
71 {
72 public:
73 
74     ReprojectionTransform(const SpatialReference& inSRS, const SpatialReference& outSRS);
75     ReprojectionTransform(const SpatialReference& inSRS, const SpatialReference& outSRS, Header const* new_header);
76     ~ReprojectionTransform();
77 
78     bool transform(Point& point);
SetHeader(Header * header)79     void SetHeader(Header* header) {m_new_header = header;}
ModifiesHeader()80     bool ModifiesHeader() { return true; }
81 
82 private:
83 
84     Header const* m_new_header;
85 
86     typedef boost::shared_ptr<void> ReferencePtr;
87     typedef boost::shared_ptr<void> TransformPtr;
88     ReferencePtr m_in_ref_ptr;
89     ReferencePtr m_out_ref_ptr;
90     TransformPtr m_transform_ptr;
91 
92 
93 
94     ReprojectionTransform(ReprojectionTransform const& other);
95     ReprojectionTransform& operator=(ReprojectionTransform const& rhs);
96 
97     void Initialize(SpatialReference const& inSRS, SpatialReference const& outSRS);
98 };
99 
100 class LAS_DLL TranslationTransform: public TransformI
101 {
102 public:
103 
104     TranslationTransform(std::string const& expression);
105     ~TranslationTransform();
106 
107     bool transform(Point& point);
ModifiesHeader()108     bool ModifiesHeader() { return false; }
109 
110     enum OPER_TYPE
111     {
112         eOPER_MULTIPLY = 0,
113         eOPER_DIVIDE = 1,
114         eOPER_SUBTRACT = 2,
115         eOPER_ADD = 3,
116         eOPER_NONE = -99
117     };
118 
119     // Yes, Mateusz, I'm embarassed by this :)
120     struct operation{
121         OPER_TYPE oper;
122         std::string dimension;
123         double value;
124         std::string expression;
125 
operationliblas::TranslationTransform::operation126         operation(std::string name) : oper(eOPER_NONE), dimension(name), value(0.0)
127         {
128         }
129     };
130 
131 private:
132 
133     TranslationTransform(TranslationTransform const& other);
134     TranslationTransform& operator=(TranslationTransform const& rhs);
135 
136     operation GetOperation(std::string const& expression);
137 
138     std::vector<operation> operations;
139 
140     std::string m_expression;
141 };
142 
143 
144 class LAS_DLL ColorFetchingTransform: public TransformI
145 {
146 public:
147 
148     ColorFetchingTransform( std::string const& datasource,
149                             std::vector<uint32_t> bands
150                             );
151     ColorFetchingTransform( std::string const& datasource,
152                             std::vector<uint32_t> bands,
153                             Header const* header);
154 
SetScaleFactor(uint32_t v)155     void SetScaleFactor(uint32_t v) {m_scale = v; }
156     ~ColorFetchingTransform();
157 
158     bool transform(Point& point);
ModifiesHeader()159     bool ModifiesHeader() { return true; }
160 
161 
162 private:
163 
164     Header const* m_new_header;
165 
166     typedef boost::shared_ptr<void> DataSourcePtr;
167 
168     DataSourcePtr m_ds;
169     std::string m_datasource;
170     std::vector<uint32_t> m_bands;
171     boost::array<double, 6> m_forward_transform;
172     boost::array<double, 6> m_inverse_transform;
173     boost::uint32_t m_scale;
174 
175     ColorFetchingTransform(ColorFetchingTransform const& other);
176     ColorFetchingTransform& operator=(ColorFetchingTransform const& rhs);
177 
178     void Initialize();
179 };
180 } // namespace liblas
181 
182 #endif // ndef LIBLAS_LASTRANSFORM_HPP_INCLUDED
183