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
path: root/intern
diff options
context:
space:
mode:
Diffstat (limited to 'intern')
-rw-r--r--intern/CMakeLists.txt5
-rw-r--r--intern/openvdb/CMakeLists.txt5
-rw-r--r--intern/openvdb/intern/openvdb_level_set.cc179
-rw-r--r--intern/openvdb/intern/openvdb_level_set.h74
-rw-r--r--intern/openvdb/intern/openvdb_transform.cc43
-rw-r--r--intern/openvdb/intern/openvdb_transform.h37
-rw-r--r--intern/openvdb/openvdb_capi.cc148
-rw-r--r--intern/openvdb/openvdb_capi.h106
-rw-r--r--intern/qex/CMakeLists.txt56
-rw-r--r--intern/qex/igl_capi.cc214
-rw-r--r--intern/qex/igl_capi.h36
-rw-r--r--intern/qex/qex_capi.cc25
-rw-r--r--intern/qex/qex_capi.h36
13 files changed, 961 insertions, 3 deletions
diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt
index b93f2057b47..f9044920ebb 100644
--- a/intern/CMakeLists.txt
+++ b/intern/CMakeLists.txt
@@ -76,3 +76,8 @@ endif()
if(WITH_OPENVDB)
add_subdirectory(openvdb)
endif()
+
+if(WITH_QEX)
+ add_definitions(-DWITH_QEX)
+ add_subdirectory(qex)
+endif()
diff --git a/intern/openvdb/CMakeLists.txt b/intern/openvdb/CMakeLists.txt
index bcb1d545c94..412dade0f1a 100644
--- a/intern/openvdb/CMakeLists.txt
+++ b/intern/openvdb/CMakeLists.txt
@@ -21,6 +21,7 @@
set(INC
.
intern
+ ../guardedalloc
)
set(INC_SYS
@@ -56,12 +57,16 @@ if(WITH_OPENVDB)
intern/openvdb_dense_convert.cc
intern/openvdb_reader.cc
intern/openvdb_writer.cc
+ intern/openvdb_level_set.cc
+ intern/openvdb_transform.cc
openvdb_capi.cc
openvdb_util.cc
intern/openvdb_dense_convert.h
intern/openvdb_reader.h
intern/openvdb_writer.h
+ intern/openvdb_level_set.h
+ intern/openvdb_transform.h
openvdb_util.h
)
diff --git a/intern/openvdb/intern/openvdb_level_set.cc b/intern/openvdb/intern/openvdb_level_set.cc
new file mode 100644
index 00000000000..ac4a041c193
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_level_set.cc
@@ -0,0 +1,179 @@
+/*
+ * 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.
+ */
+
+#include "openvdb_level_set.h"
+#include "openvdb_util.h"
+#include "openvdb_capi.h"
+#include "MEM_guardedalloc.h"
+#include "openvdb/tools/Composite.h"
+
+OpenVDBLevelSet::OpenVDBLevelSet()
+{
+ openvdb::initialize();
+}
+
+OpenVDBLevelSet::~OpenVDBLevelSet()
+{
+}
+
+void OpenVDBLevelSet::OpenVDB_mesh_to_level_set(const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ openvdb::math::Transform::Ptr xform)
+{
+ std::vector<openvdb::Vec3s> points;
+ std::vector<openvdb::Vec3I> triangles;
+ std::vector<openvdb::Vec4I> quads;
+
+ for (unsigned int i = 0; i < totvertices; i++) {
+ openvdb::Vec3s v(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]);
+ points.push_back(v);
+ }
+
+ for (unsigned int i = 0; i < totfaces; i++) {
+ openvdb::Vec3I f(faces[i * 3], faces[i * 3 + 1], faces[i * 3 + 2]);
+ triangles.push_back(f);
+ }
+
+ this->grid = openvdb::tools::meshToLevelSet<openvdb::FloatGrid>(
+ *xform, points, triangles, quads, 1);
+}
+
+void OpenVDBLevelSet::OpenVDB_volume_to_mesh(OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles)
+{
+ std::vector<openvdb::Vec3s> out_points;
+ std::vector<openvdb::Vec4I> out_quads;
+ std::vector<openvdb::Vec3I> out_tris;
+ openvdb::tools::volumeToMesh<openvdb::FloatGrid>(*this->grid,
+ out_points,
+ out_tris,
+ out_quads,
+ isovalue,
+ adaptivity,
+ relax_disoriented_triangles);
+ mesh->vertices = (float *)MEM_malloc_arrayN(
+ out_points.size(), 3 * sizeof(float), "openvdb remesher out verts");
+ mesh->quads = (unsigned int *)MEM_malloc_arrayN(
+ out_quads.size(), 4 * sizeof(unsigned int), "openvdb remesh out quads");
+ mesh->triangles = NULL;
+ if (out_tris.size() > 0) {
+ mesh->triangles = (unsigned int *)MEM_malloc_arrayN(
+ out_tris.size(), 3 * sizeof(unsigned int), "openvdb remesh out tris");
+ }
+
+ mesh->totvertices = out_points.size();
+ mesh->tottriangles = out_tris.size();
+ mesh->totquads = out_quads.size();
+
+ for (unsigned int i = 0; i < out_points.size(); i++) {
+ mesh->vertices[i * 3] = out_points[i].x();
+ mesh->vertices[i * 3 + 1] = out_points[i].y();
+ mesh->vertices[i * 3 + 2] = out_points[i].z();
+ }
+
+ for (unsigned int i = 0; i < out_quads.size(); i++) {
+ mesh->quads[i * 4] = out_quads[i].x();
+ mesh->quads[i * 4 + 1] = out_quads[i].y();
+ mesh->quads[i * 4 + 2] = out_quads[i].z();
+ mesh->quads[i * 4 + 3] = out_quads[i].w();
+ }
+
+ for (unsigned int i = 0; i < out_tris.size(); i++) {
+ mesh->triangles[i * 3] = out_tris[i].x();
+ mesh->triangles[i * 3 + 1] = out_tris[i].y();
+ mesh->triangles[i * 3 + 2] = out_tris[i].z();
+ }
+}
+
+void OpenVDBLevelSet::OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ int filter_bias)
+{
+
+ if (!this->grid) {
+ return;
+ }
+
+ if (this->grid && this->grid->getGridClass() != openvdb::GRID_LEVEL_SET) {
+ return;
+ }
+
+ openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(*this->grid);
+ filter.setSpatialScheme((openvdb::math::BiasedGradientScheme)filter_bias);
+ switch (filter_type) {
+ case OPENVDB_LEVELSET_FILTER_GAUSSIAN:
+ filter.gaussian(width);
+ break;
+ case OPENVDB_LEVELSET_FILTER_MEDIAN:
+ filter.median(width);
+ break;
+ case OPENVDB_LEVELSET_FILTER_MEAN:
+ filter.mean(width);
+ break;
+ case OPENVDB_LEVELSET_FILTER_MEAN_CURVATURE:
+ filter.meanCurvature();
+ break;
+ case OPENVDB_LEVELSET_FILTER_LAPLACIAN:
+ filter.laplacian();
+ break;
+ case OPENVDB_LEVELSET_FILTER_DILATE:
+ filter.offset(-iterations / 100.0);
+ break;
+ case OPENVDB_LEVELSET_FILTER_ERODE:
+ filter.offset(iterations / 100.0);
+ break;
+ }
+}
+openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_CSG_operation(
+ openvdb::FloatGrid::Ptr gridA,
+ openvdb::FloatGrid::Ptr gridB,
+ OpenVDBLevelSet_CSGOperation operation)
+{
+ openvdb::FloatGrid::Ptr gridA_copy = gridA; //->deepCopy();
+ openvdb::FloatGrid::Ptr gridB_copy = gridB; //->deepCopy();
+
+ switch (operation) {
+ case OPENVDB_LEVELSET_CSG_UNION:
+ openvdb::tools::csgUnion(*gridA_copy, *gridB_copy);
+ break;
+ case OPENVDB_LEVELSET_CSG_DIFFERENCE:
+ openvdb::tools::csgDifference(*gridA_copy, *gridB_copy);
+ break;
+ case OPENVDB_LEVELSET_CSG_INTERSECTION:
+ openvdb::tools::csgIntersection(*gridA_copy, *gridB_copy);
+ break;
+ }
+
+ return gridA_copy;
+}
+
+openvdb::FloatGrid::Ptr OpenVDBLevelSet::OpenVDB_level_set_get_grid()
+{
+ return this->grid;
+}
+
+void OpenVDBLevelSet::OpenVDB_level_set_set_grid(openvdb::FloatGrid::Ptr grid)
+{
+ this->grid = grid;
+}
diff --git a/intern/openvdb/intern/openvdb_level_set.h b/intern/openvdb/intern/openvdb_level_set.h
new file mode 100644
index 00000000000..01d1b8e538a
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_level_set.h
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#ifndef __OPENVDB_LEVEL_SET_H__
+#define __OPENVDB_LEVEL_SET_H__
+
+#include <openvdb/openvdb.h>
+#include <openvdb/math/FiniteDifference.h>
+#include <openvdb/tools/MeshToVolume.h>
+#include <openvdb/tools/VolumeToMesh.h>
+#include <openvdb/tools/LevelSetFilter.h>
+#include <openvdb/tools/GridTransformer.h>
+#include "openvdb_capi.h"
+
+struct OpenVDBLevelSet {
+ private:
+ openvdb::FloatGrid::Ptr grid;
+
+ public:
+ OpenVDBLevelSet();
+ ~OpenVDBLevelSet();
+ openvdb::FloatGrid::Ptr OpenVDB_level_set_get_grid();
+ void OpenVDB_level_set_set_grid(openvdb::FloatGrid::Ptr);
+ void OpenVDB_mesh_to_level_set(const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ const double voxel_size);
+
+ void OpenVDB_mesh_to_level_set(const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ openvdb::math::Transform::Ptr transform);
+
+ void OpenVDB_volume_to_mesh(float *vertices,
+ unsigned int *quads,
+ unsigned int *triangles,
+ unsigned int *totvertices,
+ unsigned int *totfaces,
+ unsigned int *tottriangles,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles);
+ void OpenVDB_volume_to_mesh(struct OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles);
+ void OpenVDB_level_set_filter(OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ int filter_bias);
+ openvdb::FloatGrid::Ptr OpenVDB_CSG_operation(openvdb::FloatGrid::Ptr gridA,
+ openvdb::FloatGrid::Ptr gridB,
+ OpenVDBLevelSet_CSGOperation operation);
+};
+
+#endif /* __OPENVDB_LEVEL_SET_H__ */
diff --git a/intern/openvdb/intern/openvdb_transform.cc b/intern/openvdb/intern/openvdb_transform.cc
new file mode 100644
index 00000000000..5fbd2c298b1
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_transform.cc
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#include "openvdb_transform.h"
+
+OpenVDBTransform::OpenVDBTransform()
+{
+}
+
+OpenVDBTransform::~OpenVDBTransform()
+{
+}
+
+void OpenVDBTransform::OpenVDB_transform_create_linear_transform(double voxel_size)
+{
+ this->transform = openvdb::math::Transform::createLinearTransform(voxel_size);
+}
+
+openvdb::math::Transform::Ptr OpenVDBTransform::OpenVDB_transform_get_transform()
+{
+ return this->transform;
+}
+
+void OpenVDBTransform::OpenVDB_transform_set_transform(openvdb::math::Transform::Ptr transform)
+{
+ this->transform = transform;
+}
diff --git a/intern/openvdb/intern/openvdb_transform.h b/intern/openvdb/intern/openvdb_transform.h
new file mode 100644
index 00000000000..71db0083cd0
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_transform.h
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+#ifndef OPENVDB_TRANSFORM_H
+#define OPENVDB_TRANSFORM_H
+
+#include <openvdb/openvdb.h>
+
+struct OpenVDBTransform {
+ private:
+ openvdb::math::Transform::Ptr transform;
+
+ public:
+ OpenVDBTransform();
+ ~OpenVDBTransform();
+ void OpenVDB_transform_create_linear_transform(double voxel_size);
+ openvdb::math::Transform::Ptr OpenVDB_transform_get_transform();
+ void OpenVDB_transform_set_transform(openvdb::math::Transform::Ptr transform);
+};
+
+#endif // OPENVDB_TRANSFORM_H
diff --git a/intern/openvdb/openvdb_capi.cc b/intern/openvdb/openvdb_capi.cc
index aff27ee6c62..0bee45934d1 100644
--- a/intern/openvdb/openvdb_capi.cc
+++ b/intern/openvdb/openvdb_capi.cc
@@ -20,10 +20,9 @@
#include "openvdb_capi.h"
#include "openvdb_dense_convert.h"
#include "openvdb_util.h"
+#include "openvdb_level_set.h"
+#include "openvdb_transform.h"
-struct OpenVDBFloatGrid {
- int unused;
-};
struct OpenVDBIntGrid {
int unused;
};
@@ -238,3 +237,146 @@ void OpenVDBReader_get_meta_mat4(OpenVDBReader *reader, const char *name, float
{
reader->mat4sMeta(name, value);
}
+
+OpenVDBLevelSet *OpenVDBLevelSet_create(bool initGrid, OpenVDBTransform *xform)
+{
+ OpenVDBLevelSet *level_set = new OpenVDBLevelSet();
+ if (initGrid) {
+ openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
+ grid->setGridClass(openvdb::GRID_LEVEL_SET);
+ if (xform) {
+ grid->setTransform(xform->OpenVDB_transform_get_transform());
+ }
+ level_set->OpenVDB_level_set_set_grid(grid);
+ }
+ return level_set;
+}
+
+OpenVDBTransform *OpenVDBTransform_create()
+{
+ return new OpenVDBTransform();
+}
+
+void OpenVDBTransform_free(OpenVDBTransform *transform)
+{
+ delete transform;
+}
+
+void OpenVDBTransform_create_linear_transform(OpenVDBTransform *transform, double voxel_size)
+{
+ transform->OpenVDB_transform_create_linear_transform(voxel_size);
+}
+
+void OpenVDBLevelSet_free(OpenVDBLevelSet *level_set)
+{
+ delete level_set;
+}
+
+void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ OpenVDBTransform *xform)
+{
+ level_set->OpenVDB_mesh_to_level_set(
+ vertices, faces, totvertices, totfaces, xform->OpenVDB_transform_get_transform());
+}
+
+void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ struct OpenVDBTransform *transform)
+{
+ level_set->OpenVDB_mesh_to_level_set(
+ vertices, faces, totvertices, totfaces, transform->OpenVDB_transform_get_transform());
+}
+
+void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set,
+ struct OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles)
+{
+ level_set->OpenVDB_volume_to_mesh(mesh, isovalue, adaptivity, relax_disoriented_triangles);
+}
+
+void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set,
+ OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ OpenVDBLevelSet_FilterBias bias)
+{
+ level_set->OpenVDB_level_set_filter(filter_type, width, iterations, bias);
+}
+
+void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out,
+ struct OpenVDBLevelSet *gridA,
+ struct OpenVDBLevelSet *gridB,
+ OpenVDBLevelSet_CSGOperation operation)
+{
+ openvdb::FloatGrid::Ptr grid = out->OpenVDB_CSG_operation(
+ gridA->OpenVDB_level_set_get_grid(), gridB->OpenVDB_level_set_get_grid(), operation);
+ out->OpenVDB_level_set_set_grid(grid);
+}
+
+OpenVDBLevelSet *OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
+ struct OpenVDBLevelSet *level_setB,
+ char sampler,
+ float isolevel)
+{
+ openvdb::FloatGrid::Ptr sourceGrid = level_setA->OpenVDB_level_set_get_grid();
+ openvdb::FloatGrid::Ptr targetGrid = level_setB->OpenVDB_level_set_get_grid()->deepCopy();
+
+ const openvdb::math::Transform &sourceXform = sourceGrid->transform(),
+ &targetXform = targetGrid->transform();
+
+ // Compute a source grid to target grid transform.
+ // (For this example, we assume that both grids' transforms are linear,
+ // so that they can be represented as 4 x 4 matrices.)
+ openvdb::Mat4R xform = sourceXform.baseMap()->getAffineMap()->getMat4() *
+ targetXform.baseMap()->getAffineMap()->getMat4().inverse();
+
+ // Create the transformer.
+ openvdb::tools::GridTransformer transformer(xform);
+
+ switch (sampler) {
+ case OPENVDB_LEVELSET_GRIDSAMPLER_POINT:
+ // Resample using nearest-neighbor interpolation.
+ transformer.transformGrid<openvdb::tools::PointSampler, openvdb::FloatGrid>(*sourceGrid,
+ *targetGrid);
+ // Prune the target tree for optimal sparsity.
+ targetGrid->tree().prune();
+ break;
+
+ case OPENVDB_LEVELSET_GRIDSAMPLER_BOX:
+ // Resample using trilinear interpolation.
+ transformer.transformGrid<openvdb::tools::BoxSampler, openvdb::FloatGrid>(*sourceGrid,
+ *targetGrid);
+ // Prune the target tree for optimal sparsity.
+ targetGrid->tree().prune();
+ break;
+
+ case OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC:
+ // Resample using triquadratic interpolation.
+ transformer.transformGrid<openvdb::tools::QuadraticSampler, openvdb::FloatGrid>(*sourceGrid,
+ *targetGrid);
+ // Prune the target tree for optimal sparsity.
+ targetGrid->tree().prune();
+ break;
+
+ case OPENVDB_LEVELSET_GRIDSAMPLER_NONE:
+ // targetGrid = sourceGrid->deepCopy();
+ break;
+ }
+
+ targetGrid = openvdb::tools::levelSetRebuild(*targetGrid, isolevel, 1.0f);
+ openvdb::tools::pruneLevelSet(targetGrid->tree());
+
+ OpenVDBLevelSet *level_set = OpenVDBLevelSet_create(false, NULL);
+ level_set->OpenVDB_level_set_set_grid(targetGrid);
+
+ return level_set;
+}
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 236bceea3e2..4ebf9d85461 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -24,11 +24,78 @@
extern "C" {
#endif
+/* Level Set Filters */
+typedef enum OpenVDBLevelSet_FilterType {
+ OPENVDB_LEVELSET_FILTER_NONE = 0,
+ OPENVDB_LEVELSET_FILTER_GAUSSIAN = 1,
+ OPENVDB_LEVELSET_FILTER_MEAN = 2,
+ OPENVDB_LEVELSET_FILTER_MEDIAN = 3,
+ OPENVDB_LEVELSET_FILTER_MEAN_CURVATURE = 4,
+ OPENVDB_LEVELSET_FILTER_LAPLACIAN = 5,
+ OPENVDB_LEVELSET_FILTER_DILATE = 6,
+ OPENVDB_LEVELSET_FILTER_ERODE = 7,
+} OpenVDBLevelSet_FilterType;
+
+typedef enum OpenVDBLevelSet_FilterBias {
+ OPENVDB_LEVELSET_FIRST_BIAS = 0,
+ OPENVDB_LEVELSET_SECOND_BIAS,
+ OPENVDB_LEVELSET_THIRD_BIAS,
+ OPENVDB_LEVELSET_WENO5_BIAS,
+ OPENVDB_LEVELSET_HJWENO5_BIAS,
+} OpenVDBLevelSet_FilterBias;
+
+/* Level Set CSG Operations */
+typedef enum OpenVDBLevelSet_CSGOperation {
+ OPENVDB_LEVELSET_CSG_UNION = 0,
+ OPENVDB_LEVELSET_CSG_DIFFERENCE = 1,
+ OPENVDB_LEVELSET_CSG_INTERSECTION = 2,
+} OpenVDBLevelSet_CSGOperation;
+
+typedef enum OpenVDBLevelSet_GridSampler {
+ OPENVDB_LEVELSET_GRIDSAMPLER_NONE = 0,
+ OPENVDB_LEVELSET_GRIDSAMPLER_POINT = 1,
+ OPENVDB_LEVELSET_GRIDSAMPLER_BOX = 2,
+ OPENVDB_LEVELSET_GRIDSAMPLER_QUADRATIC = 3,
+} OpenVDBLevelSet_Gridsampler;
+
struct OpenVDBReader;
struct OpenVDBWriter;
+struct OpenVDBTransform;
+struct OpenVDBLevelSet;
struct OpenVDBFloatGrid;
struct OpenVDBIntGrid;
struct OpenVDBVectorGrid;
+struct OpenVDBVolumeToMeshData {
+ int tottriangles;
+ int totquads;
+ int totvertices;
+
+ float *vertices;
+ unsigned int *quads;
+ unsigned int *triangles;
+};
+
+struct OpenVDBRemeshData {
+ float *verts;
+ unsigned int *faces;
+ int totfaces;
+ int totverts;
+
+ float *out_verts;
+ unsigned int *out_faces;
+ unsigned int *out_tris;
+ int out_totverts;
+ int out_totfaces;
+ int out_tottris;
+ int filter_type;
+ int filter_bias;
+ int filter_width; /*parameter for gaussian, median, mean*/
+
+ float voxel_size;
+ float isovalue;
+ float adaptivity;
+ int relax_disoriented_triangles;
+};
int OpenVDB_getVersionHex(void);
@@ -112,6 +179,45 @@ void OpenVDBReader_get_meta_mat4(struct OpenVDBReader *reader,
const char *name,
float value[4][4]);
+struct OpenVDBTransform *OpenVDBTransform_create(void);
+void OpenVDBTransform_free(struct OpenVDBTransform *transform);
+void OpenVDBTransform_create_linear_transform(struct OpenVDBTransform *transform,
+ double voxel_size);
+
+struct OpenVDBLevelSet *OpenVDBLevelSet_create(bool initGrid, struct OpenVDBTransform *xform);
+void OpenVDBLevelSet_free(struct OpenVDBLevelSet *level_set);
+void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ struct OpenVDBTransform *xform);
+void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set,
+ const float *vertices,
+ const unsigned int *faces,
+ const unsigned int totvertices,
+ const unsigned int totfaces,
+ struct OpenVDBTransform *transform);
+void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set,
+ struct OpenVDBVolumeToMeshData *mesh,
+ const double isovalue,
+ const double adaptivity,
+ const bool relax_disoriented_triangles);
+void OpenVDBLevelSet_filter(struct OpenVDBLevelSet *level_set,
+ OpenVDBLevelSet_FilterType filter_type,
+ int width,
+ int iterations,
+ OpenVDBLevelSet_FilterBias bias);
+void OpenVDBLevelSet_CSG_operation(struct OpenVDBLevelSet *out,
+ struct OpenVDBLevelSet *gridA,
+ struct OpenVDBLevelSet *gridB,
+ OpenVDBLevelSet_CSGOperation operation);
+
+struct OpenVDBLevelSet *OpenVDBLevelSet_transform_and_resample(struct OpenVDBLevelSet *level_setA,
+ struct OpenVDBLevelSet *level_setB,
+ char sampler,
+ float isolevel);
+
#ifdef __cplusplus
}
#endif
diff --git a/intern/qex/CMakeLists.txt b/intern/qex/CMakeLists.txt
new file mode 100644
index 00000000000..6d7dbdf2e65
--- /dev/null
+++ b/intern/qex/CMakeLists.txt
@@ -0,0 +1,56 @@
+# ***** 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
+)
+
+set(LIB
+)
+
+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}" "${LIB}")
diff --git a/intern/qex/igl_capi.cc b/intern/qex/igl_capi.cc
new file mode 100644
index 00000000000..59c7740e436
--- /dev/null
+++ b/intern/qex/igl_capi.cc
@@ -0,0 +1,214 @@
+/*# ***** 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, bool *hard_edges)
+{
+
+ 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);
+
+
+ //hard verts (optionally mark too)
+ std::vector<int> hverts;
+
+ //hard edges
+ std::vector<std::vector<int>> hedges;
+ for (int i = 0; i < num_tris; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ if (hard_edges[i * 3 + j])
+ {
+ std::vector<int> hedge;
+ hedge.push_back(i);
+ hedge.push_back(j);
+ hedges.push_back(hedge);
+ }
+ }
+ }
+
+ // 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, true, hverts, hedges);
+
+ // 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..2cedcf0fb5e
--- /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, bool* hard_edges);
+
+
+#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__ */