Skip to content

Commit

Permalink
removed tetrahedra option form vhacd
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJerez committed Mar 10, 2025
1 parent 1c33f19 commit 0c36adf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 819 deletions.
75 changes: 9 additions & 66 deletions newton-4.00/thirdParty/hacd/src/VHACD_Lib/inc/vhacdVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,67 +148,6 @@ namespace nd_
Vec3<double> m_barycenterPCA;
};

struct Tetrahedron {
public:
Vec3<double> m_pts[4];
unsigned char m_data;
};

//!
class TetrahedronSet : public PrimitiveSet {
friend class Volume;

public:
//! Destructor.
~TetrahedronSet(void);
//! Constructor.
TetrahedronSet();

size_t GetNPrimitives() const { return m_tetrahedra.Size(); }
size_t GetNPrimitivesOnSurf() const { return m_numTetrahedraOnSurface; }
size_t GetNPrimitivesInsideSurf() const { return m_numTetrahedraInsideSurface; }
const Vec3<double>& GetMinBB() const { return m_minBB; }
const Vec3<double>& GetMaxBB() const { return m_maxBB; }
const Vec3<double>& GetBarycenter() const { return m_barycenter; }
double GetEigenValue(AXIS axis) const { return m_D[axis][axis]; }
double GetSacle() const { return m_scale; }
double ComputeVolume() const;
double ComputeMaxVolumeError() const;
void ComputeConvexHull(Mesh& meshCH, const size_t sampling = 1) const;
void ComputePrincipalAxes();
void AlignToPrincipalAxes();
void RevertAlignToPrincipalAxes();
void Clip(const Plane& plane, PrimitiveSet* const positivePart, PrimitiveSet* const negativePart) const;
void Intersect(const Plane& plane, SArray<Vec3<double> >* const positivePts,
SArray<Vec3<double> >* const negativePts, const size_t sampling) const;
void ComputeExteriorPoints(const Plane& plane, const Mesh& mesh,
SArray<Vec3<double> >* const exteriorPts) const;
void ComputeClippedVolumes(const Plane& plane, double& positiveVolume, double& negativeVolume) const;
void SelectOnSurface(PrimitiveSet* const onSurfP) const;
void ComputeBB();
void Convert(Mesh& mesh, const VOXEL_VALUE value) const;
inline bool Add(Tetrahedron& tetrahedron);
PrimitiveSet* Create() const
{
return new TetrahedronSet();
}
static const double EPS;

private:
void GetPointArray(std::vector<Vec3<double> >& points) const;
void AddClippedTetrahedra(const Vec3<double>(&pts)[10], const int32_t nPts);

size_t m_numTetrahedraOnSurface;
size_t m_numTetrahedraInsideSurface;
double m_scale;
Vec3<double> m_minBB;
Vec3<double> m_maxBB;
Vec3<double> m_barycenter;
SArray<Tetrahedron, 8> m_tetrahedra;
double m_Q[3][3];
double m_D[3][3];
};

