Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change curvature API #448

Merged
merged 3 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions bindings/c/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ ManifoldMeshGL *to_c(manifold::MeshGL *m) {
return reinterpret_cast<ManifoldMeshGL *>(m);
}

ManifoldCurvature *to_c(manifold::Curvature *m) {
return reinterpret_cast<ManifoldCurvature *>(m);
}

ManifoldOpType to_c(manifold::OpType optype) {
ManifoldOpType op = MANIFOLD_ADD;
switch (optype) {
Expand Down Expand Up @@ -152,10 +148,6 @@ const manifold::MeshGL *from_c(ManifoldMeshGL *m) {
return reinterpret_cast<manifold::MeshGL const *>(m);
}

const manifold::Curvature *from_c(ManifoldCurvature *c) {
return reinterpret_cast<manifold::Curvature const *>(c);
}

OpType from_c(ManifoldOpType optype) {
auto op = OpType::Add;
switch (optype) {
Expand Down
2 changes: 0 additions & 2 deletions bindings/c/include/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ManifoldMesh *to_c(manifold::Mesh *m);
ManifoldMeshGL *to_c(manifold::MeshGL *m);
ManifoldBox *to_c(manifold::Box *m);
ManifoldRect *to_c(manifold::Rect *m);
ManifoldCurvature *to_c(manifold::Curvature *m);
ManifoldError to_c(manifold::Manifold::Error error);
ManifoldVec2 to_c(glm::vec2 v);
ManifoldVec3 to_c(glm::vec3 v);
Expand All @@ -41,7 +40,6 @@ CrossSection::FillRule from_c(ManifoldFillRule fillrule);
CrossSection::JoinType from_c(ManifoldJoinType jt);
const manifold::Box *from_c(ManifoldBox *m);
const manifold::Rect *from_c(ManifoldRect *r);
const manifold::Curvature *from_c(ManifoldCurvature *m);
glm::vec2 from_c(ManifoldVec2 v);
glm::vec3 from_c(ManifoldVec3 v);
glm::ivec3 from_c(ManifoldIVec3 v);
Expand Down
7 changes: 0 additions & 7 deletions bindings/c/include/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m);
float manifold_precision(ManifoldManifold *m);
int manifold_genus(ManifoldManifold *m);
ManifoldProperties manifold_get_properties(ManifoldManifold *m);
ManifoldCurvature *manifold_get_curvature(void *mem, ManifoldManifold *m);
ManifoldCurvatureBounds manifold_curvature_bounds(ManifoldCurvature *curv);
size_t manifold_curvature_vert_length(ManifoldCurvature *curv);
float *manifold_curvature_vert_mean(void *mem, ManifoldCurvature *curv);
float *manifold_curvature_vert_gaussian(void *mem, ManifoldCurvature *curv);
int manifold_get_circular_segments(float radius);
int manifold_original_id(ManifoldManifold *m);

Expand Down Expand Up @@ -333,7 +328,6 @@ void manifold_destruct_polygons(ManifoldPolygons *p);
void manifold_destruct_meshgl(ManifoldMeshGL *m);
void manifold_destruct_box(ManifoldBox *b);
void manifold_destruct_rect(ManifoldRect *b);
void manifold_destruct_curvature(ManifoldCurvature *c);

// pointer free + destruction
void manifold_delete_manifold(ManifoldManifold *m);
Expand All @@ -345,7 +339,6 @@ void manifold_delete_polygons(ManifoldPolygons *p);
void manifold_delete_meshgl(ManifoldMeshGL *m);
void manifold_delete_box(ManifoldBox *b);
void manifold_delete_rect(ManifoldRect *b);
void manifold_delete_curvature(ManifoldCurvature *c);

// MeshIO / Export
#ifdef MANIFOLD_EXPORT
Expand Down
8 changes: 0 additions & 8 deletions bindings/c/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ typedef struct ManifoldSimplePolygon ManifoldSimplePolygon;
typedef struct ManifoldPolygons ManifoldPolygons;
typedef struct ManifoldMesh ManifoldMesh;
typedef struct ManifoldMeshGL ManifoldMeshGL;
typedef struct ManifoldCurvature ManifoldCurvature;
typedef struct ManifoldBox ManifoldBox;
typedef struct ManifoldRect ManifoldRect;

Expand Down Expand Up @@ -56,13 +55,6 @@ typedef struct ManifoldProperties {
float volume;
} ManifoldProperties;

typedef struct ManifoldCurvatureBounds {
float max_mean_curvature;
float min_mean_curvature;
float max_gaussian_curvature;
float min_gaussian_curvature;
} ManifoldCurvatureBounds;

// enums

typedef enum ManifoldOpType {
Expand Down
27 changes: 0 additions & 27 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,28 +448,6 @@ ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m) {
}

float manifold_precision(ManifoldManifold *m) { return from_c(m)->Precision(); }
ManifoldCurvature *manifold_get_curvature(void *mem, ManifoldManifold *m) {
auto curv = from_c(m)->GetCurvature();
return to_c(new (mem) Curvature(curv));
}

ManifoldCurvatureBounds manifold_curvature_bounds(ManifoldCurvature *curv) {
auto c = *from_c(curv);
return {c.maxMeanCurvature, c.minMeanCurvature, c.maxGaussianCurvature,
c.minGaussianCurvature};
}

size_t manifold_curvature_vert_length(ManifoldCurvature *curv) {
return from_c(curv)->vertMeanCurvature.size();
}

float *manifold_curvature_vert_mean(void *mem, ManifoldCurvature *curv) {
return copy_data(mem, from_c(curv)->vertMeanCurvature);
}

float *manifold_curvature_vert_gaussian(void *mem, ManifoldCurvature *curv) {
return copy_data(mem, from_c(curv)->vertGaussianCurvature);
}

// Static Quality Globals

Expand Down Expand Up @@ -502,7 +480,6 @@ size_t manifold_manifold_pair_size() { return sizeof(ManifoldManifoldPair); }
size_t manifold_meshgl_size() { return sizeof(MeshGL); }
size_t manifold_box_size() { return sizeof(Box); }
size_t manifold_rect_size() { return sizeof(Rect); }
size_t manifold_curvature_size() { return sizeof(Curvature); }

// pointer free + destruction
void manifold_delete_cross_section(ManifoldCrossSection *c) {
Expand All @@ -522,7 +499,6 @@ void manifold_delete_manifold_vec(ManifoldManifoldVec *ms) {
void manifold_delete_meshgl(ManifoldMeshGL *m) { delete from_c(m); }
void manifold_delete_box(ManifoldBox *b) { delete from_c(b); }
void manifold_delete_rect(ManifoldRect *r) { delete from_c(r); }
void manifold_delete_curvature(ManifoldCurvature *c) { delete from_c(c); }

// destruction
void manifold_destruct_cross_section(ManifoldCrossSection *cs) {
Expand All @@ -542,9 +518,6 @@ void manifold_destruct_manifold_vec(ManifoldManifoldVec *ms) {
void manifold_destruct_meshgl(ManifoldMeshGL *m) { from_c(m)->~MeshGL(); }
void manifold_destruct_box(ManifoldBox *b) { from_c(b)->~Box(); }
void manifold_destruct_rect(ManifoldRect *r) { from_c(r)->~Rect(); }
void manifold_destruct_curvature(ManifoldCurvature *c) {
from_c(c)->~Curvature();
}

#ifdef __cplusplus
}
Expand Down
12 changes: 3 additions & 9 deletions bindings/wasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ EMSCRIPTEN_BINDINGS(whatever) {
.field("surfaceArea", &Properties::surfaceArea)
.field("volume", &Properties::volume);

value_object<Curvature>("curvature")
.field("maxMeanCurvature", &Curvature::maxMeanCurvature)
.field("minMeanCurvature", &Curvature::minMeanCurvature)
.field("maxGaussianCurvature", &Curvature::maxGaussianCurvature)
.field("minGaussianCurvature", &Curvature::minGaussianCurvature)
.field("vertMeanCurvature", &Curvature::vertMeanCurvature)
.field("vertGaussianCurvature", &Curvature::vertGaussianCurvature);

register_vector<glm::ivec3>("Vector_ivec3");
register_vector<glm::vec3>("Vector_vec3");
register_vector<glm::vec2>("Vector_vec2");
Expand Down Expand Up @@ -157,11 +149,13 @@ EMSCRIPTEN_BINDINGS(whatever) {
.function("numVert", &Manifold::NumVert)
.function("numEdge", &Manifold::NumEdge)
.function("numTri", &Manifold::NumTri)
.function("numProp", &Manifold::NumProp)
.function("numPropVert", &Manifold::NumPropVert)
.function("_boundingBox", &Manifold::BoundingBox)
.function("precision", &Manifold::Precision)
.function("genus", &Manifold::Genus)
.function("getProperties", &Manifold::GetProperties)
.function("_getCurvature", &Manifold::GetCurvature)
.function("calculateCurvature", &Manifold::CalculateCurvature)
.function("originalID", &Manifold::OriginalID)
.function("asOriginal", &Manifold::AsOriginal);

Expand Down
13 changes: 1 addition & 12 deletions bindings/wasm/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Module.setup = function() {
};

Module.Manifold.prototype.setProperties = function(numProp, func) {
const oldNumProp = this.numProp;
const oldNumProp = this.numProp();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug - reading existing properties didn't work before.

const wasmFuncPtr = addFunction(function(newPtr, vec3Ptr, oldPtr) {
const newProp = [];
for (let i = 0; i < numProp; ++i) {
Expand Down Expand Up @@ -300,17 +300,6 @@ Module.setup = function() {
return result;
};

Module.Manifold.prototype.getCurvature = function() {
const result = this._getCurvature();
const oldMeanCurvature = result.vertMeanCurvature;
const oldGaussianCurvature = result.vertGaussianCurvature;
result.vertMeanCurvature = fromVec(oldMeanCurvature);
result.vertGaussianCurvature = fromVec(oldGaussianCurvature);
oldMeanCurvature.delete();
oldGaussianCurvature.delete();
return result;
};

Module.Manifold.prototype.boundingBox = function() {
const result = this._boundingBox();
return {
Expand Down
23 changes: 22 additions & 1 deletion bindings/wasm/examples/public/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,28 @@ export const examples = {
const triVerts = Uint32Array.from(triangles);
const vertProperties = Float32Array.from(positions);
const scallop = new Mesh({numProp: 3, triVerts, vertProperties});
const result = Manifold.smooth(scallop, sharpenedEdges).refine(n);

const colorCurvature = (color, pos, oldProp) => {
const a = Math.max(0, Math.min(1, oldProp[0] / 3 + 0.5));
const b = a * a * (3 - 2 * a);
const red = [1, 0, 0];
const blue = [0, 0, 1];
for (let i = 0; i < 3; ++i) {
color[i] = (1 - b) * blue[i] + b * red[i];
}
};
const result = Manifold.smooth(scallop, sharpenedEdges)
.refine(n)
.calculateCurvature(-1, 0)
.setProperties(3, colorCurvature);

const node = new GLTFNode();
node.manifold = result;
node.material = {
baseColorFactor: [1, 1, 1],
metallic: 0,
attributes: ['COLOR_0']
};
return result;
},

Expand Down
44 changes: 32 additions & 12 deletions bindings/wasm/manifold-encapsulated-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {Box, Curvature, FillRule, JoinType, Mat4, Polygons, Properties, Rect, SealedFloat32Array, SealedUint32Array, SimplePolygon, Smoothness, Vec2, Vec3} from './manifold-global-types';
import {Box, FillRule, JoinType, Mat4, Polygons, Properties, Rect, SealedFloat32Array, SealedUint32Array, SimplePolygon, Smoothness, Vec2, Vec3} from './manifold-global-types';

/**
* Triangulates a set of /epsilon-valid polygons.
Expand Down Expand Up @@ -582,6 +582,25 @@ export class Manifold {
propFunc: (newProp: number[], position: Vec3, oldProp: number[]) => void):
Manifold;

/**
* Curvature is the inverse of the radius of curvature, and signed such that
* positive is convex and negative is concave. There are two orthogonal
* principal curvatures at any point on a manifold, with one maximum and the
* other minimum. Gaussian curvature is their product, while mean
* curvature is their sum. This approximates them for every vertex and assigns
* them as vertex properties on the given channels.
*
* @param gaussianIdx The property channel index in which to store the
* Gaussian curvature. An index < 0 will be ignored (stores nothing). The
* property set will be automatically expanded to include the channel
* index specified.
* @param meanIdx The property channel index in which to store the mean
* curvature. An index < 0 will be ignored (stores nothing). The property
* set will be automatically expanded to include the channel index
* specified.
*/
calculateCurvature(gaussianIdx: number, meanIdx: number): Manifold;

// Boolean Operations

/**
Expand Down Expand Up @@ -702,6 +721,18 @@ export class Manifold {
*/
numEdge(): number;

/**
* The number of properties per vertex in the Manifold.
*/
numProp(): number;

/**
* The number of property vertices in the Manifold. This will always be >=
* numVert, as some physical vertices may be duplicated to account for
* different properties on different neighboring triangles.
*/
numPropVert(): number

/**
* Returns the axis-aligned bounding box of all the Manifold's vertices.
*/
Expand Down Expand Up @@ -732,17 +763,6 @@ export class Manifold {
*/
getProperties(): Properties;

/**
* Curvature is the inverse of the radius of curvature, and signed such that
* positive is convex and negative is concave. There are two orthogonal
* principal curvatures at any point on a manifold, with one maximum and the
* other minimum. Gaussian curvature is their product, while mean
* curvature is their sum. This approximates them for every vertex (returned
* as vectors in the structure) and also returns their minimum and maximum
* values.
*/
getCurvature(): Curvature;

// Export

/**
Expand Down
8 changes: 0 additions & 8 deletions bindings/wasm/manifold-global-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,5 @@ export type Properties = {
surfaceArea: number,
volume: number
};
export type Curvature = {
maxMeanCurvature: number,
minMeanCurvature: number,
maxGaussianCurvature: number,
minGaussianCurvature: number,
vertMeanCurvature: number[],
vertGaussianCurvature: number[]
};
export type FillRule = 'EvenOdd'|'NonZero'|'Positive'|'Negative'
export type JoinType = 'Square'|'Round'|'Miter'
2 changes: 1 addition & 1 deletion src/manifold/include/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class Manifold {
float Precision() const;
int Genus() const;
Properties GetProperties() const;
Curvature GetCurvature() const;
///@}

/** @name Mesh ID
Expand All @@ -208,6 +207,7 @@ class Manifold {
Manifold Warp(std::function<void(glm::vec3&)>) const;
Manifold SetProperties(
int, std::function<void(float*, glm::vec3, const float*)>) const;
Manifold CalculateCurvature(int gaussianIdx, int meanIdx) const;
Manifold Refine(int) const;
// Manifold RefineToLength(float);
// Manifold RefineToPrecision(float);
Expand Down
2 changes: 1 addition & 1 deletion src/manifold/src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct Manifold::Impl {

// properties.cu
Properties GetProperties() const;
Curvature GetCurvature() const;
void CalculateCurvature(int gaussianIdx, int meanIdx);
void CalculateBBox();
bool IsFinite() const;
bool IsIndexInBounds(const VecDH<glm::ivec3>& triVerts) const;
Expand Down
34 changes: 22 additions & 12 deletions src/manifold/src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,6 @@ Properties Manifold::GetProperties() const {
return GetCsgLeafNode().GetImpl()->GetProperties();
}

/**
* Curvature is the inverse of the radius of curvature, and signed such that
* positive is convex and negative is concave. There are two orthogonal
* principal curvatures at any point on a manifold, with one maximum and the
* other minimum. Gaussian curvature is their product, while mean
* curvature is their sum. This approximates them for every vertex (returned as
* vectors in the structure) and also returns their minimum and maximum values.
*/
Curvature Manifold::GetCurvature() const {
return GetCsgLeafNode().GetImpl()->GetCurvature();
}

/**
* If this mesh is an original, this returns its meshID that can be referenced
* by product manifolds' MeshRelation. If this manifold is a product, this
Expand Down Expand Up @@ -619,6 +607,28 @@ Manifold Manifold::SetProperties(
return Manifold(std::make_shared<CsgLeafNode>(pImpl));
}

/**
* Curvature is the inverse of the radius of curvature, and signed such that
* positive is convex and negative is concave. There are two orthogonal
* principal curvatures at any point on a manifold, with one maximum and the
* other minimum. Gaussian curvature is their product, while mean
* curvature is their sum. This approximates them for every vertex and assigns
* them as vertex properties on the given channels.
*
* @param gaussianIdx The property channel index in which to store the Gaussian
* curvature. An index < 0 will be ignored (stores nothing). The property set
* will be automatically expanded to include the channel index specified.
*
* @param meanIdx The property channel index in which to store the mean
* curvature. An index < 0 will be ignored (stores nothing). The property set
* will be automatically expanded to include the channel index specified.
*/
Manifold Manifold::CalculateCurvature(int gaussianIdx, int meanIdx) const {
auto pImpl = std::make_shared<Impl>(*GetCsgLeafNode().GetImpl());
pImpl->CalculateCurvature(gaussianIdx, meanIdx);
return Manifold(std::make_shared<CsgLeafNode>(pImpl));
}

/**
* Increase the density of the mesh by splitting every edge into n pieces. For
* instance, with n = 2, each triangle will be split into 4 triangles. These
Expand Down
Loading