OpenSubdiv
Loading...
Searching...
No Matches
sparseSelector.h
Go to the documentation of this file.
1//
2// Copyright 2014 DreamWorks Animation LLC.
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7#ifndef OPENSUBDIV3_VTR_SPARSE_SELECTOR_H
8#define OPENSUBDIV3_VTR_SPARSE_SELECTOR_H
9
10#include "../version.h"
11
12#include "../vtr/types.h"
13#include "../vtr/refinement.h"
14
15#include <vector>
16
17namespace OpenSubdiv {
18namespace OPENSUBDIV_VERSION {
19
20namespace Vtr {
21namespace internal {
22
23//
24// SparseSelector:
25// Class supporting "selection" of components in a Level for sparse Refinement.
26// The term "selection" here implies interest in the limit for that component, i.e.
27// the limit point for a selected vertex, the limit patch for a face, etc. So this
28// class is responsible for ensuring that all neighboring components required to
29// support the limit of those selected are included in the refinement.
30//
31// This class is associated with (and constructed given) a Refinement and its role
32// is to initialize that Refinement instance for eventual sparse refinement. So it
33// is a friend of and expected to modify the Refinement as part of the selection.
34// Given its simplicity and scope it may be worth nesting it in Vtr::Refinement.
35//
36// While all three component types -- vertices, edges and faces -- can be selected,
37// only selection of faces is currently used and actively supported as part of the
38// feature-adaptive refinement.
39//
40class SparseSelector {
41
42public:
43 SparseSelector(Refinement& refine) : _refine(&refine), _selected(false) { }
44 ~SparseSelector() { }
45
46 void setRefinement(Refinement& refine) { _refine = &refine; }
47 Refinement& getRefinement() const { return *_refine; }
48
49 bool isSelectionEmpty() const { return !_selected; }
50
51 //
52 // Methods for selecting (and marking) components for refinement. All component indices
53 // refer to components in the parent:
54 //
55 void selectVertex(Index pVertex);
56 void selectEdge( Index pEdge);
57 void selectFace( Index pFace);
58
59private:
60 SparseSelector() : _refine(0), _selected(false) { }
61
62 bool wasVertexSelected(Index pVertex) const { return _refine->getParentVertexSparseTag(pVertex)._selected; }
63 bool wasEdgeSelected( Index pEdge) const { return _refine->getParentEdgeSparseTag(pEdge)._selected; }
64 bool wasFaceSelected( Index pFace) const { return _refine->getParentFaceSparseTag(pFace)._selected; }
65
66 void markVertexSelected(Index pVertex) const { _refine->getParentVertexSparseTag(pVertex)._selected = true; }
67 void markEdgeSelected( Index pEdge) const { _refine->getParentEdgeSparseTag(pEdge)._selected = true; }
68 void markFaceSelected( Index pFace) const { _refine->getParentFaceSparseTag(pFace)._selected = true; }
69
70 void initializeSelection();
71
72private:
73 Refinement* _refine;
74 bool _selected;
75};
76
77} // end namespace internal
78} // end namespace Vtr
79
80} // end namespace OPENSUBDIV_VERSION
81using namespace OPENSUBDIV_VERSION;
82} // end namespace OpenSubdiv
83
84#endif /* OPENSUBDIV3_VTR_SPARSE_SELECTOR_H */