-
Notifications
You must be signed in to change notification settings - Fork 40
Adding Signed Heat Method (& a bit more!) #28
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
434c613
All tests passed
nzfeng 9eb2472
Clean up comments; add documentation to README
nzfeng e1aeaf5
Update geometry-central to latest, edit README to not focus on polygo…
nzfeng 95c3cf5
Add bindings for (signed) fast marching
nzfeng c062177
Add fast marching and edges() function
nzfeng ce2c2d9
Update README
nzfeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule geometry-central
updated
128 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #include "heat_helpers.h" | ||
|
|
||
| std::vector<Curve> toSignedCurves(SurfaceMesh& mesh, | ||
| const std::vector<std::vector<std::pair<int64_t, std::vector<double>>>>& pythonCurves, | ||
| const std::vector<bool>& isSigned) { | ||
|
|
||
| std::vector<Curve> curves; | ||
|
|
||
| for (size_t i = 0; i < pythonCurves.size(); i++) { | ||
| Curve curve; | ||
| curve.isSigned = (i < isSigned.size()) ? isSigned[i] : true; // default to signed if not specified | ||
|
|
||
| for (const auto& node : pythonCurves[i]) { | ||
| size_t elementIndex = node.first; | ||
| const std::vector<double>& baryCoords = node.second; | ||
|
|
||
| if (baryCoords.size() < 1) { | ||
| curve.nodes.emplace_back(mesh.vertex(elementIndex)); | ||
| } else if (baryCoords.size() == 1) { | ||
| curve.nodes.emplace_back(mesh.edge(elementIndex), baryCoords[0]); | ||
| } else if (baryCoords.size() >= 2) { | ||
| double tC = (baryCoords.size() == 3) ? baryCoords[2] : 1.0 - baryCoords[0] - baryCoords[1]; | ||
| Vector3 faceCoords = {baryCoords[0], baryCoords[1], tC}; | ||
| curve.nodes.emplace_back(mesh.face(elementIndex), faceCoords); | ||
| } else { | ||
| throw std::runtime_error("Invalid barycentric coordinates for a curve node."); | ||
| } | ||
| } | ||
| curves.push_back(curve); | ||
| } | ||
|
|
||
| return curves; | ||
| } | ||
|
|
||
| std::vector<Curve> toSignedCurves(SurfaceMesh& mesh, const std::vector<std::vector<int64_t>>& pythonCurves, | ||
| const std::vector<bool>& isSigned) { | ||
|
|
||
| std::vector<Curve> curves; | ||
|
|
||
| for (size_t i = 0; i < pythonCurves.size(); i++) { | ||
| Curve curve; | ||
| curve.isSigned = (i < isSigned.size()) ? isSigned[i] : true; // default to signed if not specified | ||
| curve.nodes = toSurfacePoints(mesh, pythonCurves[i]); | ||
| curves.push_back(curve); | ||
| } | ||
|
|
||
| return curves; | ||
| } | ||
|
|
||
| std::vector<std::vector<Vertex>> toSignedVertices(SurfaceMesh& mesh, | ||
| const std::vector<std::vector<int64_t>>& pythonCurves) { | ||
| std::vector<std::vector<Vertex>> curves; | ||
| for (size_t i = 0; i < pythonCurves.size(); i++) { | ||
| curves.emplace_back(); | ||
| for (const auto& vIdx : pythonCurves[i]) { | ||
| curves.back().push_back(mesh.vertex(vIdx)); | ||
| } | ||
| } | ||
| return curves; | ||
| } | ||
|
|
||
| std::vector<SurfacePoint> toSurfacePoints(SurfaceMesh& mesh, | ||
| const std::vector<std::pair<int64_t, std::vector<double>>>& pythonPoints) { | ||
|
|
||
| std::vector<SurfacePoint> points; | ||
|
|
||
| for (const auto& point : pythonPoints) { | ||
| size_t elementIndex = point.first; | ||
| const std::vector<double>& baryCoords = point.second; | ||
|
|
||
| if (baryCoords.size() < 1) { | ||
| points.emplace_back(mesh.vertex(elementIndex)); | ||
| } else if (baryCoords.size() == 1) { | ||
| points.emplace_back(mesh.edge(elementIndex), baryCoords[0]); | ||
| } else if (baryCoords.size() >= 2) { | ||
| double tC = (baryCoords.size() == 3) ? baryCoords[2] : 1.0 - baryCoords[0] - baryCoords[1]; | ||
| Vector3 faceCoords = {baryCoords[0], baryCoords[1], tC}; | ||
| points.emplace_back(mesh.face(elementIndex), faceCoords); | ||
| } else { | ||
| throw std::runtime_error("Invalid barycentric coordinates for surface point."); | ||
| } | ||
| } | ||
|
|
||
| return points; | ||
| } | ||
|
|
||
| std::vector<SurfacePoint> toSurfacePoints(SurfaceMesh& mesh, const std::vector<int64_t>& pythonPoints) { | ||
|
|
||
| std::vector<SurfacePoint> points; | ||
|
|
||
| for (const auto& vIdx : pythonPoints) { | ||
| points.emplace_back(mesh.vertex(vIdx)); | ||
| } | ||
|
|
||
| return points; | ||
| } | ||
|
|
||
| SignedHeatOptions toSignedHeatOptions(bool preserveSourceNormals, const std::string& levelSetConstraint, | ||
| double softLevelSetWeight) { | ||
|
|
||
| auto toLower = [&](const std::string& s) -> std::string { | ||
| std::string t = s; | ||
| std::transform(t.begin(), t.end(), t.begin(), [](unsigned char c) { return std::tolower(c); }); | ||
| return t; | ||
| }; | ||
|
|
||
| SignedHeatOptions options; | ||
| options.preserveSourceNormals = preserveSourceNormals; | ||
| if (toLower(levelSetConstraint) == "none") { | ||
| options.levelSetConstraint = LevelSetConstraint::None; | ||
| } | ||
| if (toLower(levelSetConstraint) == "zeroset") { | ||
| options.levelSetConstraint = LevelSetConstraint::ZeroSet; | ||
| } | ||
| if (toLower(levelSetConstraint) == "multiple") { | ||
| options.levelSetConstraint = LevelSetConstraint::Multiple; | ||
| } | ||
| options.softLevelSetWeight = softLevelSetWeight; | ||
| return options; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "geometrycentral/surface/signed_heat_method.h" | ||
|
|
||
| using namespace geometrycentral; | ||
| using namespace geometrycentral::surface; | ||
|
|
||
| // Convert from intermediary representation -- used for easier Python bindings -- to the input structs used in | ||
| // geometry-central. | ||
|
|
||
| std::vector<Curve> toSignedCurves(SurfaceMesh& mesh, | ||
| const std::vector<std::vector<std::pair<int64_t, std::vector<double>>>>& pythonCurves, | ||
| const std::vector<bool>& isSigned); | ||
|
|
||
| std::vector<Curve> toSignedCurves(SurfaceMesh& mesh, const std::vector<std::vector<int64_t>>& pythonCurves, | ||
| const std::vector<bool>& isSigned); | ||
|
|
||
| std::vector<std::vector<Vertex>> toSignedVertices(SurfaceMesh& mesh, | ||
| const std::vector<std::vector<int64_t>>& pythonCurves); | ||
|
|
||
| std::vector<SurfacePoint> toSurfacePoints(SurfaceMesh& mesh, | ||
| const std::vector<std::pair<int64_t, std::vector<double>>>& pythonPoints); | ||
|
|
||
| std::vector<SurfacePoint> toSurfacePoints(SurfaceMesh& mesh, const std::vector<int64_t>& pythonPoints); | ||
|
|
||
| SignedHeatOptions toSignedHeatOptions(bool preserveSourceNormals = false, | ||
| const std::string& levelSetConstraint = "ZeroSet", | ||
| double softLevelSetWeight = -1.); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: can we say "3D triangle meshes & polygonal meshes" (I don't want to give the impression that all the methods here specifically target polygons since some of them still don't)