Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor datraw #1244

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmake/vcpkg_ports/datraw/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# header-only library

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO UniStuttgart-VISUS/datraw
REF "v${VERSION}"
SHA512 f38401e0e878f8df8e1b7b9750f4e7fec6920495bfb914a694aab166a0ffbda6dec189693a0d5b9aadb760789706e255f49a382d4e902002aef7120033dce016
HEAD_REF master
)

file(COPY "${SOURCE_PATH}/datraw/datraw.h" "${SOURCE_PATH}/datraw/datraw"
DESTINATION "${CURRENT_PACKAGES_DIR}/include")

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENCE.md")
7 changes: 7 additions & 0 deletions cmake/vcpkg_ports/datraw/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "datraw",
"version": "1.0.9",
"description": "C++ reimplementation of VIS's datraw library.",
"homepage": "https://github.com/UniStuttgart-VISUS/datraw",
"license": "MIT"
}
3 changes: 3 additions & 0 deletions plugins/volume/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ megamol_plugin(volume
geometry_calls)

if (volume_PLUGIN_ENABLED)
find_path(DATRAW_INCLUDE_DIRS "datraw.h")
target_include_directories(volume PRIVATE ${DATRAW_INCLUDE_DIRS})

#XXX: hacky appraoch to include datraw
add_subdirectory(datraw)

Expand Down
108 changes: 108 additions & 0 deletions plugins/volume/src/NewDatRawReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* VolumetricDataSource.cpp
*
* Copyright (C) 2024 by Visualisierungsinstitut der Universit�t Stuttgart.
* Alle rechte vorbehalten.
*/

#include "NewDatRawReader.h"

#include "mmcore/param/BoolParam.h"
#include "mmcore/param/EnumParam.h"
#include "mmcore/param/FilePathParam.h"
#include "mmcore/param/FloatParam.h"
#include "mmcore/param/IntParam.h"
#include "mmcore/param/StringParam.h"

#include "datraw.h"
#include "mmcore/utility/log/Log.h"

megamol::volume::NewDatRawReader::NewDatRawReader()
: core::Module()
, slotGetData("GetData", "Slot for requesting data.")
, paramFileName("FileName", "Path to file.") {
using geocalls::VolumetricDataCall;
this->slotGetData.SetCallback(VolumetricDataCall::ClassName(),
VolumetricDataCall::FunctionName(VolumetricDataCall::IDX_GET_DATA), &NewDatRawReader::onGetData);
this->slotGetData.SetCallback(VolumetricDataCall::ClassName(),
VolumetricDataCall::FunctionName(VolumetricDataCall::IDX_GET_EXTENTS), &NewDatRawReader::onGetExtents);
this->slotGetData.SetCallback(VolumetricDataCall::ClassName(),
VolumetricDataCall::FunctionName(VolumetricDataCall::IDX_GET_METADATA), &NewDatRawReader::onGetMetadata);
this->slotGetData.SetCallback(VolumetricDataCall::ClassName(),
VolumetricDataCall::FunctionName(VolumetricDataCall::IDX_START_ASYNC), &NewDatRawReader::onStartAsync);
this->slotGetData.SetCallback(VolumetricDataCall::ClassName(),
VolumetricDataCall::FunctionName(VolumetricDataCall::IDX_STOP_ASYNC), &NewDatRawReader::onStopAsync);
this->slotGetData.SetCallback(VolumetricDataCall::ClassName(),
VolumetricDataCall::FunctionName(VolumetricDataCall::IDX_TRY_GET_DATA), &NewDatRawReader::onTryGetData);

this->MakeSlotAvailable(&this->slotGetData);

this->paramFileName.SetParameter(new core::param::FilePathParam(""));
this->paramFileName.SetUpdateCallback(&NewDatRawReader::onFileNameChange);
this->MakeSlotAvailable(&this->paramFileName);
}

megamol::volume::NewDatRawReader::~NewDatRawReader() {}

bool megamol::volume::NewDatRawReader::create() {
return true;
}

void megamol::volume::NewDatRawReader::release() {}

bool megamol::volume::NewDatRawReader::onGetData(core::Call& call) {
geocalls::VolumetricDataCall& c = dynamic_cast<geocalls::VolumetricDataCall&>(call);
return true;
}

bool megamol::volume::NewDatRawReader::onGetMetadata(core::Call& call) {
return false;
}

