Skip to content

Commit

Permalink
Add infill generator
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Dec 16, 2024
1 parent 3b68765 commit 3ccf945
Show file tree
Hide file tree
Showing 12 changed files with 678 additions and 20 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ set(engine_SRCS # Except main.cpp.

src/feature_generation/FeatureGenerator.cpp include/feature_generation/FeatureGenerator.h
src/feature_generation/MeshFeatureGenerator.cpp include/feature_generation/MeshFeatureGenerator.h
src/feature_generation/MeshInfillGenerator.cpp include/feature_generation/MeshInfillGenerator.h
src/feature_generation/MeshInsetsGenerator.cpp include/feature_generation/MeshInsetsGenerator.h
src/feature_generation/SkirtBrimAppender.cpp include/feature_generation/SkirtBrimAppender.h

Expand Down
60 changes: 60 additions & 0 deletions include/feature_generation/MeshInfillGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#pragma once

#include <utils/Coord_t.h>

#include "feature_generation/MeshFeatureGenerator.h"

namespace cura
{

class Shape;

class MeshInfillGenerator : public MeshFeatureGenerator
{
public:
explicit MeshInfillGenerator(const std::shared_ptr<SliceMeshStorage>& mesh);

bool isActive() const override;

protected:
void generateFeatures(const SliceDataStorage& storage, const LayerPlanPtr& layer_plan, const std::vector<ExtruderPlanPtr>& extruder_plans, const SliceLayerPart& part)
const override;

private:
/*!
* \brief Add thicker (multiple layers) sparse infill for a given part in a
* layer plan.
*
* \param gcodeLayer The initial planning of the gcode of the layer.
* \param mesh The mesh for which to add to the layer plan \p gcodeLayer.
* \param extruder_nr The extruder for which to print all features of the
* mesh which should be printed with this extruder.
* \param mesh_config The line config with which to print a print feature.
* \param part The part for which to create gcode.
* \return Whether this function added anything to the layer plan.
*/
void processMultiLayerInfill(const LayerPlanPtr& layer_plan, const ExtruderPlanPtr& extruder_plan, const SliceLayerPart& part) const;

/*!
* \brief Add normal sparse infill for a given part in a layer.
* \param gcodeLayer The initial planning of the gcode of the layer.
* \param mesh The mesh for which to add to the layer plan \p gcodeLayer.
* \param extruder_nr The extruder for which to print all features of the
* mesh which should be printed with this extruder
* \param mesh_config The line config with which to print a print feature.
* \param part The part for which to create gcode.
* \return Whether this function added anything to the layer plan.
*/
void processSingleLayerInfill(const SliceDataStorage& storage, const LayerPlanPtr& layer_plan, const ExtruderPlanPtr& extruder_plan, const SliceLayerPart& part) const;

bool
partitionInfillBySkinAbove(Shape& infill_below_skin, Shape& infill_not_below_skin, const LayerPlanPtr& layer_plan, const SliceLayerPart& part, coord_t infill_line_width) const;

private:
const coord_t infill_line_distance_;
};

} // namespace cura
2 changes: 0 additions & 2 deletions include/feature_generation/MeshInsetsGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
namespace cura
{

class SliceLayerPart;

class MeshInsetsGenerator : public MeshFeatureGenerator
{
public:
Expand Down
6 changes: 6 additions & 0 deletions include/geometry/ClosedPolyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class ClosedPolyline : public Polyline
return ! explicitely_closed_;
}

/*! @see Polyline::isClosed() */
[[nodiscard]] bool isClosed() const override
{
return true;
}

/*! @see Polyline::addClosingSegment() */
[[nodiscard]] size_t segmentsCount() const override;

Expand Down
6 changes: 6 additions & 0 deletions include/geometry/OpenPolyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class OpenPolyline : public Polyline
return false; // Definitely not
}

/*! @see Polyline::isClosed() */
[[nodiscard]] bool isClosed() const override
{
return false;
}

/*! @see Polyline::segmentsCount() */
[[nodiscard]] size_t segmentsCount() const override
{
Expand Down
5 changes: 5 additions & 0 deletions include/geometry/Polyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class Polyline : public PointsSet
*/
[[nodiscard]] virtual bool hasClosingSegment() const = 0;

/*!
* \brief Indicates whether this polyline represents a closed or an open line
*/
[[nodiscard]] virtual bool isClosed() const = 0;

/*!
* \brief Gets the total number of "full" segments in the polyline. Calling this is also safe if
* there are not enough points to make a valid polyline, so it can also be a good
Expand Down
10 changes: 9 additions & 1 deletion include/print_operation/ContinuousExtruderMoveSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#pragma once

#include "geometry/Point3LL.h"
#include "print_operation/ContinuousExtruderMoveSequencePtr.h"
#include "print_operation/PrintOperationSequence.h"

namespace cura
{

struct ExtrusionLine;
struct Velocity;
struct ExtrusionJunction;
class Polyline;
class ExtruderMove;
class SliceMeshStorage;
class PlanExporter;
Expand All @@ -20,6 +24,10 @@ class ContinuousExtruderMoveSequence : public PrintOperationSequence
public:
explicit ContinuousExtruderMoveSequence(bool closed, const Point3LL& start_position = Point3LL());

static ContinuousExtruderMoveSequencePtr makeFrom(const ExtrusionLine& extrusion_line, const Velocity& speed);

static ContinuousExtruderMoveSequencePtr makeFrom(const Polyline& polyline, const coord_t line_width, const Velocity& speed);

void appendExtruderMove(const std::shared_ptr<ExtruderMove>& extruder_move);

std::optional<Point3LL> findStartPosition() const override;
Expand Down
3 changes: 3 additions & 0 deletions include/print_operation/FeatureExtrusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

#include "GCodePathConfig.h"
#include "print_operation/ContinuousExtruderMoveSequencePtr.h"
#include "print_operation/FeatureExtrusionPtr.h"
#include "print_operation/PrintOperationSequence.h"

namespace cura
{

class Shape;

class FeatureExtrusion : public PrintOperationSequence
{
public:
Expand Down
2 changes: 2 additions & 0 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "bridge.h"
#include "communication/Communication.h" //To send layer view data.
#include "feature_generation/FeatureGenerator.h"
#include "feature_generation/MeshInfillGenerator.h"
#include "feature_generation/MeshInsetsGenerator.h"
#include "geometry/LinesSet.h"
#include "geometry/OpenPolyline.h"
Expand Down Expand Up @@ -194,6 +195,7 @@ void FffGcodeWriter::writeGCode(SliceDataStorage& storage, TimeKeeper& time_keep
for (const std::shared_ptr<SliceMeshStorage>& mesh : storage.meshes)
{
feature_generators_.push_back(std::make_shared<MeshInsetsGenerator>(mesh));
feature_generators_.push_back(std::make_shared<MeshInfillGenerator>(mesh));
}

// Filter out generators that are actually useless in this context. Not highly useful, but helps for debugging.
Expand Down
Loading

0 comments on commit 3ccf945

Please sign in to comment.