void LinearTransferFunction::commit()
  {
    // Create the equivalent ISPC transfer function.
    if (ispcEquivalent == NULL) createEquivalentISPC();

    // Retrieve the color and opacity values.
    colorValues   = getParamData("colors", NULL);  
    opacityValues = getParamData("opacities", NULL);

    // Set the color values.
    if (colorValues) 
      ispc::LinearTransferFunction_setColorValues(ispcEquivalent, 
                                                  colorValues->numItems, 
                                                  (ispc::vec3f *) colorValues->data);

    // Set the opacity values.
    if (opacityValues) {
      float *alpha = (float *)opacityValues->data;
      ispc::LinearTransferFunction_setOpacityValues(ispcEquivalent, 
                                                    opacityValues->numItems, 
                                                    (float *)opacityValues->data);
    }

    // Set the value range that the transfer function covers.
    vec2f valueRange = getParam2f("valueRange", vec2f(0.0f, 1.0f));  
    ispc::TransferFunction_setValueRange(ispcEquivalent, (const ispc::vec2f &) valueRange);

    // Notify listeners that the transfer function has changed.
    notifyListenersThatObjectGotChanged();
  }
예제 #2
0
  void StreamLines::finalize(Model *model) 
  {
    radius     = getParam1f("radius",0.01f);
    vertexData = getParamData("vertex",NULL);
    indexData  = getParamData("index",NULL);
    colorData  = getParamData("vertex.color",getParamData("color"));

    Assert(radius > 0.f);
    Assert(vertexData);
    Assert(indexData);

    index       = (const uint32*)indexData->data;
    numSegments = indexData->numItems;
    vertex      = (const vec3fa*)vertexData->data;
    numVertices = vertexData->numItems;
    color       = colorData ? (const vec4f*)colorData->data : NULL;

    std::cout << "#osp: creating streamlines geometry, "
              << "#verts=" << numVertices << ", "
              << "#segments=" << numSegments << ", "
              << "radius=" << radius << std::endl;
    
    ispc::StreamLineGeometry_set(getIE(),model->getIE(),radius,
                                 (ispc::vec3fa*)vertex,numVertices,
                                 (uint32_t*)index,numSegments,
                                 (ispc::vec4f*)color);
  }
