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_ */
flann_centers_init_t
Definition: defines.h:95
flann_datatype_t data_type
Definition: serialization.h:18
size_t size() const
Definition: flann.hpp:198
#define FLANN_VERSION_
Definition: config.h:36
#define FLANN_SIGNATURE_
Definition: saving.h:43
std_msgs::Header * header(M &m)
IndexHeaderStruct h
Definition: saving.h:53
size_t veclen() const
Definition: flann.hpp:190
flann_algorithm_t index_type
Definition: serialization.h:19
void save_header(FILE *stream, const Index &index)
Definition: saving.h:89
flann_algorithm_t
Definition: defines.h:79
flann_algorithm_t getType() const
Definition: flann.hpp:216
IndexHeader load_header(FILE *stream)
Definition: saving.h:106
void serialize(Archive &ar)
Definition: saving.h:68
flann_datatype_t
Definition: defines.h:131
#define ENUM_SERIALIZER(type)
Definition: serialization.h:76
flann_log_level_t
Definition: defines.h:103


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:30