Exemple #1
0
void FEdgeXDetector::computeCurvatures(WXVertex *vertex){
    // CURVATURE LAYER
    // store all the curvature datas for each vertex

    real K1, K2, cos2theta, sin2theta;
    Vec3r e1, n, v;
    // one vertex curvature info :
    CurvatureInfo *C;
    float radius = _sphereRadius*_meanEdgeSize;

    // view independant stuff
    if(_computeViewIndependant){
        C = new CurvatureInfo();
        vertex->setCurvatures(C);
        OGF::NormalCycle ncycle ;
        ncycle.begin() ;
        if(radius > 0) {
            OGF::compute_curvature_tensor(vertex, radius, ncycle) ;
        } else {
            OGF::compute_curvature_tensor_one_ring(vertex, ncycle) ;
        }
        ncycle.end() ;
        C->K1 = ncycle.kmin();
        C->K2 = ncycle.kmax();
        C->e1 = ncycle.Kmax(); //ncycle.kmin() * ncycle.Kmax();
        C->e2 = ncycle.Kmin(); //ncycle.kmax() * ncycle.Kmin() ;

        real absK1 = fabs(C->K1);
        _meanK1 += absK1;
        if(absK1 > _maxK1)
            _maxK1 = absK1;
        if(absK1 < _minK1)
            _minK1 = absK1;
    }
    // view dependant
    C = vertex->curvatures();
    if(C == 0)
        return;
    
    // compute radial curvature :
    n = C->e1 ^ C->e2;
    v = _Viewpoint - vertex->GetVertex();
    C->er = v - (v * n) * n;
    C->er.normalize();
    e1 = C->e1;
    e1.normalize();
    cos2theta = C->er * e1;
    cos2theta *= cos2theta;
    sin2theta = 1 - cos2theta;
    C->Kr = C->K1 * cos2theta + C->K2 * sin2theta;
    real absKr = fabs(C->Kr);
    _meanKr += absKr;
    if(absKr > _maxKr)
        _maxKr = absKr;
    if(absKr < _minKr)
        _minKr = absKr;

    ++_nPoints;
}
void FEdgeXDetector::computeCurvatures(WXVertex *vertex)
{
	// TODO: for some reason, the 'vertex' may have no associated edges
	// (i.e., WVertex::_EdgeList is empty), which causes a crash due to
	// a subsequent call of WVertex::_EdgeList.front().
	if (vertex->GetEdges().empty()) {
		if (G.debug & G_DEBUG_FREESTYLE) {
			printf("Warning: WVertex %d has no associated edges.\n", vertex->GetId());
		}
		return;
	}

	// CURVATURE LAYER
	// store all the curvature datas for each vertex

	//soc unused - real K1, K2
	real cos2theta, sin2theta;
	Vec3r e1, n, v;
	// one vertex curvature info :
	CurvatureInfo *C;
	float radius = _sphereRadius * _meanEdgeSize;

	// view independent stuff
	if (_computeViewIndependent) {
		C = new CurvatureInfo();
		vertex->setCurvatures(C);
		OGF::NormalCycle ncycle;
		ncycle.begin();
		if (radius > 0) {
			OGF::compute_curvature_tensor(vertex, radius, ncycle);
		}
		else {
			OGF::compute_curvature_tensor_one_ring(vertex, ncycle);
		}
		ncycle.end();
		C->K1 = ncycle.kmin();
		C->K2 = ncycle.kmax();
		C->e1 = ncycle.Kmax(); //ncycle.kmin() * ncycle.Kmax();
		C->e2 = ncycle.Kmin(); //ncycle.kmax() * ncycle.Kmin();

		real absK1 = fabs(C->K1);
		_meanK1 += absK1;
		if (absK1 > _maxK1)
			_maxK1 = absK1;
		if (absK1 < _minK1)
			_minK1 = absK1;
	}
	// view dependant
	C = vertex->curvatures();
	if (C == 0)
		return;

	// compute radial curvature :
	n = C->e1 ^ C->e2;
	if (_orthographicProjection) {
		v = Vec3r(0.0, 0.0, _Viewpoint.z() - vertex->GetVertex().z());
	}
	else {
		v = Vec3r(_Viewpoint - vertex->GetVertex());
	}
	C->er = v - (v * n) * n;
	C->er.normalize();
	e1 = C->e1;
	e1.normalize();
	cos2theta = C->er * e1;
	cos2theta *= cos2theta;
	sin2theta = 1 - cos2theta;
	C->Kr = C->K1 * cos2theta + C->K2 * sin2theta;
	real absKr = fabs(C->Kr);
	_meanKr += absKr;
	if (absKr > _maxKr)
		_maxKr = absKr;
	if (absKr < _minKr)
		_minKr = absKr;

	++_nPoints;
}