matrix.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  * THE BSD LICENSE
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *************************************************************************/
30 
31 #ifndef RTABMAP_FLANN_DATASET_H_
32 #define RTABMAP_FLANN_DATASET_H_
33 
34 #include "rtflann/general.h"
36 #include <stdio.h>
37 
38 namespace rtflann
39 {
40 
41 typedef unsigned char uchar;
42 
43 class Matrix_
44 {
45 public:
46 
48  {
49  };
50 
51  Matrix_(void* data_, size_t rows_, size_t cols_, flann_datatype_t type_, size_t stride_ = 0) :
52  rows(rows_), cols(cols_), stride(stride_), type(type_)
53  {
54  data = static_cast<uchar*>(data_);
55 
57  }
58 
62  inline void* operator[](size_t index) const
63  {
64  return data+index*stride;
65  }
66 
67  void* ptr() const
68  {
69  return data;
70  }
71 
72  size_t rows;
73  size_t cols;
74  size_t stride;
76 protected:
77  uchar* data;
78 
79  template<typename Archive>
80  void serialize(Archive& ar)
81  {
82  ar & rows;
83  ar & cols;
84  ar & stride;
85  ar & type;
86  if (Archive::is_loading::value) {
87  data = new uchar[rows*stride];
88  }
89  ar & serialization::make_binary_object(data, rows*stride);
90  }
91  friend struct serialization::access;
92 };
93 
94 
102 template <typename T>
103 class Matrix : public Matrix_
104 {
105 public:
106  typedef T type;
107 
109  {
110  }
111 
112  Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) :
113  Matrix_(data_, rows_, cols_, flann_datatype_value<T>::value, stride_)
114  {
115  if (stride==0) stride = sizeof(T)*cols;
116  }
117 
121  inline T* operator[](size_t index) const
122  {
123  return reinterpret_cast<T*>(data+index*stride);
124  }
125 
126 
127  T* ptr() const
128  {
129  return reinterpret_cast<T*>(data);
130  }
131 };
132 
133 }
134 
135 #endif //FLANN_DATASET_H_
void * operator[](size_t index) const
Definition: matrix.h:62
#define NULL
uchar * data
Definition: matrix.h:77
T * operator[](size_t index) const
Definition: matrix.h:121
flann_datatype_t type
Definition: matrix.h:75
unsigned char uchar
Definition: matrix.h:41
T * ptr() const
Definition: matrix.h:127
size_t rows
Definition: matrix.h:72
void * ptr() const
Definition: matrix.h:67
void serialize(Archive &ar)
Definition: matrix.h:80
Matrix_(void *data_, size_t rows_, size_t cols_, flann_datatype_t type_, size_t stride_=0)
Definition: matrix.h:51
size_t flann_datatype_size(flann_datatype_t type)
Definition: general.h:196
size_t cols
Definition: matrix.h:73
Matrix(T *data_, size_t rows_, size_t cols_, size_t stride_=0)
Definition: matrix.h:112
const binary_object make_binary_object(void *t, size_t size)
flann_datatype_t
Definition: defines.h:131
size_t stride
Definition: matrix.h:74


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31