ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
GeometryIndexer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Helper.h>
11 #include <Logging.h>
12 #include <Timer.h>
13 
14 #include <unordered_map>
15 
19 
20 namespace cloudViewer {
21 namespace t {
22 namespace geometry {
23 namespace kernel {
24 
27 public:
30  TransformIndexer(const core::Tensor& intrinsics,
31  const core::Tensor& extrinsics,
32  float scale = 1.0f) {
33  core::AssertTensorShape(intrinsics, {3, 3});
35  core::AssertTensorDevice(intrinsics, core::Device("CPU:0"));
36  if (!intrinsics.IsContiguous()) {
37  utility::LogError("Intrinsics is not contiguous");
38  }
39 
40  core::AssertTensorShape(extrinsics, {4, 4});
42  core::AssertTensorDevice(extrinsics, core::Device("CPU:0"));
43  if (!extrinsics.IsContiguous()) {
44  utility::LogError("Extrinsics is not contiguous");
45  }
46 
47  const double* intrinsic_ptr = intrinsics.GetDataPtr<double>();
48  const double* extrinsic_ptr = extrinsics.GetDataPtr<double>();
49  for (int i = 0; i < 3; ++i) {
50  for (int j = 0; j < 4; ++j) {
51  extrinsic_[i][j] = extrinsic_ptr[i * 4 + j];
52  }
53  }
54 
55  fx_ = intrinsic_ptr[0 * 3 + 0];
56  fy_ = intrinsic_ptr[1 * 3 + 1];
57  cx_ = intrinsic_ptr[0 * 3 + 2];
58  cy_ = intrinsic_ptr[1 * 3 + 2];
59  scale_ = scale;
60  }
61 
64  float y_in,
65  float z_in,
66  float* x_out,
67  float* y_out,
68  float* z_out) const {
69  x_in *= scale_;
70  y_in *= scale_;
71  z_in *= scale_;
72 
73  *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
74  z_in * extrinsic_[0][2] + extrinsic_[0][3];
75  *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
76  z_in * extrinsic_[1][2] + extrinsic_[1][3];
77  *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
78  z_in * extrinsic_[2][2] + extrinsic_[2][3];
79  }
80 
83  float y_in,
84  float z_in,
85  float* x_out,
86  float* y_out,
87  float* z_out) const {
88  x_in *= scale_;
89  y_in *= scale_;
90  z_in *= scale_;
91 
92  *x_out = x_in * extrinsic_[0][0] + y_in * extrinsic_[0][1] +
93  z_in * extrinsic_[0][2];
94  *y_out = x_in * extrinsic_[1][0] + y_in * extrinsic_[1][1] +
95  z_in * extrinsic_[1][2];
96  *z_out = x_in * extrinsic_[2][0] + y_in * extrinsic_[2][1] +
97  z_in * extrinsic_[2][2];
98  }
99 
102  float y_in,
103  float z_in,
104  float* u_out,
105  float* v_out) const {
106  float inv_z = 1.0f / z_in;
107  *u_out = fx_ * x_in * inv_z + cx_;
108  *v_out = fy_ * y_in * inv_z + cy_;
109  }
110 
113  float v_in,
114  float d_in,
115  float* x_out,
116  float* y_out,
117  float* z_out) const {
118  *x_out = (u_in - cx_) * d_in / fx_;
119  *y_out = (v_in - cy_) * d_in / fy_;
120  *z_out = d_in;
121  }
122 
123  CLOUDVIEWER_HOST_DEVICE void GetFocalLength(float* fx, float* fy) const {
124  *fx = fx_;
125  *fy = fy_;
126  }
127 
129  float* y,
130  float* z) const {
131  *x = extrinsic_[0][3];
132  *y = extrinsic_[1][3];
133  *z = extrinsic_[2][3];
134  }
135 
136 private:
137  float extrinsic_[3][4];
138 
139  float fx_;
140  float fy_;
141  float cx_;
142  float cy_;
143 
144  float scale_;
145 };
146 
159 const int64_t MAX_RESOLUTION_DIMS = 4;
160 
161 template <typename index_t>
163 public:
164  TArrayIndexer() : ptr_(nullptr), element_byte_size_(0), active_dims_(0) {
165  for (index_t i = 0; i < MAX_RESOLUTION_DIMS; ++i) {
166  shape_[i] = 0;
167  }
168  }
169 
170  TArrayIndexer(const core::Tensor& ndarray, index_t active_dims) {
171  if (!ndarray.IsContiguous()) {
173  "Only support contiguous tensors for general operations.");
174  }
175 
176  core::SizeVector shape = ndarray.GetShape();
177  index_t n = ndarray.NumDims();
178  if (active_dims > MAX_RESOLUTION_DIMS || active_dims > n) {
180  "Tensor shape too large, only <= {} and <= {} array dim is "
181  "supported, but received {}.",
182  MAX_RESOLUTION_DIMS, n, active_dims);
183  }
184 
185  // Leading dimensions are coordinates
186  active_dims_ = active_dims;
187  for (index_t i = 0; i < active_dims_; ++i) {
188  shape_[i] = shape[i];
189  }
190  // Trailing dimensions are channels
191  element_byte_size_ = ndarray.GetDtype().ByteSize();
192  for (index_t i = active_dims_; i < n; ++i) {
193  element_byte_size_ *= shape[i];
194  }
195 
196  // Fill-in rest to make compiler happy, not actually used.
197  for (index_t i = active_dims_; i < MAX_RESOLUTION_DIMS; ++i) {
198  shape_[i] = 0;
199  }
200  ptr_ = const_cast<void*>(ndarray.GetDataPtr());
201  }
202 
205  index_t n = static_cast<index_t>(shape.size());
206  if (n > MAX_RESOLUTION_DIMS) {
208  "SizeVector too large, only <= {} is supported, but "
209  "received {}.",
211  }
212  active_dims_ = n;
213  for (index_t i = 0; i < active_dims_; ++i) {
214  shape_[i] = shape[i];
215  }
216 
217  // Fill-in rest to make compiler happy, not actually used.
218  for (index_t i = active_dims_; i < MAX_RESOLUTION_DIMS; ++i) {
219  shape_[i] = 0;
220  }
221 
222  // Reserved
223  element_byte_size_ = 0;
224  ptr_ = nullptr;
225  }
226 
228  return element_byte_size_;
229  }
230 
232  index_t num_elems = 1;
233  for (index_t i = 0; i < active_dims_; ++i) {
234  num_elems *= shape_[i];
235  }
236  return num_elems;
237  }
238 
241  index_t x_in, index_t y_in, index_t* workload) const {
242  *workload = y_in * shape_[1] + x_in;
243  }
244 
247  index_t x_in, index_t y_in, index_t z_in, index_t* workload) const {
248  *workload = (z_in * shape_[1] + y_in) * shape_[2] + x_in;
249  }
250 
253  index_t x_in,
254  index_t y_in,
255  index_t z_in,
256  index_t t_in,
257  index_t* workload) const {
258  *workload = ((t_in * shape_[1] + z_in) * shape_[2] + y_in) * shape_[3] +
259  x_in;
260  }
261 
264  index_t* x_out,
265  index_t* y_out) const {
266  *x_out = workload % shape_[1];
267  *y_out = workload / shape_[1];
268  }
269 
272  index_t* x_out,
273  index_t* y_out,
274  index_t* z_out) const {
275  *x_out = workload % shape_[2];
276  workload = (workload - *x_out) / shape_[2];
277  *y_out = workload % shape_[1];
278  *z_out = workload / shape_[1];
279  }
280 
283  index_t* x_out,
284  index_t* y_out,
285  index_t* z_out,
286  index_t* t_out) const {
287  *x_out = workload % shape_[3];
288  workload = (workload - *x_out) / shape_[3];
289  *y_out = workload % shape_[2];
290  workload = (workload - *y_out) / shape_[2];
291  *z_out = workload % shape_[1];
292  *t_out = workload / shape_[1];
293  }
294 
295  inline CLOUDVIEWER_HOST_DEVICE bool InBoundary(float x, float y) const {
296  return y >= 0 && x >= 0 && y <= shape_[0] - 1.0f &&
297  x <= shape_[1] - 1.0f;
298  }
300  float y,
301  float z) const {
302  return z >= 0 && y >= 0 && x >= 0 && z <= shape_[0] - 1.0f &&
303  y <= shape_[1] - 1.0f && x <= shape_[2] - 1.0f;
304  }
306  float y,
307  float z,
308  float t) const {
309  return t >= 0 && z >= 0 && y >= 0 && x >= 0 && t <= shape_[0] - 1.0f &&
310  z <= shape_[1] - 1.0f && y <= shape_[2] - 1.0f &&
311  x <= shape_[3] - 1.0f;
312  }
313 
315  return shape_[i];
316  }
317 
318  inline CLOUDVIEWER_HOST_DEVICE void* GetDataPtr() const { return ptr_; }
319 
320  template <typename T>
322  return static_cast<T*>(static_cast<void*>(static_cast<uint8_t*>(ptr_) +
323  x * element_byte_size_));
324  }
325 
326  template <typename T>
328  index_t workload;
329  CoordToWorkload(x, y, &workload);
330  return static_cast<T*>(static_cast<void*>(
331  static_cast<uint8_t*>(ptr_) + workload * element_byte_size_));
332  }
333 
334  template <typename T>
336  index_t y,
337  index_t z) const {
338  index_t workload;
339  CoordToWorkload(x, y, z, &workload);
340  return static_cast<T*>(static_cast<void*>(
341  static_cast<uint8_t*>(ptr_) + workload * element_byte_size_));
342  }
343 
344  template <typename T>
346  index_t y,
347  index_t z,
348  index_t t) const {
349  index_t workload;
350  CoordToWorkload(x, y, z, t, &workload);
351  return static_cast<T*>(static_cast<void*>(
352  static_cast<uint8_t*>(ptr_) + workload * element_byte_size_));
353  }
354 
355 private:
356  void* ptr_;
357  index_t element_byte_size_;
358  index_t active_dims_;
359 
361 };
362 
364 
365 } // namespace kernel
366 } // namespace geometry
367 } // namespace t
368 } // namespace cloudViewer
cloudViewer::t::geometry::kernel::image::CreateVertexMap
void CreateVertexMap(const core::Tensor &src, core::Tensor &dst, const core::Tensor &intrinsics, float invalid_fill)
Definition: Image.cpp:62
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::core::Tensor::GetDtype
Dtype GetDtype() const
Definition: Tensor.h:1164
cloudViewer::core::Tensor::Clone
Tensor Clone() const
Copy Tensor to the same device.
Definition: Tensor.h:502
cloudViewer::core::Tensor::EmptyLike
static Tensor EmptyLike(const Tensor &other)
Definition: Tensor.h:247
ShapeUtil.h
cloudViewer::t::geometry::Image::ClipTransform
Image ClipTransform(float scale, float min_value, float max_value, float clip_fill=0.0f) const
Return new image after scaling and clipping image values.
Definition: Image.cpp:417
cloudViewer::core::UInt16
const Dtype UInt16
Definition: Dtype.cpp:49
cloudViewer::t::geometry::Image::InterpType::Nearest
@ Nearest
Nearest neighbors interpolation.
cloudViewer::geometry::Image::GetMin2DBound
virtual Eigen::Vector2d GetMin2DBound() const override
Definition: Image.cpp:39
CUDAUtils.h
Common CUDA utilities.
cloudViewer::geometry::Image::onDeletionOf
virtual void onDeletionOf(const ccHObject *obj) override
This method is called when another object is deleted.
Definition: Image.cpp:28
cloudViewer::t::geometry::kernel::TArrayIndexer::NumElements
CLOUDVIEWER_HOST_DEVICE index_t NumElements()
Definition: GeometryIndexer.h:231
cloudViewer::t::geometry::kernel::image::PyrDownDepthCPU
void PyrDownDepthCPU(const core::Tensor &src, core::Tensor &dst, float diff_threshold, float invalid_fill)
Definition: ImageImpl.h:126
cloudViewer::t::geometry::npp::FilterBilateral
void FilterBilateral(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float value_sigma, float distance_sigma)
Definition: NPPImage.cpp:319
cloudViewer::t::geometry::kernel::TArrayIndexer::GetDataPtr
CLOUDVIEWER_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z) const
Definition: GeometryIndexer.h:335
cloudViewer::t::geometry::kernel::TArrayIndexer::InBoundary
CLOUDVIEWER_HOST_DEVICE bool InBoundary(float x, float y, float z, float t) const
Definition: GeometryIndexer.h:305
cloudViewer::core::make_pair
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:49
cloudViewer::t::geometry::kernel::TArrayIndexer::TArrayIndexer
TArrayIndexer(const core::Tensor &ndarray, index_t active_dims)
Definition: GeometryIndexer.h:170
x
normal_z x
Definition: my_point_types.h:165
cloudViewer::utility::optional::has_value
constexpr bool has_value() const noexcept
Definition: Optional.h:440
cloudViewer::core::Int16
const Dtype Int16
Definition: Dtype.cpp:45
cloudViewer::core::Tensor::GetShape
SizeVector GetShape() const
Definition: Tensor.h:1127
cloudViewer::geometry::Image::FilterType
FilterType
Specifies the Image filter type.
Definition: Image.h:52
cloudViewer::t::geometry::ipp::Resize
void Resize(const core::Tensor &src_im, core::Tensor &dst_im, Image::InterpType interp_type)
Definition: IPPImage.cpp:94
cloudViewer::t::geometry::kernel::image::CreateNormalMapCPU
void CreateNormalMapCPU(const core::Tensor &src, core::Tensor &dst, float invalid_fill)
Definition: ImageImpl.h:246
cloudViewer::core::shape_util::Concat
SizeVector Concat(const SizeVector &l_shape, const SizeVector &r_shape)
Concatenate two shapes.
Definition: ShapeUtil.cpp:199
cloudViewer::t::geometry::Image::To
Image To(const core::Device &device, bool copy=false) const
Transfer the image to a specified device.
Definition: Image.h:132
offset
int offset
Definition: FileIOFactory.cpp:135
core::Tensor
copy
bool copy
Definition: VtkUtils.cpp:74
cloudViewer::geometry::Image::Downsample
std::shared_ptr< Image > Downsample() const
Function to 2x image downsample using simple 2x2 averaging.
Definition: Image.cpp:139
cloudViewer::core::Tensor::ReinterpretCast
Tensor ReinterpretCast(const core::Dtype &dtype) const
Definition: Tensor.cpp:388
cloudViewer::t::geometry::ipp::FilterGaussian
void FilterGaussian(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float sigma)
Definition: IPPImage.cpp:233
format
filament::Texture::InternalFormat format
Definition: FilamentResourceManager.cpp:181
cloudViewer::geometry::Image::FilterType::Sobel3Dy
@ Sobel3Dy
Sobel filter along Y-axis.
cloudViewer::t::geometry::Image::CreateVertexMap
Image CreateVertexMap(const core::Tensor &intrinsics, float invalid_fill=0.0f)
Create a vertex map from a depth image using unprojection.
Definition: Image.cpp:449
cloudViewer::core::IsDevice::IsCUDA
bool IsCUDA() const
Definition: Device.h:99
cloudViewer::t::geometry::kernel::TArrayIndexer::CoordToWorkload
CLOUDVIEWER_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t z_in, index_t *workload) const
3D coordinate => workload
Definition: GeometryIndexer.h:246
cloudViewer::core::Tensor::Reshape
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:671
cloudViewer::geometry::Image::GetMax2DBound
virtual Eigen::Vector2d GetMax2DBound() const override
Definition: Image.cpp:43
cloudViewer::t::geometry::kernel::TransformIndexer::Project
CLOUDVIEWER_HOST_DEVICE void Project(float x_in, float y_in, float z_in, float *u_out, float *v_out) const
Project a 3D coordinate in camera coordinate to a 2D uv coordinate.
Definition: GeometryIndexer.h:101
AssertTensorDevice
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:45
cloudViewer::core::Tensor::Contiguous
Tensor Contiguous() const
Definition: Tensor.cpp:772
cloudViewer::t::geometry::kernel::TArrayIndexer::GetDataPtr
CLOUDVIEWER_HOST_DEVICE void * GetDataPtr() const
Definition: GeometryIndexer.h:318
cloudViewer::t::geometry::kernel::TransformIndexer::TransformIndexer
TransformIndexer(const core::Tensor &intrinsics, const core::Tensor &extrinsics, float scale=1.0f)
Definition: GeometryIndexer.h:30
ccBBox
Bounding box structure.
Definition: ecvBBox.h:25
cloudViewer::core::Dtype::ByteSize
int64_t ByteSize() const
Definition: Dtype.h:59
cloudViewer::t::geometry::Image::Resize
Image Resize(float sampling_rate=0.5f, InterpType interp_type=InterpType::Nearest) const
Return a new image after resizing with specified interpolation type.
Definition: Image.cpp:156
cloudViewer::t::geometry::kernel::image::CreateVertexMapCPU
void CreateVertexMapCPU(const core::Tensor &src, core::Tensor &dst, const core::Tensor &intrinsics, float invalid_fill)
Definition: ImageImpl.h:199
cloudViewer::t::geometry::npp::Filter
void Filter(const cloudViewer::core::Tensor &src_im, cloudViewer::core::Tensor &dst_im, const cloudViewer::core::Tensor &kernel)
Definition: NPPImage.cpp:246
cloudViewer::core::Tensor::IsContiguous
bool IsContiguous() const
Definition: Tensor.h:1036
cloudViewer::t::geometry::kernel::TArrayIndexer::TArrayIndexer
TArrayIndexer()
Definition: GeometryIndexer.h:164
ccHObject::onDeletionOf
virtual void onDeletionOf(const ccHObject *obj)
This method is called when another object is deleted.
Definition: ecvHObject.cpp:519
cloudViewer::t::geometry::Image::Reset
Image & Reset(int64_t rows=0, int64_t cols=0, int64_t channels=1, core::Dtype dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Reinitialize image with new parameters.
Definition: Image.cpp:56
ecvBBox.h
cloudViewer::utility::optional::value_or
constexpr T value_or(V &&v) const &
Definition: Optional.h:485
cloudViewer::geometry::Image::FilterType::Gaussian3
@ Gaussian3
Gaussian filter of size 3 x 3.
cloudViewer::t::geometry::dtype_channels_pairs
std::vector< std::pair< core::Dtype, int64_t > > dtype_channels_pairs
Definition: Image.cpp:29
NPPImage.h
cloudViewer::geometry::Image::Dilate
std::shared_ptr< Image > Dilate(int half_kernel_size=1) const
Function to dilate 8bit mask map.
Definition: Image.cpp:338
cloudViewer::geometry::ImagePyramid
std::vector< std::shared_ptr< Image > > ImagePyramid
Typedef and functions for ImagePyramid.
Definition: Image.h:24
cloudViewer::t::geometry::Image::Filter
Image Filter(const core::Tensor &kernel) const
Return a new image after filtering with the given kernel.
Definition: Image.cpp:278
cloudViewer::t::geometry::kernel::image::ClipTransform
void ClipTransform(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value, float clip_fill)
Definition: Image.cpp:31
cloudViewer::t::geometry::Image
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:29
cloudViewer::t::geometry::kernel::image::ColorizeDepth
void ColorizeDepth(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value)
Definition: Image.cpp:92
cloudViewer::t::geometry::Image::GetRows
int64_t GetRows() const
Get the number of rows of the image.
Definition: Image.h:84
cloudViewer::t::geometry::kernel::TArrayIndexer
Definition: GeometryIndexer.h:162
cloudViewer::t::geometry::kernel::MAX_RESOLUTION_DIMS
const int64_t MAX_RESOLUTION_DIMS
Definition: GeometryIndexer.h:159
cloudViewer::geometry::Image::FilterType::Gaussian7
@ Gaussian7
Gaussian filter of size 7 x 7.
cloudViewer::t::geometry::kernel::TArrayIndexer::WorkloadToCoord
CLOUDVIEWER_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out) const
Workload => 2D coordinate.
Definition: GeometryIndexer.h:263
cloudViewer::t::geometry::kernel::TArrayIndexer::WorkloadToCoord
CLOUDVIEWER_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out, index_t *z_out) const
Workload => 3D coordinate.
Definition: GeometryIndexer.h:271
cloudViewer::t::geometry::Image::GetDevice
core::Device GetDevice() const override
Get device of the image.
Definition: Image.h:96
cloudViewer::t::geometry::ipp::To
void To(const core::Tensor &src_im, core::Tensor &dst_im, double scale, double offset)
Definition: IPPImage.cpp:42
cloudViewer::t::geometry::kernel::TArrayIndexer::CoordToWorkload
CLOUDVIEWER_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t *workload) const
2D coordinate => workload
Definition: GeometryIndexer.h:240
cloudViewer::t::geometry::Image::Image
Image(int64_t rows=0, int64_t cols=0, int64_t channels=1, core::Dtype dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Constructor for image.
Definition: Image.cpp:31
cloudViewer::t::geometry::kernel::TransformIndexer::GetFocalLength
CLOUDVIEWER_HOST_DEVICE void GetFocalLength(float *fx, float *fy) const
Definition: GeometryIndexer.h:123
cloudViewer::core::Dtype
Definition: Dtype.h:21
cloudViewer::t::geometry::Image::RGBToGray
Image RGBToGray() const
Converts a 3-channel RGB image to a new 1-channel Grayscale image.
Definition: Image.cpp:120
cloudViewer::t::geometry::ipp::RGBToGray
void RGBToGray(const core::Tensor &src_im, core::Tensor &dst_im)
Definition: IPPImage.cpp:71
cloudViewer::t::geometry::ipp::FilterSobel
void FilterSobel(const core::Tensor &src_im, core::Tensor &dst_im_dx, core::Tensor &dst_im_dy, int kernel_size)
Definition: IPPImage.cpp:261
width
int width
Definition: FileIOFactory.cpp:142
cloudViewer::core::Device::IsCUDA
bool IsCUDA() const
Returns true iff device type is CUDA.
Definition: Device.h:49
float
float
Definition: my_point_types.h:154
cloudViewer::t::geometry::kernel::TransformIndexer::RigidTransform
CLOUDVIEWER_HOST_DEVICE void RigidTransform(float x_in, float y_in, float z_in, float *x_out, float *y_out, float *z_out) const
Transform a 3D coordinate in camera coordinate to world coordinate.
Definition: GeometryIndexer.h:63
Parallel.h
CUDA_CALL
#define CUDA_CALL(cuda_function,...)
Definition: CUDAUtils.h:49
cloudViewer::geometry::Image::FilterPyramid
static ImagePyramid FilterPyramid(const ImagePyramid &input, Image::FilterType type)
Function to filter image pyramid.
Definition: Image.cpp:238
cloudViewer::core::Tensor::NumDims
int64_t NumDims() const
Definition: Tensor.h:1172
IPP_CALL
#define IPP_CALL(ipp_function,...)
Definition: IPPImage.h:96
cloudViewer::geometry::Image::BytesPerLine
int BytesPerLine() const
Returns data size per line (row, or the width) in bytes.
Definition: Image.h:122
cloudViewer::t::geometry::Image::GetDtype
core::Dtype GetDtype() const
Get dtype of the image.
Definition: Image.h:93
IPPImage.h
height
int height
Definition: FileIOFactory.cpp:143
y
normal_z y
Definition: my_point_types.h:168
cloudViewer::t::geometry::Image::ColorizeDepth
Image ColorizeDepth(float scale, float min_value, float max_value)
Colorize an input depth image (with Dtype UInt16 or Float32).
Definition: Image.cpp:482
cloudViewer::t::geometry::Image::CreateNormalMap
Image CreateNormalMap(float invalid_fill=0.0f)
Create a normal map from a vertex map.
Definition: Image.cpp:467
cloudViewer::t::geometry::kernel::TArrayIndexer::ElementByteSize
CLOUDVIEWER_HOST_DEVICE index_t ElementByteSize()
Definition: GeometryIndexer.h:227
cloudViewer::t::geometry::kernel::TransformIndexer::Rotate
CLOUDVIEWER_HOST_DEVICE void Rotate(float x_in, float y_in, float z_in, float *x_out, float *y_out, float *z_out) const
Transform a 3D coordinate in camera coordinate to world coordinate.
Definition: GeometryIndexer.h:82
cloudViewer::t::geometry::kernel::TArrayIndexer::InBoundary
CLOUDVIEWER_HOST_DEVICE bool InBoundary(float x, float y) const
Definition: GeometryIndexer.h:295
cloudViewer::geometry::Image::FilterType::Gaussian5
@ Gaussian5
Gaussian filter of size 5 x 5.
cloudViewer::t::geometry::npp::Resize
void Resize(const cloudViewer::core::Tensor &src_im, cloudViewer::core::Tensor &dst_im, t::geometry::Image::InterpType interp_type)
Definition: NPPImage.cpp:97
cloudViewer::geometry::Image::FlipVertical
std::shared_ptr< Image > FlipVertical() const
Function to flip image vertically (upside down).
Definition: Image.cpp:293
cloudViewer::core::SizeVector::ToString
std::string ToString() const
Definition: SizeVector.cpp:132
cloudViewer::t::geometry::kernel::image::CreateNormalMap
void CreateNormalMap(const core::Tensor &src, core::Tensor &dst, float invalid_fill)
Definition: Image.cpp:79
cloudViewer::core::Int32
const Dtype Int32
Definition: Dtype.cpp:46
cloudViewer::t::geometry::Image::AsTensor
core::Tensor AsTensor() const
Returns the underlying Tensor of the Image.
Definition: Image.h:124
cloudViewer::geometry::Image::height_
int height_
Height of the image.
Definition: Image.h:221
cloudViewer::t::geometry::kernel::voxel_grid::index_t
int index_t
Definition: VoxelBlockGrid.h:23
cloudViewer::t::geometry::Image::PyrDown
Image PyrDown() const
Return a new downsampled image with pyramid downsampling.
Definition: Image.cpp:395
cloudViewer::t::geometry::Image::InterpType
InterpType
Image interpolation algorithms.
Definition: Image.h:178
cloudViewer::t::geometry::Geometry::GeometryType
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:28
cloudViewer::t::geometry::Image::FilterSobel
std::pair< Image, Image > FilterSobel(int kernel_size=3) const
Return a pair of new gradient images (dx, dy) after Sobel filtering.
Definition: Image.cpp:345
Timer.h
cloudViewer::t::geometry::Image::FromLegacy
static Image FromLegacy(const cloudViewer::geometry::Image &image_legacy, const core::Device &Device=core::Device("CPU:0"))
Create from a legacy CloudViewer Image.
Definition: Image.cpp:505
cloudViewer::core::Device
Definition: Device.h:18
cloudViewer::t::geometry::kernel::image::ClipTransformCPU
void ClipTransformCPU(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value, float clip_fill=0.0f)
Definition: ImageImpl.h:90
cloudViewer::t::geometry::kernel::image::To
void To(const core::Tensor &src, core::Tensor &dst, double scale, double offset)
Definition: Image.cpp:17
TensorCheck.h
cloudViewer::t::geometry::npp::Dilate
void Dilate(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size)
Definition: NPPImage.cpp:178
cloudViewer::geometry::Image::Clear
Image & Clear()
Definition: Image.cpp:30
cloudViewer::core::UInt8
const Dtype UInt8
Definition: Dtype.cpp:48
cloudViewer::geometry::Image::data_
std::vector< uint8_t > data_
Image storage buffer.
Definition: Image.h:227
cloudViewer::core::Bool
const Dtype Bool
Definition: Dtype.cpp:52
cloudViewer::t::geometry::kernel::TArrayIndexer::GetDataPtr
CLOUDVIEWER_HOST_DEVICE T * GetDataPtr(index_t x) const
Definition: GeometryIndexer.h:321
cloudViewer::t::geometry::npp::RGBToGray
void RGBToGray(const core::Tensor &src_im, core::Tensor &dst_im)
Definition: NPPImage.cpp:63
cloudViewer::geometry::Image::num_of_channels_
int num_of_channels_
Number of chanels in the image.
Definition: Image.h:223
cloudViewer::core::Float64
const Dtype Float64
Definition: Dtype.cpp:43
cloudViewer::t::geometry::kernel::TArrayIndexer::GetShape
CLOUDVIEWER_HOST_DEVICE index_t GetShape(int i) const
Definition: GeometryIndexer.h:314
cloudViewer::utility::floor
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
cloudViewer::core::Tensor::GetDevice
Device GetDevice() const override
Definition: Tensor.cpp:1435
cloudViewer::t::geometry::Image::ToLegacy
cloudViewer::geometry::Image ToLegacy() const
Convert to legacy Image type.
Definition: Image.cpp:534
image
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:184
cloudViewer::t::geometry::Image::ToString
std::string ToString() const
Text description.
Definition: Image.cpp:555
cloudViewer::t::geometry::Image::GetCols
int64_t GetCols() const
Get the number of columns of the image.
Definition: Image.h:87
cloudViewer::t::geometry::ipp::Filter
void Filter(const core::Tensor &src_im, core::Tensor &dst_im, const core::Tensor &kernel)
Definition: IPPImage.cpp:170
cloudViewer::t::geometry::kernel::TArrayIndexer::WorkloadToCoord
CLOUDVIEWER_HOST_DEVICE void WorkloadToCoord(index_t workload, index_t *x_out, index_t *y_out, index_t *z_out, index_t *t_out) const
Workload => 4D coordinate.
Definition: GeometryIndexer.h:282
cloudViewer::geometry::Image::width_
int width_
Width of the image.
Definition: Image.h:219
cloudViewer::core::Float32
const Dtype Float32
Definition: Dtype.cpp:42
cloudViewer::t::geometry::npp::FilterSobel
void FilterSobel(const core::Tensor &src_im, core::Tensor &dst_im_dx, core::Tensor &dst_im_dy, int kernel_size)
Definition: NPPImage.cpp:406
cloudViewer::core::SizeVector
Definition: SizeVector.h:70
cloudViewer::geometry::Image::Transpose
std::shared_ptr< Image > Transpose() const
Definition: Image.cpp:262
cloudViewer::t::geometry::Image::Dilate
Image Dilate(int kernel_size=3) const
Return a new image after performing morphological dilation.
Definition: Image.cpp:203
cloudViewer::t::geometry::Image::PyrDownDepth
Image PyrDownDepth(float diff_threshold, float invalid_fill=0.f) const
Edge and invalid value preserving downsampling by 2 specifically for depth images.
Definition: Image.cpp:400
cloudViewer::t::geometry::kernel::TArrayIndexer::GetDataPtr
CLOUDVIEWER_HOST_DEVICE T * GetDataPtr(index_t x, index_t y) const
Definition: GeometryIndexer.h:327
cloudViewer::geometry::Image::FloatValueAt
std::pair< bool, double > FloatValueAt(double u, double v) const
Definition: Image.cpp:58
cloudViewer::geometry::Image::FilterType::Sobel3Dx
@ Sobel3Dx
Sobel filter along X-axis.
cloudViewer::geometry::Image::CreateDepthBoundaryMask
std::shared_ptr< Image > CreateDepthBoundaryMask(double depth_threshold_for_discontinuity_check=0.1, int half_dilation_kernel_size_for_discontinuity_map=3) const
Function to create a depthmap boundary mask from depth image.
Definition: Image.cpp:374
cloudViewer::utility::optional
Definition: Optional.h:44
LogError
#define LogError(...)
Definition: Logging.h:60
cloudViewer::t::geometry::Image::HAVE_IPP
static constexpr bool HAVE_IPP
Do we use IPP for accelerating image processing operations?
Definition: Image.h:339
cloudViewer::geometry::Image::PointerAt
T * PointerAt(int u, int v) const
Function to access the raw data of a single-channel Image.
Definition: Image.cpp:77
cloudViewer::t::geometry::Image::FilterBilateral
Image FilterBilateral(int kernel_size=3, float value_sigma=20.0f, float distance_sigma=10.0f) const
Return a new image after bilateral filtering.
Definition: Image.cpp:239
cloudViewer::core::IsDevice::IsCPU
bool IsCPU() const
Definition: Device.h:95
cloudViewer::t::geometry::kernel::image::ColorizeDepthCPU
void ColorizeDepthCPU(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value)
Definition: ImageImpl.h:311
cloudViewer::t::geometry::kernel::TArrayIndexer::TArrayIndexer
TArrayIndexer(const core::SizeVector &shape)
Only used for simple shapes.
Definition: GeometryIndexer.h:204
cloudViewer::geometry::Image::bytes_per_channel_
int bytes_per_channel_
Number of bytes per channel.
Definition: Image.h:225
cloudViewer::geometry::Image::ConvertDepthToFloatImage
std::shared_ptr< Image > ConvertDepthToFloatImage(double depth_scale=1000.0, double depth_trunc=3.0) const
Definition: Image.cpp:97
cloudViewer::core::Device::IsCPU
bool IsCPU() const
Returns true iff device type is CPU.
Definition: Device.h:46
cloudViewer::t::geometry::kernel::TransformIndexer
Helper class for converting coordinates/indices between 3D/3D, 3D/2D, 2D/3D.
Definition: GeometryIndexer.h:26
count
int count
Definition: FileIOFactory.cpp:132
ccHObject::GetAxisAlignedBoundingBox
virtual ccBBox GetAxisAlignedBoundingBox() const
Returns an axis-aligned bounding box of the geometry.
Definition: ecvHObject.cpp:447
AssertTensorDtype
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:21
cloudViewer::t::geometry::npp::FilterGaussian
void FilterGaussian(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float sigma)
Definition: NPPImage.cpp:378
cloudViewer::t::geometry::kernel::TransformIndexer::GetCameraPosition
CLOUDVIEWER_HOST_DEVICE void GetCameraPosition(float *x, float *y, float *z) const
Definition: GeometryIndexer.h:128
cloudViewer::core::Tensor::Empty
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:400
cloudViewer::geometry::Image::FlipHorizontal
std::shared_ptr< Image > FlipHorizontal() const
Function to flip image horizontally (from left to right).
Definition: Image.cpp:310
cloudViewer::t::geometry::Image::data_
core::Tensor data_
Definition: Image.h:346
Image.h
Image.h
Tensor.h
cloudViewer::geometry::Image::ClipIntensity
Image & ClipIntensity(double min=0.0, double max=1.0)
Definition: Image.cpp:112
ccHObject
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
LogWarning
#define LogWarning(...)
Definition: Logging.h:72
cloudViewer::geometry::Image::Filter
std::shared_ptr< Image > Filter(Image::FilterType type) const
Function to filter image with pre-defined filtering type.
Definition: Image.cpp:209
cloudViewer::t::geometry::kernel::image::ToCPU
void ToCPU(const core::Tensor &src, core::Tensor &dst, double scale, double offset)
Definition: ImageImpl.h:33
cloudViewer::t::geometry::kernel::TArrayIndexer::GetDataPtr
CLOUDVIEWER_HOST_DEVICE T * GetDataPtr(index_t x, index_t y, index_t z, index_t t) const
Definition: GeometryIndexer.h:345
cloudViewer::geometry::Image::FilterHorizontal
std::shared_ptr< Image > FilterHorizontal(const std::vector< double > &kernel) const
Definition: Image.cpp:170
cloudViewer::t::geometry::Image::GetChannels
int64_t GetChannels() const
Get the number of channels of the image.
Definition: Image.h:90
cloudViewer::t::geometry::kernel::TransformIndexer::Unproject
CLOUDVIEWER_HOST_DEVICE void Unproject(float u_in, float v_in, float d_in, float *x_out, float *y_out, float *z_out) const
Unproject a 2D uv coordinate with depth to 3D in camera coordinate.
Definition: GeometryIndexer.h:112
cloudViewer::t::geometry::ipp::Dilate
void Dilate(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size)
Definition: IPPImage.cpp:133
z
normal_z z
Definition: my_point_types.h:165
cloudViewer::geometry::Image::TestImageBoundary
bool TestImageBoundary(double u, double v, double inner_margin=0.0) const
Test if coordinate (u, v) is located in the inner_marge of the image.
Definition: Image.cpp:51
cloudViewer::geometry::Image::getOwnBB
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
Definition: Image.cpp:47
CLOUDVIEWER_HOST_DEVICE
#define CLOUDVIEWER_HOST_DEVICE
Definition: CUDAUtils.h:44
AssertTensorShape
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:61
cloudViewer::t::geometry::ipp::FilterBilateral
void FilterBilateral(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float value_sigma, float distance_sigma)
Definition: IPPImage.cpp:202
cloudViewer::t::geometry::Image::FilterGaussian
Image FilterGaussian(int kernel_size=3, float sigma=1.0f) const
Return a new image after Gaussian filtering.
Definition: Image.cpp:309
cloudViewer::core::MemoryManager::MemcpyToHost
static void MemcpyToHost(void *host_ptr, const void *src_ptr, const Device &src_device, size_t num_bytes)
Same as Memcpy, but with host (CPU:0) as default dst_device.
Definition: MemoryManager.cpp:86
cloudViewer::core::MemoryManager::MemcpyFromHost
static void MemcpyFromHost(void *dst_ptr, const Device &dst_device, const void *host_ptr, size_t num_bytes)
Same as Memcpy, but with host (CPU:0) as default src_device.
Definition: MemoryManager.cpp:78
cloudViewer::geometry::Image::CreateFloatImage
std::shared_ptr< Image > CreateFloatImage(Image::ColorToIntensityConversionType type=Image::ColorToIntensityConversionType::Weighted) const
Return a gray scaled float type image.
Definition: ImageFactory.cpp:47
AssertTensorDtypes
#define AssertTensorDtypes(tensor,...)
Definition: TensorCheck.h:33
cloudViewer::geometry::Image::IsEmpty
virtual bool IsEmpty() const override
Definition: Image.h:87
type
char type
Definition: FileIOFactory.cpp:131
Dtype.h
cloudViewer::core::Tensor::To
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:739
cloudViewer::t::geometry::Geometry
The base geometry class.
Definition: Geometry.h:23
cloudViewer::geometry::Image
The Image class stores image with customizable width, height, num of channels and bytes per channel.
Definition: Image.h:33
cloudViewer::t::geometry::kernel::TArrayIndexer::InBoundary
CLOUDVIEWER_HOST_DEVICE bool InBoundary(float x, float y, float z) const
Definition: GeometryIndexer.h:299
cloudViewer::geometry::Image::LinearTransform
Image & LinearTransform(double scale=1.0, double offset=0.0)
Definition: Image.cpp:126
cloudViewer::core::Tensor::GetDataPtr
T * GetDataPtr()
Definition: Tensor.h:1144
cloudViewer::t::geometry::kernel::TArrayIndexer::CoordToWorkload
CLOUDVIEWER_HOST_DEVICE void CoordToWorkload(index_t x_in, index_t y_in, index_t z_in, index_t t_in, index_t *workload) const
4D coordinate => workload
Definition: GeometryIndexer.h:252
cloudViewer::t::geometry::kernel::image::PyrDownDepth
void PyrDownDepth(const core::Tensor &src, core::Tensor &dst, float diff_threshold, float invalid_fill)
Definition: Image.cpp:48
cloudViewer::geometry::Image::Prepare
Image & Prepare(int width, int height, int num_of_channels, int bytes_per_channel)
Prepare Image properties and allocate Image buffer.
Definition: Image.h:109