Exemplo n.º 1
0
T FacePerimeter:: getFacePerimeter ( const HalfEdge <T> *e_start )
{
        //Get perimeter of the Face given by start half edge
        T perimeter = 0;
        HalfEdge <T> *e = const_cast <HalfEdge <T> *> ( e_start );

        //There is a valid edge
        if ( e_start != NULL )
        {
                //Get point
                Node3DCartesian <T> *pi = e->getPoint();

                //Proces all edges of the Face
                do
                {
                        //Get point
                        Node3DCartesian <T> *pii = e->getNextEdge()->getPoint();

                        //Compute area
                        perimeter += EuclDistance::getEuclDistance2D ( pi->getX(), pi->getY(), pii->getX(), pii->getY() );

                        //Assign point
                        pi = pii;

                        //Assign edge
                        e = e->getNextEdge();

                }
                while ( e != e_start );
        }

        //Get area
        return perimeter;
}
Exemplo n.º 2
0
void TangentFunction::computeTangentFunctionFace ( const Face <T> *face, typename TTangentFunction <T>::Type & tf, T & rotation, const TTangentFunctionRotationMethod & rotation_method,
	const TTangentFunctionScaleMethod & scale_method )
{
        //Compute normalized tangent function for the Face  given by HalfEdge
        T turning_angle_sum = 0, normalize_length_sum = 0;
        const HalfEdge <T> *e_start = face->getHalfEdge();
        HalfEdge <T> *e = const_cast <HalfEdge <T> *> ( e_start ) ;

        //Get triplet of points
        Node3DCartesian <T> *pi, *piii = NULL;
        Node3DCartesian <T> *pii = e_start->getPoint();

        //Jump short segments
        for ( pi = e->getPreviousEdge()->getPoint(); EuclDistance::getEuclDistance2D ( pi, pii ) < MIN_POSITION_DIFF ; e = e->getPreviousEdge(), pi = e->getPreviousEdge()->getPoint() ) {}

        //Get third point for initial edge
        for ( piii = e->getNextEdge()->getPoint(); EuclDistance::getEuclDistance2D ( pii, piii ) < MIN_POSITION_DIFF ; e = e->getNextEdge(), piii = e->getNextEdge()->getPoint() ) {}

        //Compute perimeter of the Face
        const T face_perimeter = FacePerimeter::getFacePerimeter ( e_start );

        //Throw exception
        if ( face_perimeter == 0 )
        {
                throw ErrorMathZeroDevision <T> ( "ErrorMathZeroDevision: tangent function, can not normalize function (1 / perimeter), ", "perimeter = 0." );
        }

        //Compute initial angle: rotation invariant
        if ( rotation_method == RotationInvariant )
        {
                turning_angle_sum += 180 - Angle3Points::getAngle3Points ( pi, pii, piii );
        }

        //Compute initial angle: rotation dependent (do not compute the sum)
        else
        {
                turning_angle_sum = 360 - Angle3Points::getAngle3Points ( &Node3DCartesian <T> ( pii->getX() - 1, pii->getY() ), pii, piii );
        }

        //Add turning angle computed for normalized length of initial edge to map
        tf[normalize_length_sum] = turning_angle_sum;

        //Assign points from initial edge
        pi = pii;
        pii = piii;

        //Increment initial edge
        e = e_start->getNextEdge();

        //Process all edges of the Face (2, n-1)
        do
        {
                //Get third point
                piii = e->getNextEdge()->getPoint();

                //Segment is too short
                if ( EuclDistance::getEuclDistance2D ( pii, piii ) > MIN_POSITION_DIFF )
                {
                        //Compute angle: rotation invariant
                        if ( rotation_method == RotationInvariant )
                        {
                                turning_angle_sum += 180 - Angle3Points::getAngle3Points ( pi, pii, piii );
                        }

                        //Compute initial angle: rotation dependent (do not compute the sum)
                        else
                        {
                                turning_angle_sum = 360 - Angle3Points::getAngle3Points ( &Node3DCartesian <T> ( pii->getX() - 1, pii->getY() ), pii, piii );
                        }

                        //Compute normalized length sum
                        normalize_length_sum += ( scale_method == ScaleDependent ? EuclDistance::getEuclDistance2D ( pi, pii ) / face_perimeter : EuclDistance::getEuclDistance2D ( pi, pii ) );

                        //Add turning angle computed for normalized length to map
                        tf[normalize_length_sum] = turning_angle_sum;

                        //Assign points
                        pi = pii;
                        pii = piii;
                }

                //Increment edge
                e = e->getNextEdge();

        } while ( e != e_start );

        //Add last value: we visit first point again
	const T last = ( scale_method == ScaleDependent ? 1.0 : face_perimeter );
        if ( rotation_method == RotationInvariant )
        {
		tf[ last] = turning_angle_sum + tf.begin()->second;
        }

        else
        {
                tf[last] = tf.begin()->second;
        }
}
Exemplo n.º 3
0
void TurningFunction::computeTurningFunctionFace ( const Face <T> *face, typename TTurningFunction <T>::Type & tf, T & rotation, const TTurningFunctionRotationMethod & rotation_method,
                const TTurningFunctionScaleMethod & scale_method )
{
        //Compute normalized turning function for the Face  given by HalfEdge
        T turning_angle_sum = 0, normalize_length_sum = 0;
        const HalfEdge <T> *e_start = face->getHalfEdge();
        HalfEdge <T> *e = const_cast <HalfEdge <T> *> ( e_start ) ;

        //Get triplet of points
        Node3DCartesian <T> *pi, *piii = NULL;
        Node3DCartesian <T> *pii = e_start->getPoint();

        //Jump short segments
        for ( pi = e->getPreviousEdge()->getPoint(); EuclDistance::getEuclDistance2D ( pi->getX(), pi->getY(), pii->getX(), pii->getY() ) < MIN_POSITION_DIFF ; e = e->getPreviousEdge(), pi = e->getPreviousEdge()->getPoint() );

        //Get third point for initial edge
        for ( piii = e->getNextEdge()->getPoint(); EuclDistance::getEuclDistance2D ( pii->getX(), pii->getY(), piii->getX(), piii->getY() ) < MIN_POSITION_DIFF ; e = e->getNextEdge(), piii = e->getNextEdge()->getPoint() );

        //Compute perimeter of the Face
        const T face_perimeter = FacePerimeter::getFacePerimeter ( e_start );

        //Throw exception
        if ( fabs ( face_perimeter ) < MIN_FLOAT )
        {
                throw MathZeroDevisionException <T> ( "MathZeroDevisionException: turning function, can not normalize function (1 / perimeter), ", "perimeter = 0.", face_perimeter );
        }

        //Compute initial angle: rotation invariant
        if ( rotation_method == RotationInvariant )
        {
                turning_angle_sum += 180 - Angle3Points::getAngle3Points ( pi, pii, piii );
        }

        //Compute initial angle: rotation dependent (do not compute the sum)
        else
        {
                //Create temporary point P (x_temp, y_temp) on x axis
                const T dx = std::max ( fabs ( piii->getX() - pii->getX() ), fabs ( piii->getY() - pii->getY() ) );
                Node3DCartesian <T> n_temp ( pii->getX() - 2 * dx , pii->getY() );

                turning_angle_sum += Bearing::getBearing ( pii, &n_temp );
        }

        //Add turning angle computed for normalized length of initial edge to map
        tf[normalize_length_sum] = turning_angle_sum;

        //Assign points from initial edge
        pi = pii;
        pii = piii;

        //Increment initial edge
        e = e_start->getNextEdge();

        //Process all edges of the Face (2, n-1)
        do
        {
                //Get third point
                piii = e->getNextEdge()->getPoint();

                //Segment is too short
                if ( EuclDistance::getEuclDistance2D ( pii->getX(), pii->getY(), piii->getX(), piii->getY() ) > MIN_POSITION_DIFF )
                {
                        //Compute angle: rotation invariant
                        turning_angle_sum += 180.0 - Angle3Points::getAngle3Points ( pi, pii, piii );

                        //Compute normalized length sum
                        normalize_length_sum += ( scale_method == ScaleInvariant ? EuclDistance::getEuclDistance2D ( pi->getX(), pi->getY(), pii->getX(), pii->getY() ) / face_perimeter :
                                                  EuclDistance::getEuclDistance2D ( pi->getX(), pi->getY(), pii->getX(), pii->getY() ) );

                        //Add turning angle computed for normalized length to map
                        tf[normalize_length_sum] = turning_angle_sum;

                        //Assign points
                        pi = pii;
                        pii = piii;
                }

                //Increment edge
                e = e->getNextEdge();

        }
        while ( e != e_start );

        //Add last value: we visit first point again
        const T last_key = ( scale_method == ScaleInvariant ? 1.0 : face_perimeter );
        tf[last_key] = ( rotation_method == RotationInvariant ? turning_angle_sum + tf.begin()->second : tf.begin()->second );
}