-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOFile.cpp
More file actions
136 lines (108 loc) · 3.72 KB
/
Copy pathIOFile.cpp
File metadata and controls
136 lines (108 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*************************************************************************
IOFile - description
-------------------
authors : CAO Alexandre, Laurent Francioli
copyright : Institut universitaire romand de Sante au Travail
University of Geneva (UniGe)
*************************************************************************/
//-------Class Implementation of <IOFile> (fichier IOFile.cpp) -------
//---------------------------------------------------------------- INCLUDE
//--------------------------------------------------------- System Include
//------------------------------------------------------------ Own Include
#include "IOFile.h"
#include <wrap/io_trimesh/import.h>
#include <wrap/io_trimesh/export.h>
#include <wrap/io_trimesh/import_ply.h>
#include <wrap/io_trimesh/import_stl.h>
#include <wrap/io_trimesh/import_obj.h>
#include <wrap/io_trimesh/import_off.h>
#include <wrap/io_trimesh/import_ptx.h>
#include <wrap/io_trimesh/import_vmi.h>
#include <wrap/io_trimesh/export_ply.h>
#include <wrap/io_trimesh/export_stl.h>
#include <wrap/io_trimesh/export_obj.h>
#include <wrap/io_trimesh/export_vrml.h>
#include <wrap/io_trimesh/export_dxf.h>
#include <wrap/io_trimesh/export_vmi.h>
#include <wrap/io_trimesh/export.h>
#include<iostream>
#include<fstream>
#include"strConv.h"
#include <string>
#include "OldAPISupport.h"
//-------------------------------------------------------------- Constants
//----------------------------------------------------------------- PUBLIC
//--------------------------------------------------------- Public Methods
MeshModel* IOFile::loadFromFile(const char* fileName, MeshDocument *doc)
{
MeshModel *res = OldApi::CreateMeshModel(doc);
int mask;
// vcg::tri::io::ImporterPLY<CMeshO>::LoadMask(fileName,mask);
// res->Enable(mask);
// vcg::tri::io::ImporterPLY<CMeshO>::Open(res->cm, fileName, mask);
return res;
}
void IOFile::saveToFile(const char* fileName, MeshModel* mesh, int mask )
{
// vcg::tri::io::Exporter<CMeshO>::Save(mesh->cm, fileName, mask);
}
vector<float>* IOFile::loadIntensityMap(const char* fileName)
{
vector<float>* result = new vector<float>;
float value;
std::ifstream file(fileName);
if ( file.is_open() )
{
while ( file.good() )
{
std::string buffer;
getline( file, buffer );
if ( buffer.length()!=0 )
{
strConv::from_string(buffer, value);
result->push_back(value);
}
}
}
else
{
std::cout << "Error. Cannot open map file or file doesn t exist." << std::endl << std::endl;
}
file.close();
return result;
}
void IOFile::saveIntensityMap(const char* fileName, vector<float>* intensityMap)
{
std::ofstream file(fileName, std::fstream::out|std::fstream::trunc);
if ( file.is_open() )
{
vector<float>::iterator iter;
for(iter=intensityMap->begin(); iter!=intensityMap->end(); iter++)
{
std::string buffer = strConv::to_string( *iter );
file << buffer << std::endl;
}
}
else
{
std::cout << "Error. Cannot open map file." << std::endl << std::endl;
}
file.close();
}
//--------------------------------------------------- Operator Overloading
//---------------------------------------------- Constructors - destructor
// NEVER USED !!!
IOFile::IOFile ( )
{
#ifdef MAP
cout << "Call to the constructor of <IOFile>" << endl;
#endif
} //----- End of IOFile
IOFile::~IOFile ( )
{
#ifdef MAP
cout << "Call to the destructor of <IOFile>" << endl;
#endif
} //----- End of ~IOFile
//---------------------------------------------------------------- PRIVATE
//------------------------------------------------------ Protected Methods