Easy3D 2.5.3
point_cloud_io_vg.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_FILEIO_POINT_CLOUD_IO_VG_H
28#define EASY3D_FILEIO_POINT_CLOUD_IO_VG_H
29
30
31#include <string>
32#include <vector>
33
34#include <easy3d/core/types.h>
35
36
37namespace easy3d {
38
39 class PointCloud;
40
41 namespace io {
42
94 {
95 public:
96
105 static bool load_vg(const std::string& file_name, PointCloud* cloud);
114 static bool save_vg(const std::string& file_name, const PointCloud* cloud);
115
124 static bool load_bvg(const std::string& file_name, PointCloud* cloud);
133 static bool save_bvg(const std::string& file_name, const PointCloud* cloud);
134
135 private:
136
137 class VertexGroup : public std::vector<int>
138 {
139 public:
140 explicit VertexGroup(int type = UNKNOWN)
141 : primitive_type_(type)
142 , primitive_index_(-1)
143 , label_("unknown")
144 , color_(0.3f, 0.6f, 1.0f)
145 {
146 }
147 ~VertexGroup() = default;
148
149 enum PrimType { // keep the values the same as in RANSAC
150 PLANE = 0,
151 SPHERE = 1,
152 CYLINDER = 2,
153 CONE = 3,
154 TORUS = 4,
155 GENERAL = 5,
156 UNKNOWN = -1
157 };
158
159 // - "v:primitive_type" (one of PLANE, SPHERE, CYLINDER, CONE, TORUS, and UNKNOWN)
160 // - "v:primitive_index" (-1, 0, 1, 2...). -1 meaning a vertex does not belong to any primitive (thus its
161 // primitive_type must be UNKNOWN).
162 int primitive_type_;
163 int primitive_index_;
164
165 std::string label_;
166 vec3 color_;
167 std::vector<VertexGroup> children_;
168 };
169
170
171 static void read_ascii_group(std::istream& input, VertexGroup& g);
172 static void write_ascii_group(std::ostream& output, const VertexGroup& g);
173
174 static void read_binary_group(std::istream& input, VertexGroup& g);
175 static void write_binary_group(std::ostream& output, const VertexGroup& g);
176
177 static int num_group_parameters(int type);
178
179 static std::vector<float> get_group_parameters(const VertexGroup& g);
180 static void assign_group_parameters(VertexGroup& g, std::vector<float>& para);
181
182 static void collect_groups(const PointCloud* cloud, std::vector<VertexGroup>& groups);
183 };
184
185 } // namespace io
186
187} // namespace easy3d
188
189#endif // EASY3D_FILEIO_POINT_CLOUD_IO_VG_H
190
A data structure for point clouds.
Definition: point_cloud.h:45
Implementation of file input/output operations for vertex group (VG) format PointCloud.
Definition: point_cloud_io_vg.h:94
static bool save_bvg(const std::string &file_name, const PointCloud *cloud)
Saves a point_cloud to a binary file.
Definition: point_cloud_io_vg.cpp:475
static bool save_vg(const std::string &file_name, const PointCloud *cloud)
Saves a point_cloud to an ASCII file.
Definition: point_cloud_io_vg.cpp:85
static bool load_bvg(const std::string &file_name, PointCloud *cloud)
Reads a point cloud from a binary file.
Definition: point_cloud_io_vg.cpp:378
static bool load_vg(const std::string &file_name, PointCloud *cloud)
Reads a point cloud from an ASCII file.
Definition: point_cloud_io_vg.cpp:178
Definition: collider.cpp:182