Path: blob/master/thirdparty/manifold/src/csg_tree.h
10278 views
// Copyright 2022 The Manifold Authors.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314#pragma once15#include "manifold/manifold.h"16#include "utils.h"1718namespace manifold {1920enum class CsgNodeType { Union, Intersection, Difference, Leaf };2122class CsgLeafNode;2324class CsgNode : public std::enable_shared_from_this<CsgNode> {25public:26virtual std::shared_ptr<CsgLeafNode> ToLeafNode() const = 0;27virtual std::shared_ptr<CsgNode> Transform(const mat3x4& m) const = 0;28virtual CsgNodeType GetNodeType() const = 0;2930virtual std::shared_ptr<CsgNode> Boolean(31const std::shared_ptr<CsgNode>& second, OpType op);3233std::shared_ptr<CsgNode> Translate(const vec3& t) const;34std::shared_ptr<CsgNode> Scale(const vec3& s) const;35std::shared_ptr<CsgNode> Rotate(double xDegrees = 0, double yDegrees = 0,36double zDegrees = 0) const;37};3839class CsgLeafNode final : public CsgNode {40public:41CsgLeafNode();42CsgLeafNode(std::shared_ptr<const Manifold::Impl> pImpl_);43CsgLeafNode(std::shared_ptr<const Manifold::Impl> pImpl_, mat3x4 transform_);4445std::shared_ptr<const Manifold::Impl> GetImpl() const;4647std::shared_ptr<CsgLeafNode> ToLeafNode() const override;4849std::shared_ptr<CsgNode> Transform(const mat3x4& m) const override;5051CsgNodeType GetNodeType() const override;5253static std::shared_ptr<CsgLeafNode> Compose(54const std::vector<std::shared_ptr<CsgLeafNode>>& nodes);5556private:57mutable std::shared_ptr<const Manifold::Impl> pImpl_;58mutable mat3x4 transform_ = la::identity;59};6061class CsgOpNode final : public CsgNode {62public:63CsgOpNode();6465CsgOpNode(const std::vector<std::shared_ptr<CsgNode>>& children, OpType op);6667std::shared_ptr<CsgNode> Boolean(const std::shared_ptr<CsgNode>& second,68OpType op) override;6970std::shared_ptr<CsgNode> Transform(const mat3x4& m) const override;7172std::shared_ptr<CsgLeafNode> ToLeafNode() const override;7374CsgNodeType GetNodeType() const override;7576~CsgOpNode();7778private:79mutable ConcurrentSharedPtr<std::vector<std::shared_ptr<CsgNode>>> impl_ =80ConcurrentSharedPtr<std::vector<std::shared_ptr<CsgNode>>>({});81OpType op_;82mat3x4 transform_ = la::identity;83// the following fields are for lazy evaluation, so they are mutable84mutable std::shared_ptr<CsgLeafNode> cache_ = nullptr;85};8687} // namespace manifold888990