~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libri2rib/output.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright  1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU Lesser General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2.1 of the License, or (at your option) any later version.
 
10
//
 
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.
 
15
//
 
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
 
19
 
 
20
/** \file
 
21
 *  \brief Libri2rib output base class implementation.
 
22
 *  \author Lionel J. Lacour (intuition01@online.fr)
 
23
 */
 
24
 
 
25
#ifdef  WIN32
 
26
#pragma warning(disable : 4786)
 
27
#endif
 
28
 
 
29
#include "output.h"
 
30
#include "error.h"
 
31
#include "inlineparse.h"
 
32
#include "context.h"
 
33
 
 
34
USING_NAMESPACE( libri2rib );
 
35
 
 
36
#define PR(x,y)  printRequest(x,y)
 
37
#ifdef  PI
 
38
#undef  PI
 
39
#endif
 
40
#define PI(x)  printInteger(x)
 
41
#define PF(x)  printFloat(x)
 
42
#define PS(x)  printString(x)
 
43
#define S   printSpace()
 
44
#define EOL printEOL()
 
45
 
 
46
 
 
47
 
 
48
CqOutput::CqOutput( const char *name, int fdesc,
 
49
                    SqOptions::EqCompression comp,
 
50
                    SqOptions::EqIndentation i, TqInt isize )
 
51
        :
 
52
        m_ColorNComps( 3 ),
 
53
        m_ObjectHandle( 0 ),
 
54
        m_LightHandle( 0 ),
 
55
        m_Indentation( i ),
 
56
        m_IndentSize( isize ),
 
57
        m_IndentLevel( 0 )
 
58
{
 
59
    switch ( comp )
 
60
    {
 
61
    case SqOptions::Compression_None:
 
62
        out = new CqStreamFDesc();
 
63
        break;
 
64
    case SqOptions::Compression_Gzip:
 
65
        out = new CqStreamGzip();
 
66
        break;
 
67
    }
 
68
 
 
69
    if ( name != RI_NULL )
 
70
    {
 
71
        out->openFile( name );
 
72
    }
 
73
    else
 
74
    {
 
75
        out->openFile( fdesc );
 
76
    }
 
77
 
 
78
    SqSteps a = {RI_BEZIERSTEP, RI_BEZIERSTEP};
 
79
    m_Steps.push( a );
 
80
}
 
81
 
 
82
CqOutput::~CqOutput()
 
83
{
 
84
    out->closeFile();
 
85
    delete out;
 
86
}
 
87
 
 
88
 
 
89
 
 
90
 
 
91
 
 
92
// *********************************************************************
 
93
// ******* ******* ******* STEPS STACK FUNCTIONS ******* ******* *******
 
94
// *********************************************************************
 
95
void CqOutput::push()
 
96
{
 
97
    m_Steps.push( m_Steps.top() );
 
98
}
 
99
void CqOutput::pop()
 
100
{
 
101
    if ( m_Steps.size() == 0 )
 
102
    {
 
103
        return ;
 
104
    }
 
105
    m_Steps.pop();
 
106
}
 
107
 
 
108
 
 
109
 
 
110
 
 
111
 
 
112
// **************************************************************
 
113
// ******* ******* ******* PRINTING TOOLS ******* ******* *******
 
114
// **************************************************************
 
115
void CqOutput::printPL( RtInt n, RtToken tokens[], RtPointer parms[],
 
116
                        RtInt vertex, RtInt varying, RtInt uniform, RtInt facevarying )
 
117
{
 
118
    RtFloat * flt;
 
119
    RtInt *nt;
 
120
    char **cp;
 
121
 
 
122
    TqTokenId id;
 
123
    EqTokenType tt;
 
124
 
 
125
    RtInt i;
 
126
    TqUint j;
 
127
    TqUint sz;
 
128
    for ( i = 0; i < n ; i++ )
 
129
    {
 
130
        try
 
131
        {
 
132
            id = m_Dictionary.getTokenId( std::string( tokens[ i ] ) );
 
133
        }
 
134
        catch ( CqError & r )
 
135
        {
 
136
            r.manage();
 
137
            continue;
 
138
        }
 
139
 
 
140
        printToken( tokens[ i ] ); S;
 
141
        tt = m_Dictionary.getType( id );
 
142
        sz = m_Dictionary.allocSize( id, vertex, varying, uniform, facevarying);
 
143
 
 
144
        switch ( tt )
 
145
        {
 
146
        case FLOAT:
 
147
        case POINT:
 
148
        case VECTOR:
 
149
        case NORMAL:
 
150
        case MATRIX:
 
151
        case HPOINT:
 
152
            flt = static_cast<RtFloat *> ( parms[ i ] );
 
153
            printArray( sz, flt );
 
154
            break;
 
155
        case COLOR:
 
156
            flt = static_cast<RtFloat *> ( parms[ i ] );
 
157
            printArray( sz * m_ColorNComps, flt );
 
158
            break;
 
159
        case STRING:
 
160
            cp = static_cast<char **> ( parms[ i ] );
 
161
            print( "[" ); S;
 
162
            for ( j = 0; j < sz; j++ )
 
163
            {
 
164
                printCharP( cp[ j ] ); S;
 
165
            }
 
166
            print( "]" );
 
167
            break;
 
168
        case INTEGER:
 
169
            nt = static_cast<RtInt *> ( parms[ i ] );
 
170
            printArray( sz, nt );
 
171
            break;
 
172
        }
 
173
        S;
 
174
    }
 
175
    EOL;
 
176
}
 
177
 
 
178
std::string CqOutput::getFilterFuncName( RtFilterFunc filterfunc, const char *name ) const
 
179
{
 
180
    if ( filterfunc == RiBoxFilter ) return "box";
 
181
    else if ( filterfunc == RiTriangleFilter ) return "triangle";
 
182
    else if ( filterfunc == RiCatmullRomFilter ) return "catmull-rom";
 
183
    else if ( filterfunc == RiSincFilter ) return "sinc";
 
184
    else if ( filterfunc == RiGaussianFilter ) return "gaussian";
 
185
    else if ( filterfunc == RiDiskFilter ) return "disk";
 
186
    else if ( filterfunc == RiBesselFilter ) return "bessel";
 
187
    else
 
188
    {
 
189
        throw CqError( RIE_CONSISTENCY, RIE_WARNING,
 
190
                       "Unknown RiFilterFunc. ",
 
191
                       name, " function skipped.", TqTrue );
 
192
        return "";
 
193
    }
 
194
}
 
195
 
 
196
 
 
197
 
 
198
 
 
199
// *****************************************************************
 
200
// ******* ******* ******* OUTPUT FUNCTIONS  ******* ******* *******
 
201
// *****************************************************************
 
202
RtToken CqOutput::RiDeclare( const char *name, const char *declaration )
 
203
{
 
204
    CqInlineParse ip;
 
205
    std::string a( name );
 
206
    std::string b( declaration );
 
207
 
 
208
    b += " ";
 
209
    b += a;
 
210
    ip.parse( b );
 
211
    m_Dictionary.addToken( ip.getIdentifier(), ip.getClass(), ip.getType(), ip.getQuantity(), TqFalse );
 
212
 
 
213
    PR( "Declare", Declare ); S;
 
214
    printCharP( name ); S;
 
215
    printCharP( declaration );
 
216
    EOL;
 
217
 
 
218
    return const_cast<RtToken> ( name );
 
219
}
 
220
 
 
221
RtVoid CqOutput::RiBegin( RtToken name )
 
222
{
 
223
    printHeader();
 
224
}
 
225
 
 
226
RtVoid CqOutput::RiEnd( RtVoid )
 
227
{
 
228
    out->flushFile();
 
229
}
 
230
 
 
231
RtVoid CqOutput::RiFrameBegin( RtInt frame )
 
