Compare commits

...

1 commit

Author SHA1 Message Date
Théophile Bastian a209081cf6 Begin hints integration -- WIP 2018-02-12 13:40:06 +01:00
2 changed files with 61 additions and 4 deletions

View file

@ -18,7 +18,12 @@ void MarchingCubes::add_hint(const Cuboid& hint) {
Mesh MarchingCubes::operator()() {
Mesh output;
without_hints(output);
if(hints.empty()) {
without_hints(output);
}
else {
with_hints(output);
}
return output;
}
@ -36,6 +41,39 @@ void MarchingCubes::without_hints(Mesh& output) {
}
}
void MarchingCubes::with_hints(Mesh& output) {
auto fmod = [](double x, double mod) {
return x - floor(x/mod) * mod;
};
LocSet visited;
for(const Cuboid& hint: hints) {
Intersections inters = mk_intersection_cuboid(
hint.low(0), hint.low(1), hint.low(2),
hint.length(0), hint.length(1), hint.length(2));
const std::vector<CubeTri> triangles =
edges_of_intersection[inters.value()];
if(triangles.size() == 0)
continue; // this hint does not intersect anything.
const CubeEdge& edge = triangles[0].edge[0];
double edge_len = 0;
if(edge.x[0] != edge.x[1])
edge_len = hint.length(0);
else if(edge.y[0] != edge.y[1])
edge_len = hint.length(1);
else
edge_len = hint.length(2);
Point intersect_loc = intersect_location(
edge, hint.low(0), hint.low(1), hint.low(1), edge_len);
int cube_x = floor(intersect_loc.x / resolution),
cube_y = floor(intersect_loc.y / resolution),
cube_z = floor(intersect_loc.z / resolution);
//TODO
}
}
Point MarchingCubes::CubeEdge::at(double pos,
double bx, double by, double bz, double resolution) const
{
@ -102,14 +140,21 @@ bool MarchingCubes::march_at(double x, double y, double z, Mesh& output) {
MarchingCubes::Intersections MarchingCubes::mk_intersection_cube(
double bx, double by, double bz, double side_len) const
{
return mk_intersection_cuboid(bx, by, bz, side_len, side_len, side_len);
}
MarchingCubes::Intersections MarchingCubes::mk_intersection_cuboid(
double bx, double by, double bz,
double x_len, double y_len, double z_len) const
{
Intersections intersections;
for(int dx=0; dx <= 1; dx++) {
for(int dy=0; dy <= 1; dy++) {
for(int dz=0; dz <= 1; dz++) {
double cx = bx + side_len * dx;
double cy = by + side_len * dy;
double cz = bz + side_len * dz;
double cx = bx + x_len * dx;
double cy = by + y_len * dy;
double cz = bz + z_len * dz;
intersections.set_corner(dx, dy, dz,
surface(cx, cy, cz) > 0);
}
@ -120,6 +165,12 @@ MarchingCubes::Intersections MarchingCubes::mk_intersection_cube(
Point MarchingCubes::intersect_location(const CubeEdge& edge,
double bx, double by, double bz) const
{
return intersect_location(edge, bx, by, bz, this->resolution);
}
Point MarchingCubes::intersect_location(const CubeEdge& edge,
double bx, double by, double bz, double resolution) const
{
std::function<Point(double, double)> compute =
[&](double low_prop, double high_prop)

View file

@ -120,12 +120,18 @@ class MarchingCubes {
/// triangle was added.
void without_hints(Mesh& output);
void with_hints(Mesh& output);
Intersections mk_intersection_cube(double bx, double by, double bz,
double side_len) const;
Intersections mk_intersection_cuboid(double bx, double by, double bz,
double x_len, double y_len, double z_len) const;
Point intersect_location(const CubeEdge& edge,
double bx, double by, double bz) const;
Point intersect_location(const CubeEdge& edge,
double bx, double by, double bz,
double resolution) const;
private:
static const std::vector<CubeTri> edges_of_intersection[256];