Hermes
surface.h
1 /*
2  * Copyright (c) 2017 FilipeCN
3  *
4  * The MIT License (MIT)
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  *
23  */
24 
25 #ifndef HERMES_GEOMETRY_SURFACE_INTERFACE_H
26 #define HERMES_GEOMETRY_SURFACE_INTERFACE_H
27 
28 #include <hermes/geometry/bbox.h>
29 #include <hermes/geometry/ray.h>
30 
31 namespace hermes {
32 
34  bool exists;
35  double t;
38 };
39 
41 public:
42  CurveInterface() {}
43  virtual ~CurveInterface() {}
44  virtual point2 closestPoint(const point2 &p) const = 0;
45  virtual normal2 closestNormal(const point2 &p) const = 0;
46  virtual bbox2 boundingBox() const = 0;
47  virtual void closestIntersection(const Ray2 &r,
48  CurveRayIntersection *i) const = 0;
49  virtual bool intersects(const Ray2 &r) const {
51  closestIntersection(r, &i);
52  return i.exists;
53  }
54  virtual real_t closestDistance(const point2 &p) const {
55  return distance(closestPoint(p), p);
56  }
57 };
58 
60 public:
62  virtual ~ImplicitCurveInterface() {}
63  virtual double signedDistance(const point2 &p) const = 0;
64 };
65 
67  bool exists;
68  double t;
71 };
72 
74 public:
75  SurfaceInterface() {}
76  virtual ~SurfaceInterface() {}
77  virtual point3 closestPoint(const point3 &p) const = 0;
78  virtual normal3 closestNormal(const point3 &p) const = 0;
79  virtual bbox3 boundingBox() const = 0;
80  virtual void closestIntersection(const Ray3 &r,
81  SurfaceRayIntersection *i) const = 0;
82  virtual bool intersects(const Ray3 &r) const {
84  closestIntersection(r, &i);
85  return i.exists;
86  }
87  virtual double closestDistance(const point3 &p) const {
88  return distance(closestPoint(p), p);
89  }
90 };
91 
93 public:
95  virtual ~ImplicitSurfaceInterface() {}
96  virtual double signedDistance(const point3 &p) const = 0;
97 };
98 
99 } // namespace hermes
100 
101 #endif // HERMES_GEOMETRY_SURFACE_INTERFACE_H
Definition: bbox.h:84
Definition: bbox.h:187
Definition: surface.h:40
Definition: surface.h:59
Definition: surface.h:92
Definition: ray.h:39
Definition: ray.h:70
Definition: surface.h:73
float real_t
default floating point type
Definition: defs.h:75
HERMES_DEVICE_CALLABLE real_t distance(const Point2< T > &a, const Point2< T > &b)
Computes the Euclidean distance between two points.
Definition: point.h:295
Definition: surface.h:33
point2 point
intersection point
Definition: surface.h:36
double t
parametric coordinate from ray
Definition: surface.h:35
bool exists
true if intersection exists
Definition: surface.h:34
normal2 normal
intersection normal
Definition: surface.h:37
Definition: surface.h:66
double t
parametric coordinate from ray
Definition: surface.h:68
normal3 normal
intersection normal
Definition: surface.h:70
point3 point
intersection point
Definition: surface.h:69
bool exists
true if intersection exists
Definition: surface.h:67