Пример #1
0
void VolumeViewer::setSamplingRate(double value)
{
  for(size_t i=0; i<modelStates.size(); i++)
    for(size_t j=0; j<modelStates[i].volumes.size(); j++) {
      ospSet1f(modelStates[i].volumes[j], "samplingRate", value);
      ospCommit(modelStates[i].volumes[j]);
    }

  render();
}
Пример #2
0
void OSPObjectFile::importAttributeFloat(const tinyxml2::XMLNode *node, OSPObject parent)
{
  // The attribute value is encoded in a string.
  const char *text = node->ToElement()->GetText();  float value = 0.0f;  char guard[8];

  // Get the attribute value.
  exitOnCondition(sscanf(text, "%f %7s", &value, guard) != 1, "malformed XML element '" + std::string(node->ToElement()->Name()) + "'");

  // Set the attribute on the parent object.
  ospSet1f(parent, node->ToElement()->Name(), value);
}
Пример #3
0
    void ToneMapper::postCommit(RenderContext &)
    {
      if (!child("enabled").valueAs<bool>())
        return;

      auto toneMapper = valueAs<OSPPixelOp>();

      float exposure = child("exposure").valueAs<float>();
      float linearExposure = exp2(exposure);
      ospSet1f(toneMapper, "exposure", linearExposure);

      ospCommit(toneMapper);
    }
Пример #4
0
    void Material::render(RenderContext &ctx)
    {
      if (ospMaterial) return;
      
      ospMaterial = ospNewMaterial(ctx.integrator->getOSPHandle(), type.c_str());
      
      //We failed to create a material of the given type, handle it
      if (!ospMaterial) {
        std::cerr << "Warning: Could not create material type '" << type << "'. Replacing with default material." << std::endl;
        //Replace with default
        static OSPMaterial defaultMaterial = NULL;
        if (defaultMaterial) {
          ospMaterial = defaultMaterial;
          return;
        }
        defaultMaterial = ospNewMaterial(ctx.integrator->getOSPHandle(), "OBJMaterial");
        vec3f kd(.7f);
        vec3f ks(.3f);
        ospSet3fv(defaultMaterial, "Kd", &kd.x);
        ospSet3fv(defaultMaterial, "Ks", &ks.x);
        ospSet1f(defaultMaterial, "Ns", 99.f);
        ospCommit(defaultMaterial);
        return;
      }

      for(size_t i = 0; i < textures.size(); i++) {
        textures[i]->render(ctx);
      }
      
      //Forward all params on to the ospMaterial...
      for (ParamMap::const_iterator itr = param.begin(); itr != param.end(); ++itr) {
        switch(itr->second->getOSPDataType()) {
        case OSP_INT:
        case OSP_UINT:
          {
            ParamT<int> *p = (ParamT<int>*)itr->second.ptr;
            if(itr->second->getName().find("map_") != std::string::npos) {
              //Handle textures!
              assert(textures[p->value]->ospTexture != NULL && "Texture should not be null at this point.");
              ospSetObject(ospMaterial, itr->second->getName().c_str(), textures[p->value]->ospTexture);
            } else {
              ospSet1i(ospMaterial, itr->second->getName().c_str(), p->value);
            }
          }
          break;
        case OSP_INT3:
        case OSP_UINT3:
          {
            ParamT<vec3i> *p = (ParamT<vec3i>*)itr->second.ptr;
            ospSet3i(ospMaterial, itr->second->getName().c_str(), p->value.x, p->value.y, p->value.z);
          }
          break;
        case OSP_FLOAT:
          {
            ParamT<float> *p = (ParamT<float>*)itr->second.ptr;
            ospSet1f(ospMaterial, itr->second->getName().c_str(), p->value);
          }
          break;
        case OSP_FLOAT2:
          {
            ParamT<vec2f> *p = (ParamT<vec2f>*)itr->second.ptr;
            ospSet2fv(ospMaterial, itr->second->getName().c_str(), &p->value.x);
          }
          break;
        case OSP_FLOAT3:
          {
            ParamT<vec3f> *p = (ParamT<vec3f>*)itr->second.ptr;
            ospSet3fv(ospMaterial, itr->second->getName().c_str(), &p->value.x);
          }
          break;
        default: //Catch not yet implemented data types
          std::cerr << "Warning: parameter '" << itr->second->getName() << "' of material '" << name << "' had an invalid data type and will be ignored." << std::endl;
        }
      }
        

      ospCommit(ospMaterial);
    }
