Loading...
Searching...
No Matches
meshTopologyValidation.h
1//
2// Copyright 2020 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8
9#ifndef PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_VALIDATION_H
10#define PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_VALIDATION_H
11
13
14#include <array>
15#include <memory>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
20
45public:
46 friend class PxOsdMeshTopology;
48 enum class Code {
92 };
95 struct Invalidation {
96 Code code;
97 std::string message;
98 };
99private:
100 // TODO: In C++17, this class is uncessary and should be replaced with
101 // std::optional<std::vector<Invalidation>>
102 class _OptionalInvalidationVector {
103 std::unique_ptr<std::vector<Invalidation>> _value;
104
105 public:
106 _OptionalInvalidationVector() = default;
107 _OptionalInvalidationVector(_OptionalInvalidationVector&&) = default;
108 _OptionalInvalidationVector& operator=(_OptionalInvalidationVector&&) =
109 default;
110 _OptionalInvalidationVector(_OptionalInvalidationVector const& other)
111 : _value(nullptr) {
112 if (other._value) {
113 _value.reset(new std::vector<Invalidation>(*other._value));
114 }
115 }
116 _OptionalInvalidationVector& operator=(
117 _OptionalInvalidationVector const& other) {
118 _value = nullptr;
119 if (other._value) {
120 _value.reset(new std::vector<Invalidation>(*other._value));
121 }
122 return *this;
123 }
124 void emplace() { _value.reset(new std::vector<Invalidation>); }
125 explicit operator bool() const { return _value != nullptr; }
126 std::vector<Invalidation>& value() {
127 TF_DEV_AXIOM(*this);
128 return *_value;
129 }
130 std::vector<Invalidation> const& value() const {
131 TF_DEV_AXIOM(*this);
132 return *_value;
133 }
134 };
135
136 _OptionalInvalidationVector _invalidations;
137 template <size_t S>
138 void _ValidateToken(PxOsdMeshTopologyValidation::Code code,
139 const char* name, const TfToken& token,
140 const std::array<TfToken, S>& validTokens);
142 void _AppendInvalidation(const Invalidation& invalidation) {
143 if (!_invalidations) {
144 _invalidations.emplace();
145 }
146 _invalidations.value().push_back(invalidation);
147 }
149
150public:
151 PxOsdMeshTopologyValidation() = default;
154 default;
156 default;
158 PxOsdMeshTopologyValidation const& other) = default;
159
161 explicit operator bool() const {
162 return !_invalidations || _invalidations.value().empty();
163 }
164
165 using iterator = std::vector<Invalidation>::const_iterator;
166 using const_iterator = std::vector<Invalidation>::const_iterator;
167
170 const_iterator begin() const {
171 return _invalidations ? _invalidations.value().cbegin()
172 : const_iterator();
173 }
176 const_iterator end() const {
177 return _invalidations ? _invalidations.value().cend()
178 : const_iterator();
179 }
180
183 const_iterator cbegin() const {
184 return _invalidations ? _invalidations.value().cbegin()
185 : const_iterator();
186 }
189 const_iterator cend() const {
190 return _invalidations ? _invalidations.value().cend()
191 : const_iterator();
192 }
193private:
194 void _ValidateScheme(PxOsdMeshTopology const&);
195 void _ValidateOrientation(PxOsdMeshTopology const&);
196 void _ValidateTriangleSubdivision(PxOsdMeshTopology const&);
197 void _ValidateVertexInterpolation(PxOsdMeshTopology const&);
198 void _ValidateFaceVaryingInterpolation(PxOsdMeshTopology const&);
199 void _ValidateCreaseMethod(PxOsdMeshTopology const&);
200 void _ValidateCreasesAndCorners(PxOsdMeshTopology const&);
201 void _ValidateHoles(PxOsdMeshTopology const&);
202 void _ValidateFaceVertexCounts(PxOsdMeshTopology const&);
203 void _ValidateFaceVertexIndices(PxOsdMeshTopology const&);
204};
205
206PXR_NAMESPACE_CLOSE_SCOPE
207
208#endif
Topology data for meshes.
Definition: meshTopology.h:52
Utility to help validate an OpenSubdiv Mesh topology.
const_iterator begin() const
Returns an iterator for the beginning of the invalidation vector if it has been initialized.
const_iterator cbegin() const
Returns an iterator for the beginning of the invalidation vector if it has been initialized.
const_iterator cend() const
Returns an iterator for the end of the invalidation vector if it has been initialized.
const_iterator end() const
Returns an iterator for the end of the invalidation vector if it has been initialized.
Code
Codes for various invalid states for PxOsdMeshTopology.
@ InvalidCreaseIndicesSize
Encodes crease indices size not matching the sum of the lengths array.
@ InvalidCreaseWeightsSize
Encodes if crease weights is the size of the number of creases or the number of crease edges.
@ InvalidVertexInterpolationRule
Encodes invalid vertex interpolation rule token value.
@ InvalidFaceVertexCountsElement
Encodes if a vertex count is less than 3.
@ InvalidHoleIndicesElement
Encodes if the hole indices are negative or greater than the maximum face index (face count - 1)
@ InvalidFaceVertexIndicesSize
Encodes if the indices size does not match the sum of the face vertex counts array.
@ InvalidCreaseLengthElement
Encodes crease lengths element less than 2.
@ InvalidOrientation
Encodes invalid orientation token value.
@ InvalidFaceVaryingInterpolationRule
Encodes invalid face varying interpolation rule token value.
@ NegativeCreaseWeights
Encodes if crease weights are negative.
@ InvalidCreaseMethod
Encodes invalid crease method token value.
@ NegativeCornerWeights
Encodes if corner weights are negative.
@ InvalidCornerIndicesElement
Encodes corner indices element is not in the face vertex indices vector.
@ InvalidScheme
Encodes invalid scheme token value.
@ InvalidFaceVertexIndicesElement
Encodes if the element is negative.
@ InvalidCreaseIndicesElement
Encodes crease indices element is not in the face vertex indices vector.
@ InvalidTriangleSubdivision
Encodes invalid triangle subdivision token value.
@ InvalidCornerWeightsSize
Encodes if corner weights is not the size of the number of corner indices.
A tuple containing a code describing an invalidation and a descriptive message.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
Definition: diagnostic.h:205