/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2015 * * * * 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 namespace { const std::string _loggerCat = "DataProcessorKameleon"; } namespace openspace{ DataProcessorKameleon::DataProcessorKameleon() :DataProcessor() ,_kwPath("") ,_kw(nullptr) ,_initialized(false) ,_slice(0.5) {} DataProcessorKameleon::~DataProcessorKameleon(){} std::vector DataProcessorKameleon::readMetadata(std::string path, glm::size3_t& dimensions){ if(!path.empty()){ if(path != _kwPath || !_kw){ initializeKameleonWrapper(path); } std::vector opts = _kw->getVariables(); opts.erase( std::remove_if( opts.begin(), opts.end(), [this](std::string opt){ return (opt.size() > 3 || _coordinateVariables.find(opt) != _coordinateVariables.end());} ), opts.end() ); return opts; } return std::vector(); } void DataProcessorKameleon::addDataValues(std::string path, properties::SelectionProperty& dataOptions){ int numOptions = dataOptions.options().size(); initializeVectors(numOptions); if(!path.empty()){ if(path != _kwPath || !_kw) initializeKameleonWrapper(path); std::vector sum(numOptions, 0.0f); std::vector> optionValues(numOptions, std::vector()); auto options = dataOptions.options(); int numValues = _dimensions.x*_dimensions.y*_dimensions.z; float* values; float value; for(int i=0; igetUniformSliceValues(options[i].description, _dimensions, 0.5f); for(int j=0; j DataProcessorKameleon::processData(std::string path, properties::SelectionProperty& dataOptions, glm::size3_t& dimensions, float slice){ _slice = slice; // _dimensions = dimensions; return processData(path, dataOptions, dimensions); } std::vector DataProcessorKameleon::processData(std::string path, properties::SelectionProperty& dataOptions, glm::size3_t& dimensions){ int numOptions = dataOptions.options().size(); if(!path.empty()){ if(path != _kwPath || !_kw) initializeKameleonWrapper(path); std::vector selectedOptions = dataOptions.value(); int numSelected = selectedOptions.size(); auto options = dataOptions.options(); int numOptions = options.size(); int numValues = dimensions.x*dimensions.y*dimensions.z; float value; std::vector dataOptions(numOptions, nullptr); for(int option : selectedOptions){ dataOptions[option] = _kw->getUniformSliceValues(options[option].description, dimensions, _slice); for(int i=0; i(numOptions, nullptr); } void DataProcessorKameleon::initializeKameleonWrapper(std::string path){ const std::string& extension = ghoul::filesystem::File(absPath(path)).fileExtension(); if(FileSys.fileExists(absPath(path)) && extension == "cdf"){ if(_kw) _kw->close(); _kwPath = path; _kw = std::make_shared(absPath(_kwPath)); } } }//namespace openspace