componentInterfaces.h
Go to the documentation of this file.
1 //
2 // Copyright 2014 DreamWorks Animation LLC.
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 OPENSUBDIV3_VTR_COMPONENT_INTERFACES_H
25 #define OPENSUBDIV3_VTR_COMPONENT_INTERFACES_H
26 
27 #include "../version.h"
28 
29 #include "../sdc/types.h"
30 #include "../sdc/crease.h"
31 #include "../vtr/types.h"
32 #include "../vtr/stackBuffer.h"
33 
34 #include <vector>
35 
36 
37 namespace OpenSubdiv {
38 namespace OPENSUBDIV_VERSION {
39 
40 namespace Vtr {
41 namespace internal {
42 
43 //
44 // Simple classes supporting the interfaces required of generic topological
45 // types in the Scheme mask queries, e.g. <typename FACE, VERTEX, etc.>
46 //
47 // These are not used with Vtr but arguably belong with it as the details to
48 // write these efficiently depends very much on intimate details of Vtr's
49 // implmentation, e.g. the use of tag bits, subdivision Rules, etc.
50 //
51 
52 
53 //
54 // For <typename FACE>, which provides information in the neighborhood of a face:
55 //
57 public:
59  FaceInterface(int vertCount) : _vertCount(vertCount) { }
61 
62 public: // Generic interface expected of <typename FACE>:
63  int GetNumVertices() const { return _vertCount; }
64 
65 private:
66  int _vertCount;
67 };
68 
69 
70 //
71 // For <typename EDGE>, which provides information in the neighborhood of an edge:
72 //
74 public:
76  EdgeInterface(Level const& level) : _level(&level) { }
78 
79  void SetIndex(int edgeIndex) { _eIndex = edgeIndex; }
80 
81 public: // Generic interface expected of <typename EDGE>:
82  int GetNumFaces() const { return _level->getEdgeFaces(_eIndex).size(); }
83  float GetSharpness() const { return _level->getEdgeSharpness(_eIndex); }
84 
85  void GetChildSharpnesses(Sdc::Crease const&, float s[2]) const {
86  // Need to use the Refinement here to identify the two child edges:
87  s[0] = s[1] = GetSharpness() - 1.0f;
88  }
89 
90  void GetNumVerticesPerFace(int vertsPerFace[]) const {
91  ConstIndexArray eFaces = _level->getEdgeFaces(_eIndex);
92  for (int i = 0; i < eFaces.size(); ++i) {
93  vertsPerFace[i] = _level->getFaceVertices(eFaces[i]).size();
94  }
95  }
96 
97 private:
98  const Level* _level;
99 
100  int _eIndex;
101 };
102 
103 
104 //
105 // For <typename VERTEX>, which provides information in the neighborhood of a vertex:
106 //
108 public:
110  VertexInterface(Level const& parent, Level const& child) : _parent(&parent), _child(&child) { }
112 
113  void SetIndex(int parentIndex, int childIndex) {
114  _pIndex = parentIndex;
115  _cIndex = childIndex;
116  _eCount = _parent->getVertexEdges(_pIndex).size();
117  _fCount = _parent->getVertexFaces(_pIndex).size();
118  }
119 
120 public: // Generic interface expected of <typename VERT>:
121  int GetNumEdges() const { return _eCount; }
122  int GetNumFaces() const { return _fCount; }
123 
124  float GetSharpness() const { return _parent->getVertexSharpness(_pIndex); }
125  float* GetSharpnessPerEdge(float pSharpness[]) const {
126  ConstIndexArray pEdges = _parent->getVertexEdges(_pIndex);
127  for (int i = 0; i < _eCount; ++i) {
128  pSharpness[i] = _parent->getEdgeSharpness(pEdges[i]);
129  }
130  return pSharpness;
131  }
132 
133  float GetChildSharpness(Sdc::Crease const&) const { return _child->getVertexSharpness(_cIndex); }
134  float* GetChildSharpnessPerEdge(Sdc::Crease const& crease, float cSharpness[]) const {
135  internal::StackBuffer<float,16> pSharpness(_eCount);
136  GetSharpnessPerEdge(pSharpness);
137  crease.SubdivideEdgeSharpnessesAroundVertex(_eCount, pSharpness, cSharpness);
138  return cSharpness;
139  }
140 
141 private:
142  const Level* _parent;
143  const Level* _child;
144 
145  int _pIndex;
146  int _cIndex;
147  int _eCount;
148  int _fCount;
149 };
150 
151 } // end namespace internal
152 } // end namespace Vtr
153 
154 } // end namespace OPENSUBDIV_VERSION
155 using namespace OPENSUBDIV_VERSION;
156 } // end namespace OpenSubdiv
157 
158 #endif /* OPENSUBDIV3_VTR_COMPONENT_INTERFACES_H */
void GetChildSharpnesses(Sdc::Crease const &, float s[2]) const
float getEdgeSharpness(Index edgeIndex) const
Definition: level.h:655
float * GetChildSharpnessPerEdge(Sdc::Crease const &crease, float cSharpness[]) const
ConstIndexArray getVertexFaces(Index vertIndex) const
Definition: level.h:523
ConstIndexArray getFaceVertices(Index faceIndex) const
Definition: level.h:479
float getVertexSharpness(Index vertIndex) const
Definition: level.h:664
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex, float const *incidentEdgeSharpnessAroundVertex, float *childEdgesSharpnessAroundVertex) const
ConstIndexArray getEdgeFaces(Index edgeIndex) const
Definition: level.h:616
ConstIndexArray getVertexEdges(Index vertIndex) const
Definition: level.h:560
Types, constants and utilities related to semi-sharp creasing – whose implementation is independent ...
Definition: crease.h:62