Exemplo n.º 1
0
vector<Point_2D> Geom_2D::test_flattening(Mesh::EdgeHandle ehandle){

    Mesh::HalfedgeHandle heh = mesh->halfedge_handle(ehandle, 0);

    //starting point. We position our edge along the x-axis.

    vector<Point_2D> p;

    cout<<"edge length: "<<mesh->calc_edge_length(heh)<<endl;

    p.push_back(Point_2D(0.0, 0.0, 0.0));  //0

    p.push_back(Point_2D(mesh->calc_edge_length(heh), 0.0, 0.0)); //1

    cout<<"point 2"<<endl;
    p.push_back(get_2D_point(heh, p[0], p[1])); //2

    Mesh::HalfedgeLoopIter heIt;
    heIt = mesh->hl_begin(heh);

    cout<<"point 3"<<endl;
    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[2], p[1]));  //3

    Mesh::HalfedgeHandle hedge= mesh->opposite_halfedge_handle(*heIt);
    Mesh::Point to, from;
    to = mesh->point(mesh->to_vertex_handle(hedge));
    from = mesh->point(mesh->from_vertex_handle(hedge));

    cout<<"base of point 3"<<endl;
    cout<<"point 1 x:"<<to[0]<<" y: "<<to[1]<<" z: "<<to[2]<<endl;
    cout<<"point 2 x:"<<from[0]<<" y: "<<from[1]<<" z: "<<from[2]<<endl;

    cout<<"point 4"<<endl;
    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[0], p[2])); //4

    Mesh::HalfedgeHandle heh2 = mesh->opposite_halfedge_handle(heh);

    cout<<"point 5"<<endl;

    p.push_back(get_2D_point(heh2, p[1], p[0])); //5
    heIt = mesh->hl_begin(heh2);

    cout<<"point 6"<<endl;
    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[5], p[0])); //6

    cout<<"point 7"<<endl;
    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[1], p[5])); //7

    for (int i = 0; i < 8; i++){
        cout<<(p[i])<<endl;
    }

    return p;
}
#include <boost/test/unit_test.hpp>
#include "Bounding_rectangle.hpp"

BOOST_AUTO_TEST_SUITE(Bounding_rectangle_tests)

Bounding_rectangle rectangle0;
Bounding_rectangle rectangle1( Point_2D(2, 40), Point_2D(60, 10));
Bounding_rectangle rectangle2( Point_2D(10,100), Point_2D(20,1));

BOOST_AUTO_TEST_CASE(get_operators_test)
{
    BOOST_CHECK_EQUAL(rectangle2.get_up_left(), Point_2D(10,100));
    BOOST_CHECK_EQUAL(rectangle2.get_down_right(), Point_2D(20, 1));
}

BOOST_AUTO_TEST_CASE(set_operators_test_without_does_degenerete_checking)
{
    Bounding_rectangle rectangle_tmp;
    rectangle_tmp.set_up_left(Point_2D(2, 15));
    rectangle_tmp.set_down_right(Point_2D(30, 3));
    
    BOOST_CHECK_EQUAL(rectangle_tmp.get_up_left(), Point_2D(2,15));
    BOOST_CHECK_EQUAL(rectangle_tmp.get_down_right(), Point_2D(30, 3));
}

