2#include <NDEVR/DesignObjectLookup.h>
3#include <NDEVR/AngleDefinitions.h>
4#include <NDEVR/BinaryHeap.h>
43 MinHeap<fltp08, LineSegment<3, fltp08>> heap(4);
76 heap.insert(length, inverted_mat * seg);
86 for (
uint04 i = 0; i < heap.size(); i++)
88 original_points.
add(heap.getAll()[i].first[A]);
89 intersection_points.
add(heap.getAll()[i].first[B]);
93 Plane<3, fltp08> p2 = Plane<3, fltp08>::CreateBestFitPlane(intersection_points);
94 Ray<3, fltp08> n0 = p1.normal;
95 Ray<3, fltp08> n1 = p2.normal;
99 if (
dot(n0, n1) < 0.0)
102 auto cos_theta =
dot(n0, n1);
103 double sin_theta = std::sqrt(1 - cos_theta * cos_theta);
107 skew[0][1] = -cross_product[2];
108 skew[0][2] = cross_product[1];
110 skew[1][0] = cross_product[2];
112 skew[1][2] = -cross_product[0];
114 skew[2][0] = -cross_product[1];
115 skew[2][1] = cross_product[0];
119 for (
uint01 i = 0; i < 3; ++i)
121 for (
uint01 j = 0; j < 3; ++j)
122 axis_matrix[i][j] = cross_product[i] * cross_product[j];
126 for (
uint01 i = 0; i < 3; ++i)
128 for (
uint01 j = 0; j < 3; ++j)
129 mat[i][j] = mat[i][j] * cos_theta + sin_theta *
skew[i][j] + (1 - cos_theta) * axis_matrix[i][j];
131 lib_assert(
IsValid(mat),
"Bad matrix");
132 mat = mat.transpose();
133 Ray<3, fltp08> average_fall(0.0);
134 for (
uint04 i = 0; i < heap.size(); i++)
136 average_fall += heap.getAll()[i].first[B] - heap.getAll()[i].first[A];
140 return Matrix<fltp08>::OffsetMatrix(average_fall) * mat;
179 fltp08 d = bounds.
span().dimensionalValue<MAX>() * delta;
180 for (
fltp08 x = bounds[MIN][X]; x < bounds[MAX][X]; x += d)
182 for (
fltp08 y = bounds[MIN][Y]; y < bounds[MAX][Y]; y += d)
198 for (
uint04 i = 0; i < avg.size(); i++)
199 avg[i] = inverted_matrix * avg[i];
214 for (
uint04 i = 0; i < clustered_points.size(); i++)
216 if (clustered_points[i][Z] < lowest_point[Z])
218 lowest_point = clustered_points[i];
246 while(clustered_points.size() > 0)
250 fltp08 d_from_center = distanceSquared(lowest, center);
251 for (
uint04 i = clustered_points.size() - 1;
IsValid(i); i--)
253 if (distanceSquared(clustered_points[i], lowest) < cluster_distance)
255 if (clustered_points[i][Z] == lowest[Z] && distanceSquared(clustered_points[i], center) < d_from_center)
256 lowest = clustered_points[i];
257 clustered_points.removeIndex(i);
260 lowest_points.
add(lowest);
262 return lowest_points;
A specification of upper and lower bounds in N-dimensions.
constexpr t_vertex center() const
Returns the center of the bounds.
constexpr Ray< t_dims, t_type > span() const
The side lengths of these bounds.
The equivelent of std::vector but with a bit more control.
void add(t_type &&object)
Adds object to the end of the buffer.
A core class where all Design Objects including models, materials, and geometries are stored.
Computes gravity-based intersection transforms by casting rays along a gravity vector and finding whe...
Vector< 3, fltp08 > m_gravity_vector
The direction of gravity used for raycasting. Defaults to downward along the Z axis.
fltp08 m_max_fall_height
The maximum distance to cast rays along the gravity vector in each direction from a query point.
static Buffer< Vertex< 3, fltp08 > > FindGravityPoints(const Model &model, fltp08 delta, fltp08 max)
Generates a set of gravity sample points by casting vertical rays through a model's bounding area.
void setup(DesignObjectLookup *lookup, const Matrix< fltp08 > &mat, const Buffer< Vertex< 3, fltp08 > > &points)
Initializes the gravity intersection with the required scene context, transform, and query points.
static Buffer< Vertex< 3, fltp08 > > FilterSamples(fltp08 cluster_distance, Buffer< Vertex< 3, fltp08 > > clustered_points, Vertex< 3, fltp08 > center)
Filters a set of points by iteratively extracting the lowest-Z point and removing nearby neighbors wi...
Matrix< fltp08 > calculateIntersection() const
Calculates an intersection transform by projecting query points along the gravity vector and fitting ...
Buffer< Vertex< 3, fltp08 > > m_query_points
The set of local-space query points to project along the gravity vector.
static Vertex< 3, fltp08 > LowestPoint(const Buffer< Vertex< 3, fltp08 > > &clustered_points)
Finds the vertex with the lowest Z coordinate from a set of points.
DesignObjectLookup * m_lookup
Pointer to the scene lookup used for selection/intersection queries. Not owned by this class.
Matrix< fltp08 > m_current_transform
The transformation matrix applied to query points before performing intersection queries.
constexpr t_type lengthSquared() const
Templated logic for doing matrix multiplication.
void parseAll(const Model &model)
Parses the given model and all of its descendants.
std::function< bool(const Model &)> model_filter
Optional filter predicate for model processing. Returns true to include.
A core class that represents a node on model hierarchy.
Bounds< 3, fltp08 > getBoundsOfVisible() const
Returns the bounding box of all visible descendants.
Matrix< fltp08 > getCompleteTransform() const
Returns the fully composed local-to-global transform matrix for this model.
Logic for a given plane or N-dimensions.
Used to lock a particular variable for reading.
An area of N-dimensional space that is considered selected.
fltp08 screen_distance
The screen-space distance to the nearest hit.
Responsible for turning a user interaction into a selection within a DesignObjectLookup.
bool is_exact
Whether exact intersection testing is used (vs. bounding-box only).
ClosestModelInfo nearest_line
Closest hit info for line primitives.
bool use_interaction_flag
Whether to respect the model's interaction flag when selecting.
ClosestModelInfo nearest_solid
Closest hit info for solid (triangle/face) primitives.
fltp08 min_screen_cutoff_distance
Minimum screen-space distance below which hits are ignored.
Vertex< 3, fltp08 > nearestScreenLocation() const
Returns the screen-space location of the nearest selection hit.
void clearLastSelection()
Clears only the most recent selection data, preserving historical state.
SelectionArea< 3, fltp08 > current_selection
The current active selection area.
ClosestModelInfo nearest_point
Closest hit info for point primitives.
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Buffer< t_value, t_memory_manager > values() const
Returns all elements in the Set as a Buffer.
void add(const t_value &key)
Inserts a value into the Set by const reference.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
constexpr Vector< t_dims, t_norm_type > normalized(Vector< t_dims, t_norm_type > value_if_nan=Constant< Vector< t_dims, t_norm_type > >::Invalid) const
Gets the normalized, or unit length representation of this vector.
A point in N-dimensional space, used primarily for spatial location information.
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
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.
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
Matrix3< g_type > skew(const Vector3< g_type > &v)
Computes the 3x3 skew-symmetric matrix from a 3D vector.
@ allow_interactions
Whether user interactions with this object are allowed.
@ spacial_visible
Whether the object is visible in the 3D spatial view.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.