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 // Class supporting "selection" of components in a Level for sparse Refinement.
44 // The term "selection" here implies interest in the limit for that component, i.e.
45 // the limit point for a selected vertex, the limit patch for a face, etc. So this
46 // class is responsible for ensuring that all neighboring components required to
47 // support the limit of those selected are included in the refinement.
48 //
49 // This class is associated with (and constructed given) a Refinement and its role
50 // is to initialize that Refinement instance for eventual sparse refinement. So it
51 // is a friend of and expected to modify the Refinement as part of the selection.
52 // Given its simplicity and scope it may be worth nesting it in Vtr::Refinement.
53 //
54 // While all three component types -- vertices, edges and faces -- can be selected,
55 // only selection of faces is currently used and actively supported as part of the
56 // feature-adaptive refinement.
57 //
59 
60 public:
61  SparseSelector(Refinement& refine) : _refine(&refine), _selected(false) { }
63 
64  void setRefinement(Refinement& refine) { _refine = &refine; }
65  Refinement& getRefinement() const { return *_refine; }
66 
67  bool isSelectionEmpty() const { return !_selected; }
68 
69  //
70  // Methods for selecting (and marking) components for refinement. All component indices
71  // refer to components in the parent:
72  //
73  void selectVertex(Index pVertex);
74  void selectEdge( Index pEdge);
75  void selectFace( Index pFace);
76 
77 private:
78  SparseSelector() : _refine(0), _selected(false) { }
79 
80  bool wasVertexSelected(Index pVertex) const { return _refine->_parentVertexTag[pVertex]._selected; }
81  bool wasEdgeSelected( Index pEdge) const { return _refine->_parentEdgeTag[pEdge]._selected; }
82  bool wasFaceSelected( Index pFace) const { return _refine->_parentFaceTag[pFace]._selected; }
83 
84  void markVertexSelected(Index pVertex) const { _refine->_parentVertexTag[pVertex]._selected = true; }
85  void markEdgeSelected( Index pEdge) const { _refine->_parentEdgeTag[pEdge]._selected = true; }
86  void markFaceSelected( Index pFace) const { _refine->_parentFaceTag[pFace]._selected = true; }
87 
88  void initializeSelection();
89 
90 private:
91  Refinement* _refine;
92  bool _selected;
93 };
94 
95 } // end namespace Vtr
96 
97 } // end namespace OPENSUBDIV_VERSION
98 using namespace OPENSUBDIV_VERSION;
99 } // end namespace OpenSubdiv
100 
101 #endif /* VTR_SPARSE_SELECTOR_H */
102