bool megamol::volume::NewDatRawReader::onGetExtents(core::Call& call) {
try {
std::vector<float> volExt;
volExt.push_back(datInfo.slice_thickness()[0] * datInfo.resolution()[0]);
volExt.push_back(datInfo.slice_thickness()[1] * datInfo.resolution()[1]);
volExt.push_back(datInfo.slice_thickness()[2] * datInfo.resolution()[2]);

geocalls::VolumetricDataCall& c = dynamic_cast<geocalls::VolumetricDataCall&>(call);
c.SetExtent(datInfo.time_steps(), datInfo.origin()[0], datInfo.origin()[1], datInfo.origin()[2]
, datInfo.origin()[0] + volExt[0], datInfo.origin()[1] + volExt[1], datInfo.origin()[2] + volExt[2]);
return true;
} catch (vislib::Exception e) {
//TODO exception
return false;
}
}

bool megamol::volume::NewDatRawReader::onStartAsync(core::Call& call) {
return true;
}

bool megamol::volume::NewDatRawReader::onStopAsync(core::Call& call) {
return true;
}

bool megamol::volume::NewDatRawReader::onTryGetData(core::Call& call) {
try {

}
catch (std::exception e) {
geocalls::VolumetricDataCall& c = dynamic_cast<geocalls::VolumetricDataCall&>(call);
//what does this do?
c.SetDataHash(12345u);
return false;
}
return false;
}

bool megamol::volume::NewDatRawReader::onFileNameChange(core::param::ParamSlot& slot) {
// does this actually throw file not found exceptions?
try {
datInfo = datraw::info<char>::load(slot.Param<core::param::FilePathParam>()->Value().generic_string().c_str());
} catch (std::exception e) {
megamol::core::utility::log::Log::DefaultLog.WriteInfo("%s\n", e.what());
}
return true;
}
61 changes: 61 additions & 0 deletions plugins/volume/src/NewDatRawReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* VolumetricDataSource.h
*
* Copyright (C) 2024 by Visualisierungsinstitut der Universität Stuttgart.
* Alle rechte vorbehalten.
*/

#pragma once

#include <atomic>
#include <memory>
#include <vector>

#include "datraw/raw_reader.h"

#include "geometry_calls/VolumetricDataCall.h"

#include "mmcore/param/ParamSlot.h"

#include "mmcore/Call.h"
#include "mmcore/CalleeSlot.h"
#include "mmcore/Module.h"

#include "vislib/PtrArray.h"
#include "vislib/RawStorage.h"
#include "vislib/sys/Event.h"
#include "vislib/sys/Thread.h"

namespace megamol::volume {
class NewDatRawReader : public core::Module {

public:
static inline const char* ClassName() {
return "NewDatRawReader";
}
static inline const char* Description() {
return "Data source for DatRaw volumetric data.";
}
static inline bool IsAvailable() {
return true;
}
NewDatRawReader();
~NewDatRawReader() override;

protected:
bool create() override;
void release() override;

private:
core::CalleeSlot slotGetData;
core::param::ParamSlot paramFileName;
datraw::info<char> datInfo;
bool onGetData(core::Call& call);
bool onGetMetadata(core::Call& call);
bool onGetExtents(core::Call& call);
bool onStartAsync(core::Call& call);
bool onStopAsync(core::Call& call);
bool onTryGetData(core::Call& call);
bool onFileNameChange(core::param::ParamSlot& slot);
};
} // namespace megamol::volume
2 changes: 2 additions & 0 deletions plugins/volume/src/volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "DatRawWriter.h"
#include "DifferenceVolume.h"
#include "VolumetricDataSource.h"
#include "NewDatRawReader.h"

namespace megamol::volume {
class VolumePluginInstance : public megamol::core::factories::AbstractPluginInstance {
Expand All @@ -30,6 +31,7 @@ class VolumePluginInstance : public megamol::core::factories::AbstractPluginInst
this->module_descriptions.RegisterAutoDescription<megamol::volume::DatRawWriter>();
this->module_descriptions.RegisterAutoDescription<megamol::volume::DifferenceVolume>();
this->module_descriptions.RegisterAutoDescription<megamol::volume::VolumetricDataSource>();
this->module_descriptions.RegisterAutoDescription<megamol::volume::NewDatRawReader>();

// register calls
}
Expand Down
1 change: 1 addition & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"cppzmq",
"curl",
"cxxopts",
"datraw",
"delaunator-cpp",
"eigen3",
"glfw3",
Expand Down
Loading