[Bf-blender-cvs] [e2aa1018fbb] soc-2020-soft-body: fixed segfail if ctrl z
mattoverby
noreply at git.blender.org
Tue Aug 11 22:09:35 CEST 2020
Commit: e2aa1018fbb4161e0f0217398c5209d385cb7f17
Author: mattoverby
Date: Tue Aug 11 15:09:29 2020 -0500
Branches: soc-2020-soft-body
https://developer.blender.org/rBe2aa1018fbb4161e0f0217398c5209d385cb7f17
fixed segfail if ctrl z
===================================================================
M extern/softbody/src/admmpd_bvh.h
M extern/softbody/src/admmpd_bvh_traverse.cpp
M extern/softbody/src/admmpd_bvh_traverse.h
M extern/softbody/src/admmpd_geom.cpp
M extern/softbody/src/admmpd_geom.h
M extern/softbody/src/admmpd_linsolve.h
M intern/softbody/admmpd_api.h
M source/blender/blenkernel/intern/softbody.c
===================================================================
diff --git a/extern/softbody/src/admmpd_bvh.h b/extern/softbody/src/admmpd_bvh.h
index bf26d14cdd5..56844a056fb 100644
--- a/extern/softbody/src/admmpd_bvh.h
+++ b/extern/softbody/src/admmpd_bvh.h
@@ -99,11 +99,8 @@ public:
// Removes all BVH data
void clear();
- // Creates the Octree up to depth with smart subdivision
- // (only create children if it contains prims) and does not
- // create a cell if it is outside the mesh.
- // ** Assumes a closed mesh and only defined for 3D
- // eps is added to the min and max of the boxes.
+ // Creates the Octree up to stopdepth. Only boxes containing
+ // faces are subdivided up to the depth.
void init(const MatrixXT *V, const Eigen::MatrixXi *F, int stopdepth);
// Returns bounding box of the root node
diff --git a/extern/softbody/src/admmpd_bvh_traverse.cpp b/extern/softbody/src/admmpd_bvh_traverse.cpp
index 310042fcf05..6d55241d793 100644
--- a/extern/softbody/src/admmpd_bvh_traverse.cpp
+++ b/extern/softbody/src/admmpd_bvh_traverse.cpp
@@ -12,80 +12,6 @@
namespace admmpd {
using namespace Eigen;
-template <typename T>
-RayClosestHit<T>::RayClosestHit(
- const VecType &orig_,
- const VecType &dir_,
- const MatrixXType *prim_verts_,
- const Eigen::MatrixXi *tri_inds_,
- T eps_,
- T t_min_,
- T t_max_) :
- o(orig_),
- d(dir_),
- prim_verts(prim_verts_),
- tri_inds(tri_inds_),
- eps(eps_),
- t_min(t_min_)
-{
- output.t_max = t_max_;
- BLI_assert(prim_verts != NULL);
- BLI_assert(tri_inds != NULL);
- BLI_assert(prim_verts->cols()==3);
- BLI_assert(tri_inds->cols()==3);
-}
-
-template <typename T>
-void RayClosestHit<T>::traverse(
- const AABB &left_aabb, bool &go_left,
- const AABB &right_aabb, bool &go_right,
- bool &go_left_first)
-{
- go_left = geom::ray_aabb<T>(o,d,left_aabb,t_min,output.t_max) ||
- (eps > 0 ? left_aabb.exteriorDistance(o) < eps : false);
- go_right = geom::ray_aabb<T>(o,d,right_aabb,t_min,output.t_max) ||
- (eps > 0 ? right_aabb.exteriorDistance(o) < eps : false);
- (void)(go_left_first);
-}
-
-template <typename T>
-bool RayClosestHit<T>::stop_traversing(const AABB &aabb, int prim)
-{
- BLI_assert(prim > 0);
- BLI_assert(prim < tri_inds->rows());
- if (!geom::ray_aabb<T>(o,d,aabb,t_min,output.t_max))
- return true;
- RowVector3i p = tri_inds->row(prim);
- VecType v[3] = {
- prim_verts->row(p[0]),
- prim_verts->row(p[1]),
- prim_verts->row(p[2])
- };
- T t_max = output.t_max;
- VecType bary;
- bool hit = geom::ray_triangle<T>(o,d,v[0],v[1],v[2],t_min,t_max,&bary);
- if (hit)
- {
- output.prim = prim;
- output.t_max = t_max;
- output.barys = bary;
- return false;
- }
- if (eps > 0)
- {
- VecType o_on_tri = geom::point_on_triangle<T>(o,v[0],v[1],v[2]);
- T dist = (o-o_on_tri).norm();
- if (dist < eps)
- {
- output.prim = prim;
- output.t_max = dist;
- output.barys = geom::point_triangle_barys<T>(o_on_tri,v[0],v[1],v[2]);
- }
- }
- return false;
-}
-
-
template <typename T>
void PointInTetMeshTraverse<T>::traverse(
const AABB &left_aabb, bool &go_left,
@@ -132,12 +58,7 @@ bool PointInTetMeshTraverse<T>::stop_traversing(
prim_verts->row(t[3])
};
- bool hit = geom::point_in_tet(
- point.template cast<double>(),
- v[0].template cast<double>(),
- v[1].template cast<double>(),
- v[2].template cast<double>(),
- v[3].template cast<double>());
+ bool hit = geom::point_in_tet<T>(point, v[0], v[1], v[2], v[3]);
if (hit)
output.prim = prim;
@@ -377,8 +298,6 @@ bool TetIntersectsMeshTraverse<T>::stop_traversing(
} // end point in mesh stop traversing
// Compile template types
-template class admmpd::RayClosestHit<double>;
-template class admmpd::RayClosestHit<float>;
template class admmpd::PointInTetMeshTraverse<double>;
template class admmpd::PointInTetMeshTraverse<float>;
template class admmpd::PointInTriangleMeshTraverse<double>;
diff --git a/extern/softbody/src/admmpd_bvh_traverse.h b/extern/softbody/src/admmpd_bvh_traverse.h
index ae122525d0a..a1e217e9ff8 100644
--- a/extern/softbody/src/admmpd_bvh_traverse.h
+++ b/extern/softbody/src/admmpd_bvh_traverse.h
@@ -33,51 +33,6 @@ public:
virtual bool stop_traversing(const AABB &aabb, int prim) = 0;
};
-// Closest hit BVH traversal.
-template <typename T>
-class RayClosestHit : public Traverser<T,3>
-{
-protected:
- using typename Traverser<T,3>::AABB;
- typedef Eigen::Matrix<T,3,1> VecType;
- typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> MatrixXType;
-
- VecType o, d;
- const MatrixXType *prim_verts;
- const Eigen::MatrixXi *tri_inds;
- T eps;
- T t_min;
-
-public:
- struct Output {
- int prim; // -1 if no intersections
- T t_max;
- VecType barys;
- Output() :
- prim(-1),
- t_max(std::numeric_limits<T>::max()),
- barys(VecType::Zero())
- {}
- } output;
-
- RayClosestHit(
- const VecType &orig_, // ray origin
- const VecType &dir_, // normalized ray direction
- const MatrixXType *prim_verts_,
- const Eigen::MatrixXi *tri_inds_,
- T eps_, // if dist(0,tri) < eps, is a hit. eps<=0 skips this test
- T t_min_=0,
- T t_max_=std::numeric_limits<T>::max());
-
- void traverse(
- const AABB &left_aabb, bool &go_left,
- const AABB &right_aabb, bool &go_right,
- bool &go_left_first);
-
- // Searches for closest hit, so always returns false
- bool stop_traversing(const AABB &aabb, int prim);
-};
-
// Point in tet mesh traversal
template <typename T>
class PointInTetMeshTraverse : public Traverser<T,3>
diff --git a/extern/softbody/src/admmpd_geom.cpp b/extern/softbody/src/admmpd_geom.cpp
index 839e4ebd581..3947ec06c76 100644
--- a/extern/softbody/src/admmpd_geom.cpp
+++ b/extern/softbody/src/admmpd_geom.cpp
@@ -39,21 +39,22 @@ Matrix<T,4,1> geom::point_tet_barys(
// Checks that it's on the "correct" side of the normal
// for each face of the tet. Assumes winding points inward.
+template <typename T>
bool geom::point_in_tet(
- const Vector3d &p,
- const Vector3d &a,
- const Vector3d &b,
- const Vector3d &c,
- const Vector3d &d)
+ const Matrix<T,3,1> &p,
+ const Matrix<T,3,1> &a,
+ const Matrix<T,3,1> &b,
+ const Matrix<T,3,1> &c,
+ const Matrix<T,3,1> &d)
{
auto check_face = [](
- const Vector3d &point,
- const Vector3d &p0,
- const Vector3d &p1,
- const Vector3d &p2,
- const Vector3d &p3 )
+ const Matrix<T,3,1> &point,
+ const Matrix<T,3,1> &p0,
+ const Matrix<T,3,1> &p1,
+ const Matrix<T,3,1> &p2,
+ const Matrix<T,3,1> &p3 )
{
- Vector3d n = (p1-p0).cross(p2-p0);
+ Matrix<T,3,1> n = (p1-p0).cross(p2-p0);
double dp3 = n.dot(p3-p0);
double dp = n.dot(point-p0);
return (dp3*dp >= 0);
@@ -65,23 +66,24 @@ bool geom::point_in_tet(
check_face(p, d, a, b, c);
}
+template <typename T>
void geom::create_tets_from_box(
- const Eigen::Vector3d &bmin,
- const Eigen::Vector3d &bmax,
- std::vector<Eigen::Vector3d> &verts,
+ const Eigen::Matrix<T,3,1> &bmin,
+ const Eigen::Matrix<T,3,1> &bmax,
+ std::vector<Eigen::Matrix<T,3,1> > &verts,
std::vector<Eigen::RowVector4i> &tets)
{
- std::vector<Vector3d> v = {
+ std::vector<Matrix<T,3,1>> v = {
// Top plane, clockwise looking down
bmax,
- Vector3d(bmin[0], bmax[1], bmax[2]),
- Vector3d(bmin[0], bmax[1], bmin[2]),
- Vector3d(bmax[0], bmax[1], bmin[2]),
+ Matrix<T,3,1>(bmin[0], bmax[1], bmax[2]),
+ Matrix<T,3,1>(bmin[0], bmax[1], bmin[2]),
+ Matrix<T,3,1>(bmax[0], bmax[1], bmin[2]),
// Bottom plane, clockwise looking down
- Vector3d(bmax[0], bmin[1], bmax[2]),
- Vector3d(bmin[0], bmin[1], bmax[2]),
+ Matrix<T,3,1>(bmax[0], bmin[1], bmax[2]),
+ Matrix<T,3,1>(bmin[0], bmin[1], bmax[2]),
bmin,
- Vector3d(bmax[0], bmin[1], bmin[2])
+ Matrix<T,3,1>(bmax[0], bmin[1], bmin[2])
};
// Add vertices and get indices of the box
std::vector<int> b;
@@ -470,36 +472,36 @@ bool geom::ray_triangle(
return true;
} // end ray - triangle test
+template <typename T>
void geom::merge_close_vertices(
- std::vector<Vector3d> &verts,
+ std::vector<Matrix<T,3,1> > &verts,
std::vector<RowVector4i> &tets,
- double eps)
+ T eps)
{
int nv = verts.size();
- std::vector<Vector3d> new_v(nv); // new verts
+ std::vector<Matrix<T,3,1> > new_v(nv); // new verts
std::vector<int> idx(nv,0); // index mapping
std::vector<int> visited(nv,0);
- int count = 0;
+ int curr_idx = 0;
for (int i=0; i<nv; ++i)
{
if(!visited[i])
{
+ new_v[curr_idx] = verts[i];
visited[i] = 1;
- new_v[count] = verts[i];
- idx[i] = count;
- Vector3d vi = verts[i];
+ idx[i] = curr_idx;
for (int j = i+1; j<nv; ++j)
{
- if((verts[j]-vi).norm() < eps)
+ if((verts[j]-verts[i]).norm() < eps)
{
visited[j] = 1;
- idx[j] = count;
+ idx[j] = curr_idx;
}
}
- count++;
+ curr_idx++;
}
}
- new_v.resize(count);
+ new_v.resize(curr_idx);
verts = new_v;
int nt = tets.size();
for (int i=0; i<nt; ++i)
@@ -539,26 +541,48 @@ void geom::make_n3(
//
template Eigen::Matrix<double,4,1>
admmpd::geom::point_tet_barys<double>(
- const Eigen::Vector3d&,
- const Eigen::Vector3d&, const Eigen::Vector3d&,
- const Eigen::Vector3d&, const Eigen::Vector3d&);
+ const Eigen::Matrix<double,3,1>&,
+ const Eigen::Matrix<double,3,1>&, const Eigen::Matrix<double,3,1>&,
+ const Eigen::Matrix<double,3,1>&, const Eigen::Matrix<double,3,1>&);
template Eigen::Matrix<float,4,1>
admmpd::geom::point_tet_barys<float>(
const Eigen::Vector3f&,
const Eigen::Vector3f&, const Eigen::Vector3f&,
const Eigen::Vector3f&, const Eigen::Vector3f&);
+template bool admmpd::geom::point_in_tet<double>(
+ const Matrix<double,3,1>&,
+ const Matrix<double,3,1>&,
+ const Matrix<double,3,1>&,
+ const Matrix<double,3,1>&,
+ const Matrix<double,3,1>&);
+template bool admmpd::geom::point_in_tet<float>(
+ const Matrix<float,3,1>&,
+ const Matrix<float,3,1>&,
+ const Matrix<float,3,1>&,
+ const Matrix<float,3,1>&,
+ const Matrix<float,3,1>&);
+template void geom::create_tets_from_box<double>(
+ const Eigen::Matrix<double,3,1>&,
+ const Eigen::Matrix<double,3,1>&,
+ std::vector<Eigen::Matrix<double,3,1> >&,
+ std::vector<Eigen::RowVector4i>&);
+template void geom::create_tets_from_box<float>(
+ const Eigen::Matrix<float,3,1>&,
+ const Eigen::Matrix<float,3,1>&,
+ std::vector<Eigen::Matrix<float,3,1> >&,
+ std::vector<Eigen::RowVector4i>&);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list