Loading [MathJax]/extensions/tex2jax.js
Radium Engine  1.5.27
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OFFFileManager.cpp
1#include <Core/Containers/AlignedStdVector.hpp>
2#include <Core/Containers/VectorArray.hpp>
3#include <Core/CoreMacros.hpp>
4#include <Core/Geometry/IndexedGeometry.hpp>
5#include <Core/Types.hpp>
6#include <Core/Utils/Attribs.hpp>
7#include <Eigen/Core>
8#include <IO/deprecated/OFFFileManager.hpp>
9#include <istream>
10#include <memory>
11#include <utility>
12#include <vector>
13
14namespace Ra {
15
16using namespace Core;
17
18namespace IO {
19
24
29
34 return "OFF";
35}
36
41 return "off";
42}
43
44bool OFFFileManager::importData( std::istream& file, Geometry::TriangleMesh& data ) {
46 file >> h;
47 if ( h != header() ) {
48 addLogErrorEntry( "HEADER IS NOT CORRECT." );
49 return false;
50 }
51 uint v_size;
52 uint f_size;
53 uint e_size;
54 file >> v_size >> f_size >> e_size;
55 data.clear();
56 Geometry::TriangleMesh::PointAttribHandle::Container vertices;
57 Geometry::TriangleMesh::IndexContainerType indices;
58 vertices.resize( v_size );
59 indices.resize( f_size );
60
61 // Vertices
62 for ( uint i = 0; i < v_size; ++i ) {
63 Vector3 v;
64 file >> v[0] >> v[1] >> v[2];
65 vertices[i] = v;
66 }
67
68 // Edge
69 for ( uint i = 0; i < e_size; ++i ) {
70 break;
71 }
72
73 // Triangle
74 for ( uint i = 0; i < f_size; ++i ) {
75 uint side;
76 Vector3ui f;
77 file >> side;
78 if ( side == 3 ) {
79 file >> f[0] >> f[1] >> f[2];
80 indices.push_back( f );
81 }
82 }
83
84 data.setVertices( std::move( vertices ) );
85 data.setIndices( std::move( indices ) );
86 return true;
87}
88
89bool OFFFileManager::exportData( std::ostream& file, const Geometry::TriangleMesh& data ) {
90 std::string content = "";
91 const uint v_size = data.vertices().size();
92 const uint f_size = data.getIndices().size();
93 const uint e_size = 0;
94
95 if ( v_size == 0 ) {
96 addLogErrorEntry( "NO VERTICES PRESENT." );
97 return false;
98 }
99
100 // Header
101 content += header() + "\n" + std::to_string( v_size ) + " " + std::to_string( f_size ) + " " +
102 std::to_string( e_size ) + "\n";
103
104 // Vertices
105 for ( const auto& v : data.vertices() ) {
106 content += std::to_string( v[0] ) + " " + std::to_string( v[1] ) + " " +
107 std::to_string( v[2] ) + "\n";
108 }
109
110 // Triangle
111 for ( const auto& f : data.getIndices() ) {
112 content += "3 " + std::to_string( f[0] ) + " " + std::to_string( f[1] ) + " " +
113 std::to_string( f[2] ) + "\n";
114 }
115
116 file << content;
117
118 return true;
119}
120
121} // namespace IO
122} // namespace Ra
void setVertices(PointAttribHandle::Container &&vertices)
Set vertices.
void setIndices(IndexContainerType &&indices)
void clear() override
Erases all data, making the AttribArrayGeometry empty.
std::string fileExtension() const override
INTERFACE.
~OFFFileManager() override
DESTRUCTOR.
std::string header() const
HEADER.
T move(T... args)
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4
T size(T... args)
T to_string(T... args)