Пример #5
0
int main(int ac, const char **av) {
  // image size
  osp_vec2i imgSize;
  imgSize.x = 1024; // width
  imgSize.y = 768; // height

  // camera
  float cam_pos[] = {0.f, 0.f, 0.f};
  float cam_up [] = {0.f, 1.f, 0.f};
  float cam_view [] = {0.1f, 0.f, 1.f};

  // triangle mesh data
  float vertex[] = { -1.0f, -1.0f, 3.0f, 0.f,
                     -1.0f,  1.0f, 3.0f, 0.f,
                      1.0f, -1.0f, 3.0f, 0.f,
                      0.1f,  0.1f, 0.3f, 0.f };
  float color[] =  { 0.9f, 0.5f, 0.5f, 1.0f,
                     0.8f, 0.8f, 0.8f, 1.0f,
                     0.8f, 0.8f, 0.8f, 1.0f,
                     0.5f, 0.9f, 0.5f, 1.0f };
  int32_t index[] = { 0, 1, 2,
                      1, 2, 3 };


  // initialize OSPRay; OSPRay parses (and removes) its commandline parameters, e.g. "--osp:debug"
  ospInit(&ac, av);

  // create and setup camera
  OSPCamera camera = ospNewCamera("perspective");
  ospSetf(camera, "aspect", imgSize.x/(float)imgSize.y);
  ospSet3fv(camera, "pos", cam_pos);
  ospSet3fv(camera, "dir", cam_view);
  ospSet3fv(camera, "up",  cam_up);
  ospCommit(camera); // commit each object to indicate modifications are done


  // create and setup model and mesh
  OSPGeometry mesh = ospNewGeometry("triangles");
  OSPData data = ospNewData(4, OSP_FLOAT3A, vertex, 0); // OSP_FLOAT3 format is also supported for vertex positions (currently not on MIC)
  ospCommit(data);
  ospSetData(mesh, "vertex", data);

  data = ospNewData(4, OSP_FLOAT4, color, 0);
  ospCommit(data);
  ospSetData(mesh, "vertex.color", data);

  data = ospNewData(2, OSP_INT3, index, 0); // OSP_INT4 format is also supported for triangle indices
  ospCommit(data);
  ospSetData(mesh, "index", data);

  ospCommit(mesh);


  OSPModel world = ospNewModel();
  ospAddGeometry(world, mesh);
  ospCommit(world);


  // create and setup renderer
  OSPRenderer renderer = ospNewRenderer("scivis"); // choose Scientific Visualization renderer
  ospSet1f(renderer, "aoWeight", 1.0f);            // with full Ambient Occlusion
  ospSet1i(renderer, "aoSamples", 1);
  ospSetObject(renderer, "model",  world);
  ospSetObject(renderer, "camera", camera);
  ospCommit(renderer);


  // create and setup framebuffer
  OSPFrameBuffer framebuffer = ospNewFrameBuffer(&imgSize, OSP_FB_SRGBA, OSP_FB_COLOR | /*OSP_FB_DEPTH |*/ OSP_FB_ACCUM);
  ospFrameBufferClear(framebuffer, OSP_FB_COLOR | OSP_FB_ACCUM);

  // render one frame
  ospRenderFrame(framebuffer, renderer, OSP_FB_COLOR | OSP_FB_ACCUM);

  // access framebuffer and write its content as PPM file
  const uint32_t * fb = (uint32_t*)ospMapFrameBuffer(framebuffer, OSP_FB_COLOR);
  writePPM("firstFrameC.ppm", &imgSize, fb);
  ospUnmapFrameBuffer(fb, framebuffer);


  // render 10 more frames, which are accumulated to result in a better converged image
  for (int frames = 0; frames < 10; frames++)
    ospRenderFrame(framebuffer, renderer, OSP_FB_COLOR | OSP_FB_ACCUM);

  fb = (uint32_t*)ospMapFrameBuffer(framebuffer, OSP_FB_COLOR);
  writePPM("accumulatedFrameC.ppm", &imgSize, fb);
  ospUnmapFrameBuffer(fb, framebuffer);

  return 0;
}