232
{
 
233
    PR( "FrameBegin", FrameBegin ); S;
 
234
    PI( frame );
 
235
    EOL;
 
236
 
 
237
    m_IndentLevel++;
 
238
    push();
 
239
}
 
240
 
 
241
RtVoid CqOutput::RiFrameEnd( RtVoid )
 
242
{
 
243
    m_IndentLevel--;
 
244
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
245
    pop();
 
246
 
 
247
    PR( "FrameEnd", FrameEnd );
 
248
    EOL;
 
249
}
 
250
 
 
251
RtVoid CqOutput::RiWorldBegin( RtVoid )
 
252
{
 
253
    PR( "WorldBegin", WorldBegin );
 
254
    EOL;
 
255
 
 
256
    m_IndentLevel++;
 
257
    push();
 
258
}
 
259
 
 
260
RtVoid CqOutput::RiWorldEnd( RtVoid )
 
261
{
 
262
    m_IndentLevel--;
 
263
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
264
    pop();
 
265
 
 
266
    PR( "WorldEnd", WorldEnd );
 
267
    EOL;
 
268
}
 
269
 
 
270
RtObjectHandle CqOutput::RiObjectBegin( RtVoid )
 
271
{
 
272
    PR( "ObjectBegin", ObjectBegin ); S;
 
273
    PI( ( RtInt ) m_ObjectHandle );
 
274
    EOL;
 
275
 
 
276
    m_IndentLevel++;
 
277
    push();
 
278
    return ( RtObjectHandle ) m_ObjectHandle++;
 
279
}
 
280
 
 
281
RtVoid CqOutput::RiObjectEnd( RtVoid )
 
282
{
 
283
    m_IndentLevel--;
 
284
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
285
    pop();
 
286
 
 
287
    PR( "ObjectEnd", ObjectEnd );
 
288
    EOL;
 
289
}
 
290
 
 
291
RtVoid CqOutput::RiObjectInstance( RtObjectHandle handle )
 
292
{
 
293
    PR( "ObjectInstance", ObjectInstance ); S;
 
294
    PI( ( RtInt ) handle );
 
295
    EOL;
 
296
}
 
297
 
 
298
RtVoid CqOutput::RiAttributeBegin( RtVoid )
 
299
{
 
300
    PR( "AttributeBegin", AttributeBegin );
 
301
    EOL;
 
302
 
 
303
    m_IndentLevel++;
 
304
    push();
 
305
}
 
306
 
 
307
RtVoid CqOutput::RiAttributeEnd( RtVoid )
 
308
{
 
309
    m_IndentLevel--;
 
310
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
311
    pop();
 
312
 
 
313
    PR( "AttributeEnd", AttributeEnd );
 
314
    EOL;
 
315
}
 
316
 
 
317
RtVoid CqOutput::RiTransformBegin( RtVoid )
 
318
{
 
319
    PR( "TransformBegin", TransformBegin );
 
320
    EOL;
 
321
 
 
322
    m_IndentLevel++;
 
323
}
 
324
 
 
325
RtVoid CqOutput::RiTransformEnd( RtVoid )
 
326
{
 
327
    m_IndentLevel--;
 
328
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
329
 
 
330
    PR( "TransformEnd", TransformEnd );
 
331
    EOL;
 
332
}
 
333
 
 
334
RtVoid CqOutput::RiSolidBegin( RtToken operation )
 
335
{
 
336
    PR( "SolidBegin", SolidBegin ); S;
 
337
    printToken( operation );
 
338
    EOL;
 
339
 
 
340
    m_IndentLevel++;
 
341
    push();
 
342
}
 
343
 
 
344
RtVoid CqOutput::RiSolidEnd( RtVoid )
 
345
{
 
346
    m_IndentLevel--;
 
347
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
348
    pop();
 
349
 
 
350
    PR( "SolidEnd", SolidEnd );
 
351
    EOL;
 
352
}
 
353
 
 
354
RtVoid CqOutput::RiMotionBeginV( RtInt n, RtFloat times[] )
 
355
{
 
356
    PR( "MotionBegin", MotionBegin ); S;
 
357
    printArray( n, times );
 
358
    EOL;
 
359
 
 
360
    m_IndentLevel++;
 
361
}
 
362
 
 
363
RtVoid CqOutput::RiMotionEnd( RtVoid )
 
364
{
 
365
    m_IndentLevel--;
 
366
    if ( m_IndentLevel < 0 ) m_IndentLevel = 0;
 
367
 
 
368
    PR( "MotionEnd", MotionEnd );
 
369
    EOL;
 
370
}
 
371
 
 
372
 
 
373
 
 
374
 
 
375
// **************************************************************
 
376
// ******* ******* ******* CAMERA OPTIONS ******* ******* *******
 
377
// **************************************************************
 
378
RtVoid CqOutput::RiFormat ( RtInt xres, RtInt yres, RtFloat aspect )
 
379
{
 
380
    PR( "Format", Format ); S;
 
381
    PI( xres ); S;
 
382
    PI( yres ); S;
 
383
    PF( aspect );
 
384
    EOL;
 
385
}
 
386
 
 
387
RtVoid CqOutput::RiFrameAspectRatio ( RtFloat aspect )
 
388
{
 
389
    PR( "FrameAspectRatio", FrameAspectRatio ); S;
 
390
    PF( aspect );
 
391
    EOL;
 
392
}
 
393
 
 
394
RtVoid CqOutput::RiScreenWindow ( RtFloat left, RtFloat right, RtFloat bottom, RtFloat top )
 
395
{
 
396
    PR( "ScreenWindow", ScreenWindow ); S;
 
397
    PF( left ); S;
 
398
    PF( right ); S;
 
399
    PF( bottom ); S;
 
400
    PF( top );
 
401
    EOL;
 
402
}
 
403
 
 
404
RtVoid CqOutput::RiCropWindow ( RtFloat xmin, RtFloat xmax, RtFloat ymin, RtFloat ymax )
 
405
{
 
406
    PR( "CropWindow", CropWindow ); S;
 
407
    PF( xmin ); S;
 
408
    PF( xmax ); S;
 
409
    PF( ymin ); S;
 
410
    PF( ymax );
 
411
    EOL;
 
412
}
 
