2
// Copyright ļæ½ 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Implements the CqAttributes class for handling RenderMan attributes.
23
\author Paul C. Gregory (pgregory@aqsis.com)
28
#include "attributes.h"
31
#include "trimcurve.h"
32
#include "imagebuffer.h"
35
START_NAMESPACE( Aqsis )
38
std::list<CqAttributes*> Attribute_stack;
41
const TqInt CqAttributes::CqHashTable::tableSize = 127;
44
/** A macro to take care of adding a system attribute given a name.
45
* Creates a new CqParameter derived class, initialises it to the given default value and
46
* adds it to the default attributes member.
48
#define ADD_SYSTEM_ATTR(name, type, sltype, id, def) \
49
CqParameterTypedUniform<type,id, sltype>* p##name = new CqParameterTypedUniform<type,id, sltype>(#name); \
50
p##name->pValue()[0] = ( def ); \
51
pdefattrs->AddParameter(p##name);
53
/** A macro to take care of adding a system attribute given a name.
54
* Creates a new CqParameter derived class, initialises it to the given default value and
55
* adds it to the default attributes member.
57
#define ADD_SYSTEM_ATTR2(name, type, sltype, id, def0, def1) \
58
CqParameterTypedUniformArray<type,id, sltype>* p##name = new CqParameterTypedUniformArray<type,id, sltype>(#name,2); \
59
p##name->pValue()[0] = ( def0 ); \
60
p##name->pValue()[1] = ( def1 ); \
61
pdefattrs->AddParameter(p##name);
63
/** A macro to take care of adding a system attribute given a name.
64
* Creates a new CqParameter derived class, initialises it to the given default value and
65
* adds it to the default attributes member.
67
#define ADD_SYSTEM_ATTR4(name, type, sltype, id, def0, def1, def2, def3) \
68
CqParameterTypedUniformArray<type,id, sltype>* p##name = new CqParameterTypedUniformArray<type,id, sltype>(#name,4); \
69
p##name->pValue()[0] = ( def0 ); \
70
p##name->pValue()[1] = ( def1 ); \
71
p##name->pValue()[2] = ( def2 ); \
72
p##name->pValue()[3] = ( def3 ); \
73
pdefattrs->AddParameter(p##name);
75
/** A macro to take care of adding a system attribute given a name.
76
* Creates a new CqParameter derived class, initialises it to the given default value and
77
* adds it to the default attributes member.
79
#define ADD_SYSTEM_ATTR6(name, type, sltype, id, def0, def1, def2, def3, def4, def5) \
80
CqParameterTypedUniformArray<type,id, sltype>* p##name = new CqParameterTypedUniformArray<type,id, sltype>(#name,8); \
81
p##name->pValue()[0] = ( def0 ); \
82
p##name->pValue()[1] = ( def1 ); \
83
p##name->pValue()[2] = ( def2 ); \
84
p##name->pValue()[3] = ( def3 ); \
85
p##name->pValue()[4] = ( def4 ); \
86
p##name->pValue()[5] = ( def5 ); \
87
pdefattrs->AddParameter(p##name);
90
/** A macro to take care of adding a system attribute given a name.
91
* Creates a new CqParameter derived class, initialises it to the given default value and
92
* adds it to the default attributes member.
94
#define ADD_SYSTEM_ATTR8(name, type, sltype, id, def0, def1, def2, def3, def4, def5, def6, def7) \
95
CqParameterTypedUniformArray<type,id, sltype>* p##name = new CqParameterTypedUniformArray<type,id, sltype>(#name,8); \
96
p##name->pValue()[0] = ( def0 ); \
97
p##name->pValue()[1] = ( def1 ); \
98
p##name->pValue()[2] = ( def2 ); \
99
p##name->pValue()[3] = ( def3 ); \
100
p##name->pValue()[4] = ( def4 ); \
101
p##name->pValue()[5] = ( def5 ); \
102
p##name->pValue()[6] = ( def6 ); \
103
p##name->pValue()[7] = ( def7 ); \
104
pdefattrs->AddParameter(p##name);
106
//---------------------------------------------------------------------
110
CqAttributes::CqAttributes()
112
Attribute_stack.push_front( this );
113
m_StackIterator = Attribute_stack.begin();
115
boost::shared_ptr<CqNamedParameterList> pdefattrs( new CqNamedParameterList( "System" ) );
117
ADD_SYSTEM_ATTR( Color, CqColor, CqColor, type_color, CqColor( 1.0f, 1.0f, 1.0f ) ); // the current color attribute.
118
ADD_SYSTEM_ATTR( Opacity, CqColor, CqColor, type_color, CqColor( 1.0f, 1.0f, 1.0f ) ); // the current opacity attribute.
119
ADD_SYSTEM_ATTR8( TextureCoordinates, TqFloat, TqFloat, type_float, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f ); // an array of 2D vectors representing the coordinate space.
120
ADD_SYSTEM_ATTR( ShadingRate, TqFloat, TqFloat, type_float, 1.0f ); // the current effective shading rate.
121
ADD_SYSTEM_ATTR( ShadingRateSqrt, TqFloat, TqFloat, type_float, 1.0f ); // the current effective sqrt(shading rate).
122
ADD_SYSTEM_ATTR( ShadingInterpolation, TqFloat, TqInt, type_integer, ShadingConstant ); // the current shading interpolation mode.
123
ADD_SYSTEM_ATTR( Matte, TqInt, TqFloat, type_integer, 0 ); // the current state of the matte flag.
124
ADD_SYSTEM_ATTR4( DetailRange, TqFloat, TqFloat, type_float, 0.0f, 0.0f, FLT_MAX, FLT_MAX ); // the detail range minimum visible distance.
125
ADD_SYSTEM_ATTR2( Basis, CqMatrix, CqMatrix, type_matrix, RiBezierBasis, RiBezierBasis ); // the basis matrix for the u direction.
126
ADD_SYSTEM_ATTR2( BasisStep, TqInt, TqFloat, type_integer, 3, 3 ); // the steps to advance the evaluation window in the u direction.
127
ADD_SYSTEM_ATTR( Orientation, TqInt, TqFloat, type_integer, 0 ); // the orientation associated primitives are described in.
128
ADD_SYSTEM_ATTR( Sides, TqInt, TqFloat, type_integer, 2 ); // the number of visible sides associated primitives have.
129
ADD_SYSTEM_ATTR( LevelOfDetailRulerSize, TqFloat, TqFloat, type_float, FLT_MAX ); // current LOD ruler size
130
ADD_SYSTEM_ATTR2( LevelOfDetailBounds, TqFloat, TqFloat, type_float, 0.0f, 1.0f ); // relative importance bounds for this LOD representation
132
AddAttribute( pdefattrs );
136
//---------------------------------------------------------------------
137
/** Copy constructor.
140
CqAttributes::CqAttributes( const CqAttributes& From )
144
// Register ourself with the global attribute stack.
145
Attribute_stack.push_front( this );
146
m_StackIterator = Attribute_stack.begin();
150
//---------------------------------------------------------------------
154
CqAttributes::~CqAttributes()
156
assert( RefCount() == 0 );
158
// Unreference the system attributes.
159
// TqInt i = m_aAttributes.size();
162
// m_aAttributes[ i ] ->Release();
163
// m_aAttributes[ i ] = 0;
166
// Remove ourself from the stack
167
Attribute_stack.erase( m_StackIterator );
170
//---------------------------------------------------------------------
174
CqAttributes& CqAttributes::operator=( const CqAttributes& From )
176
// Copy the system attributes.
177
// m_aAttributes.resize( From.m_aAttributes.size() );
178
// TqInt i = From.m_aAttributes.size();
181
// m_aAttributes[ i ] = From.m_aAttributes[ i ];
182
// m_aAttributes[ i ] ->AddRef();
184
m_aAttributes = From.m_aAttributes;
186
m_apLightsources = From.m_apLightsources;
188
m_pshadDisplacement = From.m_pshadDisplacement;
189
m_pshadAreaLightSource = From.m_pshadAreaLightSource;
190
m_pshadSurface = From.m_pshadSurface;
191
m_pshadAtmosphere = From.m_pshadAtmosphere;
192
m_pshadInteriorVolume = From.m_pshadInteriorVolume;
193
m_pshadExteriorVolume = From.m_pshadExteriorVolume;
199
//---------------------------------------------------------------------
200
/** Get a system attribute parameter.
201
* \param strName The name of the attribute.
202
* \param strParam The name of the paramter on the attribute.
203
* \return CqParameter pointer or 0 if not found.
206
const CqParameter* CqAttributes::pParameter( const char* strName, const char* strParam ) const
208
const CqNamedParameterList* pList = pAttribute( strName ).get();
211
return ( pList->pParameter( strParam ) );
217
//---------------------------------------------------------------------
218
/** Get a system attribute parameter.
219
* \param strName The name of the attribute.
220
* \param strParam The name of the paramter on the attribute.
221
* \return CqParameter pointer or 0 if not found.
224
CqParameter* CqAttributes::pParameterWrite( const char* strName, const char* strParam )
226
CqNamedParameterList * pList = pAttributeWrite( strName ).get();
229
return (pList->pParameter( strParam ) );
235
//---------------------------------------------------------------------
236
/** Get a float system attribute parameter.
237
* \param strName The name of the attribute.
238
* \param strParam The name of the paramter on the attribute.
239
* \return Float pointer 0 if not found.
242
TqFloat* CqAttributes::GetFloatAttributeWrite( const char* strName, const char* strParam )
244
CqParameter * pParam = pParameterWrite( strName, strParam );
246
return ( static_cast<CqParameterTyped<TqFloat, TqFloat>*>( pParam ) ->pValue() );
252
//---------------------------------------------------------------------
253
/** Get an integer system attribute parameter.
254
* \param strName The name of the attribute.
255
* \param strParam The name of the paramter on the attribute.
256
* \return Integer pointer 0 if not found.
259
TqInt* CqAttributes::GetIntegerAttributeWrite( const char* strName, const char* strParam )
261
CqParameter * pParam = pParameterWrite( strName, strParam );
263
return ( static_cast<CqParameterTyped<TqInt, TqFloat>*>( pParam ) ->pValue() );
269
//---------------------------------------------------------------------
270
/** Get a string system attribute parameter.
271
* \param strName The name of the attribute.
272
* \param strParam The name of the paramter on the attribute.
273
* \return CqString pointer 0 if not found.
276
CqString* CqAttributes::GetStringAttributeWrite( const char* strName, const char* strParam )
278
CqParameter * pParam = pParameterWrite( strName, strParam );
280
return ( static_cast<CqParameterTyped<CqString, CqString>*>( pParam ) ->pValue() );
286
//---------------------------------------------------------------------
287
/** Get a point system attribute parameter.
288
* \param strName The name of the attribute.
289
* \param strParam The name of the paramter on the attribute.
290
* \return CqVetor3D pointer 0 if not found.
293
CqVector3D* CqAttributes::GetPointAttributeWrite( const char* strName, const char* strParam )
295
CqParameter * pParam = pParameterWrite( strName, strParam );
297
return ( static_cast<CqParameterTyped<CqVector3D, CqVector3D>*>( pParam ) ->pValue() );
303
//---------------------------------------------------------------------
304
/** Get a vector system attribute parameter.
305
* \param strName The name of the attribute.
306
* \param strParam The name of the paramter on the attribute.
307
* \return CqVetor3D pointer 0 if not found.
310
CqVector3D* CqAttributes::GetVectorAttributeWrite( const char* strName, const char* strParam )
312
return ( GetPointAttributeWrite( strName, strParam ) );
316
//---------------------------------------------------------------------
317
/** Get a normal system attribute parameter.
318
* \param strName The name of the attribute.
319
* \param strParam The name of the paramter on the attribute.
320
* \return CqVetor3D pointer 0 if not found.
323
CqVector3D* CqAttributes::GetNormalAttributeWrite( const char* strName, const char* strParam )
325
return ( GetPointAttributeWrite( strName, strParam ) );
329
//---------------------------------------------------------------------
330
/** Get a color system attribute parameter.
331
* \param strName The name of the attribute.
332
* \param strParam The name of the paramter on the attribute.
333
* \return CqColor pointer 0 if not found.
336
CqColor* CqAttributes::GetColorAttributeWrite( const char* strName, const char* strParam )
338
CqParameter * pParam = pParameterWrite( strName, strParam );
340
return ( static_cast<CqParameterTyped<CqColor, CqColor>*>( pParam ) ->pValue() );
346
//---------------------------------------------------------------------
347
/** Get a matrix system attribute parameter.
348
* \param strName The name of the attribute.
349
* \param strParam The name of the paramter on the attribute.
350
* \return CqMatrix pointer 0 if not found.
353
CqMatrix* CqAttributes::GetMatrixAttributeWrite( const char* strName, const char* strParam )
355
CqParameter * pParam = pParameterWrite( strName, strParam );
357
return ( static_cast<CqParameterTyped<CqMatrix, CqMatrix>*>( pParam ) ->pValue() );
363
//---------------------------------------------------------------------
364
/** Get a float system attribute parameter.
365
* \param strName The name of the attribute.
366
* \param strParam The name of the paramter on the attribute.
367
* \return Float pointer 0 if not found.
370
const TqFloat* CqAttributes::GetFloatAttribute( const char* strName, const char* strParam ) const
372
const CqParameter * pParam = pParameter( strName, strParam );
374
return ( static_cast<const CqParameterTyped<TqFloat, TqFloat>*>( pParam ) ->pValue() );
380
//---------------------------------------------------------------------
381
/** Get an integer system attribute parameter.
382
* \param strName The name of the attribute.
383
* \param strParam The name of the paramter on the attribute.
384
* \return Integer pointer 0 if not found.
387
const TqInt* CqAttributes::GetIntegerAttribute( const char* strName, const char* strParam ) const
389
const CqParameter * pParam = pParameter( strName, strParam );
391
return ( static_cast<const CqParameterTyped<TqInt, TqFloat>*>( pParam ) ->pValue() );
397
//---------------------------------------------------------------------
398
/** Get a string system attribute parameter.
399
* \param strName The name of the attribute.
400
* \param strParam The name of the paramter on the attribute.
401
* \return CqString pointer 0 if not found.
404
const CqString* CqAttributes::GetStringAttribute( const char* strName, const char* strParam ) const
406
const CqParameter * pParam = pParameter( strName, strParam );
408
return ( static_cast<const CqParameterTyped<CqString, CqString>*>( pParam ) ->pValue() );
414
//---------------------------------------------------------------------
415
/** Get a point system attribute parameter.
416
* \param strName The name of the attribute.
417
* \param strParam The name of the paramter on the attribute.
418
* \return CqVector3D pointer 0 if not found.
421
const CqVector3D* CqAttributes::GetPointAttribute( const char* strName, const char* strParam ) const
423
const CqParameter * pParam = pParameter( strName, strParam );
425
return ( static_cast<const CqParameterTyped<CqVector3D, CqVector3D>*>( pParam ) ->pValue() );
431
//---------------------------------------------------------------------
432
/** Get a vector system attribute parameter.
433
* \param strName The name of the attribute.
434
* \param strParam The name of the paramter on the attribute.
435
* \return CqVector3D pointer 0 if not found.
438
const CqVector3D* CqAttributes::GetVectorAttribute( const char* strName, const char* strParam ) const
440
return ( GetPointAttribute( strName, strParam ) );
444
//---------------------------------------------------------------------
445
/** Get a normal system attribute parameter.
446
* \param strName The name of the attribute.
447
* \param strParam The name of the paramter on the attribute.
448
* \return CqVector3D pointer 0 if not found.
451
const CqVector3D* CqAttributes::GetNormalAttribute( const char* strName, const char* strParam ) const
453
return ( GetPointAttribute( strName, strParam ) );
457
//---------------------------------------------------------------------
458
/** Get a color system attribute parameter.
459
* \param strName The name of the attribute.
460
* \param strParam The name of the paramter on the attribute.
461
* \return CqColor pointer 0 if not found.
464
const CqColor* CqAttributes::GetColorAttribute( const char* strName, const char* strParam ) const
466
const CqParameter * pParam = pParameter( strName, strParam );
468
return ( static_cast<const CqParameterTyped<CqColor, CqColor>*>( pParam ) ->pValue() );
474
//---------------------------------------------------------------------
475
/** Get a matrix system attribute parameter.
476
* \param strName The name of the attribute.
477
* \param strParam The name of the paramter on the attribute.
478
* \return CqMatrix pointer 0 if not found.
481
const CqMatrix* CqAttributes::GetMatrixAttribute( const char* strName, const char* strParam ) const
483
const CqParameter * pParam = pParameter( strName, strParam );
485
return ( static_cast<const CqParameterTyped<CqMatrix, CqMatrix>*>( pParam ) ->pValue() );
491
IqLightsource* CqAttributes::pLight( TqInt index )
493
return ( m_apLightsources[ index ].get() );
496
//---------------------------------------------------------------------
498
END_NAMESPACE( Aqsis )