Skip to content

Commit

Permalink
Ensure trees never rest on support blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRahm committed Feb 27, 2023
1 parent f3975c3 commit 1d62038
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 129 deletions.
61 changes: 61 additions & 0 deletions include/TreeModelVolumes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ class TreeModelVolumes
*/
const Polygons& getCollisionHolefree(coord_t radius, LayerIndex layer_idx, bool min_xy_dist = false);


/*!
* \brief Provides the area where there is model/build-plate below (vs support blocker)
*
* The result is a 2D area that represents where if support were to be placed in and just dropped down it would not rest on support blocker.
* \param layer_idx The layer of interest
* \return Polygons object
*/
const Polygons& getAccumulatedPlaceable0(LayerIndex layer_idx);

/*!
* \brief Provides the areas that have to be avoided by the tree's branches
* in order to reach the build plate.
Expand Down Expand Up @@ -154,6 +164,7 @@ class TreeModelVolumes
*/
Polygons extractOutlineFromMesh(const SliceMeshStorage& mesh, LayerIndex layer_idx) const;


/*!
* \brief Creates the areas that have to be avoided by the tree's branches to prevent collision with the model on this layer.
*
Expand All @@ -175,6 +186,35 @@ class TreeModelVolumes
calculateCollision(std::deque<RadiusLayerPair>{ RadiusLayerPair(key) });
}

/*!
* \brief Calculates where there is model/build-plate below (vs support blocker).
*
* The result is a 2D area that represents where if support were to be placed in and just dropped down it would not rest on support blocker. Result is saved in the cache.
* \param max_layer The layer up to which the area will be calculated.
*/
void calculateAccumulatedPlaceable0(const LayerIndex max_layer);

/*!
* \brief Creates the areas that have to be avoided by the tree's branches to prevent collision with the model on this layer and not rest on support blocker.
*
* The result is a 2D area that would cause nodes of radius \p radius to
* collide with the model and not rest on support blocker. Result is saved in the cache.
* \param keys RadiusLayerPairs of all requested areas. Every radius will be calculated up to the provided layer.
*/
void calculateCollisionAvoidance(const std::deque<RadiusLayerPair>& keys);

/*!
* \brief Creates the areas that have to be avoided by the tree's branches to prevent collision with the model on this layer and not rest on support blocker.
*
* The result is a 2D area that would cause nodes of radius \p radius to
* collide with the model and not rest on support blocker. Result is saved in the cache.
* \param key RadiusLayerPairs the requested areas. The radius will be calculated up to the provided layer.
*/
void calculateCollisionAvoidance(RadiusLayerPair key)
{
calculateCollisionAvoidance(std::deque<RadiusLayerPair>{ RadiusLayerPair(key) });
}

/*!
* \brief Creates the areas that have to be avoided by the tree's branches to prevent collision with the model on this layer. Holes are removed.
*
Expand Down Expand Up @@ -319,6 +359,11 @@ class TreeModelVolumes
*/
bool precalculated = false;

/*!
* \brief Whether the precalculate was called and finished, meaning every required value should be cached.
*/
bool precalculationFinished = false;

/*!
* \brief The index to access the outline corresponding with the currently processing mesh
*/
Expand All @@ -334,6 +379,11 @@ class TreeModelVolumes
*/
coord_t current_min_xy_dist_delta;

/*!
* \brief The top most layer where there is no anti_overhang on any layer below
*/
LayerIndex max_layer_idx_without_blocker;

/*!
* \brief Does at least one mesh allow support to rest on a model.
*/
Expand Down Expand Up @@ -367,6 +417,11 @@ class TreeModelVolumes
*/
Polygons machine_border_;

/*!
* \brief Polygons representing the printable area of the machine
*/
Polygons machine_area_;

/*!
* \brief Storage for layer outlines and the corresponding settings of the meshes grouped by meshes with identical setting.
*/
Expand Down Expand Up @@ -407,6 +462,12 @@ class TreeModelVolumes
mutable std::unordered_map<RadiusLayerPair, Polygons> collision_cache_holefree_;
std::unique_ptr<std::mutex> critical_collision_cache_holefree_ = std::make_unique<std::mutex>();

mutable std::unordered_map<LayerIndex, Polygons> accumulated_placeables_cache_radius_0_;
std::unique_ptr<std::mutex> critical_accumulated_placeables_cache_radius_0_ = std::make_unique<std::mutex>();

mutable std::unordered_map<RadiusLayerPair, Polygons> avoidance_cache_collision_;
std::unique_ptr<std::mutex> critical_avoidance_cache_collision_ = std::make_unique<std::mutex>();

mutable std::unordered_map<RadiusLayerPair, Polygons> avoidance_cache_;
std::unique_ptr<std::mutex> critical_avoidance_cache_ = std::make_unique<std::mutex>();

Expand Down
8 changes: 4 additions & 4 deletions include/TreeSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ constexpr auto SUPPORT_TREE_EXPONENTIAL_FACTOR = 1.5;
constexpr size_t SUPPORT_TREE_PRE_EXPONENTIAL_STEPS = 1;
constexpr coord_t SUPPORT_TREE_COLLISION_RESOLUTION = 500; // Only has an effect if SUPPORT_TREE_USE_EXPONENTIAL_COLLISION_RESOLUTION is false

constexpr coord_t SUPPORT_TREE_MAX_DEVIATION = 0;

using PropertyAreasUnordered = std::unordered_map<TreeSupportElement, Polygons>;
using PropertyAreas = std::map<TreeSupportElement, Polygons>;

Expand Down Expand Up @@ -209,7 +207,8 @@ class TreeSupport
* \param collision[in] The area representing obstacles.
* \param last_step_offset_without_check[in] The most it is allowed to offset in one step.
* \param min_amount_offset[in] How many steps have to be done at least. As this uses round offset this increases the amount of vertices, which may be required if Polygons get very small.
* Required as arcTolerance is not exposed in offset, which should result with a similar result.
* Required as arcTolerance is not exposed in offset, which should result with a similar result, benefit may be eliminated by simplifying.
* \param simplify[in] Should the offset operation also simplify the Polygon. Improves performance.
* \return The resulting Polygons object.
*/
[[nodiscard]] Polygons safeOffsetInc
Expand All @@ -219,7 +218,8 @@ class TreeSupport
const Polygons& collision,
coord_t safe_step_size,
coord_t last_step_offset_without_check,
size_t min_amount_offset
size_t min_amount_offset,
bool simplify
) const;

/*!
Expand Down
3 changes: 2 additions & 1 deletion include/TreeSupportEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum class AvoidanceType
{
SLOW,
FAST_SAFE,
FAST
FAST,
COLLISION
};

}//end namespace
Expand Down
Loading

0 comments on commit 1d62038

Please sign in to comment.