413
 
 
414
RtVoid CqOutput::RiProjectionV ( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
415
{
 
416
    PR( "Projection", Projection ); S;
 
417
    printCharP( name ); S;
 
418
    printPL( n, tokens, parms );
 
419
}
 
420
 
 
421
RtVoid CqOutput::RiClipping( RtFloat hither, RtFloat yon )
 
422
{
 
423
    PR( "Clipping", Clipping ); S;
 
424
    PF( hither ); S;
 
425
    PF( yon );
 
426
    EOL;
 
427
}
 
428
 
 
429
RtVoid CqOutput::RiClippingPlane( RtFloat x, RtFloat y, RtFloat z,
 
430
                                  RtFloat nx, RtFloat ny, RtFloat nz )
 
431
{
 
432
    PR( "ClippingPlane", ClippingPlane ); S;
 
433
    PF( x ); S;
 
434
    PF( y ); S;
 
435
    PF( z ); S;
 
436
    PF( nx ); S;
 
437
    PF( ny ); S;
 
438
    PF( nz );
 
439
    EOL;
 
440
}
 
441
 
 
442
RtVoid CqOutput::RiDepthOfField ( RtFloat fstop, RtFloat focallength, RtFloat focaldistance )
 
443
{
 
444
    PR( "DepthOfField", DepthOfField ); S;
 
445
    PF( fstop ); S;
 
446
    PF( focallength ); S;
 
447
    PF( focaldistance );
 
448
    EOL;
 
449
}
 
450
 
 
451
RtVoid CqOutput::RiShutter( RtFloat min, RtFloat max )
 
452
{
 
453
    PR( "Shutter", Shutter ); S;
 
454
    PF( min ); S;
 
455
    PF( max );
 
456
    EOL;
 
457
}
 
458
 
 
459
 
 
460
 
 
461
 
 
462
// ***************************************************************
 
463
// ******* ******* ******* DISPLAY OPTIONS ******* ******* *******
 
464
// ***************************************************************
 
465
RtVoid CqOutput::RiPixelVariance( RtFloat variation )
 
466
{
 
467
    PR( "PixelVariance", PixelVariance ); S;
 
468
    PF( variation );
 
469
    EOL;
 
470
}
 
471
 
 
472
RtVoid CqOutput::RiPixelSamples( RtFloat xsamples, RtFloat ysamples )
 
473
{
 
474
    PR( "PixelSamples", PixelSamples ); S;
 
475
    PF( xsamples ); S;
 
476
    PF( ysamples );
 
477
    EOL;
 
478
}
 
479
 
 
480
RtVoid CqOutput::RiPixelFilter( RtFilterFunc filterfunc, RtFloat xwidth, RtFloat ywidth )
 
481
{
 
482
    std::string st = getFilterFuncName( filterfunc, "PixelFilter" );
 
483
    PR( "PixelFilter", PixelFilter ); S;
 
484
    PS( st ); S;
 
485
    PF( xwidth ); S;
 
486
    PF( ywidth );
 
487
    EOL;
 
488
}
 
489
 
 
490
RtVoid CqOutput::RiExposure( RtFloat gain, RtFloat gamma )
 
491
{
 
492
    PR( "Exposure", Exposure ); S;
 
493
    PF( gain ); S;
 
494
    PF( gamma );
 
495
    EOL;
 
496
}
 
497
 
 
498
RtVoid CqOutput::RiImagerV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
499
{
 
500
    PR( "Imager", Imager ); S;
 
501
    printCharP( name ); S;
 
502
    printPL( n, tokens, parms );
 
503
}
 
504
 
 
505
RtVoid CqOutput::RiQuantize( RtToken type, RtInt one, RtInt min, RtInt max, RtFloat ampl )
 
506
{
 
507
    PR( "Quantize", Quantize ); S;
 
508
    printToken( type ); S;
 
509
    PI( one ); S;
 
510
    PI( min ); S;
 
511
    PI( max ); S;
 
512
    PF( ampl );
 
513
    EOL;
 
514
}
 
515
 
 
516
RtVoid CqOutput::RiDisplayV( const char *name, RtToken type, RtToken mode,
 
517
                             RtInt n, RtToken tokens[], RtPointer parms[] )
 
518
{
 
519
    PR( "Display", Display ); S;
 
520
    printCharP( name ); S;
 
521
    printToken( type ); S;
 
522
    printToken( mode ); S;
 
523
    printPL( n, tokens, parms );
 
524
}
 
525
 
 
526
 
 
527
 
 
528
 
 
529
// ******************************************************************
 
530
// ******* ******* ******* ADDITIONAL OPTIONS ******* ******* *******
 
531
// ******************************************************************
 
532
RtVoid CqOutput::RiHiderV( const char *type, RtInt n, RtToken tokens[], RtPointer parms[] )
 
533
{
 
534
    PR( "Hider", Hider ); S;
 
535
    printCharP( type ); S;
 
536
    printPL( n, tokens, parms );
 
537
}
 
538
 
 
539
RtVoid CqOutput::RiColorSamples( RtInt n, RtFloat nRGB[], RtFloat RGBn[] )
 
540
{
 
541
    PR( "ColorSamples", ColorSamples ); S;
 
542
    printArray( n * 3, nRGB ); S;
 
543
    printArray( n * 3, RGBn );
 
544
    EOL;
 
545
 
 
546
    m_ColorNComps = n;
 
547
}
 
548
 
 
549
RtVoid CqOutput::RiRelativeDetail( RtFloat relativedetail )
 
550
{
 
551
    PR( "RelativeDetail", RelativeDetail ); S;
 
552
    PF( relativedetail );
 
553
    EOL;
 
554
}
 
555
 
 
556
RtVoid CqOutput::RiOptionV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
557
{
 
558
    PR( "Option", Option ); S;
 
559
    printCharP( name ); S;
 
560
    printPL( n, tokens, parms );
 
561
}
 
562
 
 
563
 
 
564
 
 
565
 
 
566
// ******************************************************************
 
567
// ******* ******* ******* SHADING ATTRIBUTES ******* ******* *******
 
568
// ******************************************************************
 
569
RtVoid CqOutput::RiColor( RtColor color )
 
570
{
 
571
    PR( "Color", Color ); S;
 
572
    printArray( m_ColorNComps, color );
 
573
    EOL;
 
574
}
 
575
 
 
576
RtVoid CqOutput::RiOpacity( RtColor color )
 
577
{
 
578
    PR( "Opacity", Opacity ); S;
 
579
    printArray( m_ColorNComps, color );
 
580
    EOL;
 
581
}
 
582
 
 
583
RtVoid CqOutput::RiTextureCoordinates( RtFloat s1, RtFloat t1, RtFloat s2, RtFloat t2,
 
584
                                       RtFloat s3, RtFloat t3, RtFloat s4, RtFloat t4 )
 
585
{
 
586
    PR( "TextureCoordinates", TextureCoordinates ); S;
 
587
    PF( s1 ); S;
 
588
    PF( t1 ); S;
 
589
    PF( s2 ); S;
 
590
    PF( t2 ); S;
 
591
    PF( s3 ); S;
 
592
    PF( t3 ); S;
 
593
    PF( s4 ); S;
 
594
    PF( t4 );
 
595
    EOL;
 
596
}
 
597
 
 
598
RtLightHandle CqOutput::RiLightSourceV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
599
{
 
600
    PR( "LightSource", LightSource ); S;
 
601
    printCharP( name ); S;
 
602
    PI( ( RtInt ) m_LightHandle ); S;
 
603
    printPL( n, tokens, parms );
 
604
 
 
605
    return ( RtLightHandle ) m_LightHandle++;
 
606
}
 
607
 
 
608
RtLightHandle CqOutput::RiAreaLightSourceV( const char *name,
 
609
        RtInt n, RtToken tokens[], RtPointer parms[] )
 
610
{
 
611
    PR( "AreaLightSource", AreaLightSource ); S;
 
612
    printCharP( name ); S;
 
613
    PI( ( RtInt ) m_LightHandle ); S;
 
614
    printPL( n, tokens, parms );
 
615
 
 
616
    return ( RtLightHandle ) m_LightHandle++;
 
617
}
 
618
 
 
619
RtVoid CqOutput::RiIlluminate( RtLightHandle light, RtBoolean onoff )
 
620
{
 
621
    PR( "Illuminate", Illuminate ); S;
 
622
    PI( ( RtInt ) light ); S;
 
623
 
 
624
    if ( onoff == RI_TRUE )
 
625
        print( "1" );
 
626
    else
 
627
        print( "0" );
 
628
    EOL;
 
629
}
 
630
 
 
631
RtVoid CqOutput::RiSurfaceV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
632
{
 
633
    PR( "Surface", Surface ); S;
 
634
    printCharP( name ); S;
 
635
    printPL( n, tokens, parms );
 
636
}
 
637
 
 
638
RtVoid CqOutput::RiAtmosphereV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
639
{
 
640
    PR( "Atmosphere", Atmosphere ); S;
 
641
    printCharP( name ); S;
 
642
    printPL( n, tokens, parms );
 
643
}
 
644
 
 
645
RtVoid CqOutput::RiInteriorV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
646
{
 
647
    PR( "Interior", Interior ); S;
 
648
    printCharP( name ); S;
 
649
    printPL( n, tokens, parms );
 
650
}
 
651
 
 
652
RtVoid CqOutput::RiExteriorV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
653
{
 
654
    PR( "Exterior", Exterior ); S;
 
655
    printCharP( name ); S;
 
656
    printPL( n, tokens, parms );
 
657
}
 
658
 
 
659
RtVoid CqOutput::RiShadingRate( RtFloat size )
 
660
{
 
661
    PR( "ShadingRate", ShadingRate ); S;
 
662
    PF( size );
 
663
    EOL;
 
664
}
 
665
 
 
666
RtVoid CqOutput::RiShadingInterpolation( RtToken type )
 
667
{
 
668
    PR( "ShadingInterpolation", ShadingInterpolation ); S;
 
669
    printToken( type );
 
670
    EOL;
 
671
}
 
672
 
 
673
RtVoid CqOutput::RiMatte( RtBoolean onoff )
 
674
{
 
675
    PR( "Matte", Matte ); S;
 
676
 
 
677
    if ( onoff == RI_TRUE )
 
678
        print( "1" );
 
679
    else
 
680
        print( "0" );
 
681
    EOL;
 
682
}
 
683
 
 
684
 
 
685
 
 
686
 
 
687
// *******************************************************************
 
688
// ******* ******* ******* GEOMETRY ATTRIBUTES ******* ******* *******
 
689
// *******************************************************************
 
690
RtVoid CqOutput::RiBound( RtBound b )
 
691
{
 
692
    PR( "Bound", Bound ); S;
 
693
    printArray( 6, b );
 
694
    EOL;
 
695
}
 
696
 
 
697
RtVoid CqOutput::RiDetail( RtBound d )
 
698
{
 
699
    PR( "Detail", Detail ); S;
 
700
    printArray( 6, d );
 
701
    EOL;
 
702
}
 
703
 
 
704
RtVoid CqOutput::RiDetailRange( RtFloat minvis, RtFloat lowtran, RtFloat uptran, RtFloat maxvis )
 
705
{
 
706
    PR( "DetailRange", DetailRange ); S;
 
707
    PF( minvis ); S;
 
708
    PF( lowtran ); S;
 
709
    PF( uptran ); S;
 
710
    PF( maxvis );
 
711
    EOL;
 
712
}
 
713
 
 
714
RtVoid CqOutput::RiGeometricApproximation( RtToken type, RtFloat value )
 
715
{
 
716
    PR( "GeometricApproximation", GeometricApproximation ); S;
 
717
    printToken( type ); S;
 
718
    PF( value );
 
719
    EOL;
 
720
}
 
721
 
 
722
RtVoid CqOutput::RiBasis( RtBasis ubasis, RtInt ustep, RtBasis vbasis, RtInt vstep )
 
723
{
 
724
    RtInt i;
 
725
    RtFloat m[ 16 ];
 
726
 
 
727
    PR( "Basis", Basis ); S;
 
728
    for ( i = 0; i < 16; i++ )
 
729
    {
 
730
        m[ i ] = ubasis[ i / 4 ][ i % 4 ];
 
731
    }
 
732
    printArray( 16, &( m[ 0 ] ) ); S;
 
733
    PI( ustep ); S;
 
734
 
 
735
    for ( i = 0; i < 16; i++ )
 
736
    {
 
737
        m[ i ] = vbasis[ i / 4 ][ i % 4 ];
 
738
    }
 
739
    printArray( 16, m ); S;
 
740
    PI( vstep );
 
741
    EOL;
 
742
 
 
743
    m_Steps.top().uStep = ustep;
 
744
    m_Steps.top().vStep = vstep;
 
745
}
 
746
 
 
747
RtVoid CqOutput::RiTrimCurve( RtInt nloops, RtInt ncurves[], RtInt order[],
 
748
                              RtFloat knot[], RtFloat min[], RtFloat max[], RtInt n[],
 
749
                              RtFloat u[], RtFloat v[], RtFloat w[] )
 
750
{
 
751
    RtInt i;
 
752
    RtInt ttlc = 0;
 
753
    for ( i = 0; i < nloops; i++ )
 
754
        ttlc += ncurves[ i ];
 
755
 
 
756
    RtInt nbcoords = 0;
 
757
    RtInt knotsize = 0;
 
758
    for ( i = 0; i < ttlc; i++ )
 
759
    {
 
760
        nbcoords += n[ i ];
 
761
        knotsize += order[ i ] + n[ i ];
 
762
    }
 
763
 
 
764
    PR( "TrimCurve", TrimCurve ); S;
 
765
    printArray( nloops, ncurves ); S;
 
766
    printArray( ttlc, order ); S;
 
767
    printArray( knotsize, knot ); S;
 
768
    printArray( ttlc, min ); S;
 
769
    printArray( ttlc, max ); S;
 
770
    printArray( ttlc, n ); S;
 
771
    printArray( nbcoords, u ); S;
 
772
    printArray( nbcoords, v ); S;
 
773
    printArray( nbcoords, w );
 
774
    EOL;
 
775
}
 
776
 
 
777
RtVoid CqOutput::RiOrientation( RtToken o )
 
778
{
 
779
    PR( "Orientation", Orientation ); S;
 
780
    printToken( o );
 
781
    EOL;
 
782
}
 
783
 
 
784
RtVoid CqOutput::RiReverseOrientation( RtVoid )
 
785
{
 
786
    PR( "ReverseOrientation", ReverseOrientation );
 
787
    EOL;
 
788
}
 
789
 
 
790
RtVoid CqOutput::RiSides( RtInt sides )
 
791
{
 
792
    PR( "Sides", Sides ); S;
 
793
    PI( sides );
 
794
    EOL;
 
795
}
 
796
 
 
797
RtVoid CqOutput::RiDisplacementV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
798
{
 
799
    PR( "Displacement", Displacement ); S;
 
800
    printCharP( name ); S;
 
801
    printPL( n, tokens, parms );
 
802
}
 
803
 
 
804
 
 
805
 
 
806
 
 
807
// ***************************************************************
 
808
// ******* ******* ******* TRANSFORMATIONS ******* ******* *******
 
809
// ***************************************************************
 
810
RtVoid CqOutput::RiIdentity( RtVoid )
 
811
{
 
812
    PR( "Identity", Identity );
 
813
    EOL;
 
814
}
 
815
 
 
816
RtVoid CqOutput::RiTransform( RtMatrix transform )
 
817
{
 
818
    RtFloat m[ 16 ];
 
819
    for ( RtInt i = 0; i < 16; i++ )
 
820
    {
 
821
        m[ i ] = transform[ i / 4 ][ i % 4 ];
 
822
    }
 
823
 
 
824
    PR( "Transform", Transform ); S;
 
825
    printArray( 16, &( m[ 0 ] ) );
 
826
    EOL;
 
827
}
 
828
 
 
829
RtVoid CqOutput::RiConcatTransform( RtMatrix transform )
 
830
{
 
831
    RtFloat m[ 16 ];
 
832
    for ( RtInt i = 0; i < 16; i++ )
 
833
    {
 
834
        m[ i ] = transform[ i / 4 ][ i % 4 ];
 
835
    }
 
836
 
 
837
    PR( "ConcatTransform", ConcatTransform ); S;
 
838
    printArray( 16, &( m[ 0 ] ) );
 
839
    EOL;
 
840
}
 
841
 
 
842
RtVoid CqOutput::RiPerspective( RtFloat fov )
 
843
{
 
844
    PR( "Perspective", Perspective ); S;
 
845
    PF( fov );
 
846
    EOL;
 
847
}
 
848
 
 
849
RtVoid CqOutput::RiTranslate( RtFloat dx, RtFloat dy, RtFloat dz )
 
850
{
 
851
    PR( "Translate", Translate ); S;
 
852
    PF( dx ); S;
 
853
    PF( dy ); S;
 
854
    PF( dz );
 
855
    EOL;
 
856
}
 
857
 
 
858
RtVoid CqOutput::RiRotate( RtFloat angle, RtFloat dx, RtFloat dy, RtFloat dz )
 
859
{
 
860
    PR( "Rotate", Rotate ); S;
 
861
    PF( angle ); S;
 
862
    PF( dx ); S;
 
863
    PF( dy ); S;
 
864
    PF( dz );
 
865
    EOL;
 
866
}
 
867
 
 
868
RtVoid CqOutput::RiScale( RtFloat sx, RtFloat sy, RtFloat sz )
 
869
{
 
870
    PR( "Scale", Scale ); S;
 
871
    PF( sx ); S;
 
872
    PF( sy ); S;
 
873
    PF( sz );
 
874
    EOL;
 
875
}
 
876
 
 
877
RtVoid CqOutput::RiSkew( RtFloat angle, RtFloat dx1, RtFloat dy1, RtFloat dz1,
 
878
                         RtFloat dx2, RtFloat dy2, RtFloat dz2 )
 
879
{
 
880
    PR( "Skew", Skew ); S;
 
881
    PF( angle ); S;
 
882
    PF( dx1 ); S;
 
883
    PF( dy1 ); S;
 
884
    PF( dz1 ); S;
 
885
    PF( dx2 ); S;
 
886
    PF( dy2 ); S;
 
887
    PF( dz2 );
 
888
    EOL;
 
889
}
 
890
 
 
891
RtVoid CqOutput::RiDeformationV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
892
{
 
893
    PR( "Deformation", Deformation ); S;
 
894
    printCharP( name ); S;
 
895
    printPL( n, tokens, parms );
 
896
}
 
897
 
 
898
RtVoid CqOutput::RiCoordinateSystem( RtToken space )
 
899
{
 
900
    PR( "CoordinateSystem", CoordinateSystem ); S;
 
901
    printToken( space );
 
902
    EOL;
 
903
}
 
904
 
 
905
RtVoid CqOutput::RiCoordSysTransform( RtToken space )
 
906
{
 
907
    PR( "CoordSysTransform", CoordSysTransform ); S;
 
908
    printToken( space );
 
909
    EOL;
 
910
}
 
911
 
 
912
RtVoid CqOutput::RiAttributeV( const char *name, RtInt n, RtToken tokens[], RtPointer parms[] )
 
913
{
 
914
    PR( "Attribute", Attribute ); S;
 
915
    printCharP( name ); S;
 
916
    printPL( n, tokens, parms );
 
917
}
 
918
 
 
919
 
 
920
 
 
921
 
 
922
// **********************************************************
 
923
// ******* ******* ******* PRIMITIVES ******* ******* *******
 
924
// **********************************************************
 
925
RtVoid CqOutput::RiPolygonV( RtInt nverts, RtInt n, RtToken tokens[], RtPointer parms[] )
 
926
{
 
927
    PR( "Polygon", Polygon ); S;
 
928
    printPL( n, tokens, parms, nverts, nverts, nverts );
 
929
}
 
930
 
 
931
RtVoid CqOutput::RiGeneralPolygonV( RtInt nloops, RtInt nverts[],
 
932
                                    RtInt n, RtToken tokens[], RtPointer parms[] )
 
933
{
 
934
    RtInt nbpts = 0;
 
935
    for ( RtInt i = 0; i < nloops; i++ )
 
936
    {
 
937
        nbpts += nverts[ i ];
 
938
    }
 
939
 
 
940
    PR( "GeneralPolygon", GeneralPolygon ); S;
 
941
    printArray( nloops, nverts ); S;
 
942
    printPL( n, tokens, parms, nbpts, nbpts, nbpts );
 
943
}
 
944
 
 
945
RtVoid CqOutput::RiPointsPolygonsV( RtInt npolys, RtInt nverts[], RtInt verts[],
 
946
                                    RtInt n, RtToken tokens[], RtPointer parms[] )
 
947
{
 
948
    PR( "PointsPolygons", PointsPolygons ); S;
 
949
    printArray( npolys, nverts ); S;
 
950
 
 
951
    RtInt i;
 
952
    RtInt nbpts = 0;
 
953
    for ( i = 0; i < npolys; i++ )
 
954
    {
 
955
        nbpts += nverts[ i ];
 
956
    }
 
957
    printArray( nbpts, verts ); S;
 
958
 
 
959
    RtInt psize = 0;
 
960
    for ( i = 0; i < nbpts; i++ )
 
961
    {
 
962
        if ( psize < verts[ i ] )
 
963
            psize = verts[ i ];
 
964
    }
 
965
    printPL( n, tokens, parms, psize + 1, psize + 1, npolys, nbpts );
 
966
}
 
967
 
 
968
RtVoid CqOutput::RiPointsGeneralPolygonsV( RtInt npolys, RtInt nloops[], RtInt nverts[],
 
969
        RtInt verts[],
 
970
        RtInt n, RtToken tokens[], RtPointer parms[] )
 
971
{
 
972
    PR( "PointsGeneralPolygons", PointsGeneralPolygons ); S;
 
973
    printArray( npolys, nloops ); S;
 
974
 
 
975
    RtInt i;
 
976
    RtInt nbvert = 0;
 
977
    for ( i = 0; i < npolys; i++ )
 
978
    {
 
979
        nbvert += nloops[ i ];
 
980
    }
 
981
    printArray( nbvert, nverts ); S;
 
982
 
 
983
    RtInt nv = 0;
 
984
    for ( i = 0; i < nbvert; i++ )
 
985
    {
 
986
        nv += nverts[ i ];
 
987
    }
 
988
    printArray( nv, verts ); S;
 
989
 
 
990
    RtInt psize = 0;
 
991
    for ( i = 0; i < nv; i++ )
 
992
    {
 
993
        if ( psize < verts[ i ] )
 
994
            psize = verts[ i ];
 
995
    }
 
996
        RtInt facevarying = nv;
 
997
    printPL( n, tokens, parms, psize + 1, psize + 1, npolys, facevarying );
 
998
}
 
999
 
 
1000
RtVoid CqOutput::RiPatchV( RtToken type, RtInt n, RtToken tokens[], RtPointer parms[] )
 
1001
{
 
1002
    RtInt nb;
 
1003
    if ( type == RI_BILINEAR )
 
1004
        nb = 4;
 
1005
    else if ( type == RI_BICUBIC )
 
1006
        nb = 16;
 
1007
    else
 
1008
    {
 
1009
        throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1010
                       "Unknown RiPatch type: ", type,
 
1011
                       "  RiPatch() instruction skipped", TqTrue );
 
1012
    }
 
1013
 
 
1014
    PR( "Patch", Patch ); S;
 
1015
    printToken( type ); S;
 
1016
    printPL( n, tokens, parms, nb, 4 );
 
1017
}
 
