OpenSubdiv: opensubdiv/vtr/componentInterfaces.h Source File

| OpenSubdiv

Loading...
Searching...
No Matches
componentInterfaces.h
Go to the documentation of this file.
1//
2// Copyright 2014 DreamWorks Animation LLC.
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7#ifndef OPENSUBDIV3_VTR_COMPONENT_INTERFACES_H
8#define OPENSUBDIV3_VTR_COMPONENT_INTERFACES_H
9
10#include "../version.h"
11
12#include "../sdc/types.h"
13#include "../sdc/crease.h"
14#include "../vtr/types.h"
15#include "../vtr/stackBuffer.h"
16
17#include <vector>
18
19
20namespace OpenSubdiv {
21namespace OPENSUBDIV_VERSION {
22
23namespace Vtr {
24namespace internal {
25
26//
27// Simple classes supporting the interfaces required of generic topological
28// types in the Scheme mask queries, e.g. <typename FACE, VERTEX, etc.>
29//
30// These are not used with Vtr but arguably belong with it as the details to
31// write these efficiently depends very much on intimate details of Vtr's
32// implementation, e.g. the use of tag bits, subdivision Rules, etc.
33//
34
35
36//
37// For <typename FACE>, which provides information in the neighborhood of a face:
38//
39class FaceInterface {
40public:
41 FaceInterface() { }
42 FaceInterface(int vertCount) : _vertCount(vertCount) { }
43 ~FaceInterface() { }
44
45public: // Generic interface expected of <typename FACE>:
46 int GetNumVertices() const { return _vertCount; }
47
48private:
49 int _vertCount;
50};
51
52
53//
54// For <typename EDGE>, which provides information in the neighborhood of an edge:
55//
56class EdgeInterface {
57public:
58 EdgeInterface() { }
59 EdgeInterface(Level const& level) : _level(&level) { }
60 ~EdgeInterface() { }
61
62 void SetIndex(int edgeIndex) { _eIndex = edgeIndex; }
63
64public: // Generic interface expected of <typename EDGE>:
65 int GetNumFaces() const { return _level->getEdgeFaces(_eIndex).size(); }
66 float GetSharpness() const { return _level->getEdgeSharpness(_eIndex); }
67
68 void GetChildSharpnesses(Sdc::Crease const&, float s[2]) const {
69 // Need to use the Refinement here to identify the two child edges:
70 s[0] = s[1] = GetSharpness() - 1.0f;
71 }
72
73 void GetNumVerticesPerFace(int vertsPerFace[]) const {
74 ConstIndexArray eFaces = _level->getEdgeFaces(_eIndex);
75 for (int i = 0; i < eFaces.size(); ++i) {
76 vertsPerFace[i] = _level->getFaceVertices(eFaces[i]).size();
77 }
78 }
79
80private:
81 const Level* _level;
82
83 int _eIndex;
84};
85
86
87//
88// For <typename VERTEX>, which provides information in the neighborhood of a vertex:
89//
90class VertexInterface {
91public:
92 VertexInterface() { }
93 VertexInterface(Level const& parent, Level const& child) : _parent(&parent), _child(&child) { }
94 ~VertexInterface() { }
95
96 void SetIndex(int parentIndex, int childIndex) {
97 _pIndex = parentIndex;
98 _cIndex = childIndex;
99 _eCount = _parent->getVertexEdges(_pIndex).size();
100 _fCount = _parent->getVertexFaces(_pIndex).size();
101 }
102
103public: // Generic interface expected of <typename VERT>:
104 int GetNumEdges() const { return _eCount; }
105 int GetNumFaces() const { return _fCount; }
106
107 float GetSharpness() const { return _parent->getVertexSharpness(_pIndex); }
108 float* GetSharpnessPerEdge(float pSharpness[]) const {
109 ConstIndexArray pEdges = _parent->getVertexEdges(_pIndex);
110 for (int i = 0; i < _eCount; ++i) {
111 pSharpness[i] = _parent->getEdgeSharpness(pEdges[i]);
112 }
113 return pSharpness;
114 }
115
116 float GetChildSharpness(Sdc::Crease const&) const { return _child->getVertexSharpness(_cIndex); }
117 float* GetChildSharpnessPerEdge(Sdc::Crease const& crease, float cSharpness[]) const {
118 internal::StackBuffer<float,16> pSharpness(_eCount);
119 GetSharpnessPerEdge(pSharpness);
120 crease.SubdivideEdgeSharpnessesAroundVertex(_eCount, pSharpness, cSharpness);
121 return cSharpness;
122 }
123
124private:
125 const Level* _parent;
126 const Level* _child;
127
128 int _pIndex;
129 int _cIndex;
130 int _eCount;
131 int _fCount;
132};
133
134} // end namespace internal
135} // end namespace Vtr
136
137} // end namespace OPENSUBDIV_VERSION
138using namespace OPENSUBDIV_VERSION;
139} // end namespace OpenSubdiv
140
141#endif /* OPENSUBDIV3_VTR_COMPONENT_INTERFACES_H */
crease.h
stackBuffer.h
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Vtr
Definition topologyRefiner.h:23
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstIndexArray
ConstArray< Index > ConstIndexArray
Definition types.h:63
types.h
types.h