예제 #3
0
void SimulationRenderer::commit( )
{
    Renderer::commit();

    lightData = ( ospray::Data* )getParamData( "lights" );
    lightArray.clear( );

    if( lightData )
        for( size_t i=0; i < lightData->size( ); ++i )
            lightArray.push_back(
                ( ( ospray::Light** )lightData->data )[ i ]->getIE( ));

    void **lightPtr = lightArray.empty() ? nullptr : &lightArray[0];

    ospray::vec3f bgColor = getParam3f( "bgColor", ospray::vec3f( 1.f ));

    shadowsEnabled = bool( getParam1i( "shadowsEnabled", 1 ));

    softShadowsEnabled = bool(getParam1i( "softShadowsEnabled", 1 ));
    ambientOcclusionStrength = getParam1f( "ambientOcclusionStrength", 0.f );
    shadingEnabled = bool( getParam1i( "shadingEnabled", 1 ));
    randomNumber = getParam1i( "randomNumber", 0 );
    moving = bool( getParam1i( "moving", 0 ));
    timestamp = getParam1f( "timestamp", 0.f );
    spp = getParam1i("spp", 1);
    electronShadingEnabled = bool( getParam1i( "electronShading", 0 ));
    ospray::vec3f scale = getParam3f( "scale", ospray::vec3f( 1.f ));
    simulationNbOffsets = getParam1i( "simulationNbOffsets", 0 );
    simulationNbFrames = getParam1i( "simulationNbFrames", 0 );

    // Those materials are used for simulation mapping only
    materialData = ( ospray::Data* )getParamData( "materials" );
    materialArray.clear( );
    if( materialData )
        for( size_t i = 0; i < materialData->size( ); ++i )
            materialArray.push_back(
                ( ( ospray::Material** )materialData->data )[i]->getIE( ));
    void **materialPtr = materialArray.empty( ) ? nullptr : &materialArray[0];

    ispc::SimulationRenderer_set(
                getIE( ),
                ( ispc::vec3f& )bgColor,
                ( ispc::vec3f& )scale,
                shadowsEnabled,
                softShadowsEnabled,
                ambientOcclusionStrength,
                shadingEnabled,
                randomNumber,
                moving,
                timestamp,
                spp,
                electronShadingEnabled,
                simulationNbOffsets,
                simulationNbFrames,
                lightPtr, lightArray.size( ),
                materialPtr, materialArray.size( ));
}
예제 #4
0
void ProximityRenderer::commit( )
{
    Renderer::commit( );

    lightData = ( ospray::Data* )getParamData( "lights" );
    lightArray.clear( );

    if( lightData )
        for( size_t i = 0; i < lightData->size( ); ++i )
            lightArray.push_back(((Light**)lightData->data)[i]->getIE());

    void **lightPtr = lightArray.empty( ) ? NULL : &lightArray[0];

    vec3f bgColor = getParam3f( "bgColor", vec3f( 0.f ));
    vec3f nearColor = getParam3f( "detectionNearColor", vec3f( 0.f, 1.f, 0.f ));
    vec3f farColor = getParam3f( "detectionFarColor", vec3f( 1.f, 0.f, 0.f ));
    detectionDistance = getParam1f( "detectionDistance", 1.f );
    detectionOnDifferentMaterial =
        bool( getParam1i( "detectionOnDifferentMaterial", 0 ));
    randomNumber = getParam1i( "randomNumber", 0 );
    timestamp = getParam1f( "timestamp", 0.f );
    spp = getParam1i( "spp", 1 );
    electronShadingEnabled = bool( getParam1i( "electronShading", 1 ));

    // Those materials are used for skybox mapping only
    materialData = ( ospray::Data* )getParamData( "materials" );
    materialArray.clear( );
    if( materialData )
        for( size_t i = 0; i < materialData->size( ); ++i )
            materialArray.push_back(
                ( ( ospray::Material** )materialData->data )[i]->getIE( ));
    void **materialArrayPtr =
        materialArray.empty( ) ? nullptr : &materialArray[0];

    ispc::ProximityRenderer_set(
                getIE( ),
                ( ispc::vec3f& )bgColor,
                ( ispc::vec3f& )nearColor,
                ( ispc::vec3f& )farColor,
                detectionDistance,
                detectionOnDifferentMaterial,
                randomNumber,
                timestamp,
                spp,
                electronShadingEnabled,
                lightPtr, lightArray.size( ),
                materialArrayPtr, materialArray.size( ));
}
예제 #5
0
    void SciVisRenderer::commit()
    {
      Renderer::commit();

      lightData = (Data*)getParamData("lights");

      lightArray.clear();

      if (lightData) {
        for (int i = 0; i < lightData->size(); i++)
          lightArray.push_back(((Light**)lightData->data)[i]->getIE());
      }

      void **lightPtr = lightArray.empty() ? NULL : &lightArray[0];

      const bool shadowsEnabled = getParam1i("shadowsEnabled", 0);

      const int32 maxDepth = getParam1i("maxDepth", 10);

      int   numAOSamples = getParam1i("aoSamples", 0);
      float rayLength    = getParam1f("aoOcclusionDistance", 1e20f);
      float aoWeight     = getParam1f("aoWeight", 0.25f);

      ispc::SciVisRenderer_set(getIE(),
                               shadowsEnabled,
                               maxDepth,
                               numAOSamples,
                               rayLength,
                               aoWeight,
                               lightPtr,
                               lightArray.size());
    }
예제 #6
0
void ExtendedCylinders::finalize(ospray::Model *model)
{
    radius            = getParam1f("radius",0.01f);
    materialID        = getParam1i("materialID",0);
    bytesPerCylinder  = getParam1i("bytes_per_cylinder",9*sizeof(float));
    offset_v0         = getParam1i("offset_v0",0);
    offset_v1         = getParam1i("offset_v1",3*sizeof(float));
    offset_radius     = getParam1i("offset_radius",6*sizeof(float));
    offset_timestamp  = getParam1i("offset_timestamp",7*sizeof(float));
    offset_value      = getParam1i("offset_value",8*sizeof(float));
    offset_materialID = getParam1i("offset_materialID",-1);
    data              = getParamData("extendedcylinders",nullptr);

    if (data.ptr == nullptr || bytesPerCylinder == 0)
        throw std::runtime_error("#ospray:geometry/extendedcylinders: " \
                                 "no 'extendedcylinders' data specified");
    numExtendedCylinders = data->numBytes / bytesPerCylinder;
    ispc::ExtendedCylindersGeometry_set(
                getIE(),
                model->getIE(),
                data->data,
                numExtendedCylinders,
                bytesPerCylinder,
                radius,
                materialID,
                offset_v0,
                offset_v1,
                offset_radius,
                offset_timestamp,
                offset_value,
                offset_materialID);
}
예제 #7
0
  void StructuredVolume::getVolumeFromMemory() 
  {
    //! Create the equivalent ISPC volume container and allocate memory for voxel data.
    createEquivalentISPC();

    //! Get a pointer to the source voxel data.
    const Data *voxelData = getParamData("voxelData", NULL);  
    exitOnCondition(voxelData == NULL, "no voxel data specified");  

    const uint8 *data = (const uint8 *) voxelData->data;

    //! The dimensions of the source voxel data and target volume must match.
    exitOnCondition(size_t(volumeDimensions.x) * volumeDimensions.y * volumeDimensions.z != voxelData->numItems, "unexpected source voxel data dimensions");

    //! The source and target voxel types must match.
    exitOnCondition(getVoxelType() != voxelData->type, "unexpected source voxel type");

    //! Size of a volume slice in bytes.
    size_t sliceSizeInBytes = volumeDimensions.x * volumeDimensions.y * getVoxelSizeInBytes();

    //! Copy voxel data into the volume in slices to avoid overflow in ISPC offset calculations.
    for (size_t z=0 ; z < volumeDimensions.z ; z++) 
      setRegion(&data[z * sliceSizeInBytes], vec3i(0, 0, z), 
                vec3i(volumeDimensions.x, volumeDimensions.y, 1));

  }