1018
 
 
1019
RtVoid CqOutput::RiPatchMeshV( RtToken type, RtInt nu, RtToken uwrap,
 
1020
                               RtInt nv, RtToken vwrap, RtInt n, RtToken tokens[],
 
1021
                               RtPointer parms[] )
 
1022
{
 
1023
    RtInt nuptch, nvptch;
 
1024
    RtInt ii = 0;
 
1025
    if ( type == RI_BILINEAR )
 
1026
    {
 
1027
        if ( uwrap == RI_PERIODIC )
 
1028
        {
 
1029
            nuptch = nu;
 
1030
        }
 
1031
        else if ( uwrap == RI_NONPERIODIC )
 
1032
        {
 
1033
            nuptch = nu - 1;
 
1034
            ii += 1;
 
1035
        }
 
1036
        else
 
1037
        {
 
1038
            throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1039
                           "Unknown RiPatchMesh uwrap token:", uwrap,
 
1040
                           "  RiPatchMesh instruction skipped", TqTrue );
 
1041
        }
 
1042
        if ( vwrap == RI_PERIODIC )
 
1043
        {
 
1044
            nvptch = nv;
 
1045
        }
 
1046
        else if ( vwrap == RI_NONPERIODIC )
 
1047
        {
 
1048
            nvptch = nv - 1;
 
1049
            ii += 1;
 
1050
        }
 
1051
        else
 
1052
        {
 
1053
            throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1054
                           "Unknown RiPatchMesh vwrap token:", vwrap,
 
1055
                           "  RiPatchMesh instruction skipped", TqTrue );
 
1056
        }
 
