1 /******************************************************************************
2 * Copyright (c) 2014, Pete Gadomski <pete.gadomski@gmail.com>
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following
8 * conditions are met:
9 *
10 *     * Redistributions of source code must retain the above copyright
11 *       notice, this list of conditions and the following disclaimer.
12 *     * Redistributions in binary form must reproduce the above copyright
13 *       notice, this list of conditions and the following disclaimer in
14 *       the documentation and/or other materials provided
15 *       with the distribution.
16 *     * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
17 *       names of its contributors may be used to endorse or promote
18 *       products derived from this software without specific prior
19 *       written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * OF SUCH DAMAGE.
33 ****************************************************************************/
34 
35 #pragma once
36 
37 #include <array>
38 #include <string>
39 
40 #include <pdal/Filter.hpp>
41 #include <pdal/Streamable.hpp>
42 #include <pdal/util/ProgramArgs.hpp>
43 
44 namespace pdal
45 {
46 
47 class PDAL_DLL TransformationFilter : public Filter, public Streamable
48 {
49 public:
50     class Transform;
51 
52     TransformationFilter();
53     ~TransformationFilter();
54     TransformationFilter& operator=(const TransformationFilter&) = delete;
55     TransformationFilter(const TransformationFilter&) = delete;
56 
57     std::string getName() const override;
58     void doFilter(PointView& view, const Transform& matrix);
59 
60 private:
61     virtual void addArgs(ProgramArgs& args) override;
62     virtual void initialize() override;
63     virtual bool processOne(PointRef& point) override;
64     virtual void filter(PointView& view) override;
65     virtual void spatialReferenceChanged(const SpatialReference& srs) override;
66 
67     std::unique_ptr<Transform> m_matrix;
68     SpatialReference m_overrideSrs;
69     bool m_invert;
70 };
71 
72 class TransformationFilter::Transform
73 {
74 public:
75     static const size_t RowSize = 4;
76     static const size_t ColSize = 4;
77     static const size_t Size = RowSize * ColSize;
78     typedef double ValueType;
79     typedef std::array<ValueType, Size> ArrayType;
80 
81     PDAL_DLL Transform();
82     PDAL_DLL Transform(const ArrayType& arr);
83 
operator [](size_t off) const84     PDAL_DLL double operator[](size_t off) const
85         { return m_vals[off]; }
operator [](size_t off)86     PDAL_DLL double& operator[](size_t off)
87         { return m_vals[off]; }
88 
89 private:
90     ArrayType m_vals;
91 
92     PDAL_DLL friend std::istream& operator>>(std::istream& in,
93         pdal::TransformationFilter::Transform& xform);
94     PDAL_DLL friend std::ostream& operator<<(std::ostream& out,
95         const pdal::TransformationFilter::Transform& xform);
96 };
97 
98 } // namespace pdal
99