Loading...
Searching...
No Matches
selection.h
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_SELECTION_H
8#define PXR_IMAGING_HD_SELECTION_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/usd/sdf/path.h"
14#include "pxr/base/gf/vec4f.h"
15#include "pxr/base/vt/array.h"
16
17#include <memory>
18#include <vector>
19#include <unordered_map>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23using HdSelectionSharedPtr = std::shared_ptr<class HdSelection>;
24
36{
37public:
39 enum HighlightMode : uint32_t {
40 HighlightModeSelect = 0, // Active selection
41 HighlightModeLocate, // Rollover selection
42
43 HighlightModeCount
44 };
45
46 HD_API
47 virtual ~HdSelection();
48
50 HD_API
51 void AddRprim(HighlightMode const &mode,
52 SdfPath const &renderIndexPath);
53
54 HD_API
55 void AddInstance(HighlightMode const &mode,
56 SdfPath const &renderIndexPath,
57 VtIntArray const &instanceIndex=VtIntArray());
58
59 HD_API
60 void AddElements(HighlightMode const &mode,
61 SdfPath const &renderIndexPath,
62 VtIntArray const &elementIndices);
63
64 HD_API
65 void AddEdges(HighlightMode const &mode,
66 SdfPath const &renderIndexPath,
67 VtIntArray const &edgeIndices);
68
69 HD_API
70 void AddPoints(HighlightMode const &mode,
71 SdfPath const &renderIndexPath,
72 VtIntArray const &pointIndices);
73
74 // Special handling for points: we allow a set of selected point indices to
75 // also specify a color to use for highlighting in the render's working
76 // color space.
77 HD_API
78 void AddPoints(HighlightMode const &mode,
79 SdfPath const &renderIndexPath,
80 VtIntArray const &pointIndices,
81 GfVec4f const &pointColor);
82
83 // XXX: Ideally, this should be per instance, if we want to support
84 // selection of subprims (faces/edges/points) per instance of an rprim.
85 // By making this per rprim, all selected instances of the rprim will share
86 // the same subprim highlighting.
87 struct PrimSelectionState {
88 PrimSelectionState() : fullySelected(false) {}
89
90 bool fullySelected;
91 // Use a vector of VtIntArray to avoid copying the indices data.
92 // This way, we support multiple Add<Subprim> operations without
93 // having to consolidate the indices each time.
94 std::vector<VtIntArray> instanceIndices;
95 std::vector<VtIntArray> elementIndices;
96 std::vector<VtIntArray> edgeIndices;
97 std::vector<VtIntArray> pointIndices;
98 std::vector<int> pointColorIndices;
99 };
100
102
103 // Returns a pointer to the selection state for the rprim path if selected.
104 // Returns nullptr otherwise.
105 HD_API
106 PrimSelectionState const *
108 SdfPath const &renderIndexPath) const;
109
110 // Returns the selected rprim render index paths for all the selection
111 // modes. The vector returned may contain duplicates.
112 HD_API
113 SdfPathVector
114 GetAllSelectedPrimPaths() const;
115
116 // Returns the selected rprim render index paths for the given mode.
117 HD_API
118 SdfPathVector
119 GetSelectedPrimPaths(HighlightMode const &mode) const;
120
121 HD_API
122 std::vector<GfVec4f> const& GetSelectedPointColors() const;
123
124 // Returns true if nothing is selected.
125 HD_API
126 bool IsEmpty() const;
127
128 HD_API
129 static
130 HdSelectionSharedPtr Merge(
131 HdSelectionSharedPtr const &,
132 HdSelectionSharedPtr const &);
133
134private:
135 void _AddPoints(HighlightMode const &mode,
136 SdfPath const &renderIndexPath,
137 VtIntArray const &pointIndices,
138 int pointColorIndex);
139
140 void _GetSelectionPrimPathsForMode(HighlightMode const &mode,
141 SdfPathVector *paths) const;
142
143protected:
144 using _PrimSelectionStateMap =
145 std::unordered_map<SdfPath, PrimSelectionState, SdfPath::Hash>;
146 // Keep track of selection per selection mode.
147 _PrimSelectionStateMap _selMap[HighlightModeCount];
148
149 // Track all colors used for point selection highlighting.
150 std::vector<GfVec4f> _selectedPointColors;
151};
152
153PXR_NAMESPACE_CLOSE_SCOPE
154
155#endif //PXR_IMAGING_HD_SELECTION_H
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
HdSelection holds a collection of selected items per selection mode.
Definition: selection.h:36
HD_API void AddRprim(HighlightMode const &mode, SdfPath const &renderIndexPath)
---------------------— Population API -----------------------------—
HD_API PrimSelectionState const * GetPrimSelectionState(HighlightMode const &mode, SdfPath const &renderIndexPath) const
-------------------------— Query API ------------------------------—
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:39
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274