1 //******************************************************************************
2 ///
3 /// @file core/shape/prism.h
4 ///
5 /// Declarations related to the prism geometric primitive.
6 ///
7 /// @copyright
8 /// @parblock
9 ///
10 /// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11 /// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd.
12 ///
13 /// POV-Ray is free software: you can redistribute it and/or modify
14 /// it under the terms of the GNU Affero General Public License as
15 /// published by the Free Software Foundation, either version 3 of the
16 /// License, or (at your option) any later version.
17 ///
18 /// POV-Ray is distributed in the hope that it will be useful,
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 /// GNU Affero General Public License for more details.
22 ///
23 /// You should have received a copy of the GNU Affero General Public License
24 /// along with this program.  If not, see <http://www.gnu.org/licenses/>.
25 ///
26 /// ----------------------------------------------------------------------------
27 ///
28 /// POV-Ray is based on the popular DKB raytracer version 2.12.
29 /// DKBTrace was originally written by David K. Buck.
30 /// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
31 ///
32 /// @endparblock
33 ///
34 //******************************************************************************
35 
36 #ifndef POVRAY_CORE_PRISM_H
37 #define POVRAY_CORE_PRISM_H
38 
39 // Module config header file must be the first file included within POV-Ray unit header files
40 #include "core/configcore.h"
41 
42 #include "core/scene/object.h"
43 
44 namespace pov
45 {
46 
47 //##############################################################################
48 ///
49 /// @addtogroup PovCoreShape
50 ///
51 /// @{
52 
53 //******************************************************************************
54 ///
55 /// @name Object Types
56 ///
57 /// @{
58 
59 #define PRISM_OBJECT (STURM_OK_OBJECT)
60 
61 /// @}
62 ///
63 //******************************************************************************
64 
65 #define LINEAR_SPLINE    1
66 #define QUADRATIC_SPLINE 2
67 #define CUBIC_SPLINE     3
68 #define BEZIER_SPLINE    4
69 
70 #define LINEAR_SWEEP 1
71 #define CONIC_SWEEP  2
72 
73 /* Generate additional prism statistics. */
74 
75 #define PRISM_EXTRA_STATS 1
76 
77 
78 
79 /*****************************************************************************
80 * Global typedefs
81 ******************************************************************************/
82 
83 typedef struct Prism_Spline_Struct PRISM_SPLINE;
84 typedef struct Prism_Spline_Entry_Struct PRISM_SPLINE_ENTRY;
85 
86 struct Prism_Spline_Entry_Struct
87 {
88     DBL x1, y1, x2, y2;  /* Min./Max. coordinates of segment   */
89     DBL v1, u2, v2;      /* Min./Max. coordinates of segment in <u,v>, u1 not needed  */
90     Vector2d A, B, C, D; /* Coefficients of segment            */
91 };
92 
93 struct Prism_Spline_Struct
94 {
95     int References;
96     PRISM_SPLINE_ENTRY *Entry;
97 };
98 
99 class Prism : public ObjectBase
100 {
101     public:
102         int Number;
103         int Spline_Type;          /* Spline type (linear, quadratic ...)        */
104         int Sweep_Type;           /* Sweep type (linear, conic)                 */
105         DBL Height1, Height2;
106         DBL x1, y1, x2, y2;       /* Overall bounding rectangle of spline curve */
107         PRISM_SPLINE *Spline;     /* Pointer to array of splines                */
108         DBL u1, v1, u2, v2;       /* Overall <u,v> bounding rectangle of spline */
109 
110         Prism();
111         virtual ~Prism();
112 
113         virtual ObjectPtr Copy();
114 
115         virtual bool All_Intersections(const Ray&, IStack&, TraceThreadData *);
116         virtual bool Inside(const Vector3d&, TraceThreadData *) const;
117         virtual void Normal(Vector3d&, Intersection *, TraceThreadData *) const;
118         virtual void Translate(const Vector3d&, const TRANSFORM *);
119         virtual void Rotate(const Vector3d&, const TRANSFORM *);
120         virtual void Scale(const Vector3d&, const TRANSFORM *);
121         virtual void Transform(const TRANSFORM *);
122         virtual void Compute_BBox();
123 
124         void Compute_Prism(Vector2d *P, TraceThreadData *Thread);
125     protected:
126         int in_curve(DBL u, DBL v, TraceThreadData *Thread) const;
127         static bool test_rectangle(const Vector3d& P, const Vector3d& D, DBL x1, DBL y1, DBL x2, DBL y2);
128 };
129 
130 /// @}
131 ///
132 //##############################################################################
133 
134 }
135 
136 #endif // POVRAY_CORE_PRISM_H
137