1057
        ii += nuptch + nvptch;
 
1058
 
 
1059
 
 
1060
    }
 
1061
    else if ( type == RI_BICUBIC )
 
1062
    {
 
1063
        RtInt nustep = m_Steps.top().uStep;
 
1064
        RtInt nvstep = m_Steps.top().vStep;
 
1065
 
 
1066
        if ( uwrap == RI_PERIODIC )
 
1067
        {
 
1068
            nuptch = nu / nustep;
 
1069
        }
 
1070
        else if ( uwrap == RI_NONPERIODIC )
 
1071
        {
 
1072
            nuptch = ( nu - 4 ) / nustep + 1;
 
1073
            ii += 1;
 
1074
        }
 
1075
        else
 
1076
        {
 
1077
            throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1078
                           "Unknown RiPatchMesh uwrap token:", uwrap,
 
1079
                           "  RiPatchMesh instruction skipped", TqTrue );
 
1080
        }
 
1081
        if ( vwrap == RI_PERIODIC )
 
1082
        {
 
1083
            nvptch = nv / nvstep;
 
1084
        }
 
1085
        else if ( vwrap == RI_NONPERIODIC )
 
1086
        {
 
1087
            nvptch = ( nv - 4 ) / nvstep + 1;
 
1088
            ii += 1;
 
1089
        }
 
