All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sparseSelector.h
Go to the documentation of this file.
1 //
2 // Copyright 2014 DreamWorks Animation LLC.
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 #ifndef VTR_SPARSE_SELECTOR_H
25 #define VTR_SPARSE_SELECTOR_H
26 
27 #include "../version.h"
28 
29 #include "../vtr/types.h"
30 #include "../vtr/refinement.h"
31 
32 #include <vector>
33 
34 namespace OpenSubdiv {
35 namespace OPENSUBDIV_VERSION {
36 
37 namespace Vtr {
38 
39 class Refinement;
40 
41 //
42 // SparseSelector:
43 // This is experimental at present -- just keeping all of the functionality related to sparse
44 // refinment out of Refinement for now until it matures.
45 //
46 // Expected usage is as follows:
47 //
48 // SparseSelector selector(refinement);
49 //
50 // selector.selectFace(i);
51 // selector.selectFace(j);
52 // ...
53 //
54 // // To be later followed by:
55 // refinement.refine(usingSparseSelectionOptions);
56 //
57 // Since it is expected this will be protected or integrated elsewhere into another Vtr class --
58 // which will be similarly protected -- all methods intentionally begin with lower case.
59 //
61 
62 public:
63  SparseSelector(Refinement& refine) : _refine(&refine), _prevRefine(0), _selected(false) { }
65 
66  //
67  // A previous refinement may be used to indicate whether components are fully defined or
68  // not -- note since optional it is specified/returned by pointer rather than reference
69  // (could make these both ptr for consistency...).
70  //
71  // It is (increasingly) possible that this property ends up in the tags for the parent level,
72  // in which case this refinement that generated the parent will not be necessary
73  //
74  void setRefinement(Refinement& refine) { _refine = &refine; }
75  Refinement& getRefinement() const { return *_refine; }
76 
77  void setPreviousRefinement(Refinement const* refine) { _prevRefine = refine; }
78  Refinement const* getPreviousRefinement() const { return _prevRefine; }
79 
80  //
81  // Methods for selecting (and marking) components for refinement. All component indices
82  // refer to components in the parent:
83  //
84  void selectVertex(Index pVertex);
85  void selectEdge( Index pEdge);
86  void selectFace( Index pFace);
87 
88  // Mark all incident faces of a vertex -- common in the original feature-adaptive scheme
89  // to warrant inclusion, but may not be necessary if it is switch to being face-driven
90  void selectVertexFaces(Index pVertex);
91 
92  //
93  // Useful queries during or after selection:
94  //
95  bool isSelectionEmpty() const { return !_selected; }
96 
97  bool isVertexIncomplete(Index pVertex) const {
98  // A parent of this refinement was child of the previous refinement:
99  return _prevRefine && _prevRefine->_childVertexTag[pVertex]._incomplete;
100  }
101 
102 private:
103  SparseSelector() { }
104 
105  bool wasVertexSelected(Index pVertex) const { return _refine->_parentVertexTag[pVertex]._selected; }
106  bool wasEdgeSelected( Index pEdge) const { return _refine->_parentEdgeTag[pEdge]._selected; }
107  bool wasFaceSelected( Index pFace) const { return _refine->_parentFaceTag[pFace]._selected; }
108 
109  void markVertexSelected(Index pVertex) const { _refine->_parentVertexTag[pVertex]._selected = true; }
110  void markEdgeSelected( Index pEdge) const { _refine->_parentEdgeTag[pEdge]._selected = true; }
111  void markFaceSelected( Index pFace) const { _refine->_parentFaceTag[pFace]._selected = true; }
112 
113  void markSelection();
114 
115 private:
116  Refinement* _refine;
117  Refinement const* _prevRefine;
118  bool _selected;
119 };
120 
121 } // end namespace Vtr
122 
123 } // end namespace OPENSUBDIV_VERSION
124 using namespace OPENSUBDIV_VERSION;
125 } // end namespace OpenSubdiv
126 
127 #endif /* VTR_SPARSE_SELECTOR_H */
128 
void setPreviousRefinement(Refinement const *refine)