ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
saving.h
Go to the documentation of this file.
1
/***********************************************************************
2
* Software License Agreement (BSD License)
3
*
4
* Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5
* Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* 2. Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE NNIndexGOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*************************************************************************/
28
29
#ifndef FLANN_SAVING_H_
30
#define FLANN_SAVING_H_
31
32
#include <cstring>
33
#include <vector>
34
#include <stdio.h>
35
36
#include "
FLANN/general.h
"
37
#include "
FLANN/util/serialization.h
"
38
39
40
#ifdef FLANN_SIGNATURE_
41
#undef FLANN_SIGNATURE_
42
#endif
43
#define FLANN_SIGNATURE_ "FLANN_INDEX_v1.1"
44
45
namespace
flann
46
{
47
51
struct
IndexHeader
52
{
53
IndexHeaderStruct
h
;
54
55
IndexHeader
()
56
{
57
memset(
h
.
signature
, 0,
sizeof
(
h
.
signature
));
58
strcpy(
h
.
signature
,
FLANN_SIGNATURE_
);
59
memset(
h
.
version
, 0,
sizeof
(
h
.
version
));
60
strcpy(
h
.
version
,
FLANN_VERSION_
);
61
62
h
.
compression
= 0;
63
h
.
first_block_size
= 0;
64
}
65
66
private
:
67
template
<
typename
Archive>
68
void
serialize(Archive& ar)
69
{
70
ar &
h
.
signature
;
71
ar &
h
.
version
;
72
ar &
h
.
data_type
;
73
ar &
h
.
index_type
;
74
ar &
h
.
rows
;
75
ar &
h
.
cols
;
76
ar &
h
.
compression
;
77
ar &
h
.
first_block_size
;
78
}
79
friend
struct
serialization::access
;
80
};
81
88
template
<
typename
Index>
89
void
save_header
(FILE* stream,
const
Index
& index)
90
{
91
IndexHeader
header;
92
header.
h
.
data_type
=
flann_datatype_value<typename Index::ElementType>::value
;
93
header.
h
.
index_type
= index.
getType
();
94
header.
h
.
rows
= index.
size
();
95
header.
h
.
cols
= index.
veclen
();
96
97
fwrite(&header,
sizeof
(header),1,stream);
98
}
99
100
106
inline
IndexHeader
load_header
(FILE* stream)
107
{
108
IndexHeader
header;
109
int
read_size = fread(&header,
sizeof
(header),1,stream);
110
111
if
(read_size != 1) {
112
throw
FLANNException
(
"Invalid index file, cannot read"
);
113
}
114
115
if
(strncmp(header.
h
.
signature
,
116
FLANN_SIGNATURE_
,
117
strlen(
FLANN_SIGNATURE_
) - strlen(
"v0.0"
)) != 0) {
118
throw
FLANNException
(
"Invalid index file, wrong signature"
);
119
}
120
121
return
header;
122
}
123
124
125
namespace
serialization
126
{
127
ENUM_SERIALIZER
(
flann_algorithm_t
);
128
ENUM_SERIALIZER
(
flann_centers_init_t
);
129
ENUM_SERIALIZER
(
flann_log_level_t
);
130
ENUM_SERIALIZER
(
flann_datatype_t
);
131
}
132
133
}
134
135
#endif
/* FLANN_SAVING_H_ */
flann::FLANNException
Definition:
general.h:43
flann::Index
Definition:
flann.hpp:77
flann::Index::size
size_t size() const
Definition:
flann.hpp:198
flann::Index::veclen
size_t veclen() const
Definition:
flann.hpp:190
flann::Index::getType
flann_algorithm_t getType() const
Definition:
flann.hpp:206
FLANN_VERSION_
#define FLANN_VERSION_
Definition:
config.h:36
flann_datatype_t
flann_datatype_t
Definition:
defines.h:132
flann_log_level_t
flann_log_level_t
Definition:
defines.h:104
flann_algorithm_t
flann_algorithm_t
Definition:
defines.h:80
flann_centers_init_t
flann_centers_init_t
Definition:
defines.h:96
general.h
flann::serialization::ENUM_SERIALIZER
ENUM_SERIALIZER(flann_algorithm_t)
flann
Definition:
all_indices.h:50
flann::save_header
void save_header(FILE *stream, const Index &index)
Definition:
saving.h:89
flann::load_header
IndexHeader load_header(FILE *stream)
Definition:
saving.h:106
FLANN_SIGNATURE_
#define FLANN_SIGNATURE_
Definition:
saving.h:43
serialization.h
flann::IndexHeaderStruct
Definition:
serialization.h:15
flann::IndexHeaderStruct::compression
size_t compression
Definition:
serialization.h:22
flann::IndexHeaderStruct::index_type
flann_algorithm_t index_type
Definition:
serialization.h:19
flann::IndexHeaderStruct::data_type
flann_datatype_t data_type
Definition:
serialization.h:18
flann::IndexHeaderStruct::rows
size_t rows
Definition:
serialization.h:20
flann::IndexHeaderStruct::version
char version[16]
Definition:
serialization.h:17
flann::IndexHeaderStruct::cols
size_t cols
Definition:
serialization.h:21
flann::IndexHeaderStruct::signature
char signature[24]
Definition:
serialization.h:16
flann::IndexHeaderStruct::first_block_size
size_t first_block_size
Definition:
serialization.h:23
flann::IndexHeader
Definition:
saving.h:52
flann::IndexHeader::h
IndexHeaderStruct h
Definition:
saving.h:53
flann::IndexHeader::IndexHeader
IndexHeader()
Definition:
saving.h:55
flann::flann_datatype_value
Definition:
general.h:53
flann::serialization::access
Definition:
serialization.h:30
libs
Reconstruction
lib
FLANN
util
saving.h
Generated on Wed Jan 28 2026 09:00:59 for ACloudViewer by
1.9.1