1090
        else
 
1091
        {
 
1092
            throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1093
                           "Unknown RiPatchMesh vwrap token:", vwrap,
 
1094
                           "  RiPatchMesh instruction skipped", TqTrue );
 
1095
        }
 
1096
        ii += nuptch + nvptch;
 
1097
 
 
1098
 
 
1099
    }
 
1100
    else
 
1101
    {
 
1102
        throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1103
                       "Unknown RiPatchMesh type:", type,
 
1104
                       "  RiPatchMesh instruction skipped", TqTrue );
 
1105
    }
 
1106
 
 
1107
    PR( "PatchMesh", PatchMesh ); S;
 
1108
    printToken( type ); S;
 
1109
    PI( nu ); S;
 
1110
    printToken( uwrap ); S;
 
1111
    PI( nv ); S;
 
1112
    printToken( vwrap ); S;
 
1113
    printPL( n, tokens, parms, nu * nv, ii, nuptch * nvptch );
 
1114
}
 
1115
 
 
1116
RtVoid CqOutput::RiNuPatchV( RtInt nu, RtInt uorder, RtFloat uknot[],
 
1117
                             RtFloat umin, RtFloat umax,
 
1118
                             RtInt nv, RtInt vorder, RtFloat vknot[],
 
1119
                             RtFloat vmin, RtFloat vmax,
 
1120
                             RtInt n, RtToken tokens[], RtPointer parms[] )
 
1121
{
 
1122
    PR( "NuPatch", NuPatch ); S;
 
1123
    PI( nu ); S;
 
1124
    PI( uorder ); S;
 
1125
    printArray( nu + uorder, uknot ); S;
 
1126
    PF( umin ); S;
 
1127
    PF( umax ); S;
 
1128
 
 
1129
    PI( nv ); S;
 
1130
    PI( vorder ); S;
 
1131
    printArray( nv + vorder, vknot ); S;
 
1132
    PF( vmin ); S;
 
1133
    PF( vmax ); S;
 
1134
    printPL( n, tokens, parms, nu * nv, ( 2 + nu - uorder ) * ( 2 + nv - vorder ), ( 1 + nu - uorder ) * ( 1 + nv - vorder ) );
 
1135
}
 
1136
 
 
1137
RtVoid CqOutput::RiSphereV( RtFloat radius, RtFloat zmin, RtFloat zmax, RtFloat tmax,
 
1138
                            RtInt n, RtToken tokens[], RtPointer parms[] )
 
1139
{
 
1140
    PR( "Sphere", Sphere ); S;
 
1141
    PF( radius ); S;
 
1142
    PF( zmin ); S;
 
1143
    PF( zmax ); S;
 
1144
    PF( tmax ); S;
 
1145
    printPL( n, tokens, parms, 4, 4 );
 
1146
}
 
1147
 
 
1148
RtVoid CqOutput::RiConeV( RtFloat height, RtFloat radius, RtFloat tmax,
 
1149
                          RtInt n, RtToken tokens[], RtPointer parms[] )
 
1150
{
 
1151
    PR( "Cone", Cone ); S;
 
1152
    PF( height ); S;
 
1153
    PF( radius ); S;
 
1154
    PF( tmax ); S;
 
1155
    printPL( n, tokens, parms, 4, 4 );
 
1156
}
 
1157
 
 
1158
RtVoid CqOutput::RiCylinderV( RtFloat radius, RtFloat zmin, RtFloat zmax, RtFloat tmax,
 
1159
                              RtInt n, RtToken tokens[], RtPointer parms[] )
 
1160
{
 
1161
    PR( "Cylinder", Cylinder ); S;
 
1162
    PF( radius ); S;
 
1163
    PF( zmin ); S;
 
1164
    PF( zmax ); S;
 
1165
    PF( tmax ); S;
 
1166
    printPL( n, tokens, parms, 4, 4 );
 
1167
}
 
1168
 
 
1169
RtVoid CqOutput::RiHyperboloidV( RtPoint point1, RtPoint point2, RtFloat tmax,
 
1170
                                 RtInt n, RtToken tokens[], RtPointer parms[] )
 
1171
{
 
1172
    PR( "Hyperboloid", Hyperboloid ); S;
 
1173
    printArray( 3, point1 ); S;
 
1174
    printArray( 3, point2 ); S;
 
1175
    PF( tmax ); S;
 
1176
    printPL( n, tokens, parms, 4, 4 );
 
1177
}
 
1178
 
 
1179
RtVoid CqOutput::RiParaboloidV( RtFloat rmax, RtFloat zmin, RtFloat zmax, RtFloat tmax,
 
1180
                                RtInt n, RtToken tokens[], RtPointer parms[] )
 
1181
{
 
1182
    PR( "Paraboloid", Paraboloid ); S;
 
1183
    PF( rmax ); S;
 
1184
    PF( zmin ); S;
 
1185
    PF( zmax ); S;
 
1186
    PF( tmax ); S;
 
1187
    printPL( n, tokens, parms, 4, 4 );
 
1188
}
 
1189
 
 
1190
RtVoid CqOutput::RiDiskV( RtFloat height, RtFloat radius, RtFloat tmax,
 
1191
                          RtInt n, RtToken tokens[], RtPointer parms[] )
 
1192
{
 
1193
    PR( "Disk", Disk ); S;
 
1194
    PF( height ); S;
 
1195
    PF( radius ); S;
 
1196
    PF( tmax ); S;
 
1197
    printPL( n, tokens, parms, 4, 4 );
 
1198
}
 
1199
 
 
1200
RtVoid CqOutput::RiTorusV( RtFloat majrad, RtFloat minrad, RtFloat phimin, RtFloat phimax,
 
1201
                           RtFloat tmax, RtInt n, RtToken tokens[], RtPointer parms[] )
 
1202
{
 
1203
    PR( "Torus", Torus ); S;
 
1204
    PF( majrad ); S;
 
1205
    PF( minrad ); S;
 
1206
    PF( phimin ); S;
 
1207
    PF( phimax ); S;
 
1208
    PF( tmax ); S;
 
1209
    printPL( n, tokens, parms, 4, 4 );
 
1210
}
 
