Jetson Inference
DNN Vision Library
cudaPointCloud.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __CUDA_POINT_CLOUD_H__
24 #define __CUDA_POINT_CLOUD_H__
25 
26 
27 #include "cudaUtility.h"
28 
29 
30 // forward declarations
31 class glBuffer;
32 class glCamera;
33 
34 
40 {
41 public:
45  struct Vertex
46  {
50  float3 pos;
51 
56  uchar3 color;
57 
62  uint8_t classID;
63 
64  } __attribute__((packed));
65 
69  static cudaPointCloud* Create();
70 
75 
83  bool Reserve( uint32_t maxPoints );
84 
88  void Free();
89 
93  void Clear();
94 
98  bool Extract( float* depth, float4* rgba, uint32_t width, uint32_t height );
99 
103  bool Extract( float* depth, uint32_t depth_width, uint32_t depth_height,
104  float4* rgba, uint32_t color_width, uint32_t color_height );
105 
109  inline uint32_t GetNumPoints() const { return mNumPoints; }
110 
114  inline uint32_t GetMaxPoints() const { return mMaxPoints; }
115 
119  inline size_t GetSize() const { return mNumPoints * sizeof(Vertex); }
120 
124  inline size_t GetMaxSize() const { return mMaxPoints * sizeof(Vertex); }
125 
129  inline Vertex* GetData() const { return mPointsCPU; }
130 
134  inline Vertex* GetData( size_t index ) const { return mPointsCPU + index; }
135 
139  inline bool HasRGB() const { return mHasRGB; }
140 
144  bool Render();
145 
149  bool Save( const char* filename );
150 
154  bool SetCalibration( const char* filename );
155 
159  void SetCalibration( const float K[3][3] );
160 
164  void SetCalibration( const float2& focalLength, const float2& principalPoint );
165 
166 protected:
167  cudaPointCloud();
168 
169  bool allocBufferGL();
170  bool allocDepthResize( size_t size );
171 
174 
177 
178  uint32_t mNumPoints;
179  uint32_t mMaxPoints;
180 
181  float2 mFocalLength;
183 
184  float* mDepthResize;
185  size_t mDepthSize;
186 
187  bool mHasRGB;
190 };
191 
192 #endif
193 
cudaPointCloud::mHasNewPoints
bool mHasNewPoints
Definition: cudaPointCloud.h:188
cudaPointCloud::Vertex
Point vertex.
Definition: cudaPointCloud.h:45
cudaPointCloud::GetMaxSize
size_t GetMaxSize() const
Retrieve the maximum size in bytes of the point cloud.
Definition: cudaPointCloud.h:124
cudaPointCloud::Vertex::color
uchar3 color
The RGB color of the point.
Definition: cudaPointCloud.h:56
cudaPointCloud::mPointsGPU
Vertex * mPointsGPU
Definition: cudaPointCloud.h:173
cudaPointCloud::GetNumPoints
uint32_t GetNumPoints() const
Retrieve the number of points being used.
Definition: cudaPointCloud.h:109
cudaPointCloud::mNumPoints
uint32_t mNumPoints
Definition: cudaPointCloud.h:178
cudaUtility.h
cudaPointCloud::mMaxPoints
uint32_t mMaxPoints
Definition: cudaPointCloud.h:179
cudaPointCloud
CUDA-accelerated point cloud processing.
Definition: cudaPointCloud.h:39
cudaPointCloud::GetMaxPoints
uint32_t GetMaxPoints() const
Retrieve the max number of points in memory.
Definition: cudaPointCloud.h:114
cudaPointCloud::allocDepthResize
bool allocDepthResize(size_t size)
cudaPointCloud::Vertex::classID
uint8_t classID
The class ID of the point.
Definition: cudaPointCloud.h:62
cudaPointCloud::SetCalibration
bool SetCalibration(const char *filename)
Set the intrinsic camera calibration.
cudaPointCloud::Save
bool Save(const char *filename)
Save point cloud to PCD file.
cudaPointCloud::Create
static cudaPointCloud * Create()
Create.
cudaPointCloud::Render
bool Render()
Render the point cloud with OpenGL.
cudaPointCloud::mPointsCPU
Vertex * mPointsCPU
Definition: cudaPointCloud.h:172
cudaPointCloud::Clear
void Clear()
Clear the points, but keep the memory allocated.
cudaPointCloud::~cudaPointCloud
~cudaPointCloud()
Destructor.
cudaPointCloud::mDepthResize
float * mDepthResize
Definition: cudaPointCloud.h:184
cudaPointCloud::mHasRGB
bool mHasRGB
Definition: cudaPointCloud.h:187
cudaPointCloud::GetData
Vertex * GetData() const
Retrieve memory pointer to point cloud data.
Definition: cudaPointCloud.h:129
cudaPointCloud::GetData
Vertex * GetData(size_t index) const
Retrieve memory pointer to a specific point.
Definition: cudaPointCloud.h:134
glCamera
OpenGL perspective camera supporting Look-At, Yaw/Pitch/Roll, and Ortho modes.
Definition: glCamera.h:35
cudaPointCloud::Free
void Free()
Free the memory being used to store the point cloud.
cudaPointCloud::mPrincipalPoint
float2 mPrincipalPoint
Definition: cudaPointCloud.h:182
cudaPointCloud::cudaPointCloud
cudaPointCloud()
cudaPointCloud::mFocalLength
float2 mFocalLength
Definition: cudaPointCloud.h:181
cudaPointCloud::mCameraGL
glCamera * mCameraGL
Definition: cudaPointCloud.h:176
cudaPointCloud::mBufferGL
glBuffer * mBufferGL
Definition: cudaPointCloud.h:175
glBuffer
OpenGL buffer with CUDA interoperability.
Definition: glBuffer.h:114
cudaPointCloud::Vertex::pos
float3 pos
The XYZ position of the point.
Definition: cudaPointCloud.h:50
cudaPointCloud::mDepthSize
size_t mDepthSize
Definition: cudaPointCloud.h:185
cudaPointCloud::__attribute__
struct cudaPointCloud::Vertex __attribute__((packed))
cudaPointCloud::Reserve
bool Reserve(uint32_t maxPoints)
Allocate and reserve memory for the max number of points.
cudaPointCloud::allocBufferGL
bool allocBufferGL()
cudaPointCloud::HasRGB
bool HasRGB() const
Does the point cloud have RGB data?
Definition: cudaPointCloud.h:139
cudaPointCloud::Extract
bool Extract(float *depth, float4 *rgba, uint32_t width, uint32_t height)
Extract point cloud from depth map and optional RGBA image.
cudaPointCloud::GetSize
size_t GetSize() const
Retrieve the size in bytes currently being used.
Definition: cudaPointCloud.h:119
cudaPointCloud::mHasCalibration
bool mHasCalibration
Definition: cudaPointCloud.h:189