From 54e622c49ca7a550e660b3cf6a671055d4ed016d Mon Sep 17 00:00:00 2001 From: jpan <jpan@253336fb-580f-4252-a368-f3cef5a2a82b> Date: Tue, 6 Dec 2011 20:14:20 +0000 Subject: [PATCH] refactor a bit more git-svn-id: https://kforge.ros.org/fcl/fcl_ros@49 253336fb-580f-4252-a368-f3cef5a2a82b --- .../fcl/geometric_shape_to_BVH_model.h | 42 +++++++++---------- trunk/fcl/include/fcl/geometric_shapes.h | 4 +- trunk/fcl/include/fcl/motion.h | 2 +- trunk/fcl/src/AABB.cpp | 4 +- trunk/fcl/src/BVH_model.cpp | 4 +- trunk/fcl/src/BVH_utility.cpp | 24 +++++------ trunk/fcl/src/RSS.cpp | 42 +++++++++---------- trunk/fcl/src/geometric_shapes_intersect.cpp | 4 +- trunk/fcl/src/intersect.cpp | 2 +- trunk/fcl/src/matrix_3f.cpp | 6 +-- .../test_core_conservative_advancement.cpp | 8 ++-- .../fcl/test/test_core_deformable_object.cpp | 8 ++-- trunk/fcl/test/test_core_geometric_shapes.cpp | 18 ++++---- trunk/fcl/test/test_core_utility.h | 4 +- 14 files changed, 85 insertions(+), 87 deletions(-) diff --git a/trunk/fcl/include/fcl/geometric_shape_to_BVH_model.h b/trunk/fcl/include/fcl/geometric_shape_to_BVH_model.h index c721baac..914708fe 100644 --- a/trunk/fcl/include/fcl/geometric_shape_to_BVH_model.h +++ b/trunk/fcl/include/fcl/geometric_shape_to_BVH_model.h @@ -55,27 +55,27 @@ void generateBVHModel(BVHModel<BV>& model, const Box& shape) double c = shape.side[2]; std::vector<Vec3f> points(8); std::vector<Triangle> tri_indices(12); - points[0] = Vec3f(0.5 * a, -0.5 * b, 0.5 * c); - points[1] = Vec3f(0.5 * a, 0.5 * b, 0.5 * c); - points[2] = Vec3f(-0.5 * a, 0.5 * b, 0.5 * c); - points[3] = Vec3f(-0.5 * a, -0.5 * b, 0.5 * c); - points[4] = Vec3f(0.5 * a, -0.5 * b, -0.5 * c); - points[5] = Vec3f(0.5 * a, 0.5 * b, -0.5 * c); - points[6] = Vec3f(-0.5 * a, 0.5 * b, -0.5 * c); - points[7] = Vec3f(-0.5 * a, -0.5 * b, -0.5 * c); - - tri_indices[0] = Triangle(0, 4, 1); - tri_indices[1] = Triangle(1, 4, 5); - tri_indices[2] = Triangle(2, 6, 3); - tri_indices[3] = Triangle(3, 6, 7); - tri_indices[4] = Triangle(3, 0, 2); - tri_indices[5] = Triangle(2, 0, 1); - tri_indices[6] = Triangle(6, 5, 7); - tri_indices[7] = Triangle(7, 5, 4); - tri_indices[8] = Triangle(1, 5, 2); - tri_indices[9] = Triangle(2, 5, 6); - tri_indices[10] = Triangle(3, 7, 0); - tri_indices[11] = Triangle(0, 7, 4); + points[0].setValue(0.5 * a, -0.5 * b, 0.5 * c); + points[1].setValue(0.5 * a, 0.5 * b, 0.5 * c); + points[2].setValue(-0.5 * a, 0.5 * b, 0.5 * c); + points[3].setValue(-0.5 * a, -0.5 * b, 0.5 * c); + points[4].setValue(0.5 * a, -0.5 * b, -0.5 * c); + points[5].setValue(0.5 * a, 0.5 * b, -0.5 * c); + points[6].setValue(-0.5 * a, 0.5 * b, -0.5 * c); + points[7].setValue(-0.5 * a, -0.5 * b, -0.5 * c); + + tri_indices[0].set(0, 4, 1); + tri_indices[1].set(1, 4, 5); + tri_indices[2].set(2, 6, 3); + tri_indices[3].set(3, 6, 7); + tri_indices[4].set(3, 0, 2); + tri_indices[5].set(2, 0, 1); + tri_indices[6].set(6, 5, 7); + tri_indices[7].set(7, 5, 4); + tri_indices[8].set(1, 5, 2); + tri_indices[9].set(2, 5, 6); + tri_indices[10].set(3, 7, 0); + tri_indices[11].set(0, 7, 4); for(unsigned int i = 0; i < points.size(); ++i) { diff --git a/trunk/fcl/include/fcl/geometric_shapes.h b/trunk/fcl/include/fcl/geometric_shapes.h index ac3c771a..dc9d6ead 100644 --- a/trunk/fcl/include/fcl/geometric_shapes.h +++ b/trunk/fcl/include/fcl/geometric_shapes.h @@ -290,10 +290,8 @@ public: Plane(const Vec3f& n_, BVH_REAL d_) : ShapeBase(), n(n_), d(d_) { unitNormalTest(); } /** \brief Construct a plane with normal direction and offset */ - Plane(BVH_REAL a, BVH_REAL b, BVH_REAL c, BVH_REAL d_) + Plane(BVH_REAL a, BVH_REAL b, BVH_REAL c, BVH_REAL d_) : n(a, b, c), d(d_) { - n = Vec3f(a, b, c); - d = d_; unitNormalTest(); } diff --git a/trunk/fcl/include/fcl/motion.h b/trunk/fcl/include/fcl/motion.h index 6c10a221..450799db 100644 --- a/trunk/fcl/include/fcl/motion.h +++ b/trunk/fcl/include/fcl/motion.h @@ -319,7 +319,7 @@ public: ScrewMotion() { /** Default angular velocity is zero */ - axis = Vec3f(1, 0, 0); + axis.setValue(1, 0, 0); angular_vel = 0; /** Default reference point is local zero point */ diff --git a/trunk/fcl/src/AABB.cpp b/trunk/fcl/src/AABB.cpp index 62ae193b..2cd8ebd2 100644 --- a/trunk/fcl/src/AABB.cpp +++ b/trunk/fcl/src/AABB.cpp @@ -45,8 +45,8 @@ namespace fcl AABB::AABB() { BVH_REAL real_max = std::numeric_limits<BVH_REAL>::max(); - min_ = Vec3f(real_max, real_max, real_max); - max_ = Vec3f(-real_max, -real_max, -real_max); + min_.setValue(real_max, real_max, real_max); + max_.setValue(-real_max, -real_max, -real_max); } BVH_REAL AABB::distance(const AABB& other, Vec3f* P, Vec3f* Q) const diff --git a/trunk/fcl/src/BVH_model.cpp b/trunk/fcl/src/BVH_model.cpp index ffe14778..acae3c66 100644 --- a/trunk/fcl/src/BVH_model.cpp +++ b/trunk/fcl/src/BVH_model.cpp @@ -234,7 +234,7 @@ int BVHModel<BV>::addTriangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3) num_tris_allocated *= 2; } - tri_indices[num_tris] = Triangle(offset, offset + 1, offset + 2); + tri_indices[num_tris].set(offset, offset + 1, offset + 2); return BVH_OK; } @@ -329,7 +329,7 @@ int BVHModel<BV>::addSubModel(const std::vector<Vec3f>& ps, const std::vector<Tr for(int i = 0; i < num_tris_to_add; ++i) { const Triangle& t = ts[i]; - tri_indices[num_tris] = Triangle(t[0] + offset, t[1] + offset, t[2] + offset); + tri_indices[num_tris].set(t[0] + offset, t[1] + offset, t[2] + offset); num_tris++; } diff --git a/trunk/fcl/src/BVH_utility.cpp b/trunk/fcl/src/BVH_utility.cpp index 81ae732a..e4872395 100644 --- a/trunk/fcl/src/BVH_utility.cpp +++ b/trunk/fcl/src/BVH_utility.cpp @@ -862,15 +862,15 @@ void getExtentAndCenter(Vec3f* ps, Vec3f* ps2, unsigned int* indices, int n, Vec } } - Vec3f o = Vec3f((max_coord[0] + min_coord[0]) / 2, - (max_coord[1] + min_coord[1]) / 2, - (max_coord[2] + min_coord[2]) / 2); + Vec3f o((max_coord[0] + min_coord[0]) / 2, + (max_coord[1] + min_coord[1]) / 2, + (max_coord[2] + min_coord[2]) / 2); center = axis[0] * o[0] + axis[1] * o[1] + axis[2] * o[2]; - extent = Vec3f((max_coord[0] - min_coord[0]) / 2, - (max_coord[1] - min_coord[1]) / 2, - (max_coord[2] - min_coord[2]) / 2); + extent.setValue((max_coord[0] - min_coord[0]) / 2, + (max_coord[1] - min_coord[1]) / 2, + (max_coord[2] - min_coord[2]) / 2); } @@ -931,15 +931,15 @@ void getExtentAndCenter(Vec3f* ps, Vec3f* ps2, Triangle* ts, unsigned int* indic } } - Vec3f o = Vec3f((max_coord[0] + min_coord[0]) / 2, - (max_coord[1] + min_coord[1]) / 2, - (max_coord[2] + min_coord[2]) / 2); + Vec3f o((max_coord[0] + min_coord[0]) / 2, + (max_coord[1] + min_coord[1]) / 2, + (max_coord[2] + min_coord[2]) / 2); center = axis[0] * o[0] + axis[1] * o[1] + axis[2] * o[2]; - extent = Vec3f((max_coord[0] - min_coord[0]) / 2, - (max_coord[1] - min_coord[1]) / 2, - (max_coord[2] - min_coord[2]) / 2); + extent.setValue((max_coord[0] - min_coord[0]) / 2, + (max_coord[1] - min_coord[1]) / 2, + (max_coord[2] - min_coord[2]) / 2); } diff --git a/trunk/fcl/src/RSS.cpp b/trunk/fcl/src/RSS.cpp index 5c30c0c2..45178990 100644 --- a/trunk/fcl/src/RSS.cpp +++ b/trunk/fcl/src/RSS.cpp @@ -67,7 +67,7 @@ bool overlap(const Matrix3f& R0, const Vec3f& T0, const RSS& b1, const RSS& b2) R0b2.transposeDotX(b1.axis[2]), R0b2.transposeDotY(b1.axis[2]), R0b2.transposeDotZ(b1.axis[2])); Vec3f Ttemp = R0 * b2.Tr + T0 - b1.Tr; - Vec3f T = Vec3f(Ttemp.dot(b1.axis[0]), Ttemp.dot(b1.axis[1]), Ttemp.dot(b1.axis[2])); + Vec3f T(Ttemp.dot(b1.axis[0]), Ttemp.dot(b1.axis[1]), Ttemp.dot(b1.axis[2])); BVH_REAL dist = RSS::rectDistance(R, T, b1.l, b2.l); if(dist <= (b1.r + b2.r)) return true; @@ -349,7 +349,7 @@ BVH_REAL distance(const Matrix3f& R0, const Vec3f& T0, const RSS& b1, const RSS& Vec3f Ttemp = R0 * b2.Tr + T0 - b1.Tr; - Vec3f T = Vec3f(Ttemp.dot(b1.axis[0]), Ttemp.dot(b1.axis[1]), Ttemp.dot(b1.axis[2])); + Vec3f T(Ttemp.dot(b1.axis[0]), Ttemp.dot(b1.axis[1]), Ttemp.dot(b1.axis[2])); BVH_REAL dist = RSS::rectDistance(R, T, b1.l, b2.l, P, Q); dist -= (b1.r + b2.r); @@ -451,7 +451,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(a[0], t, 0); + P->setValue(a[0], t, 0); *Q = S + (*P); } @@ -480,7 +480,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(a[0], t, 0); + P->setValue(a[0], t, 0); *Q = S + (*P); } @@ -508,7 +508,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(0, t, 0); + P->setValue(0, t, 0); *Q = S + (*P); } @@ -536,7 +536,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(0, t, 0); + P->setValue(0, t, 0); *Q = S + (*P); } @@ -604,7 +604,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(a[0], t, 0); + P->setValue(a[0], t, 0); *Q = S + (*P); } @@ -632,7 +632,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(a[0], t, 0); + P->setValue(a[0], t, 0); *Q = S + (*P); } @@ -661,7 +661,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(0, t, 0); + P->setValue(0, t, 0); *Q = S + (*P); } @@ -690,7 +690,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P&& Q) { - *P = Vec3f(0, t, 0); + P->setValue(0, t, 0); *Q = S + (*P); } @@ -758,7 +758,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, a[1], 0); + P->setValue(t, a[1], 0); *Q = S + (*P); } @@ -786,7 +786,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, a[1], 0); + P->setValue(t, a[1], 0); *Q = S + (*P); } @@ -814,7 +814,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, 0, 0); + P->setValue(t, 0, 0); *Q = S + (*P); } @@ -842,7 +842,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, 0, 0); + P->setValue(t, 0, 0); *Q = S + (*P); } @@ -903,7 +903,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, a[1], 0); + P->setValue(t, a[1], 0); *Q = S + (*P); } @@ -931,7 +931,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, a[1], 0); + P->setValue(t, a[1], 0); *Q = S + (*P); } @@ -960,7 +960,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, 0, 0); + P->setValue(t, 0, 0); *Q = S + (*P); } @@ -988,7 +988,7 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(P && Q) { - *P = Vec3f(t, 0, 0); + P->setValue(t, 0, 0); *Q = S + (*P); } @@ -1029,14 +1029,14 @@ BVH_REAL RSS::rectDistance(const Matrix3f& Rab, Vec3f const& Tab, const BVH_REAL if(sep1 >= sep2 && sep1 >= 0) { if(Tab[2] > 0) - S = Vec3f(0, 0, sep1); + S.setValue(0, 0, sep1); else - S = Vec3f(0, 0, -sep1); + S.setValue(0, 0, -sep1); if(P && Q) { *Q = S; - *P = Vec3f(0, 0, 0); + P->setValue(0); } } diff --git a/trunk/fcl/src/geometric_shapes_intersect.cpp b/trunk/fcl/src/geometric_shapes_intersect.cpp index 5e808cb9..2c99d86a 100644 --- a/trunk/fcl/src/geometric_shapes_intersect.cpp +++ b/trunk/fcl/src/geometric_shapes_intersect.cpp @@ -388,9 +388,9 @@ bool GJKCollide(void* obj1, ccd_support_fn supp1, ccd_center_fn cen1, res = ccdMPRPenetration(obj1, obj2, &ccd, &depth, &dir, &pos); if(res == 0) { - *contact_points = Vec3f(ccdVec3X(&pos), ccdVec3Y(&pos), ccdVec3Z(&pos)); + contact_points->setValue(ccdVec3X(&pos), ccdVec3Y(&pos), ccdVec3Z(&pos)); *penetration_depth = depth; - *normal = Vec3f(-ccdVec3X(&dir), -ccdVec3Y(&dir), -ccdVec3Z(&dir)); + normal->setValue(-ccdVec3X(&dir), -ccdVec3Y(&dir), -ccdVec3Z(&dir)); return true; } diff --git a/trunk/fcl/src/intersect.cpp b/trunk/fcl/src/intersect.cpp index a58b6a9c..325c10cb 100644 --- a/trunk/fcl/src/intersect.cpp +++ b/trunk/fcl/src/intersect.cpp @@ -1292,7 +1292,7 @@ void Intersect::singleKernelGradient(KERNEL_PARM *kernel_parm, SVECTOR *a, SVECT void Intersect::kernelGradient(KERNEL_PARM *kernel_parm, DOC *a, DOC *b, Vec3f& g) { - g = Vec3f(0, 0, 0); + g.setValue(0, 0, 0); SVECTOR *fa, *fb; Vec3f tmp; diff --git a/trunk/fcl/src/matrix_3f.cpp b/trunk/fcl/src/matrix_3f.cpp index 75f89001..d4130bbf 100644 --- a/trunk/fcl/src/matrix_3f.cpp +++ b/trunk/fcl/src/matrix_3f.cpp @@ -175,9 +175,9 @@ void matEigen(const Matrix3f& m, BVH_REAL dout[3], Vec3f vout[3]) sm += fabs(R[ip][iq]); if(sm == 0.0) { - vout[0] = Vec3f(v[0][0], v[0][1], v[0][2]); - vout[1] = Vec3f(v[1][0], v[1][1], v[1][2]); - vout[2] = Vec3f(v[2][0], v[2][1], v[2][2]); + vout[0].setValue(v[0][0], v[0][1], v[0][2]); + vout[1].setValue(v[1][0], v[1][1], v[1][2]); + vout[2].setValue(v[2][0], v[2][1], v[2][2]); dout[0] = d[0]; dout[1] = d[1]; dout[2] = d[2]; return; } diff --git a/trunk/fcl/test/test_core_conservative_advancement.cpp b/trunk/fcl/test/test_core_conservative_advancement.cpp index b90d1a9f..91dba4a6 100644 --- a/trunk/fcl/test/test_core_conservative_advancement.cpp +++ b/trunk/fcl/test/test_core_conservative_advancement.cpp @@ -435,8 +435,8 @@ bool CA_spline_Test(const Transform& tf1, const Transform& tf2, for(int i = 0; i < 4; ++i) { - Td_2[i] = Vec3f(); - Rd_2[i] = Vec3f(0, 0, 0); + Td_2[i].setValue(0); + Rd_2[i].setValue(0); } SplineMotion<RSS> motion1(Td_1[0], Td_1[1], Td_1[2], Td_1[3], @@ -501,8 +501,8 @@ bool spline_interp_Test(const Transform& tf1, const Transform& tf2, for(int i = 0; i < 4; ++i) { - Td_2[i] = Vec3f(); - Rd_2[i] = Vec3f(0, 0, 0); + Td_2[i].setValue(0); + Rd_2[i].setValue(0); } SplineMotion<RSS> motion1(Td_1[0], Td_1[1], Td_1[2], Td_1[3], diff --git a/trunk/fcl/test/test_core_deformable_object.cpp b/trunk/fcl/test/test_core_deformable_object.cpp index 1cf2bedd..a520fad1 100644 --- a/trunk/fcl/test/test_core_deformable_object.cpp +++ b/trunk/fcl/test/test_core_deformable_object.cpp @@ -335,15 +335,15 @@ bool loadPLYFile(const std::string& fileName, float scalarFactor, std::vector<Ve for(int j = 0 ; j < mesh->mNumVertices; ++j) { - vert_list[v_index + j] = Vec3f(mesh->mVertices[j].x, mesh->mVertices[j].y, mesh->mVertices[j].z); + vert_list[v_index + j].setValue(mesh->mVertices[j].x, mesh->mVertices[j].y, mesh->mVertices[j].z); } for(int j = 0; j < mesh->mNumFaces; ++j) { - tri_list[t_index + j] = Triangle(mesh->mFaces[j].mIndices[0] + v_index, - mesh->mFaces[j].mIndices[1] + v_index, - mesh->mFaces[j].mIndices[2] + v_index); + tri_list[t_index + j].set(mesh->mFaces[j].mIndices[0] + v_index, + mesh->mFaces[j].mIndices[1] + v_index, + mesh->mFaces[j].mIndices[2] + v_index); } v_index += mesh->mNumVertices; t_index += mesh->mNumFaces; diff --git a/trunk/fcl/test/test_core_geometric_shapes.cpp b/trunk/fcl/test/test_core_geometric_shapes.cpp index 9473498b..0c3eba3d 100644 --- a/trunk/fcl/test/test_core_geometric_shapes.cpp +++ b/trunk/fcl/test/test_core_geometric_shapes.cpp @@ -560,9 +560,9 @@ TEST(shapeIntersection, spheretriangle) { Sphere s(10); Vec3f t[3]; - t[0] = Vec3f(20, 0, 0); - t[1] = Vec3f(-20, 0, 0); - t[2] = Vec3f(0, 20, 0); + t[0].setValue(20, 0, 0); + t[1].setValue(-20, 0, 0); + t[2].setValue(0, 20, 0); Transform transform; generateRandomTransform(extents, transform); @@ -578,9 +578,9 @@ TEST(shapeIntersection, spheretriangle) ASSERT_TRUE(res); s.setTransform(identity.R, identity.T); - t[0] = Vec3f(30, 0, 0); - t[1] = Vec3f(10, -20, 0); - t[2] = Vec3f(10, 20, 0); + t[0].setValue(30, 0, 0); + t[1].setValue(10, -20, 0); + t[2].setValue(10, 20, 0); res = shapeTriangleIntersect(s, t[0], t[1], t[2]); ASSERT_FALSE(res); @@ -589,9 +589,9 @@ TEST(shapeIntersection, spheretriangle) ASSERT_FALSE(res); s.setTransform(identity.R, identity.T); - t[0] = Vec3f(30, 0, 0); - t[1] = Vec3f(9.9, -20, 0); - t[2] = Vec3f(9.9, 20, 0); + t[0].setValue(30, 0, 0); + t[1].setValue(9.9, -20, 0); + t[2].setValue(9.9, 20, 0); res = shapeTriangleIntersect(s, t[0], t[1], t[2]); ASSERT_TRUE(res); diff --git a/trunk/fcl/test/test_core_utility.h b/trunk/fcl/test/test_core_utility.h index fda9b524..693b6f50 100644 --- a/trunk/fcl/test/test_core_utility.h +++ b/trunk/fcl/test/test_core_utility.h @@ -341,8 +341,8 @@ inline bool distance_PQP(const Transform& tf, distance_result.distance = res.distance; - distance_result.p1 = Vec3f(res.p1[0], res.p1[1], res.p1[2]); - distance_result.p2 = Vec3f(res.p2[0], res.p2[1], res.p2[2]); + distance_result.p1.setValue(res.p1[0], res.p1[1], res.p1[2]); + distance_result.p2.setValue(res.p2[0], res.p2[1], res.p2[2]); if(verbose) -- GitLab