Switch to smart pointers

This commit is contained in:
Lukáš Hejl 2020-08-27 07:28:43 +02:00
parent c0d21bd2b4
commit 14a7fbc9f7
3 changed files with 15 additions and 16 deletions

View File

@ -16,7 +16,7 @@ void FillAdaptive::_fill_surface_single(
Polylines &polylines_out) Polylines &polylines_out)
{ {
std::vector<Polylines> infill_polylines(3); std::vector<Polylines> infill_polylines(3);
this->generate_polylines(this->adapt_fill_octree->root_cube, this->z, this->adapt_fill_octree->origin, infill_polylines); this->generate_polylines(this->adapt_fill_octree->root_cube.get(), this->z, this->adapt_fill_octree->origin, infill_polylines);
for (Polylines &infill_polyline : infill_polylines) { for (Polylines &infill_polyline : infill_polylines) {
// Crop all polylines // Crop all polylines
@ -106,9 +106,9 @@ void FillAdaptive::generate_polylines(
} }
} }
for(Cube *child : cube->children) for(const std::unique_ptr<Cube> &child : cube->children)
{ {
generate_polylines(child, z_position, origin, polylines_out); generate_polylines(child.get(), z_position, origin, polylines_out);
} }
} }
@ -141,7 +141,7 @@ void FillAdaptive::merge_polylines(Polylines &polylines, const Line &new_line)
} }
FillAdaptive_Internal::Octree* FillAdaptive::build_octree( std::unique_ptr<FillAdaptive_Internal::Octree> FillAdaptive::build_octree(
TriangleMesh &triangleMesh, TriangleMesh &triangleMesh,
coordf_t line_spacing, coordf_t line_spacing,
const BoundingBoxf3 &printer_volume, const BoundingBoxf3 &printer_volume,
@ -181,9 +181,10 @@ FillAdaptive_Internal::Octree* FillAdaptive::build_octree(
Transform3d rotation_matrix = Geometry::assemble_transform(Vec3d::Zero(), rotation, Vec3d::Ones(), Vec3d::Ones()); Transform3d rotation_matrix = Geometry::assemble_transform(Vec3d::Zero(), rotation, Vec3d::Ones(), Vec3d::Ones());
AABBTreeIndirect::Tree3f aabbTree = AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(triangleMesh.its.vertices, triangleMesh.its.indices); AABBTreeIndirect::Tree3f aabbTree = AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(triangleMesh.its.vertices, triangleMesh.its.indices);
Octree *octree = new Octree{new Cube{cube_center, cubes_properties.size() - 1, cubes_properties.back()}, cube_center}; std::unique_ptr<Octree> octree = std::unique_ptr<Octree>(
new Octree{std::unique_ptr<Cube>(new Cube{cube_center, cubes_properties.size() - 1, cubes_properties.back()}), cube_center});
FillAdaptive::expand_cube(octree->root_cube, cubes_properties, rotation_matrix, aabbTree, triangleMesh); FillAdaptive::expand_cube(octree->root_cube.get(), cubes_properties, rotation_matrix, aabbTree, triangleMesh);
return octree; return octree;
} }
@ -213,8 +214,8 @@ void FillAdaptive::expand_cube(
Vec3d child_center_transformed = cube->center + rotation_matrix * (child_center * (cube->properties.edge_length / 4)); Vec3d child_center_transformed = cube->center + rotation_matrix * (child_center * (cube->properties.edge_length / 4));
if(AABBTreeIndirect::is_any_triangle_in_radius(triangleMesh.its.vertices, triangleMesh.its.indices, distanceTree, child_center_transformed, cube_radius_squared)) { if(AABBTreeIndirect::is_any_triangle_in_radius(triangleMesh.its.vertices, triangleMesh.its.indices, distanceTree, child_center_transformed, cube_radius_squared)) {
cube->children.push_back(new Cube{child_center_transformed, cube->depth - 1, cubes_properties[cube->depth - 1]}); cube->children.push_back(std::unique_ptr<Cube>(new Cube{child_center_transformed, cube->depth - 1, cubes_properties[cube->depth - 1]}));
FillAdaptive::expand_cube(cube->children.back(), cubes_properties, rotation_matrix, distanceTree, triangleMesh); FillAdaptive::expand_cube(cube->children.back().get(), cubes_properties, rotation_matrix, distanceTree, triangleMesh);
} }
} }
} }

