blob: eb03bb7297becce303fcd4c02be11d6951c61ae5 (
plain)
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
|
/* This file is part of the Gudhi Library. The Gudhi library
* (Geometric Understanding in Higher Dimensions) is a generic C++
* library for computational topology.
*
* Author(s): Vincent Rouvreau
*
* Copyright (C) 2015 INRIA Saclay (France)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef POINTS_FVECS_READER_H_
#define POINTS_FVECS_READER_H_
namespace Gudhi {
template<typename Kernel, typename OutputIteratorPoints>
bool load_points_from_fvecs_file(const std::string &filename, OutputIteratorPoints points, int only_the_first_n_points = -1)
{
typedef typename Kernel::Point_d Point;
std::ifstream in(filename, std::ios::binary);
if (!in.is_open()) {
std::cerr << "Could not open '" << filename << "'" << std::endl;
return false;
}
Kernel k;
unsigned long pt_dim = 0;
in.read(reinterpret_cast<char*>(&pt_dim), 4);
std::vector<float> current_pt;
current_pt.reserve(pt_dim);
for (int c = 0; !in.fail() && c != only_the_first_n_points; ++c) {
for (int j = 0; j < pt_dim; ++j)
{
float coord = 0.f;
in.read(reinterpret_cast<char*>(&coord), 4);
current_pt.push_back(coord);
}
*points++ = Point(current_pt.begin(), current_pt.end());
current_pt.clear();
in.read(reinterpret_cast<char*>(&pt_dim), 4);
}
#ifdef DEBUG_TRACES
std::cerr << "'" << filename << "' loaded." << std::endl;
#endif
return true;
}
} // namespace Gudhi
#endif // POINTS_FVECS_READER_H_
|