opensubdiv/vtr/componentInterfaces.h Source File

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 // implementation, 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 //
56 class FaceInterface {
57 public:
58 FaceInterface() { }
59 FaceInterface(int vertCount) : _vertCount(vertCount) { }
60 ~FaceInterface() { }
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 //
73 class EdgeInterface {
74 public:
75 EdgeInterface() { }
76 EdgeInterface(Level const& level) : _level(&level) { }
77 ~EdgeInterface() { }
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 //
107 class VertexInterface {
108 public:
109 VertexInterface() { }
110 VertexInterface(Level const& parent, Level const& child) : _parent(&parent), _child(&child) { }
111 ~VertexInterface() { }
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 */
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::GetNumFaces
int GetNumFaces() const
Definition: componentInterfaces.h:82
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::FaceInterface::~FaceInterface
~FaceInterface()
Definition: componentInterfaces.h:60
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level::getVertexSharpness
float getVertexSharpness(Index vertIndex) const
Definition: level.h:722
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::SetIndex
void SetIndex(int parentIndex, int childIndex)
Definition: componentInterfaces.h:113
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level::getEdgeFaces
ConstIndexArray getEdgeFaces(Index edgeIndex) const
Definition: level.h:670
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease
Types, constants and utilities related to semi-sharp creasing – whose implementation is independent...
Definition: crease.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::GetChildSharpness
float GetChildSharpness(Sdc::Crease const &) const
Definition: componentInterfaces.h:133
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface
Definition: componentInterfaces.h:73
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::GetSharpness
float GetSharpness() const
Definition: componentInterfaces.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstArray< Index >
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::VertexInterface
VertexInterface(Level const &parent, Level const &child)
Definition: componentInterfaces.h:110
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level::getEdgeSharpness
float getEdgeSharpness(Index edgeIndex) const
Definition: level.h:713
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::GetNumFaces
int GetNumFaces() const
Definition: componentInterfaces.h:122
OpenSubdiv
Definition: error.h:30
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::GetChildSharpnesses
void GetChildSharpnesses(Sdc::Crease const &, float s[2]) const
Definition: componentInterfaces.h:85
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::GetNumEdges
int GetNumEdges() const
Definition: componentInterfaces.h:121
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level
Definition: level.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level::getVertexFaces
ConstIndexArray getVertexFaces(Index vertIndex) const
Definition: level.h:577
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::SetIndex
void SetIndex(int edgeIndex)
Definition: componentInterfaces.h:79
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::EdgeInterface
EdgeInterface()
Definition: componentInterfaces.h:75
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::FaceInterface
Definition: componentInterfaces.h:56
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::GetNumVerticesPerFace
void GetNumVerticesPerFace(int vertsPerFace[]) const
Definition: componentInterfaces.h:90
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::GetSharpnessPerEdge
float * GetSharpnessPerEdge(float pSharpness[]) const
Definition: componentInterfaces.h:125
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Crease::SubdivideEdgeSharpnessesAroundVertex
void SubdivideEdgeSharpnessesAroundVertex(int incidentEdgeCountAtVertex, float const *incidentEdgeSharpnessAroundVertex, float *childEdgesSharpnessAroundVertex) const
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level::getFaceVertices
ConstIndexArray getFaceVertices(Index faceIndex) const
Definition: level.h:533
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::VertexInterface
VertexInterface()
Definition: componentInterfaces.h:109
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::FaceInterface::FaceInterface
FaceInterface(int vertCount)
Definition: componentInterfaces.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::~VertexInterface
~VertexInterface()
Definition: componentInterfaces.h:111
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface
Definition: componentInterfaces.h:107
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::StackBuffer
Definition: stackBuffer.h:50
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::EdgeInterface
EdgeInterface(Level const &level)
Definition: componentInterfaces.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::FaceInterface::FaceInterface
FaceInterface()
Definition: componentInterfaces.h:58
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level::getVertexEdges
ConstIndexArray getVertexEdges(Index vertIndex) const
Definition: level.h:614
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::GetSharpness
float GetSharpness() const
Definition: componentInterfaces.h:124
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstArray::size
size_type size() const
Definition: array.h:72
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::VertexInterface::GetChildSharpnessPerEdge
float * GetChildSharpnessPerEdge(Sdc::Crease const &crease, float cSharpness[]) const
Definition: componentInterfaces.h:134
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::EdgeInterface::~EdgeInterface
~EdgeInterface()
Definition: componentInterfaces.h:77
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::FaceInterface::GetNumVertices
int GetNumVertices() const
Definition: componentInterfaces.h:63