diff --git a/Point_set_shape_detection_3/include/CGAL/Cylinder.h b/Point_set_shape_detection_3/include/CGAL/Cylinder.h index e96ce26299c..4f15d239562 100644 --- a/Point_set_shape_detection_3/include/CGAL/Cylinder.h +++ b/Point_set_shape_detection_3/include/CGAL/Cylinder.h @@ -28,6 +28,7 @@ namespace CGAL { typedef typename Kernel::Sphere_3 Sphere_3; FT m_radius; Line m_axis; + Point m_point_on_axis; public: Cylinder() : Primitive_ab(0.1, 0.9) {m_type = CYLINDER; m_type_name ="Cylinder";} @@ -72,10 +73,10 @@ namespace CGAL { FT lineDist = n2x * Ox + n2y * Oy; m_radius = lineDist / n2x; - Point center = (m_it_Point_Normal + output[0])->first + m_radius * xDir; + m_point_on_axis = (m_it_Point_Normal + output[0])->first + m_radius * xDir; m_radius = abs(m_radius); - m_axis = Line(center, axis); + m_axis = Line(m_point_on_axis, axis); if (squared_distance((m_it_Point_Normal + output[0])->first) > m_epsilon || (cos_to_normal((m_it_Point_Normal + output[0])->first, (m_it_Point_Normal + output[0])->second) < m_normalThresh)) { m_isValid = false; @@ -105,7 +106,7 @@ namespace CGAL { std::string type_str() const {return m_type_name;} - void parameters(InputConstIterator first, std::vector> ¶meterSpace, const std::vector &indices) const { + void parameters(InputConstIterator first, std::vector> ¶meterSpace, const std::vector &indices, FT min[2], FT max[2]) const { Vector d1 = Vector(0, 0, 1); Vector a = m_axis.to_vector(); a = a * (1.0 / sqrt(a.squared_length())); @@ -124,8 +125,24 @@ namespace CGAL { d1 = CGAL::cross_product(m_axis.to_vector(), d2); d1 = d1 * (1.0 / sqrt(d1.squared_length())); + // first one separate for initializing min/max + Vector vec = first[indices[0]].first - m_point_on_axis; + FT v = vec * a; + vec = vec - ((vec * a) * a); + vec = vec * (1.0 / sqrt(vec.squared_length())); + + FT a1 = acos(vec * d1); + FT a2 = acos(vec * d2); + + FT u = (a2 < M_PI_2) ? 2 * M_PI - a1 : a1; + + parameterSpace[0] = std::pair(u, v); + + min[0] = max[0] = u; + min[1] = max[1] = v; + for (unsigned int i = 0;i(min[0], u); + max[0] = std::max(max[0], u); + min[1] = std::min(min[1], v); + max[1] = std::max(max[1], v); + parameterSpace[i] = std::pair(u, v); } @@ -145,7 +167,7 @@ namespace CGAL { //V length of axis in box? not enough FT maxLambda = std::numeric_limits::max(), minLambda = -std::numeric_limits::max(); Vector a = m_axis.to_vector(); - Point p = m_axis.point(); + Point p = m_point_on_axis; for (unsigned int i = 0;i<3;i++) { if (abs(a[i]) > 0.001) { @@ -178,23 +200,13 @@ namespace CGAL { std::cout << "Cylinder::pointOnPrimitive() construction failed!" << std::endl; } } - return m_axis.point() + d2 * m_radius / sqrt(l); + return m_point_on_axis + d2 * m_radius / sqrt(l); } -/* - Point projection() const { - return projection(pointOnPrimitive()); - } - - Point projection(const Point &_p) const { - std::cout << "Cylinder::projection() is not yet implemented!" << std::endl; - return m_sphere.center(); - }*/ - FT squared_distance(const Point &_p) const { Vector a = m_axis.to_vector(); a = a * (1.0 / sqrt(a.squared_length())); - Vector v = _p - m_axis.point(); + Vector v = _p - m_point_on_axis; v = v - ((v * a) * a); FT d = sqrt(v.squared_length()) - m_radius; return d * d; @@ -205,7 +217,7 @@ namespace CGAL { a = a * (1.0 / sqrt(a.squared_length())); for (unsigned int i = 0;i> ¶meterSpace, const std::vector &indices) const { - for (unsigned int i = 0;i> ¶meterSpace, const std::vector &indices, FT min[2], FT max[2]) const { + Vector p = (first[indices[0]].first - m_point_on_primitive); FT u = p * m_base1; FT v = p * m_base2; + parameterSpace[0] = std::pair(u, v); + min[0] = max[0] = u; + min[1] = max[1] = v; + + for (unsigned int i = 1;i(min[0], u); + max[0] = std::max(max[0], u); + min[1] = std::min(min[1], v); + max[1] = std::max(max[1], v); parameterSpace[i] = std::pair(u, v); } } diff --git a/Point_set_shape_detection_3/include/CGAL/Primitive.h b/Point_set_shape_detection_3/include/CGAL/Primitive.h index 03427c93a6c..89d4afc3b9d 100644 --- a/Point_set_shape_detection_3/include/CGAL/Primitive.h +++ b/Point_set_shape_detection_3/include/CGAL/Primitive.h @@ -8,6 +8,9 @@ #include #include +extern int ccTime; +extern int ccCount; + namespace CGAL { namespace Efficient_ransac { @@ -36,8 +39,8 @@ namespace CGAL { typedef Primitive_ab Primitive; - Primitive_ab() {init();}; - Primitive_ab(FT _ep, FT _t) {m_epsilon=_ep; m_normalThresh =_t; init();}; + Primitive_ab() {init();} + Primitive_ab(FT _ep, FT _t) {m_epsilon=_ep; m_normalThresh =_t; init();} static Primitive_ab* create(int id, FT _m_epsilon = 0.9f, FT _normalThresh = 0.9f); enum TYPE : int {PLANE = 0, SPHERE = 1, CYLINDER = 2, CONE = 3, TORUS = 4}; @@ -57,6 +60,7 @@ namespace CGAL { FT m_sum_ExpectedValue; int m_nb_subset_used; //count the number of subset used so far for the score, and thus indicate the next one to use + bool m_hasConnectedComponent; std::vector m_indices; //indices of the points fitting to the candidate @@ -78,8 +82,6 @@ namespace CGAL { void save(const char* _n, const inputIterator _data/*, const bool _withAllPoints = false*/) { std::ofstream plyFile(_n); - std::cout << "saving " << _n << std::endl; - std::cout << plyFile.is_open() << std::endl; plyFile << "ply" << std::endl; plyFile << "format ascii 1.0" << std::endl; @@ -114,7 +116,7 @@ namespace CGAL { virtual void cos_to_normal(InputConstIterator first, std::vector &angles, const std::vector &shapeIndex, const std::vector &indices) const = 0; virtual void parameterExtend(const Point ¢er, FT width, FT min[2], FT max[2]) const = 0; - virtual void parameters(InputConstIterator first, std::vector> ¶meterSpace, const std::vector &indices) const = 0; + virtual void parameters(InputConstIterator first, std::vector> ¶meterSpace, const std::vector &indices, FT min[2], FT max[2]) const = 0; unsigned int connectedComponent(InputConstIterator first, FT m_bitmapEpsilon, const Point ¢er, FT width); @@ -141,6 +143,7 @@ namespace CGAL { void init() { m_isValid = true; + m_hasConnectedComponent = false; m_score = 0; m_nb_subset_used = 0; m_sum_ExpectedValue = 0; @@ -246,11 +249,24 @@ namespace CGAL { unsigned int Primitive_ab::connectedComponent(InputConstIterator first, FT m_bitmapEpsilon, const Point ¢er, FT width) { if (m_indices.size() == 0) return 0; + +// if (m_hasConnectedComponent) +// return m_score; + + m_hasConnectedComponent = true; if (!supportsConnectedComponent()) return m_indices.size(); + ccCount++; + clock_t s, e; + s = clock(); + FT min[2], max[2]; - parameterExtend(center, width, min, max); + //parameterExtend(center, width, min, max); + std::vector> parameterSpace; + parameterSpace.resize(m_indices.size()); + + parameters(first, parameterSpace, m_indices, min, max); int iMin[2], iMax[2]; iMin[0] = min[0] / m_bitmapEpsilon; iMin[1] = min[1] / m_bitmapEpsilon; @@ -267,11 +283,6 @@ namespace CGAL { int maxIndex = uExtend * vExtend; - std::vector> parameterSpace; - parameterSpace.resize(m_indices.size()); - - parameters(first, parameterSpace, m_indices); - bool wrapU = wrapsU(); bool wrapV = wrapsV(); @@ -380,7 +391,10 @@ namespace CGAL { m_indices = cluster[maxCluster]; - return m_indices.size(); + e = clock(); + ccTime += e - s; + + return m_score = m_indices.size(); } } } diff --git a/Point_set_shape_detection_3/include/CGAL/Sphere.h b/Point_set_shape_detection_3/include/CGAL/Sphere.h index 42538e46e36..f5011a41f14 100644 --- a/Point_set_shape_detection_3/include/CGAL/Sphere.h +++ b/Point_set_shape_detection_3/include/CGAL/Sphere.h @@ -117,7 +117,7 @@ namespace CGAL { return m_sphere.center() + Vector(0, 0, sqrt(m_sphere.squared_radius())); } - void parameters(InputConstIterator first, std::vector> ¶meterSpace, const std::vector &indices) const { + void parameters(InputConstIterator first, std::vector> ¶meterSpace, const std::vector &indices, FT min[2], FT max[2]) const { } void parameterExtend(const Point ¢er, FT width, FT min[2], FT max[2]) const {