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