1211
 
 
1212
RtVoid CqOutput::RiBlobbyV( RtInt nleaf, RtInt ncode, RtInt code[],
 
1213
                            RtInt nflt, RtFloat flt[],
 
1214
                            RtInt nstr, RtToken str[],
 
1215
                            RtInt n, RtToken tokens[], RtPointer parms[] )
 
1216
{
 
1217
    PR( "Blobby", Blobby ); S;
 
1218
    printArray( ncode, code ); S;
 
1219
    printArray( nflt, flt ); S;
 
1220
    print( "[" ); S;
 
1221
    for ( RtInt i = 0; i < nstr; i++ )
 
1222
    {
 
1223
        printToken( str[ i ] ); S;
 
1224
    }
 
1225
    print( "]" ); S;
 
1226
    printPL( n, tokens, parms, nleaf, nleaf );
 
1227
}
 
1228
 
 
1229
RtVoid CqOutput::RiPointsV( RtInt npoints,
 
1230
                            RtInt n, RtToken tokens[], RtPointer parms[] )
 
1231
{
 
1232
    PR( "Points", Points ); S;
 
1233
    printPL( n, tokens, parms, npoints, npoints );
 
1234
}
 
1235
 
 
1236
RtVoid CqOutput::RiCurvesV( RtToken type, RtInt ncurves,
 
1237
                            RtInt nvertices[], RtToken wrap,
 
1238
                            RtInt n, RtToken tokens[], RtPointer parms[] )
 
1239
{
 
1240
    RtInt i;
 
1241
    RtInt vval = 0;
 
1242
    if ( type == RI_LINEAR )
 
1243
    {
 
1244
        if ( wrap == RI_PERIODIC )
 
1245
        {
 
1246
            for ( i = 0; i < ncurves; i++ )
 
1247
            {
 
1248
                vval += nvertices[ i ];
 
1249
            }
 
1250
        }
 
1251
        else if ( wrap == RI_NONPERIODIC )
 
1252
        {
 
1253
            for ( i = 0; i < ncurves; i++ )
 
1254
            {
 
1255
                vval += nvertices[ i ];
 
1256
            }
 
1257
        }
 
1258
        else
 
1259
        {
 
1260
            throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1261
                           "Unknown RiCurves wrap token:", wrap,
 
1262
                           "  RiCurves instruction skipped", TqTrue );
 
1263
        }
 
1264
    }
 
1265
    else if ( type == RI_CUBIC )
 
1266
    {
 
1267
        if ( wrap == RI_PERIODIC )
 
1268
        {
 
1269
            for ( i = 0; i < ncurves; i++ )
 
1270
            {
 
1271
                vval += ( nvertices[ i ] - 4 ) / m_Steps.top().vStep;
 
1272
            }
 
1273
        }
 
1274
        else if ( wrap == RI_NONPERIODIC )
 
1275
        {
 
1276
            for ( i = 0; i < ncurves; i++ )
 
1277
            {
 
1278
                vval += 2 + ( nvertices[ i ] - 4 ) / m_Steps.top().vStep;
 
1279
            }
 
1280
        }
 
1281
        else
 
1282
        {
 
1283
            throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1284
                           "Unknown RiCurves wrap token:", wrap,
 
1285
                           "  RiCurves instruction skipped", TqTrue );
 
1286
        }
 
1287
    }
 
1288
    else
 
1289
    {
 
1290
        throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1291
                       "Unknown RiCurves type:", type,
 
1292
                       "  RiCurves instruction skipped", TqTrue );
 
1293
    }
 
1294
 
 
1295
    PR( "Curves", Curves ); S;
 
1296
    printToken( type ); S;
 
1297
    printArray( ncurves, nvertices ); S;
 
1298
    printToken( wrap ); S;
 
1299
 
 
1300
    RtInt nbpts = 0;
 
1301
    for ( i = 0; i < ncurves; i++ )
 
1302
    {
 
1303
        nbpts += nvertices[ i ];
 
1304
    }
 
1305
    printPL( n, tokens, parms, nbpts, vval, ncurves );
 
1306
}
 
1307
 
 
1308
RtVoid CqOutput::RiSubdivisionMeshV( RtToken mask, RtInt nf, RtInt nverts[],
 
1309
                                     RtInt verts[],
 
1310
                                     RtInt ntags, RtToken tags[], RtInt numargs[],
 
1311
                                     RtInt intargs[], RtFloat floatargs[],
 
1312
                                     RtInt n, RtToken tokens[], RtPointer parms[] )
 
1313
{
 
1314
    PR( "SubdivisionMesh", SubdivisionMesh ); S;
 
1315
    printToken( mask ); S;
 
1316
    printArray( nf, nverts ); S;
 
1317
 
 
1318
    RtInt i;
 
1319
    RtInt vsize = 0;
 
1320
    for ( i = 0; i < nf; i++ )
 
1321
    {
 
1322
        vsize += nverts[ i ];
 
1323
    }
 
1324
    printArray( vsize, verts ); S;
 
1325
 
 
1326
        printArray( ntags, tags ); S;
 
1327
    printArray( ntags * 2, numargs ); S;
 
1328
 
 
1329
    RtInt isize = 0, fsize = 0;
 
1330
    for ( i = 0; i < ntags*2; i++ )
 
1331
    {
 
1332
        if ( i % 2 == 0 )
 
1333
            isize += numargs[ i ];
 
1334
        else
 
1335
            fsize += numargs[ i ];
 
1336
    }
 
1337
    printArray( isize, intargs ); S;
 
1338
    printArray( fsize, floatargs ); S;
 
1339
 
 
1340
    RtInt psize = 0;
 
1341
    for ( i = 0; i < vsize; i++ )
 
1342
    {
 
1343
        if ( psize < verts[ i ] )
 
1344
            psize = verts[ i ];
 
1345
    }
 
1346
    printPL( n, tokens, parms, psize + 1, psize + 1, nf, vsize );
 
1347
}
 
1348
 
 
1349
RtVoid CqOutput::RiProcedural( RtPointer data, RtBound bound,
 
1350
                               RtVoid ( *subdivfunc ) ( RtPointer, RtFloat ),
 
1351
                               RtVoid ( *freefunc ) ( RtPointer ) )
 
1352
{
 
1353
    std::string sf;
 
1354
    RtInt a;
 
1355
    if ( subdivfunc == RiProcDelayedReadArchive )
 
1356
    {
 
1357
        sf = "DelayedReadArchive";
 
1358
        a = 1;
 
1359
    }
 
1360
    else if ( subdivfunc == RiProcRunProgram )
 
1361
    {
 
1362
        sf = "ReadProgram";
 
1363
        a = 2;
 
1364
    }
 
1365
    else if ( subdivfunc == RiProcDynamicLoad )
 
1366
    {
 
1367
        sf = "DynamicLoad";
 
1368
        a = 3;
 
1369
    }
 
1370
    else
 
1371
    {
 
1372
        throw CqError( RIE_SYNTAX, RIE_ERROR, "Unknown procedural function.", TqTrue );
 
1373
    }
 
1374
 
 
1375
    PR( "Procedural", Procedural ); S;
 
1376
 
 
1377
    RtInt i;
 
1378
    switch ( a )
 
1379
    {
 
1380
    case 1:
 
1381
        PS( sf ); S;
 
1382
        print( "[" ); S;
 
1383
        printCharP( ( ( RtString * ) data ) [ 0 ] ); S;
 
1384
        print( "]" ); S;
 
1385
 
 
1386
        print( "[" ); S;
 
1387
        for ( i = 0; i < 6 ; i++ )
 
1388
        {
 
1389
            PF( bound[ i ] ); S;
 
1390
        }
 
1391
        print( "]" );
 
1392
        EOL;
 
1393
        break;
 
1394
    case 2:
 
1395
    case 3:
 
1396
        PS( sf ); S;
 
1397
        print( "[" ); S;
 
1398
        printCharP( ( ( RtString * ) data ) [ 0 ] ); S;
 
1399
        printCharP( ( ( RtString * ) data ) [ 1 ] ); S;
 
1400
        print( "]" ); S;
 
1401
 
 
1402
        print( "[" ); S;
 
1403
        for ( i = 0; i < 6 ; i++ )
 
1404
        {
 
1405
            PF( bound[ i ] ); S;
 
1406
        }
 
1407
        print( "]" );
 
1408
        EOL;
 
1409
        break;
 
1410
    }
 
1411
}
 
