All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
selection.h
1 //
2 // Copyright 2018 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 #ifndef HD_SELECTION_H
25 #define HD_SELECTION_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/usd/sdf/path.h"
31 #include "pxr/base/gf/vec4f.h"
32 #include "pxr/base/vt/array.h"
33 #include <boost/smart_ptr.hpp>
34 #include <vector>
35 #include <unordered_map>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 class SdfPath;
40 
41 typedef boost::shared_ptr<class HdSelection> HdSelectionSharedPtr;
42 
50 class HdSelection {
51 public:
54  HighlightModeSelect = 0,
55  HighlightModeLocate,
56 
57  HighlightModeCount
58  };
59 
60  HdSelection() = default;
61 
62  HD_API
63  void AddRprim(HighlightMode const& mode,
64  SdfPath const &path);
65 
66  HD_API
67  void AddInstance(HighlightMode const& mode,
68  SdfPath const &path,
69  VtIntArray const &instanceIndex=VtIntArray());
70 
71  HD_API
72  void AddElements(HighlightMode const& mode,
73  SdfPath const &path,
74  VtIntArray const &elementIndices);
75 
76  HD_API
77  void AddEdges(HighlightMode const& mode,
78  SdfPath const &path,
79  VtIntArray const &edgeIndices);
80 
81  HD_API
82  void AddPoints(HighlightMode const& mode,
83  SdfPath const &path,
84  VtIntArray const &pointIndices);
85  // Special handling for points: we allow a set of selected point indices to
86  // also specify a color to use for highlighting.
87  HD_API
88  void AddPoints(HighlightMode const& mode,
89  SdfPath const &path,
90  VtIntArray const &pointIndices,
91  GfVec4f const &pointColor);
92 
93  // XXX: Ideally, this should be per instance, if we want to support
94  // selection of subprims (faces/edges/points) per instance of an rprim.
95  // By making this per rprim, all selected instances of the rprim will share
96  // the same subprim highlighting.
97  struct PrimSelectionState {
98  PrimSelectionState() : fullySelected(false) {}
99  bool fullySelected;
100  // We use a vector of VtIntArray, to avoid any copy of indices data.
101  // This way, we support multiple Add<Subprim> operations, without
102  // having to consolidate the indices each time.
103  std::vector<VtIntArray> instanceIndices;
104  std::vector<VtIntArray> elementIndices;
105  std::vector<VtIntArray> edgeIndices;
106  std::vector<VtIntArray> pointIndices;
107  std::vector<int> pointColorIndices;
108  };
109 
110  HD_API
111  PrimSelectionState const*
112  GetPrimSelectionState(HighlightMode const &mode,
113  SdfPath const &path) const;
114 
115  HD_API
116  SdfPathVector
117  GetSelectedPrimPaths(HighlightMode const &mode) const;
118 
119  HD_API
120  std::vector<GfVec4f> const& GetSelectedPointColors() const;
121 
122 private:
123  HD_API
124  void _AddPoints(HighlightMode const& mode,
125  SdfPath const &path,
126  VtIntArray const &pointIndices,
127  int pointColorIndex);
128 
129 protected:
130  typedef std::unordered_map<SdfPath, PrimSelectionState, SdfPath::Hash>
131  _PrimSelectionStateMap;
132  // Keep track of selection per selection mode.
133  _PrimSelectionStateMap _selMap[HighlightModeCount];
134 
135  // Track all colors used for point selection highlighting.
136  std::vector<GfVec4f> _selectedPointColors;
137 };
138 
139 PXR_NAMESPACE_CLOSE_SCOPE
140 
141 #endif //HD_SELECTION_H
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:53
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
HdSelection holds a collection of selected items per selection mode.
Definition: selection.h:50