Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Felke <martin.felke@googlemail.com>2019-04-16 20:58:18 +0300
committerMartin Felke <martin.felke@googlemail.com>2019-04-16 20:58:18 +0300
commit31ebf10f1b4e8292dd3d78b2c7a0d3a96c9c1ec0 (patch)
tree2de74526d7603ae13fcca51de1b13b676adbdde5 /intern/qex
parenta847fa4523dae102dc9bf24cf91d2b30af7aa3b5 (diff)
initial implementation of libQex-based quad remeshing
note, still crashes often... has some memory alloc/free issues
Diffstat (limited to 'intern/qex')
-rw-r--r--intern/qex/CMakeLists.txt53
-rw-r--r--intern/qex/igl_capi.cc194
-rw-r--r--intern/qex/igl_capi.h36
-rw-r--r--intern/qex/qex_capi.cc25
-rw-r--r--intern/qex/qex_capi.h36
5 files changed, 344 insertions, 0 deletions
diff --git a/intern/qex/CMakeLists.txt b/intern/qex/CMakeLists.txt
new file mode 100644
index 00000000000..6c3e9badf75
--- /dev/null
+++ b/intern/qex/CMakeLists.txt
@@ -0,0 +1,53 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2015, Blender Foundation
+# All rights reserved.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ ../guardedalloc
+)
+
+set(INC_SYS
+)
+
+set(SRC
+ qex_capi.h
+ igl_capi.h
+)
+
+if(WITH_QEX)
+ add_definitions(
+ -DWITH_QEX
+ -DIGL_STATIC_LIBRARY=ON
+ )
+
+ list(APPEND INC_SYS
+ ${QEX_INCLUDE_DIRS}
+ ${IGL_INCLUDE_DIRS}
+ ${OPENMESH_INCLUDE_DIRS}
+ ${IGL_INCLUDE_DIR}/eigen
+ )
+
+ list(APPEND SRC
+ igl_capi.cc
+ qex_capi.cc
+ )
+endif()
+
+blender_add_lib(bf_intern_qex "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/qex/igl_capi.cc b/intern/qex/igl_capi.cc
new file mode 100644
index 00000000000..878d36c178a
--- /dev/null
+++ b/intern/qex/igl_capi.cc
@@ -0,0 +1,194 @@
+/*# ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* The Original Code is Copyright (C) 2015, Blender Foundation
+* All rights reserved.
+* ***** END GPL LICENSE BLOCK ******/
+
+
+#include <igl/avg_edge_length.h>
+#include <igl/barycenter.h>
+#include <igl/comb_cross_field.h>
+#include <igl/comb_frame_field.h>
+#include <igl/compute_frame_field_bisectors.h>
+#include <igl/cross_field_missmatch.h>
+#include <igl/cut_mesh_from_singularities.h>
+#include <igl/find_cross_field_singularities.h>
+#include <igl/local_basis.h>
+#include <igl/rotate_vectors.h>
+#include <igl/copyleft/comiso/miq.h>
+#include <igl/copyleft/comiso/nrosy.h>
+#include <igl/PI.h>
+#include <sstream>
+
+#include "igl_capi.h"
+
+
+void igl_miq(float (*verts)[3] , int (*tris)[3], int num_verts, int num_tris, float (*uv_tris)[3][2],
+ double gradient_size, double iter, double stiffness, bool direct_round)
+{
+
+ using namespace Eigen;
+
+ // Input mesh
+ MatrixXd V;
+ MatrixXi F;
+
+ // Face barycenters
+ MatrixXd B;
+
+ // Cross field
+ MatrixXd X1,X2;
+
+ // Bisector field
+ MatrixXd BIS1, BIS2;
+
+ // Combed bisector
+ MatrixXd BIS1_combed, BIS2_combed;
+
+ // Per-corner, integer mismatches
+ Matrix<int, Dynamic, 3> MMatch;
+
+ // Field singularities
+ Matrix<int, Dynamic, 1> isSingularity, singularityIndex;
+
+ // Per corner seams
+ Matrix<int, Dynamic, 3> Seams;
+
+ // Combed field
+ MatrixXd X1_combed, X2_combed;
+
+ // Global parametrization (with seams)
+ MatrixXd UV_seams;
+ MatrixXi FUV_seams;
+
+ // Global parametrization
+ MatrixXd UV;
+ MatrixXi FUV;
+
+ V.resize(num_verts, 3);
+ F.resize(num_tris, 3);
+ UV.resize(num_tris, 3*2);
+ FUV.resize(num_tris, 3);
+
+ for (int i = 0; i < num_verts; i++)
+ {
+ V(i, 0) = verts[i][0];
+ V(i, 1) = verts[i][1];
+ V(i, 2) = verts[i][2];
+ }
+
+ for (int i = 0; i < num_tris; i++)
+ {
+ F(i, 0) = tris[i][0];
+ F(i, 1) = tris[i][1];
+ F(i, 2) = tris[i][2];
+ }
+
+ //double gradient_size = 50;
+ //double iter = 0;
+ //double stiffness = 5.0;
+ //bool direct_round = 0;
+
+ // Compute face barycenters
+ igl::barycenter(V, F, B);
+
+ // Compute scale for visualizing fields
+ // global_scale = .5*igl::avg_edge_length(V, F);
+
+ // Contrain one face
+ VectorXi b(1);
+ b << 0;
+ MatrixXd bc(1, 3);
+ bc << 1, 0, 0;
+
+ // Create a smooth 4-RoSy field
+ VectorXd S;
+ igl::copyleft::comiso::nrosy(V, F, b, bc, VectorXi(), VectorXd(), MatrixXd(), 4, 0.5, X1, S);
+
+ // Find the orthogonal vector
+ MatrixXd B1, B2, B3;
+ igl::local_basis(V, F, B1, B2, B3);
+ X2 = igl::rotate_vectors(X1, VectorXd::Constant(1, igl::PI / 2), B1, B2);
+
+ // Always work on the bisectors, it is more general
+ igl::compute_frame_field_bisectors(V, F, X1, X2, BIS1, BIS2);
+
+ // Comb the field, implicitly defining the seams
+ igl::comb_cross_field(V, F, BIS1, BIS2, BIS1_combed, BIS2_combed);
+
+ // Find the integer mismatches
+ igl::cross_field_missmatch(V, F, BIS1_combed, BIS2_combed, true, MMatch);
+
+ // Find the singularities
+ igl::find_cross_field_singularities(V, F, MMatch, isSingularity, singularityIndex);
+
+ // Cut the mesh, duplicating all vertices on the seams
+ igl::cut_mesh_from_singularities(V, F, MMatch, Seams);
+
+ // Comb the frame-field accordingly
+ igl::comb_frame_field(V, F, X1, X2, BIS1_combed, BIS2_combed, X1_combed, X2_combed);
+
+ // Global parametrization
+ igl::copyleft::comiso::miq(V,
+ F,
+ X1_combed,
+ X2_combed,
+ MMatch,
+ isSingularity,
+ Seams,
+ UV,
+ FUV,
+ gradient_size,
+ stiffness,
+ direct_round,
+ iter,
+ 5,
+ true);
+
+ // Global parametrization (with seams, only for demonstration)
+ /*igl::copyleft::comiso::miq(V,
+ F,
+ X1_combed,
+ X2_combed,
+ MMatch,
+ isSingularity,
+ Seams,
+ UV_seams,
+ FUV_seams,
+ gradient_size,
+ stiffness,
+ direct_round,
+ iter,
+ 5,
+ false);*/
+
+ //output UVs (triangular parametrization)
+
+ for (int i = 0; i < num_tris; i++)
+ {
+ //uv face with 3 verts, 2 coords each
+ uv_tris[i][0][0] = UV(FUV(i, 0),0);
+ uv_tris[i][0][1] = UV(FUV(i, 0),1);
+
+ uv_tris[i][1][0] = UV(FUV(i, 1),0);
+ uv_tris[i][1][1] = UV(FUV(i, 1),1);
+
+ uv_tris[i][2][0] = UV(FUV(i, 2),0);
+ uv_tris[i][2][1] = UV(FUV(i, 2),1);
+ }
+}
+
diff --git a/intern/qex/igl_capi.h b/intern/qex/igl_capi.h
new file mode 100644
index 00000000000..d067c9f78e3
--- /dev/null
+++ b/intern/qex/igl_capi.h
@@ -0,0 +1,36 @@
+/****** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* The Original Code is Copyright (C) 2015, Blender Foundation
+* All rights reserved.
+* ***** END GPL LICENSE BLOCK ***** */
+
+#ifndef __IGL_CAPI_H__
+#define __IGL_CAPI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void igl_miq(float (*verts)[3] , int (*tris)[3], int num_verts, int num_tris, float (*uv_tris)[3][2],
+ double gradient_size, double iter, double stiffness, bool direct_round);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __IGL_CAPI_H__ */
diff --git a/intern/qex/qex_capi.cc b/intern/qex/qex_capi.cc
new file mode 100644
index 00000000000..ce720c42814
--- /dev/null
+++ b/intern/qex/qex_capi.cc
@@ -0,0 +1,25 @@
+/*# ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* The Original Code is Copyright (C) 2015, Blender Foundation
+* All rights reserved.
+* ***** END GPL LICENSE BLOCK ******/
+
+#include "qex_capi.h"
+
+void extractQuadMesh(qex_TriMesh *tri_mesh, qex_Valence *valence, qex_QuadMesh *quad_mesh) {
+ qex_extractQuadMesh(tri_mesh, valence, quad_mesh);
+}
diff --git a/intern/qex/qex_capi.h b/intern/qex/qex_capi.h
new file mode 100644
index 00000000000..e324c244e8b
--- /dev/null
+++ b/intern/qex/qex_capi.h
@@ -0,0 +1,36 @@
+/****** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* The Original Code is Copyright (C) 2015, Blender Foundation
+* All rights reserved.
+* ***** END GPL LICENSE BLOCK ***** */
+
+#ifndef __QEX_CAPI_H__
+#define __QEX_CAPI_H__
+
+#include "qex.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void extractQuadMesh(qex_TriMesh *tri_mesh, qex_Valence *valence, qex_QuadMesh *quad_mesh);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __QEX_CAPI_H__ */