All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
creaseEdit.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 HBRCREASEEDIT_H
26 #define HBRCREASEEDIT_H
27 
28 #include "../version.h"
29 
30 namespace OpenSubdiv {
31 namespace OPENSUBDIV_VERSION {
32 
33 template <class T> class HbrCreaseEdit;
34 
35 template <class T>
36 std::ostream& operator<<(std::ostream& out, const HbrCreaseEdit<T>& path) {
37  out << "edge 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.edgeid) << "), sharpness = " << path.sharpness;
42 }
43 
44 template <class T>
45 class HbrCreaseEdit : public HbrHierarchicalEdit<T> {
46 
47 public:
48 
49  HbrCreaseEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, unsigned char _edgeid, typename HbrHierarchicalEdit<T>::Operation _op, float _sharpness)
50  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), edgeid(_edgeid), op(_op), sharpness(_sharpness) {
51  }
52 
53  HbrCreaseEdit(int _faceid, int _nsubfaces, int *_subfaces, int _edgeid, typename HbrHierarchicalEdit<T>::Operation _op, float _sharpness)
54  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), edgeid(static_cast<unsigned char>(_edgeid)), op(_op), sharpness(_sharpness) {
55  }
56 
57  virtual ~HbrCreaseEdit() {}
58 
59  friend std::ostream& operator<< <T> (std::ostream& out, const HbrCreaseEdit<T>& path);
60 
61  virtual void ApplyEditToFace(HbrFace<T>* face) {
63  // Modify edge sharpness
64  float sharp=0.0f;
65  if (op == HbrHierarchicalEdit<T>::Set) {
66  sharp = sharpness;
67  } else if (op == HbrHierarchicalEdit<T>::Add) {
68  sharp = face->GetEdge(edgeid)->GetSharpness() + sharpness;
69  } else if (op == HbrHierarchicalEdit<T>::Subtract) {
70  sharp = face->GetEdge(edgeid)->GetSharpness() - sharpness;
71  }
72  if (sharp < HbrHalfedge<T>::k_Smooth)
76  // We have to make sure the neighbor of the edge exists at
77  // this point. Otherwise, if it comes into being late, it
78  // will clobber the overriden sharpness and we will lose
79  // the edit.
80  face->GetEdge(edgeid)->GuaranteeNeighbor();
81  face->GetEdge(edgeid)->SetSharpness(sharp);
82  }
83  }
84 
85 private:
86  // ID of the edge (you can think of this also as the id of the
87  // origin vertex of the two-vertex length edge)
88  const unsigned char edgeid;
90  // sharpness of the edge edit
91  const float sharpness;
92 };
93 
94 
95 } // end namespace OPENSUBDIV_VERSION
96 using namespace OPENSUBDIV_VERSION;
97 
98 } // end namespace OpenSubdiv
99 
100 #endif /* HBRCREASEEDIT_H */
101 
HbrHalfedge< T > * GetEdge(int index) const
Definition: face.h:718
HbrCreaseEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, unsigned char _edgeid, typename HbrHierarchicalEdit< T >::Operation _op, float _sharpness)
Definition: creaseEdit.h:49
HbrCreaseEdit(int _faceid, int _nsubfaces, int *_subfaces, int _edgeid, typename HbrHierarchicalEdit< T >::Operation _op, float _sharpness)
Definition: creaseEdit.h:53
virtual void ApplyEditToFace(HbrFace< T > *face)
Definition: creaseEdit.h:61