OpenSubdiv
patchDescriptor.h
Go to the documentation of this file.
1 //
2 // Copyright 2013 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 
25 #ifndef OPENSUBDIV3_FAR_PATCH_DESCRIPTOR_H
26 #define OPENSUBDIV3_FAR_PATCH_DESCRIPTOR_H
27 
28 #include "../version.h"
29 
30 #include "../far/types.h"
31 #include "../sdc/types.h"
32 
33 #include <vector>
34 
35 namespace OpenSubdiv {
36 namespace OPENSUBDIV_VERSION {
37 
38 namespace Far {
39 
45 
46 public:
47 
48  enum Type {
49  NON_PATCH = 0,
50 
53 
56 
57  LOOP,
58 
64  };
65 
66 public:
67 
70  _type(NON_PATCH) { }
71 
73  PatchDescriptor(int type) :
74  _type(type) { }
75 
78  _type(d.GetType()) { }
79 
82  _type = d.GetType();
83  return *this;
84  }
85 
87  Type GetType() const {
88  return (Type)_type;
89  }
90 
92  static inline bool IsAdaptive(Type type) {
93  return type > TRIANGLES;
94  }
95 
97  bool IsAdaptive() const {
98  return IsAdaptive( this->GetType() );
99  }
100 
103  static inline short GetNumControlVertices( Type t );
104 
106  static inline short GetNumFVarControlVertices( Type t );
107 
110  short GetNumControlVertices() const {
111  return GetNumControlVertices( this->GetType() );
112  }
113 
116  return GetNumFVarControlVertices( this->GetType() );
117  }
118 
120  static short GetRegularPatchSize() { return 16; }
121 
123  static short GetGregoryPatchSize() { return 4; }
124 
126  static short GetGregoryBasisPatchSize() { return 20; }
127 
128 
132 
134  inline bool operator < ( PatchDescriptor const other ) const;
135 
137  inline bool operator == ( PatchDescriptor const other ) const;
138 
139  // debug helper
140  void print() const;
141 
142 private:
143  unsigned int _type;
144 };
145 
147 
148 // Returns the number of control vertices expected for a patch of this type
149 inline short
151  switch (type) {
152  case REGULAR : return GetRegularPatchSize();
153  case LOOP : return 12;
154  case QUADS : return 4;
155  case GREGORY :
156  case GREGORY_BOUNDARY : return GetGregoryPatchSize();
157  case GREGORY_BASIS : return GetGregoryBasisPatchSize();
158  case GREGORY_TRIANGLE : return 18;
159  case TRIANGLES : return 3;
160  case LINES : return 2;
161  case POINTS : return 1;
162  default : return -1;
163  }
164 }
165 
166 // Returns the number of face-varying control vertices expected for a patch of this type
167 inline short
170 }
171 
172 // Allows ordering of patches by type
173 inline bool
175  return (_type < other._type);
176 }
177 
178 // True if the descriptors are identical
179 inline bool
181  return _type == other._type;
182 }
183 
184 
185 
186 } // end namespace Far
187 
188 } // end namespace OPENSUBDIV_VERSION
189 using namespace OPENSUBDIV_VERSION;
190 
191 } // end namespace OpenSubdiv
192 
193 #endif /* OPENSUBDIV3_FAR_PATCH_DESCRIPTOR_H */
regular B-Spline patch for the Catmark scheme
static short GetGregoryPatchSize()
Number of control vertices of Gregory (and Gregory Boundary) Patches in table.
regular triangular patch for the Loop scheme
Vtr::ConstArray< PatchDescriptor > ConstPatchDescriptorArray
static short GetGregoryBasisPatchSize()
Number of control vertices of Gregory patch basis (20)
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition: types.h:37
static bool IsAdaptive(Type type)
Returns true if the type is an adaptive (non-linear) patch.
Type GetType() const
Returns the type of the patch.
static Vtr::ConstArray< PatchDescriptor > GetAdaptivePatchDescriptors(Sdc::SchemeType type)
Returns a vector of all the legal patch descriptors for the given adaptive subdivision scheme.
bool IsAdaptive() const
Returns true if the type is an adaptive patch.
short GetNumControlVertices() const
Returns the number of control vertices expected for a patch of the type described.
static short GetRegularPatchSize()
Number of control vertices of Regular Patches in table.
PatchDescriptor(PatchDescriptor const &d)
Copy Constructor.
PatchDescriptor & operator=(PatchDescriptor const &d)
Assignment operator.
bool operator<(PatchDescriptor const other) const
Allows ordering of patches by type.
bool operator==(PatchDescriptor const other) const
True if the descriptors are identical.