All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
maskInterfaces.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 VTR_INTERFACES_H
25 #define VTR_INTERFACES_H
26 
27 #include "../version.h"
28 
29 #include "../sdc/type.h"
30 #include "../sdc/crease.h"
31 #include "../vtr/types.h"
32 
33 #include <vector>
34 
35 
36 namespace OpenSubdiv {
37 namespace OPENSUBDIV_VERSION {
38 
39 namespace Vtr {
40 
41 //
42 // Simple classes supporting the interfaces required of generic types in the Scheme mask
43 // queries, e.g. <typename FACE, MASK, etc.>
44 //
45 // These were added solely to support the temporary Refinement::computeMasks(), which
46 // is not expected to persist in its current form. So these are for illustration purposes
47 // now and may eventually be moved elsewhere (likely into Far).
48 //
49 
50 //
51 // For <typename MASK>, where the mask weights are stored:
52 //
54 public:
55  typedef float Weight; // Also part of the expected interface
56 
57 public:
58  MaskInterface(Weight* v, Weight* e, Weight* f) : _vertWeights(v), _edgeWeights(e), _faceWeights(f) { }
60 
61 public: // Generic interface expected of <typename MASK>:
62  int GetNumVertexWeights() const { return _vertCount; }
63  int GetNumEdgeWeights() const { return _edgeCount; }
64  int GetNumFaceWeights() const { return _faceCount; }
65 
66  void SetNumVertexWeights(int count) { _vertCount = count; }
67  void SetNumEdgeWeights( int count) { _edgeCount = count; }
68  void SetNumFaceWeights( int count) { _faceCount = count; }
69 
70  Weight const& VertexWeight(int index) const { return _vertWeights[index]; }
71  Weight const& EdgeWeight( int index) const { return _edgeWeights[index]; }
72  Weight const& FaceWeight( int index) const { return _faceWeights[index]; }
73 
74  Weight& VertexWeight(int index) { return _vertWeights[index]; }
75  Weight& EdgeWeight( int index) { return _edgeWeights[index]; }
76  Weight& FaceWeight( int index) { return _faceWeights[index]; }
77 
78 private:
79  Weight* _vertWeights;
80  Weight* _edgeWeights;
81  Weight* _faceWeights;
82 
83  int _vertCount;
84  int _edgeCount;
85  int _faceCount;
86 };
87 
88 
89 //
90 // For <typename FACE>, which provides information int the neighborhood of a face:
91 //
93 public:
95  FaceInterface(int vertCount) : _vertCount(vertCount) { }
97 
98 public: // Generic interface expected of <typename FACE>:
99  int GetNumVertices() const { return _vertCount; }
100 
101 private:
102  int _vertCount;
103 };
104 
105 
106 //
107 // For <typename EDGE>, which provides information in the neighborhood of an edge:
108 //
110 public:
112  EdgeInterface(Level const& level) : _level(&level) { }
114 
115  void SetIndex(int edgeIndex) { _eIndex = edgeIndex; }
116 
117 public: // Generic interface expected of <typename EDGE>:
118  int GetNumFaces() const { return _level->getEdgeFaces(_eIndex).size(); }
119  float GetSharpness() const { return _level->getEdgeSharpness(_eIndex); }
120 
121  void GetChildSharpnesses(Sdc::Crease const&, float s[2]) const {
122  // Need to use the Refinement here to identify the two child edges:
123  s[0] = s[1] = GetSharpness() - 1.0f;
124  }
125 
126  void GetNumVerticesPerFace(int vertsPerFace[]) const {
127  IndexArray const eFaces = _level->getEdgeFaces(_eIndex);
128  for (int i = 0; i < eFaces.size(); ++i) {
129  vertsPerFace[i] = _level->getFaceVertices(eFaces[i]).size();
130  }
131  }
132 
133 private:
134  const Level* _level;
135 
136  int _eIndex;
137 };
138 
139 
140 //
141 // For <typename VERTEX>, which provides information in the neighborhood of a vertex:
142 //
144 public:
146  VertexInterface(Level const& parent, Level const& child) : _parent(&parent), _child(&child) { }
148 
149  void SetIndex(int parentIndex, int childIndex) {
150  _pIndex = parentIndex;
151  _cIndex = childIndex;
152  _eCount = _parent->getVertexEdges(_pIndex).size();
153  _fCount = _parent->getVertexFaces(_pIndex).size();
154  }
155 
156 public: // Generic interface expected of <typename VERT>:
157  int GetNumEdges() const { return _eCount; }
158  int GetNumFaces() const { return _fCount; }
159 
160  float GetSharpness() const { return _parent->getVertexSharpness(_pIndex); }
161  float* GetSharpnessPerEdge(float pSharpness[]) const {
162  IndexArray const pEdges = _parent->getVertexEdges(_pIndex);
163  for (int i = 0; i < _eCount; ++i) {
164  pSharpness[i] = _parent->getEdgeSharpness(pEdges[i]);
165  }
166  return pSharpness;
167  }
168 
169  float GetChildSharpness(Sdc::Crease const&) const { return _child->getVertexSharpness(_cIndex); }
170  float* GetChildSharpnessPerEdge(Sdc::Crease const& crease, float cSharpness[]) const {
171  float * pSharpness = (float *)alloca(_eCount*sizeof(float));
172  GetSharpnessPerEdge(pSharpness);
173  crease.SubdivideEdgeSharpnessesAroundVertex(_eCount, pSharpness, cSharpness);
174  return cSharpness;
175  }
176 
177 private:
178  const Level* _parent;
179  const Level* _child;
180 
181  int _pIndex;
182  int _cIndex;
183  int _eCount;
184  int _fCount;
185 };
186 
187 } // end namespace Vtr
188 
189 } // end namespace OPENSUBDIV_VERSION
190 using namespace OPENSUBDIV_VERSION;
191 } // end namespace OpenSubdiv
192 
193 #endif /* VTR_INTERFACES_H */
194 
float GetChildSharpness(Sdc::Crease const &) const
void GetNumVerticesPerFace(int vertsPerFace[]) const
void GetChildSharpnesses(Sdc::Crease const &, float s[2]) const
float * GetSharpnessPerEdge(float pSharpness[]) const
float * GetChildSharpnessPerEdge(Sdc::Crease const &crease, float cSharpness[]) const
IndexArray const getEdgeFaces(Index edgeIndex) const
Definition: level.h:549
Weight const & FaceWeight(int index) const
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex, float const *incidentEdgeSharpnessAroundVertex, float *childEdgesSharpnessAroundVertex) const
void SetIndex(int parentIndex, int childIndex)
IndexArray const getFaceVertices(Index faceIndex) const
Definition: level.h:421
IndexArray const getVertexEdges(Index vertIndex) const
Definition: level.h:498
IndexArray const getVertexFaces(Index vertIndex) const
Definition: level.h:461
VertexInterface(Level const &parent, Level const &child)
Sharpness getVertexSharpness(Index vertIndex) const
Definition: level.h:586
Weight const & EdgeWeight(int index) const
Weight const & VertexWeight(int index) const
Sharpness getEdgeSharpness(Index edgeIndex) const
Definition: level.h:577
MaskInterface(Weight *v, Weight *e, Weight *f)