1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/*******************************************************************************
* blob.h
*
* This module contains all defines, typedefs, and prototypes for BLOB.CPP.
*
* ---------------------------------------------------------------------------
* Persistence of Vision Ray Tracer ('POV-Ray') version 3.7.
* Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
*
* POV-Ray is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* POV-Ray is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------------
* POV-Ray is based on the popular DKB raytracer version 2.12.
* DKBTrace was originally written by David K. Buck.
* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
* ---------------------------------------------------------------------------
* $File: //depot/public/povray/3.x/source/backend/shape/blob.h $
* $Revision: #1 $
* $Change: 6069 $
* $DateTime: 2013/11/06 11:59:40 $
* $Author: chrisc $
*******************************************************************************/
#ifndef BLOB_H
#define BLOB_H
#include "backend/bounding/bsphere.h"
namespace pov
{
/*****************************************************************************
* Global preprocessor defines
******************************************************************************/
#define BLOB_OBJECT (STURM_OK_OBJECT+HIERARCHY_OK_OBJECT)
/* Do not use the first bit!!! (Used for enter/exit in intersection test) */
#define BLOB_SPHERE 2
#define BLOB_CYLINDER 4
#define BLOB_ELLIPSOID 8
#define BLOB_BASE_HEMISPHERE 16
#define BLOB_APEX_HEMISPHERE 32
#define BLOB_BASE_HEMIELLIPSOID 64
#define BLOB_APEX_HEMIELLIPSOID 128
/* Define max. number of blob components. */
#define MAX_BLOB_COMPONENTS 1000000
/* Generate additional blob statistics. */
#define BLOB_EXTRA_STATS 1
/*****************************************************************************
* Global typedefs
******************************************************************************/
class Blob_Element
{
public:
short Type; /* Type of component: sphere, hemisphere, cylinder */
int index;
VECTOR O; /* Element's origin */
DBL len; /* Cylinder's length */
DBL rad2; /* Sphere's/Cylinder's radius^2 */
DBL c[3]; /* Component's coeffs */
TEXTURE *Texture; /* Component's texture */
TRANSFORM *Trans; /* Component's transformation */
Blob_Element();
~Blob_Element();
};
class Blob_Data
{
public:
int Number_Of_Components; /* Number of components */
DBL Threshold; /* Blob threshold */
vector<Blob_Element> Entry; /* Array of blob components */
BSPHERE_TREE *Tree; /* Bounding hierarchy */
Blob_Data(int count = 0);
~Blob_Data();
Blob_Data *AcquireReference(void);
void ReleaseReference(void);
private:
int References; /* Number of references */
};
struct Blob_List_Struct
{
Blob_Element elem; /* Current element */
Blob_List_Struct *next; /* Pointer to next element */
};
struct Blob_Interval_Struct
{
int type;
DBL bound;
const Blob_Element *Element;
};
class Blob : public ObjectBase
{
public:
Blob_Data *Data;
TEXTURE **Element_Texture;
Blob();
virtual ~Blob();
virtual ObjectPtr Copy();
virtual bool All_Intersections(const Ray&, IStack&, TraceThreadData *);
virtual bool Inside(const VECTOR, TraceThreadData *) const;
virtual void Normal(VECTOR, Intersection *, TraceThreadData *) const;
virtual void Translate(const VECTOR, const TRANSFORM *);
virtual void Rotate(const VECTOR, const TRANSFORM *);
virtual void Scale(const VECTOR, const TRANSFORM *);
virtual void Transform(const TRANSFORM *);
virtual void Invert();
virtual void Compute_BBox();
void Determine_Textures(Intersection *, bool, WeightedTextureVector&, TraceThreadData *);
Blob_List_Struct *Create_Blob_List_Element();
void Create_Blob_Element_Texture_List(Blob_List_Struct *BlobList, int npoints);
int Make_Blob(DBL threshold, Blob_List_Struct *bloblist, int npoints, TraceThreadData *Thread);
void Test_Blob_Opacity();
static void Translate_Blob_Element(Blob_Element *Element, const VECTOR Vector);
static void Rotate_Blob_Element(Blob_Element *Element, const VECTOR Vector);
static void Scale_Blob_Element(Blob_Element *Element, const VECTOR Vector);
static void Invert_Blob_Element(Blob_Element *Element);
static void Transform_Blob_Element(Blob_Element *Element, const TRANSFORM *Trans);
private:
static void element_normal(VECTOR Result, const VECTOR P, const Blob_Element *Element);
static int intersect_element(const VECTOR P, const VECTOR D, const Blob_Element *Element, DBL mindist, DBL *t0, DBL *t1, TraceThreadData *Thread);
static void insert_hit(const Blob_Element *Element, DBL t0, DBL t1, Blob_Interval_Struct *intervals, unsigned int *cnt);
int determine_influences(const VECTOR P, const VECTOR D, DBL mindist, Blob_Interval_Struct *intervals, TraceThreadData *Thread) const;
DBL calculate_field_value(const VECTOR P, TraceThreadData *Thread) const;
static DBL calculate_element_field(const Blob_Element *Element, const VECTOR P);
static int intersect_cylinder(const Blob_Element *Element, const VECTOR P, const VECTOR D, DBL mindist, DBL *tmin, DBL *tmax);
static int intersect_hemisphere(const Blob_Element *Element, const VECTOR P, const VECTOR D, DBL mindist, DBL *tmin, DBL *tmax);
static int intersect_sphere(const Blob_Element *Element, const VECTOR P, const VECTOR D, DBL mindist, DBL *tmin, DBL *tmax);
static int intersect_ellipsoid(const Blob_Element *Element, const VECTOR P, const VECTOR D, DBL mindist, DBL *tmin, DBL *tmax);
static void get_element_bounding_sphere(const Blob_Element *Element, VECTOR Center, DBL *Radius2);
void build_bounding_hierarchy();
void determine_element_texture(const Blob_Element *Element, TEXTURE *Texture, const VECTOR P, WeightedTextureVector&);
static bool insert_node(BSPHERE_TREE *Node, unsigned int *size, TraceThreadData *Thread);
void getLocalIPoint(VECTOR lip, Intersection *isect) const;
};
}
#endif
|