All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
meshTopologyValidation.h
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 
26 #ifndef PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_VALIDATION_H
27 #define PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_VALIDATION_H
28 
30 
31 #include <array>
32 #include <memory>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
36 class PxOsdMeshTopology;
37 
62 public:
63  friend class PxOsdMeshTopology;
65  enum class Code {
109  };
112  struct Invalidation {
113  Code code;
114  std::string message;
115  };
116 private:
117  // TODO: In C++17, this class is uncessary and should be replaced with
118  // std::optional<std::vector<Invalidation>>
119  class _OptionalInvalidationVector {
120  std::unique_ptr<std::vector<Invalidation>> _value;
121 
122  public:
123  _OptionalInvalidationVector() = default;
124  _OptionalInvalidationVector(_OptionalInvalidationVector&&) = default;
125  _OptionalInvalidationVector& operator=(_OptionalInvalidationVector&&) =
126  default;
127  _OptionalInvalidationVector(_OptionalInvalidationVector const& other)
128  : _value(nullptr) {
129  if (other._value) {
130  _value.reset(new std::vector<Invalidation>(*other._value));
131  }
132  }
133  _OptionalInvalidationVector& operator=(
134  _OptionalInvalidationVector const& other) {
135  _value = nullptr;
136  if (other._value) {
137  _value.reset(new std::vector<Invalidation>(*other._value));
138  }
139  return *this;
140  }
141  void emplace() { _value.reset(new std::vector<Invalidation>); }
142  explicit operator bool() const { return _value != nullptr; }
143  std::vector<Invalidation>& value() {
144  TF_DEV_AXIOM(*this);
145  return *_value;
146  }
147  std::vector<Invalidation> const& value() const {
148  TF_DEV_AXIOM(*this);
149  return *_value;
150  }
151  };
152 
153  _OptionalInvalidationVector _invalidations;
154  template <size_t S>
155  void _ValidateToken(PxOsdMeshTopologyValidation::Code code,
156  const char* name, const TfToken& token,
157  const std::array<TfToken, S>& validTokens);
159  void _AppendInvalidation(const Invalidation& invalidation) {
160  if (!_invalidations) {
161  _invalidations.emplace();
162  }
163  _invalidations.value().push_back(invalidation);
164  }
166 
167 public:
168  PxOsdMeshTopologyValidation() = default;
171  default;
173  default;
174  PxOsdMeshTopologyValidation& operator=(
175  PxOsdMeshTopologyValidation const& other) = default;
176 
178  explicit operator bool() const {
179  return !_invalidations || _invalidations.value().empty();
180  }
181 
182  using iterator = std::vector<Invalidation>::const_iterator;
183  using const_iterator = std::vector<Invalidation>::const_iterator;
184 
187  const_iterator begin() const {
188  return _invalidations ? _invalidations.value().cbegin()
189  : const_iterator();
190  }
193  const_iterator end() const {
194  return _invalidations ? _invalidations.value().cend()
195  : const_iterator();
196  }
197 
200  const_iterator cbegin() const {
201  return _invalidations ? _invalidations.value().cbegin()
202  : const_iterator();
203  }
206  const_iterator cend() const {
207  return _invalidations ? _invalidations.value().cend()
208  : const_iterator();
209  }
210 private:
211  void _ValidateScheme(PxOsdMeshTopology const&);
212  void _ValidateOrientation(PxOsdMeshTopology const&);
213  void _ValidateTriangleSubdivision(PxOsdMeshTopology const&);
214  void _ValidateVertexInterpolation(PxOsdMeshTopology const&);
215  void _ValidateFaceVaryingInterpolation(PxOsdMeshTopology const&);
216  void _ValidateCreaseMethod(PxOsdMeshTopology const&);
217  void _ValidateCreasesAndCorners(PxOsdMeshTopology const&);
218  void _ValidateHoles(PxOsdMeshTopology const&);
219  void _ValidateFaceVertexCounts(PxOsdMeshTopology const&);
220  void _ValidateFaceVertexIndices(PxOsdMeshTopology const&);
221 };
222 
223 PXR_NAMESPACE_CLOSE_SCOPE
224 
225 #endif
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
Definition: diagnostic.h:222
A tuple containing a code describing an invalidation and a descriptive message.
Encodes if crease weights is the size of the number of creases or the number of crease edges...
Encodes invalid face varying interpolation rule token value.
const_iterator begin() const
Returns an iterator for the beginning of the invalidation vector if it has been initialized.
Encodes if corner weights are negative.
Encodes if crease weights are negative.
Topology data for meshes.
Definition: meshTopology.h:69
Encodes if the hole indices are negative or greater than the maximum face index (face count - 1) ...
const_iterator end() const
Returns an iterator for the end of the invalidation vector if it has been initialized.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Encodes if corner weights is not the size of the number of corner indices.
Encodes invalid crease method token value.
Code
Codes for various invalid states for PxOsdMeshTopology.
Encodes invalid vertex interpolation rule token value.
Utility to help validate an OpenSubdiv Mesh topology.
Encodes invalid scheme token value.
Encodes corner indices element is not in the face vertex indices vector.
Encodes crease indices size not matching the sum of the lengths array.
Encodes invalid orientation token value.
const_iterator cbegin() const
Returns an iterator for the beginning of the invalidation vector if it has been initialized.
Encodes crease lengths element less than 2.
Encodes if the indices size does not match the sum of the face vertex counts array.
Encodes crease indices element is not in the face vertex indices vector.
Encodes invalid triangle subdivision token value.
const_iterator cend() const
Returns an iterator for the end of the invalidation vector if it has been initialized.