saving.h
Go to the documentation of this file.
00001 /***********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright 2008-2009  Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
00005  * Copyright 2008-2009  David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE NNIndexGOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  *************************************************************************/
00028 
00029 #ifndef RTABMAP_FLANN_SAVING_H_
00030 #define RTABMAP_FLANN_SAVING_H_
00031 
00032 #include <cstring>
00033 #include <vector>
00034 #include <stdio.h>
00035 
00036 #include "rtflann/general.h"
00037 #include "rtflann/util/serialization.h"
00038 
00039 
00040 #ifdef FLANN_SIGNATURE_
00041 #undef FLANN_SIGNATURE_
00042 #endif
00043 #define FLANN_SIGNATURE_ "FLANN_INDEX_v1.1"
00044 
00045 namespace rtflann
00046 {
00047 
00051 struct IndexHeader
00052 {
00053     IndexHeaderStruct h;
00054 
00055     IndexHeader()
00056         {
00057         memset(h.signature, 0, sizeof(h.signature));
00058         strcpy(h.signature, FLANN_SIGNATURE_);
00059         memset(h.version, 0, sizeof(h.version));
00060         strcpy(h.version, FLANN_VERSION_);
00061 
00062         h.compression = 0;
00063         h.first_block_size = 0;
00064         }
00065 
00066 private:
00067     template<typename Archive>
00068     void serialize(Archive& ar)
00069     {
00070         ar & h.signature;
00071         ar & h.version;
00072         ar & h.data_type;
00073         ar & h.index_type;
00074         ar & h.rows;
00075         ar & h.cols;
00076         ar & h.compression;
00077         ar & h.first_block_size;
00078     }
00079     friend struct serialization::access;
00080 };
00081 
00088 template<typename Index>
00089 void save_header(FILE* stream, const Index& index)
00090 {
00091     IndexHeader header;
00092     header.h.data_type = flann_datatype_value<typename Index::ElementType>::value;
00093     header.h.index_type = index.getType();
00094     header.h.rows = index.size();
00095     header.h.cols = index.veclen();
00096 
00097     fwrite(&header, sizeof(header),1,stream);
00098 }
00099 
00100 
00106 inline IndexHeader load_header(FILE* stream)
00107 {
00108     IndexHeader header;
00109     int read_size = fread(&header,sizeof(header),1,stream);
00110 
00111     if (read_size != 1) {
00112         throw FLANNException("Invalid index file, cannot read");
00113     }
00114 
00115     if (strncmp(header.h.signature,
00116                 FLANN_SIGNATURE_,
00117                 strlen(FLANN_SIGNATURE_) - strlen("v0.0")) != 0) {
00118         throw FLANNException("Invalid index file, wrong signature");
00119     }
00120 
00121     return header;
00122 }
00123 
00124 
00125 namespace serialization
00126 {
00127 ENUM_SERIALIZER(flann_algorithm_t);
00128 ENUM_SERIALIZER(flann_centers_init_t);
00129 ENUM_SERIALIZER(flann_log_level_t);
00130 ENUM_SERIALIZER(flann_datatype_t);
00131 }
00132 
00133 }
00134 
00135 #endif /* FLANN_SAVING_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:22