コード例 #1
0
ファイル: MlEngine.cpp プロジェクト: ahmidou/aphid
void MlEngine::fineOutput()
{
    ptime tt(second_clock::local_time());
    std::cout<<"fine output begins at "<<to_simple_string(tt)<<"\n";

    RenderOptions * opts = options();
    const int imageSizeX = opts->renderImageWidth();
    const int imageSizeY = opts->renderImageHeight();
    const int aas = opts->AASample();

#ifdef WIN32
    AiBegin();
    logArnoldVersion();
    loadPlugin("./driver_foo.dll");
    loadPlugin("./ExtendShaders.dll");
    loadPlugin("./mtoa_shaders.dll");

    const AtNodeEntry* nodeEntry = AiNodeEntryLookUp("featherUVCoord");
    if(nodeEntry == NULL) std::clog<<"\nWARNING: featherUVCoord node entry doesn't exist! Most likely ExtendShaders.dll is not loaded.\n";

    AtNode* options = AiNode("options");
    AtArray* outputs  = AiArrayAllocate(1, 1, AI_TYPE_STRING);
    AiArraySetStr(outputs, 0, "RGBA RGBA output:gaussian_filter output/foo");
    AiNodeSetArray(options, "outputs", outputs);

    AiNodeSetInt(options, "xres", imageSizeX);
    AiNodeSetInt(options, "yres", imageSizeY);
    AiNodeSetInt(options, "AA_samples", aas);
    AiNodeSetInt(options, "GI_diffuse_samples", 2);
    AiNodeSetInt(options, "auto_transparency_depth", 12);

    AtNode* driver = AiNode("driver_foo");
    AiNodeSetStr(driver, "name", "output/foo");

    AtNode * acamera = AiNode("persp_camera");
    AiNodeSetStr(acamera, "name", "/obj/cam");
    AiNodeSetFlt(acamera, "fov", camera()->fieldOfView());
    AiNodeSetFlt(acamera, "near_clip", camera()->nearClipPlane());
    AiNodeSetFlt(acamera, "far_clip", camera()->farClipPlane());

    AtMatrix matrix;
    setMatrix(camera()->fSpace, matrix);
    AiNodeSetMatrix(acamera, "matrix", matrix);

    AiNodeSetPtr(options, "camera", acamera);

    AtNode * filter = AiNode("gaussian_filter");
    AiNodeSetStr(filter, "name", "output:gaussian_filter");

    AtNode * standard = AiNode("standard");
    AiNodeSetStr(standard, "name", "/shop/standard1");
    AiNodeSetRGB(standard, "Kd_color", 1, 1, 1);

    AtNode * sphere = AiNode("sphere");
    AiNodeSetPtr(sphere, "shader", standard);
    AiNodeSetFlt(sphere, "radius", 1.f);
    AiM4Identity(matrix);
    matrix[3][0] = 0.f;
    matrix[3][1] = 0.f;
    matrix[3][2] = 50.f;
    AiNodeSetMatrix(sphere, "matrix", matrix);

    translateLights();
    translateCurves();

    logRenderError(AiRender(AI_RENDER_MODE_CAMERA));

    AiEnd();
#endif
    postRender();
}
コード例 #2
0
ファイル: MlEngine.cpp プロジェクト: ahmidou/aphid
void MlEngine::testOutput()
{
    if(!m_barb) return;

    translateCurves();

    ptime tt(second_clock::local_time());
    std::cout<<"test output begins at "<<to_simple_string(tt)<<"\n";

    std::string ts("2002-01-20 23:59:59.000");
    ptime tref(time_from_string(ts));
    time_duration td = tt - tref;

    boost::this_thread::interruption_point();

    char dataPackage[PACKAGESIZE];

    try
    {
        boost::asio::io_service io_service;
        tcp::resolver resolver(io_service);
        tcp::resolver::query query(tcp::v4(), "localhost", "7879");
        tcp::resolver::iterator iterator = resolver.resolve(query);
        tcp::socket s(io_service);

        boost::asio::deadline_timer t(io_service);

        const int bucketSize = 64;
        RenderOptions * opts = options();
        const int imageSizeX = opts->renderImageWidth();
        const int imageSizeY = opts->renderImageHeight();

        for(int by = 0; by <= imageSizeY/bucketSize; by++) {
            if(by * bucketSize == imageSizeY) continue;
            for(int bx = 0; bx <= imageSizeX/bucketSize; bx++) {
                if(bx * bucketSize == imageSizeX) continue;
                int * rect = (int *)dataPackage;

                rect[2] = by * bucketSize;
                rect[3] = rect[2] + bucketSize - 1;
                if(rect[3] > imageSizeY - 1) rect[3] = imageSizeY - 1;

                rect[0] = bx * bucketSize;
                rect[1] = rect[0] + bucketSize - 1;
                if(rect[1] > imageSizeX - 1) rect[1] = imageSizeX - 1;

                const float grey = (float)((rand() + td.seconds() * 391) % 457) / 457.f;
                const unsigned npix = (rect[1] - rect[0] + 1) * (rect[3] - rect[2] + 1);
                int npackage = npix * 16 / PACKAGESIZE;
                if((npix * 16) % PACKAGESIZE > 0) npackage++;

                s.connect(*iterator);

                boost::asio::write(s, boost::asio::buffer(dataPackage, 16));
                //std::cout<<"sent    bucket("<<rect[0]<<","<<rect[1]<<","<<rect[2]<<","<<rect[3]<<")\n";

                boost::array<char, 32> buf;
                boost::system::error_code error;

                size_t reply_length = s.read_some(boost::asio::buffer(buf), error);

                float *color = (float *)dataPackage;
                for(int i = 0; i < PACKAGESIZE / 16; i++) {
                    color[i * 4] = color[i * 4 + 1] = color[i * 4 + 2] = grey;
                    color[i * 4 + 3] = 1.f;
                }

                for(int i=0; i < npackage; i++) {
                    boost::asio::write(s, boost::asio::buffer(dataPackage, PACKAGESIZE));
                    reply_length = s.read_some(boost::asio::buffer(buf), error);
                }

                boost::asio::write(s, boost::asio::buffer(dataPackage, 32));
                reply_length = s.read_some(boost::asio::buffer(buf), error);

                s.close();
                t.expires_from_now(boost::posix_time::seconds(1));
                t.wait();

                boost::this_thread::interruption_point();
            }
        }

    }
    catch (std::exception& e)
    {
        std::cerr << "Exception: " << e.what() << "\n";
    }
}