예제 #8
0
void ParameterItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
    setColor(Qt::red);
    getParamData();
    setColor(Qt::darkCyan);
    event->setAccepted(true);
}
예제 #9
0
  void Cylinders::finalize(Model *model)
  {
    radius            = getParam1f("radius",0.01f);
    materialID        = getParam1i("materialID",0);
    bytesPerCylinder  = getParam1i("bytes_per_cylinder",6*sizeof(float));
    offset_v0         = getParam1i("offset_v0",0);
    offset_v1         = getParam1i("offset_v1",3*sizeof(float));
    offset_radius     = getParam1i("offset_radius",-1);
    offset_materialID = getParam1i("offset_materialID",-1);
    offset_colorID    = getParam1i("offset_colorID",-1);
    cylinderData      = getParamData("cylinders");
    materialList      = getParamData("materialList");
    colorData         = getParamData("color");

    if (cylinderData.ptr == NULL || bytesPerCylinder == 0)
      throw std::runtime_error("#ospray:geometry/cylinders: no 'cylinders' data specified");
    numCylinders = cylinderData->numBytes / bytesPerCylinder;
    std::cout << "#osp: creating 'cylinders' geometry, #cylinders = " << numCylinders << std::endl;

    if (_materialList) {
      free(_materialList);
      _materialList = NULL;
    }

    if (materialList) {
      void **ispcMaterials = (void**) malloc(sizeof(void*) * materialList->numItems);
      for (int i=0;i<materialList->numItems;i++) {
        Material *m = ((Material**)materialList->data)[i];
        ispcMaterials[i] = m?m->getIE():NULL;
      }
      _materialList = (void*)ispcMaterials;
    }

    ispc::CylindersGeometry_set(getIE(),model->getIE(),
                                cylinderData->data,_materialList,
                                colorData?(ispc::vec4f*)colorData->data:NULL,
                                numCylinders,bytesPerCylinder,
                                radius,materialID,
                                offset_v0,offset_v1,
                                offset_radius,
                                offset_materialID,offset_colorID);
  }
예제 #10
0
  void Slices::finalize(Model *model) 
  {
    planesData = getParamData("planes", NULL);
    volume     = (Volume *)getParamObject("volume", NULL);

    Assert(planesData);
    Assert(volume);

    numPlanes = planesData->numItems;
    planes    = (const vec4f*)planesData->data;

    ispc::Slices_set(getIE(), model->getIE(), numPlanes, (ispc::vec4f*)planes, volume->getIE());
  }
