This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
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.
76 HD_API
77 void AddPoints(HighlightMode const &mode,
78 SdfPath const &renderIndexPath,
79 VtIntArray const &pointIndices,
80 GfVec4f const &pointColor);
81
82 // XXX: Ideally, this should be per instance, if we want to support
83 // selection of subprims (faces/edges/points) per instance of an rprim.
84 // By making this per rprim, all selected instances of the rprim will share
85 // the same subprim highlighting.
86 struct PrimSelectionState {
87 PrimSelectionState() : fullySelected(false) {}
88
89 bool fullySelected;
90 // Use a vector of VtIntArray to avoid copying the indices data.
91 // This way, we support multiple Add<Subprim> operations without
92 // having to consolidate the indices each time.
93 std::vector<VtIntArray> instanceIndices;
94 std::vector<VtIntArray> elementIndices;
95 std::vector<VtIntArray> edgeIndices;
96 std::vector<VtIntArray> pointIndices;
97 std::vector<int> pointColorIndices;
98 };
99
101
102 // Returns a pointer to the selection state for the rprim path if selected.
103 // Returns nullptr otherwise.
104 HD_API
105 PrimSelectionState const *
107 SdfPath const &renderIndexPath) const;
108
109 // Returns the selected rprim render index paths for all the selection
110 // modes. The vector returned may contain duplicates.
111 HD_API
112 SdfPathVector
113 GetAllSelectedPrimPaths() const;
114
115 // Returns the selected rprim render index paths for the given mode.
116 HD_API
117 SdfPathVector
118 GetSelectedPrimPaths(HighlightMode const &mode) const;
119
120 HD_API
121 std::vector<GfVec4f> const& GetSelectedPointColors() const;
122
123 // Returns true if nothing is selected.
124 HD_API
125 bool IsEmpty() const;
126
127 HD_API
128 static
129 HdSelectionSharedPtr Merge(
130 HdSelectionSharedPtr const &,
131 HdSelectionSharedPtr const &);
132
133private:
134 void _AddPoints(HighlightMode const &mode,
135 SdfPath const &renderIndexPath,
136 VtIntArray const &pointIndices,
137 int pointColorIndex);
138
139 void _GetSelectionPrimPathsForMode(HighlightMode const &mode,
140 SdfPathVector *paths) const;
141
142protected:
143 using _PrimSelectionStateMap =
144 std::unordered_map<SdfPath, PrimSelectionState, SdfPath::Hash>;
145 // Keep track of selection per selection mode.
146 _PrimSelectionStateMap _selMap[HighlightModeCount];
147
148 // Track all colors used for point selection highlighting.
149 std::vector<GfVec4f> _selectedPointColors;
150};
151
152PXR_NAMESPACE_CLOSE_SCOPE
153
154#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