View File

@ -23,12 +23,12 @@ namespace FillAdaptive_Internal
Vec3d center; Vec3d center;
size_t depth; size_t depth;
CubeProperties properties; CubeProperties properties;
std::vector<Cube*> children; std::vector<std::unique_ptr<Cube>> children;
}; };
struct Octree struct Octree
{ {
Cube *root_cube; std::unique_ptr<Cube> root_cube;
Vec3d origin; Vec3d origin;
}; };
}; // namespace FillAdaptive_Internal }; // namespace FillAdaptive_Internal
@ -59,7 +59,7 @@ protected:
void merge_polylines(Polylines &polylines, const Line &new_line); void merge_polylines(Polylines &polylines, const Line &new_line);
public: public:
static FillAdaptive_Internal::Octree* build_octree( static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree(
TriangleMesh &triangleMesh, TriangleMesh &triangleMesh,
coordf_t line_spacing, coordf_t line_spacing,
const BoundingBoxf3 &printer_volume, const BoundingBoxf3 &printer_volume,

View File

@ -11,6 +11,7 @@
#include "GCode/ToolOrdering.hpp" #include "GCode/ToolOrdering.hpp"
#include "GCode/WipeTower.hpp" #include "GCode/WipeTower.hpp"
#include "GCode/ThumbnailData.hpp" #include "GCode/ThumbnailData.hpp"
#include "Fill/FillAdaptive.hpp"
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
#include "GCode/GCodeProcessor.hpp" #include "GCode/GCodeProcessor.hpp"
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
@ -30,9 +31,6 @@ enum class SlicingMode : uint32_t;
class Layer; class Layer;
class SupportLayer; class SupportLayer;
namespace FillAdaptive_Internal {
struct Octree;
};
// Print step IDs for keeping track of the print state. // Print step IDs for keeping track of the print state.
enum PrintStep { enum PrintStep {
@ -198,7 +196,7 @@ public:
// Helpers to project custom facets on slices // Helpers to project custom facets on slices
void project_and_append_custom_facets(bool seam, EnforcerBlockerType type, std::vector<ExPolygons>& expolys) const; void project_and_append_custom_facets(bool seam, EnforcerBlockerType type, std::vector<ExPolygons>& expolys) const;
FillAdaptive_Internal::Octree* adaptiveInfillOctree() { return m_adapt_fill_octree; } FillAdaptive_Internal::Octree* adaptiveInfillOctree() { return m_adapt_fill_octree.get(); }
private: private:
// to be called from Print only. // to be called from Print only.
friend class Print; friend class Print;
@ -261,7 +259,7 @@ private:
// so that next call to make_perimeters() performs a union() before computing loops // so that next call to make_perimeters() performs a union() before computing loops
bool m_typed_slices = false; bool m_typed_slices = false;
FillAdaptive_Internal::Octree* m_adapt_fill_octree = nullptr; std::unique_ptr<FillAdaptive_Internal::Octree> m_adapt_fill_octree = nullptr;
std::vector<ExPolygons> slice_region(size_t region_id, const std::vector<float> &z, SlicingMode mode) const; std::vector<ExPolygons> slice_region(size_t region_id, const std::vector<float> &z, SlicingMode mode) const;
std::vector<ExPolygons> slice_modifiers(size_t region_id, const std::vector<float> &z) const; std::vector<ExPolygons> slice_modifiers(size_t region_id, const std::vector<float> &z) const;