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 
47  Matrix_() : rows(0), cols(0), stride(0), type(FLANN_NONE), data(NULL)
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  }
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_
rtflann::Matrix_::serialize
void serialize(Archive &ar)
Definition: matrix.h:108
general.h
rtflann::Matrix::Matrix
Matrix()
Definition: matrix.h:136
rtflann::uchar
unsigned char uchar
Definition: matrix.h:69
rtflann::Matrix_::cols
size_t cols
Definition: matrix.h:101
rtflann::Matrix_::stride
size_t stride
Definition: matrix.h:102
rtflann::Matrix_
Definition: matrix.h:71
rtflann::Matrix_::data
uchar * data
Definition: matrix.h:105
rtflann::Matrix::operator[]
T * operator[](size_t index) const
Definition: matrix.h:149
type
rtflann::Matrix_::operator[]
void * operator[](size_t index) const
Definition: matrix.h:90
rtflann::serialization::access
Definition: serialization.h:29
rtflann::Matrix_::ptr
void * ptr() const
Definition: matrix.h:95
rtflann::Matrix::ptr
T * ptr() const
Definition: matrix.h:155
rtflann::Matrix_::type
flann_datatype_t type
Definition: matrix.h:103
rtflann::flann_datatype_size
size_t flann_datatype_size(flann_datatype_t type)
Definition: general.h:224
rtflann::Matrix_::rows
size_t rows
Definition: matrix.h:100
rtflann::flann_datatype_value
Definition: general.h:80
Eigen::Triplet< double >
rtflann::FLANN_NONE
@ FLANN_NONE
Definition: defines.h:133
rtflann::Matrix_::Matrix_
Matrix_()
Definition: matrix.h:75
rtflann::serialization::make_binary_object
const binary_object make_binary_object(void *t, size_t size)
Definition: serialization.h:229
serialization.h
NULL
#define NULL
rtflann::Matrix::type
T type
Definition: matrix.h:134
rtflann
Definition: all_indices.h:49
value
value
rtflann::flann_datatype_t
flann_datatype_t
Definition: defines.h:131
rtflann::Matrix
Definition: matrix.h:131


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jul 1 2024 02:42:30