MRPT  2.0.4
PLY_import_export.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/img/TColor.h>
12 #include <mrpt/math/TPoint3D.h>
13 #include <string>
14 #include <vector>
15 
16 namespace mrpt::opengl
17 {
18 /** A virtual base class that implements the capability of importing 3D point
19  * clouds and faces from a file in the Stanford PLY format.
20  * \sa https://www.mrpt.org/Support_for_the_Stanford_3D_models_file_format_PLY
21  * \sa PLY_Exporter
22  * \ingroup mrpt_opengl_grp
23  */
25 {
26  public:
27  /** Loads from a PLY file.
28  * \param[in] filename The filename to open. It can be either in binary or
29  * text format.
30  * \param[out] file_comments If provided (!=nullptr) the list of comment
31  * strings stored in the file will be returned.
32  * \param[out] file_obj_info If provided (!=nullptr) the list of "object
33  * info" strings stored in the file will be returned.
34  * \return false on any error in the file format or reading it. To obtain
35  * more details on the error you can call getLoadPLYErrorString()
36  */
37  bool loadFromPlyFile(
38  const std::string& filename,
39  std::vector<std::string>* file_comments = nullptr,
40  std::vector<std::string>* file_obj_info = nullptr);
41 
42  /** Return a description of the error if loadFromPlyFile() returned false,
43  * or an empty string if the file was loaded without problems. */
44  std::string getLoadPLYErrorString() const
45  {
47  }
48 
49  protected:
50  /** @name PLY Import virtual methods to implement in base classes
51  @{ */
52 
53  /** In a base class, reserve memory to prepare subsequent calls to
54  * PLY_import_set_vertex */
55  virtual void PLY_import_set_vertex_count(const size_t N) = 0;
56 
57  /** In a base class, reserve memory to prepare subsequent calls to
58  * PLY_import_set_face */
59  virtual void PLY_import_set_face_count(const size_t N) = 0;
60 
61  /** In a base class, will be called after PLY_import_set_vertex_count() once
62  * for each loaded point.
63  * \param pt_color Will be nullptr if the loaded file does not provide
64  * color info.
65  */
66  virtual void PLY_import_set_vertex(
67  const size_t idx, const mrpt::math::TPoint3Df& pt,
68  const mrpt::img::TColorf* pt_color = nullptr) = 0;
69 
70  /** @} */
71 
72  private:
74 
75 }; // End of class def.
76 
77 /** A virtual base class that implements the capability of exporting 3D point
78  * clouds and faces to a file in the Stanford PLY format.
79  * \sa https://www.mrpt.org/Support_for_the_Stanford_3D_models_file_format_PLY
80  * \sa PLY_Importer
81  * \ingroup mrpt_base_grp
82  */
84 {
85  public:
86  /** Saves to a PLY file.
87  * \param[in] filename The filename to be saved.
88  * \param[in] file_comments If provided (!=nullptr) the list of comment
89  * strings stored in the file will be returned.
90  * \param[in] file_obj_info If provided (!=nullptr) the list of "object
91  * info" strings stored in the file will be returned.
92  * \return false on any error writing the file. To obtain more details on
93  * the error you can call getSavePLYErrorString()
94  */
95  bool saveToPlyFile(
96  const std::string& filename, bool save_in_binary = false,
97  const std::vector<std::string>& file_comments =
98  std::vector<std::string>(),
99  const std::vector<std::string>& file_obj_info =
100  std::vector<std::string>()) const;
101 
102  /** Return a description of the error if loadFromPlyFile() returned false,
103  * or an empty string if the file was loaded without problems. */
104  std::string getSavePLYErrorString() const
105  {
107  }
108 
109  protected:
110  /** @name PLY Export virtual methods to implement in base classes
111  @{ */
112 
113  /** In a base class, return the number of vertices */
114  virtual size_t PLY_export_get_vertex_count() const = 0;
115 
116  /** In a base class, return the number of faces */
117  virtual size_t PLY_export_get_face_count() const = 0;
118 
119  /** In a base class, will be called after PLY_export_get_vertex_count() once
120  * for each exported point.
121  * \param pt_color Will be nullptr if the loaded file does not provide
122  * color info.
123  */
124  virtual void PLY_export_get_vertex(
125  const size_t idx, mrpt::math::TPoint3Df& pt, bool& pt_has_color,
126  mrpt::img::TColorf& pt_color) const = 0;
127 
128  /** @} */
129 
130  private:
131  mutable std::string m_ply_export_last_error;
132 
133 }; // End of class def.
134 
135 } // namespace mrpt::opengl
virtual void PLY_import_set_vertex_count(const size_t N)=0
In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex.
bool loadFromPlyFile(const std::string &filename, std::vector< std::string > *file_comments=nullptr, std::vector< std::string > *file_obj_info=nullptr)
Loads from a PLY file.
virtual size_t PLY_export_get_face_count() const =0
In a base class, return the number of faces.
std::string getSavePLYErrorString() const
Return a description of the error if loadFromPlyFile() returned false, or an empty string if the file...
virtual void PLY_export_get_vertex(const size_t idx, mrpt::math::TPoint3Df &pt, bool &pt_has_color, mrpt::img::TColorf &pt_color) const =0
In a base class, will be called after PLY_export_get_vertex_count() once for each exported point...
std::string getLoadPLYErrorString() const
Return a description of the error if loadFromPlyFile() returned false, or an empty string if the file...
A virtual base class that implements the capability of exporting 3D point clouds and faces to a file ...
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
virtual void PLY_import_set_face_count(const size_t N)=0
In a base class, reserve memory to prepare subsequent calls to PLY_import_set_face.
virtual void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::img::TColorf *pt_color=nullptr)=0
In a base class, will be called after PLY_import_set_vertex_count() once for each loaded point...
A virtual base class that implements the capability of importing 3D point clouds and faces from a fil...
virtual size_t PLY_export_get_vertex_count() const =0
In a base class, return the number of vertices.
bool saveToPlyFile(const std::string &filename, bool save_in_binary=false, const std::vector< std::string > &file_comments=std::vector< std::string >(), const std::vector< std::string > &file_obj_info=std::vector< std::string >()) const
Saves to a PLY file.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020