Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
corelib
src
rtflann
util
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 RTABMAP_FLANN_SAVING_H_
30
#define RTABMAP_FLANN_SAVING_H_
31
32
#include <cstring>
33
#include <vector>
34
#include <stdio.h>
35
36
#include "
rtflann/general.h
"
37
#include "
rtflann/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
rtflann
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_ */
rtflann::flann_centers_init_t
flann_centers_init_t
Definition:
defines.h:95
rtflann::IndexHeaderStruct::data_type
flann_datatype_t data_type
Definition:
serialization.h:18
FLANN_VERSION_
#define FLANN_VERSION_
Definition:
config.h:36
FLANN_SIGNATURE_
#define FLANN_SIGNATURE_
Definition:
saving.h:43
rtflann::FLANNException
Definition:
general.h:42
header
std_msgs::Header * header(M &m)
rtflann::IndexHeader::h
IndexHeaderStruct h
Definition:
saving.h:53
rtflann::flann_datatype_value
Definition:
general.h:52
serialization.h
rtflann::IndexHeaderStruct::index_type
flann_algorithm_t index_type
Definition:
serialization.h:19
rtflann::save_header
void save_header(FILE *stream, const Index &index)
Definition:
saving.h:89
rtflann::flann_algorithm_t
flann_algorithm_t
Definition:
defines.h:79
rtflann::Index
Definition:
flann.hpp:76
rtflann
Definition:
all_indices.h:49
rtflann::load_header
IndexHeader load_header(FILE *stream)
Definition:
saving.h:106
rtflann::IndexHeaderStruct::cols
size_t cols
Definition:
serialization.h:21
rtflann::Index::getType
flann_algorithm_t getType() const
Definition:
flann.hpp:216
rtflann::IndexHeader::serialize
void serialize(Archive &ar)
Definition:
saving.h:68
rtflann::IndexHeaderStruct
Definition:
serialization.h:15
general.h
rtflann::IndexHeaderStruct::rows
size_t rows
Definition:
serialization.h:20
rtflann::IndexHeaderStruct::first_block_size
size_t first_block_size
Definition:
serialization.h:23
rtflann::IndexHeader
Definition:
saving.h:51
rtflann::IndexHeaderStruct::compression
size_t compression
Definition:
serialization.h:22
rtflann::IndexHeader::IndexHeader
IndexHeader()
Definition:
saving.h:55
rtflann::serialization::access
Definition:
serialization.h:29
rtflann::Index::veclen
size_t veclen() const
Definition:
flann.hpp:190
rtflann::flann_datatype_t
flann_datatype_t
Definition:
defines.h:131
rtflann::Index::size
size_t size() const
Definition:
flann.hpp:198
ENUM_SERIALIZER
#define ENUM_SERIALIZER(type)
Definition:
serialization.h:76
rtflann::flann_log_level_t
flann_log_level_t
Definition:
defines.h:103
rtflann::IndexHeaderStruct::version
char version[16]
Definition:
serialization.h:17
rtflann::IndexHeaderStruct::signature
char signature[24]
Definition:
serialization.h:16
rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:35:00