[Bf-blender-cvs] [3bcfe9b5ace] sculpt-dev: Sculpt-dev: fix compile errors for quadriflow
Joseph Eagar
noreply at git.blender.org
Tue Oct 26 11:03:01 CEST 2021
Commit: 3bcfe9b5ace77303e2004b502fd45b3699f5731c
Author: Joseph Eagar
Date: Mon Oct 25 22:23:28 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB3bcfe9b5ace77303e2004b502fd45b3699f5731c
Sculpt-dev: fix compile errors for quadriflow
. . .when compiled with threading on (for quadriflow).
Still off however.
===================================================================
M extern/quadriflow/CMakeLists.txt
M extern/quadriflow/src/optimizer.cpp
M extern/quadriflow/src/parametrizer-int.cpp
M extern/quadriflow/src/parametrizer-mesh.cpp
M extern/quadriflow/src/parametrizer-sing.cpp
M extern/quadriflow/src/parametrizer.hpp
M extern/quadriflow/src/subdivide.cpp
M intern/instant-meshes/instant_meshes_c_api.h
M intern/instant-meshes/src/c_api.cpp
M intern/quadriflow/quadriflow_capi.cpp
M source/blender/blenkernel/BKE_mesh_remesh_voxel.h
M source/blender/blenkernel/intern/mesh_remesh_voxel.cc
M source/blender/editors/object/object_remesh.cc
===================================================================
diff --git a/extern/quadriflow/CMakeLists.txt b/extern/quadriflow/CMakeLists.txt
index 1ab2322f73b..a3a91cbcda8 100644
--- a/extern/quadriflow/CMakeLists.txt
+++ b/extern/quadriflow/CMakeLists.txt
@@ -67,6 +67,18 @@ set(INC_SYS
${EIGEN3_INCLUDE_DIRS}
)
+#if(WITH_TBB)
+# add_definitions(-DWITH_TBB)
+#
+# list(APPEND INC_SYS
+# ${TBB_INCLUDE_DIRS}
+# )
+#
+# list(APPEND LIB
+# ${TBB_LIBRARIES}
+# )
+#endif()
+
set(SRC
src/adjacent-matrix.cpp
src/adjacent-matrix.hpp
diff --git a/extern/quadriflow/src/optimizer.cpp b/extern/quadriflow/src/optimizer.cpp
index 1c59ad0f70c..8a7017393e8 100644
--- a/extern/quadriflow/src/optimizer.cpp
+++ b/extern/quadriflow/src/optimizer.cpp
@@ -13,6 +13,13 @@
#include "flow.hpp"
#include "parametrizer.hpp"
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
+
namespace qflow {
#ifdef WITH_CUDA
diff --git a/extern/quadriflow/src/parametrizer-int.cpp b/extern/quadriflow/src/parametrizer-int.cpp
index 08fa36c1baa..f80dd35cee5 100644
--- a/extern/quadriflow/src/parametrizer-int.cpp
+++ b/extern/quadriflow/src/parametrizer-int.cpp
@@ -6,6 +6,16 @@
#include <random>
#include "optimizer.hpp"
+#include <algorithm>
+
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
+
+
namespace qflow {
diff --git a/extern/quadriflow/src/parametrizer-mesh.cpp b/extern/quadriflow/src/parametrizer-mesh.cpp
index 19effe92390..418345bce7a 100644
--- a/extern/quadriflow/src/parametrizer-mesh.cpp
+++ b/extern/quadriflow/src/parametrizer-mesh.cpp
@@ -8,6 +8,16 @@
#include "dedge.hpp"
#include <queue>
+#include <algorithm>
+
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
+
+
namespace qflow {
void Parametrizer::NormalizeMesh() {
diff --git a/extern/quadriflow/src/parametrizer-sing.cpp b/extern/quadriflow/src/parametrizer-sing.cpp
index 2d600e3cda4..cb1399fb50a 100644
--- a/extern/quadriflow/src/parametrizer-sing.cpp
+++ b/extern/quadriflow/src/parametrizer-sing.cpp
@@ -2,6 +2,14 @@
#include "field-math.hpp"
#include "parametrizer.hpp"
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
+
+
namespace qflow {
void Parametrizer::ComputeOrientationSingularities() {
diff --git a/extern/quadriflow/src/parametrizer.hpp b/extern/quadriflow/src/parametrizer.hpp
index 1f4a02be6c2..ed9ec88c05a 100644
--- a/extern/quadriflow/src/parametrizer.hpp
+++ b/extern/quadriflow/src/parametrizer.hpp
@@ -19,6 +19,13 @@
#include "post-solver.hpp"
#include "serialize.hpp"
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
+
namespace qflow {
using namespace Eigen;
diff --git a/extern/quadriflow/src/subdivide.cpp b/extern/quadriflow/src/subdivide.cpp
index c408bbc6394..670291baeb4 100644
--- a/extern/quadriflow/src/subdivide.cpp
+++ b/extern/quadriflow/src/subdivide.cpp
@@ -8,6 +8,14 @@
#include "field-math.hpp"
#include "parametrizer.hpp"
+#include <algorithm>
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
+
namespace qflow {
void subdivide(MatrixXi &F, MatrixXd &V, VectorXd& rho, VectorXi &V2E, VectorXi &E2E, VectorXi &boundary,
diff --git a/intern/instant-meshes/instant_meshes_c_api.h b/intern/instant-meshes/instant_meshes_c_api.h
index 038a8769eb8..a4330368bd5 100644
--- a/intern/instant-meshes/instant_meshes_c_api.h
+++ b/intern/instant-meshes/instant_meshes_c_api.h
@@ -1,5 +1,7 @@
#pragma once
+//#define INSTANT_MESHES_VIS_COLOR
+
/* clang-format off */
//remeshedge->flag
enum {
@@ -10,6 +12,9 @@ enum {
typedef struct RemeshVertex {
float co[3], no[3];
+#ifdef INSTANT_MESHES_VIS_COLOR
+ float viscolor[3];
+#endif
} RemeshVertex;
// edge constraint
@@ -41,6 +46,8 @@ typedef struct RemeshMesh {
int totoutface;
int totoutvert;
+
+ int goal_faces, iterations;
} RemeshMesh;
#ifdef __cplusplus
diff --git a/intern/instant-meshes/src/c_api.cpp b/intern/instant-meshes/src/c_api.cpp
index 5bfc47c6c66..666447cc2a9 100644
--- a/intern/instant-meshes/src/c_api.cpp
+++ b/intern/instant-meshes/src/c_api.cpp
@@ -19,7 +19,7 @@
int instant_meshes_nprocs = 1;
-const float len_v3v3(const float *a, const float *b)
+static const float len_v3v3(const float *a, const float *b)
{
float dx = a[0] - b[0];
float dy = a[1] - b[1];
@@ -30,6 +30,34 @@ const float len_v3v3(const float *a, const float *b)
return len > 0.0f ? sqrtf(len) : 0.0f;
}
+static void cross_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
+{
+ float n1[3], n2[3];
+
+ n1[0] = v1[0] - v2[0];
+ n2[0] = v2[0] - v3[0];
+ n1[1] = v1[1] - v2[1];
+ n2[1] = v2[1] - v3[1];
+ n1[2] = v1[2] - v2[2];
+ n2[2] = v2[2] - v3[2];
+ n[0] = n1[1] * n2[2] - n1[2] * n2[1];
+ n[1] = n1[2] * n2[0] - n1[0] * n2[2];
+ n[2] = n1[0] * n2[1] - n1[1] * n2[0];
+}
+
+/* Triangles */
+static float area_tri_v3(const float v1[3], const float v2[3], const float v3[3])
+{
+ float n[3];
+ cross_tri_v3(n, v1, v2, v3);
+ return sqrtf(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]) * 0.5f;
+}
+
+static float fract(float f)
+{
+ return f - floorf(f);
+}
+
extern "C" {
void instant_meshes_run(RemeshMesh *mesh)
{
@@ -47,18 +75,22 @@ void instant_meshes_run(RemeshMesh *mesh)
V.resize(3, mesh->totvert);
N.resize(3, mesh->totvert);
- // F.resize(mesh->tottri * 3);
- // V.resize(mesh->totvert * 3);
- // N.resize(mesh->totvert * 3);
+ float area = 0.0f;
for (int i = 0; i < mesh->tottri; i++) {
RemeshTri *tri = mesh->tris + i;
- elen += len_v3v3(mesh->verts[tri->v1].co, mesh->verts[tri->v2].co);
- elen += len_v3v3(mesh->verts[tri->v2].co, mesh->verts[tri->v3].co);
- elen += len_v3v3(mesh->verts[tri->v3].co, mesh->verts[tri->v1].co);
+ float *co1 = mesh->verts[tri->v1].co;
+ float *co2 = mesh->verts[tri->v2].co;
+ float *co3 = mesh->verts[tri->v3].co;
+
+ elen += len_v3v3(co1, co2);
+ elen += len_v3v3(co2, co3);
+ elen += len_v3v3(co3, co1);
totlen += 3;
+ area += area_tri_v3(co1, co2, co3);
+
F(0, i) = tri->v1;
F(1, i) = tri->v2;
F(2, i) = tri->v3;
@@ -75,14 +107,18 @@ void instant_meshes_run(RemeshMesh *mesh)
if (totlen > 0) {
elen /= totlen;
- scale = elen * 4.0f;
+ }
+
+ scale = sqrt(area / (float)mesh->goal_faces);
+ if (scale == 0.0f) {
+ return; // error
}
const bool extrinsic = true;
const bool deterministic = false;
- const int rosy = 4, posy = 4;
+ const int rosy = 2, posy = 4;
- printf("scale: %.5f\n", scale);
+ printf("totarea: %.4f, scale: %.5f\n", area, scale);
VectorXu V2E, E2E;
VectorXb boundary;
@@ -161,8 +197,10 @@ void instant_meshes_run(RemeshMesh *mesh)
opt.setRoSy(rosy);
opt.setPoSy(posy);
+ const int iterations = mesh->iterations;
+
printf("optimizing orientation field\n");
- for (int step = 0; step < 1; step++) {
+ for (int step = 0; step < iterations; step++) {
opt.optimizeOrientations(-1);
opt.notify();
opt.wait();
@@ -173,7 +211,7 @@ void instant_meshes_run(RemeshMesh *mesh)
cout << "Orientation field has " << sing.size() << " singularities." << endl;
printf("optimizing position field\n");
- for (int step = 0; step < 1; step++) {
+ for (int step = 0; step < iterations; step++) {
opt.optimizePositions(-1);
opt.notify();
opt.wait();
@@ -183,8 +221,50 @@ void instant_meshes_run(RemeshMesh *mesh)
compute_position_singularities(mRes, sing, pos_sing, extrinsic, rosy, posy);
cout << "Position field has " << pos_sing.size() << " singularities." << endl;
+#ifdef INSTANT_MESHES_VIS_COLOR
+ {
+ mesh->totoutface = mesh->tottri;
+ mesh->totoutvert = mesh->totvert;
+
+ mesh->outfaces = (RemeshOutFace *)MEM_malloc_arrayN(
+ mesh->tottri, sizeof(RemeshOutFace), "RemeshOutFace");
+ mesh->outverts = (RemeshVertex *)MEM_malloc_arrayN(
+ mesh->totvert, sizeof(RemeshVertex), "RemeshVertex");
+ memcpy(mesh->outverts, mesh->verts, sizeof(*mesh->outverts) * mesh->totvert);
+ mesh->out_scracth = (int *)MEM_malloc_arrayN(mesh->tottri * 3, sizeof(int), "out_scratch");
+
+ int li = 0;
+ RemeshOutFace *f = mesh->outfaces;
+ RemeshTri *tri = mesh->tris;
+ RemeshVertex *v = mesh->outverts;
+
+ auto O = mRes.O(0);
+ printf("O size: [%d][%d]\n", (int)O.cols(), (int)O.rows());
+
+ for (int i = 0; i < mesh->totvert; i++, v++) {
+ v->viscolor[0] = O(0, i);
+ v->viscolor[1] = O(1, i);
+ // v->viscolor[2] = O(2, i);
+ }
+
+ for (int i = 0; i < mesh->tottri; i++, f++, tri++) {
+ f->verts = mesh->out_scracth + li;
+ li += 3;
+
+ f->verts[0] = tri->v1;
+ f->verts[1] = tri->v2;
+ f->verts[2] = tri->v3;
+ f->totvert = 3;
+ }
+ }
+#endif
+
opt.shutdown();
+#ifdef INSTANT_MESHES_VIS_COLOR
+ return;
+#endif
+
std::vector<std::vector<TaggedLink>> adj_extracted;
MatrixXu F_extracted;
@@ -219,7 +299,7 @@ void instant_meshes_run(RemeshMesh *mesh)
mRes.scale(),
creaseOut,
true,
- false,
+ true,
nullptr,
0);
diff --git a/intern/quadriflow/quadriflow_capi.cpp b/intern/quadriflow/quadriflow_capi.cpp
index 18b01099eba..f5504e43474 100644
--- a/intern/quadriflow/quadriflow_capi.cpp
+++ b/intern/quadriflow/quadriflow_capi.cpp
@@ -172,13 +172,13 @@ void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd,
const int steps = 2;
/* Setup mesh boundary constraints if needed */
-#if 0
+#if 1
if (true) { // field.flag_preserve_boundary) {
Hierarchy &mRes = field.hierarchy;
mRes.clearConstraints();
for (uint32_t i = 0; i < 3 * mRes.mF.cols(); ++i) {
- if (mRes.mFF((i) % 3, i / 3) & QFLOW_CONSTRAINED) {
+ if (qrd->faces[i / 3].eflag[i % 3] & QFLOW_CONSTRAINED) {
// if (mRes.mE2E[i] == -1) {
uint32_t i0 = mRes.mF(i % 3, i / 3);
uint32_t i1 = mRes.mF((i + 1) % 3, i / 3);
@@ -193,7 +193,8 @@ void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd,
}
}
}
- for (int j = 0; j < 10; j++) {
+
+ for (int j = 0; j < 2; j++) {
mRes.propagateConstraints();
}
}
diff --git a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h b/source/blender/blenkernel/BKE_mesh_remesh_voxel.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list