1 /******************************************************************************* 2 * bezier.h 3 * 4 * This module contains all defines, typedefs, and prototypes for BEZIER.CPP. 5 * 6 * --------------------------------------------------------------------------- 7 * Persistence of Vision Ray Tracer ('POV-Ray') version 3.7. 8 * Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd. 9 * 10 * POV-Ray is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Affero General Public License as 12 * published by the Free Software Foundation, either version 3 of the 13 * License, or (at your option) any later version. 14 * 15 * POV-Ray is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Affero General Public License for more details. 19 * 20 * You should have received a copy of the GNU Affero General Public License 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 22 * --------------------------------------------------------------------------- 23 * POV-Ray is based on the popular DKB raytracer version 2.12. 24 * DKBTrace was originally written by David K. Buck. 25 * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. 26 * --------------------------------------------------------------------------- 27 * $File: //depot/public/povray/3.x/source/backend/shape/bezier.h $ 28 * $Revision: #1 $ 29 * $Change: 6069 $ 30 * $DateTime: 2013/11/06 11:59:40 $ 31 * $Author: chrisc $ 32 *******************************************************************************/ 33 34 #ifndef BEZIER_H 35 #define BEZIER_H 36 37 namespace pov 38 { 39 40 /***************************************************************************** 41 * Global preprocessor defines 42 ******************************************************************************/ 43 44 #define BICUBIC_PATCH_OBJECT (PATCH_OBJECT) 45 /* NK 1998 double_illuminate - removed +DOUBLE_ILLUMINATE from bicubic_patch */ 46 47 #define BEZIER_INTERIOR_NODE 0 48 #define BEZIER_LEAF_NODE 1 49 50 #define MAX_PATCH_TYPE 2 51 52 53 54 /***************************************************************************** 55 * Global typedefs 56 ******************************************************************************/ 57 58 typedef DBL DISTANCES[4][4]; 59 typedef DBL WEIGHTS[4][4]; 60 typedef struct Bezier_Node_Struct BEZIER_NODE; 61 typedef struct Bezier_Child_Struct BEZIER_CHILDREN; 62 typedef struct Bezier_Vertices_Struct BEZIER_VERTICES; 63 64 struct Bezier_Child_Struct 65 { 66 BEZIER_NODE *Children[4]; 67 }; 68 69 struct Bezier_Vertices_Struct 70 { 71 float uvbnds[4]; 72 VECTOR Vertices[4]; 73 }; 74 75 struct Bezier_Node_Struct 76 { 77 int Node_Type; /* Is this an interior node, or a leaf */ 78 VECTOR Center; /* Center of sphere bounding the (sub)patch */ 79 DBL Radius_Squared; /* Radius of bounding sphere (squared) */ 80 int Count; /* # of subpatches associated with this node */ 81 void *Data_Ptr; /* Either pointer to vertices or pointer to children */ 82 }; 83 84 class BicubicPatch : public ObjectBase 85 { 86 public: 87 int Patch_Type, U_Steps, V_Steps; 88 VECTOR Control_Points[4][4]; 89 UV_VECT ST[4]; 90 VECTOR Bounding_Sphere_Center; 91 DBL Bounding_Sphere_Radius; 92 DBL Flatness_Value; 93 DBL accuracy; 94 BEZIER_NODE *Node_Tree; 95 WEIGHTS *Weights; 96 97 BicubicPatch(); 98 virtual ~BicubicPatch(); 99 100 virtual ObjectPtr Copy(); 101 102 virtual bool All_Intersections(const Ray&, IStack&, TraceThreadData *); 103 virtual bool Inside(const VECTOR, TraceThreadData *) const; 104 virtual void Normal(VECTOR, Intersection *, TraceThreadData *) const; 105 virtual void UVCoord(UV_VECT, const Intersection *, TraceThreadData *) const; 106 virtual void Translate(const VECTOR, const TRANSFORM *); 107 virtual void Rotate(const VECTOR, const TRANSFORM *); 108 virtual void Scale(const VECTOR, const TRANSFORM *); 109 virtual void Transform(const TRANSFORM *); 110 virtual void Invert(); 111 virtual void Compute_BBox(); 112 113 void Precompute_Patch_Values(); 114 protected: 115 static void bezier_value(const VECTOR(*Control_Points)[4][4], DBL u0, DBL v0, VECTOR P, VECTOR N); 116 bool intersect_subpatch(const Ray&, const VECTOR [3], const DBL [3], const DBL [3], DBL *, VECTOR, VECTOR, DBL *, DBL *) const; 117 static void find_average(int, const VECTOR *, VECTOR, DBL *); 118 static bool spherical_bounds_check(const Ray &, const VECTOR, DBL); 119 int intersect_bicubic_patch0(const Ray& , IStack&); 120 static DBL point_plane_distance(const VECTOR, const VECTOR, DBL); 121 static DBL determine_subpatch_flatness(const VECTOR(*)[4][4]); 122 bool flat_enough(const VECTOR(*)[4][4]) const; 123 static void bezier_bounding_sphere(const VECTOR(*)[4][4], VECTOR, DBL *); 124 int bezier_subpatch_intersect(const Ray &, const VECTOR(*)[4][4], DBL, DBL, DBL, DBL, IStack&); 125 static void bezier_split_left_right(const VECTOR(*)[4][4], VECTOR(*)[4][4], VECTOR(*)[4][4]); 126 static void bezier_split_up_down(const VECTOR(*)[4][4], VECTOR(*)[4][4], VECTOR(*)[4][4]); 127 int bezier_subdivider(const Ray &, const VECTOR(*)[4][4], DBL, DBL, DBL, DBL, int, IStack&); 128 static void bezier_tree_deleter(BEZIER_NODE *Node); 129 BEZIER_NODE *bezier_tree_builder(const VECTOR(*Patch)[4][4], DBL u0, DBL u1, DBL v0, DBL v1, int depth, int& max_depth_reached); 130 int bezier_tree_walker(const Ray &, const BEZIER_NODE *, IStack&); 131 static BEZIER_NODE *create_new_bezier_node(void); 132 static BEZIER_VERTICES *create_bezier_vertex_block(void); 133 static BEZIER_CHILDREN *create_bezier_child_block(void); 134 static bool subpatch_normal(const VECTOR v1, const VECTOR v2, const VECTOR v3, VECTOR Result, DBL *d); 135 static void Compute_Texture_UV(const UV_VECT p, const UV_VECT st[4], UV_VECT t); 136 }; 137 138 139 140 } 141 142 #endif 143