diff --git a/data/assets/scene/solarsystem/heliosphere/cutplane/test.asset b/data/assets/scene/solarsystem/heliosphere/cutplane/test.asset index d9cbbd71fb..25e7a0a452 100644 --- a/data/assets/scene/solarsystem/heliosphere/cutplane/test.asset +++ b/data/assets/scene/solarsystem/heliosphere/cutplane/test.asset @@ -1,5 +1,5 @@ local transforms = asset.require("scene/solarsystem/planets/earth/transforms") -local path = "C:/Users/eolsson/Documents/openspace/data/2012/3d__var_1_e20120714-160000-000.out.cdf" +local path = "C:/Users/eolsson/Documents/openspace/data/2023/marchstorm/cdfs/all/SWMF-01_2023-03-TP-01_080123_2_cdf/GM_CDF/3d__var_1_e20230321-000000-000.out.cdf" local cutplane = { Identifier = "Test-cutplane", diff --git a/modules/base/rendering/renderablecutplane.cpp b/modules/base/rendering/renderablecutplane.cpp index 156f12d804..bdac665677 100644 --- a/modules/base/rendering/renderablecutplane.cpp +++ b/modules/base/rendering/renderablecutplane.cpp @@ -37,12 +37,37 @@ constexpr openspace::properties::Property::PropertyInfo FilePathInfo = { " ", openspace::properties::Property::Visibility::User }; - constexpr openspace::properties::Property::PropertyInfo DataPropertyInfo = { - "DataProperty", - "Name of the data property", - "Data property to color the cutplane by", - openspace::properties::Property::Visibility::User + "DataProperty", + "Name of the data property", + "Data property to color the cutplane by", + openspace::properties::Property::Visibility::User +}; +constexpr openspace::properties::Property::PropertyInfo AxisInfo = { + "Axis", + "The x, y or z axis", + "Axis to cut the volume on", + openspace::properties::Property::Visibility::User +}; +constexpr openspace::properties::Property::PropertyInfo CutValueInfo = { + "CutValue", + "A value within the volume dimension", + "A value to cut the plane on within the dimension of the selected axis", + openspace::properties::Property::Visibility::User +}; +constexpr openspace::properties::Property::PropertyInfo ColorTablePathsInfo = { + "ColorTablePaths", + "A local varibale of a local color transfer function", + "A list of paths to transferfunction .txt files containing color tables used for " + "colorizing the cutplane according to different data properties", + openspace::properties::Property::Visibility::User +}; +constexpr openspace::properties::Property::PropertyInfo ColorTableRangesInfo = { + "ColorTableRanges", + "Values of a range", + "List of ranges for which their corresponding data property values will be colorized " + "by. Should be entered as {min value, max value} per range", + openspace::properties::Property::Visibility::User }; struct [[codegen::Dictionary(RenderableCutPlane)]] Parameters { @@ -50,6 +75,14 @@ struct [[codegen::Dictionary(RenderableCutPlane)]] Parameters { std::filesystem::path input; // [[codegen::verbatim(DataPropertyInfo.description)]] std::string dataProperty; + // [[codegen::verbatim(AxisInfo.description)]] + std::string axis; + // [[codegen::verbatim(CutValueInfo.description)]] + float cutValue; + // [[codegen::verbatim(ColorTablePathsInfo.description)]] + std::optional> colorTablePaths; + // [[codegen::verbatim(ColorTableRangesInfo.description)]] + std::optional> colorTableRanges; }; #include "renderablecutplane_codegen.cpp" } // namespace @@ -71,6 +104,26 @@ RenderableCutPlane::RenderableCutPlane(const ghoul::Dictionary& dictionary) _inputPath = absPath(p.input); _dataProperty = p.dataProperty; + _axis = p.axis; + _cutValue = p.cutValue; + + if (p.colorTablePaths.has_value()) { + _colorTablePaths = p.colorTablePaths.value(); + } + if (p.colorTableRanges.has_value()) { + _colorTableRanges = *p.colorTableRanges; + } + else { + _colorTableRanges.push_back(glm::vec2(0.f, 1.f)); + } + + if (_inputPath.extension() == ".cdf") { + readCdfFile(); + } + if (_inputPath.extension() == ".h5") { + readh5File(); + } + } void RenderableCutPlane::initialize() { @@ -78,26 +131,51 @@ void RenderableCutPlane::initialize() { throw ghoul::FileNotFoundError(_inputPath.string()); } + // Load cdf file + //Extract slice from data +} + +void RenderableCutPlane::readCdfFile() { std::unique_ptr kameleon = kameleonHelper::createKameleonObject( _inputPath.string() ); long status = kameleon->open(_inputPath.string()); if (status != ccmc::FileReader::OK) { - throw ghoul::RuntimeError(fmt::format( + throw ghoul::RuntimeError(std::format( "Failed to open file '{}' with Kameleon", _inputPath )); } + if (!kameleon->doesAttributeExist(_dataProperty)) { + LERROR(std::format("'{}' does not exists in data volume", _dataProperty)); + } - LINFO(fmt::format("Model name: '{}'", kameleon->getModelName())); - std::cout << "Filename: " << kameleon->getCurrentFilename() << std::endl; - std::cout << "Number of variables: " << kameleon->getNumberOfVariables() << std::endl; - std::cout << "Number of variable attributes: " << kameleon->getNumberOfVariableAttributes() << std::endl; - std::cout << "Current time: " << kameleon->getCurrentTime() << std::endl; + LINFO(std::format("Model name: '{}'", kameleon->getModelName())); + LINFO(std::format("Filename: '{}'", kameleon->getCurrentFilename())); + int number = kameleon->getNumberOfVariables(); + LINFO(std::format("Number of variables: '{}'", number)); + for (int i = 0; i < number; ++i) { + LINFO(std::format("Variable name: '{}'", kameleon->getVariableAttributeName(i))); + } + int globalnumber = kameleon->getNumberOfGlobalAttributes(); + LINFO(std::format("Number of global variables: '{}'", globalnumber)); + for (int i = 0; i < globalnumber; ++i) { + LINFO(std::format("global variable name: '{}'", kameleon->getGlobalAttributeName(i))); + } + LINFO(std::format("Number of variable attributes: '{}'", kameleon->getNumberOfVariableAttributes())); + LINFO(std::format("Current time: '{}'", kameleon->getCurrentTime().toString())); + + loadDataFromSlice(); - // Load cdf file - //Extract slice from data + +} +void RenderableCutPlane::readh5File() { + +} + +void RenderableCutPlane::loadDataFromSlice() { + _slicer = VolumeSlicer(_inputPath, _axis, _cutValue); } void RenderableCutPlane::initializeGL() { @@ -109,7 +187,7 @@ void RenderableCutPlane::deinitializeGL() { //RenderablePlane::deinitializeGL(); } -void RenderableCutPlane::render(const RenderData& data, RendererTasks& t) { +void RenderableCutPlane::render(const RenderData& data, RendererTasks& task) { } diff --git a/modules/base/rendering/renderablecutplane.h b/modules/base/rendering/renderablecutplane.h index b51e1eb3f7..dae24be133 100644 --- a/modules/base/rendering/renderablecutplane.h +++ b/modules/base/rendering/renderablecutplane.h @@ -27,7 +27,9 @@ #include +#include #include +#include #include #include #include @@ -68,6 +70,9 @@ public: RenderableCutPlane(const ghoul::Dictionary& dictionary); void initialize() override; + void readCdfFile(); + void readh5File(); + void loadDataFromSlice(); void initializeGL() override; void deinitializeGL() override; @@ -82,6 +87,15 @@ private: std::filesystem::path _inputPath; // What data property to render std::string _dataProperty; + std::string _axis; + std::string _cutValue; + std::vector _colorTablePaths; + std::vector _colorTableRanges; + + std::unique_ptr _texture = nullptr; + std::unique_ptr _transferFunction; + + VolumeSlicer _slicer; std::unique_ptr _kameleon; std::unique_ptr _interpolator; diff --git a/modules/base/util/volumeslicer.cpp b/modules/base/util/volumeslicer.cpp new file mode 100644 index 0000000000..3ee7b0975d --- /dev/null +++ b/modules/base/util/volumeslicer.cpp @@ -0,0 +1,40 @@ +///***************************************************************************************** +// * * +// * OpenSpace * +// * * +// * Copyright (c) 2014-2024 * +// * * +// * Permission is hereby granted, free of charge, to any person obtaining a copy of this * +// * software and associated documentation files (the "Software"), to deal in the Software * +// * without restriction, including without limitation the rights to use, copy, modify, * +// * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +// * permit persons to whom the Software is furnished to do so, subject to the following * +// * conditions: * +// * * +// * The above copyright notice and this permission notice shall be included in all copies * +// * or substantial portions of the Software. * +// * * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +// * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +// * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +// * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +// * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +// * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +// ****************************************************************************************/ + +#include + +#include + +namespace openspace { + constexpr std::string_view _loggerCat = "CutPlaneSlicer"; + +VolumeSlicer::VolumeSlicer(std::filesystem::path path, std::string axis, int cutValue) { + _dataProperyNames; + _volumeDimentions; + _data; +} + + +} // namespace openspace + diff --git a/modules/base/util/volumeslicer.h b/modules/base/util/volumeslicer.h new file mode 100644 index 0000000000..9ce1478894 --- /dev/null +++ b/modules/base/util/volumeslicer.h @@ -0,0 +1,44 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2024 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___VOLUMESLICER___H__ +#define __OPENSPACE_MODULE_BASE___VOLUMESLICER___H__ + + +namespace openspace { + class VolumeSlicer { + public: + VolumeSlicer() = default; + VolumeSlicer(std::filesystem::path path, std::string axis, std::string cutValue); + void getSlicer(); + + private: + std::vector _dataProperyNames; + std::vector _volumeDimentions; + std::vector>> _data; + + }; +} + +#endif //__OPENSPACE_MODULE_BASE___VOLUMESLICER___H__