diff --git a/modules/fieldlinessequence/fieldlinessequencemodule.cpp b/modules/fieldlinessequence/fieldlinessequencemodule.cpp index 0f3e8a7243..8ebbbe8a95 100644 --- a/modules/fieldlinessequence/fieldlinessequencemodule.cpp +++ b/modules/fieldlinessequence/fieldlinessequencemodule.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -60,16 +61,18 @@ FieldlinesSequenceModule::FieldlinesSequenceModule() : OpenSpaceModule(Name) { } void FieldlinesSequenceModule::internalInitialize(const ghoul::Dictionary&) { + ghoul::TemplateFactory* fTask = FactoryManager::ref().factory(); ghoul::TemplateFactory* factory = FactoryManager::ref().factory(); ghoul_assert(factory, "No renderable factory existed"); - + fTask->registerClass("KameleonVolumeToFieldlinesTask"); factory->registerClass("RenderableFieldlinesSequence"); } std::vector FieldlinesSequenceModule::documentations() const { return { + KameleonVolumeToFieldlinesTask::Documentation(); RenderableFieldlinesSequence::Documentation() }; } diff --git a/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp new file mode 100644 index 0000000000..ac3995d1dd --- /dev/null +++ b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp @@ -0,0 +1,182 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr const char* _loggerCat = "KameleonVolumeToFieldlinesTask"; + constexpr const char* KeyInput = "Input"; + constexpr const char* KeyTimeKernel = "TimeKernel"; + constexpr const char* KeyOutputFolder = "OutputFolder"; + constexpr const char* KeySeedpoints = "Seedpoints"; + constexpr const char* KeyTracingVar = "TracingVar"; + constexpr const char* KeyExtraScalarVars = "ExtraScalarVars"; + constexpr const char* KeyExtraMagnitudeVars = "ExtraMagnitudeVars"; +} // namespace + +namespace openspace { + + documentation::Documentation KameleonVolumeToFieldlinesTask::documentation() { + using namespace documentation; + return { + "KameleonVolumeToFieldlinesTask", + "kameleon_metadata_to_fieldlines_task", + { + { + "Type", + new StringEqualVerifier("KameleonVolumeToFieldlinesTask"), + Optional::No, + "The type of this task", + }, + { + KeyInput, + new StringAnnotationVerifier("A file path to a cdf file"), + Optional::No, + "The cdf file to extract data from", + }, + { + KeyTimeKernel, + new StringAnnotationVerifier("A file path to a cdf file"), + Optional::No, + "A file path to a tls spice kernel used for time", + }, + { + KeyTracingVar, + new StringAnnotationVerifier("A kameleon variable name"), + Optional::No, + "The name of the kameleon variable to use for tracing", + }, + { + KeyOutputFolder, + new StringAnnotationVerifier("A valid path to a folder"), + Optional::No, + "The folder to write the osfls file to", + }, + { + KeySeedpoints, + new StringAnnotationVerifier("A valid filepath"), + Optional::No, + "A text file with seedpoints with the format x1 y1 z1 x2 y2 z2 ... " + "Seedpoints are expressed in the native coordinate system of the model." + }, + { + KeyExtraScalarVars, + new StringListVerifier("A list of kameleon variables"), + Optional::Yes, + "A list of scalar variables to extract along the fieldlines", + }, + { + KeyExtraMagnitudeVars, + new StringListVerifier("A list of kameleon variables"), + Optional::Yes, + "A list of vector variables whose magnitude to extract along the " + "fieldlines", + }, + } + }; + } + + + KameleonVolumeToFieldlinesTask::KameleonVolumeToFieldlinesTask( + const ghoul::Dictionary& dictionary) + { + openspace::documentation::testSpecificationAndThrow( + documentation(), + dictionary, + "KameleonVolumeToFieldlinesTask" + ); + _inputPath = absPath(dictionary.value(KeyInput)); + _timeKernelPath = absPath(dictionary.value(KeyTimeKernel)); + _seedpointsPath = absPath(dictionary.value(KeySeedpoints)); + _outputFolder = absPath(dictionary.value(KeyOutputFolder)); + _tracingVar = dictionary.value(KeyTracingVar); + + if (dictionary.hasKey(KeyExtraScalarVars)) { + ghoul::Dictionary list = dictionary.value(KeyExtraScalarVars); + for (size_t i = 0; i < list.size(); ++i) { + _extraScalarVars.push_back(list.value(std::to_string(i))); + } + } + if (dictionary.hasKey(KeyExtraMagnitudeVars)) { + ghoul::Dictionary list = + dictionary.value(KeyExtraMagnitudeVars); + + for (size_t i = 0; i < list.size(); ++i) { + _extraMagnitudeVars.push_back(list.value(std::to_string(i))); + } + } + } + + std::string KameleonVolumeToFieldlinesTask::description() { + return fmt::format( + "Extract fieldline data from cdf file {} and seedpoint file {}. " + "Write osfls file into the folder {}.", + _inputPath, _seedpointsPath, _outputFolder + ); + } + + void KameleonVolumeToFieldlinesTask::perform( + const Task::ProgressCallback& progressCallback) + { + + std::vector seedPoints; + bool readSeedpoints = fls::extractSeedPointsFromFile(_seedpointsPath, seedPoints); + + if (!readSeedpoints) { + LERROR("Falied to read seedpoints"); + return; + } + + SpiceManager::ref().loadKernel(_timeKernelPath); + + FieldlinesState newState; + bool isSuccessful = fls::convertCdfToFieldlinesState( + newState, + _inputPath, + seedPoints, + _tracingVar, + _extraScalarVars, + _extraMagnitudeVars + ); + + if (isSuccessful) { + return newState.saveStateToOsfls(_outputFolder); + } + + // Ideally, we would want to signal about progress earlier as well, but + // convertCdfToFieldlinesState does all the work encapsulated in one function call. + progressCallback(1.0f); + } + +} // namespace openspace diff --git a/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h new file mode 100644 index 0000000000..43a11d2bf4 --- /dev/null +++ b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h @@ -0,0 +1,56 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * 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_FIELDLINESSEQUENCE___KAMELEONVOLUMETOFIELDLINESTASK___H__ +#define __OPENSPACE_MODULE_FIELDLINESSEQUENCE___KAMELEONVOLUMETOFIELDLINESTASK___H__ + +#include + +#include +#include +#include + +namespace openspace { + + class KameleonVolumeToFieldlinesTask : public Task { + public: + KameleonVolumeToFieldlinesTask(const ghoul::Dictionary& dictionary); + + std::string description() override; + void perform(const Task::ProgressCallback& progressCallback) override; + static documentation::Documentation documentation(); + + private: + std::string _tracingVar; + std::vector _extraScalarVars; + std::vector _extraMagnitudeVars; + std::filesystem::path _inputPath; + //std::string _timeKernelPath; + std::string _seedpointsPath; + std::string _outputFolder; + }; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_FIELDLINESSEQUENCE___KAMELEONVOLUMETOFIELDLINESTASK___H__