All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
faceEdit.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 HBRFACEEDIT_H
26 #define HBRFACEEDIT_H
27 
28 #include "../hbr/hierarchicalEdit.h"
29 
30 #include "../version.h"
31 
32 namespace OpenSubdiv {
33 namespace OPENSUBDIV_VERSION {
34 
35 template <class T> class HbrFaceEdit;
36 
37 template <class T>
38 std::ostream& operator<<(std::ostream& out, const HbrFaceEdit<T>& path) {
39  out << "face path = (" << path.faceid << ' ';
40  for (int i = 0; i < path.nsubfaces; ++i) {
41  out << static_cast<int>(path.subfaces[i]) << ' ';
42  }
43  return out << ")";
44 }
45 
46 template <class T>
47 class HbrFaceEdit : public HbrHierarchicalEdit<T> {
48 
49 public:
50 
51  HbrFaceEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, int _index, int _width, typename HbrHierarchicalEdit<T>::Operation _op, float *_edit)
52  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), index(_index), width(_width), op(_op) {
53  edit = new float[width];
54  memcpy(edit, _edit, width * sizeof(float));
55  }
56 
57  HbrFaceEdit(int _faceid, int _nsubfaces, int *_subfaces, int _index, int _width, typename HbrHierarchicalEdit<T>::Operation _op, float *_edit)
58  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), index(_index), width(_width), op(_op) {
59  edit = new float[width];
60  memcpy(edit, _edit, width * sizeof(float));
61  }
62 
63 #ifdef PRMAN
64  HbrFaceEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, int _index, int _width, typename HbrHierarchicalEdit<T>::Operation _op, RtToken _edit)
65  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), index(_index), width(_width), op(_op) {
66  edit = new float[width];
67  RtString* sedit = (RtString*) edit;
68  *sedit = _edit;
69  }
70 
71  HbrFaceEdit(int _faceid, int _nsubfaces, int *_subfaces, int _index, int _width, typename HbrHierarchicalEdit<T>::Operation _op, RtToken _edit)
72  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), index(_index), width(_width), op(_op) {
73  edit = new float[width];
74  RtString* sedit = (RtString*) edit;
75  *sedit = _edit;
76  }
77 #endif
78 
79  virtual ~HbrFaceEdit() {
80  delete[] edit;
81  }
82 
83  friend std::ostream& operator<< <T> (std::ostream& out, const HbrFaceEdit<T>& path);
84 
85  // Return index of variable this edit applies to
86  int GetIndex() const { return index; }
87 
88  // Return width of the variable
89  int GetWidth() const { return width; }
90 
91  // Get the numerical value of the edit
92  const float* GetEdit() const { return edit; }
93 
94  // Get the type of operation
95  typename HbrHierarchicalEdit<T>::Operation GetOperation() const { return op; }
96 
97  virtual void ApplyEditToFace(HbrFace<T>* face) {
99 
100  int oldUniformIndex = face->GetUniformIndex();
101 
102  // Any face below level 0 needs a new uniform index
103  if (face->GetDepth() > 0) {
104  face->SetUniformIndex(face->GetMesh()->NewUniformIndex());
105  }
106 
107  // Apply edit
108  face->GetVertex(0)->GetData().ApplyFaceEdit(oldUniformIndex, face->GetUniformIndex(), *const_cast<const HbrFaceEdit<T>*>(this));
109  }
110  }
111 
112 private:
113  int index;
114  int width;
116  float* edit;
117 };
118 
119 
120 } // end namespace OPENSUBDIV_VERSION
121 using namespace OPENSUBDIV_VERSION;
122 
123 } // end namespace OpenSubdiv
124 
125 #endif /* HBRFACEEDIT_H */
126 
virtual void ApplyEditToFace(HbrFace< T > *face)
Definition: faceEdit.h:97
HbrFaceEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, int _index, int _width, typename HbrHierarchicalEdit< T >::Operation _op, float *_edit)
Definition: faceEdit.h:51
HbrHierarchicalEdit< T >::Operation GetOperation() const
Definition: faceEdit.h:95
HbrMesh< T > * GetMesh() const
Definition: face.h:127
HbrVertex< T > * GetVertex(int index) const
Definition: face.h:730
HbrFaceEdit(int _faceid, int _nsubfaces, int *_subfaces, int _index, int _width, typename HbrHierarchicalEdit< T >::Operation _op, float *_edit)
Definition: faceEdit.h:57