Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2019-11-08 11:21:30 +0300
committertamasmeszaros <meszaros.q@gmail.com>2019-11-08 11:21:30 +0300
commit4b088658096ad38937795a9153ffd8406ce827a3 (patch)
tree4362aa549ce2a3a3e618c3cb5da2de6b040073c9 /src/libslic3r
parentbc3d22348aa6ee03c86aeab93dbdd1d2da7694b9 (diff)
hollowing params renamed, filtering generalized
Diffstat (limited to 'src/libslic3r')
-rw-r--r--src/libslic3r/CMakeLists.txt2
-rw-r--r--src/libslic3r/OpenVDBUtils.cpp31
-rw-r--r--src/libslic3r/OpenVDBUtils.hpp6
-rw-r--r--src/libslic3r/PrintConfig.cpp4
-rw-r--r--src/libslic3r/PrintConfig.hpp8
-rw-r--r--src/libslic3r/SLA/Hollowing.cpp55
-rw-r--r--src/libslic3r/SLA/Hollowing.hpp17
-rw-r--r--src/libslic3r/SLAPrint.cpp12
8 files changed, 99 insertions, 36 deletions
diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt
index e4b6ccd10..e28917b5f 100644
--- a/src/libslic3r/CMakeLists.txt
+++ b/src/libslic3r/CMakeLists.txt
@@ -204,6 +204,8 @@ add_library(libslic3r STATIC
SLA/SLARasterWriter.cpp
SLA/ConcaveHull.hpp
SLA/ConcaveHull.cpp
+ SLA/Hollowing.hpp
+ SLA/Hollowing.cpp
)
encoding_check(libslic3r)
diff --git a/src/libslic3r/OpenVDBUtils.cpp b/src/libslic3r/OpenVDBUtils.cpp
index 53f9d5ae9..91ccdd5c4 100644
--- a/src/libslic3r/OpenVDBUtils.cpp
+++ b/src/libslic3r/OpenVDBUtils.cpp
@@ -2,7 +2,7 @@
#include "OpenVDBUtils.hpp"
#include <openvdb/tools/MeshToVolume.h>
#include <openvdb/tools/VolumeToMesh.h>
-#include <openvdb/tools/Filter.h>
+#include <openvdb/tools/TopologyToLevelSet.h>
#include <boost/log/trivial.hpp>
#include "MTUtils.hpp"
@@ -158,35 +158,22 @@ inline void _scale(S s, sla::Contour3D &m)
for (auto &p : m.points) p *= s;
}
-static void filter_grid(openvdb::FloatGrid &grid, double scale, double gain)
-{
- static const double ROUNDNESS_COEFF = 1.;
-
- // Filtering:
- if (gain > 0.) {
- double rounding = ROUNDNESS_COEFF * gain;
- int width = int(rounding * scale);
- int count = 1;
- openvdb::tools::Filter<openvdb::FloatGrid>{grid}.gaussian(width, count);
- }
-}
-
template<class Mesh>
remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
double min_thickness,
- double accuracy,
- double smoothing)
+ double quality,
+ HollowingFilter filt)
{
using MMesh = remove_cvref_t<Mesh>;
MMesh imesh{std::forward<Mesh>(mesh)};
- static const double ACCURACY_COEFF = 7.;
+ static const double QUALITY_COEFF = 7.;
// I can't figure out how to increase the grid resolution through openvdb API
// so the model will be scaled up before conversion and the result scaled
// down. Voxels have a unit size. If I set voxelSize smaller, it scales
// the whole geometry down, and doesn't increase the number of voxels.
- auto scale = (1.0 + ACCURACY_COEFF * accuracy); // max 8x upscale, min is native voxel size
+ auto scale = (1.0 + QUALITY_COEFF * quality); // max 8x upscale, min is native voxel size
_scale(scale, imesh);
@@ -201,7 +188,7 @@ remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
return MMesh{};
}
- filter_grid(*gridptr, scale, smoothing);
+ if (filt) filt(*gridptr, min_thickness, scale);
double iso_surface = -offset;
double adaptivity = 0.;
@@ -214,10 +201,10 @@ remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
TriangleMesh hollowed_interior(const TriangleMesh &mesh,
double min_thickness,
- double accuracy,
- double smoothing)
+ double quality,
+ HollowingFilter filt)
{
- return _hollowed_interior(mesh, min_thickness, accuracy, smoothing);
+ return _hollowed_interior(mesh, min_thickness, quality, filt);
}
} // namespace Slic3r
diff --git a/src/libslic3r/OpenVDBUtils.hpp b/src/libslic3r/OpenVDBUtils.hpp
index 95b95db7c..bd52e81ee 100644
--- a/src/libslic3r/OpenVDBUtils.hpp
+++ b/src/libslic3r/OpenVDBUtils.hpp
@@ -18,13 +18,15 @@ TriangleMesh volumeToMesh(const openvdb::FloatGrid &grid,
double adaptivity = 0.0,
bool relaxDisorientedTriangles = true);
+using HollowingFilter = std::function<void(openvdb::FloatGrid& grid, double thickness, double scale)>;
+
// Generate an interior for any solid geometry maintaining a given minimum
// wall thickness. The returned mesh has triangles with normals facing inside
// the mesh so the result can be directly merged with the input to finish the
// hollowing.
-// TODO: The thicknes is not strictly maintained due to the used gaussian filter
TriangleMesh hollowed_interior(const TriangleMesh &mesh, double min_thickness,
- double accuracy = 0.5, double smoothing = 0.5);
+ double quality = 0.5,
+ HollowingFilter filt = nullptr);
} // namespace Slic3r
diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp
index e621d4b34..96b84cf81 100644
--- a/src/libslic3r/PrintConfig.cpp
+++ b/src/libslic3r/PrintConfig.cpp
@@ -2847,7 +2847,7 @@ void PrintConfigDef::init_sla_params()
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloat(4));
- def = this->add("hollowing_accuracy", coFloat);
+ def = this->add("hollowing_quality", coFloat);
def->label = L("Hollowing accuracy");
def->category = L("Hollowing");
def->tooltip = L("Performance vs accuracy of calculation. Lower values may produce unwanted artifacts.");
@@ -2856,7 +2856,7 @@ void PrintConfigDef::init_sla_params()
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0.5));
- def = this->add("hollowing_smoothness", coFloat);
+ def = this->add("hollowing_flatness", coFloat);
def->label = L("Hollowing smoothness");
def->category = L("Hollowing");
def->tooltip = L("The cavity shape is a smoothed version of the outside original shape. "
diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp
index d07999c88..9ed63e5d4 100644
--- a/src/libslic3r/PrintConfig.hpp
+++ b/src/libslic3r/PrintConfig.hpp
@@ -1099,11 +1099,11 @@ public:
ConfigOptionFloat hollowing_min_thickness;
// Indirectly controls the voxel size (resolution) used by openvdb
- ConfigOptionFloat hollowing_accuracy;
+ ConfigOptionFloat hollowing_quality;
// Indirectly controls the amount of filtering used to blur geometry
// features in the created cavity.
- ConfigOptionFloat hollowing_smoothness;
+ ConfigOptionFloat hollowing_flatness;
protected:
void initialize(StaticCacheBase &cache, const char *base_ptr)
@@ -1143,8 +1143,8 @@ protected:
OPT_PTR(pad_object_connector_penetration);
OPT_PTR(hollowing_enable);
OPT_PTR(hollowing_min_thickness);
- OPT_PTR(hollowing_accuracy);
- OPT_PTR(hollowing_smoothness);
+ OPT_PTR(hollowing_quality);
+ OPT_PTR(hollowing_flatness);
}
};
diff --git a/src/libslic3r/SLA/Hollowing.cpp b/src/libslic3r/SLA/Hollowing.cpp
new file mode 100644
index 000000000..430900313
--- /dev/null
+++ b/src/libslic3r/SLA/Hollowing.cpp
@@ -0,0 +1,55 @@
+#include "Hollowing.hpp"
+#include <openvdb/tools/Filter.h>
+#include <openvdb/tools/LevelSetRebuild.h>
+#include <openvdb/tools/LevelSetFilter.h>
+#include <functional>
+
+namespace Slic3r {
+namespace sla {
+
+namespace {
+
+void filter_grid_sla(openvdb::FloatGrid &grid, double scale, double /*thickness*/, double flatness)
+{
+ static const double ROUNDNESS_COEFF = 1.;
+
+ // Filtering:
+ if (flatness > 0.) {
+ double rounding = ROUNDNESS_COEFF * flatness;
+ int width = int(rounding * scale);
+ int count = 1;
+ openvdb::tools::Filter<openvdb::FloatGrid>{grid}.gaussian(width, count);
+ }
+}
+// openvdb::tools::levelSetRebuild(grid, -float(thickness * 2));
+// filter_grid_sla(grid, scale, thickness, flatness);
+
+// openvdb::tools::levelSetRebuild(grid, float(thickness));
+
+
+void redist_grid_sla(openvdb::FloatGrid &grid, double scale, double thickness, double flatness)
+{
+// openvdb::tools::levelSetRebuild(grid, -float(scale * thickness));
+
+
+ openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filt{grid};
+
+// filt.gaussian(int(flatness * scale));
+
+// openvdb::tools::levelSetRebuild(grid, float(scale * thickness));
+ //grid = openvdb::tools::topologyToLevelSet(grid);
+}
+
+}
+
+TriangleMesh generate_interior(const TriangleMesh &mesh,
+ double min_thickness,
+ double quality,
+ double flatness)
+{
+ namespace plc = std::placeholders;
+ auto filt = std::bind(filter_grid_sla, plc::_1, plc::_2, plc::_3, flatness);
+ return hollowed_interior(mesh, min_thickness, quality, filt);
+}
+
+}} // namespace Slic3r::sla
diff --git a/src/libslic3r/SLA/Hollowing.hpp b/src/libslic3r/SLA/Hollowing.hpp
new file mode 100644
index 000000000..6abbe9f99
--- /dev/null
+++ b/src/libslic3r/SLA/Hollowing.hpp
@@ -0,0 +1,17 @@
+#ifndef HOLLOWINGFILTER_HPP
+#define HOLLOWINGFILTER_HPP
+
+#include <libslic3r/OpenVDBUtils.hpp>
+
+namespace Slic3r {
+namespace sla {
+
+TriangleMesh generate_interior(const TriangleMesh &mesh,
+ double min_thickness,
+ double quality = 0.5,
+ double flatness = 0.5);
+
+}
+}
+
+#endif // HOLLOWINGFILTER_H
diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp
index d2200bcfb..b150a4f76 100644
--- a/src/libslic3r/SLAPrint.cpp
+++ b/src/libslic3r/SLAPrint.cpp
@@ -3,7 +3,7 @@
#include "SLA/SLAPad.hpp"
#include "SLA/SLAAutoSupports.hpp"
#include "ClipperUtils.hpp"
-#include "OpenVDBUtils.hpp"
+#include "SLA/Hollowing.hpp"
#include "Geometry.hpp"
#include "MTUtils.hpp"
@@ -776,10 +776,10 @@ void SLAPrint::process()
po.m_hollowing_data.reset(new SLAPrintObject::HollowingData());
double thickness = po.m_config.hollowing_min_thickness.getFloat();
- double accuracy = po.m_config.hollowing_accuracy.getFloat();
- double blur = po.m_config.hollowing_smoothness.getFloat();
+ double accuracy = po.m_config.hollowing_quality.getFloat();
+ double blur = po.m_config.hollowing_flatness.getFloat();
po.m_hollowing_data->interior =
- hollowed_interior(po.transformed_mesh(), thickness, accuracy, blur);
+ generate_interior(po.transformed_mesh(), thickness, accuracy, blur);
if (po.m_hollowing_data->interior.empty())
BOOST_LOG_TRIVIAL(warning) << "Hollowed interior is empty!";
@@ -1754,8 +1754,8 @@ bool SLAPrintObject::invalidate_state_by_config_options(const std::vector<t_conf
for (const t_config_option_key &opt_key : opt_keys) {
if ( opt_key == "hollowing_enable"
|| opt_key == "hollowing_min_thickness"
- || opt_key == "hollowing_accuracy"
- || opt_key == "hollowing_smoothness"
+ || opt_key == "hollowing_quality"
+ || opt_key == "hollowing_flatness"
) {
steps.emplace_back(slaposHollowing);
} else if (