Zivid C++ API 2.16.0+46cdaba6-1
PointCloudExport.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of the Zivid API
3 *
4 * Copyright 2015-2025 (C) Zivid AS
5 * All rights reserved.
6 *
7 * Zivid Software License, v1.0
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of Zivid AS nor the names of its contributors may be used
20 * to endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * 4. This software, with or without modification, must not be used with any
24 * other 3D camera than from Zivid AS.
25 *
26 * 5. Any software provided in binary form under this license must not be
27 * reverse engineered, decompiled, modified and/or disassembled.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
41 * Info: http://www.zivid.com
42 ******************************************************************************/
43
44#pragma once
45
47
48#include <filesystem>
49#include <optional>
50#include <string>
51
52namespace Zivid
53{
54 class Frame;
55 class UnorganizedPointCloud;
56
57 namespace Experimental::PointCloudExport
58 {
63 enum class ColorSpace
64 {
65 sRGB,
67 };
68
73 enum class IncludeNormals
74 {
75 no,
76 yes,
77 };
78
79 namespace FileFormat
80 {
85 class ZDF
86 {
87 public:
88 static constexpr const char *description{ "Zivid Data File" };
89 static constexpr const char *defaultExtension{ ".zdf" };
90 static constexpr bool canLoad{ true };
91
94 ZIVID_CORE_EXPORT explicit ZDF(const std::string &fileName);
95
97 ZIVID_CORE_EXPORT const std::filesystem::path &fileName() const;
98
100 ZIVID_CORE_EXPORT std::string toString() const;
101
102 private:
103 std::filesystem::path m_fileName;
104 };
105
111 class PLY
112 {
113 public:
114 static constexpr const char *description{ "PLY File" };
115 static constexpr const char *defaultExtension{ ".ply" };
116 static constexpr bool canLoad{ false };
117
119 enum class Layout
120 {
121 ordered,
123 };
124
130 ZIVID_CORE_EXPORT explicit PLY(const std::string &fileName);
131
140
148
150 ZIVID_CORE_EXPORT const std::filesystem::path &fileName() const;
151
154
157
160
162 ZIVID_CORE_EXPORT std::string toString() const;
163
164 private:
165 std::filesystem::path m_fileName;
166 Layout m_layout = Layout::ordered;
167 ColorSpace m_colorSpace = ColorSpace::sRGB;
168 IncludeNormals m_includeNormals = IncludeNormals::no;
169 };
170
176 class XYZ
177 {
178 public:
179 static constexpr const char *description{ "ASCII Points File" };
180 static constexpr const char *defaultExtension{ ".xyz" };
181 static constexpr bool canLoad{ false };
182
188 ZIVID_CORE_EXPORT explicit XYZ(const std::string &fileName);
189
194
196 ZIVID_CORE_EXPORT const std::filesystem::path &fileName() const;
197
200
202 ZIVID_CORE_EXPORT std::string toString() const;
203
204 private:
205 std::filesystem::path m_fileName;
206 ColorSpace m_colorSpace = ColorSpace::sRGB;
207 };
208
215 class PCD
216 {
217 public:
218 static constexpr const char *description{ "Point Cloud Data File" };
219 static constexpr const char *defaultExtension{ ".pcd" };
220 static constexpr bool canLoad{ false };
221
229 enum class Layout
230 {
231 organized,
233 };
234
240 ZIVID_CORE_EXPORT explicit PCD(const std::string &fileName);
241
249
256
264
266 ZIVID_CORE_EXPORT const std::filesystem::path &fileName() const;
267
275 ZIVID_CORE_EXPORT std::optional<Layout> layout() const;
276
279
282
284 ZIVID_CORE_EXPORT std::string toString() const;
285
286 private:
287 std::filesystem::path m_fileName;
288 ColorSpace m_colorSpace = ColorSpace::sRGB;
289 IncludeNormals m_includeNormals = IncludeNormals::no;
290 std::optional<Layout> m_layout{};
291 };
292
293 using FrameFileFormats = std::tuple<ZDF, PLY, XYZ, PCD>;
294 } // namespace FileFormat
295
302 ZIVID_CORE_EXPORT void exportFrame(const Zivid::Frame &frame, const FileFormat::ZDF &specification);
303
311 ZIVID_CORE_EXPORT void exportFrame(const Zivid::Frame &frame, const FileFormat::PLY &specification);
312
321 ZIVID_CORE_EXPORT void exportFrame(const Zivid::Frame &frame, const FileFormat::XYZ &specification);
322
334 ZIVID_CORE_EXPORT void exportFrame(const Zivid::Frame &frame, const FileFormat::PCD &specification);
335
346 const Zivid::UnorganizedPointCloud &pointCloud,
347 const FileFormat::PLY &specification);
348
358 const Zivid::UnorganizedPointCloud &pointCloud,
359 const FileFormat::XYZ &specification);
360
371 const Zivid::UnorganizedPointCloud &pointCloud,
372 const FileFormat::PCD &specification);
373
374 } // namespace Experimental::PointCloudExport
375} // namespace Zivid
#define ZIVID_CORE_EXPORT
Definition CoreExport.h:56
Specification for saving frame in PCD (*.pcd) format.
Definition PointCloudExport.h:216
static constexpr const char * description
Definition PointCloudExport.h:218
Layout
Layout for saving point cloud.
Definition PointCloudExport.h:230
ZIVID_CORE_EXPORT const std::filesystem::path & fileName() const
Get the file name.
static constexpr bool canLoad
Definition PointCloudExport.h:220
ZIVID_CORE_EXPORT PCD(const std::string &fileName, ColorSpace colorSpace, IncludeNormals includeNormals)
Create PCD specification with file name, color space and normals.
ZIVID_CORE_EXPORT std::string toString() const
Get string representation of PCD specification.
ZIVID_CORE_EXPORT PCD(const std::string &fileName, ColorSpace colorSpace, IncludeNormals includeNormals, Layout layout)
Create PCD specification with file name, color space, normals and layout.
ZIVID_CORE_EXPORT PCD(const std::string &fileName)
Create PCD specification with file name.
ZIVID_CORE_EXPORT std::optional< Layout > layout() const
Get the layout of PCD specification.
ZIVID_CORE_EXPORT PCD(const std::string &fileName, ColorSpace colorSpace)
Create PCD specification with file name and color space.
ZIVID_CORE_EXPORT IncludeNormals includeNormals() const
Get if normals are included in PCD specification.
ZIVID_CORE_EXPORT ColorSpace colorSpace() const
Get the color space of PCD specification.
static constexpr const char * defaultExtension
Definition PointCloudExport.h:219
Specification for saving frame in PLY (*.ply) format.
Definition PointCloudExport.h:112
ZIVID_CORE_EXPORT PLY(const std::string &fileName, Layout layout, ColorSpace colorSpace)
Create PLY specification with file name, layout, and color space.
ZIVID_CORE_EXPORT PLY(const std::string &fileName)
Create PLY specification with file name.
ZIVID_CORE_EXPORT const std::filesystem::path & fileName() const
Get the file name.
static constexpr const char * defaultExtension
Definition PointCloudExport.h:115
static constexpr bool canLoad
Definition PointCloudExport.h:116
ZIVID_CORE_EXPORT IncludeNormals includeNormals() const
Get if normals are included in PLY specification.
ZIVID_CORE_EXPORT ColorSpace colorSpace() const
Get the color space of PLY specification.
Layout
Layout for saving point cloud.
Definition PointCloudExport.h:120
ZIVID_CORE_EXPORT std::string toString() const
Get string representation of PLY specification.
ZIVID_CORE_EXPORT Layout layout() const
Get the layout of PLY specification.
ZIVID_CORE_EXPORT PLY(const std::string &fileName, Layout layout, ColorSpace colorSpace, IncludeNormals includeNormals)
Create PLY specification with file name, layout, color space and normals.
static constexpr const char * description
Definition PointCloudExport.h:114
Specification for saving frame in ASCII (*.xyz) format.
Definition PointCloudExport.h:177
static constexpr const char * description
Definition PointCloudExport.h:179
ZIVID_CORE_EXPORT const std::filesystem::path & fileName() const
Get the file name.
static constexpr bool canLoad
Definition PointCloudExport.h:181
ZIVID_CORE_EXPORT XYZ(const std::string &fileName, ColorSpace colorSpace)
Create XYZ specification with file name and color space.
static constexpr const char * defaultExtension
Definition PointCloudExport.h:180
ZIVID_CORE_EXPORT XYZ(const std::string &fileName)
Create XYZ specification with file name.
ZIVID_CORE_EXPORT std::string toString() const
Get string representation of XYZ specification.
ZIVID_CORE_EXPORT ColorSpace colorSpace() const
Get the color space of XYZ specification.
Specification for saving frame in ZDF (*.zdf) format.
Definition PointCloudExport.h:86
ZIVID_CORE_EXPORT std::string toString() const
Get string representation of ZDF specification.
static constexpr bool canLoad
Definition PointCloudExport.h:90
static constexpr const char * description
Definition PointCloudExport.h:88
static constexpr const char * defaultExtension
Definition PointCloudExport.h:89
ZIVID_CORE_EXPORT const std::filesystem::path & fileName() const
Get the file name.
ZIVID_CORE_EXPORT ZDF(const std::string &fileName)
Create ZDF specification with file name.
A frame captured by a Zivid camera.
Definition Frame.h:69
Point cloud with x, y, z, RGB color and SNR laid out as a linear list of only valid points.
Definition UnorganizedPointCloud.h:72
std::tuple< ZDF, PLY, XYZ, PCD > FrameFileFormats
Definition PointCloudExport.h:293
ColorSpace
Color space to use when saving frame.
Definition PointCloudExport.h:64
ZIVID_CORE_EXPORT void exportUnorganizedPointCloud(const Zivid::UnorganizedPointCloud &pointCloud, const FileFormat::PLY &specification)
Save unorganized pointcloud to PLY file.
ZIVID_CORE_EXPORT void exportFrame(const Zivid::Frame &frame, const FileFormat::ZDF &specification)
Save frame to ZDF file.
IncludeNormals
Include normals in the exported file.
Definition PointCloudExport.h:74
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:84