-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #704 from wildmeshing/teseo/tri=ins
added tri ins
- Loading branch information
Showing
20 changed files
with
374 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 @@ | ||
// TODO |
This file contains 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 @@ | ||
// TODO |
This file contains 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 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 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
9 changes: 9 additions & 0 deletions
9
components/wmtk_components/to_points/wmtk/components/to_points/CMakeLists.txt
This file contains 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,9 @@ | ||
|
||
set(SRC_FILES | ||
ToPtsOptions.hpp | ||
to_points.hpp | ||
to_points.cpp) | ||
|
||
|
||
#CURRENT_COMPONENT_LIB_NAME is set from the main cmake | ||
target_sources(${CURRENT_COMPONENT_LIB_NAME} PRIVATE ${SRC_FILES}) |
19 changes: 19 additions & 0 deletions
19
components/wmtk_components/to_points/wmtk/components/to_points/ToPtsOptions.hpp
This file contains 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,19 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace wmtk::components { | ||
|
||
|
||
struct ToPtsOptions | ||
{ | ||
std::string input; | ||
std::string position; | ||
std::string name; | ||
bool add_box; | ||
double box_scale; | ||
}; | ||
|
||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ToPtsOptions, input, position, name, add_box, box_scale); | ||
|
||
} // namespace wmtk::components |
62 changes: 62 additions & 0 deletions
62
components/wmtk_components/to_points/wmtk/components/to_points/to_points.cpp
This file contains 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,62 @@ | ||
#include "to_points.hpp" | ||
|
||
|
||
#include "ToPtsOptions.hpp" | ||
|
||
#include <bitset> | ||
|
||
#include <wmtk/Mesh.hpp> | ||
#include <wmtk/PointMesh.hpp> | ||
#include <wmtk/utils/mesh_utils.hpp> | ||
|
||
namespace wmtk::components { | ||
|
||
void to_points(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache) | ||
{ | ||
ToPtsOptions options = j.get<ToPtsOptions>(); | ||
|
||
const std::shared_ptr<Mesh> mesh_in = cache.read_mesh(options.input); | ||
const Mesh& mesh = *mesh_in; | ||
|
||
const auto pts_attr = | ||
mesh.get_attribute_handle<double>(options.position, PrimitiveType::Vertex); | ||
const auto pts_acc = mesh.create_const_accessor<double>(pts_attr); | ||
const auto vs = mesh.get_all(PrimitiveType::Vertex); | ||
|
||
Eigen::AlignedBox<double, Eigen::Dynamic> bbox(pts_acc.dimension()); | ||
|
||
int64_t box_size = std::pow(2, pts_acc.dimension()); | ||
|
||
|
||
Eigen::MatrixXd pts(vs.size() + (options.add_box ? box_size : 0), pts_acc.dimension()); | ||
int64_t index = 0; | ||
for (const auto& v : vs) { | ||
pts.row(index) << pts_acc.const_vector_attribute(v).transpose(); | ||
bbox.extend(pts.row(index).transpose()); | ||
++index; | ||
} | ||
|
||
if (options.add_box) { | ||
auto center = bbox.center(); | ||
auto r = bbox.diagonal() / 2.; | ||
|
||
bbox.min() = center - options.box_scale * r; | ||
bbox.max() = center + options.box_scale * r; | ||
|
||
for (int64_t d = 0; d < box_size; ++d) { | ||
std::bitset<32> bits = d; | ||
for (int64_t i = 0; i < pts.cols(); ++i) { | ||
pts(index, i) = bits[i] == 0 ? bbox.min()[i] : bbox.max()[i]; | ||
} | ||
++index; | ||
} | ||
} | ||
|
||
PointMesh pts_mesh(pts.rows()); | ||
|
||
mesh_utils::set_matrix_attribute(pts, options.position, PrimitiveType::Vertex, pts_mesh); | ||
|
||
cache.write_mesh(pts_mesh, options.name); | ||
} | ||
|
||
} // namespace wmtk::components |
12 changes: 12 additions & 0 deletions
12
components/wmtk_components/to_points/wmtk/components/to_points/to_points.hpp
This file contains 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,12 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <wmtk/io/Cache.hpp> | ||
|
||
#include <wmtk/components/base/Paths.hpp> | ||
|
||
namespace wmtk::components { | ||
|
||
void to_points(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache); | ||
|
||
} // namespace wmtk::components |
37 changes: 37 additions & 0 deletions
37
components/wmtk_components/to_points/wmtk/components/to_points/to_points_spec.json
This file contains 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,37 @@ | ||
[ | ||
{ | ||
"pointer": "/", | ||
"type": "object", | ||
"required": [ | ||
"input", | ||
"position", | ||
"name" | ||
], | ||
"optional": [ | ||
"add_box", | ||
"box_scale" | ||
] | ||
}, | ||
{ | ||
"pointer": "/input", | ||
"type": "string" | ||
}, | ||
{ | ||
"pointer": "/position", | ||
"type": "string" | ||
}, | ||
{ | ||
"pointer": "/name", | ||
"type": "string" | ||
}, | ||
{ | ||
"pointer": "/add_box", | ||
"type": "bool", | ||
"default": false | ||
}, | ||
{ | ||
"pointer": "/box_scale", | ||
"type": "float", | ||
"default": 1 | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
...ents/wmtk_components/triangle_insertion/wmtk/components/triangle_insertion/CMakeLists.txt
This file contains 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,9 @@ | ||
|
||
set(SRC_FILES | ||
TriInsOptions.hpp | ||
triangle_insertion.hpp | ||
triangle_insertion.cpp) | ||
|
||
|
||
#CURRENT_COMPONENT_LIB_NAME is set from the main cmake | ||
target_sources(${CURRENT_COMPONENT_LIB_NAME} PRIVATE ${SRC_FILES}) |
23 changes: 23 additions & 0 deletions
23
...s/wmtk_components/triangle_insertion/wmtk/components/triangle_insertion/TriInsOptions.hpp
This file contains 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,23 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace wmtk::components { | ||
struct TriInsOptions | ||
{ | ||
std::string input; | ||
std::string input_position; | ||
std::string background; | ||
std::string background_position; | ||
std::string name; | ||
}; | ||
|
||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( | ||
TriInsOptions, | ||
input, | ||
input_position, | ||
background, | ||
background_position, | ||
name); | ||
|
||
} // namespace wmtk::components |
71 changes: 71 additions & 0 deletions
71
...k_components/triangle_insertion/wmtk/components/triangle_insertion/triangle_insertion.cpp
This file contains 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,71 @@ | ||
#include "triangle_insertion.hpp" | ||
|
||
#include "TriInsOptions.hpp" | ||
|
||
#include <wmtk/operations/attribute_update/AttributeTransferStrategy.hpp> | ||
#include <wmtk/utils/EigenMatrixWriter.hpp> | ||
#include <wmtk/utils/VolumeRemesherTriangleInsertion.hpp> | ||
|
||
|
||
#include <wmtk/Mesh.hpp> | ||
#include <wmtk/TetMesh.hpp> | ||
#include <wmtk/utils/Logger.hpp> | ||
|
||
namespace wmtk::components { | ||
|
||
void triangle_insertion(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache) | ||
{ | ||
TriInsOptions options = j.get<TriInsOptions>(); | ||
|
||
std::shared_ptr<Mesh> mesh_in = cache.read_mesh(options.input); | ||
std::shared_ptr<Mesh> bg_mesh = cache.read_mesh(options.background); | ||
|
||
if (mesh_in->top_simplex_type() != PrimitiveType::Face) | ||
log_and_throw_error("triangle_insertion supports only triangle meshes"); | ||
if (bg_mesh->top_simplex_type() != PrimitiveType::Tetrahedron) | ||
log_and_throw_error("triangle_insertion supports only bg tet meshes"); | ||
|
||
|
||
wmtk::utils::EigenMatrixWriter writer; | ||
mesh_in->serialize(writer); | ||
|
||
|
||
wmtk::utils::EigenMatrixWriter writer_bg; | ||
bg_mesh->serialize(writer_bg); | ||
|
||
Eigen::MatrixXd V; | ||
writer.get_double_matrix(options.input_position, PrimitiveType::Vertex, V); | ||
|
||
Eigen::MatrixX<int64_t> F; | ||
writer.get_FV_matrix(F); | ||
|
||
|
||
Eigen::MatrixXd Vbg; | ||
writer_bg.get_double_matrix(options.background_position, PrimitiveType::Vertex, Vbg); | ||
|
||
Eigen::MatrixX<int64_t> Fbg; | ||
writer_bg.get_TV_matrix(Fbg); | ||
|
||
auto [tetmesh, facemesh] = | ||
utils::generate_raw_tetmesh_with_surface_from_input(V, F, 0.1, Vbg, Fbg); | ||
auto pt_attribute = | ||
tetmesh->get_attribute_handle<double>(options.input_position, PrimitiveType::Vertex); | ||
auto child_position_handle = facemesh->register_attribute<double>( | ||
options.input_position, | ||
PrimitiveType::Vertex, | ||
tetmesh->get_attribute_dimension(pt_attribute.as<double>())); | ||
|
||
auto propagate_to_child_position = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { | ||
return P; | ||
}; | ||
auto update_child_positon = | ||
std::make_shared<wmtk::operations::SingleAttributeTransferStrategy<double, double>>( | ||
child_position_handle, | ||
pt_attribute, | ||
propagate_to_child_position); | ||
update_child_positon->run_on_all(); | ||
|
||
cache.write_mesh(*tetmesh, options.name); | ||
} | ||
|
||
} // namespace wmtk::components |
14 changes: 14 additions & 0 deletions
14
...k_components/triangle_insertion/wmtk/components/triangle_insertion/triangle_insertion.hpp
This file contains 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,14 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <wmtk/io/Cache.hpp> | ||
|
||
#include <wmtk/components/base/Paths.hpp> | ||
|
||
namespace wmtk { | ||
namespace components { | ||
|
||
void triangle_insertion(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache); | ||
|
||
} // namespace components | ||
} // namespace wmtk |
Oops, something went wrong.