// Skoro test wyzej przeszedl nie ma potrzeby sprawdzania znowu funkcji set
BOOST_AUTO_TEST_CASE(set_operators_with_does_degenerete_test)
{
    Bounding_rectangle rectangle_tmp;
    BOOST_CHECK_EQUAL(rectangle_tmp.get_does_degenerate(), false);
    
Exemplo n.º 3
0
/**
 * The goal is to return the best sample point that we can split this
 * edge on. Returns the index of said sample point.
 */
int Geom_2D::get_sample_point(Mesh::EdgeHandle &ehandle){
    /*
     * The goal is to convert these coordinates into 2 dimensions
     * and do the necessary calculations there. The position of the
     * translated points is arbitrary, we shall merely calculate a
     * distance then use a unit vector to find the relevant sample point
     */

    Mesh::HalfedgeHandle heh = mesh->halfedge_handle(ehandle, 0);

    //starting point. We position our edge along the x-axis.

    vector<Point_2D> p;
    p.push_back(Point_2D(0.0, 0.0, 0.0));  //0

    p.push_back(Point_2D(mesh->calc_edge_length(heh), 0.0, 0.0)); //1

    p.push_back(get_2D_point(heh, p[0], p[1])); //2

    Mesh::HalfedgeLoopIter heIt;
    heIt = mesh->hl_begin(heh);

    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[2], p[1]));  //3

    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[0], p[2])); //4

    Mesh::HalfedgeHandle heh2 = mesh->opposite_halfedge_handle(heh);

    p.push_back(get_2D_point(heh2, p[1], p[0])); //5
    heIt = mesh->hl_begin(heh2);

    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[5], p[0])); //6

    heIt ++;
    p.push_back(get_2D_point(mesh->opposite_halfedge_handle(*heIt), p[1], p[5])); //7

    /*
     * We aim for simplicity and accuracy over speed in this section.
     * cc and r contain the circumcenter and the radius of the circumcircles
     * of the provided triangles.
     */
    double cc[2*6], r[6];

    get_circumcircle(p[0], p[2], p[5], &cc[0], r[0]);
    get_circumcircle(p[1], p[2], p[5], &cc[2], r[1]);
    get_circumcircle(p[1], p[2], p[3], &cc[4], r[2]);
    get_circumcircle(p[1], p[7], p[5], &cc[6], r[3]);
    get_circumcircle(p[0], p[2], p[4], &cc[8], r[4]);
    get_circumcircle(p[0], p[6], p[5], &cc[10], r[5]);

    vector<Mesh::Point>* samps;
    samps = &(mesh->property(*samples, ehandle));
    double score;
    Point_2D p2d(0.0,0.0,0.0);
    int maxScore = 0;
    int maxIndex = 0;

    if (samps->size()==0){
        cout<<"*************************"<<endl<<"0 samples"<<endl;
        output_point(ehandle);
        cout<<"*************************"<<endl;
        //this should never happen....but it does.
        return -1;

    }
    for (int i = 0; i < samps->size(); i++){
        //first two circles if the sample points are in both we
        //score 5
        //void Geom_2D::mesh_to_plane(Mesh::HalfedgeHandle heh, Mesh::Point &samp, Point_2D &p0, Point_2D &p1, Point_2D &dest){
        score = 0;
        mesh_to_plane(heh, (*samps)[i], (p[0]), (p[1]), p2d);

        if (score_type == 1){
            if (distance2d(cc, p2d)<r[0]){
                score += 1.5;
            }
            if (distance2d(cc+2, p2d)<r[1]){
                score += 1.5;
            }
        }else if (score_type == 0){
            if (distance2d(cc, p2d)<r[0]){
                score ++;
            }
            if (distance2d(cc+2, p2d)<r[1]){
                score ++;
            }
        }else if (score_type == 2){
            if ((distance2d(cc, p2d)<r[0])&&(distance2d(cc+2, p2d)<r[1])){
                score += 5;
            }
        }

        for (int j = 2; j < 6; j++){
            if (distance2d(cc+(2*j), p2d)>r[j]){
                score++;
            }
        }
        if (score>maxScore){
            maxScore = score;
            maxIndex = i;
        }

    }
    //cout<<"max Score: "<<maxScore<<endl;
    //if ((maxIndex == 0)||(maxIndex == samps->size()-1)) {
    if(samps->size()==0){
        cout<<"*************************"<<endl;
        cout<<"******************index: "<<maxIndex<<endl;
        cout<<"*************************"<<endl;
        cout<<"samples size: "<<samps->size()<<endl;
        cout<<" is flippable "<< mesh->property(*is_flippable, ehandle)<<endl;
        cout<<" is Delaunay "<< mesh->property(*is_NDE, ehandle)<<endl;
        output_point(ehandle);
        cout<<"length: "<<mesh->calc_edge_length(ehandle)<<endl;
        cout<<"max score "<<maxScore<<endl;

    }
    return maxIndex;
}