mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-25 01:31:14 -06:00
hollowing params renamed, filtering generalized
This commit is contained in:
parent
bc3d22348a
commit
4b08865809
12 changed files with 111 additions and 72 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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. "
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
55
src/libslic3r/SLA/Hollowing.cpp
Normal file
55
src/libslic3r/SLA/Hollowing.cpp
Normal file
|
|
@ -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
|
||||
17
src/libslic3r/SLA/Hollowing.hpp
Normal file
17
src/libslic3r/SLA/Hollowing.hpp
Normal file
|
|
@ -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
|
||||
|
|
@ -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 (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue