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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#ifndef MINISDF_H
#define MINISDF_H
#include "LinearMath/btVector3.h"
#include "LinearMath/btAabbUtil2.h"
#include "LinearMath/btAlignedObjectArray.h"
struct btMultiIndex
{
unsigned int ijk[3];
};
struct btAlignedBox3d
{
btVector3 m_min;
btVector3 m_max;
const btVector3& min() const
{
return m_min;
}
const btVector3& max() const
{
return m_max;
}
bool contains(const btVector3& x) const
{
return TestPointAgainstAabb2(m_min, m_max, x);
}
btAlignedBox3d(const btVector3& mn, const btVector3& mx)
:m_min(mn),
m_max(mx)
{
}
btAlignedBox3d()
{
}
};
struct btShapeMatrix
{
double m_vec[32];
inline double& operator[](int i)
{
return m_vec[i];
}
inline const double& operator[](int i) const
{
return m_vec[i];
}
};
struct btShapeGradients
{
btVector3 m_vec[32];
void topRowsDivide(int row, double denom)
{
for (int i=0;i<row;i++)
{
m_vec[i] /= denom;
}
}
void bottomRowsMul(int row, double val)
{
for (int i=32-row;i<32;i++)
{
m_vec[i] *= val;
}
}
inline btScalar& operator()(int i, int j)
{
return m_vec[i][j];
}
};
struct btCell32
{
unsigned int m_cells[32];
};
struct btMiniSDF
{
btAlignedBox3d m_domain;
unsigned int m_resolution[3];
btVector3 m_cell_size;
btVector3 m_inv_cell_size;
std::size_t m_n_cells;
std::size_t m_n_fields;
bool m_isValid;
btAlignedObjectArray<btAlignedObjectArray<double> > m_nodes;
btAlignedObjectArray<btAlignedObjectArray<btCell32 > > m_cells;
btAlignedObjectArray<btAlignedObjectArray<unsigned int> > m_cell_map;
btMiniSDF()
:m_isValid(false)
{
}
bool load(const char* data, int size);
bool isValid() const
{
return m_isValid;
}
unsigned int multiToSingleIndex(btMultiIndex const & ijk) const;
btAlignedBox3d subdomain(btMultiIndex const& ijk) const;
btMultiIndex singleToMultiIndex(unsigned int l) const;
btAlignedBox3d subdomain(unsigned int l) const;
btShapeMatrix
shape_function_(btVector3 const& xi, btShapeGradients* gradient = 0) const;
bool interpolate(unsigned int field_id, double& dist, btVector3 const& x, btVector3* gradient) const;
};
#endif //MINISDF_H
|