1 /*******************************************************************************
2  * threaddata.h
3  *
4  * ---------------------------------------------------------------------------
5  * Persistence of Vision Ray Tracer ('POV-Ray') version 3.7.
6  * Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
7  *
8  * POV-Ray is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as
10  * published by the Free Software Foundation, either version 3 of the
11  * License, or (at your option) any later version.
12  *
13  * POV-Ray is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  * ---------------------------------------------------------------------------
21  * POV-Ray is based on the popular DKB raytracer version 2.12.
22  * DKBTrace was originally written by David K. Buck.
23  * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
24  * ---------------------------------------------------------------------------
25  * $File: //depot/public/povray/3.x/source/backend/scene/threaddata.h $
26  * $Revision: #1 $
27  * $Change: 6069 $
28  * $DateTime: 2013/11/06 11:59:40 $
29  * $Author: chrisc $
30  *******************************************************************************/
31 
32 #ifndef POVRAY_BACKEND_THREADDATA_H
33 #define POVRAY_BACKEND_THREADDATA_H
34 
35 #include <vector>
36 #include <stack>
37 
38 #include "base/types.h"
39 #include "backend/frame.h"
40 #include "backend/support/task.h"
41 #include "backend/support/statistics.h"
42 #include "backend/shape/mesh.h"
43 #include "backend/pattern/pattern.h"
44 
45 namespace pov
46 {
47 
48 using namespace pov_base;
49 
50 class SceneData;
51 class ViewData;
52 class FunctionVM;
53 struct FPUContext;
54 struct ISO_ThreadData;
55 
56 class PhotonMap;
57 struct Blob_Interval_Struct;
58 
59 /**
60  *	Class holding parser thread specific data.
61  */
62 class SceneThreadData : public Task::TaskData
63 {
64 		friend class Scene;
65 		friend class Trace;
66 		friend class View; // TODO FIXME - needed only to access TraceThreadData for CheckCameraHollowObject()
67 	public:
68 		/**
69 		 *	Create thread local data.
70 		 *	@param	sd				Scene data defining scene attributes.
71 		 */
72 		SceneThreadData(shared_ptr<SceneData> sd);
73 
74 		/**
75 		 *	Get the statistics.
76 		 *	@return					Reference to statistic counters.
77 		 */
Stats(void)78 		RenderStatistics& Stats(void) { return renderStats; }
79 
80 		DBL *Fractal_IStack[4];
81 		PriorityQueue Mesh_Queue;
82 		void **Blob_Queue;
83 		unsigned int Max_Blob_Queue_Size;
84 		DBL *Blob_Coefficients;
85 		Blob_Interval_Struct *Blob_Intervals;
86 		int Blob_Coefficient_Count;
87 		int Blob_Interval_Count;
88 		ISO_ThreadData *isosurfaceData;
89 		void *BCyl_Intervals;
90 		void *BCyl_RInt;
91 		void *BCyl_HInt;
92 		IStackPool stackPool;
93 		FPUContext *functionContext;
94 		vector<FPUContext *> functionPatternContext;
95 		int Facets_Last_Seed;
96 		int Facets_CVC;
97 		VECTOR Facets_Cube[81];
98 
99 		// TODO FIXME - thread-local copy of lightsources. we need this
100 		// because various parts of the lighting code seem to make changes
101 		// to the lightsource object passed to them (this is not confined
102 		// just to the area light shadow code). This code ought to be fixed
103 		// to treat the lightsource as const, after which this can go away.
104 		vector<LightSource *> lightSources;
105 
106 		// all of these are for photons
107 		// most of them should be refactored into parameters, return values, or other objects
108 		LightSource *photonSourceLight;
109 		ObjectPtr photonTargetObject;
110 		bool litObjectIgnoresPhotons;
111 		RGBColour GFilCol;
112 		int hitObject;    // did we hit the target object? (for autostop)
113 		DBL photonSpread; // photon spread (in radians)
114 		DBL photonDepth;  // total distance from light to intersection
115 		int passThruThis;           // is this a pass-through object encountered before the target?
116 		int passThruPrev;           // was the previous object a pass-through object encountered before the target?
117 		bool Light_Is_Global;       // is the current light global? (not part of a light_group?)
118 		PhotonMap* surfacePhotonMap;
119 		PhotonMap* mediaPhotonMap;
120 
121 		Crackle_Cache_Type Crackle_Cache;
122 
123 		// data for waves and ripples pattern
124 		unsigned int numberOfWaves;
125 		vector<double> waveFrequencies;
126 		vector<Vector3d> waveSources;
127 
128 		/**
129 		 * called after a rectangle is finished
130 		 * used for crackle cache expiry
131 		 */
132 		void AfterTile();
133 
134 		/**
135 		 * @returns the index of the current rectangle rendered
136 		 * used by the crackle pattern to indicate age of cache entries
137 		 */
ProgressIndex()138 		inline size_t ProgressIndex() const { return progress_index; }
139 
140 		enum TimeType
141 		{
142 			kUnknownTime,
143 			kParseTime,
144 			kBoundingTime,
145 			kPhotonTime,
146 			kRadiosityTime,
147 			kRenderTime,
148 			kMaxTimeType
149 		};
150 
151 		TimeType timeType;
152 		POV_LONG cpuTime;
153 		POV_LONG realTime;
154 		unsigned int qualityFlags; // TODO FIXME - remove again
155 
GetSceneData()156 		inline shared_ptr<const SceneData> GetSceneData() const { return sceneData; }
157 
158 	protected:
159 		/// scene data
160 		shared_ptr<SceneData> sceneData;
161 		/// render statistics
162 		RenderStatistics renderStats;
163 
164 	private:
165 		/// not available
166 		SceneThreadData();
167 
168 		/// not available
169 		SceneThreadData(const SceneThreadData&);
170 
171 		/// not available
172 		SceneThreadData& operator=(const SceneThreadData&);
173 
174 		/// current number of Tiles to expire crackle cache entries after
175 		size_t CrCache_MaxAge;
176 		/// current tile index (for crackle cache expiry)
177 		size_t progress_index;
178 
179 	public: // TODO FIXME - temporary workaround [trf]
180 
181 		/**
182 		 *	Destructor.
183 		 */
184 		~SceneThreadData();
185 };
186 
187 /**
188  *	Class holding render thread specific data.
189  */
190 class ViewThreadData : public SceneThreadData
191 {
192 		friend class Scene;
193 	public:
194 		/**
195 		 *	Create thread local data.
196 		 *	@param	vd				View data defining view attributes
197 		 *							as well as view output.
198 		 */
199 		ViewThreadData(ViewData *vd);
200 
201 		/**
202 		 *	Get width of view.
203 		 *	@return					Width.
204 		 */
205 		unsigned int GetWidth() const;
206 
207 		/**
208 		 *	Get height of view.
209 		 *	@return					Height.
210 		 */
211 		unsigned int GetHeight() const;
212 
213 		/**
214 		 *	Get area of view to be rendered.
215 		 *	@return					Area rectangle.
216 		 */
217 		const POVRect& GetRenderArea();
218 	protected:
219 		/// view data
220 		ViewData *viewData;
221 	private:
222 		/// not available
223 		ViewThreadData();
224 
225 		/// not available
226 		ViewThreadData(const ViewThreadData&);
227 
228 		/// not available
229 		ViewThreadData& operator=(const ViewThreadData&);
230 	public: // TODO FIXME - temporary workaround [trf]
231 		/**
232 		 *	Destructor.
233 		 */
234 		~ViewThreadData();
235 };
236 
237 }
238 
239 #endif // POVRAY_BACKEND_THREADDATA_H
240