Lagrange
Loading...
Searching...
No Matches
SweepOptions.h
1/*
2 * Copyright 2025 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/internal/constants.h>
15#include <lagrange/utils/assert.h>
16
17#include <Eigen/Geometry>
18
19#include <array>
20#include <functional>
21#include <vector>
22
23namespace lagrange::primitive {
24
27
38template <typename Scalar>
40{
41public:
42 using Point = Eigen::Matrix<Scalar, 1, 3>;
43 using Frame = Eigen::Matrix<Scalar, 3, 3>;
44 using Transform = Eigen::Transform<Scalar, 3, Eigen::AffineCompact>;
45
46public:
56 linear_sweep(const Point& from, const Point& to, bool follow_tangent = true);
57
80 const Point& p,
81 const Point& axis,
82 Scalar angle = static_cast<Scalar>(2 * lagrange::internal::pi),
83 bool follow_tangent = true);
84
85public:
91 std::vector<Transform> sample_transforms() const;
92
100 Transform sample_transform(Scalar t) const;
101
107 std::vector<Scalar> sample_offsets() const;
108
116 Scalar sample_offset(Scalar t) const;
117
128 void set_pivot(const Point& pivot) { m_pivot = pivot; }
129
135 const Point& get_pivot() const { return m_pivot; }
136
148 void set_normalization(const Transform& normalization) { m_normalization = normalization; }
149
155 const Transform& get_normalization() const { return m_normalization; }
156
165 void set_num_samples(size_t num_samples)
166 {
167 la_runtime_assert(num_samples >= 2, "At least 2 samples are required.");
168 m_num_samples = num_samples;
169 }
170
176 size_t get_num_samples() const { return m_num_samples; }
177
188 void set_periodic(bool periodic) { m_periodic = periodic; }
189
195 bool is_periodic() const { return m_periodic; }
196
204 void set_domain(std::array<Scalar, 2> domain)
205 {
207 domain[0] < domain[1],
208 "Invalid domain: the end value must be greater than the start value.");
209 m_domain = std::move(domain);
210 }
211
217 const std::array<Scalar, 2>& get_domain() const { return m_domain; }
218
227 bool is_closed() const
228 {
229 return is_periodic() && std::abs(m_domain[1] - m_domain[0] - 1) < static_cast<Scalar>(1e-6);
230 }
231
237 void set_position_function(std::function<Point(Scalar)> fn) { m_position_fn = std::move(fn); }
238
244 bool has_positions() const { return bool(m_position_fn); }
245
255 void set_frame_function(std::function<Frame(Scalar)> fn) { m_frame_fn = std::move(fn); }
256
262 bool has_frames() const { return bool(m_frame_fn); }
263
272 void set_twist_function(std::function<Scalar(Scalar)> fn) { m_twist_fn = std::move(fn); }
273
279 bool has_twists() const { return bool(m_twist_fn); }
280
289 void set_taper_function(std::function<Scalar(Scalar)> fn) { m_taper_fn = std::move(fn); }
290
296 bool has_tapers() const { return bool(m_taper_fn); }
297
303 void set_offset_function(std::function<Scalar(Scalar)> fn) { m_offset_fn = std::move(fn); }
304
310 bool has_offsets() const { return bool(m_offset_fn); }
311
312protected:
314 Point m_pivot = Point::Zero();
316 Transform m_normalization = Transform::Identity();
318 size_t m_num_samples = 16;
320 bool m_periodic = false;
322 std::array<Scalar, 2> m_domain = {0, 1};
323
325 std::function<Point(Scalar)> m_position_fn;
327 std::function<Frame(Scalar)> m_frame_fn;
329 std::function<Scalar(Scalar)> m_twist_fn;
331 std::function<Scalar(Scalar)> m_taper_fn;
333 std::function<Scalar(Scalar)> m_offset_fn;
334};
335
337
338} // namespace lagrange::primitive
Configuration class for sweep operations on 3D geometry.
Definition SweepOptions.h:40
bool has_tapers() const
Checks if a taper function has been set.
Definition SweepOptions.h:296
std::function< Scalar(Scalar)> m_twist_fn
Function defining twist angles along the sweep path.
Definition SweepOptions.h:329
Transform sample_transform(Scalar t) const
Samples the transformation matrix at a specific parameter t.
Definition SweepOptions.cpp:68
const Point & get_pivot() const
Gets the current pivot point.
Definition SweepOptions.h:135
void set_twist_function(std::function< Scalar(Scalar)> fn)
Sets the twist function that defines rotation around the sweep path.
Definition SweepOptions.h:272
bool has_twists() const
Checks if a twist function has been set.
Definition SweepOptions.h:279
size_t get_num_samples() const
Gets the current number of samples.
Definition SweepOptions.h:176
void set_periodic(bool periodic)
Sets whether the sweep should be treated as periodic.
Definition SweepOptions.h:188
void set_offset_function(std::function< Scalar(Scalar)> fn)
Sets the offset function that defines offsets along the sweep path.
Definition SweepOptions.h:303
static SweepOptions< Scalar > linear_sweep(const Point &from, const Point &to, bool follow_tangent=true)
Creates a linear sweep configuration from one point to another.
Definition SweepOptions.cpp:129
std::function< Scalar(Scalar)> m_taper_fn
Function defining taper scale factors along the sweep path.
Definition SweepOptions.h:331
void set_normalization(const Transform &normalization)
Sets the normalization transformation applied to the sweep.
Definition SweepOptions.h:148
bool has_offsets() const
Checks if an offset function has been set.
Definition SweepOptions.h:310
bool has_frames() const
Checks if a frame function has been set.
Definition SweepOptions.h:262
std::function< Scalar(Scalar)> m_offset_fn
Function defining offsets along the sweep path.
Definition SweepOptions.h:333
std::function< Point(Scalar)> m_position_fn
Function defining positions along the sweep path.
Definition SweepOptions.h:325
void set_frame_function(std::function< Frame(Scalar)> fn)
Sets the frame function that defines orientation along the sweep path.
Definition SweepOptions.h:255
void set_num_samples(size_t num_samples)
Sets the number of samples to use along the sweep path.
Definition SweepOptions.h:165
bool is_periodic() const
Checks if the sweep is configured as periodic.
Definition SweepOptions.h:195
bool is_closed() const
Checks if the sweep is closed.
Definition SweepOptions.h:227
size_t m_num_samples
The number of samples along the sweep path.
Definition SweepOptions.h:318
std::function< Frame(Scalar)> m_frame_fn
Function defining frame orientations along the sweep path.
Definition SweepOptions.h:327
static SweepOptions< Scalar > circular_sweep(const Point &p, const Point &axis, Scalar angle=static_cast< Scalar >(2 *lagrange::internal::pi), bool follow_tangent=true)
Creates a circular sweep configuration around a specified axis.
Definition SweepOptions.cpp:149
bool m_periodic
Whether the sweep is periodic (closed loop)
Definition SweepOptions.h:320
std::vector< Scalar > sample_offsets() const
Samples offset values along the sweep path.
Definition SweepOptions.cpp:100
bool has_positions() const
Checks if a position function has been set.
Definition SweepOptions.h:244
const std::array< Scalar, 2 > & get_domain() const
Gets the current parameter domain for sampling transformations.
Definition SweepOptions.h:217
void set_domain(std::array< Scalar, 2 > domain)
Sets the parameter domain for sampling transformations.
Definition SweepOptions.h:204
void set_pivot(const Point &pivot)
Sets the pivot point for the sweep transformation.
Definition SweepOptions.h:128
const Transform & get_normalization() const
Gets the current normalization transformation.
Definition SweepOptions.h:155
void set_position_function(std::function< Point(Scalar)> fn)
Sets the position function that defines the sweep path.
Definition SweepOptions.h:237
Transform m_normalization
The normalization transformation applied to the sweep.
Definition SweepOptions.h:316
Scalar sample_offset(Scalar t) const
Samples the offset value at a specific parameter t.
Definition SweepOptions.cpp:121
std::vector< Transform > sample_transforms() const
Samples transformation matrices along the sweep path.
Definition SweepOptions.cpp:26
std::array< Scalar, 2 > m_domain
The parameter domain for sampling transformations.
Definition SweepOptions.h:322
Point m_pivot
The pivot point for sweep transformations.
Definition SweepOptions.h:314
void set_taper_function(std::function< Scalar(Scalar)> fn)
Sets the taper function that defines scaling along the sweep path.
Definition SweepOptions.h:289
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
#define la_runtime_assert(...)
Runtime assertion check.
Definition assert.h:174