Radium Engine  1.5.20
Loading...
Searching...
No Matches
OFFFileManager.cpp
1#include <IO/deprecated/OFFFileManager.hpp>
2
3namespace Ra {
4
5using namespace Core;
6
7namespace IO {
8
13
18
23 return "OFF";
24}
25
30 return "off";
31}
32
33bool OFFFileManager::importData( std::istream& file, Geometry::TriangleMesh& data ) {
35 file >> h;
36 if ( h != header() ) {
37 addLogErrorEntry( "HEADER IS NOT CORRECT." );
38 return false;
39 }
40 uint v_size;
41 uint f_size;
42 uint e_size;
43 file >> v_size >> f_size >> e_size;
44 data.clear();
45 Geometry::TriangleMesh::PointAttribHandle::Container vertices;
46 Geometry::TriangleMesh::IndexContainerType indices;
47 vertices.resize( v_size );
48 indices.resize( f_size );
49
50 // Vertices
51 for ( uint i = 0; i < v_size; ++i ) {
52 Vector3 v;
53 file >> v[0] >> v[1] >> v[2];
54 vertices[i] = v;
55 }
56
57 // Edge
58 for ( uint i = 0; i < e_size; ++i ) {
59 break;
60 }
61
62 // Triangle
63 for ( uint i = 0; i < f_size; ++i ) {
64 uint side;
65 Vector3ui f;
66 file >> side;
67 if ( side == 3 ) {
68 file >> f[0] >> f[1] >> f[2];
69 indices.push_back( f );
70 }
71 }
72
73 data.setVertices( std::move( vertices ) );
74 data.setIndices( std::move( indices ) );
75 return true;
76}
77
78bool OFFFileManager::exportData( std::ostream& file, const Geometry::TriangleMesh& data ) {
79 std::string content = "";
80 const uint v_size = data.vertices().size();
81 const uint f_size = data.getIndices().size();
82 const uint e_size = 0;
83
84 if ( v_size == 0 ) {
85 addLogErrorEntry( "NO VERTICES PRESENT." );
86 return false;
87 }
88
89 // Header
90 content += header() + "\n" + std::to_string( v_size ) + " " + std::to_string( f_size ) + " " +
91 std::to_string( e_size ) + "\n";
92
93 // Vertices
94 for ( const auto& v : data.vertices() ) {
95 content += std::to_string( v[0] ) + " " + std::to_string( v[1] ) + " " +
96 std::to_string( v[2] ) + "\n";
97 }
98
99 // Triangle
100 for ( const auto& f : data.getIndices() ) {
101 content += "3 " + std::to_string( f[0] ) + " " + std::to_string( f[1] ) + " " +
102 std::to_string( f[2] ) + "\n";
103 }
104
105 file << content;
106
107 return true;
108}
109
110} // namespace IO
111} // 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:3
T size(T... args)
T to_string(T... args)