Hollowing params: accuracy and smoothness

This commit is contained in:
tamasmeszaros 2019-11-07 09:34:34 +01:00
parent a82f1268f3
commit bc3d22348a
9 changed files with 85 additions and 23 deletions

View file

@ -158,20 +158,35 @@ 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,
int oversampling,
double accuracy,
double smoothing)
{
using MMesh = remove_cvref_t<Mesh>;
MMesh imesh{std::forward<Mesh>(mesh)};
static const double ACCURACY_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 = double(oversampling);
auto scale = (1.0 + ACCURACY_COEFF * accuracy); // max 8x upscale, min is native voxel size
_scale(scale, imesh);
@ -186,10 +201,7 @@ remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
return MMesh{};
}
// Filtering:
int width = int(smoothing * scale);
int count = 1;
openvdb::tools::Filter<openvdb::FloatGrid>{*gridptr}.gaussian(width, count);
filter_grid(*gridptr, scale, smoothing);
double iso_surface = -offset;
double adaptivity = 0.;
@ -202,10 +214,10 @@ remove_cvref_t<Mesh> _hollowed_interior(Mesh &&mesh,
TriangleMesh hollowed_interior(const TriangleMesh &mesh,
double min_thickness,
int oversampling,
double accuracy,
double smoothing)
{
return _hollowed_interior(mesh, min_thickness, oversampling, smoothing);
return _hollowed_interior(mesh, min_thickness, accuracy, smoothing);
}
} // namespace Slic3r

View file

@ -18,16 +18,13 @@ TriangleMesh volumeToMesh(const openvdb::FloatGrid &grid,
double adaptivity = 0.0,
bool relaxDisorientedTriangles = true);
sla::Contour3D hollowed_interior(sla::Contour3D&& mesh, double min_thickness);
sla::Contour3D hollowed_interior(sla::Contour3D& mesh, double min_thickness);
// 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,
int oversampling = 3, double smoothing = 0.5);
double accuracy = 0.5, double smoothing = 0.5);
} // namespace Slic3r

View file

@ -2846,6 +2846,25 @@ void PrintConfigDef::init_sla_params()
def->min = 1;
def->mode = comSimple;
def->set_default_value(new ConfigOptionFloat(4));
def = this->add("hollowing_accuracy", coFloat);
def->label = L("Hollowing accuracy");
def->category = L("Hollowing");
def->tooltip = L("Performance vs accuracy of calculation. Lower values may produce unwanted artifacts.");
def->min = 0;
def->max = 1;
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0.5));
def = this->add("hollowing_smoothness", 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. "
"Possible values span from 0 to 1 and control the amount of surface smoothing.");
def->min = 0;
def->max = 1;
def->mode = comExpert;
def->set_default_value(new ConfigOptionFloat(0.5));
}
void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &value)

View file

@ -1097,6 +1097,13 @@ public:
// resulting walls may be thicker due to smoothing out fine cavities where
// resin could stuck.
ConfigOptionFloat hollowing_min_thickness;
// Indirectly controls the voxel size (resolution) used by openvdb
ConfigOptionFloat hollowing_accuracy;
// Indirectly controls the amount of filtering used to blur geometry
// features in the created cavity.
ConfigOptionFloat hollowing_smoothness;
protected:
void initialize(StaticCacheBase &cache, const char *base_ptr)
@ -1136,6 +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);
}
};

View file

@ -776,9 +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();
po.m_hollowing_data->interior =
hollowed_interior(po.transformed_mesh(), thickness, 4, 0.5);
hollowed_interior(po.transformed_mesh(), thickness, accuracy, blur);
if (po.m_hollowing_data->interior.empty())
BOOST_LOG_TRIVIAL(warning) << "Hollowed interior is empty!";
@ -1752,7 +1753,10 @@ bool SLAPrintObject::invalidate_state_by_config_options(const std::vector<t_conf
bool invalidated = false;
for (const t_config_option_key &opt_key : opt_keys) {
if ( opt_key == "hollowing_enable"
|| opt_key == "hollowing_min_thickness") {
|| opt_key == "hollowing_min_thickness"
|| opt_key == "hollowing_accuracy"
|| opt_key == "hollowing_smoothness"
) {
steps.emplace_back(slaposHollowing);
} else if (
opt_key == "layer_height"