Point Cloud Library (PCL)  1.9.1-dev
warp_point_rigid.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/pcl_macros.h>
44 #include <pcl/registration/eigen.h>
45 
46 namespace pcl
47 {
48  namespace registration
49  {
50  /** \brief Base warp point class.
51  *
52  * \note The class is templated on the source and target point types as well as on the output scalar of the transformation matrix (i.e., float or double). Default: float.
53  * \author Radu B. Rusu
54  * \ingroup registration
55  */
56  template <typename PointSourceT, typename PointTargetT, typename Scalar = float>
58  {
59  public:
60  using Matrix4 = Eigen::Matrix<Scalar, 4, 4>;
61  using VectorX = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
62  using Vector4 = Eigen::Matrix<Scalar, 4, 1>;
63 
64  using Ptr = boost::shared_ptr<WarpPointRigid<PointSourceT, PointTargetT, Scalar> >;
65  using ConstPtr = boost::shared_ptr<const WarpPointRigid<PointSourceT, PointTargetT, Scalar> >;
66 
67  /** \brief Constructor
68  * \param[in] nr_dim the number of dimensions
69  */
70  WarpPointRigid (int nr_dim)
71  : nr_dim_ (nr_dim)
72  , transform_matrix_ (Matrix4::Zero ())
73  {
74  transform_matrix_ (3, 3) = 1.0;
75  };
76 
77  /** \brief Destructor. */
78  virtual ~WarpPointRigid () {};
79 
80  /** \brief Set warp parameters. Pure virtual.
81  * \param[in] p warp parameters
82  */
83  virtual void
84  setParam (const VectorX& p) = 0;
85 
86  /** \brief Warp a point given a transformation matrix
87  * \param[in] pnt_in the point to warp (transform)
88  * \param[out] pnt_out the warped (transformed) point
89  */
90  inline void
91  warpPoint (const PointSourceT& pnt_in, PointSourceT& pnt_out) const
92  {
93  pnt_out.x = static_cast<float> (transform_matrix_ (0, 0) * pnt_in.x + transform_matrix_ (0, 1) * pnt_in.y + transform_matrix_ (0, 2) * pnt_in.z + transform_matrix_ (0, 3));
94  pnt_out.y = static_cast<float> (transform_matrix_ (1, 0) * pnt_in.x + transform_matrix_ (1, 1) * pnt_in.y + transform_matrix_ (1, 2) * pnt_in.z + transform_matrix_ (1, 3));
95  pnt_out.z = static_cast<float> (transform_matrix_ (2, 0) * pnt_in.x + transform_matrix_ (2, 1) * pnt_in.y + transform_matrix_ (2, 2) * pnt_in.z + transform_matrix_ (2, 3));
96  //pnt_out.getVector3fMap () = transform_matrix_.topLeftCorner (3, 3) *
97  // pnt_in.getVector3fMap () +
98  // transform_matrix_.block (0, 3, 3, 1);
99  //pnt_out.data[3] = pnt_in.data[3];
100  }
101 
102  /** \brief Warp a point given a transformation matrix
103  * \param[in] pnt_in the point to warp (transform)
104  * \param[out] pnt_out the warped (transformed) point
105  */
106  inline void
107  warpPoint (const PointSourceT& pnt_in, Vector4& pnt_out) const
108  {
109  pnt_out[0] = static_cast<Scalar> (transform_matrix_ (0, 0) * pnt_in.x + transform_matrix_ (0, 1) * pnt_in.y + transform_matrix_ (0, 2) * pnt_in.z + transform_matrix_ (0, 3));
110  pnt_out[1] = static_cast<Scalar> (transform_matrix_ (1, 0) * pnt_in.x + transform_matrix_ (1, 1) * pnt_in.y + transform_matrix_ (1, 2) * pnt_in.z + transform_matrix_ (1, 3));
111  pnt_out[2] = static_cast<Scalar> (transform_matrix_ (2, 0) * pnt_in.x + transform_matrix_ (2, 1) * pnt_in.y + transform_matrix_ (2, 2) * pnt_in.z + transform_matrix_ (2, 3));
112  pnt_out[3] = 0.0;
113  }
114 
115  /** \brief Get the number of dimensions. */
116  inline int
117  getDimension () const { return (nr_dim_); }
118 
119  /** \brief Get the Transform used. */
120  inline const Matrix4&
121  getTransform () const { return (transform_matrix_); }
122 
123  public:
125 
126  protected:
127  int nr_dim_;
129  };
130  } // namespace registration
131 } // namespace pcl
const Matrix4 & getTransform() const
Get the Transform used.
void warpPoint(const PointSourceT &pnt_in, Vector4 &pnt_out) const
Warp a point given a transformation matrix.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:359
void warpPoint(const PointSourceT &pnt_in, PointSourceT &pnt_out) const
Warp a point given a transformation matrix.
WarpPointRigid(int nr_dim)
Constructor.
virtual ~WarpPointRigid()
Destructor.
boost::shared_ptr< WarpPointRigid< PointSource, PointTarget, Scalar > > Ptr
boost::shared_ptr< const WarpPointRigid< PointSource, PointTarget, Scalar > > ConstPtr
int getDimension() const
Get the number of dimensions.
virtual void setParam(const VectorX &p)=0
Set warp parameters.
Defines all the PCL and non-PCL macros used.