Commit 11d2a56a authored by Yixin Hu's avatar Yixin Hu
Browse files

code cleanup

parent 834034ed
Loading
Loading
Loading
Loading
+10 −111
Original line number Diff line number Diff line
@@ -4,17 +4,10 @@
#include <geogram/basic/geometry_nd.h>
#include <floattetwild/TriangleInsertion.h>

void floatTetWild::AABBWrapper::init_b_mesh(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces) {
    b_mesh.clear(false,false);
//    std::vector<std::array<int, 2>> edges;
//    for(int i=0;i<sf_mesh.facets.nb();i++){
//        for(int j=0;j<3;j++) {
//            if(sf_mesh.facets.adjacent(i, j)==GEO::NO_FACET){
//                edges.push_back({{}})
//            }
//        }
//    }


void floatTetWild::AABBWrapper::init_b_mesh_and_tree(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces, Mesh& mesh) {
    b_mesh.clear(false, false);
    std::vector<std::vector<int>> conn_tris(input_vertices.size());
    std::vector<std::array<int, 2>> all_edges;
    all_edges.reserve(input_faces.size() * 3);
@@ -29,16 +22,6 @@ void floatTetWild::AABBWrapper::init_b_mesh(const std::vector<Vector3>& input_ve
    }
    vector_unique(all_edges);

//    std::vector<std::array<int, 2>> b_edges;
//    for (auto &e:all_edges) {
//        std::vector<int> tmp;
//        std::set_intersection(conn_tris[e[0]].begin(), conn_tris[e[0]].end(),
//                              conn_tris[e[1]].begin(), conn_tris[e[1]].end(), std::back_inserter(tmp));
//        if (tmp.size() == 1) {
//            b_edges.push_back(e);
//        }
//    }

    std::vector<std::pair<std::array<int, 2>, std::vector<int>>> _;
    std::vector<std::array<int, 2>> b_edges;
    std::vector<bool> _1;
@@ -47,7 +30,6 @@ void floatTetWild::AABBWrapper::init_b_mesh(const std::vector<Vector3>& input_ve
                        _, _1, b_edges);

    if (b_edges.empty()) {
//    if (b_edge_infos.empty()) {
        b_mesh.vertices.clear();
        b_mesh.vertices.create_vertices(1);
        b_mesh.vertices.point(0) = GEO::vec3(0, 0, 0);
@@ -75,97 +57,13 @@ void floatTetWild::AABBWrapper::init_b_mesh(const std::vector<Vector3>& input_ve
            b_mesh.facets.set_vertex(i, 1, i * 2);
            b_mesh.facets.set_vertex(i, 2, i * 2 + 1);
        }
//        b_mesh.vertices.clear();
//        b_mesh.vertices.create_vertices((int) b_edge_infos.size() * 2);
//        int cnt = 0;
//        for (auto &info:b_edge_infos) {
//            auto& e = info.first;
//            for (int j = 0; j < 2; j++) {
//                GEO::vec3 &p = b_mesh.vertices.point(cnt++);
//                p[0] = input_vertices[e[j]][0];
//                p[1] = input_vertices[e[j]][1];
//                p[2] = input_vertices[e[j]][2];
//            }
//        }
//        b_mesh.facets.clear();
//        b_mesh.facets.create_triangles((int) b_edge_infos.size());
//        for (int i = 0; i < b_edge_infos.size(); i++) {
//            b_mesh.facets.set_vertex(i, 0, i * 2);
//            b_mesh.facets.set_vertex(i, 1, i * 2);
//            b_mesh.facets.set_vertex(i, 2, i * 2 + 1);
//        }
    }

    mesh_reorder(b_mesh, GEO::MESH_ORDER_MORTON);
}
    b_tree = std::make_shared<MeshFacetsAABBWithEps>(b_mesh);

void floatTetWild::AABBWrapper::init_tmp_b_mesh_and_tree(const Mesh& mesh, const std::vector<std::array<int, 2>>& b_edges){
    if (b_edges.empty()) {
        tmp_b_mesh.vertices.clear();
        tmp_b_mesh.vertices.create_vertices(1);
        tmp_b_mesh.vertices.point(0) = GEO::vec3(0, 0, 0);
        tmp_b_mesh.facets.clear();
        tmp_b_mesh.facets.create_triangles(1);
        tmp_b_mesh.facets.set_vertex(0, 0, 0);
        tmp_b_mesh.facets.set_vertex(0, 1, 0);
        tmp_b_mesh.facets.set_vertex(0, 2, 0);
    } else {
        tmp_b_mesh.vertices.clear();
        tmp_b_mesh.vertices.create_vertices((int) b_edges.size() * 2);
        int cnt = 0;
        for (auto &e:b_edges) {
            for (int j = 0; j < 2; j++) {
                GEO::vec3 &p = tmp_b_mesh.vertices.point(cnt++);
                p[0] = mesh.tet_vertices[e[j]].pos[0];
                p[1] = mesh.tet_vertices[e[j]].pos[1];
                p[2] = mesh.tet_vertices[e[j]].pos[2];
            }
        }
        tmp_b_mesh.facets.clear();
        tmp_b_mesh.facets.create_triangles((int) b_edges.size());
        for (int i = 0; i < b_edges.size(); i++) {
            tmp_b_mesh.facets.set_vertex(i, 0, i * 2);
            tmp_b_mesh.facets.set_vertex(i, 1, i * 2);
            tmp_b_mesh.facets.set_vertex(i, 2, i * 2 + 1);
        }
    }
    mesh_reorder(tmp_b_mesh, GEO::MESH_ORDER_MORTON);
    tmp_b_tree = std::make_shared<MeshFacetsAABBWithEps>(tmp_b_mesh);
}

void floatTetWild::AABBWrapper::init_tmp_b_mesh_and_tree(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces,
                              const std::vector<std::array<int, 2>>& b_edges){
    if (b_edges.empty()) {
        tmp_b_mesh.vertices.clear();
        tmp_b_mesh.vertices.create_vertices(1);
        tmp_b_mesh.vertices.point(0) = GEO::vec3(0, 0, 0);
        tmp_b_mesh.facets.clear();
        tmp_b_mesh.facets.create_triangles(1);
        tmp_b_mesh.facets.set_vertex(0, 0, 0);
        tmp_b_mesh.facets.set_vertex(0, 1, 0);
        tmp_b_mesh.facets.set_vertex(0, 2, 0);
    } else {
        tmp_b_mesh.vertices.clear();
        tmp_b_mesh.vertices.create_vertices((int) b_edges.size() * 2);
        int cnt = 0;
        for (auto &e:b_edges) {
            for (int j = 0; j < 2; j++) {
                GEO::vec3 &p = tmp_b_mesh.vertices.point(cnt++);
                p[0] = input_vertices[e[j]][0];
                p[1] = input_vertices[e[j]][1];
                p[2] = input_vertices[e[j]][2];
            }
        }
        tmp_b_mesh.facets.clear();
        tmp_b_mesh.facets.create_triangles((int) b_edges.size());
        for (int i = 0; i < b_edges.size(); i++) {
            tmp_b_mesh.facets.set_vertex(i, 0, i * 2);
            tmp_b_mesh.facets.set_vertex(i, 1, i * 2);
            tmp_b_mesh.facets.set_vertex(i, 2, i * 2 + 1);
        }
    }
    mesh_reorder(tmp_b_mesh, GEO::MESH_ORDER_MORTON);
    tmp_b_tree = std::make_shared<MeshFacetsAABBWithEps>(tmp_b_mesh);
    if(b_edges.empty())
        mesh.is_closed = true;
}

void floatTetWild::AABBWrapper::init_tmp_b_mesh_and_tree(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces,
@@ -216,4 +114,5 @@ void floatTetWild::AABBWrapper::init_tmp_b_mesh_and_tree(const std::vector<Vecto
    }
    mesh_reorder(tmp_b_mesh, GEO::MESH_ORDER_MORTON);
    tmp_b_tree = std::make_shared<MeshFacetsAABBWithEps>(tmp_b_mesh);

}
+106 −111
Original line number Diff line number Diff line
@@ -18,25 +18,19 @@ namespace floatTetWild {
        std::shared_ptr<MeshFacetsAABBWithEps> tmp_b_tree;
        MeshFacetsAABBWithEps sf_tree;

        void init_b_mesh(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces);

		AABBWrapper(const GEO::Mesh &sf_mesh) : sf_mesh(sf_mesh), sf_tree(sf_mesh) {}

        //// initialization
        inline Scalar get_sf_diag() const { return GEO::bbox_diagonal(sf_mesh); }

		void init_b_mesh_and_tree(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces) {
			init_b_mesh(input_vertices, input_faces);
			b_tree = std::make_shared<MeshFacetsAABBWithEps>(b_mesh);
		}
        AABBWrapper(const GEO::Mesh &sf_mesh) : sf_mesh(sf_mesh), sf_tree(sf_mesh) {}

		void init_tmp_b_mesh_and_tree(const Mesh& mesh, const std::vector<std::array<int, 2>>& b_edges);
		void init_tmp_b_mesh_and_tree(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces,
				const std::vector<std::array<int, 2>>& b_edges);
        void init_b_mesh_and_tree(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces, Mesh &mesh);

        void init_tmp_b_mesh_and_tree(const std::vector<Vector3>& input_vertices, const std::vector<Vector3i>& input_faces,
        void init_tmp_b_mesh_and_tree(const std::vector<Vector3> &input_vertices,
                                      const std::vector<Vector3i> &input_faces,
                                      const std::vector<std::array<int, 2>> &b_edges1,
                                      const Mesh &mesh, const std::vector<std::array<int, 2>> &b_edges2);

        //// projection
        inline Scalar project_to_sf(Vector3 &p) const {
            GEO::vec3 geo_p(p[0], p[1], p[2]);
            GEO::vec3 nearest_p;
@@ -49,20 +43,6 @@ namespace floatTetWild {
            return sq_dist;
        }

        inline int get_nearest_face_sf(const Vector3 &p) const {
            GEO::vec3 geo_p(p[0], p[1], p[2]);
            GEO::vec3 nearest_p;
            double sq_dist = std::numeric_limits<double>::max(); //??
            return sf_tree.nearest_facet(geo_p, nearest_p, sq_dist);
        }

		inline Scalar project_to_sf(const GEO::vec3 geo_p) const {
			GEO::vec3 nearest_p;
			double sq_dist = std::numeric_limits<double>::max(); //??
			sf_tree.nearest_facet(geo_p, nearest_p, sq_dist);
			return sq_dist;
		}

        inline Scalar project_to_b(Vector3 &p) const {
            GEO::vec3 geo_p(p[0], p[1], p[2]);
            GEO::vec3 nearest_p;
@@ -87,13 +67,22 @@ namespace floatTetWild {
            return sq_dist;
        }

		inline Scalar project_to_b(const GEO::vec3 geo_p) const {
        inline int get_nearest_face_sf(const Vector3 &p) const {
            GEO::vec3 geo_p(p[0], p[1], p[2]);
            GEO::vec3 nearest_p;
            double sq_dist = std::numeric_limits<double>::max(); //??
			b_tree->nearest_facet(geo_p, nearest_p, sq_dist);
            return sf_tree.nearest_facet(geo_p, nearest_p, sq_dist);
        }

        inline Scalar get_sq_dist_to_sf(const Vector3 &p) const {
            GEO::vec3 geo_p(p[0], p[1], p[2]);
            GEO::vec3 nearest_p;
            double sq_dist = std::numeric_limits<double>::max(); //??
            sf_tree.nearest_facet(geo_p, nearest_p, sq_dist);
            return sq_dist;
        }

        //// envelope check - triangle
        inline bool is_out_sf_envelope(const std::vector<GEO::vec3> &ps, const Scalar eps_2,
                                       GEO::index_t prev_facet = GEO::NO_FACET) const {
            GEO::vec3 nearest_point;
@@ -114,26 +103,6 @@ namespace floatTetWild {
            return false;
        }

        inline Scalar dist_sf_envelope(const std::vector<GEO::vec3> &ps, const Scalar eps_2,
                                       GEO::index_t prev_facet = GEO::NO_FACET) const {
            GEO::vec3 nearest_point;
            double sq_dist = std::numeric_limits<double>::max();

            for (const GEO::vec3 &current_point : ps) {
                if (prev_facet != GEO::NO_FACET) {
                    get_point_facet_nearest_point(sf_mesh, current_point, prev_facet, nearest_point, sq_dist);
                }
                if (Scalar(sq_dist) > eps_2) {
                    sf_tree.facet_in_envelope_with_hint(current_point, eps_2, prev_facet, nearest_point, sq_dist);
                }
                if (Scalar(sq_dist) > eps_2) {
                    return sq_dist;
                }
            }

            return 0;
        }

        inline bool is_out_b_envelope(const std::vector<GEO::vec3> &ps, const Scalar eps_2,
                                      GEO::index_t prev_facet = GEO::NO_FACET) const {
            GEO::vec3 nearest_point;
@@ -174,6 +143,7 @@ namespace floatTetWild {
            return false;
        }

        //// envelope check - point
        inline bool is_out_sf_envelope(const Vector3 &p, const Scalar eps_2, GEO::index_t &prev_facet) const {
            GEO::vec3 nearest_p;
            double sq_dist;
@@ -206,5 +176,30 @@ namespace floatTetWild {
                return true;
            return false;
        }


        //fortest
        inline Scalar dist_sf_envelope(const std::vector<GEO::vec3> &ps, const Scalar eps_2,
                                       GEO::index_t prev_facet = GEO::NO_FACET) const {///only used for checking correctness
            GEO::vec3 nearest_point;
            double sq_dist = std::numeric_limits<double>::max();

            for (const GEO::vec3 &current_point : ps) {
                if (prev_facet != GEO::NO_FACET) {
                    get_point_facet_nearest_point(sf_mesh, current_point, prev_facet, nearest_point, sq_dist);
                }
                if (Scalar(sq_dist) > eps_2) {
                    sf_tree.facet_in_envelope_with_hint(current_point, eps_2, prev_facet, nearest_point, sq_dist);
                }
                if (Scalar(sq_dist) > eps_2) {
                    return sq_dist;
                }
            }

            return 0;
        }
        //fortest

    };

}
+0 −7
Original line number Diff line number Diff line
@@ -29,13 +29,6 @@ set(SOURCES

	FloatTetDelaunay.h
	FloatTetDelaunay.cpp
	FloatTetCutting.h
	FloatTetCutting.cpp
	FloatTetCuttingCheck.h
	FloatTetCuttingCheck.cpp
	FloatTetCuttingParallel.h
	FloatTetCuttingParallel.cpp

		TriangleInsertion.cpp
		TriangleInsertion.h

src/FloatTetCutting.cpp

deleted100644 → 0
+0 −2361

File deleted.

Preview size limit exceeded, changes collapsed.

src/FloatTetCutting.h

deleted100644 → 0
+0 −78
Original line number Diff line number Diff line
// This file is part of fTetWild, a software for generating tetrahedral 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 FLOATTETWILD_FLOATTETCUTTING_H
#define FLOATTETWILD_FLOATTETCUTTING_H

#include <floattetwild/Mesh.hpp>
#include <floattetwild/AABBWrapper.h>

#ifdef FLOAT_TETWILD_USE_TBB
#include <tbb/concurrent_vector.h>
#endif

namespace floatTetWild {
    void cutting(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces, const std::vector<int> &input_tags,
                 Mesh &mesh, std::vector<bool> &is_face_inserted,
                 AABBWrapper& tree, bool is_again = false);

    bool insert_one(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces,
                    Mesh &sub_mesh, std::vector<std::array<std::vector<int>, 4>>& sub_cut_f_ids,
                    int f_id, int seed_v_id, bool is_parallel, bool is_again);

    void match_surface_fs(const Mesh &mesh, const std::vector<Vector3> &input_vertices,
                          const std::vector<Vector3i> &input_faces, std::vector<bool> &is_face_inserted,
                          std::vector<std::array<std::vector<int>, 4>> &cut_f_ids);

    void
    find_tets_for_cut(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces, int f_id,
                      int seed_v_id,
                      Mesh &mesh, std::vector<int> &intersection_results, std::vector<int> &oris);
    void
    find_tets_for_cut_again(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces,
            int f_id, Mesh &mesh, std::vector<int> &intersection_results, std::vector<int> &oris);


    int one_face_cut(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces, int f_id,
                     Mesh &mesh, std::vector<int> &intersection_results,
                     std::vector<std::array<std::vector<int>, 4>> &cut_f_ids, std::vector<int> &oris, bool is_parallel,
                     bool is_again);
    void snapping(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces, int f_id,
                  Mesh &mesh,
                  std::vector<int> &intersection_results, std::vector<int> &oris, std::vector<Scalar>& signed_dist);
    int tet_subdivision(int f_id,
                         Mesh& mesh, std::vector<int>& intersection_results, std::vector<int>& intersection_results_wn,
                         std::vector<std::array<std::vector<int>, 4>>& cut_f_ids, std::vector<Scalar>& signed_dist,std::vector<int>& oris,
                         std::map<std::array<int, 2>, int>& e_p_map, std::vector<MeshVertex>& tmp_tet_vertices,
                         bool is_again = false);
    Scalar get_min_volume(const Mesh &mesh, const std::vector<Vector4i>& new_tets, const std::vector<Vector3>& centroids,
            const std::vector<int>& global_v_ids, const std::vector<MeshVertex>& tmp_tet_vertices);
    void get_centroids(const Mesh &mesh, const std::vector<Vector4i>& new_tets, const std::vector<int>& global_v_ids,
            const std::vector<MeshVertex>& tmp_tet_vertices,  std::vector<Vector3>& cs);

    void preserve_cutting_open_boundary(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces,
        const std::vector<int>& current_inserted_cutting_fs,
        std::vector<std::array<std::vector<int>, 4>> &cut_f_ids, Mesh& mesh, AABBWrapper& tree,
        const std::vector<bool>& is_face_matched, std::vector<bool>& is_boundary_preserved, bool is_again);

    void track_surface(Mesh &mesh,
                       const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces, const std::vector<int> &input_tags,
                       std::vector<std::array<std::vector<int>, 4>> &cut_f_ids,
                       const AABBWrapper& tree, const std::vector<bool>& is_boundary_preserved);

    void get_current_open_boundary(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces,
            const std::vector<std::array<int, 2>>& edges, const std::vector<std::vector<int>>& conn_tris,
            std::vector<std::array<int, 2>>& f_id_le_id);
    void update_tmp_b_tree(const std::vector<Vector3> &input_vertices, const std::vector<Vector3i> &input_faces,
                           const std::vector<bool> &is_face_inserted, AABBWrapper& tree);

    inline Vector3 get_normal(const Vector3& a, const Vector3& b, const Vector3& c) {
        return ((b - c).cross(a - c)).normalized();
    }
}
#endif //FLOATTETWILD_FLOATTETCUTTING_H
Loading