matrix.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  * THE BSD LICENSE
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00020  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00021  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00022  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00023  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00024  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00028  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *************************************************************************/
00030 
00031 #ifndef RTABMAP_FLANN_DATASET_H_
00032 #define RTABMAP_FLANN_DATASET_H_
00033 
00034 #include "rtflann/general.h"
00035 #include "rtflann/util/serialization.h"
00036 #include <stdio.h>
00037 
00038 namespace rtflann
00039 {
00040 
00041 typedef unsigned char uchar;
00042 
00043 class Matrix_
00044 {
00045 public:
00046 
00047         Matrix_() : rows(0), cols(0), stride(0), type(FLANN_NONE), data(NULL)
00048         {
00049         };
00050 
00051     Matrix_(void* data_, size_t rows_, size_t cols_, flann_datatype_t type_, size_t stride_ = 0) :
00052         rows(rows_), cols(cols_), stride(stride_), type(type_)
00053     {
00054         data = static_cast<uchar*>(data_);
00055 
00056         if (stride==0) stride = flann_datatype_size(type)*cols;
00057     }
00058 
00062     inline void* operator[](size_t index) const
00063     {
00064         return data+index*stride;
00065     }
00066 
00067     void* ptr() const
00068     {
00069         return data;
00070     }
00071 
00072     size_t rows;
00073     size_t cols;
00074     size_t stride;
00075     flann_datatype_t type;
00076 protected:
00077     uchar* data;
00078 
00079     template<typename Archive>
00080     void serialize(Archive& ar)
00081     {
00082         ar & rows;
00083         ar & cols;
00084         ar & stride;
00085         ar & type;
00086         if (Archive::is_loading::value) {
00087                 data = new uchar[rows*stride];
00088         }
00089         ar & serialization::make_binary_object(data, rows*stride);
00090     }
00091     friend struct serialization::access;
00092 };
00093 
00094 
00102 template <typename T>
00103 class Matrix : public Matrix_
00104 {
00105 public:
00106     typedef T type;
00107 
00108     Matrix() : Matrix_()
00109     {
00110     }
00111 
00112     Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) :
00113         Matrix_(data_, rows_, cols_, flann_datatype_value<T>::value, stride_)
00114     {
00115         if (stride==0) stride = sizeof(T)*cols;
00116     }
00117 
00121     inline T* operator[](size_t index) const
00122     {
00123         return reinterpret_cast<T*>(data+index*stride);
00124     }
00125 
00126 
00127     T* ptr() const
00128     {
00129         return reinterpret_cast<T*>(data);
00130     }
00131 };
00132 
00133 }
00134 
00135 #endif //FLANN_DATASET_H_


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