All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cornerEdit.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 HBRCORNEREDIT_H
26 #define HBRCORNEREDIT_H
27 
28 #include "../version.h"
29 
30 namespace OpenSubdiv {
31 namespace OPENSUBDIV_VERSION {
32 
33 template <class T> class HbrCornerEdit;
34 
35 template <class T>
36 std::ostream& operator<<(std::ostream& out, const HbrCornerEdit<T>& path) {
37  out << "vertex path = (" << path.faceid << ' ';
38  for (int i = 0; i < path.nsubfaces; ++i) {
39  out << static_cast<int>(path.subfaces[i]) << ' ';
40  }
41  return out << static_cast<int>(path.vertexid) << "), sharpness = " << path.sharpness;
42 }
43 
44 template <class T>
45 class HbrCornerEdit : public HbrHierarchicalEdit<T> {
46 
47 public:
48 
49  HbrCornerEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, unsigned char _vertexid, typename HbrHierarchicalEdit<T>::Operation _op, float _sharpness)
50  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), vertexid(_vertexid), op(_op), sharpness(_sharpness) {
51  }
52 
53  HbrCornerEdit(int _faceid, int _nsubfaces, int *_subfaces, int _vertexid, typename HbrHierarchicalEdit<T>::Operation _op, float _sharpness)
54  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), vertexid(static_cast<unsigned char>(_vertexid)), op(_op), sharpness(_sharpness) {
55  }
56 
57  virtual ~HbrCornerEdit() {}
58 
59  friend std::ostream& operator<< <T> (std::ostream& out, const HbrCornerEdit<T>& path);
60 
61  virtual void ApplyEditToFace(HbrFace<T>* face) {
63  // Modify vertex sharpness. Note that we could actually do
64  // this in ApplyEditToVertex as well!
65  float sharp = 0.0f;
66  if (op == HbrHierarchicalEdit<T>::Set) {
67  sharp = sharpness;
68  } else if (op == HbrHierarchicalEdit<T>::Add) {
69  sharp = face->GetVertex(vertexid)->GetSharpness() + sharpness;
70  } else if (op == HbrHierarchicalEdit<T>::Subtract) {
71  sharp = face->GetVertex(vertexid)->GetSharpness() - sharpness;
72  }
73  if (sharp < HbrVertex<T>::k_Smooth) {
74  sharp = HbrVertex<T>::k_Smooth;
75  }
76  if (sharp > HbrVertex<T>::k_InfinitelySharp) {
78  }
79  face->GetVertex(vertexid)->SetSharpness(sharp);
80  }
81  }
82 
83 private:
84  // ID of the edge (you can think of this also as the id of the
85  // origin vertex of the two-vertex length edge)
86  const unsigned char vertexid;
88  // sharpness of the vertex edit
89  const float sharpness;
90 };
91 
92 
93 } // end namespace OPENSUBDIV_VERSION
94 using namespace OPENSUBDIV_VERSION;
95 
96 } // end namespace OpenSubdiv
97 
98 #endif /* HBRCORNEREDIT_H */
99 
virtual void ApplyEditToFace(HbrFace< T > *face)
Definition: cornerEdit.h:61
HbrCornerEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, unsigned char _vertexid, typename HbrHierarchicalEdit< T >::Operation _op, float _sharpness)
Definition: cornerEdit.h:49
HbrCornerEdit(int _faceid, int _nsubfaces, int *_subfaces, int _vertexid, typename HbrHierarchicalEdit< T >::Operation _op, float _sharpness)
Definition: cornerEdit.h:53
HbrVertex< T > * GetVertex(int index) const
Definition: face.h:730