HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
meshTopology.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_H
25 #define PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_H
26 
27 /// \file pxOsd/meshTopology.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/pxOsd/api.h"
33 
34 #include "pxr/base/vt/array.h"
35 #include "pxr/base/vt/value.h"
36 
37 #include "pxr/base/tf/token.h"
38 
40 
41 /// \class PxOsdMeshTopology
42 ///
43 /// Topology data for meshes.
44 ///
45 /// Once constructed, this class is immutable (except when assigned
46 /// or moved).
47 ///
48 /// To make changing certain properties easier, several methods are
49 /// provided. WithScheme, WithHoleIndices, and WithSubdivTags will
50 /// return copies of the object with certain specific properites changed.
51 ///
52 /// \code{.cpp}
53 /// PxOsdMeshTopology otherTopology =
54 /// originalTopology.WithScheme(PxOsdOpenSubdivTokens->catmullClark);
55 /// TF_VERIFY(otherTopology.GetScheme() ==
56 /// PxOsdOpenSubdivTokens->catmullClark);
57 /// TF_VERIFY(otherTopology.GetOrientation() ==
58 /// originalTopology.GetOrientation());
59 /// TF_VERIFY(otherTopology.GetSubdivTags() ==
60 /// originalTopology.GetSubdivTags());
61 /// TF_VERIFY(otherTopology.GetFaceVertexCounts() ==
62 /// originalTopology.GetFaceVertexCounts());
63 /// TF_VERIFY(otherTopology.GetFaceVertexIndices() ==
64 /// originalTopology.GetFaceVertexIndices());
65 /// \endcode
66 ///
67 /// The cost of copying should be mitigated by the copy semantics of VtArray and
68 /// TfToken.
70 
71 public:
72 
73  typedef uint64_t ID;
74 
75  PXOSD_API
77 
78  PxOsdMeshTopology& operator=(const PxOsdMeshTopology &) = default;
79  PxOsdMeshTopology(const PxOsdMeshTopology &) = default;
82  ~PxOsdMeshTopology() = default;
83 
84  /// Construct a topology without holes or subdiv tags
85  PXOSD_API
87  TfToken const& scheme,
88  TfToken const& orientation,
89  VtIntArray const& faceVertexCounts,
90  VtIntArray const& faceVertexIndices);
91 
92  /// Construct a topology with holes
93  PXOSD_API
95  TfToken const& scheme,
96  TfToken const& orientation,
97  VtIntArray const& faceVertexCounts,
98  VtIntArray const& faceVertexIndices,
99  VtIntArray const& holeIndices);
100 
101  /// Construct a topology with holes and subdiv tags
102  PXOSD_API
104  TfToken const& scheme,
105  TfToken const& orientation,
106  VtIntArray const& faceVertexCounts,
107  VtIntArray const& faceVertexIndices,
108  VtIntArray const& holeIndices,
109  PxOsdSubdivTags const& subdivTags);
110 
111  /// Construct a topology with subdiv tags
112  PXOSD_API
114  TfToken const& scheme,
115  TfToken const& orientation,
116  VtIntArray const& faceVertexCounts,
117  VtIntArray const& faceVertexIndices,
118  PxOsdSubdivTags const& subdivTags);
119 
120 public:
121 
122  /// Returns the subdivision scheme
123  TfToken const GetScheme() const {
124  return _scheme;
125  }
126 
127  /// Returns face vertex counts.
128  VtIntArray const &GetFaceVertexCounts() const {
129  return _faceVertexCounts;
130  }
131 
132  /// Returns face vertex indices.
133  VtIntArray const &GetFaceVertexIndices() const {
134  return _faceVertexIndices;
135  }
136 
137  /// Returns orientation.
138  TfToken const &GetOrientation() const {
139  return _orientation;
140  }
141 
142 
143  ///
144  /// \name Holes
145  /// @{
146  /// Returns the hole face indices.
147  VtIntArray const &GetHoleIndices() const {
148  return _holeIndices;
149  }
150 
151  /// @}
152 
153  ///
154  /// \name Tags
155  /// @{
156 
157  /// Returns subdivision tags
158  PxOsdSubdivTags const & GetSubdivTags() const {
159  return _subdivTags;
160  }
161 
162  /// @}
163 
164  /// Return a copy of the topology, changing only the scheme.
165  /// Valid values include: catmullClark, loop, bilinear.
166  ///
167  /// Note that the token "catmark" is also supported for backward
168  /// compatibility, but has been deprecated.
170  return PxOsdMeshTopology(scheme, GetOrientation(),
173  }
174 
175  /// Return a copy of the topology, changing only the subdiv tags.
179  GetHoleIndices(), tags);
180  }
181 
182  /// Return a copy of the topology, changing only the hole indices.
183  PXOSD_API PxOsdMeshTopology WithHoleIndices(VtIntArray const& holeIndices) const {
186  holeIndices, GetSubdivTags());
187  }
188 public:
189 
190  /// Returns the hash value of this topology to be used for instancing.
191  PXOSD_API
192  ID ComputeHash() const;
193 
194  /// Equality check between two mesh topologies.
195  PXOSD_API
196  bool operator==(PxOsdMeshTopology const &other) const;
197 
198  /// Returns a validation object which is empty if the topology is valid
199  ///
200  /// \code{.cpp}
201  /// // Validation with minimal reporting
202  /// if (!topology.Validate()) TF_CODING_ERROR("Invalid topology.");
203  /// \endcode
204  ///
205  /// \code{.cpp}
206  /// {
207  /// PxOsdMeshTopologyValidation validation = topology.Validate();
208  /// if (!validation){
209  /// for (auto const& elem: validation){
210  /// TF_WARN(elem.message);
211  /// }
212  /// }
213  /// }
214  /// \endcode
215  ///
216  /// \note Internally caches the result of the validation if the topology is
217  /// valid
218  PXOSD_API
220 
221 private:
222 
223  // note: if you're going to add more members, make sure
224  // ComputeHash will be updated too.
225 
226  TfToken _scheme,
227  _orientation;
228 
229  VtIntArray _faceVertexCounts;
230  VtIntArray _faceVertexIndices;
231  VtIntArray _holeIndices;
232 
233  PxOsdSubdivTags _subdivTags;
234 
235  struct _Validated {
236  std::atomic<bool> value;
237 
238  _Validated() : value(false) {}
239  _Validated(const _Validated& other) : value(other.value.load()) {}
240  _Validated(_Validated&& other) : value(other.value.load()) {
241  other.value = false;
242  }
243  _Validated& operator=(const _Validated& other) {
244  value.store(other.value.load());
245  return *this;
246  }
247  _Validated& operator=(_Validated&& other) {
248  value.store(other.value.load());
249  other.value = false;
250  return *this;
251  }
252  };
253 
254  // This should NOT be included in the hash
255  // This evaluates to true if the topology has been successfully
256  // pre-validated. If this is false, the topology is either invalid
257  // or it hasn't been validated yet.
258  mutable _Validated _validated;
259 };
260 
261 PXOSD_API
262 std::ostream& operator << (std::ostream &out, PxOsdMeshTopology const &);
263 PXOSD_API
264 bool operator!=(const PxOsdMeshTopology& lhs, const PxOsdMeshTopology& rhs);
265 
266 
268 
269 #endif // PXR_IMAGING_PX_OSD_MESH_TOPOLOGY_H
PXOSD_API PxOsdMeshTopology WithSubdivTags(PxOsdSubdivTags const &tags) const
Return a copy of the topology, changing only the subdiv tags.
Definition: meshTopology.h:176
PXOSD_API PxOsdMeshTopologyValidation Validate() const
TfToken const GetScheme() const
Returns the subdivision scheme.
Definition: meshTopology.h:123
GLsizei const GLfloat * value
Definition: glcorearb.h:824
VtIntArray const & GetFaceVertexCounts() const
Returns face vertex counts.
Definition: meshTopology.h:128
TfToken const & GetOrientation() const
Returns orientation.
Definition: meshTopology.h:138
Definition: token.h:87
#define PXOSD_API
Definition: api.h:40
~PxOsdMeshTopology()=default
PXOSD_API std::ostream & operator<<(std::ostream &out, PxOsdMeshTopology const &)
PXOSD_API bool operator==(PxOsdMeshTopology const &other) const
Equality check between two mesh topologies.
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
VtIntArray const & GetFaceVertexIndices() const
Returns face vertex indices.
Definition: meshTopology.h:133
VtIntArray const & GetHoleIndices() const
Definition: meshTopology.h:147
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
PXOSD_API PxOsdMeshTopology WithHoleIndices(VtIntArray const &holeIndices) const
Return a copy of the topology, changing only the hole indices.
Definition: meshTopology.h:183
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
PXOSD_API PxOsdMeshTopology WithScheme(TfToken const &scheme) const
Definition: meshTopology.h:169
Definition: core.h:1131
PxOsdMeshTopology & operator=(const PxOsdMeshTopology &)=default
PXOSD_API PxOsdMeshTopology()
PxOsdSubdivTags const & GetSubdivTags() const
Returns subdivision tags.
Definition: meshTopology.h:158
PXOSD_API ID ComputeHash() const
Returns the hash value of this topology to be used for instancing.
constexpr FMT_INLINE value()
Definition: core.h:1154