NDEVR
API Documentation
Selector.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: Selector
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Model.h>
34#include <NDEVR/Material.h>
35#include <NDEVR/SnapsManager.h>
36#include <NDEVR/ModelIterator.h>
37#include <NDEVR/DesignSelection.h>
38#include <NDEVR/SelectionArea.h>
39#include <functional>
40
41namespace NDEVR
42{
43 enum class PrimitiveMode;
44 struct GeometryVertices;
45
51 class NDEVR_DESIGN_API SelectionInfo final : public ModelIterator
52 {
53 public:
88
91
93 void clear();
94
97
101 ParseResult process(Model& model) override;
102
106 ParseResult postProcess(Model& model) override;
107
112 ParseResult process(Model& model, Material& mat) override;
113
118 ParseResult process(Model& model, Geometry& geo) override;
119
126 bool processGeometry(const Model& model, const Geometry& geo, PrimitiveProperty primitive_property, UUID selection_id);
127
131 fltp08 screenClosestDistanceSqr(bool outer_bound) const;
132
137
143 void setNearestGeometry(const Geometry& geo, PrimitiveMode primitive_mode, uint04 index, uint04 vertex);
144
150 //returns true if recommended adjust line
151 bool setNearestScreenPosition(PrimitiveMode mode, const Vertex<3, fltp08>& screen_point, fltp08 screen_distance);
152
157
161 void setNearestModel(PrimitiveMode mode, const Model& model);
162
166 void setNearestMaterial(PrimitiveMode mode, const UUID& material);
167
171 void setNearestLayer(PrimitiveMode mode, const UUID& layer);
172
177
181 bool validModelSelection(const Model& model) const;
182
185 void setAllowSolidInteraction(bool allow_solid_intersection) { m_allow_solid_intersection = allow_solid_intersection; }
186
190
194
198
202
207
210
213
217
221
224 UUID uuid() const { return m_id; }
225
228 bool operator==(const SelectionInfo&) const { return false; }
229
233
237
253 UUID current_model = Constant<UUID>::Invalid;
254 UUID camera = Constant<UUID>::Invalid;
256 bool is_edit = false;
257 bool is_exact = true;
259 bool mask_added = false;
260 bool mask_subtracted = true;
261 std::function<bool(const Model&)> selection_filter;
262 private:
266 struct ProcessStruct
267 {
268 Geometry geo;
269 UUID selection_id;
273 PrimitiveProperty primitive_property;
274 PrimitiveMode primitive_mode;
275 Buffer<uint04> indices;
276 Buffer<bool> selection_mask;
277 fltp04 max_distance;
278 };
279
282 void _processGeometryNoTree(ProcessStruct& geo);
283
286 void _processGeometryWithTree(ProcessStruct& geo);
287
291 bool _doesIntersect(const Model& model) const;
292
296 bool _processLineSelection(ProcessStruct& pstruct);
297
302 bool _processLineSelection(uint04 current_index, ProcessStruct& pstruct);
303
307 bool _processPointSelection(ProcessStruct& pstruct);
308
313 bool _processPointSelection(uint04 current_index, ProcessStruct& pstruct);
314 protected:
321 };
322}
323
324
325
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:54
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A simple structure for storing a collection of data.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
A class to easily iterate each line segment over a Geometry of lines.
Definition Geometry.h:2599
Class: LineSegment.
Definition Line.hpp:52
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
ParseResult
The result returned by process functions to control iteration flow.
ModelIterator()
Default constructor.
A core class that represents a node on model hierarchy.
Definition Model.h:292
An area of N-dimensional space that is considered selected.
Stores information about the closest model element found during a selection operation,...
Definition Selector.h:59
void update(const SelectionArea< 3, fltp08 > &new_selection, const SelectionArea< 3, fltp08 > &old_selection)
Updates internal state when the selection area changes, adjusting tracked distances and positions rel...
UUID nearest_material
The UUID of the nearest material.
Definition Selector.h:81
uint04 nearest_index
The primitive index of the nearest hit.
Definition Selector.h:84
UUID nearest_geometry
The UUID of the nearest geometry object.
Definition Selector.h:79
ClosestModelInfo()
Constructs a default ClosestModelInfo with invalid/default values.
void clear()
Resets all tracked closest-model data to default/invalid values.
fltp08 screen_distance
The screen-space distance to the nearest hit.
Definition Selector.h:83
Vertex< 3, fltp08 > screen_location
The screen-space position of the nearest hit.
Definition Selector.h:78
UUID nearest_layer
The UUID of the nearest layer.
Definition Selector.h:82
Matrix< fltp08 > geometry_transform
The world transform of the nearest geometry.
Definition Selector.h:77
void setMaxDistance(fltp08 distance)
Sets the maximum screen-space distance threshold for considering a hit.
uint04 nearest_vertex
The vertex index of the nearest hit.
Definition Selector.h:85
UUID nearest_model
The UUID of the nearest model object.
Definition Selector.h:80
bool is_smooth
Whether the nearest hit lies on a smooth (interpolated) surface.
Definition Selector.h:86
Bounds< 3, fltp08 > selectionBounds() const
Returns the bounding box of the current selection area in local coordinates.
Buffer< UUID > grips
Collection of grip point UUIDs associated with the selection.
Definition Selector.h:255
ParseResult process(Model &model, Geometry &geo) override
Processes a model with its associated geometry for selection.
void updateLineEndPoint(PrimitiveMode mode, Vertex< 3, fltp08 > vec)
Updates the endpoint of the selection line for a given primitive mode.
void prepareSelection()
Prepares internal state before beginning a new selection pass.
Vertex< 3, fltp08 > world_nearest_location
The world-space position of the nearest hit.
Definition Selector.h:243
Material override_material
Material used to override rendering of selected objects.
Definition Selector.h:238
bool processGeometry(const Model &model, const Geometry &geo, PrimitiveProperty primitive_property, UUID selection_id)
Evaluates a specific geometry primitive for selection hits.
SelectionArea< 3, fltp08 > last_selection
The previous selection area, used for incremental updates.
Definition Selector.h:240
DesignSelection selection
The resulting design selection produced by this operation.
Definition Selector.h:245
bool is_exact
Whether exact intersection testing is used (vs. bounding-box only).
Definition Selector.h:257
UUID m_id
Unique identifier for this SelectionInfo instance.
Definition Selector.h:319
bool allowSolidInteraction() const
Returns whether solid (filled) geometry intersection testing is allowed.
Definition Selector.h:189
ParseResult process(Model &model) override
Processes a model during iteration, evaluating it for selection.
void setCurrentSelection(const SelectionArea< 3, fltp08 > &new_selection)
Sets the current selection area used for hit testing.
void setNearestLayer(PrimitiveMode mode, const UUID &layer)
Sets the nearest layer UUID for a given primitive mode.
WindingMode selection_winding_mode
The winding mode used for determining enclosed geometry.
Definition Selector.h:249
UUID nearestGeometry(PrimitiveMode mode) const
Returns the UUID of the nearest geometry for a specific primitive mode.
VertexIterator< Vertex< 3, fltp04 > > m_position_iter
Iterator for accessing vertex positions.
Definition Selector.h:315
fltp08 screenClosestDistanceSqr(PrimitiveMode mode) const
Returns the squared screen-space distance to the closest element of a specific primitive mode.
bool mask_added
Whether additive mask mode is active.
Definition Selector.h:259
UUID current_model
The UUID of the model currently being processed.
Definition Selector.h:253
ClosestModelInfo nearest_line
Closest hit info for line primitives.
Definition Selector.h:247
bool use_interaction_flag
Whether to respect the model's interaction flag when selecting.
Definition Selector.h:258
ClosestModelInfo nearest_solid
Closest hit info for solid (triangle/face) primitives.
Definition Selector.h:248
LineSegment< 3, fltp08 > world_selection_line
The selection ray/line in world (screen) space.
Definition Selector.h:242
bool is_edit
Whether this selection is for editing (vs. simple picking).
Definition Selector.h:256
LineIterator< 3, fltp04 > m_line_position_iter
Iterator for accessing line segment positions.
Definition Selector.h:316
void setNearestMaterial(PrimitiveMode mode, const UUID &material)
Sets the nearest material UUID for a given primitive mode.
Bounds< 3, fltp08 > globalSelectionBounds() const
Returns the bounding box of the current selection area in global coordinates.
UUID nearestModel() const
Returns the UUID of the nearest model across all primitive modes.
std::function< bool(const Model &)> selection_filter
Optional filter callback invoked after selection to validate the selected model's parent....
Definition Selector.h:261
void setAllowSolidInteraction(bool allow_solid_intersection)
Sets whether solid (filled) geometry intersection testing is allowed.
Definition Selector.h:185
fltp08 screen_line_bias
Bias added to line selection distances for priority tuning.
Definition Selector.h:252
bool setNearestScreenPosition(PrimitiveMode mode, const Vertex< 3, fltp08 > &screen_point, fltp08 screen_distance)
Sets the nearest screen-space position for a given primitive mode.
Buffer< Model > m_valid_model_stack
Stack of models that passed validation during traversal.
Definition Selector.h:318
ParseResult postProcess(Model &model) override
Post-processes a model after its children have been visited.
void setNearestGeometry(const Geometry &geo, PrimitiveMode primitive_mode, uint04 index, uint04 vertex)
Sets the nearest geometry hit for a given primitive mode.
fltp08 screenClosestDistanceSqr(bool outer_bound) const
Returns the squared screen-space distance to the closest selected element.
void clear()
Resets all selection state, clearing tracked results and selection areas.
fltp08 screen_point_bias
Bias added to point selection distances for priority tuning.
Definition Selector.h:251
SelectionInfo()
Constructs a default SelectionInfo with initial state.
fltp08 min_screen_cutoff_distance
Minimum screen-space distance below which hits are ignored.
Definition Selector.h:250
Dictionary< UUID, EnclosedModelInfo > enclosed_info
Map of model UUIDs to their enclosed selection information.
Definition Selector.h:244
Vertex< 3, fltp08 > nearestScreenLocation() const
Returns the screen-space location of the nearest selection hit.
Buffer< SelectionArea< 3, fltp08 > > selection_masks
Collection of selection mask areas for complex selection shapes.
Definition Selector.h:241
bool operator==(const SelectionInfo &) const
Equality operator.
Definition Selector.h:228
void getEnclosedVertices(GeometryVertices &vertices) const
Populates the given GeometryVertices with all vertices enclosed by the current selection area.
TriangleIterator< 3, fltp04 > m_triangle_position_iter
Iterator for accessing triangle positions.
Definition Selector.h:317
void finishSelection()
Finalizes selection state after a selection pass is complete.
void setNearestModel(PrimitiveMode mode, const Model &model)
Sets the nearest model for a given primitive mode.
UUID camera
The UUID of the camera used for screen-space projection.
Definition Selector.h:254
bool m_allow_solid_intersection
Whether solid geometry intersection testing is enabled.
Definition Selector.h:320
bool validModelSelection(const Model &model) const
Checks whether a model passes the current selection filters and is valid for selection.
void setGeometryTransform(PrimitiveMode mode, const Matrix< fltp08 > &mat)
Sets the geometry transform matrix for a given primitive mode.
Vertex< 3, fltp08 > nearestWorldLocation() const
Returns the world-space location of the nearest selection hit.
UUID uuid() const
Returns the unique identifier of this SelectionInfo instance.
Definition Selector.h:224
void clearLastSelection()
Clears only the most recent selection data, preserving historical state.
bool mask_subtracted
Whether subtractive mask mode is active.
Definition Selector.h:260
ParseResult process(Model &model, Material &mat) override
Processes a model with its associated material for selection.
SelectionArea< 3, fltp08 > current_selection
The current active selection area.
Definition Selector.h:239
ClosestModelInfo nearest_point
Closest hit info for point primitives.
Definition Selector.h:246
A class to easily iterate each triangle over a Geometry of triangles or meshes.
Definition Geometry.h:2737
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Typed vertex iterator providing array-style access to geometry vertex data.
Definition Geometry.h:2566
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
The primary namespace for the NDEVR SDK.
PrimitiveMode
Used with Geometry to describe how vertices and indices are used to form shapes.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
PrimitiveProperty
Describes which rendering property a primitive index buffer corresponds to.
WindingMode
Describes the vertex winding order used to determine front-facing direction of polygons.
A container for storing vertex data associated with geometry, including positions,...