2#include "Engine/Attribute/Attribute.h"
3#include "Engine/Attribute/AttributeHandle.h"
4#include "Engine/Attribute/Point.h"
5#include "Engine/Attribute/Transform.h"
35 using iterator_category = std::forward_iterator_tag;
36 using difference_type = std::ptrdiff_t;
39 value_type operator*()
const {
return curOffset_; }
42 : primitive_(primitive), curOffset_(current)
65 return a.curOffset_ == b.curOffset_;
69 return a.curOffset_ != b.curOffset_;
77 const Offset end = primitive_.getNumPoints();
78 while (curOffset_ < end && !primitive_.isValidPoint(curOffset_))
83 Iterator end() {
return Iterator(primitive_, primitive_.getNumPoints()); }
88 Primitive(std::string_view path =
"/prim");
89 Primitive(
const Primitive& other);
90 Primitive& operator=(
const Primitive& rhs);
91 virtual ~Primitive() =
default;
93 virtual PrimType getType()
const = 0;
94 virtual std::shared_ptr<Primitive> clone()
const = 0;
95 virtual TransformClass transformType()
const = 0;
96 virtual void applyTransform(
const Matrix4& mat, TransformClass transformClass) = 0;
97 void applyTransform(
const Transform& transform, TransformClass transformClass)
99 applyTransform(transform.getMatrix(), transformClass);
101 virtual bool canMerge()
const {
return false; }
102 virtual void merge(std::shared_ptr<Primitive> other) {}
103 void incrementVersion();
105 virtual bool hasPoints()
const {
return false; }
107 virtual PointOffsets getPoints() {
return PointOffsets(*
this); }
108 virtual bool isValidPoint(Offset offset)
const {
return true; }
109 virtual void deletePoints(
const std::vector<Offset>& pointOffsets) {}
130 bool intrinsic =
false,
131 bool isInternal =
false
147 bool intrinsic =
false,
148 bool isInternal =
false
160 template <
typename T>
164 bool intrinsic =
false,
165 bool isInternal =
false
169 owner, std::move(name), attr::getAttributeType<T>(), intrinsic, isInternal
182 template <
typename T>
186 bool intrinsic =
false,
187 bool isInternal =
false
193 attr::getAttributeType<T>(),
197 if (!attribute)
return std::nullopt;
201 std::shared_ptr<attr::Attribute>
209 std::shared_ptr<const attr::Attribute> getAttribByName(
212 bool includeIntrinsics =
false
215 std::weak_ptr<const attr::Attribute>
222 std::vector<std::shared_ptr<const attr::Attribute>>
239 const std::string& name,
240 const std::vector<Offset>& offsets
246 std::shared_ptr<attr::Attribute>
255 std::weak_ptr<const attr::Attribute>
271 return addGroup(attr::AttributeOwner::POINT, std::move(name));
276 return addGroup(attr::AttributeOwner::PRIMITIVE, std::move(name));
281 addToGroup(attr::AttributeOwner::POINT, name, offsets);
286 addToGroup(attr::AttributeOwner::PRIMITIVE, name, offsets);
289 String getPath()
const {
return path_; };
290 void setPath(
const String& path) { path_ = path; };
293 virtual attr::attribVector& getAttributeStore(
const attr::AttributeOwner& owner);
294 virtual const attr::attribVector& getAttributeStore(
const attr::AttributeOwner& owner)
const;
295 virtual attr::attribVector& getGroupStore(
const attr::AttributeOwner& owner);
296 virtual const attr::attribVector& getGroupStore(
const attr::AttributeOwner& owner)
const;
297 attr::attribVector deepCopyAttributes(attr::attribVector source);
305 std::string path_ =
"/prim";
306 attr::attribVector pointAttributes_;
307 attr::attribVector primitiveAttributes_;
308 attr::attribVector pointGroups_;
309 attr::attribVector primitiveGroups_;
312using PrimPtr = std::shared_ptr<Primitive>;
Basic attribute, parameter, and node types for Enzo.
size_t Offset
enzo::Offset is the internal discontinuous index of an element in a given AttributeOwner.
Definition Types.h:181
AttributeType
Data types available to store attribute values in.
Definition Types.h:37
AttributeOwner
The segment of geometry that owns a particular attribute.
Definition Types.h:27
Read write accessor for enzo::attr::Attribute.
Base class for all primitive types in the engine.
attr::AttributeHandleBool addGroup(attr::AttributeOwner owner, std::string name)
Returns the group of this name on the given owner, adding one when the name is free.
Definition Primitive.cpp:216
std::vector< std::shared_ptr< const attr::Attribute > > getGroups(attr::AttributeOwner owner) const
Returns every group on the owner.
Definition Primitive.cpp:268
std::shared_ptr< attr::Attribute > tryAddAttribute(attr::AttributeOwner owner, std::string name, attr::AttributeType type, bool intrinsic=false, bool isInternal=false)
Returns the attribute of this name and type, adding one when the name is free.
Definition Primitive.cpp:139
std::shared_ptr< attr::Attribute > addAttribute(attr::AttributeOwner owner, std::string name, attr::AttributeType type, bool intrinsic=false, bool isInternal=false)
Returns the attribute of this name and type, adding one when the name is free.
Definition Primitive.cpp:124
void addAttributesFrom(const Primitive &source, attr::AttributeOwner owner)
Adds each attribute and group of the source to this primitive, keeping its name and type.
Definition Primitive.cpp:274
std::vector< std::shared_ptr< const attr::Attribute > > getAttributes(attr::AttributeOwner owner, bool includeIntrinsics=false) const
Returns every attribute on the owner.
Definition Primitive.cpp:65
std::weak_ptr< const attr::Attribute > getGroupByIndex(attr::AttributeOwner owner, unsigned int index) const
Returns the group at the given index in the owner's group store.
Definition Primitive.cpp:254
std::shared_ptr< attr::Attribute > getGroupByName(attr::AttributeOwner owner, const std::string &name) const
Looks up a group by name.
Definition Primitive.cpp:239
size_t getElementCount(const attr::AttributeOwner &owner) const
Returns the number of elements in the given owner's store.
Definition Primitive.cpp:204
std::optional< attr::AttributeHandle< T > > tryAddAttribute(attr::AttributeOwner owner, std::string name, bool intrinsic=false, bool isInternal=false)
Returns a handle to the attribute of this type stored under this name, adding one when the name is fr...
Definition Primitive.h:183
attr::AttributeHandle< T > addAttribute(attr::AttributeOwner owner, std::string name, bool intrinsic=false, bool isInternal=false)
Returns a handle to the attribute of this type stored under this name, adding one when the name is fr...
Definition Primitive.h:161
void addToPointGroup(const std::string &name, const std::vector< Offset > &offsets)
Marks the given offsets as members of the point group.
Definition Primitive.h:279
void addToPrimitiveGroup(const std::string &name, const std::vector< Offset > &offsets)
Marks the given offsets as members of the primitive group.
Definition Primitive.h:284
attr::AttributeHandleBool addPointGroup(std::string name)
Returns the point group of this name, adding one when the name is free.
Definition Primitive.h:269
size_t getNumGroups(attr::AttributeOwner owner) const
Returns how many groups live on the given owner.
Definition Primitive.cpp:248
attr::AttributeHandleBool addPrimitiveGroup(std::string name)
Returns the primitive group of this name, adding one when the name is free.
Definition Primitive.h:274
virtual void defragment()
Compacts storage, removing entries marked invalid so offsets are contiguous again.
Definition Primitive.h:115
void addToGroup(attr::AttributeOwner owner, const std::string &name, const std::vector< Offset > &offsets)
Marks the given offsets as members of the group.
Definition Primitive.cpp:223
Definition Primitive.h:34
Definition Primitive.h:31