예제 #11
0
    void SciVisRenderer::commit()
    {
      Renderer::commit();

      lightData = (Data*)getParamData("lights");

      lightArray.clear();
      vec3f aoColor = vec3f(0.f);
      bool ambientLights = false;

      if (lightData) {
        for (uint32_t i = 0; i < lightData->size(); i++)
        {
          const Light* const light = ((Light**)lightData->data)[i];
          // extract color from ambient lights and remove them
          const AmbientLight* const ambient = dynamic_cast<const AmbientLight*>(light);
          if (ambient) {
            ambientLights = true;
            aoColor += ambient->getRadiance();
          } else
            lightArray.push_back(light->getIE());
        }
      }

      void **lightPtr = lightArray.empty() ? nullptr : &lightArray[0];

      const bool shadowsEnabled = getParam1i("shadowsEnabled", 0);
      int aoSamples = getParam1i("aoSamples", 0);
      float aoDistance = getParam1f("aoDistance",
                          getParam1f("aoOcclusionDistance"/*old name*/, 1e20f));
      // "aoWeight" is deprecated, use an ambient light instead
      if (!ambientLights)
        aoColor = vec3f(getParam1f("aoWeight", 0.f));
      const bool aoTransparencyEnabled = getParam1i("aoTransparencyEnabled", 0);
      const bool oneSidedLighting = getParam1i("oneSidedLighting", 1);

      ispc::SciVisRenderer_set(getIE(),
                               shadowsEnabled,
                               aoSamples,
                               aoDistance,
                               (ispc::vec3f&)aoColor,
                               aoTransparencyEnabled,
                               lightPtr,
                               lightArray.size(),
                               oneSidedLighting);
    }
  void RaycastVolumeRenderer::commit() 
  {
    // Create the equivalent ISPC RaycastVolumeRenderer object.
    if (ispcEquivalent == NULL) ispcEquivalent = ispc::RaycastVolumeRenderer_createInstance();

    // Get the background color.
    vec3f bgColor = getParam3f("bgColor", vec3f(1.f));

    // Set the background color.
    ispc::RaycastVolumeRenderer_setBackgroundColor(ispcEquivalent, (const ispc::vec3f&) bgColor);

    // Set the lights if any.
    ispc::RaycastVolumeRenderer_setLights(ispcEquivalent, getLightsFromData(getParamData("lights", NULL)));

    // Initialize state in the parent class, must be called after the ISPC object is created.
    Renderer::commit();
  }
예제 #13
0
  void PathTracer::commit()
  {
    Renderer::commit();

    destroyGeometryLights();
    lightArray.clear();
    geometryLights = 0;

    const bool useGeometryLights = getParam1i("useGeometryLights", true);

    if (model && useGeometryLights) {
      areaPDF.resize(model->geometry.size());
      generateGeometryLights(model, affine3f(one), &areaPDF[0]);
      geometryLights = lightArray.size();
    }

    lightData = (Data*)getParamData("lights");
    if (lightData) {
      for (uint32_t i = 0; i < lightData->size(); i++)
        lightArray.push_back(((Light**)lightData->data)[i]->getIE());
    }

    void **lightPtr = lightArray.empty() ? nullptr : &lightArray[0];

    const int32 rouletteDepth = getParam1i("rouletteDepth", 5);
    const float maxRadiance = getParam1f("maxContribution",
                                         getParam1f("maxRadiance", inf));
    Texture2D *backplate = (Texture2D*)getParamObject("backplate", nullptr);
    vec4f shadowCatcherPlane = getParam4f("shadowCatcherPlane", vec4f(0.f));

    ispc::PathTracer_set(getIE()
        , rouletteDepth
        , maxRadiance
        , backplate ? backplate->getIE() : nullptr
        , (ispc::vec4f&)shadowCatcherPlane
        , lightPtr
        , lightArray.size()
        , geometryLights
        , &areaPDF[0]
        );
  }
예제 #14
0
    void DistributedModel::commit()
    {
      othersRegions.clear();

      // TODO: We may need to override the ISPC calls made
      // to the Model or customize the model struct on the ISPC
      // side. In which case we need some ISPC side inheritence
      // for the model type. Currently the code is actually identical.
      Model::commit();
      // Send my bounding boxes to other nodes, recieve theirs for a
      // "full picture" of what geometries live on what nodes
      Data *regionData = getParamData("regions");
      Data *ghostRegionData = getParamData("ghostRegions");

      // The box3f data is sent as data of FLOAT3 items
      // TODO: It's a little awkward to copy the boxes again like this, maybe
      // can re-thinkg the send side of the bcast call? One that takes
      // a ptr and a size since we know we won't be writing out to it?
      // TODO: For now it doesn't matter that we don't know who owns the
      // other boxes, just that we know they exist and their bounds, and that
      // they aren't ours.
      if (regionData) {
        box3f *boxes = reinterpret_cast<box3f*>(regionData->data);
        myRegions = std::vector<box3f>(boxes, boxes + regionData->numItems / 2);
      }

      // If the user hasn't set any regions, there's an implicit infinitely
      // large region box we can place around the entire world.
      if (myRegions.empty()) {
        postStatusMsg("No regions found, making implicit "
                      "infinitely large region", 1);
        myRegions.push_back(box3f(vec3f(neg_inf), vec3f(pos_inf)));
      }

      // Check if we've got ghost regions set, otherwise just use the regions
      if (ghostRegionData) {
        box3f *boxes = reinterpret_cast<box3f*>(ghostRegionData->data);
        ghostRegions = std::vector<box3f>(boxes, boxes + ghostRegionData->numItems / 2);
      } else {
        ghostRegions = myRegions;
      }

      for (int i = 0; i < mpicommon::numGlobalRanks(); ++i) {
        if (i == mpicommon::globalRank()) {
          messaging::bcast(i, myRegions);
        } else {
          std::vector<box3f> recv;
          messaging::bcast(i, recv);
          std::copy(recv.begin(), recv.end(),
                    std::back_inserter(othersRegions));
        }
      }

      if (logLevel() >= 1) {
        for (int i = 0; i < mpicommon::numGlobalRanks(); ++i) {
          if (i == mpicommon::globalRank()) {
            postStatusMsg(1) << "Rank " << mpicommon::globalRank()
              << ": Got regions from others {";
            for (const auto &b : othersRegions) {
              postStatusMsg(1) << "\t" << b << ",";
            }
            postStatusMsg(1) << "}";
          }
        }
      }
    }
