Enzo
Loading...
Searching...
No Matches
NodePacket.h
1#pragma once
2#include "Engine/Primitives/Primitive.h"
3#include <cstddef>
4#include <memory>
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace enzo {
10
12{
13 public:
14 // Lazy forward iterator that flattens transforms across all primitives.
15 // See NodePacket.cpp for Iterator method implementations.
17 {
18 struct Iterator
19 {
20 using iterator_category = std::forward_iterator_tag;
21 using difference_type = std::ptrdiff_t;
22 using value_type = Transform;
23
25 std::vector<geo::PrimPtr>& primitives,
26 TransformClass transformClass,
27 size_t primIdx
28 );
29
30 Transform operator*() const;
31 Iterator& operator++();
32 Iterator operator++(int);
33 friend bool operator==(const Iterator& a, const Iterator& b)
34 {
35 return a.primIdx_ == b.primIdx_ && a.offset_ == b.offset_;
36 }
37 friend bool operator!=(const Iterator& a, const Iterator& b) { return !(a == b); }
38
39 private:
40 std::vector<geo::PrimPtr>& primitives_;
41 TransformClass transformClass_;
42 size_t primIdx_;
43 Offset offset_ = 0;
44 std::shared_ptr<attr::Attribute> curAttrib_;
45 size_t curSize_ = 0;
46 std::vector<Transform> orientations_;
47
48 void advance();
49 };
50
51 Transforms(std::vector<geo::PrimPtr>& primitives, TransformClass transformClass)
52 : primitives_(primitives), transformClass_(transformClass)
53 {
54 }
55
56 Iterator begin() { return Iterator(primitives_, transformClass_, 0); }
57 Iterator end() { return Iterator(primitives_, transformClass_, primitives_.size()); }
58
59 private:
60 std::vector<geo::PrimPtr>& primitives_;
61 TransformClass transformClass_;
62 };
63
67 void addPrimitive(std::shared_ptr<enzo::geo::Primitive> primitive);
69 void attemptMerge(geo::PrimPtr prim);
70
71 std::shared_ptr<enzo::geo::Primitive> getPrimitive(unsigned int index);
72 std::shared_ptr<const enzo::geo::Primitive> getPrimitive(unsigned int index) const;
73 geo::PrimPtr getPrimAtPath(const std::string& path);
74 std::shared_ptr<const geo::Primitive> getPrimAtPath(const std::string& path) const;
75
76 const std::vector<std::shared_ptr<enzo::geo::Primitive>>& getPrimitives() const
77 {
78 return primitives_;
79 }
80 std::vector<geo::PrimPtr> getPrimitives(enzo::geo::PrimType type) const;
82 void movePrim(const geo::PrimPtr& primitive, const std::string& toPath);
84 void movePrim(const std::string& fromPath, const std::string& toPath);
85 void removePrim(std::string path);
86
87 Transforms getTransforms(TransformClass transformClass)
88 {
89 return Transforms(primitives_, transformClass);
90 }
91
92 size_t size() const;
93 NodePacket deepCopy() const;
94
95 private:
97 std::string claimPath(const std::string& path);
98
99 std::vector<geo::PrimPtr> primitives_;
101 std::unordered_map<std::string, std::size_t> nextNumberByPath_;
102};
103
104} // namespace enzo
size_t Offset
enzo::Offset is the internal discontinuous index of an element in a given AttributeOwner.
Definition Types.h:182
Definition NodePacket.h:12
void movePrim(const geo::PrimPtr &primitive, const std::string &toPath)
Moves the primitive to the path, numbering it when another primitive holds it.
Definition NodePacket.cpp:266
void addPrimitive(std::shared_ptr< enzo::geo::Primitive > primitive)
Adds the primitive, numbering its path when another primitive holds it.
Definition NodePacket.cpp:204
void attemptMerge(geo::PrimPtr prim)
Merges the primitive into the one at its path, or adds it when either cannot merge.
Definition NodePacket.cpp:210
An affine transform that composes translation, rotation, and scale.
Definition NodePacket.h:19
Definition NodePacket.h:17