HOG2
VoxelTriangleExtraction.h
Go to the documentation of this file.
1 //
2 // VoxelTriangleExtraction.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 6/19/17.
6 // Copyright © 2017 University of Denver. All rights reserved.
7 //
8 
9 #ifndef VoxelTriangleExtraction_h
10 #define VoxelTriangleExtraction_h
11 
12 #include <stdio.h>
13 #include <vector>
14 #include "VoxelGrid.h"
15 
16 namespace VoxelUtils {
17 
18  struct vn{
19  uint16_t normal[3];
20  uint16_t v[3];
21  };
22 
23  struct triangle {
24  uint16_t normal[3];
25  uint16_t v1[3];
26  uint16_t v2[3];
27  uint16_t v3[3];
28 
29  vn GetVN(int which)
30  {
31  switch (which)
32  {
33  case 0:
34  return {normal[0], normal[1], normal[2], v1[0], v1[1], v1[2]};
35  case 1:
36  return {normal[0], normal[1], normal[2], v2[0], v2[1], v2[2]};
37  case 2:
38  return {normal[0], normal[1], normal[2], v3[0], v3[1], v3[2]};
39  default:
40  exit(0);
41  return vn();
42  }
43  }
44  };
45  bool operator==(const triangle &a, const triangle &b);
46 
47  bool operator==(const vn &a, const vn &b);
48 
49  void GetTriangles(VoxelGrid *s, std::vector<triangle> &data);
50 
51 }
52 
53 namespace std {
54  template <> struct hash<VoxelUtils::triangle>
55  {
56  size_t operator()(const VoxelUtils::triangle & x) const
57  {
58  uint64_t t =
59  (((uint64_t)x.v1[0]<<0)|((uint64_t)x.v1[1]<<8)|((uint64_t)x.v1[2]<<16)|
60  ((uint64_t)x.v2[0]<<24)|((uint64_t)x.v2[1]<<32)|((uint64_t)x.v2[2]<<40)|
61  ((uint64_t)x.v3[0]<<48)|((uint64_t)x.v3[1]<<56));
62  t ^= ((uint64_t)x.v3[2]<<28);
63  t ^= (x.normal[0]<<7)|(x.normal[1]<<15)|(x.normal[2]<<24);
64  return t;
65  }
66  };
67 
68  template <> struct hash<VoxelUtils::vn>
69  {
70  size_t operator()(const VoxelUtils::vn & x) const
71  {
72  uint64_t t =
73  (((uint64_t)x.v[0]<<0)|((uint64_t)x.v[1]<<8)|((uint64_t)x.v[2]<<16)|
74  ((uint64_t)x.normal[0]<<24)|((uint64_t)x.normal[1]<<32)|((uint64_t)x.normal[2]<<40));
75  return t;
76  }
77  };
78 
79 }
80 
81 
82 #endif /* VoxelTriangleExtraction_h */
VoxelUtils::triangle::v2
uint16_t v2[3]
Definition: VoxelTriangleExtraction.h:26
VoxelUtils::triangle
Definition: VoxelTriangleExtraction.h:23
VoxelUtils::vn::v
uint16_t v[3]
Definition: VoxelTriangleExtraction.h:20
VoxelUtils
Definition: VoxelTriangleExtraction.cpp:13
std::hash< VoxelUtils::triangle >::operator()
size_t operator()(const VoxelUtils::triangle &x) const
Definition: VoxelTriangleExtraction.h:56
VoxelUtils::vn::normal
uint16_t normal[3]
Definition: VoxelTriangleExtraction.h:19
VoxelUtils::triangle::v3
uint16_t v3[3]
Definition: VoxelTriangleExtraction.h:27
VoxelGrid
Definition: VoxelGrid.h:41
VoxelUtils::triangle::v1
uint16_t v1[3]
Definition: VoxelTriangleExtraction.h:25
VoxelUtils::vn
Definition: VoxelTriangleExtraction.h:18
VoxelUtils::triangle::normal
uint16_t normal[3]
Definition: VoxelTriangleExtraction.h:24
VoxelUtils::triangle::GetVN
vn GetVN(int which)
Definition: VoxelTriangleExtraction.h:29
VoxelGrid.h
std
Definition: CanonicalGraphEnvironment.h:26
std::hash< VoxelUtils::vn >::operator()
size_t operator()(const VoxelUtils::vn &x) const
Definition: VoxelTriangleExtraction.h:70
VoxelUtils::GetTriangles
void GetTriangles(VoxelGrid *s, std::vector< triangle > &data)
Definition: VoxelTriangleExtraction.cpp:73
VoxelUtils::operator==
bool operator==(const triangle &a, const triangle &b)
Definition: VoxelTriangleExtraction.cpp:31