Open3D (C++ API)
Geometry3D.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <Eigen/Geometry>
31 
33 #include "Open3D/Utility/Eigen.h"
34 
35 namespace open3d {
36 namespace geometry {
37 
38 class Geometry3D : public Geometry {
39 public:
40  enum class RotationType { XYZ, YZX, ZXY, XZY, ZYX, YXZ, AxisAngle };
41 
42  ~Geometry3D() override {}
43 
44 protected:
46 
47 public:
48  void Clear() override = 0;
49  bool IsEmpty() const override = 0;
50  virtual Eigen::Vector3d GetMinBound() const = 0;
51  virtual Eigen::Vector3d GetMaxBound() const = 0;
52  virtual Geometry3D& Transform(const Eigen::Matrix4d& transformation) = 0;
53  virtual Geometry3D& Translate(const Eigen::Vector3d& translation) = 0;
54  virtual Geometry3D& Scale(const double scale, bool center = true) = 0;
55  virtual Geometry3D& Rotate(const Eigen::Vector3d& rotation,
56  bool center = true,
58 
59 protected:
60  Eigen::Matrix3d GetRotationMatrix(
61  const Eigen::Vector3d& rotation,
63  if (type == RotationType::XYZ) {
64  return open3d::utility::RotationMatrixX(rotation(0)) *
67  } else if (type == RotationType::YZX) {
68  return open3d::utility::RotationMatrixY(rotation(0)) *
71  } else if (type == RotationType::ZXY) {
72  return open3d::utility::RotationMatrixZ(rotation(0)) *
75  } else if (type == RotationType::XZY) {
76  return open3d::utility::RotationMatrixX(rotation(0)) *
79  } else if (type == RotationType::ZYX) {
80  return open3d::utility::RotationMatrixZ(rotation(0)) *
83  } else if (type == RotationType::YXZ) {
84  return open3d::utility::RotationMatrixY(rotation(0)) *
87  } else if (type == RotationType::AxisAngle) {
88  const double phi = rotation.norm();
89  return Eigen::AngleAxisd(phi, rotation / phi).toRotationMatrix();
90  } else {
91  return Eigen::Matrix3d::Identity();
92  }
93  }
94 };
95 
96 } // namespace geometry
97 } // namespace open3d
Eigen::Matrix3d RotationMatrixZ(double radians)
Definition: Eigen.cpp:295
virtual Geometry3D & Scale(const double scale, bool center=true)=0
Definition: Geometry.h:32
bool IsEmpty() const override=0
virtual Eigen::Vector3d GetMinBound() const =0
Geometry3D(GeometryType type)
Definition: Geometry3D.h:45
virtual Geometry3D & Transform(const Eigen::Matrix4d &transformation)=0
Eigen::Matrix3d GetRotationMatrix(const Eigen::Vector3d &rotation, RotationType type=RotationType::XYZ) const
Definition: Geometry3D.h:60
virtual Eigen::Vector3d GetMaxBound() const =0
RotationType
Definition: Geometry3D.h:40
virtual Geometry3D & Rotate(const Eigen::Vector3d &rotation, bool center=true, RotationType type=RotationType::XYZ)=0
Eigen::Matrix3d RotationMatrixX(double radians)
Definition: Eigen.cpp:281
Definition: Geometry3D.h:38
char type
Definition: FilePCD.cpp:56
~Geometry3D() override
Definition: Geometry3D.h:42
Definition: PinholeCameraIntrinsic.cpp:34
Eigen::Matrix3d RotationMatrixY(double radians)
Definition: Eigen.cpp:288
GeometryType
Definition: Geometry.h:34
virtual Geometry3D & Translate(const Eigen::Vector3d &translation)=0