All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fvarEdit.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 HBRFVAREDIT_H
26 #define HBRFVAREDIT_H
27 
28 #include "../hbr/hierarchicalEdit.h"
29 #include "../hbr/vertexEdit.h"
30 
31 #include "../version.h"
32 
33 namespace OpenSubdiv {
34 namespace OPENSUBDIV_VERSION {
35 
36 template <class T> class HbrFVarEdit;
37 
38 template <class T>
39 std::ostream& operator<<(std::ostream& out, const HbrFVarEdit<T>& path) {
40  out << "vertex path = (" << path.faceid << ' ';
41  for (int i = 0; i < path.nsubfaces; ++i) {
42  out << static_cast<int>(path.subfaces[i]) << ' ';
43  }
44  return out << static_cast<int>(path.vertexid) << "), edit = (" << path.edit[0] << ',' << path.edit[1] << ',' << path.edit[2] << ')';
45 }
46 
47 template <class T>
48 class HbrFVarEdit : public HbrHierarchicalEdit<T> {
49 
50 public:
51 
52  HbrFVarEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, unsigned char _vertexid, int _index, int _width, int _offset, typename HbrHierarchicalEdit<T>::Operation _op, float *_edit)
53  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), vertexid(_vertexid), index(_index), width(_width), offset(_offset), op(_op) {
54  edit = new float[width];
55  memcpy(edit, _edit, width * sizeof(float));
56  }
57 
58  HbrFVarEdit(int _faceid, int _nsubfaces, int *_subfaces, int _vertexid, int _index, int _width, int _offset, typename HbrHierarchicalEdit<T>::Operation _op, float *_edit)
59  : HbrHierarchicalEdit<T>(_faceid, _nsubfaces, _subfaces), vertexid(_vertexid), index(_index), width(_width), offset(_offset), op(_op) {
60  edit = new float[width];
61  memcpy(edit, _edit, width * sizeof(float));
62  }
63 
64  virtual ~HbrFVarEdit() {
65  delete[] edit;
66  }
67 
68  // Return the vertex id (the last element in the path)
69  unsigned char GetVertexID() const { return vertexid; }
70 
71  friend std::ostream& operator<< <T> (std::ostream& out, const HbrFVarEdit<T>& path);
72 
73  // Return index into the facevarying data
74  int GetIndex() const { return index; }
75 
76  // Return width of the data
77  int GetWidth() const { return width; }
78 
79  // Return offset of the data
80  int GetOffset() const { return offset; }
81 
82  // Get the numerical value of the edit
83  const float* GetEdit() const { return edit; }
84 
85  // Get the type of operation
86  typename HbrHierarchicalEdit<T>::Operation GetOperation() const { return op; }
87 
88  virtual void ApplyEditToFace(HbrFace<T>* face) {
90  // The edit will modify the data and almost certainly
91  // create a discontinuity, so allocate storage for a new
92  // copy of the existing data specific to the face (or use
93  // one that already exists) and modify that
94  HbrFVarData<T> &fvt = face->GetVertex(vertexid)->GetFVarData(face);
95  if (fvt.GetFaceID() != face->GetID()) {
96  // This is the generic fvt, allocate a new copy and edit it
97  HbrFVarData<T> &newfvt = face->GetVertex(vertexid)->NewFVarData(face);
98  newfvt.SetAllData(face->GetMesh()->GetTotalFVarWidth(), fvt.GetData(0));
99  newfvt.ApplyFVarEdit(*const_cast<const HbrFVarEdit<T>*>(this));
100  } else {
101  fvt.ApplyFVarEdit(*const_cast<const HbrFVarEdit<T>*>(this));
102  }
103  }
104  }
105 
106 private:
107  const unsigned char vertexid;
108  const int index;
109  const int width;
110  const int offset;
111  float* edit;
113 };
114 
115 
116 } // end namespace OPENSUBDIV_VERSION
117 using namespace OPENSUBDIV_VERSION;
118 
119 } // end namespace OpenSubdiv
120 
121 #endif /* HBRFVAREDIT_H */
122 
void ApplyFVarEdit(const HbrFVarEdit< T > &edit)
Definition: fvarData.h:176
HbrFVarEdit(int _faceid, int _nsubfaces, int *_subfaces, int _vertexid, int _index, int _width, int _offset, typename HbrHierarchicalEdit< T >::Operation _op, float *_edit)
Definition: fvarEdit.h:58
HbrFVarEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces, unsigned char _vertexid, int _index, int _width, int _offset, typename HbrHierarchicalEdit< T >::Operation _op, float *_edit)
Definition: fvarEdit.h:52
HbrMesh< T > * GetMesh() const
Definition: face.h:127
virtual void ApplyEditToFace(HbrFace< T > *face)
Definition: fvarEdit.h:88
HbrHierarchicalEdit< T >::Operation GetOperation() const
Definition: fvarEdit.h:86
HbrVertex< T > * GetVertex(int index) const
Definition: face.h:730
void SetAllData(int width, const float *values)
Definition: fvarData.h:139
unsigned char GetVertexID() const
Definition: fvarEdit.h:69