EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Transform.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_TRANSFORM_HPP
12#define EBGEOMETRY_TRANSFORM_HPP
13
14// Std includes
15#include <cstddef>
16#include <memory>
17#include <type_traits>
18#include <utility>
19#include <vector>
20
21// Our includes
23#include "EBGeometry_Vec.hpp"
24
25namespace EBGeometry {
26
33template <class T>
34[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
36
44template <class T>
45[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
47
56template <class T>
57[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
58Rotate(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_angle, const size_t a_axis);
59
67template <class T>
68[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
69Scale(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_scale);
70
78template <class T>
79[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
80Offset(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_offset);
81
89template <class T>
90[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
91Annular(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_delta);
92
100template <class T>
101[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
103
112template <class T>
113[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
115 const T a_dist,
116 const size_t a_mollifierSamples = 2);
117
125template <class T>
126[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
128
136template <class T>
137[[nodiscard]] std::shared_ptr<ImplicitFunction<T>>
138Reflect(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const size_t& a_reflectPlane);
139
144template <class T>
146{
147 static_assert(std::is_floating_point_v<T>, "ComplementIF requires a floating-point T");
148
149public:
153 ComplementIF() = delete;
154
159 ComplementIF(const ComplementIF& a_other) noexcept = default;
160
165 ComplementIF(ComplementIF&& a_other) noexcept = default;
166
171 ComplementIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction) noexcept;
172
176 ~ComplementIF() override = default;
177
184 operator=(const ComplementIF& a_other) noexcept = default;
185
192 operator=(ComplementIF&& a_other) noexcept = default;
193
199 [[nodiscard]] T
200 value(const Vec3T<T>& a_point) const noexcept override;
201
202protected:
206 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
207};
208
213template <class T>
215{
216 static_assert(std::is_floating_point_v<T>, "TranslateIF requires a floating-point T");
217
218public:
222 TranslateIF() = delete;
223
228 TranslateIF(const TranslateIF& a_other) noexcept = default;
229
234 TranslateIF(TranslateIF&& a_other) noexcept = default;
235
241 TranslateIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const Vec3T<T>& a_shift) noexcept;
242
246 ~TranslateIF() override = default;
247
254 operator=(const TranslateIF& a_other) noexcept = default;
255
262 operator=(TranslateIF&& a_other) noexcept = default;
263
269 [[nodiscard]] T
270 value(const Vec3T<T>& a_point) const noexcept override;
271
272protected:
276 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
277
282};
283
288template <class T>
289class RotateIF : public ImplicitFunction<T>
290{
291 static_assert(std::is_floating_point_v<T>, "RotateIF requires a floating-point T");
292
293public:
297 RotateIF() = delete;
298
303 RotateIF(const RotateIF& a_other) noexcept = default;
304
309 RotateIF(RotateIF&& a_other) noexcept = default;
310
318 const T a_angle,
319 const size_t a_axis) noexcept;
320
324 ~RotateIF() override = default;
325
331 RotateIF&
332 operator=(const RotateIF& a_other) noexcept = default;
333
339 RotateIF&
340 operator=(RotateIF&& a_other) noexcept = default;
341
347 [[nodiscard]] T
348 value(const Vec3T<T>& a_point) const noexcept override;
349
350protected:
354 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
355
359 size_t m_axis;
360
365
370
375};
376
381template <class T>
382class OffsetIF : public ImplicitFunction<T>
383{
384 static_assert(std::is_floating_point_v<T>, "OffsetIF requires a floating-point T");
385
386public:
390 OffsetIF() = delete;
391
396 OffsetIF(const OffsetIF& a_other) noexcept = default;
397
402 OffsetIF(OffsetIF&& a_other) noexcept = default;
403
409 OffsetIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_offset) noexcept;
410
414 ~OffsetIF() override = default;
415
421 OffsetIF&
422 operator=(const OffsetIF& a_other) noexcept = default;
423
429 OffsetIF&
430 operator=(OffsetIF&& a_other) noexcept = default;
431
437 [[nodiscard]] T
438 value(const Vec3T<T>& a_point) const noexcept override;
439
440protected:
444 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
445
450};
451
456template <class T>
457class ScaleIF : public ImplicitFunction<T>
458{
459 static_assert(std::is_floating_point_v<T>, "ScaleIF requires a floating-point T");
460
461public:
465 ScaleIF() = delete;
466
471 ScaleIF(const ScaleIF& a_other) noexcept = default;
472
477 ScaleIF(ScaleIF&& a_other) noexcept = default;
478
484 ScaleIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_scale) noexcept;
485
489 ~ScaleIF() override = default;
490
496 ScaleIF&
497 operator=(const ScaleIF& a_other) noexcept = default;
498
504 ScaleIF&
505 operator=(ScaleIF&& a_other) noexcept = default;
506
512 [[nodiscard]] T
513 value(const Vec3T<T>& a_point) const noexcept override;
514
515protected:
519 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
520
525};
526
531template <class T>
533{
534 static_assert(std::is_floating_point_v<T>, "AnnularIF requires a floating-point T");
535
536public:
540 AnnularIF() = delete;
541
546 AnnularIF(const AnnularIF& a_other) noexcept = default;
547
552 AnnularIF(AnnularIF&& a_other) noexcept = default;
553
559 AnnularIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const T a_delta) noexcept;
560
564 ~AnnularIF() override = default;
565
571 AnnularIF&
572 operator=(const AnnularIF& a_other) noexcept = default;
573
579 AnnularIF&
580 operator=(AnnularIF&& a_other) noexcept = default;
581
587 [[nodiscard]] T
588 value(const Vec3T<T>& a_point) const noexcept override;
589
590protected:
594 std::shared_ptr<const ImplicitFunction<T>> m_implicitFunction = nullptr;
595
600};
601
610template <class T>
611class BlurIF : public ImplicitFunction<T>
612{
613 static_assert(std::is_floating_point_v<T>, "BlurIF requires a floating-point T");
614
615public:
619 BlurIF() = delete;
620
625 BlurIF(const BlurIF& a_other) noexcept = default;
626
631 BlurIF(BlurIF&& a_other) noexcept = default;
632
640 const T a_blurDistance,
641 const T a_alpha = 0.5) noexcept;
642
647
653 BlurIF&
655
661 BlurIF&
663
669 [[nodiscard]] T
671
676 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
677
682
687};
688
696template <class T>
698{
699 static_assert(std::is_floating_point_v<T>, "MollifyIF requires a floating-point T");
700
701public:
705 MollifyIF() = delete;
706
711 MollifyIF(const MollifyIF& a_other) = default;
712
717 MollifyIF(MollifyIF&& a_other) noexcept = default;
718
727 const std::shared_ptr<ImplicitFunction<T>>& a_mollifier,
728 const T a_maxValue,
729 const size_t a_numPoints) noexcept;
730
734 ~MollifyIF() override = default;
735
741 MollifyIF&
742 operator=(const MollifyIF& a_other) = default;
743
749 MollifyIF&
750 operator=(MollifyIF&& a_other) noexcept = default;
751
757 [[nodiscard]] T
758 value(const Vec3T<T>& a_point) const noexcept override;
759
760protected:
764 std::shared_ptr<ImplicitFunction<T>> m_implicitFunction = nullptr;
765
769 std::shared_ptr<ImplicitFunction<T>> m_mollifier = nullptr;
770
774 std::vector<std::pair<Vec3T<T>, T>> m_sampledMollifier;
775};
776
784template <class T>
786{
787 static_assert(std::is_floating_point_v<T>, "ElongateIF requires a floating-point T");
788
789public:
793 ElongateIF() = delete;
794
799 ElongateIF(const ElongateIF& a_other) noexcept = default;
800
805 ElongateIF(ElongateIF&& a_other) noexcept = default;
806
812 ElongateIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const Vec3T<T>& a_elongation) noexcept;
813
817 ~ElongateIF() override = default;
818
825 operator=(const ElongateIF& a_other) noexcept = default;
826
833 operator=(ElongateIF&& a_other) noexcept = default;
834
840 [[nodiscard]] T
841 value(const Vec3T<T>& a_point) const noexcept override;
842
843protected:
847 std::shared_ptr<const ImplicitFunction<T>> m_implicitFunction = nullptr;
848
853};
854
859template <class T>
861{
862 static_assert(std::is_floating_point_v<T>, "ReflectIF requires a floating-point T");
863
864public:
868 ReflectIF() = delete;
869
874 ReflectIF(const ReflectIF& a_other) noexcept = default;
875
880 ReflectIF(ReflectIF&& a_other) noexcept = default;
881
887 ReflectIF(const std::shared_ptr<ImplicitFunction<T>>& a_implicitFunction, const size_t& a_reflectPlane) noexcept;
888
892 ~ReflectIF() override = default;
893
899 ReflectIF&
900 operator=(const ReflectIF& a_other) noexcept = default;
901
907 ReflectIF&
908 operator=(ReflectIF&& a_other) noexcept = default;
909
915 [[nodiscard]] T
916 value(const Vec3T<T>& a_point) const noexcept override;
917
918protected:
922 std::shared_ptr<const ImplicitFunction<T>> m_implicitFunction = nullptr;
923
928};
929
930} // namespace EBGeometry
931
932#include "EBGeometry_TransformImplem.hpp"
933
934#endif
Abstract base class for representing an implicit function.
Declaration of 2D and 3D point/vector classes with templated precision. Used with DCEL tools.
Annular implicit function. Creates a shell out of the implicit function.
Definition EBGeometry_Transform.hpp:533
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
~AnnularIF() override=default
Destructor.
T m_delta
Shell thickness.
Definition EBGeometry_Transform.hpp:599
AnnularIF()=delete
Disallowed weak construction.
std::shared_ptr< const ImplicitFunction< T > > m_implicitFunction
Original implicit function.
Definition EBGeometry_Transform.hpp:594
AnnularIF & operator=(const AnnularIF &a_other) noexcept=default
Copy assignment operator.
AnnularIF(const AnnularIF &a_other) noexcept=default
Copy constructor.
AnnularIF & operator=(AnnularIF &&a_other) noexcept=default
Move assignment operator.
AnnularIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_delta) noexcept
Full constructor.
AnnularIF(AnnularIF &&a_other) noexcept=default
Move constructor.
Blurred/interpolated implicit function — can be used for smoothing.
Definition EBGeometry_Transform.hpp:612
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
BlurIF(const BlurIF &a_other) noexcept=default
Copy constructor.
T m_blurDistance
Blur distance.
Definition EBGeometry_Transform.hpp:681
BlurIF()=delete
Disallowed weak construction.
BlurIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_blurDistance, const T a_alpha=0.5) noexcept
Full constructor.
BlurIF(BlurIF &&a_other) noexcept=default
Move constructor.
T m_alpha
Alpha factor.
Definition EBGeometry_Transform.hpp:686
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Original implicit function.
Definition EBGeometry_Transform.hpp:676
Complemented implicit function.
Definition EBGeometry_Transform.hpp:146
ComplementIF & operator=(ComplementIF &&a_other) noexcept=default
Move assignment operator.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
ComplementIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction) noexcept
Full constructor.
ComplementIF(ComplementIF &&a_other) noexcept=default
Move constructor.
~ComplementIF() override=default
Destructor (does nothing)
ComplementIF()=delete
No weak construction for this one.
ComplementIF & operator=(const ComplementIF &a_other) noexcept=default
Copy assignment operator.
ComplementIF(const ComplementIF &a_other) noexcept=default
Copy constructor.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Implicit function.
Definition EBGeometry_Transform.hpp:206
Implicit function which is an elongation of another implicit function along each axis.
Definition EBGeometry_Transform.hpp:786
ElongateIF(ElongateIF &&a_other) noexcept=default
Move constructor.
ElongateIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const Vec3T< T > &a_elongation) noexcept
Full constructor.
ElongateIF & operator=(const ElongateIF &a_other) noexcept=default
Copy assignment operator.
Vec3T< T > m_elongation
Elongation.
Definition EBGeometry_Transform.hpp:852
ElongateIF & operator=(ElongateIF &&a_other) noexcept=default
Move assignment operator.
ElongateIF(const ElongateIF &a_other) noexcept=default
Copy constructor.
ElongateIF()=delete
Disallowed weak construction.
~ElongateIF() override=default
Destructor.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
Abstract representation of an implicit function (not necessarily a signed distance function).
Definition EBGeometry_ImplicitFunction.hpp:32
Mollified implicit function.
Definition EBGeometry_Transform.hpp:698
MollifyIF & operator=(MollifyIF &&a_other) noexcept=default
Move assignment operator.
MollifyIF & operator=(const MollifyIF &a_other)=default
Copy assignment operator.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
MollifyIF(MollifyIF &&a_other) noexcept=default
Move constructor.
MollifyIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const std::shared_ptr< ImplicitFunction< T > > &a_mollifier, const T a_maxValue, const size_t a_numPoints) noexcept
Full constructor.
std::vector< std::pair< Vec3T< T >, T > > m_sampledMollifier
Mollifier Weights.
Definition EBGeometry_Transform.hpp:774
~MollifyIF() override=default
Destructor.
MollifyIF()=delete
Disallowed weak construction.
MollifyIF(const MollifyIF &a_other)=default
Copy constructor.
Offset implicit function. Offsets (grows or shrinks) the implicit function by a constant.
Definition EBGeometry_Transform.hpp:383
~OffsetIF() override=default
Destructor.
OffsetIF()=delete
Disallowed weak construction.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Underlying implicit function.
Definition EBGeometry_Transform.hpp:444
OffsetIF(OffsetIF &&a_other) noexcept=default
Move constructor.
OffsetIF & operator=(const OffsetIF &a_other) noexcept=default
Copy assignment operator.
T m_offset
Offset value.
Definition EBGeometry_Transform.hpp:449
OffsetIF & operator=(OffsetIF &&a_other) noexcept=default
Move assignment operator.
OffsetIF(const OffsetIF &a_other) noexcept=default
Copy constructor.
T value(const Vec3T< T > &a_point) const noexcept override
Value function with offset applied.
OffsetIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_offset) noexcept
Full constructor. Subtracts a_offset from the wrapped function value.
Implicit function which is a reflection of another implicit function.
Definition EBGeometry_Transform.hpp:861
ReflectIF & operator=(const ReflectIF &a_other) noexcept=default
Copy assignment operator.
ReflectIF(ReflectIF &&a_other) noexcept=default
Move constructor.
ReflectIF()=delete
Disallowed weak construction.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
Vec3T< T > m_reflectParams
Reflection parameters.
Definition EBGeometry_Transform.hpp:927
ReflectIF & operator=(ReflectIF &&a_other) noexcept=default
Move assignment operator.
ReflectIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const size_t &a_reflectPlane) noexcept
Full constructor. Reflects across the specified plane.
~ReflectIF() override=default
Destructor.
ReflectIF(const ReflectIF &a_other) noexcept=default
Copy constructor.
Rotated implicit function. Rotates an implicit function about an axis.
Definition EBGeometry_Transform.hpp:290
T m_angle
Angle to rotate.
Definition EBGeometry_Transform.hpp:364
T m_cosAngle
Parameter in rotation matrix. Stored for efficiency.
Definition EBGeometry_Transform.hpp:369
RotateIF(RotateIF &&a_other) noexcept=default
Move constructor.
RotateIF(const RotateIF &a_other) noexcept=default
Copy constructor.
T value(const Vec3T< T > &a_point) const noexcept override
Value function with rotation applied to the query point.
RotateIF & operator=(RotateIF &&a_other) noexcept=default
Move assignment operator.
size_t m_axis
Axis to rotate about.
Definition EBGeometry_Transform.hpp:359
~RotateIF() override=default
Destructor.
RotateIF()=delete
No weak construction.
T m_sinAngle
Parameter in rotation matrix. Stored for efficiency.
Definition EBGeometry_Transform.hpp:374
RotateIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_angle, const size_t a_axis) noexcept
Full constructor. Rotates the wrapped implicit function by a_angle degrees about a_axis.
RotateIF & operator=(const RotateIF &a_other) noexcept=default
Copy assignment operator.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Underlying implicit function.
Definition EBGeometry_Transform.hpp:354
Uniformly scaled implicit function.
Definition EBGeometry_Transform.hpp:458
ScaleIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_scale) noexcept
Full constructor.
ScaleIF & operator=(const ScaleIF &a_other) noexcept=default
Copy assignment operator.
ScaleIF(ScaleIF &&a_other) noexcept=default
Move constructor.
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Original implicit function.
Definition EBGeometry_Transform.hpp:519
ScaleIF()=delete
Disallowed weak construction.
ScaleIF & operator=(ScaleIF &&a_other) noexcept=default
Move assignment operator.
T m_scale
Scaling factor.
Definition EBGeometry_Transform.hpp:524
~ScaleIF() override=default
Destructor.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
ScaleIF(const ScaleIF &a_other) noexcept=default
Copy constructor.
Translated implicit function.
Definition EBGeometry_Transform.hpp:215
TranslateIF(const TranslateIF &a_other) noexcept=default
Copy constructor.
~TranslateIF() override=default
Destructor (does nothing)
Vec3T< T > m_shift
Input point translate.
Definition EBGeometry_Transform.hpp:281
std::shared_ptr< ImplicitFunction< T > > m_implicitFunction
Underlying implicit function.
Definition EBGeometry_Transform.hpp:276
TranslateIF()=delete
No weak construction for this one.
T value(const Vec3T< T > &a_point) const noexcept override
Value function.
TranslateIF & operator=(const TranslateIF &a_other) noexcept=default
Copy assignment operator.
TranslateIF(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const Vec3T< T > &a_shift) noexcept
Full constructor.
TranslateIF(TranslateIF &&a_other) noexcept=default
Move constructor.
TranslateIF & operator=(TranslateIF &&a_other) noexcept=default
Move assignment operator.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31
std::shared_ptr< ImplicitFunction< T > > Rotate(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_angle, const size_t a_axis)
Convenience function for rotating an implicit function.
std::shared_ptr< ImplicitFunction< T > > Offset(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_offset)
Convenience function for offsetting an implicit function.
std::shared_ptr< ImplicitFunction< T > > Translate(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const Vec3T< T > &a_shift)
Convenience function for translating an implicit function.
std::shared_ptr< ImplicitFunction< T > > Blur(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_blurDistance)
Convenience function for blurring an implicit function.
std::shared_ptr< ImplicitFunction< T > > Complement(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction)
Convenience function for taking the complement of an implicit function.
std::shared_ptr< ImplicitFunction< T > > Scale(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_scale)
Convenience function for scaling an implicit function.
std::shared_ptr< ImplicitFunction< T > > Elongate(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const Vec3T< T > &a_elongation)
Convenience function for elongating (stretching) an implicit function.
std::shared_ptr< ImplicitFunction< T > > Annular(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_delta)
Convenience function for creating a shell out of an implicit function.
std::shared_ptr< ImplicitFunction< T > > Reflect(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const size_t &a_reflectPlane)
Convenience function for reflecting an implicit function.
std::shared_ptr< ImplicitFunction< T > > Mollify(const std::shared_ptr< ImplicitFunction< T > > &a_implicitFunction, const T a_dist, const size_t a_mollifierSamples=2)
Convenience function for mollification with an input sphere.