Implement Operator base class and fix circ. dependencies

This commit is contained in:
Jonathan Grangien
2018-06-08 14:57:18 -04:00
committed by Matthias Berg
parent dea5b58c79
commit a40cd79252
13 changed files with 193 additions and 41 deletions

View File

@@ -26,15 +26,19 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/dataloadermodule.h
${CMAKE_CURRENT_SOURCE_DIR}/reader.h
${CMAKE_CURRENT_SOURCE_DIR}/loader.h
${CMAKE_CURRENT_SOURCE_DIR}/helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/operators/operator.h
${CMAKE_CURRENT_SOURCE_DIR}/operators/reader.h
${CMAKE_CURRENT_SOURCE_DIR}/operators/loader.h
)
source_group("Header Files" FILES ${HEADER_FILES})
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/dataloadermodule.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/loader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/operators/operator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/operators/reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/operators/loader.cpp
)
option(OPENSPACE_MODULE_DATALOADER "Use Data Loader Module" ON)

View File

@@ -23,27 +23,59 @@
****************************************************************************************/
#include <modules/dataloader/dataloadermodule.h>
#include <modules/dataloader/reader.h>
#include <modules/dataloader/loader.h>
#include <openspace/util/factorymanager.h>
#include <modules/dataloader/operators/reader.h>
#include <modules/dataloader/operators/loader.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/openspaceengine.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
namespace {
constexpr const char* _loggerCat = "DataLoaderModule";
}
namespace openspace {
using namespace dataloader;
DataLoaderModule::DataLoaderModule() : OpenSpaceModule(Name) {}
void DataLoaderModule::internalInitialize(const ghoul::Dictionary&) {
// auto rFactory = FactoryManager::ref().factory<Renderable>();
// ghoul_assert(rFactory, "No renderable factory existed");
// rFactory->registerClass<RenderableTimeVaryingVolume>("RenderableTimeVaryingVolume");
DataLoaderModule::~DataLoaderModule() {}
_reader = std::make_unique<openspace::dataloader::Reader>();
_loader = std::make_unique<openspace::dataloader::Loader>();
addPropertySubOwner(*_reader);
addPropertySubOwner(*_loader);
void DataLoaderModule::internalInitialize(const ghoul::Dictionary&) {
OsEng.registerModuleCallback(OpenSpaceEngine::CallbackOption::Initialize, [&] {
_reader = std::make_unique<openspace::dataloader::Reader>();
_loader = std::make_unique<openspace::dataloader::Loader>();
addPropertySubOwner(*_reader);
addPropertySubOwner(*_loader);
});
}
void DataLoaderModule::setDataDirectoryRead(bool isRead) {
LDEBUG("Called a module function");
_dataDirectoryIsRead = isRead;
}
void DataLoaderModule::validateDataDirectory() {
if(!_dataDirectoryIsRead) {
_reader->readVolumeDataItems();
}
}
std::vector<std::string> DataLoaderModule::volumeDataItems() {
validateDataDirectory();
return _volumeDataItems;
}
void DataLoaderModule::setVolumeDataItems(std::vector<std::string> items) {
_volumeDataItems = items;
}
openspace::dataloader::Reader* DataLoaderModule::reader() {
return _reader.get();
}
openspace::dataloader::Loader* DataLoaderModule::loader() {
return _loader.get();
}
} // namespace openspace

View File

@@ -26,13 +26,16 @@
#define __OPENSPACE_MODULE_DATALOADER___DATALOADERMODULE___H__
#include <openspace/util/openspacemodule.h>
#include <modules/dataloader/reader.h>
#include <modules/dataloader/loader.h>
namespace openspace::dataloader {
class Reader;
class Loader;
}
namespace openspace {
/**
* Own reader, writer, loader
* Reference reader, writer, loader
* Have functions like getDataItemList that gets list from reader
*/
class DataLoaderModule : public OpenSpaceModule {
@@ -40,12 +43,26 @@ public:
constexpr static const char* Name = "DataLoader";
DataLoaderModule();
~DataLoaderModule();
void internalInitialize(const ghoul::Dictionary&) override;
void validateDataDirectory();
void setDataDirectoryRead(bool isRead);
std::vector<std::string> volumeDataItems();
void setVolumeDataItems(std::vector<std::string> items);
dataloader::Reader* reader();
dataloader::Loader* loader();
private:
std::unique_ptr<openspace::dataloader::Reader> _reader;
std::unique_ptr<openspace::dataloader::Loader> _loader;
bool _dataDirectoryIsRead = true;
std::unique_ptr<dataloader::Reader> _reader;
std::unique_ptr<dataloader::Loader> _loader;
std::vector<std::string> _volumeDataItems;
};
} // namespace openspace

View File

@@ -0,0 +1,22 @@
#include <iostream>
#include <regex>
#include <ghoul/logging/logmanager.h>
namespace openspace::dataloader::helpers {
namespace {
constexpr const char* _loggerCat = "Helper";
}
std::string getDirLeaf(std::string dir) {
std::regex dirLeaf_regex("([^/]+)/?$");
std::smatch dirLeaf_match;
if (std::regex_search(dir, dirLeaf_match, dirLeaf_regex)) {
return dirLeaf_match[0].str();
} else {
LWARNING("Found no match in " + dir + ".");
}
}
}

View File

@@ -0,0 +1,5 @@
#include <iostream>
namespace openspace::dataloader::helpers {
std::string getDirLeaf(std::string dir);
}

View File

@@ -22,9 +22,12 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/dataloader/loader.h>
#include <ghoul/logging/logmanager.h>
#include <iostream>
#include <modules/dataloader/operators/loader.h>
#include <modules/dataloader/dataloadermodule.h>
#include <ghoul/logging/logmanager.h>
#include <openspace/properties/triggerproperty.h>
#include <modules/dataloader/helpers.cpp>
#ifdef _WIN32
#include <windows.h>
@@ -32,7 +35,7 @@
namespace {
constexpr const char* _loggerCat = "Loader";
} // namespace
}
namespace {
static const openspace::properties::Property::PropertyInfo SelectedFilesInfo = {
@@ -65,8 +68,6 @@ Loader::Loader()
void Loader::uploadData() {
char filepath[ MAX_PATH ];
// Linux
#ifdef _linux
system("thunar /home/mberg");
@@ -74,6 +75,8 @@ void Loader::uploadData() {
// Windows
#elif _WIN32
char filepath[ MAX_PATH ];
OPENFILENAME ofn;
ZeroMemory( &filepath, sizeof( filepath ) );
ZeroMemory( &ofn, sizeof( ofn ) );
@@ -127,17 +130,35 @@ void Loader::uploadData() {
}
void Loader::addInternalDataItemProperties() {
// Get list of internal data items
getModule()->validateDataDirectory();
std::vector<std::string> volumeItems = getModule()->volumeDataItems();
// Iterate data items
// Initialize trigger property with data item name (are they unique?)
// Set onChange method to call loadDataItem with the path as argument
// addProperty()
for (auto item : volumeItems) {
static const openspace::properties::Property::PropertyInfo info = {
"ItemTrigger_" + openspace::dataloader::helpers::getDirLeaf(item),
"",
""
};
// Initialize trigger property with data item name (are they unique?)
properties::TriggerProperty volumeItemTrigger(info);
// Set onChange method to call loadDataItem with the path as argument
volumeItemTrigger.onChange([this](){
// loadDataItem(item);
});
addProperty(volumeItemTrigger);
}
}
// addDataItemProperty();
// removeDataItemProperties();
// loadDataItem(std::string absPathToItem);
// loadDataItem(std::string absPathToItem) {
// LINFO("Load item " + absPathToItem);
// }
// createVolumeDataItem(std::string absPath);
}

View File

@@ -25,13 +25,16 @@
#ifndef __OPENSPACE_MODULE_DATALOADER___LOADER___H__
#define __OPENSPACE_MODULE_DATALOADER___LOADER___H__
#include <modules/dataloader/operators/operator.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
namespace openspace::dataloader {
class Loader : public properties::PropertyOwner {
using properties::PropertyOwner;
class Loader : public PropertyOwner, public Operator {
public:
Loader();

View File

@@ -0,0 +1,13 @@
#include <modules/dataloader/operators/operator.h>
#include <modules/dataloader/dataloadermodule.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/openspaceengine.h>
namespace openspace::dataloader {
DataLoaderModule* Operator::getModule() {
return OsEng.moduleEngine().module<DataLoaderModule>();
}
}

View File

@@ -0,0 +1,23 @@
#ifndef __OPENSPACE_MODULE_DATALOADER___OPERATOR___H__
#define __OPENSPACE_MODULE_DATALOADER___OPERATOR___H__
// #include <modules/dataloader/dataloadermodule.h>
namespace openspace {
class DataLoaderModule;
namespace dataloader {
class Operator {
public:
virtual ~Operator() {};
protected:
DataLoaderModule* getModule();
};
}
}
#endif // __OPENSPACE_MODULE_DATALOADER___OPERATOR___H__

View File

@@ -22,18 +22,27 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/dataloader/reader.h>
#include <modules/dataloader/operators/reader.h>
#include <modules/dataloader/dataloadermodule.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/moduleengine.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <regex>
#include <string>
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#endif
namespace {
constexpr const char* _loggerCat = "Reader";
} // namespace
}
namespace {
static const openspace::properties::Property::PropertyInfo VolumesInfo = {
@@ -93,7 +102,8 @@ void Reader::readVolumeDataItems() {
ghoul::filesystem::Directory::Sort::Yes
);
// DataLoader _internalDirDirty = false
getModule()->setVolumeDataItems(_volumeItems);
getModule()->setDataDirectoryRead(true);
// for (auto el : volumeItems) {
// LINFO("A dir: " + el);
@@ -109,7 +119,6 @@ void Reader::readVolumeDataItems() {
// if (std::regex_search(dir, dirLeaf_match, dirLeaf_regex)) {
// itemDirLeaves.push_back(dirLeaf_match[0].str());
// } else {
// LWARNING("Looked for match in " + dir + " but found none.");
// }
// }

View File

@@ -25,6 +25,7 @@
#ifndef __OPENSPACE_MODULE_DATALOADER___READER___H__
#define __OPENSPACE_MODULE_DATALOADER___READER___H__
#include <modules/dataloader/operators/operator.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/property.h> // do we need this
#include <openspace/properties/stringlistproperty.h>
@@ -33,7 +34,9 @@
namespace openspace::dataloader {
class Reader : public properties::PropertyOwner {
using properties::PropertyOwner;
class Reader : public PropertyOwner, public Operator {
public:
Reader();