void VolumeViewer::initObjects(const std::string &renderer_type) { // Create an OSPRay renderer. renderer = ospNewRenderer(renderer_type.c_str()); exitOnCondition(renderer == NULL, "could not create OSPRay renderer object"); // Set renderer defaults (if not using 'aoX' renderers) if (renderer_type[0] != 'a' && renderer_type[1] != 'o') { ospSet1i(renderer, "aoSamples", 1); ospSet1i(renderer, "shadowsEnabled", 1); } // Create OSPRay ambient and directional lights. GUI elements will modify their parameters. ambientLight = ospNewLight(renderer, "AmbientLight"); exitOnCondition(ambientLight == NULL, "could not create ambient light"); ospCommit(ambientLight); directionalLight = ospNewLight(renderer, "DirectionalLight"); exitOnCondition(directionalLight == NULL, "could not create directional light"); ospCommit(directionalLight); // Set the light sources on the renderer. std::vector<OSPLight> lights; lights.push_back(ambientLight); lights.push_back(directionalLight); ospSetData(renderer, "lights", ospNewData(lights.size(), OSP_OBJECT, &lights[0])); // Create an OSPRay transfer function. transferFunction = ospNewTransferFunction("piecewise_linear"); exitOnCondition(transferFunction == NULL, "could not create OSPRay transfer function object"); ospCommit(transferFunction); // Load OSPRay objects from files. for (size_t i=0 ; i < objectFileFilenames.size() ; i++) importObjectsFromFile(objectFileFilenames[i]); // Get the bounding box of all volumes of the first model. if(modelStates.size() > 0 && modelStates[0].volumes.size() > 0) { ospGetVec3f(modelStates[0].volumes[0], "boundingBoxMin", (osp::vec3f*)&boundingBox.lower); ospGetVec3f(modelStates[0].volumes[0], "boundingBoxMax", (osp::vec3f*)&boundingBox.upper); for (size_t i=1; i<modelStates[0].volumes.size(); i++) { ospcommon::box3f volumeBoundingBox; ospGetVec3f(modelStates[0].volumes[i], "boundingBoxMin", (osp::vec3f*)&volumeBoundingBox.lower); ospGetVec3f(modelStates[0].volumes[i], "boundingBoxMax", (osp::vec3f*)&volumeBoundingBox.upper); boundingBox.extend(volumeBoundingBox); } } }
OSPLight OSPObjectFile::importLight(const tinyxml2::XMLNode *root) { // Create the OSPRay object. OSPLight light = ospNewLight(NULL, root->ToElement()->Attribute("type")); // Iterate over object attributes. for (const tinyxml2::XMLNode *node = root->FirstChild() ; node ; node = node->NextSibling()) { // Light color. if (!strcmp(node->ToElement()->Name(), "color")) { importAttributeFloat3(node, light); continue; } // Light direction. if (!strcmp(node->ToElement()->Name(), "direction")) { importAttributeFloat3(node, light); continue; } // Light half angle for spot lights. if (!strcmp(node->ToElement()->Name(), "halfAngle")) { importAttributeFloat(node, light); continue; } // Light position. if (!strcmp(node->ToElement()->Name(), "position")) { importAttributeFloat3(node, light); continue; } // Light illumination distance cutoff. if (!strcmp(node->ToElement()->Name(), "range")) { importAttributeFloat(node, light); continue; } // Error check. exitOnCondition(true, "unrecognized XML element type '" + std::string(node->ToElement()->Name()) + "'"); } // The populated light object. return light; }
OSPObjectCatalog OSPObjectFile::importLight(const tinyxml2::XMLNode *root) { //! Create the OSPRay object. OSPLight light = ospNewLight(NULL, root->ToElement()->Attribute("type")); //! Iterate over object attributes. for (const tinyxml2::XMLNode *node = root->FirstChild() ; node ; node = node->NextSibling()) importLightAttribute(node, light); //! Catalog the object attributes to allow introspection by the application. return(new ObjectCatalog(root->ToElement()->Attribute("name"), (ManagedObject *) light)); }