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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
/*
**************************************************************************
description
--------------------
copyright : (C) 2003 by Leon Pennington
email : [email protected]
**************************************************************************
**************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
**************************************************************************/
#include "pmradiosity.h"
#include "pmxmlhelper.h"
#include "pmmemento.h"
#include "pmradiosityedit.h"
#include <tdelocale.h>
const double adcBailoutDefault = 0.01;
const double brightnessDefault = 1.0;
const int countDefault = 35;
const double errorBoundDefault = 1.8;
const double grayThresholdDefault = 0.0;
const double lowErrorFactorDefault = 0.5;
const double maxSampleDefault = -1.0;
const double minimumReuseDefault = 0.015;
const int nearestCountDefault = 5;
const double pretraceStartDefault = 0.08;
const double pretraceEndDefault = 0.04;
const int recursionLimitDefault = 2;
PMDefinePropertyClass( PMRadiosity, PMRadiosityProperty );
PMMetaObject* PMRadiosity::s_pMetaObject = 0;
PMObject* createNewRadiosity( PMPart* part )
{
return new PMRadiosity( part );
}
PMRadiosity::PMRadiosity( PMPart* part ) : Base( part )
{
m_adcBailout = adcBailoutDefault;
m_alwaysSample = true;
m_brightness = brightnessDefault;
m_count = countDefault;
m_errorBound = errorBoundDefault;
m_grayThreshold = grayThresholdDefault;
m_lowErrorFactor = lowErrorFactorDefault;
m_maxSample = maxSampleDefault;
m_media = false;
m_minimumReuse = minimumReuseDefault;
m_nearestCount = nearestCountDefault;
m_normal = false;
m_pretraceStart = pretraceStartDefault;
m_pretraceEnd = pretraceEndDefault;
m_recursionLimit = recursionLimitDefault;
}
PMRadiosity::PMRadiosity( const PMRadiosity& r )
: Base( r )
{
m_adcBailout = r.m_adcBailout;
m_alwaysSample = r.m_alwaysSample;
m_brightness = r.m_brightness;
m_count = r.m_count;
m_errorBound = r.m_errorBound;
m_grayThreshold = r.m_grayThreshold;
m_lowErrorFactor = r.m_lowErrorFactor;
m_maxSample = r.m_maxSample;
m_media = r.m_media;
m_minimumReuse = r.m_minimumReuse;
m_nearestCount = r.m_nearestCount;
m_normal = r.m_normal;
m_pretraceStart = r.m_pretraceStart;
m_pretraceEnd = r.m_pretraceEnd;
m_recursionLimit = r.m_recursionLimit;
}
PMRadiosity::~PMRadiosity( )
{
}
PMMetaObject* PMRadiosity::metaObject( ) const
{
if( !s_pMetaObject )
{
s_pMetaObject = new PMMetaObject( "Radiosity", Base::metaObject( ),
createNewRadiosity );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "adcBailout", &PMRadiosity::setAdcBailout, &PMRadiosity::adcBailout ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "alwaysSample", &PMRadiosity::setAlwaysSample, &PMRadiosity::alwaysSample ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "brightness", &PMRadiosity::setBrightness, &PMRadiosity::brightness ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "count", &PMRadiosity::setCount, &PMRadiosity::count ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "errorBound", &PMRadiosity::setErrorBound, &PMRadiosity::errorBound ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "grayThreshold", &PMRadiosity::setGrayThreshold, &PMRadiosity::grayThreshold ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "lowErrorFactor", &PMRadiosity::setLowErrorFactor, &PMRadiosity::lowErrorFactor ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "maxSample", &PMRadiosity::setMaxSample, &PMRadiosity::maxSample ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "media", &PMRadiosity::setMedia, &PMRadiosity::media ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "minimumReuse", &PMRadiosity::setMinimumReuse, &PMRadiosity::minimumReuse ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "nearestCount", &PMRadiosity::setNearestCount, &PMRadiosity::nearestCount ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "normal", &PMRadiosity::setNormal, &PMRadiosity::normal ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "pretraceStart", &PMRadiosity::setPretraceStart, &PMRadiosity::pretraceStart ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "pretraceEnd", &PMRadiosity::setPretraceEnd, &PMRadiosity::pretraceEnd ) );
s_pMetaObject->addProperty(
new PMRadiosityProperty( "recursionLimit", &PMRadiosity::setRecursionLimit, &PMRadiosity::recursionLimit ) );
}
return s_pMetaObject;
}
void PMRadiosity::cleanUp( ) const
{
if( s_pMetaObject )
{
delete s_pMetaObject;
s_pMetaObject = 0;
}
Base::cleanUp( );
}
TQString PMRadiosity::description( ) const
{
return i18n( "radiosity" );
}
void PMRadiosity::serialize( TQDomElement& e, TQDomDocument& ) const
{
e.setAttribute( "adc_bailout", m_adcBailout );
if ( m_alwaysSample )
e.setAttribute( "always_sample", "1" );
else
e.setAttribute( "always_sample", "0" );
e.setAttribute( "brightness", m_brightness );
e.setAttribute( "count", m_count );
e.setAttribute( "error_bound", m_errorBound );
e.setAttribute( "gray_threshold", m_grayThreshold );
e.setAttribute( "low_error_factor", m_lowErrorFactor );
e.setAttribute( "max_sample", m_maxSample );
if ( m_media )
e.setAttribute( "media", "1" );
else
e.setAttribute( "media", "0" );
e.setAttribute( "minimum_reuse", m_minimumReuse );
e.setAttribute( "nearest_count", m_nearestCount );
if ( m_normal )
e.setAttribute( "normal", "1" );
else
e.setAttribute( "normal", "0" );
e.setAttribute( "pretrace_start", m_pretraceStart );
e.setAttribute( "pretrace_end", m_pretraceEnd );
e.setAttribute( "recursion_limit", m_recursionLimit );
}
void PMRadiosity::readAttributes( const PMXMLHelper& h )
{
m_adcBailout = h.doubleAttribute( "adc_bailout", adcBailoutDefault );
m_alwaysSample = h.boolAttribute( "always_sample", true );
m_brightness = h.doubleAttribute( "brightness", brightnessDefault );
m_count = h.intAttribute( "count", countDefault );
m_errorBound = h.doubleAttribute( "error_bound", errorBoundDefault );
m_grayThreshold = h.doubleAttribute( "gray_threshold", grayThresholdDefault );
m_lowErrorFactor = h.doubleAttribute( "low_error_factor", lowErrorFactorDefault );
m_maxSample = h.doubleAttribute( "max_sample", maxSampleDefault );
m_media = h.boolAttribute( "media", false );
m_minimumReuse = h.doubleAttribute( "minimum_reuse", minimumReuseDefault );
m_nearestCount = h.intAttribute( "nearest_count", nearestCountDefault );
m_normal = h.boolAttribute( "normal", false );
m_pretraceStart = h.doubleAttribute( "pretrace_start", pretraceStartDefault );
m_pretraceEnd = h.doubleAttribute( "pretrace_end", pretraceEndDefault );
m_recursionLimit = h.intAttribute( "recursion_limit", recursionLimitDefault );
}
void PMRadiosity::setAdcBailout( double ab )
{
if( ab != m_adcBailout )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMAdcBailoutID, m_adcBailout );
m_adcBailout = ab;
}
}
void PMRadiosity::setAlwaysSample( bool as )
{
if( as != m_alwaysSample )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMAlwaysSampleID, m_alwaysSample );
m_alwaysSample = as;
}
}
void PMRadiosity::setBrightness( double b )
{
if( b != m_brightness )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMBrightnessID, m_brightness );
m_brightness = b;
}
}
void PMRadiosity::setCount( int c )
{
if( c != m_count )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMCountID, m_count );
m_count = c;
}
}
void PMRadiosity::setErrorBound( double eb )
{
if( eb != m_errorBound )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMErrorBoundID, m_errorBound );
m_errorBound = eb;
}
}
void PMRadiosity::setGrayThreshold( double gt )
{
if( gt != m_grayThreshold )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMGrayThresholdID, m_grayThreshold );
m_grayThreshold = gt;
}
}
void PMRadiosity::setLowErrorFactor( double lew )
{
if( lew != m_lowErrorFactor )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMLowErrorFactorID, m_lowErrorFactor );
m_lowErrorFactor = lew;
}
}
void PMRadiosity::setMaxSample( double ms )
{
if( ms != m_maxSample )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMMaxSampleID, m_maxSample );
m_maxSample = ms;
}
}
void PMRadiosity::setMedia( bool m )
{
if( m != m_media )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMMediaID, m_media );
m_media = m;
}
}
void PMRadiosity::setMinimumReuse( double c )
{
if( c != m_minimumReuse )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMMinimumReuseID, m_minimumReuse );
m_minimumReuse = c;
}
}
void PMRadiosity::setNearestCount( int c )
{
if( c != m_nearestCount )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMNearestCountID, m_nearestCount );
m_nearestCount = c;
}
}
void PMRadiosity::setNormal( bool n )
{
if( n != m_normal )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMNormalID, m_normal );
m_normal = n;
}
}
void PMRadiosity::setPretraceStart( double ps )
{
if ( ps < m_pretraceEnd )
{
kdError( PMArea ) << "Pretrace Start < Pretrace End in PMRadiosity::setPretraceStart\n";
ps = m_pretraceEnd;
}
if( ps != m_pretraceStart )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMPretraceStartID, m_pretraceStart );
m_pretraceStart = ps;
}
}
void PMRadiosity::setPretraceEnd( double pe )
{
if ( pe > m_pretraceStart )
{
kdError( PMArea ) << "Pretrace End > Pretrace Start in PMRadiosity::setPretraceEnd\n";
pe = m_pretraceStart;
}
if( pe != m_pretraceEnd )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMPretraceEndID, m_pretraceEnd );
m_pretraceEnd = pe;
}
}
void PMRadiosity::setRecursionLimit( int c )
{
if( c != m_recursionLimit )
{
if( m_pMemento )
m_pMemento->addData( s_pMetaObject, PMRecursionLimitID, m_recursionLimit );
m_recursionLimit = c;
}
}
PMDialogEditBase* PMRadiosity::editWidget( TQWidget* parent ) const
{
return new PMRadiosityEdit( parent );
}
void PMRadiosity::restoreMemento( PMMemento* s )
{
PMMementoDataIterator it( s );
PMMementoData* data;
for( ; it.current( ); ++it )
{
data = it.current( );
if( data->objectType( ) == s_pMetaObject )
{
switch( data->valueID( ) )
{
case PMAdcBailoutID:
setAdcBailout( data->doubleData( ) );
break;
case PMAlwaysSampleID:
setAlwaysSample( data->boolData( ) );
break;
case PMBrightnessID:
setBrightness( data->doubleData( ) );
break;
case PMCountID:
setCount( data->intData( ) );
break;
case PMErrorBoundID:
setErrorBound( data->doubleData( ) );
break;
case PMGrayThresholdID:
setGrayThreshold( data->doubleData( ) );
break;
case PMLowErrorFactorID:
setLowErrorFactor( data->doubleData( ) );
break;
case PMMaxSampleID:
setMaxSample( data->doubleData( ) );
break;
case PMMediaID:
setMedia( data->boolData( ) );
break;
case PMMinimumReuseID:
setMinimumReuse( data->doubleData( ) );
break;
case PMNearestCountID:
setNearestCount( data->intData( ) );
break;
case PMNormalID:
setNormal( data->boolData( ) );
break;
case PMPretraceStartID:
setPretraceStart( data->doubleData( ) );
break;
case PMPretraceEndID:
setPretraceEnd( data->doubleData( ) );
break;
case PMRecursionLimitID:
setRecursionLimit( data->intData( ) );
break;
default:
kdError( PMArea ) << "Wrong ID in PMRadiosity::restoreMemento\n";
break;
}
}
}
Base::restoreMemento( s );
}
|