mirror of https://github.com/CGAL/cgal
connected component takes bitmap extend now from extracted parameters (instead from bbox)
cylinder maps sample point to axis instead of using Line::point from CGAL added some profiling to Primitive.h
This commit is contained in:
parent
b53fd21fc7
commit
a24d771308
|
|
@ -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<Kernel, inputDataType>(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<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &indices) const {
|
||||
void parameters(InputConstIterator first, std::vector<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &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,8 @@ namespace CGAL {
|
|||
d1 = CGAL::cross_product(m_axis.to_vector(), d2);
|
||||
d1 = d1 * (1.0 / sqrt(d1.squared_length()));
|
||||
|
||||
for (unsigned int i = 0;i<indices.size();i++) {
|
||||
Vector vec = first[indices[i]].first - m_axis.point();
|
||||
// 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()));
|
||||
|
|
@ -135,6 +136,27 @@ namespace CGAL {
|
|||
|
||||
FT u = (a2 < M_PI_2) ? 2 * M_PI - a1 : a1;
|
||||
|
||||
parameterSpace[0] = std::pair<FT, FT>(u, v);
|
||||
|
||||
min[0] = max[0] = u;
|
||||
min[1] = max[1] = v;
|
||||
|
||||
for (unsigned int i = 0;i<indices.size();i++) {
|
||||
Vector vec = first[indices[i]].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;
|
||||
|
||||
min[0] = std::min<FT>(min[0], u);
|
||||
max[0] = std::max<FT>(max[0], u);
|
||||
min[1] = std::min<FT>(min[1], v);
|
||||
max[1] = std::max<FT>(max[1], v);
|
||||
|
||||
parameterSpace[i] = std::pair<FT, FT>(u, v);
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +167,7 @@ namespace CGAL {
|
|||
//V length of axis in box? not enough
|
||||
FT maxLambda = std::numeric_limits<double>::max(), minLambda = -std::numeric_limits<double>::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<indices.size();i++) {
|
||||
if (shapeIndex[indices[i]] == -1) {
|
||||
Vector v = first[indices[i]].first - m_axis.point();
|
||||
Vector v = first[indices[i]].first - m_point_on_axis;
|
||||
v = v - ((v * a) * a);
|
||||
dists[i] = sqrt(v.squared_length()) - m_radius;
|
||||
dists[i] = dists[i] * dists[i];
|
||||
|
|
@ -218,10 +230,10 @@ namespace CGAL {
|
|||
a = a * (1.0 / sqrt(a.squared_length()));
|
||||
for (unsigned int i = 0;i<indices.size();i++) {
|
||||
if (shapeIndex[indices[i]] == -1) {
|
||||
Vector v = first[indices[i]].first - m_axis.point();
|
||||
Vector v = first[indices[i]].first - m_point_on_axis;
|
||||
v = v - ((v * a) * a);
|
||||
v = v * (1.0 / sqrt(v.squared_length()));
|
||||
angles[i] = v * first[indices[i]].second;
|
||||
angles[i] = abs(v * first[indices[i]].second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -229,10 +241,10 @@ namespace CGAL {
|
|||
FT cos_to_normal(const Point &_p, const Vector &_n) 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);
|
||||
v = v * (1.0 / sqrt(v.squared_length()));
|
||||
return v * _n;
|
||||
return abs(v * _n);
|
||||
}
|
||||
|
||||
virtual bool supportsConnectedComponent() {return true;}
|
||||
|
|
|
|||
|
|
@ -77,11 +77,22 @@ namespace CGAL {
|
|||
|
||||
Point pointOnPrimitive() const {return m_point_on_primitive;}
|
||||
|
||||
void parameters(InputConstIterator first, std::vector<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &indices) const {
|
||||
for (unsigned int i = 0;i<indices.size();i++) {
|
||||
Vector p = (first[indices[i]].first - m_plane.point());
|
||||
void parameters(InputConstIterator first, std::vector<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &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<FT, FT>(u, v);
|
||||
min[0] = max[0] = u;
|
||||
min[1] = max[1] = v;
|
||||
|
||||
for (unsigned int i = 1;i<indices.size();i++) {
|
||||
Vector p = (first[indices[i]].first - m_point_on_primitive);
|
||||
FT u = p * m_base1;
|
||||
FT v = p * m_base2;
|
||||
min[0] = std::min<FT>(min[0], u);
|
||||
max[0] = std::max<FT>(max[0], u);
|
||||
min[1] = std::min<FT>(min[1], v);
|
||||
max[1] = std::max<FT>(max[1], v);
|
||||
parameterSpace[i] = std::pair<FT, FT>(u, v);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
#include <CGAL/Fuzzy_sphere.h>
|
||||
#include <CGAL/Search_traits_3.h>
|
||||
|
||||
extern int ccTime;
|
||||
extern int ccCount;
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
namespace Efficient_ransac {
|
||||
|
|
@ -36,8 +39,8 @@ namespace CGAL {
|
|||
|
||||
typedef Primitive_ab<Kernel, inputDataType> 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<int> 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<FT> &angles, const std::vector<int> &shapeIndex, const std::vector<unsigned int> &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<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &indices) const = 0;
|
||||
virtual void parameters(InputConstIterator first, std::vector<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &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<Kernel, inputDataType>::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<std::pair<FT, FT>> 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<std::pair<FT, FT>> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ namespace CGAL {
|
|||
return m_sphere.center() + Vector(0, 0, sqrt(m_sphere.squared_radius()));
|
||||
}
|
||||
|
||||
void parameters(InputConstIterator first, std::vector<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &indices) const {
|
||||
void parameters(InputConstIterator first, std::vector<std::pair<FT, FT>> ¶meterSpace, const std::vector<int> &indices, FT min[2], FT max[2]) const {
|
||||
}
|
||||
|
||||
void parameterExtend(const Point ¢er, FT width, FT min[2], FT max[2]) const {
|
||||
|
|
|
|||
Loading…
Reference in New Issue