예제 #15
0
파일: AMRVolume.cpp 프로젝트: ospray/OSPRay
    //! Allocate storage and populate the volume.
    void AMRVolume::commit()
    {
      updateEditableParameters();

      // Make the voxel value range visible to the application.
      if (findParam("voxelRange") == nullptr)
        setParam("voxelRange", voxelRange);
      else
        voxelRange = getParam2f("voxelRange", voxelRange);

      auto methodStringFromEnv =
          utility::getEnvVar<std::string>("OSPRAY_AMR_METHOD");

      std::string methodString =
          methodStringFromEnv.value_or(getParamString("amrMethod","current"));

      if (methodString == "finest" || methodString == "finestLevel")
        ispc::AMR_install_finest(getIE());
      else if (methodString == "current" || methodString == "currentLevel")
        ispc::AMR_install_current(getIE());
      else if (methodString == "octant")
        ispc::AMR_install_octant(getIE());

      if (data != nullptr) //TODO: support data updates
        return;

      brickInfoData = getParamData("brickInfo");
      assert(brickInfoData);
      assert(brickInfoData->data);

      brickDataData = getParamData("brickData");
      assert(brickDataData);
      assert(brickDataData->data);

      data  = make_unique<amr::AMRData>(*brickInfoData,*brickDataData);
      accel = make_unique<amr::AMRAccel>(*data);

      // finding coarset cell size + finest level cell width
      float coarsestCellWidth = 0.f;
      float finestLevelCellWidth = data->brick[0].cellWidth;
      box3i rootLevelBox = empty;

      for (auto &b : data->brick) {
        if (b.level == 0)
          rootLevelBox.extend(b.box);
        finestLevelCellWidth = min(finestLevelCellWidth, b.cellWidth);
        coarsestCellWidth    = max(coarsestCellWidth, b.cellWidth);
      }

      vec3i rootGridDims = rootLevelBox.size() + vec3i(1);
      ospLogF(1) << "found root level dimensions of " << rootGridDims;
      ospLogF(1) << "coarsest cell width is " << coarsestCellWidth << std::endl;

      auto rateFromEnv =
          utility::getEnvVar<float>("OSPRAY_AMR_SAMPLING_STEP");

      float samplingStep = rateFromEnv.value_or(0.1f * coarsestCellWidth);

      box3f worldBounds = accel->worldBounds;

      const vec3f gridSpacing = getParam3f("gridSpacing", vec3f(1.f));
      const vec3f gridOrigin  = getParam3f("gridOrigin", vec3f(0.f));

      voxelType =  getParamString("voxelType", "unspecified");
      auto voxelTypeID = getVoxelType();

      switch (voxelTypeID) {
      case OSP_UCHAR:
        break;
      case OSP_SHORT:
        break;
      case OSP_USHORT:
        break;
      case OSP_FLOAT:
        break;
      case OSP_DOUBLE:
        break;
      default:
        throw std::runtime_error("amrVolume unsupported voxel type '"
                                 + voxelType + "'");
      }

      ispc::AMRVolume_set(getIE(), (ispc::box3f&)worldBounds, samplingStep,
                          (const ispc::vec3f&)gridOrigin,
                          (const ispc::vec3f&)gridSpacing);

      ispc::AMRVolume_setAMR(getIE(),
                             accel->node.size(),
                             &accel->node[0],
                             accel->leaf.size(),
                             &accel->leaf[0],
                             accel->level.size(),
                             &accel->level[0],
                             voxelTypeID,
                             (ispc::box3f &)worldBounds);

      tasking::parallel_for(accel->leaf.size(),[&](size_t leafID) {
        ispc::AMRVolume_computeValueRangeOfLeaf(getIE(), leafID);
      });
    }