Page d'accueil Description du projet
/*********************************************
 *
 * Cedric Pradalier
 * DEA 2000/2001 
 * INRIA Rhones Alpes
 * http://cedric.pradalier.free.fr/index.html
 * mail : http://cedric.pradalier.free.fr/mail.html
 *
 * *******************************************/
#include "TriangleStrip.h"
#include <math.h>

#ifdef EPSILON
#undef EPSILON
#endif
#define EPSILON 1e-6

TriangleStrip::TriangleStrip(Polygon * P)
{
        tristrip = new gpc_tristrip;
        gpc_polygon_to_tristrip(P->getGpcPolygon(),tristrip);
}


bool TriangleStrip::contains(double x,double y)
{
        int i,j;
        bool res;
        for (i=0;i<tristrip->num_strips;i++)
                for (j=0;j<tristrip->strip[i].num_vertices-2;j++)
                {
                        double xa = tristrip->strip[i].vertex[j].x - x;
                        double ya = tristrip->strip[i].vertex[j].y - y;
                        double xb = tristrip->strip[i].vertex[j+1].x - x;
                        double yb = tristrip->strip[i].vertex[j+1].y - y;
                        double xc = tristrip->strip[i].vertex[j+2].x - x;
                        double yc = tristrip->strip[i].vertex[j+2].y - y;

                        // (x,y) doit etre un barycentre positif de P1,P2,P3
                        double t1 = xa*yb;
                        double t2 = xb*ya;
                        double t4 = xc*ya;
                        double t5 = xc*yb;
                        double t6 = xa*yc;
                        double t7 = xb*yc;
                        double t9 = 1/(t1+t4-t5-t6-t2+t7);
                        double lambda1 = (t1-t2)*t9;
                        double lambda2 = (-t5+t7)*t9;
                        double lambda3 = -(-t4+t6)*t9;
                        res = (lambda1>=-EPSILON) && (lambda2>=-EPSILON) 
                                && (lambda3>=-EPSILON);
                        if (res) return true;
                }
        return false;
}

void TriangleStrip::collectVtkPoints(VtkPoints & pts,VtkTriStrips & t,
        double theta, int ConnexPart)
{
    int i,j;
    VtkPoint3D P;
    P.z = theta;
    P.c = (double)ConnexPart;
    for (i=0;i<tristrip->num_strips;i++)
    {
        VtkTriStrip tri;
        for (j=0;j<tristrip->strip[i].num_vertices;j++)
        {
            P.x = tristrip->strip[i].vertex[j].x;
            P.y = tristrip->strip[i].vertex[j].y;
            tri.push_back(pts.size());
            pts.push_back(P);
        }
        t.push_back(tri);
    }
}