root / branches / test / PS3Capture / Include / opencv2 / flann / matrix.h @ 6

View | Annotate | Download (2.9 KB)

1
/***********************************************************************
2
 * Software License Agreement (BSD License)
3
 *
4
 * Copyright 2008-2009  Marius Muja ([email protected]). All rights reserved.
5
 * Copyright 2008-2009  David G. Lowe ([email protected]). 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 _OPENCV_DATASET_H_
32
#define _OPENCV_DATASET_H_
33
34
#include <stdio.h>
35
36
#include "opencv2/flann/general.h"
37
38
39
namespace cvflann 
40
{
41
42
/**
43
* Class that implements a simple rectangular matrix stored in a memory buffer and
44
* provides convenient matrix-like access using the [] operators.
45
*/
46
template <typename T>
47
class Matrix {
48
public:
49
    size_t rows;
50
    size_t cols;
51
    T* data;
52
53
    Matrix() : rows(0), cols(0), data(NULL)
54
    {
55
    }
56
57
    Matrix(T* data_, long rows_, long cols_) :
58
             rows(rows_), cols(cols_), data(data_)
59
        {
60
        }
61
62
    /**
63
     * Convenience function for deallocating the storage data.
64
     */
65
    void release()
66
    {
67
        if (data!=NULL) delete[] data;
68
    }
69
70
        ~Matrix()
71
        {
72
        }
73
74
    /**
75
    * Operator that return a (pointer to a) row of the data.
76
    */
77
    T* operator[](size_t index)
78
    {
79
        return data+index*cols;
80
    }
81
82
    T* operator[](size_t index) const
83
    {
84
        return data+index*cols;
85
    }
86
};
87
88
89
class UntypedMatrix
90
{
91
public:
92
    size_t rows;
93
    size_t cols;
94
    void* data;
95
    flann_datatype_t type;
96
97
    UntypedMatrix(void* data_, long rows_, long cols_) :
98
             rows(rows_), cols(cols_), data(data_)
99
    {
100
    }
101
102
    ~UntypedMatrix()
103
    {
104
    }
105
106
107
    template<typename T>
108
    Matrix<T> as()
109
    {
110
        return Matrix<T>((T*)data, rows, cols);
111
    }
112
};
113
114
115
116
} // namespace cvflann
117
118
#endif //_OPENCV_DATASET_H_