当前位置: 首页>>代码示例>>C++>>正文


C++ Worker::GetOutput方法代码示例

本文整理汇总了C++中Worker::GetOutput方法的典型用法代码示例。如果您正苦于以下问题:C++ Worker::GetOutput方法的具体用法?C++ Worker::GetOutput怎么用?C++ Worker::GetOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Worker的用法示例。


在下文中一共展示了Worker::GetOutput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main( int argc, char **argv ) {
    if ( argc > 1 ) {
        char * mode = argv[1];
        if ( strcmp( mode, "server" ) == 0 ) {
            // 
            printf( "STUB server mode.\n" );
        } else if ( strcmp( mode, "client" ) == 0 ) {
            printf( "STUB client mode.\n" );
        } else if ( strcmp( mode, "local" ) == 0 ) {
            if ( argc >= 4 ) {
                int w = atoi( argv[2] );
                int h = atoi( argv[3] );

                // parameter setup
                params.bmp = new BMP( w, h );

                params.w = w;
                params.h = h;

                params.rt.camera.focalLength = 1.0;
                params.rt.camera.depthOfFocus = 40.0;
                params.rt.camera.aperture = 1.0;
                params.rt.camera.pos.y = -2; // raise the camera up slightly
                params.rt.camera.aspectRatio = static_cast<float>( w ) / static_cast<float>( h );

                rt::Sphere s1( Vec3( -9, -13, -44 ), 7, new Dielectric( 1.3 ) );
                rt::Sphere s2( Vec3( -2, -13, -88 ), 7, new Metallic( Vec4( 0.7, 0.7, 0.7, 1 ), 0.5 ) );
                rt::Sphere s3( Vec3( 10, -13, -66 ), 7, new Lambertian( Vec4( 0.7, 0.7, 0.7, 1 ) ) );

                // cornell box faces
                // top face
                rt::Plane  ptop( Vec3(  0,  20, 0 ), Vec3( 0, -1, 0 ), new Lambertian( Vec4( 0.9, 0.9, 0.9, 1 ) ) );

                // bottom face
                rt::Plane  pbot( Vec3(  0, -20, 0 ), Vec3( 0, 1, 0 ), new Lambertian( Vec4( 0.8, 0.8, 0.8, 1 ) ) );

                // back face
                rt::Plane  pbak( Vec3(  0, 0, -65 ), Vec3( 0, 0, 1 ), new Lambertian( Vec4( 0.9, 0.9, 0.9, 1 ) ) );

                // side faces
                rt::Plane  pr( Vec3(  20, 0, 0 ), Vec3( -1, 0, 0 ), new Lambertian( Vec4( 0.8, 0.3, 0.3, 1 ) ) );
                rt::Plane  pl( Vec3( -20, 0, 0 ), Vec3(  1, 0, 0 ), new Lambertian( Vec4( 0.3, 0.8, 0.3, 1 ) ) );

                params.rt.scene.objects.push_back( &s1 );
                params.rt.scene.objects.push_back( &s2 );
                params.rt.scene.objects.push_back( &s3 );

                // params.rt.scene.objects.push_back( &ptop );
                params.rt.scene.objects.push_back( &pbot );
                // params.rt.scene.objects.push_back( &pbak );
                // params.rt.scene.objects.push_back( &pl );
                // params.rt.scene.objects.push_back( &pr );

                Worker * worker;

                struct WorkParams work_params;
                
                work_params.bounces = 4;
                work_params.w = w;
                work_params.h = h;

                if ( params.singleThreaded ) {
                    worker = new Worker( work_params );
                    worker->StartWork();
                    worker->WaitUntilFinished();
                    params.bmp = worker->GetOutput();
                } else { // multithreaded
                    pthread_t threads[ NUM_THREADS ];

                    pthread_attr_t attr;
                    pthread_attr_init( &attr );
                    pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );

                    if ( params.useJobs ) {
                        pthread_mutex_init( &params.jobQueue_mutex, NULL );
                        pthread_cond_init( &params.jobQueueAvailable, NULL );

                        for ( int i = 0; i < NUM_THREADS; i++ ) {
                            uint64_t t = i;
                            int rc = pthread_create( &threads[i], &attr, startWorker, (void *) t );
                        }

                        // add jobs to the queue
                        for ( int y = 0; y < h; y++ ) {
                            pthread_mutex_lock( &params.jobQueue_mutex );
                            params.jobQueue.push( y );
                            pthread_cond_signal( &params.jobQueueAvailable );
                            pthread_mutex_unlock( &params.jobQueue_mutex );
                        }

                        // we're done, wake up all waiting threads
                        pthread_mutex_lock( &params.jobQueue_mutex );
                        params.allJobsQueued = true;
                        pthread_cond_broadcast( &params.jobQueueAvailable );
                        pthread_mutex_unlock( &params.jobQueue_mutex );
                    } else { // simple thread-index based work division
                        for ( int i = 0; i < NUM_THREADS; i++ ) {
                            uint64_t t = i;
                            int rc = pthread_create( &threads[i], &attr, renderTile, (void *) t );
                        }
//.........这里部分代码省略.........
开发者ID:davidyu,项目名称:Slowpoke,代码行数:101,代码来源:main.cpp


注:本文中的Worker::GetOutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。