Point Cloud Library (PCL)  1.11.1
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/memory.h>
44 #include <pcl/pcl_macros.h>
45 #include <pcl/registration/eigen.h>
46 
47 namespace pcl
48 {
49  namespace registration
50  {
51  /** \brief Base warp point class.
52  *
53  * \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.
54  * \author Radu B. Rusu
55  * \ingroup registration
56  */
57  template <typename PointSourceT, typename PointTargetT, typename Scalar = float>
59  {
60  public:
61  using Matrix4 = Eigen::Matrix<Scalar, 4, 4>;
62  using VectorX = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
63  using Vector4 = Eigen::Matrix<Scalar, 4, 1>;
64 
65  using Ptr = shared_ptr<WarpPointRigid<PointSourceT, PointTargetT, Scalar> >;
66  using ConstPtr = shared_ptr<const WarpPointRigid<PointSourceT, PointTargetT, Scalar> >;
67 
68  /** \brief Constructor
69  * \param[in] nr_dim the number of dimensions
70  */
71  WarpPointRigid (int nr_dim)
72  : nr_dim_ (nr_dim)
73  , transform_matrix_ (Matrix4::Zero ())
74  {
75  transform_matrix_ (3, 3) = 1.0;
76  };
77 
78  /** \brief Destructor. */
79  virtual ~WarpPointRigid () {};
80 
81  /** \brief Set warp parameters. Pure virtual.
82  * \param[in] p warp parameters
83  */
84  virtual void
85  setParam (const VectorX& p) = 0;
86 
87  /** \brief Warp a point given a transformation matrix
88  * \param[in] pnt_in the point to warp (transform)
89  * \param[out] pnt_out the warped (transformed) point
90  */
91  inline void
92  warpPoint (const PointSourceT& pnt_in, PointSourceT& pnt_out) const
93  {
94  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));
95  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));
96  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));
97  //pnt_out.getVector3fMap () = transform_matrix_.topLeftCorner (3, 3) *
98  // pnt_in.getVector3fMap () +
99  // transform_matrix_.block (0, 3, 3, 1);
100  //pnt_out.data[3] = pnt_in.data[3];
101  }
102 
103  /** \brief Warp a point given a transformation matrix
104  * \param[in] pnt_in the point to warp (transform)
105  * \param[out] pnt_out the warped (transformed) point
106  */
107  inline void
108  warpPoint (const PointSourceT& pnt_in, Vector4& pnt_out) const
109  {
110  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));
111  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));
112  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));
113  pnt_out[3] = 0.0;
114  }
115 
116  /** \brief Get the number of dimensions. */
117  inline int
118  getDimension () const { return (nr_dim_); }
119 
120  /** \brief Get the Transform used. */
121  inline const Matrix4&
122  getTransform () const { return (transform_matrix_); }
123 
124  public:
126 
127  protected:
128  int nr_dim_;
130  };
131  } // namespace registration
132 } // namespace pcl
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::registration::WarpPointRigid< PointSourceT, PointTargetT, float >::ConstPtr
shared_ptr< const WarpPointRigid< PointSourceT, PointTargetT, float > > ConstPtr
Definition: warp_point_rigid.h:66
pcl::registration::WarpPointRigid::transform_matrix_
Matrix4 transform_matrix_
Definition: warp_point_rigid.h:129
pcl
Definition: convolution.h:46
pcl::registration::WarpPointRigid::warpPoint
void warpPoint(const PointSourceT &pnt_in, PointSourceT &pnt_out) const
Warp a point given a transformation matrix.
Definition: warp_point_rigid.h:92
pcl::registration::WarpPointRigid::warpPoint
void warpPoint(const PointSourceT &pnt_in, Vector4 &pnt_out) const
Warp a point given a transformation matrix.
Definition: warp_point_rigid.h:108
pcl::registration::WarpPointRigid< PointSourceT, PointTargetT, float >::Matrix4
Eigen::Matrix< float, 4, 4 > Matrix4
Definition: warp_point_rigid.h:61
pcl::registration::WarpPointRigid
Base warp point class.
Definition: warp_point_rigid.h:59
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
pcl::registration::WarpPointRigid< PointSourceT, PointTargetT, float >::VectorX
Eigen::Matrix< float, Eigen::Dynamic, 1 > VectorX
Definition: warp_point_rigid.h:62
pcl::registration::WarpPointRigid::getDimension
int getDimension() const
Get the number of dimensions.
Definition: warp_point_rigid.h:118
pcl::registration::WarpPointRigid::nr_dim_
int nr_dim_
Definition: warp_point_rigid.h:128
pcl::registration::WarpPointRigid::WarpPointRigid
WarpPointRigid(int nr_dim)
Constructor.
Definition: warp_point_rigid.h:71
pcl::registration::WarpPointRigid< PointSourceT, PointTargetT, float >::Vector4
Eigen::Matrix< float, 4, 1 > Vector4
Definition: warp_point_rigid.h:63
pcl::registration::WarpPointRigid::getTransform
const Matrix4 & getTransform() const
Get the Transform used.
Definition: warp_point_rigid.h:122
pcl::registration::WarpPointRigid::~WarpPointRigid
virtual ~WarpPointRigid()
Destructor.
Definition: warp_point_rigid.h:79
pcl::registration::WarpPointRigid::setParam
virtual void setParam(const VectorX &p)=0
Set warp parameters.
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl::registration::WarpPointRigid< PointSourceT, PointTargetT, float >::Ptr
shared_ptr< WarpPointRigid< PointSourceT, PointTargetT, float > > Ptr
Definition: warp_point_rigid.h:65