mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-28 07:59:37 -06:00
some edits from PR comments
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
#include <modules/base/rendering/renderableplanetimevaryingimage.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
@@ -33,10 +32,9 @@
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
// Test debugging tools more then logmanager
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <optional>
|
||||
|
||||
@@ -45,22 +43,22 @@ namespace {
|
||||
constexpr const char* _loggerCat = "RenderablePlaneTimeVaryingImage";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo TextureInfo = {
|
||||
"Texture",
|
||||
"Texture",
|
||||
"This value specifies an image that is loaded from disk and is used as a texture "
|
||||
"that is applied to this plane. This image has to be square."
|
||||
"SourceFolder",
|
||||
"Texture Directory",
|
||||
"This value specifies the image directory that is loaded from disk and "
|
||||
"is used as a texture that is applied to this plane."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo RenderTypeInfo = {
|
||||
"RenderType",
|
||||
"RenderType",
|
||||
"This value specifies if the plane should be rendered in the Background,"
|
||||
"This value specifies if the plane should be rendered in the Background, "
|
||||
"Opaque, Transparent, or Overlay rendering step."
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(RenderablePlaneTimeVaryingImage)]] Parameters {
|
||||
// [[codegen::verbatim(TextureInfo.description)]]
|
||||
std::string texture;
|
||||
std::string sourceFolder;
|
||||
|
||||
enum class RenderType {
|
||||
Background,
|
||||
@@ -104,14 +102,17 @@ RenderablePlaneTimeVaryingImage::RenderablePlaneTimeVaryingImage(
|
||||
|
||||
addProperty(_blendMode);
|
||||
|
||||
_texturePath = absPath(p.texture).string();
|
||||
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath.value());
|
||||
_texturePath = p.sourceFolder;
|
||||
std::filesystem::path textureDirectory = absPath(_texturePath);
|
||||
if (!std::filesystem::is_directory(textureDirectory)) {
|
||||
LERROR(fmt::format(
|
||||
"Time varying image, {} is not a valid directory",
|
||||
_texturePath
|
||||
));
|
||||
}
|
||||
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange([this]() {loadTexture(); });
|
||||
_textureFile->setCallback(
|
||||
[this]() { _textureIsDirty = true; }
|
||||
);
|
||||
|
||||
if (p.renderType.has_value()) {
|
||||
switch (*p.renderType) {
|
||||
@@ -153,11 +154,8 @@ RenderablePlaneTimeVaryingImage::RenderablePlaneTimeVaryingImage(
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderablePlaneTimeVaryingImage::isReady() const {
|
||||
return RenderablePlane::isReady();
|
||||
}
|
||||
|
||||
void RenderablePlaneTimeVaryingImage::initialize() {
|
||||
void RenderablePlaneTimeVaryingImage::initialize() {
|
||||
RenderablePlane::initialize();
|
||||
bool success = extractMandatoryInfoFromDictionary();
|
||||
if (!success) {
|
||||
return;
|
||||
@@ -188,39 +186,29 @@ bool RenderablePlaneTimeVaryingImage::extractMandatoryInfoFromDictionary() {
|
||||
// Ensure that the source folder exists and then extract
|
||||
// the files with the same extension as <inputFileTypeString>
|
||||
namespace fs = std::filesystem;
|
||||
fs::path sourceFolder = _texturePath.value();
|
||||
if (std::filesystem::is_directory(sourceFolder)) {
|
||||
// Extract all file paths from the provided folder
|
||||
_sourceFiles.clear();
|
||||
namespace fs = std::filesystem;
|
||||
for (const fs::directory_entry& e : fs::directory_iterator(sourceFolder)) {
|
||||
if (e.is_regular_file()) {
|
||||
_sourceFiles.push_back(e.path().string());
|
||||
}
|
||||
}
|
||||
std::sort(_sourceFiles.begin(), _sourceFiles.end());
|
||||
// Ensure that there are available and valid source files left
|
||||
if (_sourceFiles.empty()) {
|
||||
LERROR(fmt::format(
|
||||
"{}: Plane sequence filepath {} was empty",
|
||||
_identifier, _texturePath
|
||||
));
|
||||
return false;
|
||||
fs::path sourceFolder = absPath(_texturePath);
|
||||
// Extract all file paths from the provided folder
|
||||
_sourceFiles.clear();
|
||||
namespace fs = std::filesystem;
|
||||
for (const fs::directory_entry& e : fs::directory_iterator(sourceFolder)) {
|
||||
if (e.is_regular_file()) {
|
||||
_sourceFiles.push_back(e.path().string());
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::sort(_sourceFiles.begin(), _sourceFiles.end());
|
||||
// Ensure that there are available and valid source files left
|
||||
if (_sourceFiles.empty()) {
|
||||
LERROR(fmt::format(
|
||||
"{}: Plane sequence filepath {} is not a valid directory",
|
||||
"{}: Plane sequence filepath {} was empty",
|
||||
_identifier, _texturePath
|
||||
));
|
||||
return false;
|
||||
}
|
||||
_nStates = _sourceFiles.size();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderablePlaneTimeVaryingImage::deinitializeGL() {
|
||||
_textureFile = nullptr;
|
||||
|
||||
BaseModule::TextureManager.release(_texture);
|
||||
|
||||
@@ -241,7 +229,7 @@ void RenderablePlaneTimeVaryingImage::update(const UpdateData& data) {
|
||||
if (!_enabled || _startTimes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool needsUpdate = false;
|
||||
const double currentTime = data.time.j2000Seconds();
|
||||
bool isInInterval = (currentTime >= _startTimes[0]) &&
|
||||
(currentTime < _sequenceEndTime);
|
||||
@@ -251,35 +239,35 @@ void RenderablePlaneTimeVaryingImage::update(const UpdateData& data) {
|
||||
// true => We stepped back to a time represented by another state
|
||||
currentTime < _startTimes[_activeTriggerTimeIndex] ||
|
||||
// true => We stepped forward to a time represented by another state
|
||||
(nextIdx < _nStates && currentTime >= _startTimes[nextIdx]))
|
||||
(nextIdx < _sourceFiles.size() && currentTime >= _startTimes[nextIdx]))
|
||||
{
|
||||
updateActiveTriggerTimeIndex(currentTime);
|
||||
_needsUpdate = true;
|
||||
needsUpdate = true;
|
||||
|
||||
} // else we're still in same state as previous frame (no changes needed)
|
||||
}
|
||||
else {
|
||||
// not in interval => set everything to false
|
||||
_activeTriggerTimeIndex = -1;
|
||||
_needsUpdate = false;
|
||||
needsUpdate = false;
|
||||
}
|
||||
|
||||
if ((_needsUpdate || _textureIsDirty) && !_isLoadingTexture) {
|
||||
_isLoadingTexture = true;
|
||||
if (needsUpdate || _textureIsDirty) {
|
||||
loadTexture();
|
||||
_textureIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderablePlaneTimeVaryingImage::render(const RenderData& data, RendererTasks& t) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
RenderablePlane::render(data, t);
|
||||
if (data.time.j2000Seconds() < _sequenceEndTime) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
RenderablePlane::render(data, t);
|
||||
}
|
||||
}
|
||||
|
||||
// Requires time to be formated as such: 'YYYY-MM-DDTHH-MM-SS-XXX'
|
||||
void RenderablePlaneTimeVaryingImage::extractTriggerTimesFromFileNames() {
|
||||
for (const std::string& filePath : _sourceFiles) {
|
||||
LDEBUG("filepath " + filePath);
|
||||
// Extract the filename from the path (without extension)
|
||||
std::string timeString = std::filesystem::path(filePath).stem().string();
|
||||
|
||||
@@ -298,24 +286,23 @@ void RenderablePlaneTimeVaryingImage::updateActiveTriggerTimeIndex(double curren
|
||||
auto iter = std::upper_bound(_startTimes.begin(), _startTimes.end(), currentTime);
|
||||
if (iter != _startTimes.end()) {
|
||||
if (iter != _startTimes.begin()) {
|
||||
_activeTriggerTimeIndex = static_cast<int>(
|
||||
std::distance(_startTimes.begin(), iter)
|
||||
) - 1;
|
||||
std::ptrdiff_t idx = std::distance(_startTimes.begin(), iter);
|
||||
_activeTriggerTimeIndex = static_cast<int>(idx) - 1;
|
||||
}
|
||||
else {
|
||||
_activeTriggerTimeIndex = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_activeTriggerTimeIndex = static_cast<int>(_nStates) - 1;
|
||||
_activeTriggerTimeIndex = static_cast<int>(_sourceFiles.size() - 1);
|
||||
}
|
||||
}
|
||||
void RenderablePlaneTimeVaryingImage::computeSequenceEndTime() {
|
||||
if (_nStates > 1) {
|
||||
const double lastTriggerTime = _startTimes[_nStates - 1];
|
||||
if (_sourceFiles.size() > 1) {
|
||||
const double lastTriggerTime = _startTimes[_sourceFiles.size() - 1];
|
||||
const double sequenceDuration = lastTriggerTime - _startTimes[0];
|
||||
const double averageStateDuration = sequenceDuration /
|
||||
(static_cast<double>(_nStates) - 1.0);
|
||||
(static_cast<double>(_sourceFiles.size() - 1.0));
|
||||
_sequenceEndTime = lastTriggerTime + averageStateDuration;
|
||||
}
|
||||
else {
|
||||
@@ -326,7 +313,6 @@ void RenderablePlaneTimeVaryingImage::computeSequenceEndTime() {
|
||||
void RenderablePlaneTimeVaryingImage::loadTexture() {
|
||||
if (_activeTriggerTimeIndex != -1) {
|
||||
_texture = _textureFiles[_activeTriggerTimeIndex].get();
|
||||
_isLoadingTexture = false;
|
||||
}
|
||||
}
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user