//!
class Volume {
public:
Expand Down Expand Up @@ -241,7 +180,6 @@ namespace nd_
size_t GetNPrimitivesInsideSurf() const { return m_numVoxelsInsideSurface; }
void Convert(Mesh& mesh, const VOXEL_VALUE value) const;
void Convert(VoxelSet& vset) const;
void Convert(TetrahedronSet& tset) const;
void AlignToPrincipalAxes(double(&rot)[3][3]) const;

private:
Expand Down Expand Up @@ -400,22 +338,27 @@ namespace nd_
++j1;
if (k1 < m_dim[2])
++k1;
for (size_t i = i0; i < i1; ++i) {
for (size_t i = i0; i < i1; ++i)
{
boxcenter[0] = (double)i;
for (size_t j = j0; j < j1; ++j) {
for (size_t j = j0; j < j1; ++j)
{
boxcenter[1] = (double)j;
for (size_t k = k0; k < k1; ++k) {
for (size_t k = k0; k < k1; ++k)
{
boxcenter[2] = (double)k;
int32_t res = TriBoxOverlap(boxcenter, boxhalfsize, p[0], p[1], p[2]);
unsigned char& value = GetVoxel(i, j, k);
if (res == 1 && value == PRIMITIVE_UNDEFINED) {
if (res == 1 && value == PRIMITIVE_UNDEFINED)
{
value = PRIMITIVE_ON_SURFACE;
++m_numVoxelsOnSurface;
}
}
}
}
}

FillOutsideSurface(0, 0, 0, m_dim[0], m_dim[1], 1);
FillOutsideSurface(0, 0, m_dim[2] - 1, m_dim[0], m_dim[1], m_dim[2]);
FillOutsideSurface(0, 0, 0, m_dim[0], 1, m_dim[2]);
Expand Down
2 changes: 0 additions & 2 deletions newton-4.00/thirdParty/hacd/src/VHACD_Lib/public/VHACD.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ namespace nd_
m_alpha = 0.05;
m_beta = 0.05;
m_pca = 0;
m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based
m_maxNumVerticesPerCH = 64;
m_minVolumePerCH = 0.0001;
m_callback = 0;
Expand All @@ -138,7 +137,6 @@ namespace nd_
uint32_t m_planeDownsampling;
uint32_t m_convexhullDownsampling;
uint32_t m_pca;
uint32_t m_mode;
uint32_t m_convexhullApproximation;
uint32_t m_maxConvexHulls;
bool m_projectHullVertices;
Expand Down
127 changes: 8 additions & 119 deletions newton-4.00/thirdParty/hacd/src/VHACD_Lib/src/VHACD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,9 @@ namespace nd_
}

Update(0.0, 0.0, params);
if (params.m_mode == 0) {
VoxelSet* vset = new VoxelSet;
m_volume->Convert(*vset);
m_pset = vset;
}
else {
TetrahedronSet* tset = new TetrahedronSet;
m_volume->Convert(*tset);
m_pset = tset;
}
VoxelSet* vset = new VoxelSet;
m_volume->Convert(*vset);
m_pset = vset;

delete m_volume;
m_volume = 0;
Expand Down Expand Up @@ -192,50 +185,7 @@ namespace nd_
planes.PushBack(plane);
}
}
void ComputeAxesAlignedClippingPlanes(const TetrahedronSet& tset, const short downsampling, SArray<Plane>& planes)
{
const Vec3<double> minV = tset.GetMinBB();
const Vec3<double> maxV = tset.GetMaxBB();
const double scale = tset.GetSacle();
const short i0 = 0;
const short j0 = 0;
const short k0 = 0;
const short i1 = static_cast<short>((maxV[0] - minV[0]) / scale + 0.5);
const short j1 = static_cast<short>((maxV[1] - minV[1]) / scale + 0.5);
const short k1 = static_cast<short>((maxV[2] - minV[2]) / scale + 0.5);

Plane plane;
plane.m_a = 1.0;
plane.m_b = 0.0;
plane.m_c = 0.0;
plane.m_axis = AXIS_X;
for (short i = i0; i <= i1; i += downsampling) {
double x = minV[0] + scale * i;
plane.m_d = -x;
plane.m_index = i;
planes.PushBack(plane);
}
plane.m_a = 0.0;
plane.m_b = 1.0;
plane.m_c = 0.0;
plane.m_axis = AXIS_Y;
for (short j = j0; j <= j1; j += downsampling) {
double y = minV[1] + scale * j;
plane.m_d = -y;
plane.m_index = j;
planes.PushBack(plane);
}
plane.m_a = 0.0;
plane.m_b = 0.0;
plane.m_c = 1.0;
plane.m_axis = AXIS_Z;
for (short k = k0; k <= k1; k += downsampling) {
double z = minV[2] + scale * k;
plane.m_d = -z;
plane.m_index = k;
planes.PushBack(plane);
}
}
void RefineAxesAlignedClippingPlanes(const VoxelSet& vset, const Plane& bestPlane, const short downsampling,
SArray<Plane>& planes)
{
Expand Down Expand Up @@ -287,57 +237,7 @@ namespace nd_
}
}
}
void RefineAxesAlignedClippingPlanes(const TetrahedronSet& tset, const Plane& bestPlane, const short downsampling,
SArray<Plane>& planes)
{
const Vec3<double> minV = tset.GetMinBB();
const Vec3<double> maxV = tset.GetMaxBB();
const double scale = tset.GetSacle();
Plane plane;

if (bestPlane.m_axis == AXIS_X) {
const short i0 = MAX(0, bestPlane.m_index - downsampling);
const short i1 = static_cast<short>(MIN((maxV[0] - minV[0]) / scale + 0.5, bestPlane.m_index + downsampling));
plane.m_a = 1.0;
plane.m_b = 0.0;
plane.m_c = 0.0;
plane.m_axis = AXIS_X;
for (short i = i0; i <= i1; ++i) {
double x = minV[0] + scale * i;
plane.m_d = -x;
plane.m_index = i;
planes.PushBack(plane);
}
}
else if (bestPlane.m_axis == AXIS_Y) {
const short j0 = MAX(0, bestPlane.m_index - downsampling);
const short j1 = static_cast<short>(MIN((maxV[1] - minV[1]) / scale + 0.5, bestPlane.m_index + downsampling));
plane.m_a = 0.0;
plane.m_b = 1.0;
plane.m_c = 0.0;
plane.m_axis = AXIS_Y;
for (short j = j0; j <= j1; ++j) {
double y = minV[1] + scale * j;
plane.m_d = -y;
plane.m_index = j;
planes.PushBack(plane);
}
}
else {
const short k0 = MAX(0, bestPlane.m_index - downsampling);
const short k1 = static_cast<short>(MIN((maxV[2] - minV[2]) / scale + 0.5, bestPlane.m_index + downsampling));
plane.m_a = 0.0;
plane.m_b = 0.0;
plane.m_c = 1.0;
plane.m_axis = AXIS_Z;
for (short k = k0; k <= k1; ++k) {
double z = minV[2] + scale * k;
plane.m_d = -z;
plane.m_index = k;
planes.PushBack(plane);
}
}
}
inline double ComputeLocalConcavity(const double volume, const double volumeCH)
{
return fabs(volumeCH - volume) / volumeCH;
Expand Down Expand Up @@ -642,14 +542,9 @@ namespace nd_
Vec3<double> preferredCuttingDirection;
double w = ComputePreferredCuttingDirection(pset, preferredCuttingDirection);
planes.Resize(0);
if (params.m_mode == 0) {
VoxelSet* vset = (VoxelSet*)pset;
ComputeAxesAlignedClippingPlanes(*vset, short(params.m_planeDownsampling), planes);
}
else {
TetrahedronSet* tset = (TetrahedronSet*)pset;
ComputeAxesAlignedClippingPlanes(*tset, short(params.m_planeDownsampling), planes);
}

//VoxelSet* vset = (VoxelSet*)pset;
ComputeAxesAlignedClippingPlanes(*((VoxelSet*)pset), short(params.m_planeDownsampling), planes);

if (params.m_logger) {
msg.str("");
Expand All @@ -675,14 +570,8 @@ namespace nd_
if (!m_cancel && (params.m_planeDownsampling > 1 || params.m_convexhullDownsampling > 1)) {
planesRef.Resize(0);

if (params.m_mode == 0) {
VoxelSet* vset = (VoxelSet*)pset;
RefineAxesAlignedClippingPlanes(*vset, bestPlane, short(params.m_planeDownsampling), planesRef);
}
else {
TetrahedronSet* tset = (TetrahedronSet*)pset;
RefineAxesAlignedClippingPlanes(*tset, bestPlane, short(params.m_planeDownsampling), planesRef);
}
//VoxelSet* vset = (VoxelSet*)pset;
RefineAxesAlignedClippingPlanes(*((VoxelSet*)pset), bestPlane, short(params.m_planeDownsampling), planesRef);

if (params.m_logger) {
msg.str("");
Expand Down
Loading

0 comments on commit 0c36adf

Please sign in to comment.