Gradient Augmented Levelset Implementation in CPU & GPU
vec3.cc (Latest change: Author:Lakshman Anumolu <acrlakshman@yahoo.co.in>, 2019-07-26 22:25:50 -0500, [commit: 8a07ea1])
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/vec3.h"
33 
35 
36 template <typename T>
37 GALS::CPU::Vec3<T>::Vec3(const T a, const T b, const T c)
38 {
39  m_data[0] = a;
40  m_data[1] = b;
41  m_data[2] = c;
42 }
43 
44 template <typename T>
45 GALS::CPU::Vec3<T>::Vec3(const std::vector<T> a)
46 {
47  if (a.size() != 3) GALS_ABORT("While constructing Vec3 object using std::vector, input must be of size 3.");
48 
49  m_data[0] = a[0];
50  m_data[1] = a[1];
51  m_data[2] = a[2];
52 }
53 
54 template <typename T>
55 GALS::CPU::Vec3<T>::Vec3() : Vec3(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0))
56 {
57 }
58 
59 template <typename T>
61 {
62 }
63 
64 template <typename T>
65 const int GALS::CPU::Vec3<T>::size() const
66 {
67  return SIZE;
68 }
69 
70 template <typename T>
71 const double GALS::CPU::Vec3<T>::mag() const
72 {
73  return sqrt(m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]);
74 }
75 
76 template <typename T>
77 const T GALS::CPU::Vec3<T>::min() const
78 {
79  if (m_data[0] < m_data[1] && m_data[0] < m_data[2]) return m_data[0];
80  if (m_data[1] < m_data[0] && m_data[1] < m_data[2]) return m_data[1];
81  return m_data[2];
82 }
83 
84 template <typename T>
85 const T GALS::CPU::Vec3<T>::operator[](const int idx) const
86 {
87  return m_data[idx];
88 }
89 
90 template <typename T>
92 {
93  return m_data[idx];
94 }
95 
96 template <typename T>
98 {
99  for (int i = 0; i < SIZE; ++i) m_data[i] = vec[i];
100 }
101 
102 template <typename T>
104 {
105  return (GALS::is_equal(m_data[0], vec[0]) && GALS::is_equal(m_data[1], vec[1]) && GALS::is_equal(m_data[2], vec[2]));
106 }
107 
108 template <typename T>
110 {
111  return Vec3<T>(m_data[0] - vec[0], m_data[1] - vec[1], m_data[2] - vec[2]);
112 }
113 
114 template <typename T>
116 {
117  return Vec3<T>(m_data[0] * vec[0], m_data[1] * vec[1], m_data[2] * vec[2]);
118 }
119 
120 template <typename T>
122 {
123  return Vec3<T>(m_data[0] * var, m_data[1] * var, m_data[2] * var);
124 }
125 
126 template <typename T>
128 {
129  return Vec3<T>(m_data[0] / vec[0], m_data[1] / vec[1], m_data[2] / vec[2]);
130 }
131 
132 template class GALS::CPU::Vec3<int>;
133 template class GALS::CPU::Vec3<double>;
const T operator[](const int idx) const
Definition: vec3.cc:85
const T min() const
Definition: vec3.cc:77
const int size() const
Definition: vec3.cc:65
void operator=(const Vec3< T > &vec)
Definition: vec3.cc:97
const double mag() const
Definition: vec3.cc:71
bool operator==(const Vec3< T > &vec) const
Definition: vec3.cc:103
static bool is_equal(double a, double b)
Definition: utilities.h:70
static constexpr int SIZE
Definition: vec3.h:51
const Vec3< T > operator-(const Vec3< T > &vec) const
Definition: vec3.cc:109
const Vec3< T > operator/(const Vec3< T > &vec) const
Definition: vec3.cc:127
#define GALS_ABORT(var)
Definition: utilities.h:48
const Vec3< T > operator*(const Vec3< T > &vec) const
Definition: vec3.cc:115