예제 #1
0
static int check_linear(const Cubic& cubic, Cubic& reduction,
        int minX, int maxX, int minY, int maxY) {
    int startIndex = 0;
    int endIndex = 3;
    while (cubic[startIndex].approximatelyEqual(cubic[endIndex])) {
        --endIndex;
        if (endIndex == 0) {
            printf("%s shouldn't get here if all four points are about equal", __FUNCTION__);
            assert(0);
        }
    }
    if (!isLinear(cubic, startIndex, endIndex)) {
        return 0;
    }
    // four are colinear: return line formed by outside
    reduction[0] = cubic[0];
    reduction[1] = cubic[3];
    int sameSide1;
    int sameSide2;
    bool useX = cubic[maxX].x - cubic[minX].x >= cubic[maxY].y - cubic[minY].y;
    if (useX) {
        sameSide1 = sign(cubic[0].x - cubic[1].x) + sign(cubic[3].x - cubic[1].x);
        sameSide2 = sign(cubic[0].x - cubic[2].x) + sign(cubic[3].x - cubic[2].x);
    } else {
        sameSide1 = sign(cubic[0].y - cubic[1].y) + sign(cubic[3].y - cubic[1].y);
        sameSide2 = sign(cubic[0].y - cubic[2].y) + sign(cubic[3].y - cubic[2].y);
    }
    if (sameSide1 == sameSide2 && (sameSide1 & 3) != 2) {
        return 2;
    }
    double tValues[2];
    int roots;
    if (useX) {
        roots = findExtrema(cubic[0].x, cubic[1].x, cubic[2].x, cubic[3].x, tValues);
    } else {
        roots = findExtrema(cubic[0].y, cubic[1].y, cubic[2].y, cubic[3].y, tValues);
    }
    for (int index = 0; index < roots; ++index) {
        _Point extrema;
        extrema.x = interp_cubic_coords(&cubic[0].x, tValues[index]);
        extrema.y = interp_cubic_coords(&cubic[0].y, tValues[index]);
        // sameSide > 0 means mid is smaller than either [0] or [3], so replace smaller
        int replace;
        if (useX) {
            if (extrema.x < cubic[0].x ^ extrema.x < cubic[3].x) {
                continue;
            }
            replace = (extrema.x < cubic[0].x | extrema.x < cubic[3].x)
                    ^ cubic[0].x < cubic[3].x;
        } else {
            if (extrema.y < cubic[0].y ^ extrema.y < cubic[3].y) {
                continue;
            }
            replace = (extrema.y < cubic[0].y | extrema.y < cubic[3].y)
                    ^ cubic[0].y < cubic[3].y;
        }
        reduction[replace] = extrema;
    }
    return 2;
}
예제 #2
0
파일: main.cpp 프로젝트: Mric26/M2-S1
// Ecriture d'un fichier KML pour afficher une image
void writeKmlImgFile(QString filename, std::vector<std::string>* latitude, std::vector<std::string>* longitude, QString output) {
    QFile file(filename);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        return;
    }

    QString path = QDir::currentPath() + "/../Images/" + output;
    float minLat, maxLat;
    float minLong, maxLong;
    findExtrema(minLat, maxLat, latitude);
    findExtrema(minLong, maxLong, longitude);

    QTextStream out(&file);
    out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    out << "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" << endl;
    out << "  <Folder>" << endl;
    out << "    <name>Ground Overlays</name>" << endl;
    out << "    <GroundOverlay>" << endl;
    out << "      <name>Large-scale overlay on terrain</name>" << endl;
    out << "      <Icon>" << endl;
    out << "        <href>" << path << "</href>" << endl;
    out << "      </Icon>" << endl;
    out << "      <LatLonBox>" << endl;
    out << "        <north>" << maxLat << "</north>" << endl;
    out << "        <south>" << minLat << "</south>" << endl;
    out << "        <east>" << minLong << "</east>" << endl;
    out << "        <west>" << maxLong << "</west>" << endl;
    out << "      </LatLonBox>" << endl;
    out << "    </GroundOverlay>" << endl;
    out << "  </Folder>" << endl;
    out << "</kml>" << endl;
}
예제 #3
0
파일: main.cpp 프로젝트: Mric26/M2-S1
// Interpolation de Shepard
void computeShepard(std::vector< std::vector< float >* >* interpoleData, std::vector<std::string>* latitude, std::vector<std::string>* longitude, std::vector<std::string>* data) {
    float lati, longi;
    float minLat, maxLat;
    float minLong, maxLong;
    findExtrema(minLat, maxLat, latitude);
    findExtrema(minLong, maxLong, longitude);

    // interpolation sur toutes les grilles
    for (int i = 0; i < resolution; ++i) {
        for (int j = 0; j < resolution; ++j) {
            lati = minLat + ((double(i)/(resolution-1)) * (maxLat - minLat));
            longi = minLong + ((double(j)/(resolution-1)) * (maxLong - minLong));

            // calcul de s pour wk
            float s = 0;
            for (unsigned int k = 0; k < data->size(); ++k) {
                float latik = atof(latitude->at(k).c_str());
                float longik = atof(longitude->at(k).c_str());
                s += 1.0 / pow(distance(lati, longi, latik, longik), mu);
            }

            // interpolation des donnees
            float eval = 0;
            for (unsigned int k = 0; k < data->size(); ++k) {
                float latik = atof(latitude->at(k).c_str());
                float longik = atof(longitude->at(k).c_str());

                float wk = (1.0 / pow(distance(lati, longi, latik, longik), mu)) * (1.0 / s);
                eval += wk * atof(data->at(k).c_str());
            }

            interpoleData->at(i)->at(j) = eval;
        }
    }
}
예제 #4
0
static int check_linear(const Quadratic& quad, Quadratic& reduction,
        int minX, int maxX, int minY, int maxY) {
    int startIndex = 0;
    int endIndex = 2;
    while (quad[startIndex].approximatelyEqual(quad[endIndex])) {
        --endIndex;
        if (endIndex == 0) {
            printf("%s shouldn't get here if all four points are about equal", __FUNCTION__);
            assert(0);
        }
    }
    if (!isLinear(quad, startIndex, endIndex)) {
        return 0;
    }
    // four are colinear: return line formed by outside
    reduction[0] = quad[0];
    reduction[1] = quad[2];
    int sameSide;
    bool useX = quad[maxX].x - quad[minX].x >= quad[maxY].y - quad[minY].y;
    if (useX) {
        sameSide = sign(quad[0].x - quad[1].x) + sign(quad[2].x - quad[1].x);
    } else {
        sameSide = sign(quad[0].y - quad[1].y) + sign(quad[2].y - quad[1].y);
    }
    if ((sameSide & 3) != 2) {
        return 2;
    }
    double tValue;
    int root;
    if (useX) {
        root = findExtrema(quad[0].x, quad[1].x, quad[2].x, &tValue);
    } else {
        root = findExtrema(quad[0].y, quad[1].y, quad[2].y, &tValue);
    }
    if (root) {
        _Point extrema;
        extrema.x = interp_quad_coords(quad[0].x, quad[1].x, quad[2].x, tValue);
        extrema.y = interp_quad_coords(quad[0].x, quad[1].x, quad[2].x, tValue);
        // sameSide > 0 means mid is smaller than either [0] or [2], so replace smaller
        int replace;
        if (useX) {
            if (extrema.x < quad[0].x ^ extrema.x < quad[2].x) {
                return 2;
            }
            replace = (extrema.x < quad[0].x | extrema.x < quad[2].x)
                    ^ (quad[0].x < quad[2].x);
        } else {
            if (extrema.y < quad[0].y ^ extrema.y < quad[2].y) {
                return 2;
            }
            replace = (extrema.y < quad[0].y | extrema.y < quad[2].y)
                    ^ (quad[0].y < quad[2].y);
        }
        reduction[replace] = extrema;
    }
    return 2;
}
예제 #5
0
void _Rect::setBounds(const Quadratic& quad) {
    set(quad[0]);
    add(quad[2]);
    double tValues[2];
    int roots = 0;
    if (!between(quad[0].x, quad[1].x, quad[2].x)) {
        roots = findExtrema(quad[0].x, quad[1].x, quad[2].x, tValues);
    }
    if (!between(quad[0].y, quad[1].y, quad[2].y)) {
        roots += findExtrema(quad[0].y, quad[1].y, quad[2].y, &tValues[roots]);
    }
    for (int x = 0; x < roots; ++x) {
        _Point result;
        xy_at_t(quad, tValues[x], result.x, result.y);
        add(result);
    }
}
예제 #6
0
파일: main.cpp 프로젝트: Mric26/M2-S1
// Inteprolation de Hardy
void computeHardy(std::vector< std::vector< float >* >* interpoleData, std::vector<std::string>* latitude, std::vector<std::string>* longitude, std::vector<std::string>* data) {
    unsigned int n = data->size();
    Eigen::MatrixXf A = Eigen::MatrixXf(n,n);
    Eigen::VectorXf b = Eigen::VectorXf(data->size());
    Eigen::VectorXf x;

    float lati, longi, latj, longj, latk, longk;
    float minLat, maxLat;
    float minLong, maxLong;
    findExtrema(minLat, maxLat, latitude);
    findExtrema(minLong, maxLong, longitude);

    for (unsigned int i = 0; i < n; ++i) {
        for (unsigned int j = 0; j < n; ++j) {
            lati = atof(latitude->at(i).c_str());
            longi = atof(longitude->at(i).c_str());
            latj = atof(latitude->at(j).c_str());
            longj = atof(longitude->at(j).c_str());
            A(i,j) = sqrt(R + pow(distance(longi,lati,longj,latj),2));
        }
    }

    for (unsigned int i = 0; i < data->size(); ++i) {
        b(i) = atof(data->at(i).c_str());
    }

    x = A.ldlt().solve(b);

    for (int i = 0; i < resolution; ++i) {
        for (int j = 0; j < resolution; ++j) {
            lati = minLat + ((double(i)/(resolution-1)) * (maxLat - minLat));
            longi = minLong + ((double(j)/(resolution-1)) * (maxLong - minLong));
            float eval = 0.0;
            for (unsigned int k = 0; k < n; ++k) {
                latk = atof(latitude->at(k).c_str());
                longk = atof(longitude->at(k).c_str());
                eval += x(k) * sqrt(R + pow(distance(lati, longi, latk, longk),2));
            }
            interpoleData->at(i)->at(j) = eval;
        }
    }
}
예제 #7
0
double leftMostT(const Quadratic& quad, double startT, double endT) {
    double leftT;
    if (findExtrema(quad[0].x, quad[1].x, quad[2].x, &leftT)
            && startT <= leftT && leftT <= endT) {
        return leftT;
    }
    _Point startPt;
    xy_at_t(quad, startT, startPt.x, startPt.y);
    _Point endPt;
    xy_at_t(quad, endT, endPt.x, endPt.y);
    return startPt.x <= endPt.x ? startT : endT;
}
예제 #8
0
static int horizontal_line(const Quadratic& quad, Quadratic& reduction) {
    double tValue;
    reduction[0] = quad[0];
    reduction[1] = quad[2];
    int smaller = reduction[1].x > reduction[0].x;
    int larger = smaller ^ 1;
    if (findExtrema(quad[0].x, quad[1].x, quad[2].x, &tValue)) {
        double xExtrema = interp_quad_coords(quad[0].x, quad[1].x, quad[2].x, tValue);
        if (reduction[smaller].x > xExtrema) {
            reduction[smaller].x = xExtrema;
        }  else if (reduction[larger].x < xExtrema) {
            reduction[larger].x = xExtrema;
        }
    }
    return 2;
}
예제 #9
0
static int vertical_line(const Quadratic& quad, Quadratic& reduction) {
    double tValue;
    reduction[0] = quad[0];
    reduction[1] = quad[2];
    int smaller = reduction[1].y > reduction[0].y;
    int larger = smaller ^ 1;
    if (findExtrema(quad[0].y, quad[1].y, quad[2].y, &tValue)) {
        double yExtrema = interp_quad_coords(quad[0].y, quad[1].y, quad[2].y, tValue);
        if (reduction[smaller].y > yExtrema) {
            reduction[smaller].y = yExtrema;
        } else if (reduction[larger].y < yExtrema) {
            reduction[larger].y = yExtrema;
        }
    }
    return 2;
}
예제 #10
0
static int horizontal_line(const Cubic& cubic, Cubic& reduction) {
    double tValues[2];
    reduction[0] = cubic[0];
    reduction[1] = cubic[3];
    int smaller = reduction[1].x > reduction[0].x;
    int larger = smaller ^ 1;
    int roots = findExtrema(cubic[0].x, cubic[1].x, cubic[2].x, cubic[3].x, tValues);
    for (int index = 0; index < roots; ++index) {
        double xExtrema = interp_cubic_coords(&cubic[0].x, tValues[index]);
        if (reduction[smaller].x > xExtrema) {
            reduction[smaller].x = xExtrema;
            continue;
        }
        if (reduction[larger].x < xExtrema) {
            reduction[larger].x = xExtrema;
        }
    }
    return 2;
}
예제 #11
0
static int vertical_line(const Cubic& cubic, Cubic& reduction) {
    double tValues[2];
    reduction[0] = cubic[0];
    reduction[1] = cubic[3];
    int smaller = reduction[1].y > reduction[0].y;
    int larger = smaller ^ 1;
    int roots = findExtrema(cubic[0].y, cubic[1].y, cubic[2].y, cubic[3].y, tValues);
    for (int index = 0; index < roots; ++index) {
        double yExtrema = interp_cubic_coords(&cubic[0].y, tValues[index]);
        if (reduction[smaller].y > yExtrema) {
            reduction[smaller].y = yExtrema;
            continue;
        }
        if (reduction[larger].y < yExtrema) {
            reduction[larger].y = yExtrema;
        }
    }
    return 2;
}
예제 #12
0
_Point top(const Quadratic& quad, double startT, double endT) {
    Quadratic sub;
    sub_divide(quad, startT, endT, sub);
    _Point topPt = sub[0];
    if (topPt.y > sub[2].y || (topPt.y == sub[2].y && topPt.x > sub[2].x)) {
        topPt = sub[2];
    }
    if (!between(sub[0].y, sub[1].y, sub[2].y)) {
        double extremeT;
        if (findExtrema(sub[0].y, sub[1].y, sub[2].y, &extremeT)) {
            extremeT = startT + (endT - startT) * extremeT;
            _Point test;
            xy_at_t(quad, extremeT, test.x, test.y);
            if (topPt.y > test.y || (topPt.y == test.y && topPt.x > test.x)) {
                topPt = test;
            }
        }
    }
    return topPt;
}
예제 #13
0
_Point top(const Cubic& cubic, double startT, double endT) {
    Cubic sub;
    sub_divide(cubic, startT, endT, sub);
    _Point topPt = sub[0];
    if (topPt.y > sub[3].y || (topPt.y == sub[3].y && topPt.x > sub[3].x)) {
        topPt = sub[3];
    }
    double extremeTs[2];
    if (!monotonic_in_y(sub)) {
        int roots = findExtrema(sub[0].y, sub[1].y, sub[2].y, sub[3].y, extremeTs);
        for (int index = 0; index < roots; ++index) {
            _Point mid;
            double t = startT + (endT - startT) * extremeTs[index];
            xy_at_t(cubic, t, mid.x, mid.y);
            if (topPt.y > mid.y || (topPt.y == mid.y && topPt.x > mid.x)) {
                topPt = mid;
            }
        }
    }
    return topPt;
}
예제 #14
0
int main ( int argc, char **argv )
{
    int intervals=5;
    int octave=0;
    /*CvCapture *capture;
    capture = cvCreateFileCapture("/users/eleves-a/x2008/benoit.seguin/INF560/Projet/cuda.avi");
    if (!capture) {
     printf("Ouverture du flux vidéo impossible !\n");
     return 1;
    }
    IplImage *img = cvQueryFrame(capture);*/
    IplImage *img = cvLoadImage("image1.jpg");
    uint width=img->width;
    uint height=img->height;
    IplImage *imgGrayscale = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 );
    cvCvtColor( img, imgGrayscale, CV_RGB2GRAY );
    //initialisation de la memoire CUDA
    CUDAinit(imgGrayscale->width,imgGrayscale->height,intervals);

    //initialisation des variables
    char s[255];
    clock_t totaltime;
    IplImage *integral = cvCreateImage(cvSize(imgGrayscale->width,imgGrayscale->height),IPL_DEPTH_32S,1);
    IplImage *imgs[intervals];
    IplImage *imgsShow[intervals];
    for(int i=0; i<intervals; i++) {
        imgs[i]=cvCreateImage(cvSize(imgGrayscale->width,imgGrayscale->height),IPL_DEPTH_32S,1);
        imgsShow[i]=cvCreateImage(cvSize(imgGrayscale->width,imgGrayscale->height),IPL_DEPTH_32S,1);
    }
    //initialisation de la boucle
    makeIntegralImage(imgGrayscale,integral);
    CUDAcalculateGaussianDerivative(integral,octave,intervals);
    //boucle de traitement
    for(int frame=1; frame<=90; frame++) {
        totaltime=clock();
        sprintf(s,"image%i.jpg",frame);
        img = cvLoadImage(s);
        cvCvtColor( img, imgGrayscale, CV_RGB2GRAY );
        //integralImage
        clock_t timer=clock();
        makeIntegralImage(imgGrayscale,integral);
        std::cout << "integrale : " << 1000*(float)(clock()-timer)/(float)CLOCKS_PER_SEC <<"ms"<< std::endl;
        //  for(int i=1;i<img->height;i++){
        //  	for(int j=1;j<img->width;j++){
        //  		i=j;
        //  		//if(((int*)( imgs[0]->imageData + imgs[0]->widthStep * i)) [j] != ((int*)( imgs2[0]->imageData + imgs2[0]->widthStep * i)) [j])
        //  		std::cout << i << "," << j << " "<< (int)((uchar*)( (img->imageData) + (img->widthStep) * i)) [j]<< " "<< getPixel(img2,i,j)+getPixel(img2,i-1,j-1)-getPixel(img2,i-1,j)-getPixel(img2,i,j-1) << std::endl;
        //    }
        //  }

        //filtres gaussiens
        timer=clock();

        CUDAretrieveGaussianDerivative(imgs,intervals);
        CUDAcalculateGaussianDerivative(integral,octave,intervals);

        //calculateGaussianDerivative(integral,imgs,octave,intervals);
        std::cout << "calculateGaussianDerivative : " << 1000*(float)(clock()-timer)/(float)CLOCKS_PER_SEC <<"ms"<< std::endl;


        //recherche d'extremas
        timer=clock();
        std::list<std::vector<int> > maxs(findExtrema(imgs,intervals));
        std::cout << "findExtrema : " << 1000*(float)(clock()-timer)/(float)CLOCKS_PER_SEC <<"ms"<< std::endl;

        std::cout << "tmps total avt affichage : " << 1000*(float)(clock()-totaltime)/(float)CLOCKS_PER_SEC <<"ms"<< std::endl;

        //affichage
        //cvShowImage( "Integrale", img2 );

        std::list<vector<int> >::iterator tmp=maxs.begin();
        for (int i = 0; i < intervals; ++i) {
            cvScale(imgs[i],imgsShow[i],100);
            while(tmp!=maxs.end() && (*tmp)[0]==i) {
                cvCircle(imgsShow[i], cvPoint((*tmp)[2],(*tmp)[1]), borderSize(octave,i), cvScalar(0,255,0), 1);
                cvCircle(img, cvPoint((*tmp)[2],(*tmp)[1]), borderSize(octave,i), cvScalar(0,255,0), 2);
                tmp++;
            }
            sprintf(s,"%i",i);
            cvShowImage( s, imgsShow[i] );
        }
        cvShowImage( "Image originale", img );
        cvWaitKey();
    }
    //FIN
    cvWaitKey();
    cvReleaseImage(&imgGrayscale);
    cvReleaseImage(&integral);
    //cvReleaseCapture(&capture);
    CUDAclose(intervals);
    return 0;
}
예제 #15
0
파일: main.cpp 프로젝트: Mric26/M2-S1
int main() {

    // importation des donnees
    Csv_meteoFranceParser* csvPoste = new Csv_meteoFranceParser(pathPoste);
    Csv_meteoFranceParser* csvDatas = new Csv_meteoFranceParser(pathDatas);
    Csv_meteoFranceParser* csvJoin = csv_join_force(csvPoste, csvDatas, std::string("ID"), std::string("numer_sta"), std::string("Id_Fusion"));

    // selection des donnes requises (latitude, longitude, temperature, ...)
    std::vector<std::string>* cities = (*csvJoin)[std::string("Nom")];
    std::vector<std::string>* latitude = (*csvJoin)[std::string("Latitude")];
    std::vector<std::string>* longitude = (*csvJoin)[std::string("Longitude")];
    std::vector<std::string>* kelvin = (*csvJoin)[std::string("t")];

    float minT, maxT;
    findExtrema(minT, maxT, kelvin);

    float minLat, maxLat;
    float minLong, maxLong;
    findExtrema(minLat, maxLat, latitude);
    findExtrema(minLong, maxLong, longitude);

    ////////////////////////////// Instanciation //////////////////////////////
    std::vector< std::vector< float >* >* interpoleShepard = new std::vector< std::vector< float >* >(resolution);
    for (int i = 0; i < resolution; ++i) {
        (*interpoleShepard)[i] = new std::vector<float>(resolution);
    }

    std::vector< std::vector< float >* >* interpoleHardy = new std::vector< std::vector< float >* >(resolution);
    for (int i = 0; i < resolution; ++i) {
        (*interpoleHardy)[i] = new std::vector<float>(resolution);
    }

    int resoSquare = resolution-1;
    std::vector< std::vector< short >* >* square = new std::vector< std::vector< short >* >(resoSquare);
    for (int i = 0; i < resoSquare; ++i) {
        (*square)[i] = new std::vector<short>(resoSquare);
    }


    ////////////////////////////// Interpolation //////////////////////////////
    // interpolation des temperatures
    computeShepard(interpoleShepard, latitude, longitude, kelvin);
    computeHardy(interpoleHardy, latitude, longitude, kelvin);
    std::vector< std::vector< float >* >* interpoleData = interpoleHardy;


    ////////////////////////////// Creation des images //////////////////////////////
    QImage *imgSquare = new QImage(resoSquare * RESO, resoSquare * RESO, QImage::Format_ARGB32);
    int count = 1;

    // calcul des isolignes avec le marching square
    for (float isoLine = minT; isoLine < maxT; isoLine += 1) {

        computeMarchingSquare(square, interpoleData, isoLine);
        drawMarchingSquare(imgSquare, square, interpoleData, isoLine);

        imgSquare->save(QString("../Images/anim" + QString::number(count) + ".png"));
        std::cout << "n° : " << count << " --> " <<  isoLine << std::endl;
        count++;
    }

    // creation de la colormap
    Colormap *colorMap = createColorMap(minT, maxT);

    // calcul de la map des couleurs
    QImage *imgColor = new QImage(resoSquare, resoSquare, QImage::Format_ARGB32);
    imgColor->fill(qRgba(0,0,0,0));
    drawData(imgColor, colorMap, interpoleData);

    // dessine la colormap
    QImage *imgColormap = new QImage(50, 200, QImage::Format_RGB32);
    drawColorMap(imgColormap, colorMap, minT, maxT);

    // ecriture dans les fichiers de sorties
    imgColormap->save(QString("../Images/colorMap.png"));
    imgColor->save(QString("../Images/colorData.png"));
    writeKmlInfoFile(QString("../cities.kml"), cities, latitude, longitude);
    writeKmlImgFile(QString("../colorData.kml"), latitude, longitude, QString("colorData.png"));
    writeKmlImgFile(QString("../isoLine.kml"), latitude, longitude, QString("anim4.png"));


    ////////////////////////////// Free Memory //////////////////////////////
    std::cout << "Delete memory" << std::endl;
    delete csvPoste;
    delete csvDatas;
    delete csvJoin;
    delete cities;
    delete latitude;
    delete longitude;
    delete kelvin;
    delete imgSquare;
    delete imgColor;
    delete colorMap;
    delete imgColormap;

    std::cout << "Fin" << std::endl;
    return 0;
}