1412
 
 
1413
RtVoid CqOutput::RiGeometryV( RtToken type, RtInt n, RtToken tokens[], RtPointer parms[] )
 
1414
{
 
1415
    PR( "Geometry", Geometry ); S;
 
1416
    printToken( type ); S;
 
1417
    printPL( n, tokens, parms );
 
1418
}
 
1419
 
 
1420
 
 
1421
 
 
1422
 
 
1423
// *******************************************************
 
1424
// ******* ******* ******* TEXTURE ******* ******* *******
 
1425
// *******************************************************
 
1426
RtVoid CqOutput::RiMakeTextureV( const char *pic, const char *tex, RtToken swrap, RtToken twrap,
 
1427
                                 RtFilterFunc filterfunc, RtFloat swidth, RtFloat twidth,
 
1428
                                 RtInt n, RtToken tokens[], RtPointer parms[] )
 
1429
{
 
1430
    std::string ff = getFilterFuncName( filterfunc, "MakeTexture" );
 
1431
 
 
1432
    PR( "MakeTexture", MakeTexture ); S;
 
1433
    printCharP( pic ); S;
 
1434
    printCharP( tex ); S;
 
1435
    printToken( swrap ); S;
 
1436
    printToken( twrap ); S;
 
1437
    PS( ff ); S;
 
1438
    PF( swidth ); S;
 
1439
    PF( twidth ); S;
 
1440
    printPL( n, tokens, parms );
 
1441
}
 
1442
 
 
1443
RtVoid CqOutput::RiMakeBumpV( const char *pic, const char *tex, RtToken swrap, RtToken twrap,
 
1444
                              RtFilterFunc filterfunc, RtFloat swidth, RtFloat twidth,
 
1445
                              RtInt n, RtToken tokens[], RtPointer parms[] )
 
1446
{
 
1447
    std::string ff = getFilterFuncName( filterfunc, "MakeBump" );
 
1448
 
 
1449
    PR( "MakeBump", MakeBump ); S;
 
1450
    printCharP( pic ); S;
 
1451
    printCharP( tex ); S;
 
1452
    printToken( swrap ); S;
 
1453
    printToken( twrap ); S;
 
1454
    PS( ff ); S;
 
1455
    PF( swidth ); S;
 
1456
    PF( twidth ); S;
 
1457
    printPL( n, tokens, parms );
 
1458
}
 
1459
 
 
1460
RtVoid CqOutput::RiMakeLatLongEnvironmentV( const char *pic, const char *tex, RtFilterFunc filterfunc,
 
1461
        RtFloat swidth, RtFloat twidth,
 
1462
        RtInt n, RtToken tokens[], RtPointer parms[] )
 
1463
{
 
1464
    std::string ff = getFilterFuncName( filterfunc, "MakeLatLongEnvironment" );
 
1465
 
 
1466
    PR( "MakeLatLongEnvironment", MakeLatLongEnvironment ); S;
 
1467
    printCharP( pic ); S;
 
1468
    printCharP( tex ); S;
 
1469
    PS( ff ); S;
 
1470
    PF( swidth ); S;
 
1471
    PF( twidth ); S;
 
1472
    printPL( n, tokens, parms );
 
1473
}
 
1474
 
 
1475
RtVoid CqOutput::RiMakeCubeFaceEnvironmentV( const char *px, const char *nx, const char *py, const char *ny,
 
1476
        const char *pz, const char *nz, const char *tex, RtFloat fov,
 
1477
        RtFilterFunc filterfunc, RtFloat swidth,
 
1478
        RtFloat twidth,
 
1479
        RtInt n, RtToken tokens[], RtPointer parms[] )
 
1480
{
 
1481
    std::string ff = getFilterFuncName( filterfunc, "MakeCubeFaceEnvironment" );
 
1482
 
 
1483
    PR( "MakeCubeFaceEnvironment", MakeCubeFaceEnvironment ); S;
 
1484
    printCharP( px ); S;
 
1485
    printCharP( nx ); S;
 
1486
    printCharP( py ); S;
 
1487
    printCharP( ny ); S;
 
1488
    printCharP( pz ); S;
 
1489
    printCharP( nz ); S;
 
1490
    printCharP( tex ); S;
 
1491
    PF( fov ); S;
 
1492
    PS( ff ); S;
 
1493
    PF( swidth ); S;
 
1494
    PF( twidth ); S;
 
1495
    printPL( n, tokens, parms );
 
1496
}
 
1497
 
 
1498
RtVoid CqOutput::RiMakeShadowV( const char *pic, const char *tex,
 
1499
                                RtInt n, RtToken tokens[], RtPointer parms[] )
 
1500
{
 
1501
    PR( "MakeShadow", MakeShadow ); S;
 
1502
    printCharP( pic ); S;
 
1503
    printCharP( tex ); S;
 
1504
    printPL( n, tokens, parms );
 
1505
}
 
1506
 
 
1507
 
 
1508
 
 
1509
 
 
1510
// *******************************************************
 
1511
// ******* ******* ******* ARCHIVE ******* ******* *******
 
1512
// *******************************************************
 
1513
RtVoid CqOutput::RiArchiveRecord( RtToken type, std::string txt )
 
1514
{
 
1515
    std::string tmp;
 
1516
 
 
1517
    if ( type == RI_COMMENT ) tmp = "#";
 
1518
    else if ( type == RI_STRUCTURE ) tmp = "##";
 
1519
    else if ( type == RI_VERBATIM )
 
1520
    {
 
1521
        print( txt.c_str() ); return ;
 
1522
    }
 
1523
    else
 
1524
    {
 
1525
        throw CqError( RIE_BADTOKEN, RIE_ERROR,
 
1526
                       "Unknown ArchiveRecord type: ", type, "", TqTrue );
 
1527
    }
 
1528
    // EOL must be forced for binary
 
1529
    print( ( tmp + txt + "\n" ).c_str() );
 
1530
}
 
1531
 
 
1532
RtVoid CqOutput::RiReadArchiveV( RtToken name, RtArchiveCallback callback,
 
1533
                                 RtInt n, RtToken tokens[], RtPointer parms[] )
 
1534
{
 
1535
    PR( "ReadArchive", ReadArchive ); S;
 
1536
    printToken( name );
 
1537
    EOL;
 
1538
}
 
1539
 
 
1540
 
 
1541
 
 
1542
 
 
1543
// *************************************************************
 
1544
// ******* ******* ******* ERROR HANDLER ******* ******* *******
 
1545
// *************************************************************
 
1546
RtVoid CqOutput::RiErrorHandler( RtErrorFunc handler )
 
1547
{
 
1548
    std::string ch;
 
1549
    if ( handler == RiErrorIgnore ) ch = "ignore";
 
1550
    else if ( handler == RiErrorPrint ) ch = "print";
 
1551
    else if ( handler == RiErrorAbort ) ch = "abort";
 
1552
    else
 
1553
    {
 
1554
        throw CqError( RIE_CONSISTENCY, RIE_ERROR, "Unknown Error handler", TqTrue );
 
1555
    }
 
1556
    PR( "ErrorHandler", ErrorHandler ); S;
 
1557
    PS( ch );
 
1558
    EOL;
 
1559
}