Visual Computing Library  devel
Loading...
Searching...
No Matches
ray.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_SPACE_CORE_RAY_H
24#define VCL_SPACE_CORE_RAY_H
25
26#include "point.h"
27
28namespace vcl {
29
39template<PointConcept PointT>
40class Ray
41{
42 PointT mOrigin;
43 PointT mDirection;
44
45public:
50 using PointType = PointT;
51
55 using ScalarType = PointT::ScalarType;
56
60 static const uint DIM = PointT::DIM;
61
66 Ray() {}
67
74 Ray(const PointT& origin, const PointT& direction) :
75 mOrigin(origin), mDirection(direction)
76 {
77 }
78
84 PointT& origin() { return mOrigin; }
85
91 const PointT& origin() const { return mOrigin; }
92
98 PointT& direction() { return mDirection; }
99
105 const PointT& direction() const { return mDirection; }
106
107 PointT normalizedDirection() const { return mDirection.normalized(); }
108
109 bool operator==(const Ray<PointT>& s) const = default;
110
111 bool operator!=(const Ray<PointT>& s) const = default;
112};
113
114/* Specialization Aliases */
115
116template<typename S>
117using Ray2 = Ray<Point2<S>>;
118
119using Ray2i = Ray<Point2i>;
120using Ray2f = Ray<Point2f>;
121using Ray2d = Ray<Point2d>;
122
123template<typename S>
124using Ray3 = Ray<Point3<S>>;
125
126using Ray3i = Ray<Point3i>;
127using Ray3f = Ray<Point3f>;
128using Ray3d = Ray<Point3d>;
129
130/* Concepts */
131
142template<typename T>
143concept RayConcept = std::derived_from< // same type or derived type
144 std::remove_cvref_t<T>,
145 Ray<typename RemoveRef<T>::PointType>>;
146
157template<typename T>
158concept Ray2Concept = RayConcept<T> && RemoveRef<T>::DIM == 2;
159
170template<typename T>
171concept Ray3Concept = RayConcept<T> && RemoveRef<T>::DIM == 3;
172
173} // namespace vcl
174
175#endif // VCL_SPACE_CORE_RAY_H
A class representing a ray in n-dimensional space. The class is parameterized by a PointConcept,...
Definition ray.h:41
PointT::ScalarType ScalarType
The scalar type of the ray.
Definition ray.h:55
const PointT & direction() const
Returns the direction of the ray.
Definition ray.h:105
Ray(const PointT &origin, const PointT &direction)
Creates a ray with the given origin and direction.
Definition ray.h:74
PointT PointType
The type of point used to represent the origin and direction of the ray.
Definition ray.h:50
static const uint DIM
The dimensionality of the ray.
Definition ray.h:60
const PointT & origin() const
Returns the origin of the ray.
Definition ray.h:91
PointT & origin()
Returns the origin of the ray.
Definition ray.h:84
PointT & direction()
Returns the direction of the ray.
Definition ray.h:98
Ray()
Default constructor. Creates an invalid Ray at the origin (direction is zero).
Definition ray.h:66
A concept representing a 2D Ray.
Definition ray.h:158
A concept representing a 3D Ray.
Definition ray.h:171
A concept representing a Ray.
Definition ray.h:143