Fixed some instance of simplify_polygons() invocation.

Geometry::deg2rad() made a template.
Some methods of Layer made inline.
Added a helper template remove_nulls().
This commit is contained in:
bubnikv 2017-03-22 15:35:09 +01:00
parent 6b99cbdc02
commit 04cd474708
7 changed files with 17 additions and 54 deletions

View file

@ -198,7 +198,7 @@ ExPolygon::simplify_p(double tolerance) const
p.points.pop_back(); p.points.pop_back();
pp.push_back(p); pp.push_back(p);
} }
simplify_polygons(pp, &pp); pp = simplify_polygons(pp);
return pp; return pp;
} }

View file

@ -168,11 +168,7 @@ void make_fill(LayerRegion &layerm, ExtrusionEntityCollection &out)
continue; continue;
// get filler object // get filler object
#if SLIC3R_CPPVER >= 11
std::unique_ptr<Fill> f = std::unique_ptr<Fill>(Fill::new_from_type(fill_pattern)); std::unique_ptr<Fill> f = std::unique_ptr<Fill>(Fill::new_from_type(fill_pattern));
#else
std::auto_ptr<Fill> f = std::auto_ptr<Fill>(Fill::new_from_type(fill_pattern));
#endif
f->set_bounding_box(layerm.layer()->object()->bounding_box()); f->set_bounding_box(layerm.layer()->object()->bounding_box());
// calculate the actual flow we'll be using for this infill // calculate the actual flow we'll be using for this infill

View file

@ -317,12 +317,6 @@ rad2deg_dir(double angle)
return rad2deg(angle); return rad2deg(angle);
} }
double
deg2rad(double angle)
{
return PI * angle / 180.0;
}
void void
simplify_polygons(const Polygons &polygons, double tolerance, Polygons* retval) simplify_polygons(const Polygons &polygons, double tolerance, Polygons* retval)
{ {
@ -334,7 +328,7 @@ simplify_polygons(const Polygons &polygons, double tolerance, Polygons* retval)
p.points.pop_back(); p.points.pop_back();
pp.push_back(p); pp.push_back(p);
} }
Slic3r::simplify_polygons(pp, retval); *retval = Slic3r::simplify_polygons(pp);
} }
double double

View file

@ -64,7 +64,7 @@ bool directions_parallel(double angle1, double angle2, double max_diff = 0);
template<class T> bool contains(const std::vector<T> &vector, const Point &point); template<class T> bool contains(const std::vector<T> &vector, const Point &point);
double rad2deg(double angle); double rad2deg(double angle);
double rad2deg_dir(double angle); double rad2deg_dir(double angle);
double deg2rad(double angle); template<typename T> T deg2rad(T angle) { return T(PI) * angle / T(180.0); }
void simplify_polygons(const Polygons &polygons, double tolerance, Polygons* retval); void simplify_polygons(const Polygons &polygons, double tolerance, Polygons* retval);
double linint(double value, double oldmin, double oldmax, double newmin, double newmax); double linint(double value, double oldmin, double oldmax, double newmin, double newmax);

View file

@ -13,12 +13,10 @@ Layer::Layer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z,
coordf_t slice_z) coordf_t slice_z)
: upper_layer(NULL), : upper_layer(NULL),
lower_layer(NULL), lower_layer(NULL),
regions(),
slicing_errors(false), slicing_errors(false),
slice_z(slice_z), slice_z(slice_z),
print_z(print_z), print_z(print_z),
height(height), height(height),
slices(),
_id(id), _id(id),
_object(object) _object(object)
{ {
@ -38,37 +36,6 @@ Layer::~Layer()
this->clear_regions(); this->clear_regions();
} }
size_t
Layer::id() const
{
return this->_id;
}
void
Layer::set_id(size_t id)
{
this->_id = id;
}
PrintObject*
Layer::object()
{
return this->_object;
}
const PrintObject*
Layer::object() const
{
return this->_object;
}
size_t
Layer::region_count() const
{
return this->regions.size();
}
void void
Layer::clear_regions() Layer::clear_regions()
{ {

View file

@ -15,13 +15,12 @@ class Layer;
class PrintRegion; class PrintRegion;
class PrintObject; class PrintObject;
// TODO: make stuff private // TODO: make stuff private
class LayerRegion class LayerRegion
{ {
friend class Layer; friend class Layer;
public: public:
Layer* layer() { return this->_layer; } Layer* layer() { return this->_layer; }
const Layer* layer() const { return this->_layer; } const Layer* layer() const { return this->_layer; }
PrintRegion* region() { return this->_region; } PrintRegion* region() { return this->_region; }
@ -88,10 +87,10 @@ class Layer {
friend class PrintObject; friend class PrintObject;
public: public:
size_t id() const; size_t id() const { return this->_id; }
void set_id(size_t id); void set_id(size_t id) { this->_id = id; }
PrintObject* object(); PrintObject* object() { return this->_object; }
const PrintObject* object() const; const PrintObject* object() const { return this->_object; }
Layer *upper_layer; Layer *upper_layer;
Layer *lower_layer; Layer *lower_layer;
@ -107,7 +106,7 @@ public:
// order will be recovered by the G-code generator. // order will be recovered by the G-code generator.
ExPolygonCollection slices; ExPolygonCollection slices;
size_t region_count() const; size_t region_count() const { return this->regions.size(); }
const LayerRegion* get_region(int idx) const { return this->regions.at(idx); } const LayerRegion* get_region(int idx) const { return this->regions.at(idx); }
LayerRegion* get_region(int idx) { return this->regions.at(idx); } LayerRegion* get_region(int idx) { return this->regions.at(idx); }
LayerRegion* add_region(PrintRegion* print_region); LayerRegion* add_region(PrintRegion* print_region);
@ -129,7 +128,6 @@ protected:
size_t _id; // sequential number of layer, 0-based size_t _id; // sequential number of layer, 0-based
PrintObject *_object; PrintObject *_object;
Layer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z, Layer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z,
coordf_t slice_z); coordf_t slice_z);
virtual ~Layer(); virtual ~Layer();

View file

@ -119,6 +119,14 @@ void append(std::vector<T>& dest, std::vector<T>&& src)
src.shrink_to_fit(); src.shrink_to_fit();
} }
template <typename T>
void remove_nulls(std::vector<T*> &vec)
{
vec.erase(
std::remove_if(vec.begin(), vec.end(), [](const T *ptr) { return ptr == nullptr; }),
vec.end());
}
} // namespace Slic3r } // namespace Slic3r
#endif #endif