2018-09-07 14:11:04 +00:00
|
|
|
#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)
|
2019-01-03 13:26:51 +00:00
|
|
|
: m_min(mn),
|
|
|
|
m_max(mx)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
btAlignedBox3d()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct btShapeMatrix
|
|
|
|
{
|
|
|
|
double m_vec[32];
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
inline double& operator[](int i)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
return m_vec[i];
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
inline const double& operator[](int i) const
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
return m_vec[i];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct btShapeGradients
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btVector3 m_vec[32];
|
2018-09-07 14:11:04 +00:00
|
|
|
|
|
|
|
void topRowsDivide(int row, double denom)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int i = 0; i < row; i++)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
m_vec[i] /= denom;
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2018-09-07 14:11:04 +00:00
|
|
|
void bottomRowsMul(int row, double val)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int i = 32 - row; i < 32; i++)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
m_vec[i] *= val;
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
inline btScalar& operator()(int i, int j)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
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;
|
2019-01-03 13:26:51 +00:00
|
|
|
btAlignedObjectArray<btAlignedObjectArray<btCell32> > m_cells;
|
2018-09-07 14:11:04 +00:00
|
|
|
btAlignedObjectArray<btAlignedObjectArray<unsigned int> > m_cell_map;
|
|
|
|
|
|
|
|
btMiniSDF()
|
2019-01-03 13:26:51 +00:00
|
|
|
: m_isValid(false)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
bool load(const char* data, int size);
|
|
|
|
bool isValid() const
|
|
|
|
{
|
|
|
|
return m_isValid;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
unsigned int multiToSingleIndex(btMultiIndex const& ijk) const;
|
|
|
|
|
2018-09-07 14:11:04 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //MINISDF_H
|