Commit fd051fae authored by Teseo Schneider's avatar Teseo Schneider
Browse files

Merge branch 'dev' of github.com:wildmeshing/fTetWild into dev

parents c25ac12e 465aee99
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -863,12 +863,68 @@ void floatTetWild::pausee(std::string msg) {
        exit(0);
}

bool floatTetWild::is_energy_unstable(const std::array<Scalar, 12>& T, Scalar res) {
    static const std::vector<std::array<int, 4>> combs = {{{0, 1, 3, 2}},
                                                          {{0, 2, 1, 3}},
                                                          {{0, 2, 3, 1}},
                                                          {{0, 3, 1, 2}},
                                                          {{0, 3, 2, 1}},
                                                          {{1, 0, 2, 3}},
                                                          {{1, 0, 3, 2}},
                                                          {{1, 2, 0, 3}},
                                                          {{1, 2, 3, 0}},
                                                          {{1, 3, 0, 2}},
                                                          {{1, 3, 2, 0}},
                                                          {{2, 0, 1, 3}},
                                                          {{2, 0, 3, 1}},
                                                          {{2, 1, 0, 3}},
                                                          {{2, 1, 3, 0}},
                                                          {{2, 3, 0, 1}},
                                                          {{2, 3, 1, 0}},
                                                          {{3, 0, 1, 2}},
                                                          {{3, 0, 2, 1}},
                                                          {{3, 1, 0, 2}},
                                                          {{3, 1, 2, 0}},
                                                          {{3, 2, 0, 1}},
                                                          {{3, 2, 1, 0}}};
    Scalar res0;
    if (std::isinf(res))
        res0 = 0;
    else
        res0 = res;
    for (int i = 0; i < combs.size(); i++) {
        std::array<Scalar, 12> tmp_T;
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 3; k++)
                tmp_T[j * 3 + k] = T[combs[i][j] * 3 + k];
        }
        Scalar res1 = AMIPS_energy_aux(tmp_T);
        if (std::isinf(res1))
            continue;
        if (res0 == 0)
            res0 = res1;
        if (res1 - res0 > 10)
            return true;
    }
    return false;
}

int cnt_stable = 0;
int cnt_large = 0;
#include <floattetwild/Rational.h>
Scalar floatTetWild::AMIPS_energy(const std::array<Scalar, 12>& T) {
    Scalar res = AMIPS_energy_aux(T);
//    return res;


    if (res > 1e8) {
//        //fortest
//        cnt_large++;
//        if(!is_energy_unstable(T, res)){
//            cout<<(cnt_stable++)<<"/"<<cnt_large<<endl;
//        }
//        //fortest

        if(is_inverted(Vector3(T[0], T[1], T[2]), Vector3(T[3], T[4], T[5]), Vector3(T[6], T[7], T[8]),
                    Vector3(T[9], T[10], T[11])))
            return std::numeric_limits<double>::infinity();
+1 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ namespace floatTetWild {
    };

    Scalar AMIPS_energy_aux(const std::array<Scalar, 12>& T);
    bool is_energy_unstable(const std::array<Scalar, 12>& T, Scalar res);
    Scalar AMIPS_energy(const std::array<Scalar, 12>& T);
    void AMIPS_jacobian(const std::array<Scalar, 12>& T, Vector3& result_0);
    void AMIPS_hessian(const std::array<Scalar, 12>& T, Matrix3& result_0);