HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vertexAdjacency.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_HD_VERTEX_ADJACENCY_H
25 #define PXR_IMAGING_HD_VERTEX_ADJACENCY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
33 
34 #include "pxr/base/vt/array.h"
35 
36 #include <memory>
37 
39 
40 
42  std::shared_ptr<class Hd_VertexAdjacency>;
44  std::shared_ptr<class Hd_AdjacencyBuilderComputation>;
46  std::weak_ptr<class Hd_AdjacencyBuilderComputation>;
47 
48 class HdMeshTopology;
49 
50 /// \class Hd_VertexAdjacency
51 ///
52 /// Hd_VertexAdjacency encapsulates mesh adjacency information,
53 /// which is used for smooth normal computation.
54 ///
55 /// The Adjacency table (built by the AdjacencyBuilder computation)
56 /// provides the index of the previous and next vertex for each face
57 /// that uses that vertex.
58 ///
59 /// The table is split into two parts. The first part of the table
60 /// provides a offset to the prev/next data for the vertex as well as the
61 /// number of faces that use the vertex. The second part of the table
62 /// provides the actual prev/next indices.
63 ///
64 /// For example, The following prim has 4 vertices and 2 faces and uses
65 /// a CCW winding order:
66 ///
67 /// 3.---.2
68 /// | /|
69 /// | / |
70 /// |/ |
71 /// 0.---.1
72 ///
73 /// Picking one vertex, 0, it is used by 2 faces, so it contains 2 previous/
74 /// next pairs: (2, 1) and (3, 2)
75 ///
76 /// The full adjacency table for this prim would be:
77 ///
78 /// 0 1 | 2 3 | 4 5 | 6 7 || 8 9 10 11 | 12 13 | 14 15 16 17 | 18 19
79 /// 8 2 | 12 1 | 14 2 | 18 1 || 2 1 3 2 | 0 2 | 1 0 0 3 | 2 0
80 /// Offset / Count pairs || Prev / Next Pairs
81 /// per vertex || Per Vertex, Per Face.
82 ///
83 class Hd_VertexAdjacency final {
84 public:
85  HD_API
87 
88  HD_API
90 
91  /// Updates the internal adjacency table using the supplied topology.
92  /// Important! The adjacency table needs to be computed before smooth
93  /// normals.
94  HD_API
96 
97  /// Returns a shared adjacency builder computation which will call
98  /// BuildAdjacencyTable. The shared computation is useful if multiple
99  /// meshes share a topology and adjacency table, and only want to build the
100  /// adjacency table once.
101  HD_API
103  HdMeshTopology const *topology);
104 
105  /// Sets the buffer range used for adjacency table storage.
107  _adjacencyRange = range;
108  }
109 
110  /// Returns the buffer range used for adjacency table storage.
112  return _adjacencyRange;
113  }
114 
115  /// Returns the number of points in the adjacency table.
116  int GetNumPoints() const {
117  return _numPoints;
118  }
119 
120  /// Returns the adjacency table.
121  VtIntArray const &GetAdjacencyTable() const {
122  return _adjacencyTable;
123  }
124 
125 private:
126  int _numPoints;
127  VtIntArray _adjacencyTable;
128 
129  // adjacency buffer range
130  HdBufferArrayRangeSharedPtr _adjacencyRange;
131 
132  // weak ptr of adjacency builder used for dependent computations
133  Hd_AdjacencyBuilderComputationPtr _sharedAdjacencyBuilder;
134 };
135 
136 /// \class Hd_AdjacencyBuilderComputation
137 ///
138 /// A null buffer source to compute the adjacency table.
139 /// Since this is a null buffer source, it won't actually produce buffer
140 /// output; but other computations can depend on this to ensure
141 /// BuildAdjacencyTable is called.
142 ///
144 public:
145  HD_API
147  HdMeshTopology const *topology);
148  HD_API
149  virtual bool Resolve() override;
150 
151 protected:
152  HD_API
153  virtual bool _CheckValid() const override;
154 
155 private:
156  Hd_VertexAdjacency *_adjacency;
157  HdMeshTopology const *_topology;
158 };
159 
160 /// \class Hd_AdjacencyBufferSource
161 ///
162 /// A buffer source that puts an already computed adjacency table into
163 /// a resource registry buffer. This computation should be dependent on an
164 /// Hd_AdjacencyBuilderComputation.
165 ///
167 public:
168  HD_API
170  Hd_VertexAdjacency const *adjacency,
171  HdBufferSourceSharedPtr const &adjacencyBuilder);
172 
173  // overrides
174  HD_API
175  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
176  HD_API
177  virtual bool Resolve() override;
178 
179 protected:
180  HD_API
181  virtual bool _CheckValid() const override;
182 
183 private:
184  Hd_VertexAdjacency const *_adjacency;
185  HdBufferSourceSharedPtr const _adjacencyBuilder;
186 };
187 
188 
190 
191 #endif // PXR_IMAGING_HD_VERTEX_ADJACENCY_H
HD_API Hd_AdjacencyBuilderComputation(Hd_VertexAdjacency *adjacency, HdMeshTopology const *topology)
GLenum GLint * range
Definition: glew.h:3500
virtual HD_API bool _CheckValid() const override
void SetAdjacencyRange(HdBufferArrayRangeSharedPtr const &range)
Sets the buffer range used for adjacency table storage.
std::shared_ptr< class Hd_AdjacencyBuilderComputation > Hd_AdjacencyBuilderComputationSharedPtr
HD_API Hd_VertexAdjacency()
HD_API bool BuildAdjacencyTable(HdMeshTopology const *topology)
virtual HD_API bool _CheckValid() const override
#define HD_API
Definition: api.h:40
VtIntArray const & GetAdjacencyTable() const
Returns the adjacency table.
int GetNumPoints() const
Returns the number of points in the adjacency table.
HD_API HdBufferSourceSharedPtr GetSharedAdjacencyBuilderComputation(HdMeshTopology const *topology)
HD_API Hd_AdjacencyBufferSource(Hd_VertexAdjacency const *adjacency, HdBufferSourceSharedPtr const &adjacencyBuilder)
virtual HD_API bool Resolve() override
GT_API const UT_StringHolder topology
virtual HD_API bool Resolve() override
std::vector< struct HdBufferSpec > HdBufferSpecVector
std::weak_ptr< class Hd_AdjacencyBuilderComputation > Hd_AdjacencyBuilderComputationPtr
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
virtual HD_API void GetBufferSpecs(HdBufferSpecVector *specs) const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:45
HdBufferArrayRangeSharedPtr const & GetAdjacencyRange() const
Returns the buffer range used for adjacency table storage.
std::shared_ptr< class Hd_VertexAdjacency > Hd_VertexAdjacencySharedPtr
std::shared_ptr< class HdBufferSource > HdBufferSourceSharedPtr
HD_API ~Hd_VertexAdjacency()