Gradient Augmented Levelset Implementation in CPU & GPU
mat3.cc (Latest change: Author:Lakshman Anumolu <acrlakshman@yahoo.co.in>, 2019-07-21 09:04:10 -0500, [commit: 9635e15])
Go to the documentation of this file.
1 // Copyright 2019 Lakshman Anumolu, Raunak Bardia.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 #include "gals/utilities/mat3.h"
33 
35 
36 template <typename T>
37 GALS::CPU::Mat3<T>::Mat3(T a00, T a01, T a02, T a10, T a11, T a12, T a20, T a21, T a22)
38 {
39  m_data[0] = a00;
40  m_data[1] = a01;
41  m_data[2] = a02;
42  m_data[3] = a10;
43  m_data[4] = a11;
44  m_data[5] = a12;
45  m_data[6] = a20;
46  m_data[7] = a21;
47  m_data[8] = a22;
48 }
49 
50 template <typename T>
52  : Mat3(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0),
53  static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0))
54 {
55 }
56 
57 template <typename T>
59 {
60 }
61 
62 template <typename T>
63 const int GALS::CPU::Mat3<T>::size() const
64 {
65  return SIZE;
66 }
67 
68 template <typename T>
70 {
72 
73  for (int i = 0; i < 3; ++i)
74  for (int j = 0; j < 3; ++j) res[i] += m_data[j * 3 + i] * vec[j];
75 
76  return res;
77 }
78 
79 template <typename T>
80 const T GALS::CPU::Mat3<T>::operator[](const int idx) const
81 {
82  return m_data[idx];
83 }
84 
85 template <typename T>
87 {
88  return m_data[idx];
89 }
90 
91 template <typename T>
92 const T GALS::CPU::Mat3<T>::operator()(const int i_row, const int i_col) const
93 {
94  return m_data[i_row * 3 + i_col];
95 }
96 
97 template <typename T>
98 T& GALS::CPU::Mat3<T>::operator()(const int i_row, const int i_col)
99 {
100  return m_data[i_row * 3 + i_col];
101 }
102 
103 template <typename T>
105 {
106  for (int i = 0; i < SIZE; ++i) m_data[i] = mat[i];
107 }
108 
109 template <typename T>
111 {
112  Mat3<T> res;
113  for (int i = 0; i < SIZE; ++i) res[i] = m_data[i] - mat[i];
114 
115  return res;
116 }
117 
118 template <typename T>
120 {
121  Mat3<T> res;
122  for (int i = 0; i < SIZE; ++i) res[i] = m_data[i] * var;
123 
124  return res;
125 }
126 
127 template <typename T>
129 {
130  return (GALS::is_equal(m_data[0], mat[0]) && GALS::is_equal(m_data[1], mat[1]) && GALS::is_equal(m_data[2], mat[2]) &&
131  GALS::is_equal(m_data[3], mat[3]) && GALS::is_equal(m_data[4], mat[4]) && GALS::is_equal(m_data[5], mat[5]) &&
132  GALS::is_equal(m_data[6], mat[6]) && GALS::is_equal(m_data[7], mat[7]) && GALS::is_equal(m_data[8], mat[8]));
133 }
134 
135 template class GALS::CPU::Mat3<int>;
136 template class GALS::CPU::Mat3<double>;
const Mat3< T > operator-(const Mat3< T > &mat) const
Definition: mat3.cc:110
const T operator()(const int i_row, const int i_col) const
Definition: mat3.cc:92
const Mat3< T > operator*(const T var) const
Definition: mat3.cc:119
bool operator==(const Mat3< T > &mat) const
Definition: mat3.cc:128
static constexpr int SIZE
Definition: mat3.h:52
static bool is_equal(double a, double b)
Definition: utilities.h:70
const T operator[](const int idx) const
Definition: mat3.cc:80
const Vec3< T > dot(const Vec3< T > vec) const
Definition: mat3.cc:69
void operator=(const Mat3< T > &mat)
Definition: mat3.cc:104
const int size() const
Definition: mat3.cc:63