Line | Hotness | Optimization | Source | Inline Context |
---|---|---|---|---|
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 OPENCV_FLANN_SAVING_H_ | |||
30 | #define OPENCV_FLANN_SAVING_H_ | |||
31 | ||||
32 | //! @cond IGNORED | |||
33 | ||||
34 | #include <cstring> | |||
35 | #include <vector> | |||
36 | ||||
37 | #include "general.h" | |||
38 | #include "nn_index.h" | |||
39 | ||||
40 | #ifdef FLANN_SIGNATURE_ | |||
41 | #undef FLANN_SIGNATURE_ | |||
42 | #endif | |||
43 | #define FLANN_SIGNATURE_ "FLANN_INDEX" | |||
44 | ||||
45 | namespace cvflann | |||
46 | { | |||
47 | ||||
48 | template <typename T> | |||
49 | struct Datatype {}; | |||
50 | template<> | |||
51 | struct Datatype<char> { static flann_datatype_t type() { return FLANN_INT8; } }; | |||
52 | template<> | |||
53 | struct Datatype<short> { static flann_datatype_t type() { return FLANN_INT16; } }; | |||
54 | template<> | |||
55 | struct Datatype<int> { static flann_datatype_t type() { return FLANN_INT32; } }; | |||
56 | template<> | |||
57 | struct Datatype<unsigned char> { static flann_datatype_t type() { return FLANN_UINT8; } }; | |||
58 | template<> | |||
59 | struct Datatype<unsigned short> { static flann_datatype_t type() { return FLANN_UINT16; } }; | |||
60 | template<> | |||
61 | struct Datatype<unsigned int> { static flann_datatype_t type() { return FLANN_UINT32; } }; | |||
62 | template<> | |||
63 | struct Datatype<float> { static flann_datatype_t type() { return FLANN_FLOAT32; } }; | |||
64 | template<> | |||
65 | struct Datatype<double> { static flann_datatype_t type() { return FLANN_FLOAT64; } }; | |||
66 | ||||
67 | ||||
68 | /** | |||
69 | * Structure representing the index header. | |||
70 | */ | |||
71 | struct IndexHeader | |||
72 | { | |||
73 | char signature[16]; | |||
74 | char version[16]; | |||
75 | flann_datatype_t data_type; | |||
76 | flann_algorithm_t index_type; | |||
77 | size_t rows; | |||
78 | size_t cols; | |||
79 | }; | |||
80 | ||||
81 | /** | |||
82 | * Saves index header to stream | |||
83 | * | |||
84 | * @param stream - Stream to save to | |||
85 | * @param index - The index to save | |||
86 | */ | |||
87 | template<typename Distance> | |||
88 | void save_header(FILE* stream, const NNIndex<Distance>& index) | |||
89 | { | |||
90 | IndexHeader header; | |||
91 | memset(header.signature, 0, sizeof(header.signature)); | |||
92 | strcpy(header.signature, FLANN_SIGNATURE_); | |||
93 | memset(header.version, 0, sizeof(header.version)); | |||
94 | strcpy(header.version, FLANN_VERSION_); | |||
95 | header.data_type = Datatype<typename Distance::ElementType>::type(); | |||
96 | header.index_type = index.getType(); | |||
97 | header.rows = index.size(); | |||
0 | ^ | |||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)** not eliminated because it is clobbered by call | cvflann::save_header | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)* not eliminated because it is clobbered by call | cvflann::save_header | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)** not eliminated because it is clobbered by call | cv::flann::saveIndex_ | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)* not eliminated because it is clobbered by call | cv::flann::saveIndex_ | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)** not eliminated because it is clobbered by call | cv::flann::saveIndex | ||
0 | ...16 similar remarks omitted. | |||
98 | header.cols = index.veclen(); | |||
0 | ^ | |||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)** not eliminated in favor of load because it is clobbered by call | cvflann::save_header | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)* not eliminated because it is clobbered by call | cvflann::save_header | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)** not eliminated in favor of load because it is clobbered by call | cv::flann::saveIndex_ | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)* not eliminated because it is clobbered by call | cv::flann::saveIndex_ | ||
gvn | • load of type i64 (%"class.cvflann::NNIndex"*)** not eliminated in favor of load because it is clobbered by call | cv::flann::saveIndex | ||
0 | ...16 similar remarks omitted. | |||
99 | ||||
100 | std::fwrite(&header, sizeof(header),1,stream); | |||
0 | ^ | |||
inline | • fwrite will not be inlined into cvflann::save_header<cvflann::HammingLUT> because its definition is unavailable | cvflann::save_header | ||
inline | • fwrite will not be inlined into cvflann::save_header<cvflann::L2<float> > because its definition is unavailable | cvflann::save_header | ||
inline | • fwrite will not be inlined into cvflann::save_header<cvflann::L1<float> > because its definition is unavailable | cvflann::save_header | ||
101 | } | |||
102 | ||||
103 | ||||
104 | /** | |||
105 | * | |||
106 | * @param stream - Stream to load from | |||
107 | * @return Index header | |||
108 | */ | |||
109 | inline IndexHeader load_header(FILE* stream) | |||
110 | { | |||
111 | IndexHeader header; | |||
112 | size_t read_size = fread(&header,sizeof(header),1,stream); | |||
0 | ^ | |||
inline | • fread will not be inlined into cvflann::load_header because its definition is unavailable | cvflann::load_header | ||
113 | ||||
114 | if (read_size!=(size_t)1) { | |||
115 | FLANN_THROW(cv::Error::StsError, "Invalid index file, cannot read"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_header' because too costly to inline (cost=25, threshold=0) | cvflann::load_header | ||
116 | } | |||
117 | ||||
118 | if (strcmp(header.signature,FLANN_SIGNATURE_)!=0) { | |||
0 | ^ | |||
inline | • bcmp will not be inlined into cvflann::load_header because its definition is unavailable | cvflann::load_header | ||
119 | FLANN_THROW(cv::Error::StsError, "Invalid index file, wrong signature"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_header' because too costly to inline (cost=25, threshold=0) | cvflann::load_header | ||
120 | } | |||
121 | ||||
122 | return header; | |||
123 | ||||
124 | } | |||
125 | ||||
126 | ||||
127 | template<typename T> | |||
128 | void save_value(FILE* stream, const T& value, size_t count = 1) | |||
129 | { | |||
130 | fwrite(&value, sizeof(value),count, stream); | |||
0 | ^ | |||
inline | • fwrite will not be inlined into cvflann::save_value<int> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<float> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<cvflann::KMeansIndex<cvflann::HammingLUT>::KMeansNode> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<unsigned char> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<cvflann::flann_centers_init_t> because its definition is unavailable | cvflann::save_value | ||
0 | ...13 similar remarks omitted. | |||
0 | ^ | |||
gvn | • load of type i8 not eliminated because it is clobbered by call | cvflann::KDTreeSingleIndex | ||
gvn | • load of type i8 not eliminated because it is clobbered by call | cvflann::KDTreeSingleIndex | ||
131 | } | |||
132 | ||||
133 | template<typename T> | |||
134 | void save_value(FILE* stream, const cvflann::Matrix<T>& value) | |||
135 | { | |||
136 | fwrite(&value, sizeof(value),1, stream); | |||
0 | ^ | |||
inline | • fwrite will not be inlined into cvflann::save_value<unsigned char> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<float> because its definition is unavailable | cvflann::save_value | ||
137 | fwrite(value.data, sizeof(T),value.rows*value.cols, stream); | |||
0 | ^ | |||
inline | • fwrite will not be inlined into cvflann::save_value<unsigned char> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<float> because its definition is unavailable | cvflann::save_value | ||
gvn | • load of type i8* not eliminated because it is clobbered by call | cvflann::save_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::save_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::save_value | ||
gvn | • load of type i8* not eliminated because it is clobbered by call | cvflann::LshIndex | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::LshIndex | ||
0 | ...19 similar remarks omitted. | |||
0 | ^ | |||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::LshIndex | ||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::KDTreeSingleIndex | ||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::LshIndex | ||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::KDTreeSingleIndex | ||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::LshIndex | ||
0 | ...1 similar remarks omitted. | |||
138 | } | |||
139 | ||||
140 | template<typename T> | |||
141 | void save_value(FILE* stream, const std::vector<T>& value) | |||
142 | { | |||
143 | size_t size = value.size(); | |||
144 | fwrite(&size, sizeof(size_t), 1, stream); | |||
0 | ^ | |||
inline | • fwrite will not be inlined into cvflann::save_value<cvflann::KDTreeSingleIndex<cvflann::L2<float> >::Interval> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<int> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<cvflann::KDTreeSingleIndex<cvflann::L1<float> >::Interval> because its definition is unavailable | cvflann::save_value | ||
145 | fwrite(&value[0], sizeof(T), size, stream); | |||
0 | ^ | |||
inline | • fwrite will not be inlined into cvflann::save_value<cvflann::KDTreeSingleIndex<cvflann::L2<float> >::Interval> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<int> because its definition is unavailable | cvflann::save_value | ||
inline | • fwrite will not be inlined into cvflann::save_value<cvflann::KDTreeSingleIndex<cvflann::L1<float> >::Interval> because its definition is unavailable | cvflann::save_value | ||
0 | ^ | |||
gvn | • load of type i64 not eliminated in favor of store because it is clobbered by call | cvflann::save_value | ||
gvn | • load of type i64 not eliminated in favor of store because it is clobbered by call | cvflann::save_value | ||
gvn | • load of type i64 not eliminated in favor of store because it is clobbered by call | cvflann::KDTreeSingleIndex | ||
gvn | • load of type i64 not eliminated in favor of store because it is clobbered by call | cvflann::save_value | ||
gvn | • load of type i64 not eliminated in favor of store because it is clobbered by call | cvflann::KDTreeSingleIndex | ||
146 | } | |||
147 | ||||
148 | template<typename T> | |||
149 | void load_value(FILE* stream, T& value, size_t count = 1) | |||
150 | { | |||
151 | size_t read_cnt = fread(&value, sizeof(value), count, stream); | |||
0 | ^ | |||
inline | • fread will not be inlined into cvflann::load_value<int> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<float> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<cvflann::KMeansIndex<cvflann::HammingLUT>::KMeansNode> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<unsigned char> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<cvflann::flann_centers_init_t> because its definition is unavailable | cvflann::load_value | ||
0 | ...13 similar remarks omitted. | |||
152 | if (read_cnt != count) { | |||
0 | ^ | |||
loop-vectorize | • loop not vectorized | cvflann::KMeansIndex | ||
loop-vectorize | • loop not vectorized | cvflann::HierarchicalClusteringIndex | ||
loop-vectorize | • loop not vectorized | cvflann::KMeansIndex | ||
loop-vectorize | • loop not vectorized | cvflann::HierarchicalClusteringIndex | ||
loop-vectorize | • loop not vectorized | cvflann::KMeansIndex | ||
0 | ...3 similar remarks omitted. | |||
153 | FLANN_THROW(cv::Error::StsParseError, "Cannot read from file"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<int>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<float>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<cvflann::KMeansIndex<cvflann::HammingLUT>::KMeansNode>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<unsigned char>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::KMeansIndex<cvflann::HammingLUT>::load_tree' because too costly to inline (cost=25, threshold=0) | cvflann::KMeansIndex | ||
0 | ...46 similar remarks omitted. | |||
154 | } | |||
155 | } | |||
156 | ||||
157 | template<typename T> | |||
158 | void load_value(FILE* stream, cvflann::Matrix<T>& value) | |||
159 | { | |||
160 | size_t read_cnt = fread(&value, sizeof(value), 1, stream); | |||
0 | ^ | |||
inline | • fread will not be inlined into cvflann::load_value<unsigned char> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<float> because its definition is unavailable | cvflann::load_value | ||
161 | if (read_cnt != 1) { | |||
162 | FLANN_THROW(cv::Error::StsParseError, "Cannot read from file"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<unsigned char>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<float>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
163 | } | |||
164 | value.data = new T[value.rows*value.cols]; | |||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
0 | ^ | |||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::load_value | ||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::load_value | ||
165 | read_cnt = fread(value.data, sizeof(T), value.rows*value.cols, stream); | |||
0 | ^ | |||
inline | • fread will not be inlined into cvflann::load_value<unsigned char> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<float> because its definition is unavailable | cvflann::load_value | ||
166 | if (read_cnt != (size_t)(value.rows*value.cols)) { | |||
gvn | • load of type i64 not eliminated in favor of load because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated in favor of load because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated in favor of load because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated in favor of load because it is clobbered by call | cvflann::load_value | ||
0 | ^ | |||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::load_value | ||
slp-vectorizer | • List vectorization was possible but not beneficial with cost 0 >= 0 | cvflann::load_value | ||
167 | FLANN_THROW(cv::Error::StsParseError, "Cannot read from file"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<unsigned char>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<float>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
168 | } | |||
169 | } | |||
170 | ||||
171 | ||||
172 | template<typename T> | |||
173 | void load_value(FILE* stream, std::vector<T>& value) | |||
174 | { | |||
175 | size_t size; | |||
176 | size_t read_cnt = fread(&size, sizeof(size_t), 1, stream); | |||
0 | ^ | |||
inline | • fread will not be inlined into cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L2<float> >::Interval> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<int> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L1<float> >::Interval> because its definition is unavailable | cvflann::load_value | ||
177 | if (read_cnt!=1) { | |||
178 | FLANN_THROW(cv::Error::StsError, "Cannot read from file"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L2<float> >::Interval>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<int>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L1<float> >::Interval>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
179 | } | |||
180 | value.resize(size); | |||
0 | ^ | |||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
gvn | • load of type i64 not eliminated because it is clobbered by call | cvflann::load_value | ||
181 | read_cnt = fread(&value[0], sizeof(T), size, stream); | |||
0 | ^ | |||
inline | • fread will not be inlined into cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L2<float> >::Interval> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<int> because its definition is unavailable | cvflann::load_value | ||
inline | • fread will not be inlined into cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L1<float> >::Interval> because its definition is unavailable | cvflann::load_value | ||
182 | if (read_cnt != size) { | |||
183 | FLANN_THROW(cv::Error::StsError, "Cannot read from file"); | |||
0 | ^ | |||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L2<float> >::Interval>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<int>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
inline | • 'cvflann::FLANNException::FLANNException' not inlined into 'cvflann::load_value<cvflann::KDTreeSingleIndex<cvflann::L1<float> >::Interval>' because too costly to inline (cost=25, threshold=0) | cvflann::load_value | ||
184 | } | |||
185 | } | |||
186 | ||||
187 | } | |||
188 | ||||
189 | //! @endcond | |||
190 | ||||
191 | #endif /* OPENCV_FLANN_SAVING_H_ */ | |||
192 | ||||
193 |