| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#pragma once |
| 16 |
#include "manifold/manifold.h" |
| 17 |
#include "utils.h" |
| 18 |
|
| 19 |
namespace manifold { |
| 20 |
|
| 21 |
enum class CsgNodeType { Union, Intersection, Difference, Leaf }; |
| 22 |
|
| 23 |
class CsgLeafNode; |
| 24 |
|
| 25 |
class CsgNode : public std::enable_shared_from_this<CsgNode> { |
| 26 |
public: |
| 27 |
virtual std::shared_ptr<CsgLeafNode> ToLeafNode() const = 0; |
| 28 |
virtual std::shared_ptr<CsgNode> Transform(const mat3x4& m) const = 0; |
| 29 |
virtual CsgNodeType GetNodeType() const = 0; |
| 30 |
|
| 31 |
virtual std::shared_ptr<CsgNode> Boolean( |
| 32 |
const std::shared_ptr<CsgNode>& second, OpType op); |
| 33 |
|
| 34 |
std::shared_ptr<CsgNode> Translate(const vec3& t) const; |
| 35 |
std::shared_ptr<CsgNode> Scale(const vec3& s) const; |
| 36 |
std::shared_ptr<CsgNode> Rotate(double xDegrees = 0, double yDegrees = 0, |
| 37 |
double zDegrees = 0) const; |
| 38 |
}; |
| 39 |
|
| 40 |
class CsgLeafNode final : public CsgNode { |
| 41 |
public: |
| 42 |
CsgLeafNode(); |
| 43 |
CsgLeafNode(std::shared_ptr<const Manifold::Impl> pImpl_); |
| 44 |
CsgLeafNode(std::shared_ptr<const Manifold::Impl> pImpl_, mat3x4 transform_); |
| 45 |
|
| 46 |
std::shared_ptr<const Manifold::Impl> GetImpl() const; |
| 47 |
|
| 48 |
std::shared_ptr<CsgLeafNode> ToLeafNode() const override; |
| 49 |
|
| 50 |
std::shared_ptr<CsgNode> Transform(const mat3x4& m) const override; |
| 51 |
|
| 52 |
CsgNodeType GetNodeType() const override; |
| 53 |
|
| 54 |
static std::shared_ptr<CsgLeafNode> Compose( |
| 55 |
const std::vector<std::shared_ptr<CsgLeafNode>>& nodes); |
| 56 |
|
| 57 |
private: |
| 58 |
mutable std::shared_ptr<const Manifold::Impl> pImpl_; |
| 59 |
mutable mat3x4 transform_ = la::identity; |
| 60 |
}; |
| 61 |
|
| 62 |
class CsgOpNode final : public CsgNode { |
| 63 |
public: |
| 64 |
CsgOpNode(); |
| 65 |
|
| 66 |
CsgOpNode(const std::vector<std::shared_ptr<CsgNode>>& children, OpType op); |
| 67 |
|
| 68 |
std::shared_ptr<CsgNode> Boolean(const std::shared_ptr<CsgNode>& second, |
| 69 |
OpType op) override; |
| 70 |
|
| 71 |
std::shared_ptr<CsgNode> Transform(const mat3x4& m) const override; |
| 72 |
|
| 73 |
std::shared_ptr<CsgLeafNode> ToLeafNode() const override; |
| 74 |
|
| 75 |
CsgNodeType GetNodeType() const override; |
| 76 |
|
| 77 |
~CsgOpNode(); |
| 78 |
|
| 79 |
private: |
| 80 |
mutable ConcurrentSharedPtr<std::vector<std::shared_ptr<CsgNode>>> impl_ = |
| 81 |
ConcurrentSharedPtr<std::vector<std::shared_ptr<CsgNode>>>({}); |
| 82 |
OpType op_; |
| 83 |
mat3x4 transform_ = la::identity; |
| 84 |
|
| 85 |
mutable std::shared_ptr<CsgLeafNode> cache_ = nullptr; |
| 86 |
}; |
| 87 |
|
| 88 |
} |