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"
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 
52 {
54 
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 {
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 {
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,
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 {
131 }
132 
133 }
134 
135 #endif /* FLANN_SAVING_H_ */
rtflann::IndexHeaderStruct::signature
char signature[24]
Definition: serialization.h:16
general.h
rtflann::IndexHeaderStruct::data_type
flann_datatype_t data_type
Definition: serialization.h:18
rtflann::Index::veclen
size_t veclen() const
Definition: flann.hpp:218
stream
stream
rtflann::FLANNException
Definition: general.h:70
rtflann::IndexHeaderStruct
Definition: serialization.h:15
rtflann::serialization::access
Definition: serialization.h:29
rtflann::IndexHeader::h
IndexHeaderStruct h
Definition: saving.h:53
rtflann::load_header
IndexHeader load_header(FILE *stream)
Definition: saving.h:106
rtflann::Index::size
size_t size() const
Definition: flann.hpp:226
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_datatype_value
Definition: general.h:80
rtflann::IndexHeader
Definition: saving.h:51
rtflann::IndexHeaderStruct::cols
size_t cols
Definition: serialization.h:21
rtflann::flann_algorithm_t
flann_algorithm_t
Definition: defines.h:79
header
std_msgs::Header const * header(const M &m)
rtflann::IndexHeaderStruct::compression
size_t compression
Definition: serialization.h:22
rtflann::IndexHeader::serialize
void serialize(Archive &ar)
Definition: saving.h:68
rtflann::IndexHeader::IndexHeader
IndexHeader()
Definition: saving.h:55
rtflann::Index::getType
flann_algorithm_t getType() const
Definition: flann.hpp:244
rtflann::IndexHeaderStruct::rows
size_t rows
Definition: serialization.h:20
rtflann::IndexHeaderStruct::first_block_size
size_t first_block_size
Definition: serialization.h:23
serialization.h
rtflann::flann_centers_init_t
flann_centers_init_t
Definition: defines.h:95
FLANN_VERSION_
#define FLANN_VERSION_
Definition: config.h:36
FLANN_SIGNATURE_
#define FLANN_SIGNATURE_
Definition: saving.h:43
rtflann
Definition: all_indices.h:49
rtflann::IndexHeaderStruct::version
char version[16]
Definition: serialization.h:17
rtflann::flann_log_level_t
flann_log_level_t
Definition: defines.h:103
rtflann::flann_datatype_t
flann_datatype_t
Definition: defines.h:131
rtflann::serialization::ENUM_SERIALIZER
ENUM_SERIALIZER(flann_algorithm_t)
rtflann::Index
Definition: flann.hpp:104


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:15