File size: 2,012 Bytes
0a95064
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
 * holder of all proprietary rights on this computer program.
 * You can only use this computer program if you have closed
 * a license agreement with MPG or you get the right to use the computer
 * program from someone who is authorized to grant you that right.
 * Any use of the computer program without a valid license is prohibited and
 * liable to prosecution.
 *
 * Copyright©2019 Max-Planck-Gesellschaft zur Förderung
 * der Wissenschaften e.V. (MPG). acting on behalf of its Max Planck Institute
 * for Intelligent Systems. All rights reserved.
 *
 * @author Vasileios Choutas
 * Contact: vassilis.choutas@tuebingen.mpg.de
 * Contact: ps-license@tuebingen.mpg.de
 *
 */

#ifndef TRIANGLE_H
#define TRIANGLE_H

#include "defs.hpp"
#include "double_vec_ops.hpp"
#include "helper_math.h"

#include "math_utils.hpp"
#include <cuda.h>
#include <cuda_profiler_api.h>
#include <cuda_runtime.h>

template <typename T>
__align__(48)
    struct Triangle {
public:
  vec3<T> v0;
  vec3<T> v1;
  vec3<T> v2;

  __host__ __device__ Triangle() {}
  __host__ __device__ Triangle(vec3<T> vertex0, vec3<T> vertex1,
                               vec3<T> vertex2)
      : v0(vertex0), v1(vertex1), v2(vertex2){};
  __host__ __device__ Triangle(const vec3<T> &vertex0, const vec3<T> &vertex1,
                               const vec3<T> &vertex2)
      : v0(vertex0), v1(vertex1), v2(vertex2){};

  __host__ __device__ AABB<T> bbox() const {
    return AABB<T>(min(v0.x, min(v1.x, v2.x)), min(v0.y, min(v1.y, v2.y)),
                   min(v0.z, min(v1.z, v2.z)), max(v0.x, max(v1.x, v2.x)),
                   max(v0.y, max(v1.y, v2.y)), max(v0.z, max(v1.z, v2.z)));
  }
};

template <typename T> using TrianglePtr = Triangle<T> *;

template <typename T>
std::ostream &operator<<(std::ostream &os, const Triangle<T> &x) {
  os << x.v0 << std::endl;
  os << x.v1 << std::endl;
  os << x.v2 << std::endl;
  return os;
}


#endif // TRIANGLE_H