diff --git a/plugins/OSPRay_plugin/CMakeLists.txt b/plugins/OSPRay_plugin/CMakeLists.txt index 104ef11c41..b91c709fc8 100644 --- a/plugins/OSPRay_plugin/CMakeLists.txt +++ b/plugins/OSPRay_plugin/CMakeLists.txt @@ -14,6 +14,7 @@ if(BUILD_${EXPORT_NAME}_PLUGIN) set(DEP_LIST "${DEP_LIST};BUILD_OSPRAY_PLUGIN BUILD_CORE BUILD_GEOMETRY_CALLS_PLUGIN BUILD_MMSTD_DATATOOLS_PLUGIN BUILD_PROTEIN_CALLS_PLUGIN BUILD_MESH_PLUGIN" CACHE INTERNAL "") find_package(ospray CONFIG REQUIRED) + find_package(rkcommon CONFIG REQUIRED) file(GLOB_RECURSE public_header_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/*.h") file(GLOB_RECURSE source_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.cpp") @@ -23,10 +24,10 @@ if(BUILD_${EXPORT_NAME}_PLUGIN) # Target definition add_library(${PROJECT_NAME} STATIC ${public_header_files} ${header_files} ${shader_files} ${source_files}) target_compile_definitions(${PROJECT_NAME} PRIVATE ${EXPORT_NAME}_EXPORTS) - target_include_directories(${PROJECT_NAME} PUBLIC $ "include" "src" ${OSPRAY_INCLUDE_DIRS}) + target_include_directories(${PROJECT_NAME} PUBLIC $ "include" "src") target_link_libraries(${PROJECT_NAME} PRIVATE core geometry_calls mmstd_datatools protein_calls mesh - PUBLIC ${OSPRAY_LIBRARIES}) + PUBLIC ospray::ospray ospray::ospray_module_ispc rkcommon::rkcommon) # Installation rules for generated files #install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "include") diff --git a/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayMaterial.h b/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayMaterial.h index 9cfc66f3ee..b10df4ca32 100644 --- a/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayMaterial.h +++ b/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayMaterial.h @@ -10,6 +10,8 @@ #include "mmcore/factories/CallAutoDescription.h" #include "mmcore/Call.h" #include +#include + namespace megamol { namespace ospray { @@ -27,62 +29,84 @@ enum materialTypeEnum { VELVET }; + +// OBJMaterial/ScivisMaterial +struct objMaterial { +std::array Kd; +std::array Ks; +float Ns = 0.0f; +float d = 0.0f; +std::array Tf; +}; + +// LUMINOUS +struct luminousMaterial { +std::array lumColor; +float lumIntensity = 0.0f; +float lumTransparency = 0.0f; +}; + +// VELVET +struct velvetMaterial { +std::array velvetReflectance; +float velvetBackScattering = 0.0f; +std::array velvetHorizonScatteringColor; +float velvetHorizonScatteringFallOff = 0.0f; +}; + +// MATTE +struct matteMaterial { +std::array matteReflectance; +}; + +// METAL +struct metalMaterial { +std::array metalReflectance; +std::array metalEta; +std::array metalK; +float metalRoughness = 0.0f; +}; + +// METALLICPAINT +struct metallicpaintMaterial { +std::array metallicShadeColor; +std::array metallicGlitterColor; +float metallicGlitterSpread = 0.0f; +float metallicEta = 0.0f; +}; + +// GLASS +struct glassMaterial { +float glassEtaInside = 0.0f; +float glassEtaOutside = 0.0f; +std::array glassAttenuationColorInside; +std::array glassAttenuationColorOutside; +float glassAttenuationDistance = 0.0f; +}; + +// THINGLASS +struct thinglassMaterial { +std::array thinglassTransmission; +float thinglassEta = 0.0f; +float thinglassThickness = 0.0f; +}; + +// PLASTIC +struct plasticMaterial { +std::array plasticPigmentColor; +float plasticEta = 0.0f; +float plasticRoughness = 0.0f; +float plasticThickness = 0.0f; +}; + + struct OSPRayMaterialContainer { materialTypeEnum materialType = materialTypeEnum::OBJMATERIAL; - // OBJMaterial/ScivisMaterial - std::array Kd; - std::array Ks; - float Ns = 0.0f; - float d = 0.0f; - std::array Tf; - - // LUMINOUS - std::array lumColor; - float lumIntensity = 0.0f; - float lumTransparency = 0.0f; - - // VELVET - std::array velvetReflectance; - float velvetBackScattering = 0.0f; - std::array velvetHorizonScatteringColor; - float velvetHorizonScatteringFallOff = 0.0f; - - // MATTE - std::array matteReflectance; - - // METAL - std::array metalReflectance; - std::array metalEta; - std::array metalK; - float metalRoughness = 0.0f; - - // METALLICPAINT - std::array metallicShadeColor; - std::array metallicGlitterColor; - float metallicGlitterSpread = 0.0f; - float metallicEta = 0.0f; - - // GLASS - float glassEtaInside = 0.0f; - float glassEtaOutside = 0.0f; - std::array glassAttenuationColorInside; - std::array glassAttenuationColorOutside; - float glassAttenuationDistance = 0.0f; - - //THINGLASS - std::array thinglassTransmission; - float thinglassEta = 0.0f; - float thinglassThickness = 0.0f; - - // PLASTIC - std::array plasticPigmentColor; - float plasticEta = 0.0f; - float plasticRoughness = 0.0f; - float plasticThickness = 0.0f; - + std::variant material; bool isValid = false; - + }; @@ -160,4 +184,4 @@ typedef core::factories::CallAutoDescription CallOSPRayMater } // namespace ospray -} // namespace megamol \ No newline at end of file +} // namespace megamol diff --git a/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayStructure.h b/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayStructure.h index b53885e671..8997767c58 100644 --- a/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayStructure.h +++ b/plugins/OSPRay_plugin/include/OSPRay_plugin/CallOSPRayStructure.h @@ -24,10 +24,11 @@ enum structureTypeEnum { UNINITIALIZED, GEOMETRY, VOLUME, OSPRAY_API_STRUCTURES enum geometryTypeEnum { SPHERES, NHSPHERES, - TRIANGLES, - STREAMLINES, + MESH, + LINES, + CURVES, CYLINDERS, - QUADS + TEST }; enum volumeTypeEnum { STRUCTUREDVOLUME, BLOCKBRICKEDVOLUME, GHOSTBLOCKBRICKEDVOLUME }; @@ -48,93 +49,90 @@ static uint32_t voxelDataTypeOSP[] = {2500, 3000, 3500, 6000, 7000}; // DOUBLE = OSP_DOUBLE //}; - -class OSPRayStructureContainer { -public: - structureTypeEnum type; - std::shared_ptr materialContainer; - geometryTypeEnum geometryType; - volumeTypeEnum volumeType; - volumeRepresentationType volRepType; - - std::shared_ptr transformationContainer = nullptr; - bool transformationChanged = false; - +struct sphereStructure { std::shared_ptr> vertexData; std::shared_ptr> colorData; std::shared_ptr> indexData; - void* voxels; - std::shared_ptr> gridOrigin; - std::shared_ptr> gridSpacing; - std::shared_ptr> dimensions; - std::shared_ptr> clippingBoxLower; - std::shared_ptr> clippingBoxUpper; - std::shared_ptr> isoValue; - std::shared_ptr> sliceData; - std::shared_ptr> clipPlaneData; - std::shared_ptr> clipPlaneColor; + const void* raw; - std::shared_ptr raw2; + unsigned int vertexCount; + unsigned int vertexLength; + unsigned int dataStride; + unsigned int colorLength; + int colorType; + long long int partCount; + float globalRadius; + core::moldyn::SimpleSphericalParticles::ColourDataType mmpldColor = + core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_NONE; +}; + +struct structuredVolumeStructure { std::shared_ptr> tfRGB; std::shared_ptr> tfA; - std::shared_ptr> valueRange; - std::shared_ptr> xData; - std::shared_ptr> yData; - std::shared_ptr> zData; - std::shared_ptr boundingBox; //< TODO data duplicate to extent container ... however, - // this makes access more concise in the renderer - - std::pair,structureTypeEnum> ospStructures; + std::array valueRange; + + const void* voxels; + std::array gridOrigin; + std::array gridSpacing; + std::array dimensions; + std::array clippingBoxLower; + std::array clippingBoxUpper; + float isoValue; + bool clippingBoxActive; + volumeRepresentationType volRepType; + voxelDataType voxelDType; + unsigned int voxelCount; + unsigned int maxDim; +}; +struct meshStrucutre { std::shared_ptr mesh; std::shared_ptr mesh_textures; +}; - unsigned int voxelCount; - unsigned int maxDim; - unsigned int vertexCount; +struct apiStructure { + std::pair, structureTypeEnum> ospStructures; +}; + +struct curveStructure { + std::shared_ptr mesh; + + std::shared_ptr> vertexData; + std::shared_ptr> colorData; + std::shared_ptr> indexData; unsigned int vertexLength; - unsigned int vertexStride; + unsigned int dataStride; unsigned int colorLength; - unsigned int colorStride; - int colorType; - long long int partCount; float globalRadius; - core::moldyn::SimpleSphericalParticles::ColourDataType mmpldColor; +}; - bool clippingBoxActive; +struct OSPRayStructureContainer { + + structureTypeEnum type = structureTypeEnum::UNINITIALIZED; + std::shared_ptr materialContainer; + + geometryTypeEnum geometryType; + volumeTypeEnum volumeType; + + std::shared_ptr transformationContainer = nullptr; + bool transformationChanged = false; bool dataChanged; bool materialChanged; bool parameterChanged; - bool isValid; - bool smooth; //< valid for lines - - // stuff that should be in OSPRayVolumetricStructure: AbstractOSPRayStructure - // TODO: both actually. - bool useMIP; - bool useGradient; - bool usePreIntegration; - bool useAdaptiveSampling; - float adaptiveFactor; - float adaptiveMaxRate; - - voxelDataType voxelDType; - - float samplingRate; - float aoThreshold; - float aoRayOffsetFactor; + bool isValid = false; - OSPRayStructureContainer(); - ~OSPRayStructureContainer(); + std::variant structure; }; + class OSPRayExtendContainer { public: std::shared_ptr boundingBox; unsigned int timeFramesCount; - bool isValid; + bool isValid = false; - OSPRayExtendContainer(); - ~OSPRayExtendContainer(); + OSPRayExtendContainer() = default; + ~OSPRayExtendContainer() = default; }; diff --git a/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.cpp b/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.cpp index 1df1c57ccb..7b3a73f44f 100644 --- a/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.cpp +++ b/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.cpp @@ -22,15 +22,10 @@ #include "mmcore/view/light/PointLight.h" #include "mmcore/view/light/QuadLight.h" #include "mmcore/view/light/SpotLight.h" -#include "ospcommon/box.h" -#include "ospray/ospray.h" #include "vislib/graphics/gl/FramebufferObject.h" #include "vislib/sys/Path.h" - - #include - namespace megamol { namespace ospray { @@ -40,40 +35,28 @@ namespace ospray { AbstractOSPRayRenderer::AbstractOSPRayRenderer(void) : core::view::Renderer3DModule_2() - , lightSlot("lights", + , _lightSlot("lights", "Lights are retrieved over this slot. If no light is connected") - , accumulateSlot("accumulate", "Activates the accumulation buffer") - , + , _accumulateSlot("accumulate", "Activates the accumulation buffer") // general renderer parameters - rd_epsilon("Epsilon", "Ray epsilon to avoid self-intersections") - , rd_spp("SamplesPerPixel", "Samples per pixel") - , rd_maxRecursion("maxRecursion", "Maximum ray recursion depth") - , rd_type("Type", "Select between SciVis and PathTracer") - , shadows("SciVis::Shadows", "Enables/Disables computation of hard shadows (scivis)") - , + , _rd_spp("SamplesPerPixel", "Samples per pixel") + , _rd_maxRecursion("maxRecursion", "Maximum ray recursion depth") + , _rd_type("Type", "Select between SciVis and PathTracer") + , _shadows("SciVis::Shadows", "Enables/Disables computation of hard shadows (scivis)") // scivis renderer parameters - AOtransparencyEnabled("SciVis::AOtransparencyEnabled", "Enables or disables AO transparency") - , AOsamples("SciVis::AOsamples", "Number of rays per sample to compute ambient occlusion") - , AOdistance("SciVis::AOdistance", "Maximum distance to consider for ambient occlusion") - , + , _AOsamples("SciVis::AOsamples", "Number of rays per sample to compute ambient occlusion") + , _AOdistance("SciVis::AOdistance", "Maximum distance to consider for ambient occlusion") // pathtracer renderer parameters - rd_ptBackground("PathTracer::BackgroundTexture", + , _rd_ptBackground("PathTracer::BackgroundTexture", "Texture image used as background, replacing visible lights in infinity") - , // Use depth buffer component - useDB("useDBcomponent", "activates depth composition with OpenGL content") - , deviceTypeSlot("device", "Set the type of the OSPRay device") - , numThreads("numThreads", "Number of threads used for rendering") { + , _useDB("useDBcomponent", "activates depth composition with OpenGL content") + , _deviceTypeSlot("device", "Set the type of the OSPRay device") + , _numThreads("numThreads", "Number of threads used for rendering") { - // ospray lights - lightsToRender = NULL; - // ospray device and framebuffer - device = NULL; - framebufferIsDirty = true; - maxDepthTexture = NULL; - this->lightSlot.SetCompatibleCall(); - this->MakeSlotAvailable(&this->lightSlot); + this->_lightSlot.SetCompatibleCall(); + this->MakeSlotAvailable(&this->_lightSlot); core::param::EnumParam* rdt = new core::param::EnumParam(SCIVIS); rdt->SetTypePair(SCIVIS, "SciVis"); @@ -81,48 +64,44 @@ namespace ospray { rdt->SetTypePair(MPI_RAYCAST, "MPI_Raycast"); // Ambient parameters - this->AOtransparencyEnabled << new core::param::BoolParam(false); - this->AOsamples << new core::param::IntParam(1); - this->AOdistance << new core::param::FloatParam(1e20f); - this->accumulateSlot << new core::param::BoolParam(true); - this->MakeSlotAvailable(&this->AOtransparencyEnabled); - this->MakeSlotAvailable(&this->AOsamples); - this->MakeSlotAvailable(&this->AOdistance); - this->MakeSlotAvailable(&this->accumulateSlot); + this->_AOsamples << new core::param::IntParam(1); + this->_AOdistance << new core::param::FloatParam(1e20f); + this->_accumulateSlot << new core::param::BoolParam(true); + this->MakeSlotAvailable(&this->_AOsamples); + this->MakeSlotAvailable(&this->_AOdistance); + this->MakeSlotAvailable(&this->_accumulateSlot); // General Renderer - this->rd_epsilon << new core::param::FloatParam(1e-4f); - this->rd_spp << new core::param::IntParam(1); - this->rd_maxRecursion << new core::param::IntParam(10); - this->rd_type << rdt; - this->MakeSlotAvailable(&this->rd_epsilon); - this->MakeSlotAvailable(&this->rd_spp); - this->MakeSlotAvailable(&this->rd_maxRecursion); - this->MakeSlotAvailable(&this->rd_type); - this->shadows << new core::param::BoolParam(0); - this->MakeSlotAvailable(&this->shadows); - - this->rd_type.ForceSetDirty(); //< TODO HAZARD Dirty hack + this->_rd_spp << new core::param::IntParam(1); + this->_rd_maxRecursion << new core::param::IntParam(10); + this->_rd_type << rdt; + this->MakeSlotAvailable(&this->_rd_spp); + this->MakeSlotAvailable(&this->_rd_maxRecursion); + this->MakeSlotAvailable(&this->_rd_type); + this->_shadows << new core::param::BoolParam(0); + this->MakeSlotAvailable(&this->_shadows); + + this->_rd_type.ForceSetDirty(); //< TODO HAZARD Dirty hack // PathTracer - this->rd_ptBackground << new core::param::FilePathParam(""); - this->MakeSlotAvailable(&this->rd_ptBackground); + this->_rd_ptBackground << new core::param::FilePathParam(""); + this->MakeSlotAvailable(&this->_rd_ptBackground); // Number of threads - this->numThreads << new core::param::IntParam(0); - this->MakeSlotAvailable(&this->numThreads); + this->_numThreads << new core::param::IntParam(0); + this->MakeSlotAvailable(&this->_numThreads); // Depth - this->useDB << new core::param::BoolParam(false); - this->MakeSlotAvailable(&this->useDB); + this->_useDB << new core::param::BoolParam(false); + this->MakeSlotAvailable(&this->_useDB); // Device auto deviceEp = new megamol::core::param::EnumParam(deviceType::DEFAULT); - deviceEp->SetTypePair(deviceType::DEFAULT, "default"); + deviceEp->SetTypePair(deviceType::DEFAULT, "cpu"); deviceEp->SetTypePair(deviceType::MPI_DISTRIBUTED, "mpi_distributed"); - this->deviceTypeSlot << deviceEp; - this->MakeSlotAvailable(&this->deviceTypeSlot); + this->_deviceTypeSlot << deviceEp; + this->MakeSlotAvailable(&this->_deviceTypeSlot); } void AbstractOSPRayRenderer::renderTexture2D(vislib::graphics::gl::GLSLShader& shader, const uint32_t* fb, @@ -191,11 +170,11 @@ namespace ospray { this->new_fbo.Disable(); */ glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, this->tex); + glBindTexture(GL_TEXTURE_2D, this->_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, fb); glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, this->depth); + glBindTexture(GL_TEXTURE_2D, this->_depth); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, db); glBindTexture(GL_TEXTURE_2D, 0); @@ -204,12 +183,12 @@ namespace ospray { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, this->tex); + glBindTexture(GL_TEXTURE_2D, this->_tex); glUniform1i(shader.ParameterLocation("tex"), 0); glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, this->depth); + glBindTexture(GL_TEXTURE_2D, this->_depth); glUniform1i(shader.ParameterLocation("depth"), 1); @@ -226,17 +205,17 @@ namespace ospray { void AbstractOSPRayRenderer::setupTextureScreen() { // setup color texture glEnable(GL_TEXTURE_2D); - glGenTextures(1, &this->tex); - glBindTexture(GL_TEXTURE_2D, this->tex); + glGenTextures(1, &this->_tex); + glBindTexture(GL_TEXTURE_2D, this->_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, 0); - + //// setup depth texture - glGenTextures(1, &this->depth); - glBindTexture(GL_TEXTURE_2D, this->depth); + glGenTextures(1, &this->_depth); + glBindTexture(GL_TEXTURE_2D, this->_depth); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -246,54 +225,48 @@ namespace ospray { } void AbstractOSPRayRenderer::releaseTextureScreen() { - glDeleteTextures(1, &this->tex); - glDeleteTextures(1, &this->depth); + glDeleteTextures(1, &this->_tex); + glDeleteTextures(1, &this->_depth); } - void AbstractOSPRayRenderer::initOSPRay(OSPDevice& dvce) { - if (dvce == nullptr) { + void AbstractOSPRayRenderer::initOSPRay() { + if (!_device) { ospLoadModule("ispc"); - switch (this->deviceTypeSlot.Param()->Value()) { + switch (this->_deviceTypeSlot.Param()->Value()) { case deviceType::MPI_DISTRIBUTED: { ospLoadModule("mpi"); - dvce = ospNewDevice("mpi_distributed"); - ospDeviceSet1i(dvce, "masterRank", 0); - if (this->numThreads.Param()->Value() > 0) { - ospDeviceSet1i( - dvce, "numThreads", this->numThreads.Param()->Value()); + _device = std::make_shared<::ospray::cpp::Device>("mpi_distributed"); + _device->setParam("masterRank", 0); + if (this->_numThreads.Param()->Value() > 0) { + _device->setParam("numThreads", this->_numThreads.Param()->Value()); } } break; default: { - dvce = ospNewDevice("default"); - if (this->numThreads.Param()->Value() > 0) { - ospDeviceSet1i( - dvce, "numThreads", this->numThreads.Param()->Value()); + _device = std::make_shared<::ospray::cpp::Device>("cpu"); + if (this->_numThreads.Param()->Value() > 0) { + _device->setParam("numThreads", this->_numThreads.Param()->Value()); } else { - ospDeviceSet1i(dvce, "numThreads", vislib::sys::SystemInformation::ProcessorCount() - 1); + //_device->setParam("numThreads", vislib::sys::SystemInformation::ProcessorCount() - 1); } } } - ospDeviceSetErrorFunc(dvce, ospErrorCallback); - ospDeviceCommit(dvce); - ospSetCurrentDevice(dvce); + _device->commit(); + _device->setCurrent(); } // this->deviceTypeSlot.MakeUnavailable(); //< TODO: Make sure you can set a device only once } - void AbstractOSPRayRenderer::setupOSPRay( - OSPRenderer& renderer, OSPCamera& camera, OSPModel& world, const char* renderer_name) { + void AbstractOSPRayRenderer::setupOSPRay(const char* renderer_name) { // create and setup renderer - renderer = ospNewRenderer(renderer_name); - camera = ospNewCamera("perspective"); - world = ospNewModel(); - ospSetObject(renderer, "model", world); - ospSetObject(renderer, "camera", camera); + _renderer = std::make_shared<::ospray::cpp::Renderer>(renderer_name); + _camera = std::make_shared<::ospray::cpp::Camera>("perspective"); + _world = std::make_shared<::ospray::cpp::World>(); } - OSPTexture2D AbstractOSPRayRenderer::TextureFromFile(vislib::TString fileName) { + ::ospray::cpp::Texture AbstractOSPRayRenderer::TextureFromFile(vislib::TString fileName) { fileName = vislib::sys::Path::Resolve(fileName); @@ -358,95 +331,23 @@ namespace ospray { for (int x = 0; x < width * 3; x++) std::swap(texels[y * width * 3 + x], texels[(height - 1 - y) * width * 3 + x]); - OSPTexture2D ret_tex = ospNewTexture2D({width, height}, OSP_TEXTURE_RGB8, texels); - return ret_tex; - } catch (std::runtime_error e) { std::cerr << e.what() << std::endl; } - - } else if (ext == vislib::TString("pfm")) { - try { - // Note: the PFM file specification does not support comments thus we don't skip any - // http://netpbm.sourceforge.net/doc/pfm.html - int rc = 0; - - - // read format specifier: - // PF: color floating point image - // Pf: grayscae floating point image - char format[2] = {0}; - if (fscanf(file, "%c%c\n", &format[0], &format[1]) != 2) - throw std::runtime_error("could not fscanf"); - - if (format[0] != 'P' || (format[1] != 'F' && format[1] != 'f')) { - throw std::runtime_error("Invalid pfm texture file, header is not PF or Pf"); - } - int numChannels = 3; - if (format[1] == 'f') { - numChannels = 1; - } - - // read width and height - int width = -1; - int height = -1; - rc = fscanf(file, "%i %i\n", &width, &height); - if (rc != 2) { - throw std::runtime_error("Could not parse width and height in PF PFM file"); - } - - // read scale factor/endiannes - float scaleEndian = 0.0; - rc = fscanf(file, "%f\n", &scaleEndian); - - if (rc != 1) { - throw std::runtime_error("Could not parse scale factor/endianness in PF PFM file"); - } - if (scaleEndian == 0.0) { - throw std::runtime_error("Scale factor/endianness in PF PFM file can not be 0"); - } - if (scaleEndian > 0.0) { - throw std::runtime_error("Could not parse PF PFM file"); - } - float scaleFactor = std::abs(scaleEndian); - - int depth = sizeof(float); - float* data; - data = new float[width * height * numChannels]; - if (fread(data, sizeof(float), width * height * numChannels, file) != width * height * numChannels) { - throw std::runtime_error("could not fread"); - } - // flip in y, because OSPRay's textures have the origin at the lower left corner - float* texels = (float*) data; - for (int y = 0; y < height / 2; ++y) { - for (int x = 0; x < width * numChannels; ++x) { - // Scale the pixels by the scale factor - texels[y * width * numChannels + x] = texels[y * width * numChannels + x] * scaleFactor; - texels[(height - 1 - y) * width * numChannels + x] = - texels[(height - 1 - y) * width * numChannels + x] * scaleFactor; - std::swap( - texels[y * width * numChannels + x], texels[(height - 1 - y) * width * numChannels + x]); - } - } - OSPTextureFormat type = OSP_TEXTURE_R8; - - if (numChannels == 1) - type = OSP_TEXTURE_R32F; - if (numChannels == 3) - type = OSP_TEXTURE_RGB32F; - if (numChannels == 4) - type = OSP_TEXTURE_RGBA32F; + ::ospray::cpp::Texture ret_tex("texture2d"); + ret_tex.setParam("format", OSP_TEXTURE_RGB8); + ::ospray::cpp::Data texel_data(texels, OSP_UCHAR,width*height); - OSPTexture2D ret_tex = ospNewTexture2D({width, height}, type, texels); return ret_tex; + } catch (std::runtime_error e) { std::cerr << e.what() << std::endl; } } else { - std::cerr << "File type not supported. Only PPM and PFM file formats allowed." << std::endl; + std::cerr << "File type not supported. Only PPM file format allowed." << std::endl; } } bool AbstractOSPRayRenderer::AbstractIsDirty() { - if (this->AOsamples.IsDirty() || this->AOtransparencyEnabled.IsDirty() || this->AOdistance.IsDirty() || - this->accumulateSlot.IsDirty() || this->shadows.IsDirty() || this->rd_type.IsDirty() || - this->rd_epsilon.IsDirty() || this->rd_spp.IsDirty() || this->rd_maxRecursion.IsDirty() || - this->rd_ptBackground.IsDirty() || this->useDB.IsDirty() || this->framebufferIsDirty) { + if (this->_AOsamples.IsDirty() || this->_AOdistance.IsDirty() || + this->_accumulateSlot.IsDirty() || this->_shadows.IsDirty() || this->_rd_type.IsDirty() || + this->_rd_spp.IsDirty() || this->_rd_maxRecursion.IsDirty() || + this->_rd_ptBackground.IsDirty() || this->_useDB.IsDirty()) { return true; } else { return false; @@ -454,30 +355,32 @@ namespace ospray { } void AbstractOSPRayRenderer::AbstractResetDirty() { - this->AOsamples.ResetDirty(); - this->AOtransparencyEnabled.ResetDirty(); - this->AOdistance.ResetDirty(); - this->accumulateSlot.ResetDirty(); - this->shadows.ResetDirty(); - this->rd_type.ResetDirty(); - this->rd_epsilon.ResetDirty(); - this->rd_spp.ResetDirty(); - this->rd_maxRecursion.ResetDirty(); - this->rd_ptBackground.ResetDirty(); - this->useDB.ResetDirty(); - this->framebufferIsDirty = false; + this->_AOsamples.ResetDirty(); + this->_AOdistance.ResetDirty(); + this->_accumulateSlot.ResetDirty(); + this->_shadows.ResetDirty(); + this->_rd_type.ResetDirty(); + this->_rd_spp.ResetDirty(); + this->_rd_maxRecursion.ResetDirty(); + this->_rd_ptBackground.ResetDirty(); + this->_useDB.ResetDirty(); } - void AbstractOSPRayRenderer::fillLightArray(glm::vec4& eyeDir) { + void AbstractOSPRayRenderer::fillLightArray(std::array eyeDir) { // clear current lights - this->lightArray.clear(); + if (!_lightArray.empty()) { + for (auto& l : _lightArray) { + ospRelease(l.handle()); + } + } + _lightArray.clear(); // create custom ospray light - OSPLight light; + ::ospray::cpp::Light light; auto lights = core::view::light::LightCollection(); - auto call_light = lightSlot.CallAs(); + auto call_light = _lightSlot.CallAs(); if (call_light != nullptr) { lights = call_light->getData(); } @@ -490,119 +393,111 @@ namespace ospray { auto ambient_lights = lights.get(); for (auto dl : distant_lights) { - light = ospNewLight(this->renderer, "distant"); - if (dl.eye_direction == true) { - ospSet3f(light, "direction", eyeDir.x, eyeDir.y, eyeDir.z); - } else { - ospSet3fv(light, "direction", dl.direction.data()); - } - ospSet1f(light, "angularDiameter", dl.angularDiameter); - ospSet1f(light, "intensity", dl.intensity); - ospSet3fv(light, "color", dl.colour.data()); - ospCommit(light); - this->lightArray.push_back(light); + light = ::ospray::cpp::Light("distant"); + if (dl.eye_direction == true) { + light.setParam("direction", convertToVec4f(eyeDir)); + } else { + light.setParam("direction", convertToVec3f(dl.direction)); + } + light.setParam("angularDiameter", dl.angularDiameter); + light.setParam("intensity", dl.intensity); + light.setParam("color", convertToVec4f(dl.colour)); + light.commit(); + _lightArray.emplace_back(light); } for (auto pl : point_lights) { - light = ospNewLight(this->renderer, "point"); - ospSet3fv(light, "position", pl.position.data()); - ospSet1f(light, "radius", pl.radius); - ospSet1f(light, "intensity", pl.intensity); - ospSet3fv(light, "color", pl.colour.data()); - ospCommit(light); - this->lightArray.push_back(light); + light = ::ospray::cpp::Light("point"); + light.setParam("position", convertToVec3f(pl.position)); + light.setParam("radius", pl.radius); + light.setParam("intensity", pl.intensity); + light.setParam("color", convertToVec4f(pl.colour)); + light.commit(); + _lightArray.emplace_back(light); } for (auto sl : spot_lights) { - light = ospNewLight(this->renderer, "spot"); - ospSet3fv(light, "position", sl.position.data()); - ospSet3fv(light, "direction", sl.direction.data()); - ospSet1f(light, "openingAngle", sl.openingAngle); - ospSet1f(light, "penumbraAngle", sl.penumbraAngle); - ospSet1f(light, "radius", sl.radius); - ospSet1f(light, "intensity", sl.intensity); - ospSet3fv(light, "color", sl.colour.data()); - ospCommit(light); - this->lightArray.push_back(light); + light = ::ospray::cpp::Light("spot"); + light.setParam("position", convertToVec3f(sl.position)); + light.setParam("direction", convertToVec3f(sl.direction)); + light.setParam("openingAngle", sl.openingAngle); + light.setParam("penumbraAngle", sl.penumbraAngle); + light.setParam("radius", sl.radius); + light.setParam("intensity", sl.intensity); + light.setParam("color", convertToVec4f(sl.colour)); + light.commit(); + _lightArray.emplace_back(light); } for (auto ql : quad_lights) { - light = ospNewLight(this->renderer, "quad"); - ospSet3fv(light, "position", ql.position.data()); - ospSet3fv(light, "edge1", ql.edgeOne.data()); - ospSet3fv(light, "edge2", ql.edgeTwo.data()); - ospSet1f(light, "intensity", ql.intensity); - ospSet3fv(light, "color", ql.colour.data()); - ospCommit(light); - this->lightArray.push_back(light); + light = ::ospray::cpp::Light("quad"); + light.setParam("position", convertToVec3f(ql.position)); + light.setParam("edge1", convertToVec3f(ql.edgeOne)); + light.setParam("edge2", convertToVec3f(ql.edgeTwo)); + light.setParam("intensity", ql.intensity); + light.setParam("color", convertToVec4f(ql.colour)); + light.commit(); + _lightArray.emplace_back(light); } for (auto hl : hdri_lights) { - light = ospNewLight(this->renderer, "hdri"); - ospSet3fv(light, "up", hl.up.data()); - ospSet3fv(light, "dir", hl.direction.data()); + light = ::ospray::cpp::Light("hdri"); + light.setParam("up", convertToVec3f(hl.up)); + light.setParam("dir", convertToVec3f(hl.direction)); if (hl.evnfile != vislib::TString("")) { - OSPTexture2D hdri_tex = this->TextureFromFile(hl.evnfile); - ospSetObject(this->renderer, "backplate", hdri_tex); + ::ospray::cpp::Texture hdri_tex = this->TextureFromFile(hl.evnfile); + _renderer->setParam("map_backplate", hdri_tex); } - ospSet1f(light, "intensity", hl.intensity); - ospSet3fv(light, "color", hl.colour.data()); - ospCommit(light); - this->lightArray.push_back(light); + light.setParam("intensity", hl.intensity); + light.setParam("color", convertToVec4f(hl.colour)); + light.commit(); + _lightArray.emplace_back(light); } for (auto al : ambient_lights) { - light = ospNewLight(this->renderer, "ambient"); - ospSet1f(light, "intensity", al.intensity); - ospSet3fv(light, "color", al.colour.data()); - ospCommit(light); - this->lightArray.push_back(light); + light =::ospray::cpp::Light("ambient"); + light.setParam("intensity", al.intensity); + light.setParam("color", convertToVec4f(al.colour)); + light.commit(); + _lightArray.emplace_back(light); } } - void AbstractOSPRayRenderer::RendererSettings(OSPRenderer& renderer) { + void AbstractOSPRayRenderer::RendererSettings(glm::vec4 bg_color) { // general renderer settings - ospSet1f(renderer, "epsilon", this->rd_epsilon.Param()->Value()); - ospSet1i(renderer, "spp", this->rd_spp.Param()->Value()); - ospSet1i(renderer, "maxDepth", this->rd_maxRecursion.Param()->Value()); - ospSetObject(renderer, "maxDepthTexture", this->maxDepthTexture); + _renderer->setParam("pixelSamples", this->_rd_spp.Param()->Value()); + _renderer->setParam("maxPathLength", this->_rd_maxRecursion.Param()->Value()); + + if (this->_rd_ptBackground.Param()->Value() != vislib::TString("")) { + ::ospray::cpp::Texture bkgnd_tex = + this->TextureFromFile(this->_rd_ptBackground.Param()->Value()); + _renderer->setParam("map_backplate", bkgnd_tex); + } else { + _renderer->setParam("backgroundColor", convertToVec4f(bg_color)); + } - switch (this->rd_type.Param()->Value()) { + switch (this->_rd_type.Param()->Value()) { case SCIVIS: // scivis renderer settings - ospSet1i(renderer, "aoTransparencyEnabled", - this->AOtransparencyEnabled.Param()->Value()); - ospSet1i(renderer, "aoSamples", this->AOsamples.Param()->Value()); - ospSet1i(renderer, "shadowsEnabled", this->shadows.Param()->Value()); - ospSet1f(renderer, "aoDistance", this->AOdistance.Param()->Value()); - // ospSet1i(renderer, "backgroundEnabled", 0); - - GLfloat bgcolor[4]; - glGetFloatv(GL_COLOR_CLEAR_VALUE, bgcolor); - ospSet3fv(renderer, "bgColor", bgcolor); - ospSet1i(renderer, "oneSidedLighting", true); - + _renderer->setParam("aoSamples", this->_AOsamples.Param()->Value()); + _renderer->setParam("shadows", this->_shadows.Param()->Value()); + _renderer->setParam("aoDistance", this->_AOdistance.Param()->Value()); break; case PATHTRACER: - if (this->rd_ptBackground.Param()->Value() != vislib::TString("")) { - OSPTexture2D bkgnd_tex = - this->TextureFromFile(this->rd_ptBackground.Param()->Value()); - ospSetObject(renderer, "backplate", bkgnd_tex); - } else { - ospSet1i(renderer, "backgroundEnabled", 0); - } + _renderer->setParam("backgroundRefraction", true); + // TODO: _renderer->setParam("roulettePathLength", ); break; } } - void AbstractOSPRayRenderer::setupOSPRayCamera(OSPCamera& ospcam, megamol::core::view::Camera_2& mmcam) { + void AbstractOSPRayRenderer::setupOSPRayCamera(megamol::core::view::Camera_2& mmcam) { // calculate image parts for e.g. screenshooter - std::vector imgStart(2, 0); - std::vector imgEnd(2, 0); + std::array imgStart = {0, 0}; + std::array imgEnd = {0, 0}; imgStart[0] = mmcam.image_tile().left() / static_cast(mmcam.resolution_gate().width()); imgStart[1] = mmcam.image_tile().bottom() / static_cast(mmcam.resolution_gate().height()); @@ -612,153 +507,169 @@ namespace ospray { static_cast(mmcam.resolution_gate().height()); // setup ospcam - ospSet2fv(ospcam, "imageStart", imgStart.data()); - ospSet2fv(ospcam, "imageEnd", imgEnd.data()); - ospSetf(ospcam, "aspect", mmcam.resolution_gate_aspect()); - - - ospSet3f(ospcam, "pos", mmcam.eye_position().x(), mmcam.eye_position().y(), mmcam.eye_position().z()); - ospSet3f(ospcam, "dir", mmcam.view_vector().x(), mmcam.view_vector().y(), mmcam.view_vector().z()); - ospSet3f(ospcam, "up", mmcam.up_vector().x(), mmcam.up_vector().y(), mmcam.up_vector().z()); - ospSet1f(ospcam, "fovy", mmcam.aperture_angle()); - - // ospSet1i(ospcam, "architectural", 1); - ospSet1f(ospcam, "nearClip", mmcam.near_clipping_plane()); - ospSet1f(ospcam, "farClip", mmcam.far_clipping_plane()); - // ospSet1f(ospcam, "apertureRadius", ); - // ospSet1f(ospcam, "focalDistance", cr->GetCameraParameters()->FocalDistance()); - } - - OSPFrameBuffer AbstractOSPRayRenderer::newFrameBuffer( - osp::vec2i& imgSize, const OSPFrameBufferFormat format, const uint32_t frameBufferChannels) { - OSPFrameBuffer frmbuff = ospNewFrameBuffer(imgSize, format, frameBufferChannels); - this->framebufferIsDirty = true; - return frmbuff; + _camera->setParam("imageStart", convertToVec2f(imgStart)); + _camera->setParam("imageEnd", convertToVec2f(imgEnd)); + _camera->setParam("aspect", static_cast(mmcam.resolution_gate_aspect())); + _camera->setParam("nearClip", static_cast(mmcam.near_clipping_plane())); + + glm::vec4 eye_pos = mmcam.eye_position(); + glm::vec4 view_vec = mmcam.view_vector(); + glm::vec4 up_vec = mmcam.up_vector(); + _camera->setParam("position", convertToVec3f(eye_pos)); + _camera->setParam("direction", convertToVec3f(view_vec)); + _camera->setParam("up", convertToVec3f(up_vec)); + _camera->setParam("fovy", static_cast(mmcam.aperture_angle())); + + // ospSet1i(_camera, "architectural", 1); + // TODO: ospSet1f(_camera, "apertureRadius", ); + // TODO: ospSet1f(_camera, "focalDistance", cr->GetCameraParameters()->FocalDistance()); } AbstractOSPRayRenderer::~AbstractOSPRayRenderer(void) { - if (lightsToRender != NULL) - ospRelease(lightsToRender); this->Release(); } // helper function to write the rendered image as PPM file - void AbstractOSPRayRenderer::writePPM(const char* fileName, const osp::vec2i& size, const uint32_t* pixel) { + void AbstractOSPRayRenderer::writePPM(std::string fileName, const std::array& size, const uint32_t* pixel) { // std::ofstream file; // file << "P6\n" << size.x << " " << size.y << "\n255\n"; - FILE* file = fopen(fileName, "wb"); - fprintf(file, "P6\n%i %i\n255\n", size.x, size.y); - unsigned char* out = (unsigned char*) alloca(3 * size.x); - for (int y = 0; y < size.y; y++) { - const unsigned char* in = (const unsigned char*) &pixel[(size.y - 1 - y) * size.x]; - for (int x = 0; x < size.x; x++) { + FILE* file = fopen(fileName.c_str(), "wb"); + fprintf(file, "P6\n%i %i\n255\n", size[0], size[1]); + unsigned char* out = (unsigned char*) alloca(3 * size[0]); + for (int y = 0; y < size[1]; y++) { + const unsigned char* in = (const unsigned char*) &pixel[(size[1] - 1 - y) * size[1]]; + for (int x = 0; x < size[0]; x++) { out[3 * x + 0] = in[4 * x + 0]; out[3 * x + 1] = in[4 * x + 1]; out[3 * x + 2] = in[4 * x + 2]; } - fwrite(out, 3 * size.x, sizeof(char), file); + fwrite(out, 3 * size[0], sizeof(char), file); } fprintf(file, "\n"); fclose(file); } + void AbstractOSPRayRenderer::fillMaterialContainer(CallOSPRayStructure* entry_first, const OSPRayStructureContainer& element) { + switch (element.materialContainer->materialType) { + case OBJMATERIAL: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(this->_rd_type_string.c_str(), "obj"); + _materials[entry_first].setParam("Kd", convertToVec3f(container.Kd)); + _materials[entry_first].setParam("Ks", convertToVec3f(container.Ks)); + _materials[entry_first].setParam("Ns", container.Ns); + _materials[entry_first].setParam("d", container.d); + _materials[entry_first].setParam("Tf", convertToVec3f(container.Tf)); + } + break; + case LUMINOUS: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "luminous"); + _materials[entry_first].setParam("color", convertToVec3f(container.lumColor)); + _materials[entry_first].setParam("intensity", container.lumIntensity); + _materials[entry_first].setParam("transparency", container.lumTransparency); + } + break; + case GLASS: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "glass"); + _materials[entry_first].setParam("etaInside", container.glassEtaInside); + _materials[entry_first].setParam("etaOutside", container.glassEtaOutside); + _materials[entry_first].setParam( + "attenuationColorInside", convertToVec3f(container.glassAttenuationColorInside)); + _materials[entry_first].setParam( + "attenuationColorOutside", convertToVec3f(container.glassAttenuationColorOutside)); + _materials[entry_first].setParam("attenuationDistance", container.glassAttenuationDistance); + } + break; + case MATTE: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "Matte"); + _materials[entry_first].setParam("reflectance", convertToVec3f(container.matteReflectance)); + } + break; + case METAL: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "metal"); + _materials[entry_first].setParam("reflectance", convertToVec3f(container.metalReflectance)); + _materials[entry_first].setParam("eta", convertToVec3f(container.metalEta)); + _materials[entry_first].setParam("k", convertToVec3f(container.metalK)); + _materials[entry_first].setParam("roughness", container.metalRoughness); + } + break; + case METALLICPAINT: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "metallicPaint"); + _materials[entry_first].setParam( + "shadeColor", convertToVec3f(container.metallicShadeColor)); + _materials[entry_first].setParam( + "glitterColor", convertToVec3f(container.metallicGlitterColor)); + _materials[entry_first].setParam("glitterSpread", container.metallicGlitterSpread); + _materials[entry_first].setParam("eta", container.metallicEta); + } + break; + case PLASTIC: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "Plastic"); + _materials[entry_first].setParam( + "pigmentColor", convertToVec3f(container.plasticPigmentColor)); + _materials[entry_first].setParam("eta", container.plasticEta); + _materials[entry_first].setParam("roughness", container.plasticRoughness); + _materials[entry_first].setParam("thickness", container.plasticThickness); + } + break; + case THINGLASS: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "thinGlass"); + _materials[entry_first].setParam( + "transmission", convertToVec3f(container.thinglassTransmission)); + _materials[entry_first].setParam("eta", container.thinglassEta); + _materials[entry_first].setParam("thickness", container.thinglassThickness); + } + break; + case VELVET: + { + auto& container = std::get(element.materialContainer->material); + _materials[entry_first] = ::ospray::cpp::Material(_rd_type_string.c_str(), "Velvet"); + _materials[entry_first].setParam( + "reflectance", convertToVec3f(container.velvetReflectance)); + _materials[entry_first].setParam( + "horizonScatteringColor", convertToVec3f(container.velvetHorizonScatteringColor)); + _materials[entry_first].setParam("backScattering", container.velvetBackScattering); + _materials[entry_first].setParam( + "horizonScatteringFallOff", container.velvetHorizonScatteringFallOff); + } + break; + } + } void AbstractOSPRayRenderer::changeMaterial() { - for (auto entry : this->structureMap) { + for (auto entry : this->_structureMap) { auto const& element = entry.second; // custom material settings - if (this->materials[entry.first] != nullptr) { - ospRelease(this->materials[entry.first]); - this->materials.erase(entry.first); + if (this->_materials[entry.first] != NULL) { + //ospRelease(this->_materials[entry.first]); + this->_materials.erase(entry.first); } if (element.materialContainer != NULL) { - switch (element.materialContainer->materialType) { - case OBJMATERIAL: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "OBJMaterial"); - ospSet3fv(this->materials[entry.first], "Kd", element.materialContainer->Kd.data()); - ospSet3fv(this->materials[entry.first], "Ks", element.materialContainer->Ks.data()); - ospSet1f(this->materials[entry.first], "Ns", element.materialContainer->Ns); - ospSet1f(this->materials[entry.first], "d", element.materialContainer->d); - ospSet3fv(this->materials[entry.first], "Tf", element.materialContainer->Tf.data()); - break; - case LUMINOUS: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Luminous"); - ospSet3fv(this->materials[entry.first], "color", element.materialContainer->lumColor.data()); - ospSet1f(this->materials[entry.first], "intensity", element.materialContainer->lumIntensity); - ospSet1f(this->materials[entry.first], "transparency", element.materialContainer->lumTransparency); - break; - case GLASS: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Glass"); - ospSet1f(this->materials[entry.first], "etaInside", element.materialContainer->glassEtaInside); - ospSet1f(this->materials[entry.first], "etaOutside", element.materialContainer->glassEtaOutside); - ospSet3fv(this->materials[entry.first], "attenuationColorInside", - element.materialContainer->glassAttenuationColorInside.data()); - ospSet3fv(this->materials[entry.first], "attenuationColorOutside", - element.materialContainer->glassAttenuationColorOutside.data()); - ospSet1f(this->materials[entry.first], "attenuationDistance", - element.materialContainer->glassAttenuationDistance); - break; - case MATTE: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Matte"); - ospSet3fv(this->materials[entry.first], "reflectance", - element.materialContainer->matteReflectance.data()); - break; - case METAL: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Metal"); - ospSet3fv(this->materials[entry.first], "reflectance", - element.materialContainer->metalReflectance.data()); - ospSet3fv(this->materials[entry.first], "eta", element.materialContainer->metalEta.data()); - ospSet3fv(this->materials[entry.first], "k", element.materialContainer->metalK.data()); - ospSet1f(this->materials[entry.first], "roughness", element.materialContainer->metalRoughness); - break; - case METALLICPAINT: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "MetallicPaint"); - ospSet3fv(this->materials[entry.first], "shadeColor", - element.materialContainer->metallicShadeColor.data()); - ospSet3fv(this->materials[entry.first], "glitterColor", - element.materialContainer->metallicGlitterColor.data()); - ospSet1f(this->materials[entry.first], "glitterSpread", - element.materialContainer->metallicGlitterSpread); - ospSet1f(this->materials[entry.first], "eta", element.materialContainer->metallicEta); - break; - case PLASTIC: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Plastic"); - ospSet3fv(this->materials[entry.first], "pigmentColor", - element.materialContainer->plasticPigmentColor.data()); - ospSet1f(this->materials[entry.first], "eta", element.materialContainer->plasticEta); - ospSet1f(this->materials[entry.first], "roughness", element.materialContainer->plasticRoughness); - ospSet1f(this->materials[entry.first], "thickness", element.materialContainer->plasticThickness); - break; - case THINGLASS: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "ThinGlass"); - ospSet3fv(this->materials[entry.first], "transmission", - element.materialContainer->thinglassTransmission.data()); - ospSet1f(this->materials[entry.first], "eta", element.materialContainer->thinglassEta); - ospSet1f(this->materials[entry.first], "thickness", element.materialContainer->thinglassThickness); - break; - case VELVET: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Velvet"); - ospSet3fv(this->materials[entry.first], "reflectance", - element.materialContainer->velvetReflectance.data()); - ospSet3fv(this->materials[entry.first], "horizonScatteringColor", - element.materialContainer->velvetHorizonScatteringColor.data()); - ospSet1f(this->materials[entry.first], "backScattering", - element.materialContainer->velvetBackScattering); - ospSet1f(this->materials[entry.first], "horizonScatteringFallOff", - element.materialContainer->velvetHorizonScatteringFallOff); - break; - } - ospCommit(this->materials[entry.first]); + fillMaterialContainer(entry.first, element); + _materials[entry.first].commit(); } - if (this->materials[entry.first] != NULL) { + if (this->_materials[entry.first] != NULL) { if (element.type == structureTypeEnum::GEOMETRY) { - ospSetMaterial( - std::get(this->baseStructures[entry.first].back()), this->materials[entry.first]); - ospCommit(std::get(this->baseStructures[entry.first].back())); + _geometricModels[entry.first].back().setParam("material", ::ospray::cpp::CopiedData(_materials[entry.first])); + _geometricModels[entry.first].back().commit(); } } } @@ -766,11 +677,11 @@ namespace ospray { void AbstractOSPRayRenderer::changeTransformation() { - for (auto& entry : this->baseStructures) { - if (this->structureMap[entry.first].transformationContainer == nullptr) + for (auto& entry : this->_baseStructures) { + if (this->_structureMap[entry.first].transformationContainer == nullptr) continue; - auto trafo = this->structureMap[entry.first].transformationContainer; - osp::affine3f xfm; + auto trafo = this->_structureMap[entry.first].transformationContainer; + ::rkcommon::math::affine3f xfm; xfm.p.x = trafo->pos[0]; xfm.p.y = trafo->pos[1]; xfm.p.z = trafo->pos[2]; @@ -784,350 +695,302 @@ namespace ospray { xfm.l.vz.y = trafo->MX[2][1]; xfm.l.vz.z = trafo->MX[2][2]; - if (this->structureMap[entry.first].dataChanged) { - if (instancedModels[entry.first] != nullptr) { - ospRelease(instancedModels[entry.first]); - instancedModels.erase(entry.first); - } - instancedModels[entry.first] = ospNewModel(); - if (this->structureMap[entry.first].type == structureTypeEnum::GEOMETRY) { - for (int i = 0; i < entry.second.size(); i++) { - ospAddGeometry(instancedModels[entry.first], std::get(entry.second[i])); - } - } else { - for (int i = 0; i < entry.second.size(); i++) { - ospAddVolume(instancedModels[entry.first], std::get(entry.second[i])); - } - } - } - ospCommit(instancedModels[entry.first]); - if (this->instances[entry.first] != nullptr) { - ospRemoveGeometry(world, this->instances[entry.first]); - // ospRelease(this->instances[entry.first]); - this->instances.erase(entry.first); - } - this->instances[entry.first] = ospNewInstance(instancedModels[entry.first], xfm); - if (this->materials[entry.first] != nullptr) { - ospSetMaterial(this->instances[entry.first], this->materials[entry.first]); - } - ospCommit(this->instances[entry.first]); - ospAddGeometry(world, this->instances[entry.first]); - ospCommit(world); + _instances[entry.first].setParam("xfm", xfm); + _instances[entry.first].commit(); } } - bool AbstractOSPRayRenderer::fillWorld() { + bool AbstractOSPRayRenderer::generateRepresentations() { bool returnValue = true; - bool applyTransformation = false; - ospcommon::box3f worldBounds; - std::vector ghostRegions; - std::vector regions; + ::rkcommon::math::box3f _worldBounds; + std::vector<::rkcommon::math::box3f> ghostRegions; + std::vector<::rkcommon::math::box3f> regions; - for (auto& entry : this->structureMap) { + for (auto& entry : this->_structureMap) { - numCreateGeo = 1; + _numCreateGeo = 1; auto const& element = entry.second; // check if structure should be released first if (element.dataChanged) { - for (auto& stru : this->baseStructures[entry.first]) { - if (element.type == structureTypeEnum::GEOMETRY) { - ospRemoveGeometry(this->world, std::get(stru)); - // ospRelease(std::get(stru)); - } else if (element.type == structureTypeEnum::VOLUME) { - ospRemoveVolume(this->world, std::get(stru)); - // ospRelease(std::get(stru)); + for (int i = 0; i < _baseStructures[entry.first].size(); ++i) { + if (_baseStructures[entry.first].types[i] == structureTypeEnum::GEOMETRY) { + ospRelease(std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures[i]).handle()); + } else { + ospRelease(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures[i]).handle()); } } - this->baseStructures.erase(entry.first); + _baseStructures[entry.first].clear(); + _baseStructures.erase(entry.first); + + for (auto& georep : _geometricModels[entry.first]) { + ospRelease(georep.handle()); + } + _geometricModels[entry.first].clear(); + _geometricModels.erase(entry.first); + + for (auto& volrep : _volumetricModels[entry.first]) { + ospRelease(volrep.handle()); + } + _volumetricModels[entry.first].clear(); + _volumetricModels.erase(entry.first); + + for (auto& cliprep : _clippingModels[entry.first]) { + ospRelease(cliprep.handle()); + } + _clippingModels[entry.first].clear(); + _clippingModels.erase(entry.first); + + if (_groups[entry.first]) { + ospRelease(_groups[entry.first].handle()); + } + _groups[entry.first] = nullptr; + _groups.erase(entry.first); + } else { continue; } // custom material settings - if (this->materials[entry.first] != nullptr) { - ospRelease(this->materials[entry.first]); - this->materials.erase(entry.first); + if (_materials[entry.first]) { + _materials.erase(entry.first); } - if (element.materialContainer != NULL && - this->rd_type.Param()->Value() != MPI_RAYCAST) { - switch (element.materialContainer->materialType) { - case OBJMATERIAL: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "OBJMaterial"); - ospSet3fv(this->materials[entry.first], "Kd", element.materialContainer->Kd.data()); - ospSet3fv(this->materials[entry.first], "Ks", element.materialContainer->Ks.data()); - ospSet1f(this->materials[entry.first], "Ns", element.materialContainer->Ns); - ospSet1f(this->materials[entry.first], "d", element.materialContainer->d); - ospSet3fv(this->materials[entry.first], "Tf", element.materialContainer->Tf.data()); - break; - case LUMINOUS: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Luminous"); - ospSet3fv(this->materials[entry.first], "color", element.materialContainer->lumColor.data()); - ospSet1f(this->materials[entry.first], "intensity", element.materialContainer->lumIntensity); - ospSet1f(this->materials[entry.first], "transparency", element.materialContainer->lumTransparency); - break; - case GLASS: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Glass"); - ospSet1f(this->materials[entry.first], "etaInside", element.materialContainer->glassEtaInside); - ospSet1f(this->materials[entry.first], "etaOutside", element.materialContainer->glassEtaOutside); - ospSet3fv(this->materials[entry.first], "attenuationColorInside", - element.materialContainer->glassAttenuationColorInside.data()); - ospSet3fv(this->materials[entry.first], "attenuationColorOutside", - element.materialContainer->glassAttenuationColorOutside.data()); - ospSet1f(this->materials[entry.first], "attenuationDistance", - element.materialContainer->glassAttenuationDistance); - break; - case MATTE: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Matte"); - ospSet3fv(this->materials[entry.first], "reflectance", - element.materialContainer->matteReflectance.data()); - break; - case METAL: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Metal"); - ospSet3fv(this->materials[entry.first], "reflectance", - element.materialContainer->metalReflectance.data()); - ospSet3fv(this->materials[entry.first], "eta", element.materialContainer->metalEta.data()); - ospSet3fv(this->materials[entry.first], "k", element.materialContainer->metalK.data()); - ospSet1f(this->materials[entry.first], "roughness", element.materialContainer->metalRoughness); - break; - case METALLICPAINT: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "MetallicPaint"); - ospSet3fv(this->materials[entry.first], "shadeColor", - element.materialContainer->metallicShadeColor.data()); - ospSet3fv(this->materials[entry.first], "glitterColor", - element.materialContainer->metallicGlitterColor.data()); - ospSet1f(this->materials[entry.first], "glitterSpread", - element.materialContainer->metallicGlitterSpread); - ospSet1f(this->materials[entry.first], "eta", element.materialContainer->metallicEta); - break; - case PLASTIC: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Plastic"); - ospSet3fv(this->materials[entry.first], "pigmentColor", - element.materialContainer->plasticPigmentColor.data()); - ospSet1f(this->materials[entry.first], "eta", element.materialContainer->plasticEta); - ospSet1f(this->materials[entry.first], "roughness", element.materialContainer->plasticRoughness); - ospSet1f(this->materials[entry.first], "thickness", element.materialContainer->plasticThickness); - break; - case THINGLASS: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "ThinGlass"); - ospSet3fv(this->materials[entry.first], "transmission", - element.materialContainer->thinglassTransmission.data()); - ospSet1f(this->materials[entry.first], "eta", element.materialContainer->thinglassEta); - ospSet1f(this->materials[entry.first], "thickness", element.materialContainer->thinglassThickness); - break; - case VELVET: - this->materials[entry.first] = ospNewMaterial2(this->rd_type_string.c_str(), "Velvet"); - ospSet3fv(this->materials[entry.first], "reflectance", - element.materialContainer->velvetReflectance.data()); - ospSet3fv(this->materials[entry.first], "horizonScatteringColor", - element.materialContainer->velvetHorizonScatteringColor.data()); - ospSet1f(this->materials[entry.first], "backScattering", - element.materialContainer->velvetBackScattering); - ospSet1f(this->materials[entry.first], "horizonScatteringFallOff", - element.materialContainer->velvetHorizonScatteringFallOff); - break; - } - ospCommit(this->materials[entry.first]); + if (element.materialContainer && + this->_rd_type.Param()->Value() != MPI_RAYCAST) { + fillMaterialContainer(entry.first, element); + _materials[entry.first].commit(); } - OSPData vertexData = NULL; - OSPData colorData = NULL; - OSPData normalData = NULL; - OSPData texData = NULL; - OSPData indexData = NULL; - OSPData voxels = NULL; - OSPData isovalues = NULL; - OSPData planes = NULL; - OSPData xData = NULL; - OSPData yData = NULL; - OSPData zData = NULL; - OSPData bboxData = NULL; - OSPVolume aovol = NULL; - OSPError error; - - // OSPPlane pln = NULL; //TEMPORARILY DISABLED switch (element.type) { case structureTypeEnum::UNINITIALIZED: break; case structureTypeEnum::OSPRAY_API_STRUCTURES: - if (element.ospStructures.first.empty()) { + { + auto& container = std::get(element.structure); + if (container.ospStructures.first.empty()) { // returnValue = false; break; } - for (auto structure : element.ospStructures.first) { - if (element.ospStructures.second == structureTypeEnum::GEOMETRY) { - baseStructures[entry.first].push_back(reinterpret_cast(structure)); - } else if (element.ospStructures.second == structureTypeEnum::VOLUME) { - baseStructures[entry.first].push_back(reinterpret_cast(structure)); + + for (auto structure : container.ospStructures.first) { + if (container.ospStructures.second == structureTypeEnum::GEOMETRY) { + _baseStructures[entry.first].emplace_back( + reinterpret_cast(structure), structureTypeEnum::GEOMETRY); + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel(std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); + //_geometricModels[entry.first].back().commit(); + } else if (container.ospStructures.second == structureTypeEnum::VOLUME) { + _baseStructures[entry.first].emplace_back( + reinterpret_cast(structure), structureTypeEnum::VOLUME); + _volumetricModels[entry.first].emplace_back(::ospray::cpp::VolumetricModel( + std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.back()))); + _volumetricModels[entry.first].back().commit(); } else { megamol::core::utility::log::Log::DefaultLog.WriteError( "OSPRAY_API_STRUCTURE: Something went wrong."); + break; } } + // General geometry execution - for (unsigned int i = 0; i < element.ospStructures.first.size(); i++) { - auto idx = baseStructures[entry.first].size() - 1 - i; - if (this->materials[entry.first] != NULL && baseStructures[entry.first].size() > 0) { - ospSetMaterial( - std::get(baseStructures[entry.first][idx]), this->materials[entry.first]); + for (unsigned int i = 0; i < container.ospStructures.first.size(); i++) { + auto idx = _baseStructures[entry.first].size() - 1 - i; + if (_materials[entry.first] != NULL && _baseStructures[entry.first].size() > 0) { + _geometricModels[entry.first][idx].setParam("material", ::ospray::cpp::CopiedData(_materials[entry.first])); + _geometricModels[entry.first][idx].commit(); } + } - if (baseStructures[entry.first].size() > 0) { - ospCommit(std::get(baseStructures[entry.first][idx])); - ospAddGeometry(world, std::get(baseStructures[entry.first][idx])); - } + _groups[entry.first] = ::ospray::cpp::Group(); + if (!_geometricModels[entry.first].empty()) { + _groups[entry.first].setParam("geometry", ::ospray::cpp::CopiedData(_geometricModels[entry.first])); + } + if (!_volumetricModels[entry.first].empty()) { + _groups[entry.first].setParam("volume", ::ospray::cpp::CopiedData(_volumetricModels[entry.first])); + } + _groups[entry.first].commit(); } break; case structureTypeEnum::GEOMETRY: switch (element.geometryType) { + case geometryTypeEnum::TEST: + + using namespace rkcommon::math; + using namespace ::ospray::cpp; + { + // triangle mesh data + std::vector vertex = {vec3f(-1.0f, -1.0f, 3.0f), vec3f(-1.0f, 1.0f, 3.0f), + vec3f(1.0f, -1.0f, 3.0f), vec3f(0.1f, 0.1f, 0.3f)}; + + std::vector color = {vec4f(0.9f, 0.5f, 0.5f, 1.0f), vec4f(0.8f, 0.8f, 0.8f, 1.0f), + vec4f(0.8f, 0.8f, 0.8f, 1.0f), vec4f(0.5f, 0.9f, 0.5f, 1.0f)}; + + std::vector index = {vec3ui(0, 1, 2), vec3ui(1, 2, 3)}; + + // create and setup model and mesh + _baseStructures[entry.first].emplace_back( + ::ospray::cpp::Geometry("mesh"), structureTypeEnum::GEOMETRY); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("vertex.position", CopiedData(vertex)); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("vertex.color", CopiedData(color)); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("index", CopiedData(index)); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + + // put the mesh into a model + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); + _geometricModels[entry.first].back().commit(); + } + + break; case geometryTypeEnum::SPHERES: - if (element.vertexData == NULL) { + { + auto& container = std::get(element.structure); + + if (container.vertexData == NULL) { // returnValue = false; break; } - numCreateGeo = element.partCount * element.vertexLength * sizeof(float) / ispcLimit + 1; + _numCreateGeo = container.partCount * container.vertexLength * sizeof(float) / _ispcLimit + 1; - for (unsigned int i = 0; i < numCreateGeo; i++) { - baseStructures[entry.first].push_back(ospNewGeometry("spheres")); + for (unsigned int i = 0; i < _numCreateGeo; i++) { + _baseStructures[entry.first].emplace_back( + ::ospray::cpp::Geometry("sphere"), structureTypeEnum::GEOMETRY); - long long int vertexFloatsToRead = element.partCount * element.vertexLength / numCreateGeo; - vertexFloatsToRead -= vertexFloatsToRead % element.vertexLength; - if (vertexData != NULL) - ospRelease(vertexData); - vertexData = ospNewData(vertexFloatsToRead, OSP_FLOAT, - &element.vertexData->operator[](i* vertexFloatsToRead), OSP_DATA_SHARED_BUFFER); + unsigned long long vertexFloatsToRead = + container.partCount * container.vertexLength / _numCreateGeo; + vertexFloatsToRead -= vertexFloatsToRead % container.vertexLength; - ospSet1i(std::get(baseStructures[entry.first].back()), "bytes_per_sphere", - element.vertexLength * sizeof(float)); + unsigned long long bytes_per_sphere = container.vertexLength * sizeof(float); + auto vertexData = + ::ospray::cpp::SharedData(&container.vertexData->operator[](i* vertexFloatsToRead), + OSP_VEC3F, vertexFloatsToRead / container.vertexLength, bytes_per_sphere); - if (element.vertexLength > 3) { - // ospRemoveParam(geo.back(), "radius"); - ospSet1f(std::get(baseStructures[entry.first].back()), "offset_radius", - 3 * sizeof(float)); - // TODO: HACK - ospSet1f(std::get(baseStructures[entry.first].back()), "radius", 1); + vertexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("sphere.position", vertexData); + + if (container.vertexLength > 3) { + auto radiusData = + ::ospray::cpp::SharedData(&container.vertexData->operator[](i* vertexFloatsToRead + 3), + OSP_FLOAT, vertexFloatsToRead / container.vertexLength, bytes_per_sphere); + radiusData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("sphere.radius", radiusData); } else { - ospSet1f(std::get(baseStructures[entry.first].back()), "radius", - element.globalRadius); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("radius", container.globalRadius); } - ospCommit(vertexData); - ospSetData(std::get(baseStructures[entry.first].back()), "spheres", vertexData); - - if (element.colorLength == 4) { - long long int colorFloatsToRead = element.partCount * element.colorLength / numCreateGeo; - colorFloatsToRead -= colorFloatsToRead % element.colorLength; - if (colorData != NULL) - ospRelease(colorData); - colorData = ospNewData(colorFloatsToRead, OSP_FLOAT, - &element.colorData->operator[](i* colorFloatsToRead), OSP_DATA_SHARED_BUFFER); - ospCommit(colorData); - ospSetData(std::get(baseStructures[entry.first].back()), "color", colorData); - // ospSet1i(geo.back(), "color_components", 4); - ospSet1i( - std::get(baseStructures[entry.first].back()), "color_format", OSP_FLOAT4); - // ospSet1i(geo.back(), "color_offset", 0); - // ospSet1i(geo.back(), "color_stride", 4 * sizeof(float)); + + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); + + if (container.colorLength == 4) { + unsigned long long colorFloatsToRead = + container.partCount * container.colorLength / _numCreateGeo; + colorFloatsToRead -= colorFloatsToRead % container.colorLength; + + auto colorData = + ::ospray::cpp::SharedData(&container.colorData->operator[](i* colorFloatsToRead), + OSP_VEC4F, colorFloatsToRead / container.colorLength); + colorData.commit(); + _geometricModels[entry.first].back().setParam("color", colorData); } } - // clipPlane setup - /* TEMPORARILY DISABLED - if (!std::all_of(element.clipPlaneData->begin(), element.clipPlaneData->end() - 1, [](float i) { - return i == 0; })) { pln = ospNewPlane("clipPlane"); ospSet1f(pln, "dist", - element.clipPlaneData->data()[3]); ospSet3fv(pln, "normal", element.clipPlaneData->data()); - ospSet4fv(pln, "color", element.clipPlaneColor->data()); - ospCommit(pln); - ospSetObject(geo, "clipPlane", pln); - } else { - ospSetObject(geo, "clipPlane", NULL); } - */ break; case geometryTypeEnum::NHSPHERES: - if (element.raw == NULL) { + { + auto& container = std::get(element.structure); + if (container.raw == NULL) { // returnValue = false; break; } - numCreateGeo = element.partCount * element.vertexStride / ispcLimit + 1; + _numCreateGeo = container.partCount * container.dataStride / _ispcLimit + 1; - for (unsigned int i = 0; i < numCreateGeo; i++) { - baseStructures[entry.first].push_back(ospNewGeometry("spheres")); + for (unsigned int i = 0; i < _numCreateGeo; i++) { + _baseStructures[entry.first].emplace_back( + ::ospray::cpp::Geometry("sphere"), structureTypeEnum::GEOMETRY); + unsigned long long floatsToRead = + container.partCount * container.dataStride / (_numCreateGeo * sizeof(float)); + floatsToRead -= floatsToRead % (container.dataStride / sizeof(float)); + unsigned long long bytes_per_sphere = container.dataStride; + unsigned long long floats_per_sphere = container.dataStride / sizeof(float); - long long int floatsToRead = - element.partCount * element.vertexStride / (numCreateGeo * sizeof(float)); - floatsToRead -= floatsToRead % (element.vertexStride / sizeof(float)); + auto vertexData = ::ospray::cpp::SharedData(&static_cast(container.raw)[i * floatsToRead], + OSP_VEC3F, floatsToRead / floats_per_sphere, bytes_per_sphere); + vertexData.commit(); - if (vertexData != NULL) - ospRelease(vertexData); - vertexData = ospNewData(floatsToRead, OSP_FLOAT, - &static_cast(element.raw)[i * floatsToRead], OSP_DATA_SHARED_BUFFER); - ospCommit(vertexData); - ospSet1i(std::get(baseStructures[entry.first].back()), "bytes_per_sphere", - element.vertexStride); - ospSetData(std::get(baseStructures[entry.first].back()), "spheres", vertexData); - ospSetData(std::get(baseStructures[entry.first].back()), "color", NULL); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("sphere.position", vertexData); - if (element.vertexLength > 3) { - ospSet1f(std::get(baseStructures[entry.first].back()), "offset_radius", - 3 * sizeof(float)); + if (container.vertexLength > 3) { + auto radiusData = ::ospray::cpp::SharedData( + &static_cast(container.raw)[i * floatsToRead + 3], + OSP_FLOAT, floatsToRead / floats_per_sphere, bytes_per_sphere); + radiusData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("sphere.radius", + radiusData); } else { - ospSet1f(std::get(baseStructures[entry.first].back()), "radius", - element.globalRadius); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("radius", container.globalRadius); } - if (element.mmpldColor == - core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGB || - element.mmpldColor == + + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); + if (container.mmpldColor == core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGBA) { - ospSet1i(std::get(baseStructures[entry.first].back()), "color_offset", - element.vertexLength * - sizeof(float)); // TODO: This won't work if there are radii in the array - ospSet1i(std::get(baseStructures[entry.first].back()), "color_stride", - element.colorStride); - ospSetData(std::get(baseStructures[entry.first].back()), "color", vertexData); - if (element.mmpldColor == - core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGB) { - // ospSet1i(geo.back(), "color_components", 3); - ospSet1i(std::get(baseStructures[entry.first].back()), "color_format", - OSP_FLOAT3); - } else { - // ospSet1i(geo.back(), "color_components", 4); - ospSet1i(std::get(baseStructures[entry.first].back()), "color_format", - OSP_FLOAT4); - } - } + auto colorData = ::ospray::cpp::SharedData( + &static_cast(container.raw)[i * floatsToRead + container.vertexLength], + OSP_VEC4F, floatsToRead / floats_per_sphere, bytes_per_sphere); + colorData.commit(); + _geometricModels[entry.first].back().setParam("color", colorData); + } else if (container.mmpldColor == + core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGB) { + megamol::core::utility::log::Log::DefaultLog.WriteError("OSPRAY_NHSPERES: RGB not supported."); + rkcommon::math::vec4f gcol = {0.8, 0.8, 0.8, 1.0}; + _geometricModels[entry.first].back().setParam("color", gcol); + } else if (container.mmpldColor == + core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_NONE) { + // TODO: get global color + rkcommon::math::vec4f gcol = {0.8, 0.8, 0.8, 1.0}; + _geometricModels[entry.first].back().setParam("color", gcol); + } // end if color type + } // end for num geometies } break; - case geometryTypeEnum::QUADS: - case geometryTypeEnum::TRIANGLES: - if (element.mesh == NULL) { + case geometryTypeEnum::MESH: + { + auto& container = std::get(element.structure); + if (container.mesh == NULL) { // returnValue = false; break; } { std::vector tex_vec; - if (element.mesh_textures != nullptr) { - assert(element.mesh->accessMeshes().size() == element.mesh_textures->accessImages().size()); - tex_vec = element.mesh_textures->accessImages(); + if (container.mesh_textures != nullptr) { + assert(container.mesh->accessMeshes().size() == + container.mesh_textures->accessImages().size()); + tex_vec = container.mesh_textures->accessImages(); } - this->numCreateGeo = element.mesh->accessMeshes().size(); + _numCreateGeo = container.mesh->accessMeshes().size(); uint32_t mesh_index = 0; - for (auto& mesh : element.mesh->accessMeshes()) { + for (auto& mesh : container.mesh->accessMeshes()) { - if (element.geometryType == TRIANGLES) { - this->baseStructures[entry.first].push_back(ospNewGeometry("triangles")); - } else if (element.geometryType == QUADS) { - this->baseStructures[entry.first].push_back(ospNewGeometry("quads")); - } + _baseStructures[entry.first].emplace_back(ospNewGeometry("mesh"), structureTypeEnum::GEOMETRY); + + auto mesh_type = mesh.second.primitive_type; for (auto& attrib : mesh.second.attributes) { @@ -1135,139 +998,164 @@ namespace ospray { auto count = attrib.byte_size / (mesh::MeshDataAccessCollection::getByteSize(attrib.component_type) * attrib.component_cnt); - auto ospType = OSP_FLOAT3; - if (attrib.stride == 4 * sizeof(float)) - ospType = OSP_FLOAT3A; - vertexData = ospNewData(count, ospType, attrib.data, OSP_DATA_SHARED_BUFFER); - ospCommit(vertexData); - ospSetData(std::get(baseStructures[entry.first].back()), "vertex", - vertexData); + + auto vertexData = + ::ospray::cpp::SharedData(attrib.data, OSP_VEC3F, count, attrib.stride); + vertexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("vertex.position", vertexData); } // check normal pointer if (attrib.semantic == mesh::MeshDataAccessCollection::NORMAL) { auto count = attrib.byte_size / attrib.stride; - auto ospType = OSP_FLOAT3; - if (attrib.stride == 4 * sizeof(float)) - ospType = OSP_FLOAT3A; - normalData = ospNewData(count, ospType, attrib.data); - ospCommit(normalData); - ospSetData(std::get(baseStructures[entry.first].back()), - "vertex.normal", normalData); + auto normalData = + ::ospray::cpp::SharedData(attrib.data, OSP_VEC3F, count, attrib.stride); + normalData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("vertex.normal", normalData); } // check colorpointer and convert to rgba if (attrib.semantic == mesh::MeshDataAccessCollection::COLOR) { - if (attrib.component_type == mesh::MeshDataAccessCollection::ValueType::FLOAT) - colorData = ospNewData( - attrib.byte_size / - (mesh::MeshDataAccessCollection::getByteSize(attrib.component_type) * - attrib.component_cnt), - OSP_FLOAT4, attrib.data); - else - colorData = ospNewData( - attrib.byte_size, OSP_UCHAR, attrib.data, OSP_DATA_SHARED_BUFFER); - ospCommit(colorData); - ospSetData(std::get(baseStructures[entry.first].back()), - "vertex.color", colorData); + ::ospray::cpp::SharedData colorData; + if (attrib.component_type == mesh::MeshDataAccessCollection::ValueType::FLOAT) { + auto count = attrib.byte_size / (mesh::MeshDataAccessCollection::getByteSize(attrib.component_type) * attrib.component_cnt); + auto osp_type = OSP_VEC3F; + if (attrib.component_cnt == 4) osp_type = OSP_VEC4F; + colorData = + ::ospray::cpp::SharedData(attrib.data, osp_type, count, attrib.stride); + } else { + core::utility::log::Log::DefaultLog.WriteError("[OSPRayRenderer][MESH] Color type not supported."); + } + colorData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("vertex.color", colorData); } // check texture array if (attrib.semantic == mesh::MeshDataAccessCollection::TEXCOORD) { - texData = ospNewData( - attrib.byte_size / - (mesh::MeshDataAccessCollection::getByteSize(attrib.component_type) * - attrib.component_cnt), - OSP_FLOAT2, attrib.data, OSP_DATA_SHARED_BUFFER); - ospCommit(texData); - ospSetData(std::get(baseStructures[entry.first].back()), - "vertex.texcoord", texData); + auto count = attrib.byte_size / + (mesh::MeshDataAccessCollection::getByteSize(attrib.component_type) * + attrib.component_cnt); + auto texData = ::ospray::cpp::SharedData(attrib.data, OSP_VEC2F, count, attrib.stride); + texData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("vertex.texcoord", texData); } } // check index pointer if (mesh.second.indices.data != nullptr) { auto count = mesh.second.indices.byte_size / mesh::MeshDataAccessCollection::getByteSize(mesh.second.indices.type); - indexData = - ospNewData(count, OSP_UINT, mesh.second.indices.data, OSP_DATA_SHARED_BUFFER); - ospCommit(indexData); - ospSetData( - std::get(baseStructures[entry.first].back()), "index", indexData); + + unsigned long long stride = 3 * sizeof(unsigned int); + auto osp_type = OSP_VEC3UI; + + if (mesh_type == mesh::MeshDataAccessCollection::QUADS) { + stride = 4 * sizeof(unsigned int); + osp_type = OSP_VEC4UI; + } + + auto indexData = + ::ospray::cpp::SharedData(mesh.second.indices.data, osp_type, count, stride); + indexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("index", indexData); } else { megamol::core::utility::log::Log::DefaultLog.WriteError( "OSPRay cannot render meshes without index array"); returnValue = false; } - if (element.mesh_textures != nullptr) { - OSPTextureFormat osp_tex_format = OSP_TEXTURE_FORMAT_INVALID; + + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); + + if (container.mesh_textures != nullptr) { + auto osp_tex_format = OSP_TEXTURE_FORMAT_INVALID; + auto osp_data_format = OSP_BYTE; switch (tex_vec[mesh_index].format) { case mesh::ImageDataAccessCollection::TextureFormat::RGBA8: osp_tex_format = OSP_TEXTURE_RGBA8; break; case mesh::ImageDataAccessCollection::TextureFormat::RGB32F: osp_tex_format = OSP_TEXTURE_RGB32F; + osp_data_format = OSP_FLOAT; break; case mesh::ImageDataAccessCollection::TextureFormat::RGB8: osp_tex_format = OSP_TEXTURE_RGB8; break; case mesh::ImageDataAccessCollection::TextureFormat::RGBA32F: osp_tex_format = OSP_TEXTURE_RGBA32F; + osp_data_format = OSP_FLOAT; break; default: osp_tex_format = OSP_TEXTURE_RGB8; break; } - auto ospTexture = - ospNewTexture2D({tex_vec[mesh_index].width, tex_vec[mesh_index].height}, - osp_tex_format, tex_vec[mesh_index].data, OSP_DATA_SHARED_BUFFER); - auto ospMat = ospNewMaterial2(this->rd_type_string.c_str(), "OBJMaterial"); - ospCommit(ospTexture); - ospSetObject(ospMat, "map_Kd", ospTexture); + auto ospTexture = ::ospray::cpp::Texture("texture2d"); + rkcommon::math::vec2i width_height = {tex_vec[mesh_index].width, tex_vec[mesh_index].height}; + + auto textureData = ::ospray::cpp::SharedData( + tex_vec[mesh_index].data, osp_data_format, width_height); + textureData.commit(); + + ospTexture.setParam("format", osp_tex_format); + ospTexture.setParam("data", textureData); + ospTexture.commit(); + + auto ospMat = ::ospray::cpp::Material(_rd_type_string.c_str(), "obj"); + ospMat.setParam("map_Kd", ospTexture); // ospSetObject(ospMat, "map_Ks", ospTexture); // ospSetObject(ospMat, "map_d", ospTexture); - ospCommit(ospMat); - ospSetMaterial(std::get(baseStructures[entry.first].back()), ospMat); + ospMat.commit(); + _geometricModels[entry.first].back().setParam("material", ::ospray::cpp::CopiedData(ospMat)); } mesh_index++; } } + } break; - case geometryTypeEnum::STREAMLINES: - if (element.vertexData == nullptr && element.mesh == nullptr) { + case geometryTypeEnum::LINES: + case geometryTypeEnum::CURVES: + { + auto& container = std::get(element.structure); + if (container.vertexData == nullptr && container.mesh == nullptr) { // returnValue = false; megamol::core::utility::log::Log::DefaultLog.WriteError( "[AbstractOSPRayRenderer]Streamline geometry detected but no data found."); break; } - if (element.mesh != nullptr) { - this->numCreateGeo = element.mesh->accessMeshes().size(); - for (auto& mesh : element.mesh->accessMeshes()) { + if (container.mesh != nullptr) { + this->_numCreateGeo = container.mesh->accessMeshes().size(); + for (auto& mesh : container.mesh->accessMeshes()) { + + _baseStructures[entry.first].emplace_back(::ospray::cpp::Geometry("curve"), structureTypeEnum::GEOMETRY); - baseStructures[entry.first].push_back(ospNewGeometry("streamlines")); for (auto& attrib : mesh.second.attributes) { if (attrib.semantic == mesh::MeshDataAccessCollection::POSITION) { const auto count = attrib.byte_size / attrib.stride; - assert(attrib.stride == 4 * sizeof(float)); - vertexData = ospNewData(count, OSP_FLOAT3A, attrib.data, OSP_DATA_SHARED_BUFFER); - ospCommit(vertexData); - ospSetData(std::get(baseStructures[entry.first].back()), "vertex", - vertexData); + auto vertexData = ::ospray::cpp::SharedData(attrib.data, OSP_VEC3F, count, attrib.stride); + vertexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("vertex.position", vertexData); } // check colorpointer and convert to rgba if (attrib.semantic == mesh::MeshDataAccessCollection::COLOR) { - if (attrib.component_type == mesh::MeshDataAccessCollection::ValueType::FLOAT) - colorData = - ospNewData(attrib.byte_size / attrib.stride, OSP_FLOAT4, attrib.data); - else - colorData = ospNewData( - attrib.byte_size, OSP_UCHAR, attrib.data, OSP_DATA_SHARED_BUFFER); - ospCommit(colorData); - ospSetData(std::get(baseStructures[entry.first].back()), - "vertex.color", colorData); + ::ospray::cpp::SharedData colorData; + if (attrib.component_type == mesh::MeshDataAccessCollection::ValueType::FLOAT) { + auto count = attrib.byte_size / attrib.stride; + colorData = ::ospray::cpp::SharedData( + attrib.data, OSP_VEC3F, count, attrib.stride); + } else { + core::utility::log::Log::DefaultLog.WriteError("[OSPRayRenderer][CURVE] Color type not supported."); + } + colorData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("vertex.color", colorData); } } // check index pointer @@ -1275,287 +1163,262 @@ namespace ospray { const auto count = mesh.second.indices.byte_size / mesh::MeshDataAccessCollection::getByteSize(mesh.second.indices.type); - indexData = - ospNewData(count, OSP_INT, mesh.second.indices.data, OSP_DATA_SHARED_BUFFER); - ospCommit(indexData); - ospSetData( - std::get(baseStructures[entry.first].back()), "index", indexData); + auto indexData = ::ospray::cpp::SharedData(mesh.second.indices.data, OSP_UINT, count); + indexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("index", indexData); } else { megamol::core::utility::log::Log::DefaultLog.WriteError( - "OSPRay cannot render meshes without index array"); + "OSPRay cannot render curves without index array"); returnValue = false; } - ospSet1f(std::get(baseStructures[entry.first].back()), "radius", - element.globalRadius); - ospSet1i( - std::get(baseStructures[entry.first].back()), "smooth", element.smooth); - } // end for geometry - } else { - baseStructures[entry.first].push_back(ospNewGeometry("streamlines")); - this->numCreateGeo = 1; - osp::vec3fa* data = new osp::vec3fa[element.vertexData->size() / 3]; - - // fill aligned array with vertex data - for (unsigned int i = 0; i < element.vertexData->size() / 3; i++) { - data[i].x = element.vertexData->data()[3 * i + 0]; - data[i].y = element.vertexData->data()[3 * i + 1]; - data[i].z = element.vertexData->data()[3 * i + 2]; - } - + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("radius", container.globalRadius); + // TODO: Add user input support for this + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("type", OSP_ROUND); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("basis", OSP_LINEAR); - vertexData = - ospNewData(element.vertexData->size() / 3, OSP_FLOAT3A, data, OSP_DATA_SHARED_BUFFER); - ospCommit(vertexData); - ospSetData(std::get(baseStructures[entry.first].back()), "vertex", vertexData); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); - indexData = ospNewData( - element.indexData->size(), OSP_UINT, element.indexData->data(), OSP_DATA_SHARED_BUFFER); - ospCommit(indexData); - ospSetData(std::get(baseStructures[entry.first].back()), "index", indexData); - - if (element.colorData->size() > 0) { - colorData = ospNewData(element.colorData->size() / element.colorLength, OSP_FLOAT4, - element.colorData->data(), OSP_DATA_SHARED_BUFFER); - ospCommit(colorData); - ospSetData( - std::get(baseStructures[entry.first].back()), "vertex.color", colorData); + } // end for geometry + } else { + _baseStructures[entry.first].emplace_back(::ospray::cpp::Geometry("curve"), structureTypeEnum::GEOMETRY); + + this->_numCreateGeo = 1; + + auto vertexData = ::ospray::cpp::SharedData( + container.vertexData->data(), OSP_VEC3F, container.vertexData->size() / 3); + vertexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).setParam("vertex.position", vertexData); + + auto indexData = ::ospray::cpp::SharedData(*container.indexData); + indexData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("index", indexData); + + if (container.colorData->size() > 0) { + auto colorData = ::ospray::cpp::SharedData( + container.colorData->data(), OSP_VEC4F, container.colorData->size() / 4); + colorData.commit(); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("vertex.color", colorData); } - ospSet1f( - std::get(baseStructures[entry.first].back()), "radius", element.globalRadius); - ospSet1i(std::get(baseStructures[entry.first].back()), "smooth", element.smooth); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("radius", container.globalRadius); + // TODO: Add user input support for this + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("type", OSP_ROUND); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("basis", OSP_LINEAR); + + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); } - break; - case geometryTypeEnum::CYLINDERS: - if (element.raw == NULL) { - // returnValue = false; - break; - } - - numCreateGeo = element.partCount * element.vertexStride / ispcLimit + 1; - - for (unsigned int i = 0; i < numCreateGeo; i++) { - baseStructures[entry.first].push_back(ospNewGeometry("cylinders")); - - - long long int floatsToRead = - element.partCount * element.vertexStride / (numCreateGeo * sizeof(float)); - floatsToRead -= floatsToRead % (element.vertexStride / sizeof(float)); - - if (vertexData != NULL) - ospRelease(vertexData); - vertexData = ospNewData(floatsToRead, OSP_FLOAT, - &static_cast(element.raw)[i * floatsToRead], OSP_DATA_SHARED_BUFFER); - ospCommit(vertexData); - ospSet1i(std::get(baseStructures[entry.first].back()), "bytes_per_cylinder", - 2 * element.vertexStride); - ospSet1i(std::get(baseStructures[entry.first].back()), "offset_v1", - element.vertexStride); - ospSetData(std::get(baseStructures[entry.first].back()), "cylinders", vertexData); - ospSetData(std::get(baseStructures[entry.first].back()), "color", NULL); - - if (element.vertexLength > 3) { - ospSet1f(std::get(baseStructures[entry.first].back()), "offset_radius", - 3 * sizeof(float)); - } else { - ospSet1f(std::get(baseStructures[entry.first].back()), "radius", - element.globalRadius); - } } break; } // General geometry execution - for (unsigned int i = 0; i < this->numCreateGeo; i++) { - if (this->materials[entry.first] != NULL && baseStructures[entry.first].size() > 0) { - ospSetMaterial(std::get(baseStructures[entry.first].rbegin()[i]), - this->materials[entry.first]); + for (unsigned int i = 0; i < this->_numCreateGeo; i++) { + if (_materials[entry.first] != NULL && _geometricModels[entry.first].size() > 0) { + _geometricModels[entry.first].rbegin()[i].setParam("material", ::ospray::cpp::CopiedData(_materials[entry.first])); } - if (baseStructures[entry.first].size() > 0) { - ospCommit(std::get(baseStructures[entry.first].rbegin()[i])); - if (element.transformationContainer == nullptr) { - ospAddGeometry(world, std::get(baseStructures[entry.first].rbegin()[i])); - } else { - applyTransformation = true; - } + if (_geometricModels[entry.first].size() > 0) { + _geometricModels[entry.first].rbegin()[i].commit(); } + _groups[entry.first] = ::ospray::cpp::Group(); + _groups[entry.first].setParam("geometry", ::ospray::cpp::CopiedData(_geometricModels[entry.first])); + _groups[entry.first].commit(); } - - // if (vertexData != NULL) ospRelease(vertexData); - // if (colorData != NULL) ospRelease(colorData); - // if (normalData != NULL) ospRelease(normalData); - // if (texData != NULL) ospRelease(texData); - // if (indexData != NULL) ospRelease(indexData); - // if (xData != NULL) ospRelease(xData); - // if (yData != NULL) ospRelease(yData); - // if (zData != NULL) ospRelease(zData); - // if (bboxData != NULL) ospRelease(bboxData); - // if (aovol != NULL) ospRelease(aovol); - // if (voxels != NULL) ospRelease(voxels); - break; case structureTypeEnum::VOLUME: - - if (element.voxels == NULL) { + { + auto& container = std::get(element.structure); + if (container.voxels == NULL) { // returnValue = false; break; } - baseStructures[entry.first].push_back(ospNewVolume("shared_structured_volume")); - - auto type = static_cast(element.voxelDType); - - ospSetString( - std::get(baseStructures[entry.first].back()), "voxelType", voxelDataTypeS[type].c_str()); - // float fixedSpacing[3]; - // for (auto x = 0; x < 3; ++x) { - // fixedSpacing[x] = element.gridSpacing->at(x) / (element.dimensions->at(x) - 1) + - // element.gridSpacing->at(x); - //} - // scaling properties of the volume - ospSet3iv( - std::get(baseStructures[entry.first].back()), "dimensions", element.dimensions->data()); - ospSet3fv( - std::get(baseStructures[entry.first].back()), "gridOrigin", element.gridOrigin->data()); - ospSet3fv(std::get(baseStructures[entry.first].back()), "gridSpacing", - element.gridSpacing->data()); - ospSet2f(std::get(baseStructures[entry.first].back()), "voxelRange", - element.valueRange->first, element.valueRange->second); - - ospSet1b(std::get(baseStructures[entry.first].back()), "singleShade", element.useMIP); - ospSet1b(std::get(baseStructures[entry.first].back()), "gradientShadingEnables", - element.useGradient); - ospSet1b(std::get(baseStructures[entry.first].back()), "preIntegration", - element.usePreIntegration); - ospSet1b(std::get(baseStructures[entry.first].back()), "adaptiveSampling", - element.useAdaptiveSampling); - ospSet1f( - std::get(baseStructures[entry.first].back()), "adaptiveScalar", element.adaptiveFactor); - ospSet1f(std::get(baseStructures[entry.first].back()), "adaptiveMaxSamplingRate", - element.adaptiveMaxRate); - ospSet1f(std::get(baseStructures[entry.first].back()), "samplingRate", element.samplingRate); - - // add data - voxels = ospNewData(element.voxelCount, static_cast(voxelDataTypeOSP[type]), - element.voxels, OSP_DATA_SHARED_BUFFER); - ospCommit(voxels); - ospSetData(std::get(baseStructures[entry.first].back()), "voxelData", voxels); + _baseStructures[entry.first].emplace_back(::ospray::cpp::Volume("structuredRegular"), structureTypeEnum::VOLUME); - // ClippingBox + auto type = static_cast(voxelDataTypeOSP[static_cast(container.voxelDType)]); - if (element.clippingBoxActive) { - ospSet3fv(std::get(baseStructures[entry.first].back()), "volumeClippingBoxLower", - element.clippingBoxLower->data()); - ospSet3fv(std::get(baseStructures[entry.first].back()), "volumeClippingBoxUpper", - element.clippingBoxUpper->data()); - } else { - ospSetVec3f(std::get(baseStructures[entry.first].back()), "volumeClippingBoxLower", - {0.0f, 0.0f, 0.0f}); - ospSetVec3f(std::get(baseStructures[entry.first].back()), "volumeClippingBoxUpper", - {0.0f, 0.0f, 0.0f}); - } + // add data + rkcommon::math::vec3i dims = { + container.dimensions[0], container.dimensions[1], container.dimensions[2]}; + auto voxelData = ::ospray::cpp::SharedData(container.voxels, + type, dims); + voxelData.commit(); + + + std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.back()) + .setParam("data", voxelData); + + //ospSet3iv(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "dimensions",element.dimensions->data()); + std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.back()) + .setParam("gridOrigin", convertToVec3f(container.gridOrigin)); + std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.back()) + .setParam("gridSpacing", convertToVec3f(container.gridSpacing)); + + + //std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()).setParam("voxelRange", element.valueRange); + //ospSet1b(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "singleShade", element.useMIP); + //ospSet1b(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "gradientShadingEnables", + // element.useGradient); + //ospSet1b(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "preIntegration", + // element.usePreIntegration); + //ospSet1b(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "adaptiveSampling", + // element.useAdaptiveSampling); + //ospSet1f( + // std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "adaptiveScalar", element.adaptiveFactor); + //ospSet1f(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "adaptiveMaxSamplingRate", + // element.adaptiveMaxRate); + //ospSet1f(std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].back()), "samplingRate", element.samplingRate); + + auto tf = ::ospray::cpp::TransferFunction("piecewiseLinear"); - OSPTransferFunction tf = ospNewTransferFunction("piecewise_linear"); + auto tf_rgb = + ::ospray::cpp::SharedData(container.tfRGB->data(), OSP_VEC3F, container.tfRGB->size() / 3); + auto tf_opa = ::ospray::cpp::SharedData(container.tfA->data(), OSP_FLOAT, container.tfA->size()); + tf.setParam("color", tf_rgb); + tf.setParam("opacity", tf_opa); + rkcommon::math::vec2f valrange = {container.valueRange[0], container.valueRange[1]}; + tf.setParam("valueRange", valrange); - OSPData tf_rgb = ospNewData(element.tfRGB->size() / 3, OSP_FLOAT3, element.tfRGB->data()); - OSPData tf_opa = ospNewData(element.tfA->size(), OSP_FLOAT, element.tfA->data()); - ospSetData(tf, "colors", tf_rgb); - ospSetData(tf, "opacities", tf_opa); - ospSet2f(tf, "valueRange", element.valueRange->first, element.valueRange->second); + tf.commit(); - ospCommit(tf); + std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.back()).commit(); + _volumetricModels[entry.first].emplace_back(::ospray::cpp::VolumetricModel( + std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.back()))); - ospSetObject(std::get(baseStructures[entry.first].back()), "transferFunction", tf); - ospCommit(std::get(baseStructures[entry.first].back())); - // ospRelease(tf); + _volumetricModels[entry.first].back().setParam("transferFunction", tf); + _volumetricModels[entry.first].back().commit(); - switch (element.volRepType) { + // ClippingBox + if (container.clippingBoxActive) { + _baseStructures[entry.first].emplace_back(::ospray::cpp::Geometry("box"), GEOMETRY); + + ::rkcommon::math::box3f box; + box.lower = { + container.clippingBoxLower[0], container.clippingBoxLower[1], container.clippingBoxLower[2]}; + box.upper = { + container.clippingBoxUpper[0], container.clippingBoxUpper[1], container.clippingBoxUpper[2]}; + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("box", ::ospray::cpp::CopiedData(box)); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + + _clippingModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); + _clippingModels[entry.first].back().commit(); + } + + switch (container.volRepType) { case volumeRepresentationType::VOLUMEREP: - if (element.transformationContainer == nullptr) { - ospAddVolume(world, std::get(baseStructures[entry.first].back())); - } else { - applyTransformation = true; + _groups[entry.first] = ::ospray::cpp::Group(); + _groups[entry.first].setParam("volume", ::ospray::cpp::CopiedData(_volumetricModels[entry.first])); + if (container.clippingBoxActive) { + _groups[entry.first].setParam( + "clippingGeometry", ::ospray::cpp::CopiedData(_clippingModels[entry.first])); } + _groups[entry.first].commit(); break; case volumeRepresentationType::ISOSURFACE: // isosurface - baseStructures[entry.first].push_back(ospNewGeometry("isosurfaces")); - isovalues = ospNewData(1, OSP_FLOAT, element.isoValue->data()); - ospCommit(isovalues); - ospSetData(std::get(baseStructures[entry.first].back()), "isovalues", isovalues); - ospSetObject(std::get(baseStructures[entry.first].back()), "volume", - std::get(baseStructures[entry.first].front())); - - if (this->materials[entry.first] != NULL) { - ospSetMaterial( - std::get(baseStructures[entry.first].back()), this->materials[entry.first]); - } + _baseStructures[entry.first].emplace_back(::ospray::cpp::Geometry("isosurface"), GEOMETRY); - ospCommit(std::get(baseStructures[entry.first].back())); + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam("isovalue", container.isoValue); + + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()) + .setParam( + "volume", std::get<::ospray::cpp::Volume>(_baseStructures[entry.first].structures.front())); - if (element.transformationContainer == nullptr) { - ospAddGeometry( - world, std::get(baseStructures[entry.first].back())); // Show isosurface - } else { - applyTransformation = true; - } - break; + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()).commit(); + _geometricModels[entry.first].emplace_back(::ospray::cpp::GeometricModel( + std::get<::ospray::cpp::Geometry>(_baseStructures[entry.first].structures.back()))); - case volumeRepresentationType::SLICE: - baseStructures[entry.first].push_back(ospNewGeometry("slices")); - planes = ospNewData(1, OSP_FLOAT4, element.sliceData->data()); - ospCommit(planes); - ospSetData(std::get(baseStructures[entry.first].back()), "planes", planes); - ospSetObject(std::get(baseStructures[entry.first].back()), "volume", - std::get(baseStructures[entry.first].front())); - - if (this->materials[entry.first] != NULL) { - ospSetMaterial( - std::get(baseStructures[entry.first].back()), this->materials[entry.first]); - } - - ospCommit(std::get(baseStructures[entry.first].back())); - if (element.transformationContainer == nullptr) { - ospAddGeometry(world, std::get(baseStructures[entry.first].back())); // Show slice - } else { - applyTransformation = true; + if (_materials[entry.first] != NULL) { + _geometricModels[entry.first].back().setParam( + "material", ::ospray::cpp::CopiedData(_materials[entry.first])); } + _geometricModels[entry.first].back().commit(); + _groups[entry.first] = ::ospray::cpp::Group(); + _groups[entry.first].setParam("geometry", ::ospray::cpp::CopiedData(_geometricModels[entry.first])); + if (container.clippingBoxActive) { + _groups[entry.first].setParam("clippingGeometry", ::ospray::cpp::CopiedData(_clippingModels[entry.first])); + } + _groups[entry.first].commit(); break; } - - // if (voxels != NULL) ospRelease(voxels); - // if (planes != NULL) ospRelease(planes); - // if (isovalues != NULL) ospRelease(isovalues); - + } break; } } // for element loop - if (this->rd_type.Param()->Value() == MPI_RAYCAST && ghostRegions.size() > 0 && - regions.size() > 0) { - for (auto const& el : regions) { - ghostRegions.push_back(worldBounds); + //if (this->_rd_type.Param()->Value() == MPI_RAYCAST && ghostRegions.size() > 0 && + // regions.size() > 0) { + // for (auto const& el : regions) { + // ghostRegions.push_back(_worldBounds); + // } + // auto ghostRegionData = ospNewData(2 * ghostRegions.size(), OSP_FLOAT3, ghostRegions.data()); + // auto regionData = ospNewData(2 * regions.size(), OSP_FLOAT3, ghostRegions.data()); + // ospCommit(ghostRegionData); + // ospCommit(regionData); + // ospSetData(_world, "ghostRegions", ghostRegionData); + // ospSetData(_world, "regions", ghostRegionData); + //} + + return returnValue; + } + + void AbstractOSPRayRenderer::createInstances() { + + for (auto& entry : this->_structureMap) { + + if (_instances[entry.first]) { + ospRelease(_instances[entry.first].handle()); } - auto ghostRegionData = ospNewData(2 * ghostRegions.size(), OSP_FLOAT3, ghostRegions.data()); - auto regionData = ospNewData(2 * regions.size(), OSP_FLOAT3, ghostRegions.data()); - ospCommit(ghostRegionData); - ospCommit(regionData); - ospSetData(world, "ghostRegions", ghostRegionData); - ospSetData(world, "regions", ghostRegionData); - } + _instances.erase(entry.first); - if (applyTransformation) - this->changeTransformation(); + auto const& element = entry.second; + _instances[entry.first] = ::ospray::cpp::Instance(_groups[entry.first]); + + if (element.transformationContainer) { + + auto trafo = element.transformationContainer; + ::rkcommon::math::affine3f xfm; + xfm.p.x = trafo->pos[0]; + xfm.p.y = trafo->pos[1]; + xfm.p.z = trafo->pos[2]; + xfm.l.vx.x = trafo->MX[0][0]; + xfm.l.vx.y = trafo->MX[0][1]; + xfm.l.vx.z = trafo->MX[0][2]; + xfm.l.vy.x = trafo->MX[1][0]; + xfm.l.vy.y = trafo->MX[1][1]; + xfm.l.vy.z = trafo->MX[1][2]; + xfm.l.vz.x = trafo->MX[2][0]; + xfm.l.vz.y = trafo->MX[2][1]; + xfm.l.vz.z = trafo->MX[2][2]; + + _instances[entry.first].setParam("xfm", xfm); + } - return returnValue; + _instances[entry.first].commit(); + } } void AbstractOSPRayRenderer::releaseOSPRayStuff() {} diff --git a/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.h b/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.h index f1802ae1d7..0beafd5334 100644 --- a/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.h +++ b/plugins/OSPRay_plugin/src/AbstractOSPRayRenderer.h @@ -13,14 +13,85 @@ #include "mmcore/view/CallRender3D_2.h" #include "mmcore/view/Renderer3DModule_2.h" #include "mmcore/view/light/CallLight.h" -#include "ospray/ospray.h" +#include "ospray/ospray_cpp.h" +#include "ospray/ospray_cpp/ext/rkcommon.h" #include "vislib/graphics/gl/FramebufferObject.h" #include "vislib/graphics/gl/GLSLShader.h" - namespace megamol { namespace ospray { + +template + struct second_t { + typename tPair::second_type operator()(const tPair& p) const { + return p.second; + } + }; + +template + second_t second(const tMap& m) { + return second_t(); + } + + +inline rkcommon::math::vec2f convertToVec2f(std::array inp) { + return rkcommon::math::vec2f(inp[0], inp[1]); + } + +inline rkcommon::math::vec3f convertToVec3f(std::array inp) { + return rkcommon::math::vec3f(inp[0], inp[1], inp[2]); +} + +inline rkcommon::math::vec4f convertToVec4f(std::array inp) { + return rkcommon::math::vec4f(inp[0], inp[1], inp[2], inp[3]); +} + +inline rkcommon::math::vec3f convertToVec3f(glm::vec3 inp) { + return rkcommon::math::vec3f(inp[0], inp[1], inp[2]); +} + +inline rkcommon::math::vec4f convertToVec4f(glm::vec4 inp) { + return rkcommon::math::vec4f(inp[0], inp[1], inp[2], inp[3]); +} + +inline rkcommon::math::vec3f convertToVec3f(glm::vec4 inp) { + return rkcommon::math::vec3f(inp[0], inp[1], inp[2]); +} + +struct baseStructureData { + void emplace_back(::ospray::cpp::Geometry geo, structureTypeEnum type) { + structures.emplace_back(geo); + types.emplace_back(type); + } + void emplace_back(::ospray::cpp::Volume vol, structureTypeEnum type) { + structures.emplace_back(vol); + types.emplace_back(type); + } + void emplace_back(OSPGeometry geo, structureTypeEnum type) { + structures.emplace_back(geo); + types.emplace_back(type); + } + void emplace_back(OSPVolume vol, structureTypeEnum type) { + structures.emplace_back(vol); + types.emplace_back(type); + } + void clear() { + structures.clear(); + types.clear(); + } + size_t size() { + assert(types.size() == structures.size()); + return structures.size(); + } + + + std::vector types; + std::vector> structures; +}; + + + class AbstractOSPRayRenderer : public core::view::Renderer3DModule_2 { protected: // Ctor @@ -32,7 +103,7 @@ class AbstractOSPRayRenderer : public core::view::Renderer3DModule_2 { /** * initializes OSPRay */ - void initOSPRay(OSPDevice& dvce); + void initOSPRay(); /** * helper function for rendering the OSPRay texture @@ -68,14 +139,14 @@ class AbstractOSPRayRenderer : public core::view::Renderer3DModule_2 { * @param volume name/type * @param renderer type */ - void setupOSPRay(OSPRenderer& renderer, OSPCamera& camera, OSPModel& world, const char* renderer_name); + void setupOSPRay(const char* renderer_name); /** * helper function for initializing OSPRays Camera * @param OSPRay camera object * @param CallRenderer3D object */ - void setupOSPRayCamera(OSPCamera& ospcam, megamol::core::view::Camera_2& mmcam); + void setupOSPRayCamera(megamol::core::view::Camera_2& mmcam); /** @@ -83,28 +154,29 @@ class AbstractOSPRayRenderer : public core::view::Renderer3DModule_2 { * @param file path * @return 2 */ - OSPTexture2D TextureFromFile(vislib::TString fileName); + ::ospray::cpp::Texture TextureFromFile(vislib::TString fileName); // helper function to write the rendered image as PPM file - void writePPM(const char* fileName, const osp::vec2i& size, const uint32_t* pixel); + void writePPM(std::string fileName, const std::array& size, const uint32_t* pixel); + void fillMaterialContainer(CallOSPRayStructure* entry_first, const OSPRayStructureContainer& element); // TODO: Documentation bool AbstractIsDirty(); void AbstractResetDirty(); - void RendererSettings(OSPRenderer& renderer); - OSPFrameBuffer newFrameBuffer(osp::vec2i& imgSize, const OSPFrameBufferFormat format = OSP_FB_RGBA8, - const uint32_t frameBufferChannels = OSP_FB_COLOR); + void RendererSettings(glm::vec4 bg_color); // vertex array, vertex buffer object, texture - GLuint vaScreen, vbo, tex, depth; - vislib::graphics::gl::FramebufferObject new_fbo; + unsigned int _vaScreen, _vbo, _tex, _depth; + vislib::graphics::gl::FramebufferObject _new_fbo; /** * Reads the structure map and uses its parameteres to * create geometries and volumes. * */ - bool fillWorld(); + bool generateRepresentations(); + + void createInstances(); void changeMaterial(); @@ -117,27 +189,25 @@ class AbstractOSPRayRenderer : public core::view::Renderer3DModule_2 { void releaseOSPRayStuff(); // Call slots - megamol::core::CallerSlot lightSlot; + megamol::core::CallerSlot _lightSlot; // Interface Variables - core::param::ParamSlot AOtransparencyEnabled; - core::param::ParamSlot AOsamples; - core::param::ParamSlot AOdistance; - core::param::ParamSlot accumulateSlot; - - core::param::ParamSlot rd_epsilon; - core::param::ParamSlot rd_spp; - core::param::ParamSlot rd_maxRecursion; - core::param::ParamSlot rd_type; - core::param::ParamSlot rd_ptBackground; - core::param::ParamSlot shadows; - core::param::ParamSlot useDB; - core::param::ParamSlot numThreads; + core::param::ParamSlot _AOsamples; + core::param::ParamSlot _AOdistance; + core::param::ParamSlot _accumulateSlot; + + core::param::ParamSlot _rd_spp; + core::param::ParamSlot _rd_maxRecursion; + core::param::ParamSlot _rd_type; + core::param::ParamSlot _rd_ptBackground; + core::param::ParamSlot _shadows; + core::param::ParamSlot _useDB; + core::param::ParamSlot _numThreads; // Fix for deprecated material (ospNewMaterial2 now) - std::string rd_type_string; + std::string _rd_type_string; - megamol::core::param::ParamSlot deviceTypeSlot; + megamol::core::param::ParamSlot _deviceTypeSlot; // device type enum deviceType { DEFAULT, MPI_DISTRIBUTED }; @@ -146,38 +216,39 @@ class AbstractOSPRayRenderer : public core::view::Renderer3DModule_2 { enum rdenum { SCIVIS, PATHTRACER, MPI_RAYCAST }; // light - std::vector lightArray; - OSPData lightsToRender; - - // framebuffer dirtyness - bool framebufferIsDirty; + std::vector<::ospray::cpp::Light> _lightArray; // OSP objects - OSPFrameBuffer framebuffer; - OSPCamera camera; - OSPModel world; + std::shared_ptr<::ospray::cpp::FrameBuffer> _framebuffer; + std::shared_ptr<::ospray::cpp::Camera> _camera; + std::shared_ptr<::ospray::cpp::World> _world; // device - OSPDevice device; + std::shared_ptr<::ospray::cpp::Device> _device; // renderer - OSPRenderer renderer; - OSPTexture2D maxDepthTexture; + std::shared_ptr<::ospray::cpp::Renderer> _renderer; + ::ospray::cpp::Texture _maxDepthTexture; // structure vectors - std::map>> baseStructures; - std::map instancedModels; - std::map instances; - std::map materials; + std::map + _baseStructures; + std::map> _volumetricModels; + std::map> _geometricModels; + std::map> _clippingModels; + + std::map _groups; + std::map _instances; + std::map _materials; // Structure map - OSPRayStrcutrureMap structureMap; + OSPRayStrcutrureMap _structureMap; // extend map - OSPRayExtendMap extendMap; + OSPRayExtendMap _extendMap; - void fillLightArray(glm::vec4& eyeDir); + void fillLightArray(std::array eyeDir); - long long int ispcLimit = 1ULL << 30; - long long int numCreateGeo; + long long int _ispcLimit = 1ULL << 30; + long long int _numCreateGeo; }; } // end namespace ospray diff --git a/plugins/OSPRay_plugin/src/CallOSPRayStructure.cpp b/plugins/OSPRay_plugin/src/CallOSPRayStructure.cpp index f32cf88fc0..75ab76c583 100644 --- a/plugins/OSPRay_plugin/src/CallOSPRayStructure.cpp +++ b/plugins/OSPRay_plugin/src/CallOSPRayStructure.cpp @@ -12,41 +12,6 @@ using namespace megamol::ospray; -OSPRayStructureContainer::OSPRayStructureContainer() : - isValid(false), - vertexData(NULL), - colorData(NULL), - indexData(NULL), - voxels(NULL), - gridOrigin(NULL), - gridSpacing(NULL), - dimensions(NULL), - clippingBoxLower(NULL), - clippingBoxUpper(NULL), - isoValue(NULL), - sliceData(NULL), - clipPlaneData(NULL), - clipPlaneColor(NULL), - raw(NULL), - mmpldColor(core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_NONE), - xData(NULL), - yData(NULL), - zData(NULL), - type(structureTypeEnum::UNINITIALIZED) { } - -OSPRayStructureContainer::~OSPRayStructureContainer() { - // -} - -OSPRayExtendContainer::OSPRayExtendContainer() : - isValid(false) { -} - -OSPRayExtendContainer::~OSPRayExtendContainer() { - // -} - - // ################################# // ###### CallOSPRayStructure ###### // ################################# diff --git a/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.cpp b/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.cpp index bf9ccd0248..53b7499f68 100644 --- a/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.cpp @@ -13,8 +13,9 @@ #include "mmcore/moldyn/MultiParticleDataCall.h" #include "mmcore/param/FloatParam.h" #include "mmcore/param/IntParam.h" -#include "ospray/ospray.h" +#include "ospray/ospray_cpp.h" #include "mmcore/utility/log/Log.h" +#include "ospray/ospray_cpp/ext/rkcommon.h" using namespace megamol::ospray; @@ -124,8 +125,9 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { } } - OSPVolume aovol = NULL; - std::vector geo; + ::ospray::cpp::Volume aovol = NULL; + ::ospray::cpp::VolumetricModel aovol_model; + std::vector<::ospray::cpp::Geometry> geo; if (!volDataOK) { megamol::core::utility::log::Log::DefaultLog.WriteError( "OSPRayAOVSphereGeometry: connected module supplies no volume data, ignore subsequent errors\n"); @@ -182,7 +184,7 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { colorLength = 0; } - int vertStride = parts.GetVertexDataStride(); + unsigned long long vertStride = parts.GetVertexDataStride(); if (vertStride == 0) { vertStride = core::moldyn::MultiParticleDataCall::Particles::VertexDataSize[parts.GetVertexDataType()]; } @@ -220,7 +222,7 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { } float const minV = metadata->MinValues[0]; float const maxV = metadata->MaxValues[0]; - this->valuerange = std::make_pair(minV, maxV); + this->valuerange = {minV, maxV}; this->gridorigin = {metadata->Origin[0], metadata->Origin[1], metadata->Origin[2]}; this->gridspacing = {metadata->SliceDists[0][0], metadata->SliceDists[1][0], metadata->SliceDists[2][0]}; this->dimensions = {static_cast(metadata->Resolution[0]), static_cast(metadata->Resolution[1]), @@ -236,39 +238,37 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { for (unsigned int i = 0; i < numCreateGeo; i++) { if (parts.GetCount() == 0) continue; - geo.emplace_back(ospNewGeometry("aovspheres_geometry")); - long long int floatsToRead = parts.GetCount() * vertStride / (numCreateGeo * sizeof(float)); + geo.emplace_back(::ospray::cpp::Geometry("aovspheres_geometry")); + unsigned long long floatsToRead = parts.GetCount() * vertStride / (numCreateGeo * sizeof(float)); floatsToRead -= floatsToRead % (vertStride / sizeof(float)); - auto vertexData = ospNewData(floatsToRead / 3, OSP_FLOAT3, - &static_cast(parts.GetVertexData())[i * floatsToRead], OSP_DATA_SHARED_BUFFER); + auto vertexData = ::ospray::cpp::SharedData( + &static_cast(parts.GetVertexData())[i * floatsToRead], + OSP_FLOAT, floatsToRead / 3, vertStride); - ospCommit(vertexData); - ospSet1i(geo.back(), "bytes_per_sphere", vertStride); - ospSetData(geo.back(), "spheres", vertexData); - ospSetData(geo.back(), "color", nullptr); + vertexData.commit(); + geo.back().setParam("spheres", vertexData); + geo.back().setParam("color", NULL); if (vertexLength > 3) { - ospSet1f(geo.back(), "offset_radius", 3 * sizeof(float)); + geo.back().setParam("offset_radius", 3 * sizeof(float)); } else { - ospSet1f(geo.back(), "radius", globalRadius); + geo.back().setParam("radius", globalRadius); } if (parts.GetColourDataType() == core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGB || parts.GetColourDataType() == core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGBA) { - ospSet1i(geo.back(), "color_offset", + geo.back().setParam("color_offset", vertexLength * sizeof(float)); // TODO: This won't work if there are radii in the array - ospSet1i(geo.back(), "color_stride", parts.GetColourDataStride()); - ospSetData(geo.back(), "color", vertexData); + geo.back().setParam("color_stride", parts.GetColourDataStride()); + geo.back().setParam("color", vertexData); if (parts.GetColourDataType() == core::moldyn::SimpleSphericalParticles::ColourDataType::COLDATA_FLOAT_RGB) { - // ospSet1i(geo.back(), "color_components", 3); - ospSet1i(geo.back(), "color_format", OSP_FLOAT3); + geo.back().setParam("color_format", OSP_VEC3F); } else { - // ospSet1i(geo.back(), "color_components", 4); - ospSet1i(geo.back(), "color_format", OSP_FLOAT4); + geo.back().setParam("color_format", OSP_VEC4F); } } @@ -282,18 +282,29 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { // aovol // auto const aovol = ospNewVolume("block_bricked_volume"); if (aovol == NULL) { - aovol = ospNewVolume("shared_structured_volume"); - ospSet2f(aovol, "voxelRange", this->valuerange.first, this->valuerange.second); - ospSet1f(aovol, "samplingRate", this->samplingRateSlot.Param()->Value()); - // ospSet1b(aovol, "adaptiveSampling", false); - ospSet3iv(aovol, "dimensions", this->dimensions.data()); - ospSetString( - aovol, "voxelType", voxelDataTypeS[static_cast(voxelDataType::FLOAT)].c_str()); - ospSet3fv(aovol, "gridOrigin", this->gridorigin.data()); - ospSet3fv(aovol, "gridSpacing", this->gridspacing.data()); + aovol = ::ospray::cpp::Volume("shared_structured_volume"); + + + // add data + rkcommon::math::vec3i dims = { + this->dimensions[0], + this->dimensions[1], + this->dimensions[2]}; + auto voxelData = ::ospray::cpp::SharedData(vd->GetData(), OSP_FLOAT, dims, rkcommon::math::vec3i(0)); + voxelData.commit(); + + + aovol.setParam("data", voxelData); + + rkcommon::math::vec3f gorigin = { + this->gridorigin[0], this->gridorigin[1], this->gridorigin[2]}; + aovol.setParam("gridOrigin", gorigin); + rkcommon::math::vec3f gspacing = {this->gridspacing[0], this->gridspacing[1], this->gridspacing[2]}; + aovol.setParam("gridSpacing", gspacing); - OSPTransferFunction tf = ospNewTransferFunction("piecewise_linear"); + + auto tf = ::ospray::cpp::TransferFunction("piecewiseLinear"); std::vector faketf = { 1.0f, @@ -305,41 +316,44 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { }; std::vector fakeopa = {1.0f, 1.0f}; - OSPData tf_rgb = ospNewData(2, OSP_FLOAT3, faketf.data()); - OSPData tf_opa = ospNewData(2, OSP_FLOAT, fakeopa.data()); - ospSetData(tf, "colors", tf_rgb); - ospSetData(tf, "opacities", tf_opa); - ospSet2f(tf, "valueRange", 0.0f, 1.0f); + auto tf_rgb = ::ospray::cpp::CopiedData(faketf.data(), OSP_FLOAT, faketf.size() / 3); + auto tf_opa = ::ospray::cpp::CopiedData(fakeopa); + tf.setParam("color", tf_rgb); + tf.setParam("opacity", tf_opa); + rkcommon::math::vec2f valrange = { + this->valuerange[0], this->valuerange[1]}; + tf.setParam("valueRange", valrange); - ospCommit(tf); + tf.commit(); + + aovol.commit(); + + aovol_model = ::ospray::cpp::VolumetricModel(aovol); + + aovol_model.setParam("transferFunction", tf); + aovol_model.commit(); + + + //aovol, "voxelRange", this->valuerange.first, this->valuerange.second); + //ospSet1f(aovol, "samplingRate", this->samplingRateSlot.Param()->Value()); + // ospSet1b(aovol, "adaptiveSampling", false); - ospSetObject(aovol, "transferFunction", tf); - ospRelease(tf); - // add data - auto voxelcount = this->dimensions[0] * this->dimensions[1] * this->dimensions[2]; - auto voxels = ospNewData(voxelcount, - static_cast(voxelDataTypeOSP[static_cast(voxelDataType::FLOAT)]), - vd->GetData(), OSP_DATA_SHARED_BUFFER); - ospCommit(voxels); - ospSetData(aovol, "voxelData", voxels); /*auto ptr = element.raw2.get(); ospSetRegion(aovol, ptr, osp::vec3i{0, 0, 0}, osp::vec3i{(*element.dimensions)[0], (*element.dimensions)[1], (*element.dimensions)[2]});*/ - ospCommit(aovol); - - // ospStructures.push_back(std::make_pair(aovol, structureTypeEnum::VOLUME)); + /*ospStructures.push_back(std::make_pair(aovol, structureTypeEnum::VOLUME));*/ } assert(aovol); - ospSet1f(geo.back(), "aothreshold", + geo.back().setParam("aothreshold", valRange * this->aoThresholdSlot.Param()->Value()); - ospSet1f(geo.back(), "aoRayOffset", + geo.back().setParam("aoRayOffset", maxGridSpacing * this->aoRayOffsetFactorSlot.Param()->Value()); - ospSetObject(geo.back(), "aovol", aovol); + geo.back().setParam("aovol", ::ospray::cpp::CopiedData(aovol_model)); // ospCommit(geo); } // geometries } // particle lists @@ -347,7 +361,7 @@ bool OSPRayAOVSphereGeometry::getDataCallback(megamol::core::Call& call) { std::vector geo_transfer(geo.size()); for (auto i = 0; i < geo.size(); i++) { - geo_transfer[i] = reinterpret_cast(geo[i]); + geo_transfer[i] = geo[i].handle(); } os->setStructureType(GEOMETRY); os->setAPIObjects(std::move(geo_transfer)); diff --git a/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.h b/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.h index 78578d784d..9a7db01ca9 100644 --- a/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.h +++ b/plugins/OSPRay_plugin/src/OSPRayAOVSphereGeometry.h @@ -92,16 +92,16 @@ class OSPRayAOVSphereGeometry : public core::Module { size_t time; - std::pair valuerange; + std::array valuerange; - std::vector gridorigin; + std::array gridorigin; - std::vector gridspacing; + std::array gridspacing; - std::vector dimensions; + std::array dimensions; long long int ispcLimit = 1ULL << 30; }; } // namespace ospray -} // namespace megamol \ No newline at end of file +} // namespace megamol diff --git a/plugins/OSPRay_plugin/src/OSPRayAPIStructure.cpp b/plugins/OSPRay_plugin/src/OSPRayAPIStructure.cpp index 0c6ec1a281..6ec295e835 100644 --- a/plugins/OSPRay_plugin/src/OSPRayAPIStructure.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayAPIStructure.cpp @@ -55,18 +55,21 @@ bool OSPRayAPIStructure::readData(megamol::core::Call &call) { // Write stuff into the structureContainer this->structureContainer.type = structureTypeEnum::OSPRAY_API_STRUCTURES; - + apiStructure apis; switch (cd->getStructureType()) { case structureTypeEnum::GEOMETRY: - this->structureContainer.ospStructures = std::make_pair, structureTypeEnum>(cd->getAPIObjects(), structureTypeEnum::GEOMETRY); + apis.ospStructures = + std::make_pair, structureTypeEnum>(cd->getAPIObjects(), structureTypeEnum::GEOMETRY); break; case structureTypeEnum::VOLUME: - this->structureContainer.ospStructures = std::make_pair, structureTypeEnum>(cd->getAPIObjects(), structureTypeEnum::VOLUME); + apis.ospStructures = + std::make_pair, structureTypeEnum>(cd->getAPIObjects(), structureTypeEnum::VOLUME); break; case structureTypeEnum::UNINITIALIZED: megamol::core::utility::log::Log::DefaultLog.WriteError("OSPRay API structure type is not set."); return false; } + structureContainer.structure = apis; return true; } @@ -111,4 +114,4 @@ bool OSPRayAPIStructure::getExtends(megamol::core::Call &call) { this->extendContainer.isValid = true; return true; -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayCylinderGeometry.cpp b/plugins/OSPRay_plugin/src/OSPRayCylinderGeometry.cpp deleted file mode 100644 index 95bb030d93..0000000000 --- a/plugins/OSPRay_plugin/src/OSPRayCylinderGeometry.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* -* OSPRayCylinderGeometry.cpp -* Copyright (C) 2009-2017 by MegaMol Team -* Alle Rechte vorbehalten. -*/ - -#include "stdafx.h" -#include "OSPRayCylinderGeometry.h" -#include "vislib/forceinline.h" -#include "mmcore/moldyn/MultiParticleDataCall.h" -#include "mmcore/param/FloatParam.h" -#include "mmcore/param/IntParam.h" -#include "mmcore/param/Vector3fParam.h" -#include "mmcore/param/EnumParam.h" -#include "mmcore/utility/log/Log.h" -#include "mmcore/Call.h" - -#include "mmcore/view/CallGetTransferFunction.h" -#include "mmcore/view/CallClipPlane.h" - -using namespace megamol::ospray; - - -typedef float(*floatFromArrayFunc)(const megamol::core::moldyn::MultiParticleDataCall::Particles& p, size_t index); -typedef unsigned char(*byteFromArrayFunc)(const megamol::core::moldyn::MultiParticleDataCall::Particles& p, size_t index); - - -OSPRayCylinderGeometry::OSPRayCylinderGeometry(void) : - AbstractOSPRayStructure(), - getDataSlot("getdata", "Connects to the data source"), - - particleList("ParticleList", "Switches between particle lists") -{ - - this->getDataSlot.SetCompatibleCall(); - this->MakeSlotAvailable(&this->getDataSlot); - - this->particleList << new core::param::IntParam(0); - this->MakeSlotAvailable(&this->particleList); -} - - -bool OSPRayCylinderGeometry::readData(megamol::core::Call &call) { - - // fill material container - this->processMaterial(); - - // get transformation parameter - this->processTransformation(); - - // read Data, calculate shape parameters, fill data vectors - CallOSPRayStructure *os = dynamic_cast(&call); - megamol::core::moldyn::MultiParticleDataCall *cd = this->getDataSlot.CallAs(); - - this->structureContainer.dataChanged = false; - if (cd == NULL) return false; - cd->SetTimeStamp(os->getTime()); - cd->SetFrameID(os->getTime(), true); // isTimeForced flag set to true - if (this->datahash != cd->DataHash() || this->time != os->getTime() || this->InterfaceIsDirty()) { - this->datahash = cd->DataHash(); - this->time = os->getTime(); - this->structureContainer.dataChanged = true; - } else { - return true; - } - - if (!(*cd)(1)) return false; - if (!(*cd)(0)) return false; - if (cd->GetParticleListCount() == 0) return false; - - if (this->particleList.Param()->Value() > (cd->GetParticleListCount() - 1)) { - this->particleList.Param()->SetValue(0); - } - - core::moldyn::MultiParticleDataCall::Particles &parts = cd->AccessParticles(this->particleList.Param()->Value()); - - unsigned int partCount = parts.GetCount(); - float globalRadius = parts.GetGlobalRadius(); - - size_t vertexLength; - size_t colorLength; - - // Vertex data type check - if (parts.GetVertexDataType() == core::moldyn::MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZ) { - vertexLength = 3; - } else if (parts.GetVertexDataType() == core::moldyn::MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZR) { - vertexLength = 4; - } - - // Color data type check - if (parts.GetColourDataType() == core::moldyn::MultiParticleDataCall::Particles::COLDATA_FLOAT_RGBA) { - colorLength = 4; - } else if (parts.GetColourDataType() == core::moldyn::MultiParticleDataCall::Particles::COLDATA_FLOAT_I) { - colorLength = 1; - } else if (parts.GetColourDataType() == core::moldyn::MultiParticleDataCall::Particles::COLDATA_FLOAT_RGB) { - colorLength = 3; - } else if (parts.GetColourDataType() == core::moldyn::MultiParticleDataCall::Particles::COLDATA_UINT8_RGBA) { - colorLength = 4; - } else if (parts.GetColourDataType() == core::moldyn::MultiParticleDataCall::Particles::COLDATA_NONE) { - colorLength = 0; - } - - int vstride = parts.GetVertexDataStride(); - if (parts.GetVertexDataStride() == 0) { - vstride = core::moldyn::MultiParticleDataCall::Particles::VertexDataSize[parts.GetVertexDataType()]; - } - - if (parts.GetVertexDataType() == core::moldyn::MultiParticleDataCall::Particles::VERTDATA_NONE && - parts.GetColourDataType() != core::moldyn::MultiParticleDataCall::Particles::COLDATA_NONE) { - megamol::core::utility::log::Log::DefaultLog.WriteError("Only color data is not allowed."); - } - - // Write stuff into the structureContainer - this->structureContainer.type = structureTypeEnum::GEOMETRY; - this->structureContainer.geometryType = geometryTypeEnum::CYLINDERS; - this->structureContainer.raw = parts.GetVertexData(); - this->structureContainer.vertexLength = vertexLength; - this->structureContainer.vertexStride = vstride; - this->structureContainer.colorLength = colorLength; - this->structureContainer.colorStride = parts.GetColourDataStride(); - this->structureContainer.partCount = partCount; - this->structureContainer.globalRadius = globalRadius; - this->structureContainer.mmpldColor = parts.GetColourDataType(); - - return true; -} - - -OSPRayCylinderGeometry::~OSPRayCylinderGeometry() { - this->Release(); -} - -bool OSPRayCylinderGeometry::create() { - return true; -} - -void OSPRayCylinderGeometry::release() { - -} - -/* -ospray::OSPRayCylinderGeometry::InterfaceIsDirty() -*/ -bool OSPRayCylinderGeometry::InterfaceIsDirty() { - if ( - this->particleList.IsDirty() - ) { - this->particleList.ResetDirty(); - return true; - } else { - return false; - } -} - - -bool OSPRayCylinderGeometry::getExtends(megamol::core::Call &call) { - CallOSPRayStructure *os = dynamic_cast(&call); - megamol::core::moldyn::MultiParticleDataCall *cd = this->getDataSlot.CallAs(); - - if (cd == NULL) return false; - cd->SetFrameID(os->getTime(), true); // isTimeForced flag set to true - // if (!(*cd)(1)) return false; // table returns flase at first attempt and breaks everything - (*cd)(1); - this->extendContainer.boundingBox = std::make_shared(); - this->extendContainer.boundingBox->SetBoundingBox(cd->AccessBoundingBoxes().ObjectSpaceBBox()); - this->extendContainer.timeFramesCount = cd->FrameCount(); - this->extendContainer.isValid = true; - - return true; -} \ No newline at end of file diff --git a/plugins/OSPRay_plugin/src/OSPRayGeometryTest.cpp b/plugins/OSPRay_plugin/src/OSPRayGeometryTest.cpp new file mode 100644 index 0000000000..939f0d6d96 --- /dev/null +++ b/plugins/OSPRay_plugin/src/OSPRayGeometryTest.cpp @@ -0,0 +1,71 @@ +/* +* OSPRayGeometryTest.cpp +* Copyright (C) 2009-2017 by MegaMol Team +* Alle Rechte vorbehalten. +*/ + +#include "stdafx.h" +#include "OSPRayGeometryTest.h" +#include "mmcore/utility/log/Log.h" +#include "mmcore/Call.h" + +using namespace megamol::ospray; + + +typedef float(*floatFromArrayFunc)(const megamol::core::moldyn::MultiParticleDataCall::Particles& p, size_t index); +typedef unsigned char(*byteFromArrayFunc)(const megamol::core::moldyn::MultiParticleDataCall::Particles& p, size_t index); + + +OSPRayGeometryTest::OSPRayGeometryTest(void) : AbstractOSPRayStructure() {} + + +bool OSPRayGeometryTest::readData(megamol::core::Call &call) { + + // fill material container + this->processMaterial(); + + // get transformation parameter + this->processTransformation(); + + // read Data, calculate shape parameters, fill data vectors + + this->structureContainer.dataChanged = true; + + + this->structureContainer.type = structureTypeEnum::GEOMETRY; + this->structureContainer.geometryType = geometryTypeEnum::TEST; + + return true; +} + + +OSPRayGeometryTest::~OSPRayGeometryTest() { + this->Release(); +} + +bool OSPRayGeometryTest::create() { + return true; +} + +void OSPRayGeometryTest::release() { + +} + +/* +ospray::OSPRayGeometryTest::InterfaceIsDirty() +*/ +bool OSPRayGeometryTest::InterfaceIsDirty() { + return false; +} + + +bool OSPRayGeometryTest::getExtends(megamol::core::Call &call) { + CallOSPRayStructure *os = dynamic_cast(&call); + + this->extendContainer.boundingBox = std::make_shared(); + this->extendContainer.boundingBox->SetBoundingBox(-1,-1,1,1,1,-1); + this->extendContainer.timeFramesCount = 1; + this->extendContainer.isValid = true; + + return true; +} diff --git a/plugins/OSPRay_plugin/src/OSPRayCylinderGeometry.h b/plugins/OSPRay_plugin/src/OSPRayGeometryTest.h similarity index 75% rename from plugins/OSPRay_plugin/src/OSPRayCylinderGeometry.h rename to plugins/OSPRay_plugin/src/OSPRayGeometryTest.h index 9290a27bd6..dba2629d29 100644 --- a/plugins/OSPRay_plugin/src/OSPRayCylinderGeometry.h +++ b/plugins/OSPRay_plugin/src/OSPRayGeometryTest.h @@ -1,5 +1,5 @@ /* -* OSPRayCylinderGeometry.h +* OSPRayGeometryTest.h * Copyright (C) 2009-2017 by MegaMol Team * Alle Rechte vorbehalten. */ @@ -12,7 +12,7 @@ namespace megamol { namespace ospray { -class OSPRayCylinderGeometry : public AbstractOSPRayStructure { +class OSPRayGeometryTest : public AbstractOSPRayStructure { public: @@ -22,7 +22,7 @@ class OSPRayCylinderGeometry : public AbstractOSPRayStructure { * @return The name of this module. */ static const char *ClassName(void) { - return "OSPRayCylinderGeometry"; + return "OSPRayGeometryTest"; } /** @@ -31,7 +31,7 @@ class OSPRayCylinderGeometry : public AbstractOSPRayStructure { * @return A human readable description of this module. */ static const char *Description(void) { - return "Creator for OSPRay cylinder geometries."; + return "Creator for OSPRay no overhead sphere geometries."; } /** @@ -44,10 +44,10 @@ class OSPRayCylinderGeometry : public AbstractOSPRayStructure { } /** Dtor. */ - virtual ~OSPRayCylinderGeometry(void); + virtual ~OSPRayGeometryTest(void); /** Ctor. */ - OSPRayCylinderGeometry(void); + OSPRayGeometryTest(void); protected: /** @@ -68,19 +68,7 @@ class OSPRayCylinderGeometry : public AbstractOSPRayStructure { bool InterfaceIsDirty(); - core::param::ParamSlot particleList; - - /** The call for data */ - core::CallerSlot getDataSlot; - -private: - - - // color transfer data - unsigned int tex_size; - - }; } // namespace ospray -} // namespace megamol \ No newline at end of file +} // namespace megamol diff --git a/plugins/OSPRay_plugin/src/OSPRayGlassMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayGlassMaterial.cpp index 635d78fbf2..7b840187e9 100644 --- a/plugins/OSPRay_plugin/src/OSPRayGlassMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayGlassMaterial.cpp @@ -40,17 +40,18 @@ OSPRayGlassMaterial::~OSPRayGlassMaterial(void) { void OSPRayGlassMaterial::readParams() { materialContainer.materialType = materialTypeEnum::GLASS; + glassMaterial gm; auto colori = this->glassAttenuationColorInside.Param(); - materialContainer.glassAttenuationColorInside = colori->getArray(); - + gm.glassAttenuationColorInside = colori->getArray(); auto coloro = this->glassAttenuationColorOutside.Param(); - materialContainer.glassAttenuationColorOutside = coloro->getArray(); - - materialContainer.glassEtaInside = this->glassEtaInside.Param()->Value(); + gm.glassAttenuationColorOutside = coloro->getArray(); + gm.glassEtaInside = this->glassEtaInside.Param()->Value(); + gm.glassEtaOutside = + this->glassEtaOutside.Param()->Value(); + gm.glassAttenuationDistance = + this->glassAttenuationDistance.Param()->Value(); - materialContainer.glassEtaOutside = this->glassEtaOutside.Param()->Value(); - - materialContainer.glassAttenuationDistance = this->glassAttenuationDistance.Param()->Value(); + materialContainer.material = gm; } bool OSPRayGlassMaterial::InterfaceIsDirty() { @@ -70,4 +71,4 @@ bool OSPRayGlassMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayLineGeometry.cpp b/plugins/OSPRay_plugin/src/OSPRayLineGeometry.cpp index 2f09f115b8..408ed14083 100644 --- a/plugins/OSPRay_plugin/src/OSPRayLineGeometry.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayLineGeometry.cpp @@ -51,7 +51,7 @@ bool OSPRayLineGeometry::readData(core::Call& call) { CallOSPRayStructure* os = dynamic_cast(&call); mesh::CallMesh* cm = this->getLineDataSlot.CallAs(); - + curveStructure cs; if (cm != nullptr) { auto meta_data = cm->getMetaData(); this->structureContainer.dataChanged = false; @@ -64,12 +64,13 @@ bool OSPRayLineGeometry::readData(core::Call& call) { if (!(*cm)(1)) return false; if (!(*cm)(0)) return false; meta_data = cm->getMetaData(); - - if (cm->hasUpdate() || this->time != os->getTime() || this->InterfaceIsDirty()) { + auto interface_dirty = this->InterfaceIsDirty(); + if (cm->hasUpdate() || this->time != os->getTime() || interface_dirty) { this->time = os->getTime(); this->structureContainer.dataChanged = true; this->extendContainer.boundingBox = std::make_shared(meta_data.m_bboxs); - this->structureContainer.mesh = cm->getData(); + cs.mesh = cm->getData(); + structureContainer.structure = cs; } } else { @@ -79,7 +80,12 @@ bool OSPRayLineGeometry::readData(core::Call& call) { if (cd == NULL) return false; cd->SetTime(os->getTime()); cd->SetFrameID(os->getTime(), true); // isTimeForced flag set to true - if (this->datahash != cd->DataHash() || this->time != os->getTime() || this->InterfaceIsDirty()) { + auto interface_dirty = this->InterfaceIsDirty(); + + if (!(*cd)(1)) return false; + if (!(*cd)(0)) return false; + + if (this->datahash != cd->DataHash() || this->time != os->getTime() || interface_dirty) { this->datahash = cd->DataHash(); this->time = os->getTime(); this->structureContainer.dataChanged = true; @@ -87,8 +93,7 @@ bool OSPRayLineGeometry::readData(core::Call& call) { return true; } - if (!(*cd)(1)) return false; - if (!(*cd)(0)) return false; + unsigned int lineCount = cd->Count(); @@ -149,17 +154,17 @@ bool OSPRayLineGeometry::readData(core::Call& call) { // Write stuff into the structureContainer - this->structureContainer.vertexData = std::make_shared>(std::move(vd)); - this->structureContainer.colorData = std::make_shared>(std::move(cd_rgba)); - this->structureContainer.vertexLength = 3; - this->structureContainer.colorLength = 4; - this->structureContainer.indexData = std::make_shared>(std::move(index)); + cs.vertexData = std::make_shared>(std::move(vd)); + cs.colorData = std::make_shared>(std::move(cd_rgba)); + cs.vertexLength = 3; + cs.colorLength = 4; + cs.indexData = std::make_shared>(std::move(index)); } this->structureContainer.type = structureTypeEnum::GEOMETRY; - this->structureContainer.geometryType = geometryTypeEnum::STREAMLINES; - this->structureContainer.globalRadius = globalRadiusSlot.Param()->Value(); - this->structureContainer.smooth = smoothSlot.Param()->Value(); + this->structureContainer.geometryType = geometryTypeEnum::LINES; + cs.globalRadius = globalRadiusSlot.Param()->Value(); + structureContainer.structure = cs; return true; } @@ -219,4 +224,4 @@ bool OSPRayLineGeometry::getExtends(core::Call& call) { } return true; -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayLuminousMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayLuminousMaterial.cpp index c9ef1f563b..769a679b61 100644 --- a/plugins/OSPRay_plugin/src/OSPRayLuminousMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayLuminousMaterial.cpp @@ -35,12 +35,15 @@ OSPRayLuminousMaterial::~OSPRayLuminousMaterial(void) { void OSPRayLuminousMaterial::readParams() { materialContainer.materialType = materialTypeEnum::LUMINOUS; + luminousMaterial lm; auto lumcolor = this->lumColor.Param(); - materialContainer.lumColor = lumcolor->getArray(); + lm.lumColor = lumcolor->getArray(); + lm.lumIntensity = + this->lumIntensity.Param()->Value(); + lm.lumTransparency = + this->lumTransparency.Param()->Value(); - materialContainer.lumIntensity = this->lumIntensity.Param()->Value(); - - materialContainer.lumTransparency = this->lumTransparency.Param()->Value(); + materialContainer.material = lm; } bool OSPRayLuminousMaterial::InterfaceIsDirty() { @@ -56,4 +59,4 @@ bool OSPRayLuminousMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayMatteMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayMatteMaterial.cpp index 40d48c96e4..e7466f47a7 100644 --- a/plugins/OSPRay_plugin/src/OSPRayMatteMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayMatteMaterial.cpp @@ -28,8 +28,12 @@ OSPRayMatteMaterial::~OSPRayMatteMaterial(void) { void OSPRayMatteMaterial::readParams() { materialContainer.materialType = materialTypeEnum::MATTE; + matteMaterial mm; + auto reflect = this->matteReflectance.Param(); - materialContainer.matteReflectance = reflect->getArray(); + mm.matteReflectance = reflect->getArray(); + + materialContainer.material = mm; } bool OSPRayMatteMaterial::InterfaceIsDirty() { @@ -41,4 +45,4 @@ bool OSPRayMatteMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayTriangleMesh.cpp b/plugins/OSPRay_plugin/src/OSPRayMeshGeometry.cpp similarity index 91% rename from plugins/OSPRay_plugin/src/OSPRayTriangleMesh.cpp rename to plugins/OSPRay_plugin/src/OSPRayMeshGeometry.cpp index e91105d348..c1856c3878 100644 --- a/plugins/OSPRay_plugin/src/OSPRayTriangleMesh.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayMeshGeometry.cpp @@ -1,11 +1,11 @@ /* - * OSPRayTriangleMesh.cpp + * OSPRayMeshGeometry.cpp * Copyright (C) 2009-2017 by MegaMol Team * Alle Rechte vorbehalten. */ #include "stdafx.h" -#include "OSPRayTriangleMesh.h" +#include "OSPRayMeshGeometry.h" #include #include "geometry_calls/CallTriMeshData.h" #include "mmcore/BoundingBoxes_2.h" @@ -20,7 +20,7 @@ using namespace megamol::ospray; -OSPRayTriangleMesh::OSPRayTriangleMesh(void) +OSPRayMeshGeometry::OSPRayMeshGeometry(void) : AbstractOSPRayStructure() , getTrimeshDataSlot("getTrimeshData", "Connects to the data source") , getMeshDataSlot("getMeshData", "Connects to the data source") { @@ -33,7 +33,7 @@ OSPRayTriangleMesh::OSPRayTriangleMesh(void) } -bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { +bool OSPRayMeshGeometry::readData(megamol::core::Call& call) { // fill material container this->processMaterial(); @@ -66,7 +66,7 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { this->extendContainer.boundingBox = std::make_shared(meta_data.m_bboxs); this->extendContainer.timeFramesCount = meta_data.m_frame_cnt; this->extendContainer.isValid = true; - this->structureContainer.mesh = cm->getData(); + std::get(this->structureContainer.structure).mesh = cm->getData(); } } else { @@ -94,7 +94,9 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { if (!(*cd)(0)) return false; - this->structureContainer.mesh = std::make_shared(); + meshStrucutre ms; + ms.mesh = std::make_shared(); + unsigned int triangleCount = 0; @@ -127,7 +129,7 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { // case geocalls::CallTriMeshData::Mesh::DT_DOUBLE: default: megamol::core::utility::log::Log::DefaultLog.WriteError( - "[OSPRayTriangleMesh] Vertex: No other data types than FLOAT are supported."); + "[OSPRayMeshGeometry] Vertex: No other data types than FLOAT are supported."); return false; } @@ -144,7 +146,7 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { break; default: megamol::core::utility::log::Log::DefaultLog.WriteError( - "[OSPRayTriangleMesh] Normals: No other data types than FLOAT are supported."); + "[OSPRayMeshGeometry] Normals: No other data types than FLOAT are supported."); return false; } } @@ -174,7 +176,7 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { break; default: megamol::core::utility::log::Log::DefaultLog.WriteError( - "[OSPRayTriangleMesh] Color: No other data types than BYTE or FLOAT are supported."); + "[OSPRayMeshGeometry] Color: No other data types than BYTE or FLOAT are supported."); return false; } @@ -200,7 +202,7 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { break; default: megamol::core::utility::log::Log::DefaultLog.WriteError( - "[OSPRayTriangleMesh] TextureCoordinate: No other data " + "[OSPRayMeshGeometry] TextureCoordinate: No other data " "types than BYTE or FLOAT are supported."); return false; } @@ -216,25 +218,27 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { case geocalls::CallTriMeshData::Mesh::DT_UINT32: index.data = const_cast(reinterpret_cast(obj.GetTriIndexPointerUInt32())); index.type = mesh::MeshDataAccessCollection::ValueType::UNSIGNED_INT; - index.byte_size = 3 * triangleCount * sizeof(uint32_t); + index.byte_size = 3 * sizeof(uint32_t) * (triangleCount - 1); break; default: megamol::core::utility::log::Log::DefaultLog.WriteError( - "[OSPRayTriangleMesh] Index: No other data types than BYTE or FLOAT are supported."); + "[OSPRayMeshGeometry] Index: No other data types than BYTE or FLOAT are supported."); return false; } } std::string identifier = std::string(FullName()) + "_object_" + std::to_string(i); - this->structureContainer.mesh->addMesh(identifier, attrib, index); + ms.mesh->addMesh(identifier, attrib, index); } // end for + + structureContainer.structure = ms; } // Write stuff into the structureContainer this->structureContainer.type = structureTypeEnum::GEOMETRY; - this->structureContainer.geometryType = geometryTypeEnum::TRIANGLES; + this->structureContainer.geometryType = geometryTypeEnum::MESH; // this->structureContainer.vertexData = std::make_shared>(std::move(vertexD)); // this->structureContainer.colorData = std::make_shared>(std::move(colorD)); // this->structureContainer.normalData = std::make_shared>(std::move(normalD)); @@ -247,25 +251,25 @@ bool OSPRayTriangleMesh::readData(megamol::core::Call& call) { } -OSPRayTriangleMesh::~OSPRayTriangleMesh() { +OSPRayMeshGeometry::~OSPRayMeshGeometry() { this->Release(); } -bool OSPRayTriangleMesh::create() { +bool OSPRayMeshGeometry::create() { return true; } -void OSPRayTriangleMesh::release() {} +void OSPRayMeshGeometry::release() {} /* ospray::OSPRaySphereGeometry::InterfaceIsDirty() */ -bool OSPRayTriangleMesh::InterfaceIsDirty() { +bool OSPRayMeshGeometry::InterfaceIsDirty() { return false; } -bool OSPRayTriangleMesh::getExtends(megamol::core::Call& call) { +bool OSPRayMeshGeometry::getExtends(megamol::core::Call& call) { CallOSPRayStructure* os = dynamic_cast(&call); mesh::CallMesh* cm = this->getMeshDataSlot.CallAs(); diff --git a/plugins/OSPRay_plugin/src/OSPRayTriangleMesh.h b/plugins/OSPRay_plugin/src/OSPRayMeshGeometry.h similarity index 81% rename from plugins/OSPRay_plugin/src/OSPRayTriangleMesh.h rename to plugins/OSPRay_plugin/src/OSPRayMeshGeometry.h index bb344a4cfe..99941ef087 100644 --- a/plugins/OSPRay_plugin/src/OSPRayTriangleMesh.h +++ b/plugins/OSPRay_plugin/src/OSPRayMeshGeometry.h @@ -1,5 +1,5 @@ /* -* OSPRayTriangleMesh.h +* OSPRayMeshGeometry.h * Copyright (C) 2009-2017 by MegaMol Team * Alle Rechte vorbehalten. */ @@ -12,7 +12,7 @@ namespace megamol { namespace ospray { -class OSPRayTriangleMesh : public AbstractOSPRayStructure { +class OSPRayMeshGeometry : public AbstractOSPRayStructure { public: @@ -22,7 +22,7 @@ class OSPRayTriangleMesh : public AbstractOSPRayStructure { * @return The name of this module. */ static const char *ClassName(void) { - return "OSPRayTriangleMesh"; + return "OSPRayMeshGeometry"; } /** @@ -31,7 +31,7 @@ class OSPRayTriangleMesh : public AbstractOSPRayStructure { * @return A human readable description of this module. */ static const char *Description(void) { - return "Creator for OSPRay triangle mesh geometries."; + return "Creator for OSPRay mesh geometries."; } /** @@ -44,10 +44,10 @@ class OSPRayTriangleMesh : public AbstractOSPRayStructure { } /** Dtor. */ - virtual ~OSPRayTriangleMesh(void); + virtual ~OSPRayMeshGeometry(void); /** Ctor. */ - OSPRayTriangleMesh(void); + OSPRayMeshGeometry(void); protected: @@ -68,4 +68,4 @@ class OSPRayTriangleMesh : public AbstractOSPRayStructure { }; } // namespace ospray -} // namespace megamol \ No newline at end of file +} // namespace megamol diff --git a/plugins/OSPRay_plugin/src/OSPRayMetalMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayMetalMaterial.cpp index c75a9bebf6..cb319afe32 100644 --- a/plugins/OSPRay_plugin/src/OSPRayMetalMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayMetalMaterial.cpp @@ -38,16 +38,18 @@ OSPRayMetalMaterial::~OSPRayMetalMaterial(void) { void OSPRayMetalMaterial::readParams() { materialContainer.materialType = materialTypeEnum::METAL; - auto reflect = this->metalReflectance.Param(); - materialContainer.metalReflectance = reflect->getArray(); + metalMaterial mm; + auto reflect = this->metalReflectance.Param(); + mm.metalReflectance = reflect->getArray(); auto eta = this->metalEta.Param(); - materialContainer.metalEta = eta->getArray(); - + mm.metalEta = eta->getArray(); auto k = this->metalK.Param(); - materialContainer.metalK = k->getArray(); + mm.metalK = k->getArray(); + mm.metalRoughness = + this->metalRoughness.Param()->Value(); - materialContainer.metalRoughness = this->metalRoughness.Param()->Value(); + materialContainer.material = mm; } bool OSPRayMetalMaterial::InterfaceIsDirty() { @@ -65,4 +67,4 @@ bool OSPRayMetalMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayMetallicPaintMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayMetallicPaintMaterial.cpp index 0162bd1109..020f2f4b3f 100644 --- a/plugins/OSPRay_plugin/src/OSPRayMetallicPaintMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayMetallicPaintMaterial.cpp @@ -38,15 +38,18 @@ OSPRayMetallicPaintMaterial::~OSPRayMetallicPaintMaterial(void) { void OSPRayMetallicPaintMaterial::readParams() { materialContainer.materialType = materialTypeEnum::METALLICPAINT; - auto scolor = this->metallicShadeColor.Param(); - materialContainer.metallicShadeColor = scolor->getArray(); + metallicpaintMaterial mpm; + auto scolor = this->metallicShadeColor.Param(); + mpm.metallicShadeColor = scolor->getArray(); auto gcolor = this->metallicGlitterColor.Param(); - materialContainer.metallicGlitterColor = gcolor->getArray(); + mpm.metallicGlitterColor = gcolor->getArray(); + mpm.metallicGlitterSpread = + this->metallicGlitterSpread.Param()->Value(); + mpm.metallicEta = + this->metallicEta.Param()->Value(); - materialContainer.metallicGlitterSpread = this->metallicGlitterSpread.Param()->Value(); - - materialContainer.metallicEta = this->metallicEta.Param()->Value(); + materialContainer.material = mpm; } bool OSPRayMetallicPaintMaterial::InterfaceIsDirty() { @@ -64,4 +67,4 @@ bool OSPRayMetallicPaintMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayNHSphereGeometry.cpp b/plugins/OSPRay_plugin/src/OSPRayNHSphereGeometry.cpp index a58bd539cb..e68d3695ce 100644 --- a/plugins/OSPRay_plugin/src/OSPRayNHSphereGeometry.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayNHSphereGeometry.cpp @@ -113,14 +113,14 @@ bool OSPRayNHSphereGeometry::readData(megamol::core::Call &call) { // Write stuff into the structureContainer this->structureContainer.type = structureTypeEnum::GEOMETRY; this->structureContainer.geometryType = geometryTypeEnum::NHSPHERES; - this->structureContainer.raw = parts.GetVertexData(); - this->structureContainer.vertexLength = vertexLength; - this->structureContainer.vertexStride = vstride; - this->structureContainer.colorLength = colorLength; - this->structureContainer.colorStride = parts.GetColourDataStride(); - this->structureContainer.partCount = partCount; - this->structureContainer.globalRadius = globalRadius; - this->structureContainer.mmpldColor = parts.GetColourDataType(); + sphereStructure ss; + ss.raw = parts.GetVertexData(); + ss.vertexLength = vertexLength; + ss.dataStride = vstride; + ss.colorLength = colorLength; + ss.partCount = partCount; + ss.globalRadius = globalRadius; + ss.mmpldColor = parts.GetColourDataType(); return true; } @@ -167,4 +167,4 @@ bool OSPRayNHSphereGeometry::getExtends(megamol::core::Call &call) { this->extendContainer.isValid = true; return true; -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayOBJMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayOBJMaterial.cpp index 949549b54f..4cdf912bd9 100644 --- a/plugins/OSPRay_plugin/src/OSPRayOBJMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayOBJMaterial.cpp @@ -42,18 +42,18 @@ OSPRayOBJMaterial::~OSPRayOBJMaterial(void) { void OSPRayOBJMaterial::readParams() { materialContainer.materialType = materialTypeEnum::OBJMATERIAL; - auto kd = this->Kd.Param(); - materialContainer.Kd = kd->getArray(); + objMaterial obj; + auto kd = this->Kd.Param(); + obj.Kd = kd->getArray(); auto ks = this->Ks.Param(); - materialContainer.Ks = ks->getArray(); - + obj.Ks = ks->getArray(); auto tf = this->Tf.Param(); - materialContainer.Tf = tf->getArray(); + obj.Tf = tf->getArray(); + obj.Ns = this->Ns.Param()->Value(); + obj.d = this->d.Param()->Value(); - materialContainer.Ns = this->Ns.Param()->Value(); - - materialContainer.d = this->d.Param()->Value(); + materialContainer.material = obj; } bool OSPRayOBJMaterial::InterfaceIsDirty() { @@ -73,4 +73,4 @@ bool OSPRayOBJMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayPKDGeometry.cpp b/plugins/OSPRay_plugin/src/OSPRayPKDGeometry.cpp index 30fe6172d6..76aed8d80d 100644 --- a/plugins/OSPRay_plugin/src/OSPRayPKDGeometry.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayPKDGeometry.cpp @@ -15,7 +15,7 @@ #include "vislib/forceinline.h" #include "mmcore/utility/log/Log.h" -#include +#include "ospray/ospray_cpp.h" #include "OSPRay_plugin/CallOSPRayAPIObject.h" #include "mmcore/view/CallClipPlane.h" #include "mmcore/view/CallGetTransferFunction.h" @@ -87,29 +87,30 @@ bool OSPRayPKDGeometry::getDataCallback(megamol::core::Call& call) { if (!(*cd)(0)) return false; size_t listCount = cd->GetParticleListCount(); - std::vector geo; + std::vector<::ospray::cpp::Geometry> geo; for (size_t i = 0; i < listCount; i++) { core::moldyn::MultiParticleDataCall::Particles& parts = cd->AccessParticles(i); auto colorType = this->colorTypeSlot.Param()->Value(); - geo.push_back(ospNewGeometry("pkd_geometry")); + geo.emplace_back(ospNewGeometry("pkd_geometry")); - auto vertexData = ospNewData(parts.GetCount(), OSP_FLOAT4, parts.GetVertexData(), OSP_DATA_SHARED_BUFFER); - ospCommit(vertexData); + auto vertexData = + ::ospray::cpp::SharedData(parts.GetVertexData(), OSP_FLOAT, parts.GetCount(), 4 * sizeof(float)); + vertexData.commit(); // set bbox - auto bboxData = ospNewData(6, OSP_FLOAT, parts.GetBBox().PeekBounds()); - ospCommit(bboxData); + auto bboxData = ::ospray::cpp::CopiedData(parts.GetBBox().PeekBounds(),OSP_FLOAT, 6); + bboxData.commit(); - ospSet1f(geo.back(), "radius", parts.GetGlobalRadius()); + geo.back().setParam("radius", parts.GetGlobalRadius()); //ospSet1i(geo.back(), "colorType", colorType); - ospSet1i(geo.back(), "colorType", 2); - ospSetData(geo.back(), "position", vertexData); + geo.back().setParam("colorType", 2); + geo.back().setParam("position", vertexData); // ospSetData(geo.back(), "bbox", bboxData); - ospSetData(geo.back(), "bbox", nullptr); - ospCommit(geo.back()); + geo.back().setParam("bbox", NULL); + geo.back().commit(); // TODO: implement distributed stuff // if (this->rd_type.Param()->Value() == MPI_RAYCAST) { @@ -128,7 +129,7 @@ bool OSPRayPKDGeometry::getDataCallback(megamol::core::Call& call) { std::vector geo_transfer(geo.size()); for (auto i = 0; i < geo.size(); i++) { - geo_transfer[i] = reinterpret_cast(geo[i]); + geo_transfer[i] = geo[i].handle(); } os->setStructureType(GEOMETRY); os->setAPIObjects(std::move(geo_transfer)); @@ -198,4 +199,4 @@ bool OSPRayPKDGeometry::getDirtyCallback(core::Call& call) { } // namespace ospray -} // namespace megamol \ No newline at end of file +} // namespace megamol diff --git a/plugins/OSPRay_plugin/src/OSPRayPlasticMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayPlasticMaterial.cpp index 9a0ed9a722..367c1a0972 100644 --- a/plugins/OSPRay_plugin/src/OSPRayPlasticMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayPlasticMaterial.cpp @@ -38,14 +38,21 @@ OSPRayPlasticMaterial::~OSPRayPlasticMaterial(void) { void OSPRayPlasticMaterial::readParams() { materialContainer.materialType = materialTypeEnum::PLASTIC; + plasticMaterial pm; + auto pcolor = this->plasticPigmentColor.Param(); - materialContainer.plasticPigmentColor = pcolor->getArray(); + pm.plasticPigmentColor = pcolor->getArray(); + + pm.plasticEta = + this->plasticEta.Param()->Value(); - materialContainer.plasticEta = this->plasticEta.Param()->Value(); + pm.plasticRoughness = + this->plasticRoughness.Param()->Value(); - materialContainer.plasticRoughness = this->plasticRoughness.Param()->Value(); + pm.plasticThickness = + this->plasticThickness.Param()->Value(); - materialContainer.plasticThickness = this->plasticThickness.Param()->Value(); + materialContainer.material = pm; } bool OSPRayPlasticMaterial::InterfaceIsDirty() { @@ -63,4 +70,4 @@ bool OSPRayPlasticMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayQuadMesh.cpp b/plugins/OSPRay_plugin/src/OSPRayQuadMesh.cpp deleted file mode 100644 index 9314fb23a1..0000000000 --- a/plugins/OSPRay_plugin/src/OSPRayQuadMesh.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * OSPRayQuadMesh.cpp - * Copyright (C) 2019 by MegaMol Team - * Alle Rechte vorbehalten. - */ - -#include "stdafx.h" -#include "OSPRayQuadMesh.h" -#include "geometry_calls/CallTriMeshData.h" -#include "mmcore/utility/log/Log.h" -#include "mmcore/BoundingBoxes_2.h" - - -using namespace megamol::ospray; - - -OSPRayQuadMesh::OSPRayQuadMesh(void) - : AbstractOSPRayStructure() - , getMeshDataSlot("getMeshData", "Connects to the data source") { - - this->getMeshDataSlot.SetCompatibleCall(); - this->MakeSlotAvailable(&this->getMeshDataSlot); -} - - -bool OSPRayQuadMesh::readData(megamol::core::Call& call) { - - // fill material container - this->processMaterial(); - - // fill transformation container - this->processTransformation(); - - // read Data, calculate shape parameters, fill data vectors - CallOSPRayStructure* os = dynamic_cast(&call); - - mesh::CallMesh* cm = this->getMeshDataSlot.CallAs(); - - if (cm != nullptr) { - auto meta_data = cm->getMetaData(); - this->structureContainer.dataChanged = false; - if (os->getTime() > meta_data.m_frame_cnt) { - meta_data.m_frame_ID = meta_data.m_frame_cnt - 1; - } else { - meta_data.m_frame_ID = os->getTime(); - } - cm->setMetaData(meta_data); - if (!(*cm)(1)) return false; - if (!(*cm)(0)) return false; - meta_data = cm->getMetaData(); - if (cm->hasUpdate() || this->time != os->getTime() || this->InterfaceIsDirty()) { - this->time = os->getTime(); - this->structureContainer.dataChanged = true; - this->extendContainer.boundingBox = std::make_shared(meta_data.m_bboxs); - this->extendContainer.timeFramesCount = meta_data.m_frame_cnt; - this->extendContainer.isValid = true; - this->structureContainer.mesh = cm->getData(); - } - } - - // Write stuff into the structureContainer - this->structureContainer.type = structureTypeEnum::GEOMETRY; - this->structureContainer.geometryType = geometryTypeEnum::QUADS; - - - return true; -} - - -OSPRayQuadMesh::~OSPRayQuadMesh() { this->Release(); } - -bool OSPRayQuadMesh::create() { return true; } - -void OSPRayQuadMesh::release() {} - -/* -ospray::OSPRaySphereGeometry::InterfaceIsDirty() -*/ -bool OSPRayQuadMesh::InterfaceIsDirty() { - return false; -} - - -bool OSPRayQuadMesh::getExtends(megamol::core::Call& call) { - CallOSPRayStructure* os = dynamic_cast(&call); - - mesh::CallMesh* cm = this->getMeshDataSlot.CallAs(); - - if (cm != nullptr) { - - if (!(*cm)(1)) return false; - auto meta_data = cm->getMetaData(); - if (os->getTime() > meta_data.m_frame_cnt) { - meta_data.m_frame_ID = meta_data.m_frame_cnt - 1; - } else { - meta_data.m_frame_ID = os->getTime(); - } - cm->setMetaData(meta_data); - - this->extendContainer.boundingBox = std::make_shared(meta_data.m_bboxs); - this->extendContainer.timeFramesCount = meta_data.m_frame_cnt; - this->extendContainer.isValid = true; - - } - return true; -} \ No newline at end of file diff --git a/plugins/OSPRay_plugin/src/OSPRayQuadMesh.h b/plugins/OSPRay_plugin/src/OSPRayQuadMesh.h deleted file mode 100644 index e427482e96..0000000000 --- a/plugins/OSPRay_plugin/src/OSPRayQuadMesh.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -* OSPRayQuadMesh.h -* Copyright (C) 2019 by MegaMol Team -* Alle Rechte vorbehalten. -*/ -#pragma once - -#include "mmcore/param/ParamSlot.h" -#include "mmcore/CallerSlot.h" -#include "OSPRay_plugin/AbstractOSPRayStructure.h" - -namespace megamol { -namespace ospray { - -class OSPRayQuadMesh : public AbstractOSPRayStructure { - -public: - - /** - * Answer the name of this module. - * - * @return The name of this module. - */ - static const char *ClassName(void) { - return "OSPRayQuadMesh"; - } - - /** - * Answer a human readable description of this module. - * - * @return A human readable description of this module. - */ - static const char *Description(void) { - return "Creator for OSPRay quad mesh geometries."; - } - - /** - * Answers whether this module is available on the current system. - * - * @return 'true' if the module is available, 'false' otherwise. - */ - static bool IsAvailable(void) { - return true; - } - - /** Dtor. */ - virtual ~OSPRayQuadMesh(void); - - /** Ctor. */ - OSPRayQuadMesh(void); - -protected: - - virtual bool create(); - virtual void release(); - - virtual bool readData(core::Call &call); - virtual bool getExtends(core::Call &call); - - - bool InterfaceIsDirty(); - - /** The call for data */ - core::CallerSlot getMeshDataSlot; - std::vector _color; - -}; - -} // namespace ospray -} // namespace megamol \ No newline at end of file diff --git a/plugins/OSPRay_plugin/src/OSPRayRenderer.cpp b/plugins/OSPRay_plugin/src/OSPRayRenderer.cpp index a271a62ab4..fa82e3e281 100644 --- a/plugins/OSPRay_plugin/src/OSPRayRenderer.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayRenderer.cpp @@ -19,11 +19,11 @@ #include #include -#include "ospcommon/vec.h" -#include "ospray/ospray.h" +#include "ospray/ospray_cpp.h" #include #include +#include using namespace megamol::ospray; @@ -32,25 +32,23 @@ ospray::OSPRayRenderer::OSPRaySphereRenderer */ OSPRayRenderer::OSPRayRenderer(void) : AbstractOSPRayRenderer() - , cam() - , osprayShader() - , getStructureSlot("getStructure", "Connects to an OSPRay structure") + , _cam() + , _osprayShader() + , _getStructureSlot("getStructure", "Connects to an OSPRay structure") { - this->getStructureSlot.SetCompatibleCall(); - this->MakeSlotAvailable(&this->getStructureSlot); - - - imgSize.x = 0; - imgSize.y = 0; - time = 0; - framebuffer = NULL; - renderer = NULL; - camera = NULL; - world = NULL; - - accum_time.count = 0; - accum_time.amount = 0; + this->_getStructureSlot.SetCompatibleCall(); + this->MakeSlotAvailable(&this->_getStructureSlot); + + _imgSize = {0,0}; + _time = 0; + _framebuffer = nullptr; + _renderer = nullptr; + _camera = nullptr; + _world = nullptr; + + _accum_time.count = 0; + _accum_time.amount = 0; } @@ -58,7 +56,7 @@ OSPRayRenderer::OSPRayRenderer(void) ospray::OSPRayRenderer::~OSPRaySphereRenderer */ OSPRayRenderer::~OSPRayRenderer(void) { - this->osprayShader.Release(); + this->_osprayShader.Release(); this->Release(); } @@ -79,7 +77,7 @@ bool OSPRayRenderer::create() { } try { - if (!this->osprayShader.Create(vert.Code(), vert.Count(), frag.Code(), frag.Count())) { + if (!this->_osprayShader.Create(vert.Code(), vert.Count(), frag.Code(), frag.Count())) { megamol::core::utility::log::Log::DefaultLog.WriteMsg( megamol::core::utility::log::Log::LEVEL_ERROR, "Unable to compile ospray shader: Unknown error\n"); return false; @@ -102,7 +100,7 @@ bool OSPRayRenderer::create() { // this->initOSPRay(device); this->setupTextureScreen(); - // this->setupOSPRay(renderer, camera, world, "scivis"); + // this->setupOSPRay(renderer, camera, world, "scivis");# return true; } @@ -111,134 +109,113 @@ bool OSPRayRenderer::create() { ospray::OSPRayRenderer::release */ void OSPRayRenderer::release() { - for (auto& model : this->instancedModels) { - ospRelease(model.second); - } - for (auto& inst : this->instances) { - ospRelease(inst.second); - } - for (auto& structs : this->baseStructures) { - if (this->structureMap[structs.first].type == structureTypeEnum::GEOMETRY) { - for (auto& geo : structs.second) { - ospRelease(std::get(geo)); - } - } else { - for (auto& vol : structs.second) { - ospRelease(std::get(vol)); - } - } - } - for (auto& material : this->materials) { - ospRelease(material.second); - } - if (camera != NULL) ospRelease(camera); - if (world != NULL) ospRelease(world); - //if (renderer != NULL) ospRelease(renderer); + + ospShutdown(); + releaseTextureScreen(); + } /* ospray::OSPRayRenderer::Render */ bool OSPRayRenderer::Render(megamol::core::view::CallRender3D_2& cr) { - this->initOSPRay(device); - - if (device != ospGetCurrentDevice()) { - ospSetCurrentDevice(device); - } + this->initOSPRay(); + // if user wants to switch renderer - if (this->rd_type.IsDirty()) { - ospRelease(camera); - ospRelease(world); - ospRelease(renderer); - switch (this->rd_type.Param()->Value()) { + if (this->_rd_type.IsDirty()) { + //ospRelease(_camera); + //ospRelease(_world); + //ospRelease(_renderer); + switch (this->_rd_type.Param()->Value()) { case PATHTRACER: - this->setupOSPRay(renderer, camera, world, "pathtracer"); - this->rd_type_string = "pathtracer"; + this->setupOSPRay("pathtracer"); + this->_rd_type_string = "pathtracer"; break; case MPI_RAYCAST: //< TODO: Probably only valid if device is a "mpi_distributed" device - this->setupOSPRay(renderer, camera, world, "mpi_raycast"); - this->rd_type_string = "mpi_raycast"; + this->setupOSPRay("mpi_raycast"); + this->_rd_type_string = "mpi_raycast"; break; default: - this->setupOSPRay(renderer, camera, world, "scivis"); - this->rd_type_string = "scivis"; + this->setupOSPRay("scivis"); + this->_rd_type_string = "scivis"; } - renderer_has_changed = true; - this->rd_type.ResetDirty(); + _renderer_has_changed = true; + this->_rd_type.ResetDirty(); } if (&cr == nullptr) return false; - CallOSPRayStructure* os = this->getStructureSlot.CallAs(); + CallOSPRayStructure* os = this->_getStructureSlot.CallAs(); if (os == nullptr) return false; // read data - os->setStructureMap(&structureMap); + os->setStructureMap(&_structureMap); os->setTime(cr.Time()); if (!os->fillStructureMap()) return false; // check if data has changed - data_has_changed = false; - material_has_changed = false; - transformation_has_changed = false; - for (auto element : this->structureMap) { + _data_has_changed = false; + _material_has_changed = false; + _transformation_has_changed = false; + for (auto element : this->_structureMap) { auto structure = element.second; if (structure.dataChanged) { - data_has_changed = true; + _data_has_changed = true; } if (structure.materialChanged) { - material_has_changed = true; + _material_has_changed = true; + } + if (structure.transformationChanged) { + _transformation_has_changed = true; } - if (structure.transformationChanged) - transformation_has_changed = true; } // Light setup - auto call_light = lightSlot.CallAs(); + auto call_light = _lightSlot.CallAs(); if (call_light != nullptr) { if (!(*call_light)(0)) { return false; } - this->light_has_changed = call_light->hasUpdate(); + _light_has_changed = call_light->hasUpdate(); } - core::view::Camera_2 tmp_newcam; - cr.GetCamera(tmp_newcam); - cam_type::snapshot_type snapshot; - cam_type::matrix_type viewTemp, projTemp; + core::view::Camera_2 tmp_newcam; + cr.GetCamera(tmp_newcam); + cam_type::snapshot_type snapshot; + cam_type::matrix_type viewTemp, projTemp; // Generate complete snapshot and calculate matrices tmp_newcam.calc_matrices(snapshot, viewTemp, projTemp, core::thecam::snapshot_content::all); // check data and camera hash - if (cam.eye_position().x() != tmp_newcam.eye_position().x() || - cam.eye_position().y() != tmp_newcam.eye_position().y() || - cam.eye_position().z() != tmp_newcam.eye_position().z() || - cam.view_vector() != tmp_newcam.view_vector() - ) { - cam_has_changed = true; - } else { - cam_has_changed = false; - } + if (_cam.eye_position().x() != tmp_newcam.eye_position().x() || + _cam.eye_position().y() != tmp_newcam.eye_position().y() || + _cam.eye_position().z() != tmp_newcam.eye_position().z() || + _cam.view_vector() != tmp_newcam.view_vector() + ) { + _cam_has_changed = true; + } else { + _cam_has_changed = false; + } - // Generate complete snapshot and calculate matrices - cam = tmp_newcam; + // Generate complete snapshot and calculate matrices + _cam = tmp_newcam; // glDisable(GL_CULL_FACE); // new framebuffer at resize action // bool triggered = false; - if (imgSize.x != cam.resolution_gate().width() || - imgSize.y != cam.resolution_gate().height() || accumulateSlot.IsDirty()) { + if (_imgSize[0] != _cam.resolution_gate().width() || + _imgSize[1] != _cam.resolution_gate().height() || _accumulateSlot.IsDirty()) { // triggered = true; // Breakpoint for Screenshooter debugging // if (framebuffer != NULL) ospFreeFrameBuffer(framebuffer); - imgSize.x = cam.resolution_gate().width(); - imgSize.y = cam.resolution_gate().height(); - framebuffer = newFrameBuffer(imgSize, OSP_FB_RGBA8, OSP_FB_COLOR | OSP_FB_DEPTH | OSP_FB_ACCUM); - db.resize(imgSize.x * imgSize.y); - ospCommit(framebuffer); + _imgSize[0] = _cam.resolution_gate().width(); + _imgSize[1] = _cam.resolution_gate().height(); + _framebuffer = std::make_shared<::ospray::cpp::FrameBuffer>(_imgSize[0], _imgSize[1], OSP_FB_RGBA8, OSP_FB_COLOR | OSP_FB_DEPTH | OSP_FB_ACCUM); + _db.resize(_imgSize[0] * _imgSize[1]); + _framebuffer->commit(); } //// if user wants to switch renderer @@ -258,38 +235,58 @@ bool OSPRayRenderer::Render(megamol::core::view::CallRender3D_2& cr) { // } // renderer_has_changed = true; //} - setupOSPRayCamera(camera, cam); - ospCommit(camera); + setupOSPRayCamera(_cam); + _camera->commit(); - osprayShader.Enable(); + _osprayShader.Enable(); // if nothing changes, the image is rendered multiple times - if (data_has_changed || material_has_changed || light_has_changed || cam_has_changed || renderer_has_changed || - transformation_has_changed || !(this->accumulateSlot.Param()->Value()) || - frameID != static_cast(cr.Time()) || this->InterfaceIsDirty()) { + if (_data_has_changed || _material_has_changed || _light_has_changed || _cam_has_changed || _renderer_has_changed || + _transformation_has_changed || !(this->_accumulateSlot.Param()->Value()) || + _frameID != static_cast(cr.Time()) || this->InterfaceIsDirty()) { - if (data_has_changed || frameID != static_cast(cr.Time()) || renderer_has_changed) { + std::array eyeDir = { + _cam.view_vector().x(), _cam.view_vector().y(), _cam.view_vector().z(), _cam.view_vector().w()}; + if (_data_has_changed || _frameID != static_cast(cr.Time()) || _renderer_has_changed) { // || this->InterfaceIsDirty()) { - if (!this->fillWorld()) return false; + if (!this->generateRepresentations()) return false; + this->createInstances(); + std::vector<::ospray::cpp::Instance> instanceArray; + std::transform(_instances.begin(), _instances.end(), std::back_inserter(instanceArray), second(_instances)); + _world->setParam("instance", ::ospray::cpp::CopiedData(instanceArray)); + + // Enable Lights + this->fillLightArray(eyeDir); + _world->setParam("light", ::ospray::cpp::CopiedData(_lightArray)); // Commiting world and measuring time auto t1 = std::chrono::high_resolution_clock::now(); - ospCommit(world); + _world->commit(); auto t2 = std::chrono::high_resolution_clock::now(); const auto duration = std::chrono::duration_cast(t2 - t1).count(); megamol::core::utility::log::Log::DefaultLog.WriteMsg( 242, "[OSPRayRenderer] Commiting World took: %d microseconds", duration); } - if (material_has_changed && !data_has_changed) { + if (_material_has_changed && !_data_has_changed) { this->changeMaterial(); } - if (transformation_has_changed || material_has_changed && !data_has_changed) { + if (_transformation_has_changed || _material_has_changed && !_data_has_changed) { this->changeTransformation(); + std::vector<::ospray::cpp::Instance> instanceArray; + std::transform(_instances.begin(), _instances.end(), std::back_inserter(instanceArray), second(_instances)); + _world->setParam("instance", ::ospray::cpp::CopiedData(instanceArray)); + _world->commit(); } + if (_light_has_changed && !_data_has_changed) { + this->fillLightArray(eyeDir); + _world->setParam("light", ::ospray::cpp::CopiedData(_lightArray)); + _world->commit(); + } + this->InterfaceResetDirty(); - time = cr.Time(); - frameID = static_cast(cr.Time()); - renderer_has_changed = false; + _time = cr.Time(); + _frameID = static_cast(cr.Time()); + _renderer_has_changed = false; /* if (this->maxDepthTexture) { @@ -297,41 +294,58 @@ bool OSPRayRenderer::Render(megamol::core::view::CallRender3D_2& cr) { } this->maxDepthTexture = getOSPDepthTextureFromOpenGLPerspective(*cr); */ - RendererSettings(renderer); - - - // Enable Lights - auto eyeDir = cam.view_vector(); - this->fillLightArray(eyeDir); - lightsToRender = ospNewData(this->lightArray.size(), OSP_OBJECT, lightArray.data(), 0); - ospCommit(lightsToRender); - ospSetData(renderer, "lights", lightsToRender); - - ospSetObject(renderer, "model", world); - ospCommit(renderer); + RendererSettings(cr.BackgroundColor()); + + + if (this->_useDB.Param()->Value()) { + // far distance + float far_clip = _cam.far_clipping_plane(); + std::vector far_dist(_imgSize[0] * _imgSize[1], far_clip); + rkcommon::math::vec2i imgSize = { + _imgSize[0], + _imgSize[1] + }; + + auto depth_texture_data = ::ospray::cpp::CopiedData(far_dist.data(), OSP_FLOAT, imgSize); + depth_texture_data.commit(); + auto depth_texture = ::ospray::cpp::Texture("texture2d"); + depth_texture.setParam("format", OSP_TEXTURE_R32F); + depth_texture.setParam("filter", OSP_TEXTURE_FILTER_NEAREST); + depth_texture.setParam("data", depth_texture_data); + depth_texture.commit(); + + _renderer->setParam("map_maxDepth", depth_texture); + } + _renderer->commit(); // setup framebuffer and measure time auto t1 = std::chrono::high_resolution_clock::now(); - ospFrameBufferClear(framebuffer, OSP_FB_COLOR | OSP_FB_DEPTH | OSP_FB_ACCUM); - ospRenderFrame(framebuffer, renderer, OSP_FB_COLOR | OSP_FB_DEPTH | OSP_FB_ACCUM); + _framebuffer->clear();//(OSP_FB_COLOR | OSP_FB_DEPTH | OSP_FB_ACCUM); + _framebuffer->renderFrame(*_renderer, *_camera, *_world); // get the texture from the framebuffer - fb = (uint32_t*)ospMapFrameBuffer(framebuffer, OSP_FB_COLOR); + _fb = reinterpret_cast(_framebuffer->map(OSP_FB_COLOR)); + auto t2 = std::chrono::high_resolution_clock::now(); const auto duration = std::chrono::duration_cast(t2 - t1); - accum_time.amount += duration.count(); - accum_time.count += 1; - if (accum_time.amount >= static_cast(1e6)) { - const unsigned long long int mean_rendertime = accum_time.amount / accum_time.count; + _accum_time.amount += duration.count(); + _accum_time.count += 1; + if (_accum_time.amount >= static_cast(1e6)) { + const unsigned long long int mean_rendertime = _accum_time.amount / _accum_time.count; megamol::core::utility::log::Log::DefaultLog.WriteMsg(242, "[OSPRayRenderer] Rendering took: %d microseconds", mean_rendertime); - accum_time.count = 0; - accum_time.amount = 0; + _accum_time.count = 0; + _accum_time.amount = 0; } - if (this->useDB.Param()->Value()) { - getOpenGLDepthFromOSPPerspective(db.data()); + + float* db; + if (this->_useDB.Param()->Value()) { + db = static_cast(_framebuffer->map(OSP_FB_DEPTH)); + _db = std::vector(db, db + _imgSize[0] * _imgSize[1]); + + getOpenGLDepthFromOSPPerspective(_db.data()); } // write a sequence of single pictures while the screenshooter is running @@ -348,24 +362,34 @@ bool OSPRayRenderer::Render(megamol::core::view::CallRender3D_2& cr) { // this->number++; //} - this->renderTexture2D(osprayShader, fb, db.data(), imgSize.x, imgSize.y, cr); + //std::string fname("blub.ppm"); + //writePPM(fname, _imgSize, _fb); + + + this->renderTexture2D(_osprayShader, _fb, _db.data(), _imgSize[0], _imgSize[1], cr); // clear stuff - ospUnmapFrameBuffer(fb, framebuffer); + _framebuffer->unmap(_fb); + if (this->_useDB.Param()->Value()) { + _framebuffer->unmap(db); + } + //auto dvce_ = ospGetCurrentDevice(); + //auto error_ = std::string(ospDeviceGetLastErrorMsg(dvce_)); + //megamol::core::utility::log::Log::DefaultLog.WriteError(std::string("OSPRAY last ERROR: " + error_).c_str()); this->releaseOSPRayStuff(); } else { - ospRenderFrame(framebuffer, renderer, OSP_FB_COLOR | OSP_FB_DEPTH | OSP_FB_ACCUM); - fb = (uint32_t*)ospMapFrameBuffer(framebuffer, OSP_FB_COLOR); + _framebuffer->renderFrame(*_renderer, *_camera, *_world); + _fb = reinterpret_cast(_framebuffer->map(OSP_FB_COLOR)); - this->renderTexture2D(osprayShader, fb, db.data(), imgSize.x, imgSize.y, cr); - ospUnmapFrameBuffer(fb, framebuffer); + this->renderTexture2D(_osprayShader, _fb, _db.data(), _imgSize[0], _imgSize[1], cr); + _framebuffer->unmap(_fb); } - osprayShader.Disable(); + _osprayShader.Disable(); return true; } @@ -393,15 +417,15 @@ void OSPRayRenderer::InterfaceResetDirty() { this->AbstractResetDirty(); } bool OSPRayRenderer::GetExtents(megamol::core::view::CallRender3D_2& cr) { if (&cr == NULL) return false; - CallOSPRayStructure* os = this->getStructureSlot.CallAs(); + CallOSPRayStructure* os = this->_getStructureSlot.CallAs(); if (os == NULL) return false; os->setTime(static_cast(cr.Time())); - os->setExtendMap(&(this->extendMap)); + os->setExtendMap(&(this->_extendMap)); if (!os->fillExtendMap()) return false; megamol::core::BoundingBoxes_2 finalBox; unsigned int frameCnt = 0; - for (auto pair : this->extendMap) { + for (auto pair : this->_extendMap) { auto element = pair.second; if (frameCnt == 0) { @@ -452,23 +476,23 @@ bool OSPRayRenderer::GetExtents(megamol::core::view::CallRender3D_2& cr) { void OSPRayRenderer::getOpenGLDepthFromOSPPerspective(float* db) { - const float fovy = cam.aperture_angle(); - const float aspect = cam.resolution_gate_aspect(); - const float zNear = cam.near_clipping_plane(); - const float zFar = cam.far_clipping_plane(); + const float fovy = _cam.aperture_angle(); + const float aspect = _cam.resolution_gate_aspect(); + const float zNear = _cam.near_clipping_plane(); + const float zFar = _cam.far_clipping_plane(); - const ospcommon::vec3f cameraUp(cam.up_vector().x(), cam.up_vector().y(), cam.up_vector().z()); - const ospcommon::vec3f cameraDir(cam.view_vector().x(), cam.view_vector().y(), cam.view_vector().z()); + const glm::vec3 cameraUp = {_cam.up_vector().x(), _cam.up_vector().y(), _cam.up_vector().z()}; + const glm::vec3 cameraDir = {_cam.view_vector().x(), _cam.view_vector().y(), _cam.view_vector().z()}; // map OSPRay depth buffer from provided frame buffer - const auto ospDepthBuffer = static_cast(ospMapFrameBuffer(this->framebuffer, OSP_FB_DEPTH)); + auto ospDepthBuffer = static_cast(_framebuffer->map(OSP_FB_DEPTH)); - const auto ospDepthBufferWidth = static_cast(this->imgSize.x); - const auto ospDepthBufferHeight = static_cast(this->imgSize.y); + const auto ospDepthBufferWidth = static_cast(_imgSize[0]); + const auto ospDepthBufferHeight = static_cast(_imgSize[1]); // transform from ray distance t to orthogonal Z depth - ospcommon::vec3f dir_du = normalize(cross(cameraDir, cameraUp)); - ospcommon::vec3f dir_dv = normalize(cross(dir_du, cameraDir)); + auto dir_du = glm::normalize(glm::cross(cameraDir, cameraUp)); + auto dir_dv = glm::normalize(glm::cross(dir_du, cameraDir)); const float imagePlaneSizeY = 2.f * tanf(fovy / 2.f * M_PI / 180.f); const float imagePlaneSizeX = imagePlaneSizeY * aspect; @@ -476,7 +500,7 @@ void OSPRayRenderer::getOpenGLDepthFromOSPPerspective(float* db) { dir_du *= imagePlaneSizeX; dir_dv *= imagePlaneSizeY; - const ospcommon::vec3f dir_00 = cameraDir - .5f * dir_du - .5f * dir_dv; + const auto dir_00 = cameraDir - .5f * dir_du - .5f * dir_dv; const float A = -(zFar + zNear) / (zFar - zNear); const float B = -2. * zFar * zNear / (zFar - zNear); @@ -485,7 +509,7 @@ void OSPRayRenderer::getOpenGLDepthFromOSPPerspective(float* db) { #pragma omp parallel for private(i) for (j = 0; j < ospDepthBufferHeight; j++) { for (i = 0; i < ospDepthBufferWidth; i++) { - const ospcommon::vec3f dir_ij = normalize(dir_00 + float(i) / float(ospDepthBufferWidth - 1) * dir_du + + const auto dir_ij = glm::normalize(dir_00 + float(i) / float(ospDepthBufferWidth - 1) * dir_du + float(j) / float(ospDepthBufferHeight - 1) * dir_dv); const float tmp = ospDepthBuffer[j * ospDepthBufferWidth + i];// * dot(cameraDir, dir_ij); @@ -495,5 +519,5 @@ void OSPRayRenderer::getOpenGLDepthFromOSPPerspective(float* db) { } } // unmap OSPRay depth buffer - ospUnmapFrameBuffer(ospDepthBuffer, this->framebuffer); + _framebuffer->unmap(ospDepthBuffer); } diff --git a/plugins/OSPRay_plugin/src/OSPRayRenderer.h b/plugins/OSPRay_plugin/src/OSPRayRenderer.h index aed3a7ea72..dea3d4f4bd 100644 --- a/plugins/OSPRay_plugin/src/OSPRayRenderer.h +++ b/plugins/OSPRay_plugin/src/OSPRayRenderer.h @@ -90,40 +90,40 @@ class OSPRayRenderer : public AbstractOSPRayRenderer { virtual bool GetExtents(megamol::core::view::CallRender3D_2& call); /** The call for data */ - core::CallerSlot getStructureSlot; + core::CallerSlot _getStructureSlot; /** The texture shader */ - vislib::graphics::gl::GLSLShader osprayShader; + vislib::graphics::gl::GLSLShader _osprayShader; // Interface dirty flag bool InterfaceIsDirty(); void InterfaceResetDirty(); // rendering conditions - bool data_has_changed; - bool material_has_changed; - bool light_has_changed; - bool cam_has_changed; - bool transformation_has_changed; + bool _data_has_changed; + bool _material_has_changed; + bool _light_has_changed; + bool _cam_has_changed; + bool _transformation_has_changed; - core::view::Camera_2 cam; - float time; - size_t frameID; + core::view::Camera_2 _cam; + float _time; + size_t _frameID; - osp::vec2i imgSize; + std::array _imgSize; // OSPRay textures - const uint32_t* fb; - std::vector db; + uint32_t* _fb; + std::vector _db; void getOpenGLDepthFromOSPPerspective(float* db); - bool renderer_has_changed; + bool _renderer_has_changed; struct { unsigned long long int count; unsigned long long int amount; - } accum_time; + } _accum_time; }; } /*end namespace ospray*/ diff --git a/plugins/OSPRay_plugin/src/OSPRaySphereGeometry.cpp b/plugins/OSPRay_plugin/src/OSPRaySphereGeometry.cpp index 7af398d683..57a3699b17 100644 --- a/plugins/OSPRay_plugin/src/OSPRaySphereGeometry.cpp +++ b/plugins/OSPRay_plugin/src/OSPRaySphereGeometry.cpp @@ -115,12 +115,16 @@ bool OSPRaySphereGeometry::readData(megamol::core::Call& call) { } } - this->structureContainer.vertexData = std::make_shared>(std::move(vd)); - this->structureContainer.colorData = std::make_shared>(std::move(cd_rgba)); - this->structureContainer.vertexLength = 3; - this->structureContainer.colorLength = 4; - this->structureContainer.partCount = partCount; - this->structureContainer.globalRadius = globalRadius; + sphereStructure ss; + + ss.vertexData = std::make_shared>(std::move(vd)); + ss.colorData = std::make_shared>(std::move(cd_rgba)); + ss.vertexLength = 3; + ss.colorLength = 4; + ss.partCount = partCount; + ss.globalRadius = globalRadius; + + this->structureContainer.structure = ss; this->datahash = cd->DataHash(); this->time = cd->FrameID(); @@ -130,16 +134,16 @@ bool OSPRaySphereGeometry::readData(megamol::core::Call& call) { } // clipPlane setup - std::vector clipDat(4); - std::vector clipCol(4); + std::array clipDat; + std::array clipCol; this->getClipData(clipDat.data(), clipCol.data()); // Write stuff into the structureContainer this->structureContainer.type = structureTypeEnum::GEOMETRY; this->structureContainer.geometryType = geometryTypeEnum::SPHERES; - this->structureContainer.clipPlaneData = std::make_shared>(std::move(clipDat)); - this->structureContainer.clipPlaneColor = std::make_shared>(std::move(clipCol)); + //this->structureContainer.clipPlaneData = std::make_shared>(std::move(clipDat)); + //this->structureContainer.clipPlaneColor = std::make_shared>(std::move(clipCol)); return true; } diff --git a/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.cpp b/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.cpp index dbd776ff65..c954c1e3c6 100644 --- a/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.cpp @@ -12,6 +12,7 @@ #include "mmcore/param/EnumParam.h" #include "mmcore/param/FloatParam.h" #include "mmcore/param/Vector3fParam.h" +#include "mmcore/param/StringParam.h" #include "mmcore/view/CallGetTransferFunction.h" #include "mmcore/utility/log/Log.h" @@ -27,39 +28,14 @@ OSPRayStructuredVolume::OSPRayStructuredVolume(void) , clippingBoxUpper("ClippingBox::Right", "Right corner of the clipping Box") , clippingBoxActive("ClippingBox::Active", "Activates the clipping Box") , repType("Representation", "Activates one of the three different volume representations: Volume, Isosurfae, Slice") - , useMIP("shading::useMIP", "toggle maximum intensity projection") - , useGradient("shading::useGradient", "compute gradient for shading") - , usePreIntegration("shading::usePreintegration", "toggle preintegration") - , useAdaptiveSampling("adaptive::enable", "toggle adaptive sampling") - , adaptiveFactor("adaptive::factor", "modifier for adaptive step size") - , adaptiveMaxRate("adaptive::maxRate", "maximum sampling rate") - , samplingRate("adaptive::minRate", "minimum sampling rate") , IsoValue("Isosurface::Isovalue", "Sets the isovalue of the isosurface") - , sliceNormal("Slice::sliceNormal", "Direction of the slice normal") - , sliceDist("Slice::sliceDist", "Distance of the slice in the direction of the normal vector") { + , showBoundingBox("showBoundingBox", "Bounding box of the volume data set") { core::param::EnumParam* rt = new core::param::EnumParam(VOLUMEREP); rt->SetTypePair(VOLUMEREP, "Volume"); rt->SetTypePair(ISOSURFACE, "Isosurface"); - rt->SetTypePair(SLICE, "Slice"); this->repType << rt; this->MakeSlotAvailable(&this->repType); - this->useMIP << new core::param::BoolParam(false); - this->MakeSlotAvailable(&this->useMIP); - this->useGradient << new core::param::BoolParam(false); - this->MakeSlotAvailable(&this->useGradient); - this->usePreIntegration << new core::param::BoolParam(false); - this->MakeSlotAvailable(&this->usePreIntegration); - - this->useAdaptiveSampling << new core::param::BoolParam(false); - this->MakeSlotAvailable(&this->useAdaptiveSampling); - this->adaptiveFactor << new core::param::FloatParam(15.0f, std::numeric_limits::min()); - this->MakeSlotAvailable(&this->adaptiveFactor); - this->adaptiveMaxRate << new core::param::FloatParam(2.0f, std::numeric_limits::min()); - this->MakeSlotAvailable(&this->adaptiveMaxRate); - this->samplingRate << new core::param::FloatParam(0.125f, std::numeric_limits::min()); - this->MakeSlotAvailable(&this->samplingRate); - this->clippingBoxActive << new core::param::BoolParam(false); this->clippingBoxLower << new core::param::Vector3fParam({-5.0f, -5.0f, -5.0f}); this->clippingBoxUpper << new core::param::Vector3fParam({0.0f, 5.0f, 5.0f}); @@ -67,21 +43,18 @@ OSPRayStructuredVolume::OSPRayStructuredVolume(void) this->MakeSlotAvailable(&this->clippingBoxLower); this->MakeSlotAvailable(&this->clippingBoxUpper); - this->sliceNormal << new core::param::Vector3fParam({1.0f, 0.0f, 0.0f}); - this->sliceDist << new core::param::FloatParam(0.0f); - this->MakeSlotAvailable(&this->sliceNormal); - this->MakeSlotAvailable(&this->sliceDist); - - this->IsoValue << new core::param::FloatParam(0.0f); + this->IsoValue << new core::param::FloatParam(0.1f); this->MakeSlotAvailable(&this->IsoValue); - /*this->getDataSlot.SetCompatibleCall(); - this->MakeSlotAvailable(&this->getDataSlot);*/ this->getDataSlot.SetCompatibleCall(); this->MakeSlotAvailable(&this->getDataSlot); this->getTFSlot.SetCompatibleCall(); this->MakeSlotAvailable(&this->getTFSlot); + + this->showBoundingBox << new core::param::StringParam(""); + this->showBoundingBox.Parameter()->SetGUIReadOnly(true); + this->MakeSlotAvailable(&this->showBoundingBox); // this->SetSlotUnavailable(&this->getMaterialSlot); } @@ -137,23 +110,11 @@ bool OSPRayStructuredVolume::readData(megamol::core::Call& call) { return false; } - /*unsigned int voxelCount = - cd->VolumeDimension().GetDepth() * cd->VolumeDimension().GetHeight() * cd->VolumeDimension().GetWidth();*/ unsigned int const voxelCount = metadata->Resolution[0] * metadata->Resolution[1] * metadata->Resolution[2]; - - /*unsigned int maxDim = vislib::math::Max(cd->VolumeDimension().Depth(), - vislib::math::Max(cd->VolumeDimension().Height(), cd->VolumeDimension().Width()));*/ - - // float scale = 2.0f; - /*std::vector gridOrigin = {-0.5f * scale, -0.5f * scale, -0.5f * scale}; - std::vector gridSpacing = {scale / (float)maxDim, scale / (float)maxDim, scale / (float)maxDim}; - std::vector dimensions = {(int)cd->VolumeDimension().GetWidth(), (int)cd->VolumeDimension().GetHeight(), - (int)cd->VolumeDimension().GetDepth()};*/ - - std::vector gridOrigin = {metadata->Origin[0], metadata->Origin[1], metadata->Origin[2]}; - std::vector gridSpacing = { + std::array gridOrigin = {metadata->Origin[0], metadata->Origin[1], metadata->Origin[2]}; + std::array gridSpacing = { metadata->SliceDists[0][0], metadata->SliceDists[1][0], metadata->SliceDists[2][0]}; - std::vector dimensions = {static_cast(metadata->Resolution[0]), static_cast(metadata->Resolution[1]), + std::array dimensions = {static_cast(metadata->Resolution[0]), static_cast(metadata->Resolution[1]), static_cast(metadata->Resolution[2])}; //< TODO HAZARD explicit narrowing unsigned int const maxDim = @@ -236,46 +197,34 @@ bool OSPRayStructuredVolume::readData(megamol::core::Call& call) { this->structureContainer.type = structureTypeEnum::VOLUME; this->structureContainer.volumeType = volumeTypeEnum::STRUCTUREDVOLUME; - this->structureContainer.volRepType = + structuredVolumeStructure svs; + + svs.volRepType = (volumeRepresentationType)this->repType.Param()->Value(); - this->structureContainer.voxels = cd->GetData(); - this->structureContainer.gridOrigin = std::make_shared>(std::move(gridOrigin)); - this->structureContainer.gridSpacing = std::make_shared>(std::move(gridSpacing)); - this->structureContainer.dimensions = std::make_shared>(std::move(dimensions)); - this->structureContainer.voxelCount = voxelCount; - this->structureContainer.maxDim = maxDim; - this->structureContainer.valueRange = - std::make_shared>(metadata->MinValues[0], metadata->MaxValues[0]); - this->structureContainer.tfRGB = std::make_shared>(std::move(rgb)); - this->structureContainer.tfA = std::make_shared>(std::move(a)); - this->structureContainer.voxelDType = voxelType; - - this->structureContainer.clippingBoxActive = this->clippingBoxActive.Param()->Value(); - std::vector cbl = {this->clippingBoxLower.Param()->Value().GetX(), + svs.voxels = cd->GetData(); + svs.gridOrigin = gridOrigin; + svs.gridSpacing = gridSpacing; + svs.dimensions = dimensions; + svs.voxelCount = voxelCount; + svs.maxDim = maxDim; + svs.valueRange = {static_cast(metadata->MinValues[0]), static_cast(metadata->MaxValues[0])}; + svs.tfRGB = std::make_shared>(std::move(rgb)); + svs.tfA = std::make_shared>(std::move(a)); + svs.voxelDType = voxelType; + + svs.clippingBoxActive = this->clippingBoxActive.Param()->Value(); + std::array cbl = {this->clippingBoxLower.Param()->Value().GetX(), this->clippingBoxLower.Param()->Value().GetY(), this->clippingBoxLower.Param()->Value().GetZ()}; - this->structureContainer.clippingBoxLower = std::make_shared>(std::move(cbl)); - std::vector cbu = {this->clippingBoxUpper.Param()->Value().GetX(), + svs.clippingBoxLower = cbl; + std::array cbu = {this->clippingBoxUpper.Param()->Value().GetX(), this->clippingBoxUpper.Param()->Value().GetY(), this->clippingBoxUpper.Param()->Value().GetZ()}; - this->structureContainer.clippingBoxUpper = std::make_shared>(std::move(cbu)); - - std::vector sData = {this->sliceNormal.Param()->Value().GetX(), - this->sliceNormal.Param()->Value().GetY(), - this->sliceNormal.Param()->Value().GetZ(), - this->sliceDist.Param()->Value()}; - this->structureContainer.sliceData = std::make_shared>(std::move(sData)); + svs.clippingBoxUpper = cbu; - std::vector iValue = {this->IsoValue.Param()->Value()}; - this->structureContainer.isoValue = std::make_shared>(std::move(iValue)); + svs.isoValue = this->IsoValue.Param()->Value(); - this->structureContainer.useMIP = this->useMIP.Param()->Value(); - this->structureContainer.useAdaptiveSampling = this->useAdaptiveSampling.Param()->Value(); - this->structureContainer.useGradient = this->useGradient.Param()->Value(); - this->structureContainer.usePreIntegration = this->usePreIntegration.Param()->Value(); - this->structureContainer.adaptiveFactor = this->adaptiveFactor.Param()->Value(); - this->structureContainer.adaptiveMaxRate = this->adaptiveMaxRate.Param()->Value(); - this->structureContainer.samplingRate = this->samplingRate.Param()->Value(); + this->structureContainer.structure = svs; return true; } @@ -292,13 +241,11 @@ ospray::OSPRaySphereGeometry::InterfaceIsDirty() */ bool OSPRayStructuredVolume::InterfaceIsDirty() { if (this->clippingBoxActive.IsDirty() || this->clippingBoxLower.IsDirty() || this->clippingBoxUpper.IsDirty() || - this->sliceDist.IsDirty() || this->sliceNormal.IsDirty() || this->IsoValue.IsDirty() || + this->IsoValue.IsDirty() || this->repType.IsDirty()) { this->clippingBoxActive.ResetDirty(); this->clippingBoxLower.ResetDirty(); this->clippingBoxUpper.ResetDirty(); - this->sliceDist.ResetDirty(); - this->sliceNormal.ResetDirty(); this->IsoValue.ResetDirty(); this->repType.ResetDirty(); return true; @@ -324,6 +271,14 @@ bool OSPRayStructuredVolume::getExtends(megamol::core::Call& call) { this->extendContainer.boundingBox = std::make_shared(); this->extendContainer.boundingBox->SetBoundingBox(cd->AccessBoundingBoxes().ObjectSpaceBBox()); + std::string bbox_string = + "LEFT: " + std::to_string(extendContainer.boundingBox->BoundingBox().Left()) + + ";\nBOTTOM: " + std::to_string(extendContainer.boundingBox->BoundingBox().Bottom()) + + ";\nBACK: " + std::to_string(extendContainer.boundingBox->BoundingBox().Back()) + + ";\nRIGHT: " + std::to_string(extendContainer.boundingBox->BoundingBox().Right()) + + ";\nTOP: " + std::to_string(extendContainer.boundingBox->BoundingBox().Top()) + + ";\nFRONT: " + std::to_string(extendContainer.boundingBox->BoundingBox().Bottom()); + this->showBoundingBox.Param()->SetValue(bbox_string.c_str()); this->extendContainer.timeFramesCount = cd->FrameCount(); this->extendContainer.isValid = true; diff --git a/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.h b/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.h index b2ff56f92a..bebc24dae3 100644 --- a/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.h +++ b/plugins/OSPRay_plugin/src/OSPRayStructuredVolume.h @@ -60,21 +60,12 @@ class OSPRayStructuredVolume : public AbstractOSPRayStructure { megamol::core::param::ParamSlot clippingBoxLower; megamol::core::param::ParamSlot clippingBoxUpper; megamol::core::param::ParamSlot clippingBoxActive; + megamol::core::param::ParamSlot showBoundingBox; megamol::core::param::ParamSlot repType; - megamol::core::param::ParamSlot useMIP; - megamol::core::param::ParamSlot useGradient; - megamol::core::param::ParamSlot usePreIntegration; - megamol::core::param::ParamSlot useAdaptiveSampling; - megamol::core::param::ParamSlot adaptiveFactor; - megamol::core::param::ParamSlot adaptiveMaxRate; - megamol::core::param::ParamSlot samplingRate; - megamol::core::param::ParamSlot IsoValue; - megamol::core::param::ParamSlot sliceNormal; - megamol::core::param::ParamSlot sliceDist; }; } // namespace ospray -} // namespace megamol \ No newline at end of file +} // namespace megamol diff --git a/plugins/OSPRay_plugin/src/OSPRayThinGlassMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayThinGlassMaterial.cpp index 0dff2ed447..34d85120c4 100644 --- a/plugins/OSPRay_plugin/src/OSPRayThinGlassMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayThinGlassMaterial.cpp @@ -34,12 +34,18 @@ OSPRayThinGlassMaterial::~OSPRayThinGlassMaterial(void) { void OSPRayThinGlassMaterial::readParams() { materialContainer.materialType = materialTypeEnum::THINGLASS; + thinglassMaterial tgm; + auto transmission = this->thinglassTransmission.Param(); - materialContainer.thinglassTransmission = transmission->getArray(); + tgm.thinglassTransmission = transmission->getArray(); + + tgm.thinglassEta = + this->thinglassEta.Param()->Value(); - materialContainer.thinglassEta = this->thinglassEta.Param()->Value(); + tgm.thinglassThickness = + this->thinglassThickness.Param()->Value(); - materialContainer.thinglassThickness = this->thinglassThickness.Param()->Value(); + materialContainer.material = tgm; } bool OSPRayThinGlassMaterial::InterfaceIsDirty() { @@ -55,4 +61,4 @@ bool OSPRayThinGlassMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRayVelvetMaterial.cpp b/plugins/OSPRay_plugin/src/OSPRayVelvetMaterial.cpp index bb6504cfdd..f653a44a10 100644 --- a/plugins/OSPRay_plugin/src/OSPRayVelvetMaterial.cpp +++ b/plugins/OSPRay_plugin/src/OSPRayVelvetMaterial.cpp @@ -38,14 +38,16 @@ void OSPRayVelvetMaterial::readParams() { materialContainer.materialType = materialTypeEnum::VELVET; auto reflect = this->velvetReflectance.Param(); - materialContainer.velvetReflectance = reflect->getArray(); + std::get(materialContainer.material).velvetReflectance = reflect->getArray(); auto color = this->velvetHorizonScatteringColor.Param(); - materialContainer.velvetHorizonScatteringColor = color->getArray(); + std::get(materialContainer.material).velvetHorizonScatteringColor = color->getArray(); - materialContainer.velvetBackScattering = this->velvetBackScattering.Param()->Value(); + std::get(materialContainer.material).velvetBackScattering = + this->velvetBackScattering.Param()->Value(); - materialContainer.velvetHorizonScatteringFallOff = this->velvetHorizonScatteringFallOff.Param()->Value(); + std::get(materialContainer.material).velvetHorizonScatteringFallOff = + this->velvetHorizonScatteringFallOff.Param()->Value(); } bool OSPRayVelvetMaterial::InterfaceIsDirty() { @@ -63,4 +65,4 @@ bool OSPRayVelvetMaterial::InterfaceIsDirty() { } else { return false; } -} \ No newline at end of file +} diff --git a/plugins/OSPRay_plugin/src/OSPRay_plugin.cpp b/plugins/OSPRay_plugin/src/OSPRay_plugin.cpp index db5e977e51..dde47ca75e 100644 --- a/plugins/OSPRay_plugin/src/OSPRay_plugin.cpp +++ b/plugins/OSPRay_plugin/src/OSPRay_plugin.cpp @@ -18,11 +18,9 @@ #include "OSPRayAPIStructure.h" #include "OSPRayLineGeometry.h" #include "OSPRayNHSphereGeometry.h" -#include "OSPRayCylinderGeometry.h" #include "OSPRaySphereGeometry.h" #include "OSPRayStructuredVolume.h" -#include "OSPRayTriangleMesh.h" -#include "OSPRayQuadMesh.h" +#include "OSPRayMeshGeometry.h" #include "OSPRay_plugin/CallOSPRayAPIObject.h" #include "OSPRay_plugin/CallOSPRayStructure.h" #include "OSPRayAOVSphereGeometry.h" @@ -39,6 +37,7 @@ #include "OSPRayVelvetMaterial.h" #include "OSPRay_plugin/CallOSPRayMaterial.h" #include "Pkd.h" +#include "OSPRayGeometryTest.h" namespace megamol::ospray { /** Implementing the instance class of this plugin */ @@ -70,12 +69,11 @@ class plugin_instance : public ::megamol::core::utility::plugins::Plugin200Insta this->module_descriptions.RegisterAutoDescription(); this->module_descriptions.RegisterAutoDescription(); - this->module_descriptions.RegisterAutoDescription(); + this->module_descriptions.RegisterAutoDescription(); this->module_descriptions.RegisterAutoDescription(); this->module_descriptions.RegisterAutoDescription(); this->module_descriptions.RegisterAutoDescription(); - this->module_descriptions.RegisterAutoDescription(); - this->module_descriptions.RegisterAutoDescription(); + this->module_descriptions.RegisterAutoDescription(); this->module_descriptions.RegisterAutoDescription(); this->module_descriptions.RegisterAutoDescription(); diff --git a/plugins/OSPRay_plugin/src/Pkd.cpp b/plugins/OSPRay_plugin/src/Pkd.cpp index 1346442e84..45a72430b6 100644 --- a/plugins/OSPRay_plugin/src/Pkd.cpp +++ b/plugins/OSPRay_plugin/src/Pkd.cpp @@ -74,14 +74,14 @@ void ospray::Pkd::setDim(size_t ID, int dim) const { #if DIM_FROM_DEPTH return; #else - ospcommon::vec3f& particle = (ospcommon::vec3f&)this->model->position[ID]; + rkcommon::math::vec3f& particle = (rkcommon::math::vec3f&) this->model->position[ID]; int& pxAsInt = (int&)particle.x; pxAsInt = (pxAsInt & ~3) | dim; #endif } -inline size_t ospray::Pkd::maxDim(const ospcommon::vec3f& v) const { - const float maxVal = ospcommon::reduce_max(v); +inline size_t ospray::Pkd::maxDim(const rkcommon::math::vec3f& v) const { + const float maxVal = rkcommon::math::reduce_max(v); if (maxVal == v.x) { return 0; } else if (maxVal == v.y) { @@ -129,14 +129,14 @@ void ospray::Pkd::build() { } // PRINT(numLevels); - const ospcommon::box3f& bounds = model->getBounds(); + const rkcommon::math::box3f& bounds = model->getBounds(); /*std::cout << "#osp:pkd: bounds of model " << bounds << std::endl; std::cout << "#osp:pkd: number of input particles " << numParticles << std::endl;*/ this->buildRec(0, bounds, 0); } -void ospray::Pkd::buildRec(const size_t nodeID, const ospcommon::box3f& bounds, const size_t depth) const { +void ospray::Pkd::buildRec(const size_t nodeID, const rkcommon::math::box3f& bounds, const size_t depth) const { // if (depth < 4) // std::cout << "#osp:pkd: building subtree " << nodeID << std::endl; if (!hasLeftChild(nodeID)) @@ -230,8 +230,8 @@ void ospray::Pkd::buildRec(const size_t nodeID, const ospcommon::box3f& bounds, } } - ospcommon::box3f lBounds = bounds; - ospcommon::box3f rBounds = bounds; + rkcommon::math::box3f lBounds = bounds; + rkcommon::math::box3f rBounds = bounds; setDim(nodeID, dim); diff --git a/plugins/OSPRay_plugin/src/Pkd.h b/plugins/OSPRay_plugin/src/Pkd.h index b2d7b3cd03..0ddc4e3364 100644 --- a/plugins/OSPRay_plugin/src/Pkd.h +++ b/plugins/OSPRay_plugin/src/Pkd.h @@ -9,8 +9,9 @@ #include "mmcore/CallerSlot.h" #include "mmcore/moldyn/MultiParticleDataCall.h" #include "mmstd_datatools/AbstractParticleManipulator.h" -#include "ospray/ospcommon/box.h" -#include "ospray/ospcommon/vec.h" +#include "rkcommon/math/box.h" +#include "rkcommon/math/vec.h" + #include "pkd/ParticleModel.h" @@ -74,12 +75,12 @@ struct Pkd { // save the given particle's split dimension void setDim(size_t ID, int dim) const; - inline size_t maxDim(const ospcommon::vec3f& v) const; + inline size_t maxDim(const rkcommon::math::vec3f& v) const; //! build particle tree over given model. WILL REORDER THE MODEL'S ELEMENTS void build(); - void buildRec(const size_t nodeID, const ospcommon::box3f& bounds, const size_t depth) const; + void buildRec(const size_t nodeID, const rkcommon::math::box3f& bounds, const size_t depth) const; }; @@ -113,9 +114,9 @@ struct SubtreeIterator { struct PKDBuildJob { const Pkd* const pkd; const size_t nodeID; - const ospcommon::box3f bounds; + const rkcommon::math::box3f bounds; const size_t depth; - __forceinline PKDBuildJob(const Pkd* pkd, size_t nodeID, ospcommon::box3f bounds, size_t depth) + __forceinline PKDBuildJob(const Pkd* pkd, size_t nodeID, rkcommon::math::box3f bounds, size_t depth) : pkd(pkd), nodeID(nodeID), bounds(bounds), depth(depth){}; }; diff --git a/plugins/OSPRay_plugin/src/pkd/ParticleModel.cpp b/plugins/OSPRay_plugin/src/pkd/ParticleModel.cpp index 5ed2b6c12a..b139645e8b 100644 --- a/plugins/OSPRay_plugin/src/pkd/ParticleModel.cpp +++ b/plugins/OSPRay_plugin/src/pkd/ParticleModel.cpp @@ -46,18 +46,18 @@ typedef unsigned char (*byteColFromArrayFunc)( const megamol::core::moldyn::MultiParticleDataCall::Particles& p, size_t index); -inline ospcommon::vec3f makeRandomColor(const int i) { +inline rkcommon::math::vec3f makeRandomColor(const int i) { const int mx = 13 * 17 * 43; const int my = 11 * 29; const int mz = 7 * 23 * 63; const uint32_t g = (i * (3 * 5 * 127) + 12312314); - return ospcommon::vec3f((g % mx) * (1.f / (mx - 1)), (g % my) * (1.f / (my - 1)), (g % mz) * (1.f / (mz - 1))); + return rkcommon::math::vec3f((g % mx) * (1.f / (mx - 1)), (g % my) * (1.f / (my - 1)), (g % mz) * (1.f / (mz - 1))); } //! return world bounding box of all particle *positions* (i.e., particles *ex* radius) -ospcommon::box3f ospray::ParticleModel::getBounds() const { - ospcommon::box3f bounds = ospcommon::empty; +rkcommon::math::box3f ospray::ParticleModel::getBounds() const { + rkcommon::math::box3f bounds = rkcommon::math::empty; for (size_t i = 0; i < position.size(); ++i) bounds.extend({position[i].x, position[i].y, position[i].z}); return bounds; } @@ -87,13 +87,13 @@ void megamol::ospray::ParticleModel::fill(megamol::core::moldyn::SimpleSpherical for (size_t loop = 0; loop < parts.GetCount(); ++loop) { - ospcommon::vec3f pos; + rkcommon::math::vec3f pos; pos.x = xAcc->Get_f(loop); pos.y = yAcc->Get_f(loop); pos.z = zAcc->Get_f(loop); - ospcommon::vec4uc col; + rkcommon::math::vec4uc col; col.x = rAcc->Get_u8(loop); col.y = gAcc->Get_u8(loop); diff --git a/plugins/OSPRay_plugin/src/pkd/ParticleModel.h b/plugins/OSPRay_plugin/src/pkd/ParticleModel.h index c818dc2bed..ba49c76f60 100644 --- a/plugins/OSPRay_plugin/src/pkd/ParticleModel.h +++ b/plugins/OSPRay_plugin/src/pkd/ParticleModel.h @@ -12,7 +12,8 @@ #include "mmcore/moldyn/MultiParticleDataCall.h" -#include "ospcommon/box.h" +#include "rkcommon/math//box.h" +#include "rkcommon/math/vec.h" namespace megamol { @@ -23,14 +24,14 @@ struct ParticleModel { ParticleModel() : radius(0) {} - std::vector position; //!< particle position + color encoded in 'w' + std::vector position; //!< particle position + color encoded in 'w' void fill(megamol::core::moldyn::SimpleSphericalParticles parts); //! return world bounding box of all particle *positions* (i.e., particles *ex* radius) - ospcommon::box3f getBounds() const; + rkcommon::math::box3f getBounds() const; - float encodeColorToFloat(ospcommon::vec4f const& col) { + float encodeColorToFloat(rkcommon::math::vec4f const& col) { unsigned int r = static_cast(col.x * 255.f); unsigned int g = static_cast(col.y * 255.f); unsigned int b = static_cast(col.z * 255.f); @@ -44,7 +45,7 @@ struct ParticleModel { return ret; } - float encodeColorToFloat(ospcommon::vec4uc const& col) { + float encodeColorToFloat(rkcommon::math::vec4uc const& col) { unsigned int r = static_cast(col.x); unsigned int g = static_cast(col.y); unsigned int b = static_cast(col.z); @@ -58,7 +59,7 @@ struct ParticleModel { return ret; } - float encodeColorToFloat(ospcommon::vec3f const& col) { + float encodeColorToFloat(rkcommon::math::vec3f const& col) { unsigned int r = static_cast(col.x * 255.f); unsigned int g = static_cast(col.y * 255.f); unsigned int b = static_cast(col.z * 255.f); @@ -71,7 +72,7 @@ struct ParticleModel { return ret; } - float encodeColorToFloat(ospcommon::vec3uc const& col) { + float encodeColorToFloat(rkcommon::math::vec3uc const& col) { unsigned int r = static_cast(col.x); unsigned int g = static_cast(col.y); unsigned int b = static_cast(col.z);