Commit 8bc502a4 authored by YIxin-Hu's avatar YIxin-Hu
Browse files

verify with rational

parent 0307b23d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -85,6 +85,11 @@ include(FloatTetwildDependencies)
# FloatTetwild library
################################################################################

find_package(GMPfTetWild)
IF(NOT ${GMP_FOUND})
	MESSAGE(FATAL_ERROR "Cannot find GMP")
ENDIF()

# add_library() can only be called without any source since CMake 3.11 ...
add_library(${PROJECT_NAME} src/Logger.cpp)

@@ -116,6 +121,8 @@ if(FLOAT_TETWILD_USE_FLOAT)
	target_compile_definitions(${PROJECT_NAME} PUBLIC -DFLOAT_TETWILD_USE_FLOAT)
endif()

target_include_directories(${PROJECT_NAME} PUBLIC ${GMP_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME}
	PUBLIC
		igl::core
@@ -123,6 +130,7 @@ target_link_libraries(${PROJECT_NAME}
		spdlog::spdlog
		Threads::Threads
		fast_winding_number
		${GMP_LIBRARIES}
)
if(FLOAT_TETWILD_ENABLE_TBB)
	target_link_libraries(${PROJECT_NAME} PUBLIC tbb::tbb)
+22 −0
Original line number Diff line number Diff line
# Try to find the GMP librairies
# GMP_FOUND - system has GMP lib
# GMP_INCLUDE_DIRS - the GMP include directory
# GMP_LIBRARIES - Libraries needed to use GMP

if (GMP_INCLUDE_DIRS AND GMP_LIBRARIES)
        # Already in cache, be silent
        set(GMP_FIND_QUIETLY TRUE)
endif (GMP_INCLUDE_DIRS AND GMP_LIBRARIES)


find_path(GMP_INCLUDE_DIRS NAMES gmp.h PATHS $ENV{GMP_INC} ${GMP_WINDOWS_PATH})
find_library(GMP_LIBRARIES NAMES gmp libgmp PATHS $ENV{GMP_LIB} ${GMP_WINDOWS_PATH})
find_library(GMPXX_LIBRARIES NAMES gmpxx libgmpxx PATHS $ENV{GMP_LIB} ${GMP_WINDOWS_PATH})
#MESSAGE(STATUS "GMP libs: " ${GMP_LIBRARIES} " " ${GMPXX_LIBRARIES} )


include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_INCLUDE_DIRS GMP_LIBRARIES)

mark_as_advanced(GMP_INCLUDE_DIRS GMP_LIBRARIES)
MESSAGE(STATUS "GMP libs: " ${GMP_LIBRARIES} " " ${GMP_INCLUDE_DIRS} )
+18 −3
Original line number Diff line number Diff line
@@ -32,9 +32,11 @@
#include <numeric>
#include <unordered_map>


#define III -1

