Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Utility.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 "open3d/core/Tensor.h"
30 
31 namespace open3d {
32 namespace t {
33 namespace geometry {
34 
37  T.AssertShape({4, 4});
39  T.AssertDevice(core::Device("CPU:0"));
40  if (!T.IsContiguous()) {
41  utility::LogError("T is expected to be contiguous");
42  }
43 
44  core::Tensor Tinv({4, 4}, core::Dtype::Float64, core::Device("CPU:0"));
45  const double* T_ptr = T.GetDataPtr<double>();
46  double* Tinv_ptr = Tinv.GetDataPtr<double>();
47 
48  // R' = R.T
49  Tinv_ptr[0 * 4 + 0] = T_ptr[0 * 4 + 0];
50  Tinv_ptr[0 * 4 + 1] = T_ptr[1 * 4 + 0];
51  Tinv_ptr[0 * 4 + 2] = T_ptr[2 * 4 + 0];
52 
53  Tinv_ptr[1 * 4 + 0] = T_ptr[0 * 4 + 1];
54  Tinv_ptr[1 * 4 + 1] = T_ptr[1 * 4 + 1];
55  Tinv_ptr[1 * 4 + 2] = T_ptr[2 * 4 + 1];
56 
57  Tinv_ptr[2 * 4 + 0] = T_ptr[0 * 4 + 2];
58  Tinv_ptr[2 * 4 + 1] = T_ptr[1 * 4 + 2];
59  Tinv_ptr[2 * 4 + 2] = T_ptr[2 * 4 + 2];
60 
61  // t' = -R.T @ t = -R' @ t
62  Tinv_ptr[0 * 4 + 3] = -(Tinv_ptr[0 * 4 + 0] * T_ptr[0 * 4 + 3] +
63  Tinv_ptr[0 * 4 + 1] * T_ptr[1 * 4 + 3] +
64  Tinv_ptr[0 * 4 + 2] * T_ptr[2 * 4 + 3]);
65  Tinv_ptr[1 * 4 + 3] = -(Tinv_ptr[1 * 4 + 0] * T_ptr[0 * 4 + 3] +
66  Tinv_ptr[1 * 4 + 1] * T_ptr[1 * 4 + 3] +
67  Tinv_ptr[1 * 4 + 2] * T_ptr[2 * 4 + 3]);
68  Tinv_ptr[2 * 4 + 3] = -(Tinv_ptr[2 * 4 + 0] * T_ptr[0 * 4 + 3] +
69  Tinv_ptr[2 * 4 + 1] * T_ptr[1 * 4 + 3] +
70  Tinv_ptr[2 * 4 + 2] * T_ptr[2 * 4 + 3]);
71 
72  // Remaining part
73  Tinv_ptr[3 * 4 + 0] = 0;
74  Tinv_ptr[3 * 4 + 1] = 0;
75  Tinv_ptr[3 * 4 + 2] = 0;
76  Tinv_ptr[3 * 4 + 3] = 1;
77 
78  return Tinv;
79 }
80 } // namespace geometry
81 } // namespace t
82 } // namespace open3d
#define LogError(...)
Definition: Console.h:79
core::Tensor InverseTransformation(const core::Tensor &T)
TODO(wei): find a proper place for such functionalities.
Definition: Utility.h:36
Definition: Device.h:39
bool IsContiguous() const
Definition: Tensor.h:897
void AssertDtype(const Dtype &expected_dtype, const std::string &error_msg="") const
Assert that the Tensor has the specified dtype.
Definition: Tensor.cpp:1534
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:50
T * GetDataPtr()
Definition: Tensor.h:1005
void AssertDevice(const Device &expected_device, const std::string &error_msg="") const
Assert that the Tensor has the specified device.
Definition: Tensor.cpp:1518
static const Dtype Float64
Definition: Dtype.h:43
void AssertShape(const SizeVector &expected_shape, const std::string &error_msg="") const
Assert that the Tensor has the specified shape.
Definition: Tensor.cpp:1498