1 //******************************************************************************
2 ///
3 /// @file core/shape/polynomial.h
4 ///
5 /// Declarations related to the 3-variable polynomial 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_POLYNOMIAL_H
37 #define POVRAY_CORE_POLYNOMIAL_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 POLY_OBJECT (STURM_OK_OBJECT)
60 #define CUBIC_OBJECT (STURM_OK_OBJECT)
61 #define QUARTIC_OBJECT (STURM_OK_OBJECT)
62
63 /// @}
64 ///
65 //******************************************************************************
66
67 /* Number of coefficients of a three variable polynomial of order x */
68
term_counts(int x)69 inline int term_counts(int x) { return ((x+1)*(x+2)*(x+3)/6); }
70
71
72
73 /*****************************************************************************
74 * Global typedefs
75 ******************************************************************************/
76
77 class Poly : public ObjectBase
78 {
79 public:
80 int Order;
81 DBL *Coeffs;
82
83 Poly(int order);
84 virtual ~Poly();
85
86 virtual ObjectPtr Copy();
87
88 virtual bool All_Intersections(const Ray&, IStack&, TraceThreadData *);
89 virtual bool Inside(const Vector3d&, TraceThreadData *) const;
90 virtual void Normal(Vector3d&, Intersection *, TraceThreadData *) const;
91 virtual void Translate(const Vector3d&, const TRANSFORM *);
92 virtual void Rotate(const Vector3d&, const TRANSFORM *);
93 virtual void Scale(const Vector3d&, const TRANSFORM *);
94 virtual void Transform(const TRANSFORM *);
95 virtual void Compute_BBox();
96 virtual bool Intersect_BBox(BBoxDirection, const BBoxVector3d&, const BBoxVector3d&, BBoxScalar) const;
97
98 bool Set_Coeff(const unsigned int x,const unsigned int y, const unsigned int z, const DBL value);
99 protected:
100 static int intersect(const BasicRay &Ray, int Order, const DBL *Coeffs, int Sturm_Flag, DBL *Depths, TraceThreadData *Thread);
101 static void normal0(Vector3d& Result, int Order, const DBL *Coeffs, const Vector3d& IPoint);
102 static void normal1(Vector3d& Result, int Order, const DBL *Coeffs, const Vector3d& IPoint);
103 static DBL inside(const Vector3d& IPoint, int Order, const DBL *Coeffs);
104 static int intersect_linear(const BasicRay &ray, const DBL *Coeffs, DBL *Depths);
105 static int intersect_quadratic(const BasicRay &ray, const DBL *Coeffs, DBL *Depths);
106 // static int factor_out(int n, int i, int *c, int *s);
107 //static int binomial(int n, int r);
108 //static void factor1(int n, int *c, int *s);
109 };
110
111 /// @}
112 ///
113 //##############################################################################
114
115 }
116
117 #endif // POVRAY_CORE_POLYNOMIAL_H
118