00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "renderfarm.h"
00024
00025
00026 #include "lux.h"
00027 #include "context.h"
00028 #include "dynload.h"
00029 #include "api.h"
00030 #include "camera.h"
00031 #include "light.h"
00032 #include "primitive.h"
00033 #include "scene.h"
00034 #include "volume.h"
00035 #include "material.h"
00036 #include "stats.h"
00037
00038 #include <boost/iostreams/filtering_stream.hpp>
00039 #include <boost/iostreams/filtering_streambuf.hpp>
00040 #include <boost/iostreams/copy.hpp>
00041 #include <boost/iostreams/filter/zlib.hpp>
00042
00043 using namespace boost::iostreams;
00044 using namespace lux;
00045
00046 Context *Context::activeContext;
00047
00048
00049 #define VERIFY_INITIALIZED(func) \
00050 if (currentApiState == STATE_UNINITIALIZED) { \
00051 std::stringstream ss; \
00052 ss<<"luxInit() must be called before calling '"<<func<<"'. Ignoring."; \
00053 luxError(LUX_NOTSTARTED,LUX_SEVERE,ss.str().c_str()); \
00054 return; \
00055 } else
00056 #define VERIFY_OPTIONS(func) \
00057 VERIFY_INITIALIZED(func); \
00058 if (currentApiState == STATE_WORLD_BLOCK) { \
00059 std::stringstream ss; \
00060 ss<<"Options cannot be set inside world block; '"<<func<<"' not allowed. Ignoring."; \
00061 luxError(LUX_NESTING,LUX_ERROR,ss.str().c_str()); \
00062 return; \
00063 } else
00064 #define VERIFY_WORLD(func) \
00065 VERIFY_INITIALIZED(func); \
00066 if (currentApiState == STATE_OPTIONS_BLOCK) { \
00067 std::stringstream ss; \
00068 ss<<"Scene description must be inside world block; '"<<func<<"' not allowed. Ignoring."; \
00069 luxError(LUX_NESTING,LUX_ERROR,ss.str().c_str()); \
00070 return; \
00071 } else
00072
00073
00074 void Context::init() {
00075
00076 currentApiState = STATE_OPTIONS_BLOCK;
00077 luxCurrentScene = NULL;
00078 curTransform = Transform();
00079 namedCoordinateSystems.clear();
00080 renderOptions = new RenderOptions;
00081 graphicsState = new GraphicsState;
00082 namedmaterials.clear();
00083 pushedGraphicsStates.clear();
00084 pushedTransforms.clear();
00085 renderFarm = new RenderFarm();
00086 }
00087
00088 void Context::free() {
00089
00090 if (luxCurrentScene) {
00091 delete luxCurrentScene;
00092 luxCurrentScene = NULL;
00093 }
00094
00095 if (renderOptions) {
00096 delete renderOptions;
00097 renderOptions = NULL;
00098 }
00099
00100 if (graphicsState) {
00101 delete graphicsState;
00102 graphicsState = NULL;
00103 }
00104
00105 if (renderFarm) {
00106 delete renderFarm;
00107 renderFarm = NULL;
00108 }
00109 }
00110
00111
00112
00113 void Context::addServer(const string &name) {
00114
00115 renderFarm->connect(name);
00116 }
00117
00118 void Context::cleanup() {
00119 renderFarm->send("luxCleanup");
00120
00121 StatsCleanup();
00122
00123 if (currentApiState == STATE_UNINITIALIZED)
00124 luxError(LUX_NOTSTARTED,LUX_ERROR,"luxCleanup() called without luxInit().");
00125 else if (currentApiState == STATE_WORLD_BLOCK)
00126 luxError(LUX_ILLSTATE,LUX_ERROR,"luxCleanup() called while inside world block.");
00127
00128
00129 free();
00130
00131
00132 init();
00133 }
00134
00135 void Context::identity() {
00136 VERIFY_INITIALIZED("Identity");
00137 renderFarm->send("luxIdentity");
00138 curTransform = Transform();
00139 }
00140
00141 void Context::translate(float dx, float dy, float dz) {
00142 VERIFY_INITIALIZED("Translate");
00143 renderFarm->send("luxTranslate", dx, dy, dz);
00144 curTransform = curTransform * Translate(Vector(dx, dy, dz));
00145 }
00146
00147 void Context::transform(float tr[16]) {
00148 VERIFY_INITIALIZED("Transform");
00149 renderFarm->send("luxTransform", tr);
00150 boost::shared_ptr<Matrix4x4> o(new Matrix4x4(
00151 tr[0], tr[4], tr[8], tr[12],
00152 tr[1], tr[5], tr[9], tr[13],
00153 tr[2], tr[6], tr[10], tr[14],
00154 tr[3], tr[7], tr[11], tr[15]));
00155 curTransform = Transform(o);
00156 }
00157 void Context::concatTransform(float tr[16]) {
00158 VERIFY_INITIALIZED("ConcatTransform");
00159 renderFarm->send("luxConcatTransform", tr);
00160 boost::shared_ptr<Matrix4x4> o(new Matrix4x4(tr[0], tr[4], tr[8], tr[12],
00161 tr[1], tr[5], tr[9], tr[13],
00162 tr[2], tr[6], tr[10], tr[14],
00163 tr[3], tr[7], tr[11], tr[15]));
00164 curTransform = curTransform * Transform(o);
00165 }
00166 void Context::rotate(float angle, float dx, float dy, float dz) {
00167 VERIFY_INITIALIZED("Rotate");
00168 renderFarm->send("luxRotate", angle, dx, dy, dz);
00169 curTransform = curTransform * Rotate(angle, Vector(dx, dy, dz));
00170 }
00171 void Context::scale(float sx, float sy, float sz) {
00172 VERIFY_INITIALIZED("Scale");
00173 renderFarm->send("luxScale", sx, sy, sz);
00174 curTransform = curTransform * Scale(sx, sy, sz);
00175 }
00176 void Context::lookAt(float ex, float ey, float ez, float lx, float ly, float lz,
00177 float ux, float uy, float uz) {
00178 VERIFY_INITIALIZED("LookAt");
00179 renderFarm->send("luxLookAt", ex, ey, ez, lx, ly, lz, ux, uy, uz);
00180
00181 curTransform = curTransform * LookAt(Point(ex, ey, ez), Point(lx, ly, lz),
00182 Vector(ux, uy, uz));
00183 }
00184 void Context::coordinateSystem(const string &name) {
00185 VERIFY_INITIALIZED("CoordinateSystem");
00186 renderFarm->send("luxCoordinateSystem", name);
00187 namedCoordinateSystems[name] = curTransform;
00188 }
00189 void Context::coordSysTransform(const string &name) {
00190 VERIFY_INITIALIZED("CoordSysTransform");
00191 renderFarm->send("luxCoordSysTransform", name);
00192 if (namedCoordinateSystems.find(name) != namedCoordinateSystems.end())
00193 curTransform = namedCoordinateSystems[name];
00194 }
00195 void Context::enableDebugMode() {
00196 VERIFY_OPTIONS("EnableDebugMode")
00197 ;
00198
00199 renderOptions->debugMode = true;
00200 }
00201 void Context::pixelFilter(const string &name, const ParamSet ¶ms) {
00202 VERIFY_OPTIONS("PixelFilter")
00203 ;
00204 renderFarm->send("luxPixelFilter", name, params);
00205 renderOptions->FilterName = name;
00206 renderOptions->FilterParams = params;
00207 }
00208 void Context::film(const string &type, const ParamSet ¶ms) {
00209 VERIFY_OPTIONS("Film")
00210 ;
00211 renderFarm->send("luxFilm", type, params);
00212 renderOptions->FilmParams = params;
00213 renderOptions->FilmName = type;
00214 }
00215 void Context::sampler(const string &name, const ParamSet ¶ms) {
00216 VERIFY_OPTIONS("Sampler")
00217 ;
00218 renderFarm->send("luxSampler", name, params);
00219 renderOptions->SamplerName = name;
00220 renderOptions->SamplerParams = params;
00221 }
00222 void Context::accelerator(const string &name, const ParamSet ¶ms) {
00223 VERIFY_OPTIONS("Accelerator")
00224 ;
00225 renderFarm->send("luxAccelerator", name, params);
00226 renderOptions->AcceleratorName = name;
00227 renderOptions->AcceleratorParams = params;
00228 }
00229 void Context::surfaceIntegrator(const string &name, const ParamSet ¶ms) {
00230 VERIFY_OPTIONS("SurfaceIntegrator")
00231 ;
00232 renderFarm->send("luxSurfaceIntegrator", name, params);
00233 renderOptions->SurfIntegratorName = name;
00234 renderOptions->SurfIntegratorParams = params;
00235 }
00236 void Context::volumeIntegrator(const string &name, const ParamSet ¶ms) {
00237 VERIFY_OPTIONS("VolumeIntegrator")
00238 ;
00239 renderFarm->send("luxVolumeIntegrator", name, params);
00240 renderOptions->VolIntegratorName = name;
00241 renderOptions->VolIntegratorParams = params;
00242 }
00243 void Context::camera(const string &name, const ParamSet ¶ms) {
00244 VERIFY_OPTIONS("Camera")
00245 ;
00246 renderFarm->send("luxCamera", name, params);
00247
00248 renderOptions->CameraName = name;
00249 renderOptions->CameraParams = params;
00250 renderOptions->WorldToCamera = curTransform;
00251 namedCoordinateSystems["camera"] = curTransform.GetInverse();
00252 }
00253 void Context::worldBegin() {
00254 VERIFY_OPTIONS("WorldBegin")
00255 ;
00256 renderFarm->send("luxWorldBegin");
00257 currentApiState = STATE_WORLD_BLOCK;
00258 curTransform = Transform();
00259 namedCoordinateSystems["world"] = curTransform;
00260 }
00261 void Context::attributeBegin() {
00262 VERIFY_WORLD("AttributeBegin")
00263 ;
00264 renderFarm->send("luxAttributeBegin");
00265 pushedGraphicsStates.push_back(*graphicsState);
00266 pushedTransforms.push_back(curTransform);
00267 }
00268 void Context::attributeEnd() {
00269 VERIFY_WORLD("AttributeEnd")
00270 ;
00271 renderFarm->send("luxAttributeEnd");
00272 if (!pushedGraphicsStates.size()) {
00273 luxError(LUX_ILLSTATE,LUX_ERROR,"Unmatched luxAttributeEnd() encountered. Ignoring it.");
00274 return;
00275 }
00276 *graphicsState = pushedGraphicsStates.back();
00277 curTransform = pushedTransforms.back();
00278 pushedGraphicsStates.pop_back();
00279 pushedTransforms.pop_back();
00280 }
00281 void Context::transformBegin() {
00282 VERIFY_WORLD("TransformBegin")
00283 ;
00284 renderFarm->send("luxTransformBegin");
00285 pushedTransforms.push_back(curTransform);
00286 }
00287 void Context::transformEnd() {
00288 VERIFY_WORLD("TransformEnd")
00289 ;
00290 renderFarm->send("luxTransformEnd");
00291 if (!pushedTransforms.size()) {
00292 luxError(LUX_ILLSTATE,LUX_ERROR,"Unmatched luxTransformEnd() encountered. Ignoring it.");
00293 return;
00294 }
00295 curTransform = pushedTransforms.back();
00296 pushedTransforms.pop_back();
00297 }
00298 void Context::texture(const string &name, const string &type, const string &texname,
00299 const ParamSet ¶ms) {
00300 VERIFY_WORLD("Texture")
00301 ;
00302 renderFarm->send("luxTexture", name, type, texname, params);
00303
00304 TextureParams tp(params, params, graphicsState->floatTextures,
00305 graphicsState->spectrumTextures);
00306 if (type == "float") {
00307
00308 if (graphicsState->floatTextures.find(name)
00309 != graphicsState->floatTextures.end()) {
00310
00311 std::stringstream ss;
00312 ss<<"Texture '"<<name<<"' being redefined.";
00313 luxError(LUX_SYNTAX,LUX_WARNING,ss.str().c_str());
00314 }
00315 boost::shared_ptr<Texture<float> > ft = MakeFloatTexture(texname,
00316 curTransform, tp);
00317 if (ft)
00318 graphicsState->floatTextures[name] = ft;
00319 } else if (type == "color") {
00320
00321 if (graphicsState->spectrumTextures.find(name)
00322 != graphicsState->spectrumTextures.end()) {
00323
00324 std::stringstream ss;
00325 ss<<"Texture '"<<name<<"' being redefined.";
00326 luxError(LUX_SYNTAX,LUX_WARNING,ss.str().c_str());
00327 }
00328 boost::shared_ptr<Texture<Spectrum> > st = MakeSpectrumTexture(texname,
00329 curTransform, tp);
00330 if (st)
00331 graphicsState->spectrumTextures[name] = st;
00332 } else {
00333
00334 std::stringstream ss;
00335 ss<<"Texture type '"<<type<<"' unknown";
00336 luxError(LUX_SYNTAX,LUX_ERROR,ss.str().c_str());
00337 }
00338
00339 }
00340 void Context::material(const string &name, const ParamSet ¶ms) {
00341 VERIFY_WORLD("Material")
00342 ;
00343 renderFarm->send("luxMaterial", name, params);
00344 graphicsState->material = name;
00345 graphicsState->materialParams = params;
00346 }
00347
00348 void Context::makenamedmaterial(const string &name, const ParamSet ¶ms) {
00349 VERIFY_WORLD("MakeNamedMaterial")
00350 ;
00351 renderFarm->send("luxMakeNamedMaterial", name, params);
00352 NamedMaterial nm;
00353 nm.material = name;
00354 nm.materialParams = params;
00355 namedmaterials.push_back(nm);
00356 }
00357
00358 void Context::namedmaterial(const string &name, const ParamSet ¶ms) {
00359 VERIFY_WORLD("NamedMaterial")
00360 ;
00361 renderFarm->send("luxNamedMaterial", name, params);
00362 bool found = false;
00363 for(unsigned int i=0; i<namedmaterials.size(); i++)
00364 if(namedmaterials[i].material == name) {
00365 string type = namedmaterials[i].materialParams.FindOneString("type", "matte");
00366 ParamSet nparams = namedmaterials[i].materialParams;
00367 nparams.EraseString("type");
00368 material(type, nparams);
00369 found = true;
00370 }
00371
00372 if(!found) {
00373 std::stringstream ss;
00374 ss<<"NamedMaterial named '"<<name<<"' unknown";
00375 luxError(LUX_SYNTAX,LUX_ERROR,ss.str().c_str());
00376 }
00377 }
00378
00379 void Context::lightSource(const string &name, const ParamSet ¶ms) {
00380 VERIFY_WORLD("LightSource")
00381 ;
00382 renderFarm->send("luxLightSource", name, params);
00383
00384 if (name == "sunsky") {
00385
00386 Light *lt_sun = MakeLight("sun", curTransform, params);
00387 if (lt_sun == NULL)
00388 luxError(LUX_SYNTAX,LUX_ERROR,"luxLightSource: light type sun unknown.");
00389 else {
00390 renderOptions->lights.push_back(lt_sun);
00391 graphicsState->currentLight = name;
00392 graphicsState->currentLightPtr = lt_sun;
00393 }
00394 Light *lt_sky = MakeLight("sky", curTransform, params);
00395 if (lt_sky == NULL)
00396 luxError(LUX_SYNTAX,LUX_ERROR,"luxLightSource: light type sky unknown.");
00397 else {
00398 renderOptions->lights.push_back(lt_sky);
00399 graphicsState->currentLight = name;
00400 graphicsState->currentLightPtr = lt_sky;
00401 }
00402 } else {
00403
00404 Light *lt = MakeLight(name, curTransform, params);
00405 if (lt == NULL) {
00406
00407
00408 std::stringstream ss;
00409 ss<<"luxLightSource: light type '"<<name<<"' unknown";
00410 luxError(LUX_SYNTAX,LUX_ERROR,ss.str().c_str());
00411 } else {
00412 renderOptions->lights.push_back(lt);
00413 graphicsState->currentLight = name;
00414 graphicsState->currentLightPtr = lt;
00415 }
00416 }
00417 }
00418
00419 void Context::areaLightSource(const string &name, const ParamSet ¶ms) {
00420 VERIFY_WORLD("AreaLightSource")
00421 ;
00422 renderFarm->send("luxAreaLightSource", name, params);
00423
00424 graphicsState->areaLight = name;
00425 graphicsState->areaLightParams = params;
00426 }
00427
00428 void Context::portalShape(const string &name, const ParamSet ¶ms) {
00429 VERIFY_WORLD("PortalShape")
00430 ;
00431 renderFarm->send("luxPortalShape", name, params);
00432
00433 boost::shared_ptr<Shape> shape = MakeShape(name, curTransform,
00434 graphicsState->reverseOrientation, params, &graphicsState->floatTextures);
00435 if (!shape)
00436 return;
00437 params.ReportUnused();
00438
00439 AreaLight *area= NULL;
00440
00441
00442
00443
00444 if (graphicsState->currentLight != "") {
00445 if (graphicsState->currentLight == "sunsky"
00446 || graphicsState->currentLight == "infinite")
00447 graphicsState->currentLightPtr->AddPortalShape(shape);
00448 else {
00449
00450 std::stringstream ss;
00451 ss<<"LightType '"<<graphicsState->currentLight
00452 <<" does not support PortalShape(s).";
00453 luxError(LUX_UNIMPLEMENT,LUX_WARNING,ss.str().c_str());
00454 return;
00455 }
00456 }
00457
00458
00459 TextureParams mp(params, graphicsState->materialParams,
00460 graphicsState->floatTextures, graphicsState->spectrumTextures);
00461 boost::shared_ptr<Texture<float> > bump;
00462 boost::shared_ptr<Material> mtl = MakeMaterial("matte", curTransform, mp);
00463
00464
00465 Primitive* prim(new GeometricPrimitive(shape, mtl, area));
00466 }
00467
00468 void Context::makemixmaterial(const ParamSet shapeparams, const ParamSet materialparams, boost::shared_ptr<Material> mtl) {
00469
00470 string namedmaterial1 = materialparams.FindOneString("namedmaterial1", "-");
00471 bool found = false;
00472 for(unsigned int i=0; i<namedmaterials.size(); i++)
00473 if(namedmaterials[i].material == namedmaterial1) {
00474 string type = namedmaterials[i].materialParams.FindOneString("type", "matte");
00475 ParamSet nparams = namedmaterials[i].materialParams;
00476 nparams.EraseString("type");
00477 TextureParams mp1(shapeparams, nparams,
00478 graphicsState->floatTextures, graphicsState->spectrumTextures);
00479 boost::shared_ptr<Material> mtl1 = MakeMaterial(type, curTransform, mp1);
00480
00481 if(type == "mix")
00482 makemixmaterial(shapeparams, nparams, mtl1);
00483
00484 mtl->SetChild1(mtl1);
00485 found = true;
00486 }
00487 if(!found) {
00488 std::stringstream ss;
00489 ss<<"MixMaterial: NamedMaterial1 named '"<<namedmaterial1<<"' unknown";
00490 luxError(LUX_SYNTAX,LUX_ERROR,ss.str().c_str());
00491 }
00492
00493
00494 string namedmaterial2 = materialparams.FindOneString("namedmaterial2", "-");
00495 found = false;
00496 for(unsigned int i=0; i<namedmaterials.size(); i++)
00497 if(namedmaterials[i].material == namedmaterial2) {
00498 string type = namedmaterials[i].materialParams.FindOneString("type", "matte");
00499 ParamSet nparams = namedmaterials[i].materialParams;
00500 nparams.EraseString("type");
00501 TextureParams mp1(shapeparams, nparams,
00502 graphicsState->floatTextures, graphicsState->spectrumTextures);
00503 boost::shared_ptr<Material> mtl2 = MakeMaterial(type, curTransform, mp1);
00504
00505 if(type == "mix")
00506 makemixmaterial(shapeparams, nparams, mtl2);
00507
00508 mtl->SetChild2(mtl2);
00509 found = true;
00510 }
00511 if(!found) {
00512 std::stringstream ss;
00513 ss<<"MixMaterial: NamedMaterial2 named '"<<namedmaterial1<<"' unknown";
00514 luxError(LUX_SYNTAX,LUX_ERROR,ss.str().c_str());
00515 }
00516 }
00517
00518 void Context::shape(const string &name, const ParamSet ¶ms) {
00519 VERIFY_WORLD("Shape")
00520 ;
00521 renderFarm->send("luxShape", name, params);
00522
00523 boost::shared_ptr<Shape> shape = MakeShape(
00524 name,
00525 curTransform,
00526 graphicsState->reverseOrientation,
00527 params,
00528 &graphicsState->floatTextures);
00529 if (!shape)
00530 return;
00531 params.ReportUnused();
00532
00533 AreaLight *area= NULL;
00534 if (graphicsState->areaLight != "")
00535 area = MakeAreaLight(graphicsState->areaLight, curTransform,
00536 graphicsState->areaLightParams, shape);
00537
00538 TextureParams mp(params, graphicsState->materialParams,
00539 graphicsState->floatTextures, graphicsState->spectrumTextures);
00540 boost::shared_ptr<Texture<float> > bump;
00541 boost::shared_ptr<Material> mtl = MakeMaterial(graphicsState->material, curTransform, mp);
00542 if (!mtl)
00543 mtl = MakeMaterial("matte", curTransform, mp);
00544 if (!mtl)
00545 luxError(LUX_BUG,LUX_SEVERE,"Unable to create \"matte\" material?!");
00546
00547
00548
00549 if(graphicsState->material == "mix") {
00550 makemixmaterial(params, graphicsState->materialParams, mtl);
00551 }
00552
00553
00554 Primitive* prim(new GeometricPrimitive(shape, mtl, area));
00555 if (renderOptions->currentInstance) {
00556 if (area)
00557 luxError(LUX_UNIMPLEMENT,LUX_WARNING,"Area lights not supported with object instancing");
00558 renderOptions->currentInstance->push_back(prim);
00559 } else {
00560 renderOptions->primitives.push_back(prim);
00561 if (area != NULL) {
00562
00563 renderOptions->lights.push_back(area);
00564 }
00565 }
00566 }
00567 void Context::reverseOrientation() {
00568 VERIFY_WORLD("ReverseOrientation")
00569 ;
00570 renderFarm->send("luxReverseOrientation");
00571 graphicsState->reverseOrientation = !graphicsState->reverseOrientation;
00572 }
00573 void Context::volume(const string &name, const ParamSet ¶ms) {
00574 VERIFY_WORLD("Volume")
00575 ;
00576 renderFarm->send("luxVolume", name, params);
00577 VolumeRegion *vr = MakeVolumeRegion(name, curTransform, params);
00578 if (vr)
00579 renderOptions->volumeRegions.push_back(vr);
00580 }
00581 void Context::objectBegin(const string &name) {
00582 VERIFY_WORLD("ObjectBegin")
00583 ;
00584 renderFarm->send("luxObjectBegin", name);
00585 luxAttributeBegin();
00586 if (renderOptions->currentInstance)
00587 luxError(LUX_NESTING,LUX_ERROR,"ObjectBegin called inside of instance definition");
00588 renderOptions->instances[name] = vector<Primitive*>();
00589 renderOptions->currentInstance = &renderOptions->instances[name];
00590 }
00591 void Context::objectEnd() {
00592 VERIFY_WORLD("ObjectEnd")
00593 ;
00594 renderFarm->send("luxObjectEnd");
00595 if (!renderOptions->currentInstance)
00596 luxError(LUX_NESTING,LUX_ERROR,"ObjectEnd called outside of instance definition");
00597 renderOptions->currentInstance = NULL;
00598 luxAttributeEnd();
00599 }
00600 void Context::objectInstance(const string &name) {
00601 VERIFY_WORLD("ObjectInstance")
00602 ;
00603 renderFarm->send("luxObjectInstance", name);
00604
00605 if (renderOptions->currentInstance) {
00606 luxError(LUX_NESTING,LUX_ERROR,"ObjectInstance can't be called inside instance definition");
00607 return;
00608 }
00609 if (renderOptions->instances.find(name) == renderOptions->instances.end()) {
00610
00611 std::stringstream ss;
00612 ss<<"Unable to find instance named '"<<name<<"'";
00613 luxError(LUX_BADTOKEN,LUX_ERROR,ss.str().c_str());
00614 return;
00615 }
00616 vector<Primitive* > &in = renderOptions->instances[name];
00617 if (in.size() == 0)
00618 return;
00619 if (in.size() > 1 || !in[0]->CanIntersect()) {
00620
00621 Primitive* accel = MakeAccelerator(renderOptions->AcceleratorName, in,
00622 renderOptions->AcceleratorParams);
00623 if (!accel)
00624 accel = MakeAccelerator("kdtree", in, ParamSet());
00625 if (!accel)
00626 luxError(LUX_BUG,LUX_SEVERE,"Unable to find \"kdtree\" accelerator");
00627 in.erase(in.begin(), in.end());
00628 in.push_back(accel);
00629 }
00630 Primitive* o(new InstancePrimitive(in[0], curTransform));
00631 Primitive* prim = o;
00632 renderOptions->primitives.push_back(prim);
00633 }
00634
00635 void Context::worldEnd() {
00636 VERIFY_WORLD("WorldEnd")
00637 ;
00638 renderFarm->send("luxWorldEnd");
00639 renderFarm->flush();
00640
00641
00642
00643 boost::mutex::scoped_lock lock(renderingMutex);
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 while (pushedGraphicsStates.size()) {
00654 luxError(LUX_NESTING, LUX_WARNING, "Missing end to luxAttributeBegin()");
00655 pushedGraphicsStates.pop_back();
00656 pushedTransforms.pop_back();
00657 }
00658
00659 luxCurrentScene = renderOptions->MakeScene();
00660 if (luxCurrentScene) {
00661
00662 if (renderFarm->getServerCount() > 0)
00663 renderFarm->startFilmUpdater(luxCurrentScene);
00664
00665 luxCurrentScene->Render();
00666
00667
00668 if (renderFarm->getServerCount() > 0)
00669 renderFarm->stopFilmUpdater();
00670 }
00671
00672
00673
00674 currentApiState = STATE_OPTIONS_BLOCK;
00675 StatsPrint(stdout);
00676 curTransform = Transform();
00677 namedCoordinateSystems.erase(namedCoordinateSystems.begin(),
00678 namedCoordinateSystems.end());
00679 }
00680
00681 Scene *Context::RenderOptions::MakeScene() const {
00682
00683 Filter *filter = MakeFilter(FilterName, FilterParams);
00684 Film *film = MakeFilm(FilmName, FilmParams, filter);
00685 if (std::string(FilmName)=="film")
00686 luxError(LUX_NOERROR,LUX_WARNING,"Warning: Legacy PBRT 'film' does not provide tonemapped output or GUI film display. Use 'multifilm' instead.");
00687 Camera *camera = MakeCamera(CameraName, CameraParams, WorldToCamera, film);
00688 Sampler *sampler = MakeSampler(SamplerName, SamplerParams, film);
00689 SurfaceIntegrator *surfaceIntegrator = MakeSurfaceIntegrator(
00690 SurfIntegratorName, SurfIntegratorParams);
00691 VolumeIntegrator *volumeIntegrator = MakeVolumeIntegrator(
00692 VolIntegratorName, VolIntegratorParams);
00693 Primitive *accelerator = MakeAccelerator(AcceleratorName, primitives,
00694 AcceleratorParams);
00695 if (!accelerator) {
00696 ParamSet ps;
00697 accelerator = MakeAccelerator("kdtree", primitives, ps);
00698 }
00699 if (!accelerator)
00700 luxError(LUX_BUG,LUX_SEVERE,"Unable to find \"kdtree\" accelerator");
00701
00702 VolumeRegion *volumeRegion;
00703 if (volumeRegions.size() == 0)
00704 volumeRegion = NULL;
00705 else if (volumeRegions.size() == 1)
00706 volumeRegion = volumeRegions[0];
00707 else
00708 volumeRegion = new AggregateVolume(volumeRegions);
00709
00710 if (!camera || !sampler || !film || !accelerator || !filter
00711 || !surfaceIntegrator || !volumeIntegrator) {
00712 luxError(LUX_BUG,LUX_SEVERE,"Unable to create scene due to missing plug-ins");
00713 return NULL;
00714 }
00715 Scene *ret = new Scene(camera,
00716 surfaceIntegrator, volumeIntegrator,
00717 sampler, accelerator, lights, volumeRegion);
00718
00719 primitives.erase(primitives.begin(), primitives.end());
00720 lights.erase(lights.begin(), lights.end());
00721 volumeRegions.erase(volumeRegions.begin(), volumeRegions.end());
00722
00723
00724 if (debugMode) {
00725
00726 ret->seedBase = 0;
00727 }
00728
00729 return ret;
00730 }
00731
00732
00733 void Context::start() {
00734 luxCurrentScene->Start();
00735 }
00736
00737 void Context::pause() {
00738 luxCurrentScene->Pause();
00739 }
00740
00741 void Context::wait() {
00742 boost::mutex::scoped_lock lock(renderingMutex);
00743 }
00744
00745 void Context::exit() {
00746
00747 activeContext->renderFarm->stopFilmUpdater();
00748
00749 activeContext->renderFarm->updateFilm(luxCurrentScene);
00750
00751 activeContext->renderFarm->disconnectAll();
00752
00753 luxCurrentScene->Exit();
00754 }
00755
00756
00757 int Context::addThread() {
00758 return luxCurrentScene->AddThread();
00759 }
00760
00761 void Context::removeThread() {
00762 luxCurrentScene->RemoveThread();
00763 }
00764
00765
00766 void Context::updateFramebuffer() {
00767 luxCurrentScene->UpdateFramebuffer();
00768 }
00769
00770 unsigned char* Context::framebuffer() {
00771 return luxCurrentScene->GetFramebuffer();
00772 }
00773
00774 double Context::statistics(const string &statName) {
00775 if (statName=="sceneIsReady") return (luxCurrentScene!=NULL);
00776 else if (luxCurrentScene!=NULL) return luxCurrentScene->Statistics(statName);
00777 else return 0;
00778 }
00779
00780 void Context::transmitFilm(std::basic_ostream<char> &stream) {
00781
00782 FlexImageFilm *fif = (FlexImageFilm *)luxCurrentScene->camera->film;
00783
00784 fif->TransmitFilm(stream);
00785 }
00786
00787 void Context::updateFilmFromNetwork() {
00788 renderFarm->updateFilm(luxCurrentScene);
00789 }