Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
  void OSPObjectFile::importLightAttribute(const tinyxml2::XMLNode *node, OSPLight light) {

    //! Light color.
    if (!strcmp(node->ToElement()->Name(), "color")) return(importAttributeFloat3(node, light));

    //! Light direction.
    if (!strcmp(node->ToElement()->Name(), "direction")) return(importAttributeFloat3(node, light));

    //! Light half angle for spot lights.
    if (!strcmp(node->ToElement()->Name(), "halfAngle")) return(importAttributeFloat(node, light));

    //! Light position.
    if (!strcmp(node->ToElement()->Name(), "position")) return(importAttributeFloat3(node, light));

    //! Light illumination distance cutoff.
    if (!strcmp(node->ToElement()->Name(), "range")) return(importAttributeFloat(node, light));

    //! Error check.
    exitOnCondition(true, "unrecognized XML element type '" + std::string(node->ToElement()->Name()) + "'");

  }
Ejemplo n.º 3
0
  void OSPObjectFile::importVolumeAttribute(const tinyxml2::XMLNode *node, OSPVolume volume) {

    //! Volume size in voxels per dimension.
    if (!strcmp(node->ToElement()->Name(), "dimensions")) return(importAttributeInteger3(node, volume));

    //! File containing a volume specification and / or voxel data.
    if (!strcmp(node->ToElement()->Name(), "filename")) return(importVolumeFile(node, volume));

    //! Gamma correction coefficient and exponent.
    if (!strcmp(node->ToElement()->Name(), "gammaCorrection")) return(importAttributeFloat2(node, volume));

    //! Sampling rate for ray casting based renderers.
    if (!strcmp(node->ToElement()->Name(), "samplingRate")) return(importAttributeFloat(node, volume));

    //! Subvolume offset from origin within the full volume.
    if (!strcmp(node->ToElement()->Name(), "subvolumeOffsets")) return(importAttributeInteger3(node, volume));

    //! Subvolume dimensions within the full volume.
    if (!strcmp(node->ToElement()->Name(), "subvolumeDimensions")) return(importAttributeInteger3(node, volume));

    //! Subvolume steps in each dimension; can be used to subsample the volume.
    if (!strcmp(node->ToElement()->Name(), "subvolumeSteps")) return(importAttributeInteger3(node, volume));

    //! Voxel value range.
    if (!strcmp(node->ToElement()->Name(), "voxelRange")) return(importAttributeFloat2(node, volume));

    //! Voxel spacing in world coordinates (currently unused).
    if (!strcmp(node->ToElement()->Name(), "voxelSpacing")) return(importAttributeFloat3(node, volume));

    //! Voxel type string.
    if (!strcmp(node->ToElement()->Name(), "voxelType")) return(importAttributeString(node, volume));

    //! Error check.
    exitOnCondition(true, "unrecognized XML element type '" + std::string(node->ToElement()->Name()) + "'");

  }
Ejemplo n.º 4
0
OSPVolume OSPObjectFile::importVolume(const tinyxml2::XMLNode *root)
{
  const char *dpFromEnv = getenv("OSPRAY_DATA_PARALLEL");

  OSPVolume volume = NULL;
  if (dpFromEnv) {
    // Create the OSPRay object.
    osp::vec3i blockDims;
    int rc = sscanf(dpFromEnv,"%dx%dx%d",&blockDims.x,&blockDims.y,&blockDims.z);
    if (rc !=3)
      throw std::runtime_error("could not parse OSPRAY_DATA_PARALLEL env-var. Must be of format <X>x<Y>x<>Z (e.g., '4x4x4'");
    volume = ospNewVolume("data_distributed_volume");
    if (volume == NULL)
      throw std::runtime_error("#loaders.ospObjectFile: could not create volume ...");
   ospSetVec3i(volume,"num_dp_blocks",blockDims);
  } else {
    // Create the OSPRay object.
    volume = ospNewVolume("block_bricked_volume");
  }
  if (volume == NULL)
    throw std::runtime_error("#loaders.ospObjectFile: could not create volume ...");

  // Temporary storage for the file name attribute if specified.
  const char *volumeFilename = NULL;

  // Iterate over object attributes.
  for (const tinyxml2::XMLNode *node = root->FirstChild() ; node ; node = node->NextSibling()) {

    // Volume size in voxels per dimension.
    if (!strcmp(node->ToElement()->Name(), "dimensions")) { importAttributeInteger3(node, volume);  continue; }

    // File containing a volume specification and / or voxel data.
    if (!strcmp(node->ToElement()->Name(), "filename")) { volumeFilename = node->ToElement()->GetText();  continue; }

    // Grid origin in world coordinates.
    if (!strcmp(node->ToElement()->Name(), "gridOrigin")) { importAttributeFloat3(node, volume);  continue; }

    // Grid spacing in each dimension in world coordinates.
    if (!strcmp(node->ToElement()->Name(), "gridSpacing")) { importAttributeFloat3(node, volume);  continue; }

    // Sampling rate for ray casting based renderers.
    if (!strcmp(node->ToElement()->Name(), "samplingRate")) { importAttributeFloat(node, volume);  continue; }

    // Subvolume offset from origin within the full volume.
    if (!strcmp(node->ToElement()->Name(), "subvolumeOffsets")) { importAttributeInteger3(node, volume);  continue; }

    // Subvolume dimensions within the full volume.
    if (!strcmp(node->ToElement()->Name(), "subvolumeDimensions")) { importAttributeInteger3(node, volume);  continue; }

    // Subvolume steps in each dimension; can be used to subsample the volume.
    if (!strcmp(node->ToElement()->Name(), "subvolumeSteps")) { importAttributeInteger3(node, volume);  continue; }

    // Voxel value range.
    if (!strcmp(node->ToElement()->Name(), "voxelRange")) { importAttributeFloat2(node, volume);  continue; }

    // Voxel type string.
    if (!strcmp(node->ToElement()->Name(), "voxelType")) { importAttributeString(node, volume);  continue; }

    // Error check.
    exitOnCondition(true, "unrecognized XML element type '" + std::string(node->ToElement()->Name()) + "'");
  }

  // Load the contents of the volume file if specified.
  if (volumeFilename != NULL) {

    // Some implementations of 'dirname()' are destructive.
    char *duplicateFilename = strdup(filename.c_str());

    // The volume file path is absolute.
    if (volumeFilename[0] == '/') 
      return(VolumeFile::importVolume(volumeFilename, volume));

    // The volume file path is relative to the object file path.
    if (volumeFilename[0] != '/') 
      return(VolumeFile::importVolume((std::string(dirname(duplicateFilename)) + "/" + volumeFilename).c_str(), volume));

    // Free the temporary character array.
    if (duplicateFilename != NULL) free(duplicateFilename);
  }

  // The populated volume object.
  return volume;
}