//fortest
#include <floattetwild/Rational.h>
double time_find_cutting_tets = 0;
double time_find_cutting_tets1 = 0;
double time_find_cutting_tets2 = 0;
@@ -463,7 +465,7 @@ bool floatTetWild::insert_one_triangle(int insert_f_id, const std::vector<Vector
    time_push_new_tets += timer.getElapsedTime();

    timer.start();
    simplify_subdivision_result(insert_f_id, input_vertices.size(), mesh, tree, track_surface_fs, modified_t_ids);
//    simplify_subdivision_result(insert_f_id, input_vertices.size(), mesh, tree, track_surface_fs, modified_t_ids);
    time_simplify_subdivision_result += timer.getElapsedTime();

    return true;
@@ -745,8 +747,8 @@ void floatTetWild::find_cutting_tets(int f_id, const std::vector<Vector3> &input

//    const int CUT_UNKNOWN = INT_MIN;
//    std::vector<std::array<int, 4>> visited_results(mesh.tets.size(), {{CUT_UNKNOWN, CUT_UNKNOWN, CUT_UNKNOWN, CUT_UNKNOWN}});
//    const int test_f_id = 771;
    const int test_f_id = -1;
    const int test_f_id = 771;
//    const int test_f_id = -1;
    const int test_j = 1;
    const int test_v_id = input_faces[test_f_id][test_j];
    while (!queue_t_ids.empty()) {
@@ -835,6 +837,8 @@ void floatTetWild::find_cutting_tets(int f_id, const std::vector<Vector3> &input
                             << Predicates::orient_3d(tp1, tp3, tp2, vs[k]) << " "
                             << Predicates::orient_3d(tp3, tp2, tp1, vs[k]) << endl;
                    }


                    pausee();
                }

@@ -883,6 +887,17 @@ void floatTetWild::find_cutting_tets(int f_id, const std::vector<Vector3> &input
                cout << "cnt_neg = " << cnt_neg << endl;
                cout << "result = " << result << endl;
//                if (cnt_pos > 0 && cnt_neg > 0) {
                if (t_id == 3976){
                    {
                        Eigen::MatrixXd V(4, 3);
                        Eigen::MatrixXi F(4, 3);
                        for (int k = 0; k < 4; k++) {
                            V.row(k) = mesh.tet_vertices[mesh.tets[t_id][k]].pos;
                            F.row(k) << (k + 1) % 4, (k + 2) % 4, (k + 3) % 4;
                        }
                        igl::writeOFF("test_cut_t_ids1_"+std::to_string(t_id)+".off", V, F);
                    }
                }
                if (t_id == 1016) {
                    {
                        Eigen::MatrixXd V(4, 3);
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ set(SOURCES

	FastWindingNumber.hpp
	FastWindingNumber.cpp

		Rational.h
		)

prepend_current_path(SOURCES)
+158 −0
Original line number Diff line number Diff line
// This file is part of TriWild, a software for generating linear/curved triangle meshes.
//
// Copyright (C) 2019 Yixin Hu <yixin.hu@nyu.edu>
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
//

#ifndef TRIWILD_RATIONAL_H
#define TRIWILD_RATIONAL_H

#include <gmp.h>
#include <iostream>

namespace triwild {

    class Rational {//https://cs.nyu.edu/acsys/cvc3/releases/1.5/doc/rational-gmp_8cpp-source.html
    public:
        mpq_t value;
        void canonicalize() {
            mpq_canonicalize(value);
        }
        int get_sign() {
            return mpq_sgn(value);
        }

        Rational() {
            mpq_init(value);
            mpq_set_d(value, 0);
        }

        Rational(double d) {
            mpq_init(value);
            mpq_set_d(value, d);
//            canonicalize();
        }

        Rational(const mpq_t &v_) {
            mpq_init(value);
            mpq_set(value, v_);
//            canonicalize();
        }

        Rational(const Rational &other) {
            mpq_init(value);
            mpq_set(value, other.value);
        }

        ~Rational() {
            mpq_clear(value);
        }

//        //+, - another point
//        Rational operator+(const Rational &r) const {
//            Rational r_out;
//            mpq_add(r_out.value, value, r.value);
//            return r_out;
//        }
//
//        Rational operator-(const Rational &r) const {
//            Rational r_out;
//            mpq_sub(r_out.value, value, r.value);
//            return r_out;
//        }
//
//        //*, / double/rational
//        Rational operator*(const Rational &r) const {
//            Rational r_out;
//            mpq_mul(r_out.value, value, r.value);
//            return r_out;
//        }
//
//        Rational operator/(const Rational &r) const {
//            Rational r_out;
//            mpq_div(r_out.value, value, r.value);
//            return r_out;
//        }
//
//        //=
//        void operator=(const Rational &r) {
//            mpq_set(value, r.value);
//        }

        friend Rational operator+(const Rational& x, const Rational& y) {
            Rational r_out;
            mpq_add(r_out.value, x.value, y.value);
            return r_out;
        }

        friend Rational operator-(const Rational& x, const Rational& y) {
            Rational r_out;
            mpq_sub(r_out.value, x.value, y.value);
            return r_out;
        }

        friend Rational operator*(const Rational& x, const Rational& y) {
            Rational r_out;
            mpq_mul(r_out.value, x.value, y.value);
            return r_out;
        }

        friend Rational operator/(const Rational& x, const Rational& y) {
            Rational r_out;
            mpq_div(r_out.value, x.value, y.value);
            return r_out;
        }

        Rational& operator=(const Rational& x) {
            if (this == &x) return *this;
            mpq_set(value, x.value);
            return *this;
        }

        Rational& operator=(const double x) {
            mpq_set_d(value, x);
//            canonicalize();
            return *this;
        }

        //> < ==
        friend bool operator<(const Rational &r, const Rational &r1) {
            return mpq_cmp(r.value, r1.value) < 0;
        }

        friend bool operator>(const Rational &r, const Rational &r1) {
            return mpq_cmp(r.value, r1.value) > 0;
        }

        friend bool operator<=(const Rational &r, const Rational &r1) {
            return mpq_cmp(r.value, r1.value) <= 0;
        }

        friend bool operator>=(const Rational &r, const Rational &r1) {
            return mpq_cmp(r.value, r1.value) >= 0;
        }

        friend bool operator==(const Rational &r, const Rational &r1) {
            return mpq_equal(r.value, r1.value);
        }

        friend bool operator!=(const Rational &r, const Rational &r1) {
            return !mpq_equal(r.value, r1.value);
        }

        //to double
        double to_double() {
            return mpq_get_d(value);
        }

        //<<
        friend std::ostream &operator<<(std::ostream &os, const Rational &r) {
            os << mpq_get_d(r.value);
            return os;
        }
    };
}

#endif //TRIWILD_RATIONAL_H