mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 17:30:04 -05:00
Merge branch 'develop' into stars
Conflicts: include/openspace/util/constants.h shaders/pscstandard_fs.glsl shaders/pscstandard_vs.glsl src/interaction/interactionhandler.cpp src/main.cpp src/rendering/renderengine.cpp src/scenegraph/scenegraph.cpp src/scenegraph/scenegraphnode.cpp src/util/factorymanager.cpp
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __ABUFFER_H__
|
||||
#define __ABUFFER_H__
|
||||
|
||||
#include <openspace/abuffer/abuffer_i.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class Texture;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ABuffer: public ABuffer_I {
|
||||
public:
|
||||
|
||||
ABuffer();
|
||||
virtual ~ABuffer();
|
||||
virtual void resolve();
|
||||
|
||||
void addVolume(const std::string& tag,ghoul::opengl::Texture* volume);
|
||||
void addTransferFunction(const std::string& tag,ghoul::opengl::Texture* transferFunction);
|
||||
int addSamplerfile(const std::string& filename);
|
||||
|
||||
protected:
|
||||
virtual std::string settings() = 0;
|
||||
|
||||
bool initializeABuffer();
|
||||
|
||||
void generateShaderSource();
|
||||
bool updateShader();
|
||||
|
||||
std::string openspaceHeaders();
|
||||
std::string openspaceSamplerCalls();
|
||||
std::string openspaceSamplers();
|
||||
std::string openspaceTransferFunction();
|
||||
|
||||
unsigned int _width, _height, _totalPixels;
|
||||
|
||||
private:
|
||||
GLuint _screenQuad;
|
||||
|
||||
bool _validShader;
|
||||
std::string _fragmentShaderPath;
|
||||
ghoul::filesystem::File* _fragmentShaderFile;
|
||||
ghoul::opengl::ProgramObject* _resolveShader;
|
||||
|
||||
std::vector<std::pair<std::string,ghoul::opengl::Texture*> > _volumes;
|
||||
std::vector<std::pair<std::string,ghoul::opengl::Texture*> > _transferFunctions;
|
||||
std::vector<ghoul::filesystem::File*> _samplerFiles;
|
||||
std::vector<std::string> _samplers;
|
||||
|
||||
// Development functionality to update shader for changes in several files
|
||||
std::vector<ghoul::filesystem::File*> _shaderFiles;
|
||||
|
||||
float _volumeStepFactor;
|
||||
|
||||
|
||||
|
||||
}; // ABuffer
|
||||
} // openspace
|
||||
|
||||
#endif // __ABUFFER_H__
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __ABUFFERSINGLELINKED_H__
|
||||
#define __ABUFFERSINGLELINKED_H__
|
||||
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ABufferSingleLinked: public ABuffer {
|
||||
public:
|
||||
|
||||
ABufferSingleLinked();
|
||||
virtual ~ABufferSingleLinked();
|
||||
virtual bool initialize();
|
||||
|
||||
virtual void clear();
|
||||
virtual void preRender();
|
||||
virtual void postRender();
|
||||
|
||||
virtual std::string settings();
|
||||
|
||||
private:
|
||||
|
||||
GLuint *_data;
|
||||
GLuint _anchorPointerTexture;
|
||||
GLuint _anchorPointerTextureInitializer;
|
||||
GLuint _atomicCounterBuffer;
|
||||
GLuint _fragmentBuffer;
|
||||
GLuint _fragmentTexture;
|
||||
|
||||
|
||||
|
||||
|
||||
}; // ABufferSingleLinked
|
||||
} // openspace
|
||||
|
||||
#endif // __ABUFFERSINGLELINKED_H__
|
||||
@@ -0,0 +1,43 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __ABUFFER_I_H__
|
||||
#define __ABUFFER_I_H__
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ABuffer_I {
|
||||
public:
|
||||
virtual ~ABuffer_I() {};
|
||||
virtual bool initialize() = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
virtual void preRender() = 0;
|
||||
virtual void postRender() = 0;
|
||||
virtual void resolve() = 0;
|
||||
|
||||
}; // ABuffer_I
|
||||
} // openspace
|
||||
|
||||
#endif // __ABUFFER_I_H__
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __ABUFFERDYNAMIC_H__
|
||||
#define __ABUFFERDYNAMIC_H__
|
||||
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ABufferDynamic: public ABuffer {
|
||||
public:
|
||||
|
||||
ABufferDynamic();
|
||||
virtual ~ABufferDynamic();
|
||||
virtual bool initialize();
|
||||
|
||||
virtual void clear();
|
||||
virtual void preRender();
|
||||
virtual void postRender();
|
||||
|
||||
virtual std::string settings();
|
||||
|
||||
private:
|
||||
|
||||
GLuint *_data;
|
||||
GLuint _anchorPointerTexture;
|
||||
GLuint _anchorPointerTextureInitializer;
|
||||
GLuint _atomicCounterBuffer;
|
||||
GLuint _fragmentBuffer;
|
||||
GLuint _fragmentTexture;
|
||||
|
||||
|
||||
|
||||
|
||||
}; // ABufferDynamic
|
||||
} // openspace
|
||||
|
||||
#endif // __ABUFFERDYNAMIC_H__
|
||||
@@ -0,0 +1,61 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __ABUFFERFIXED_H__
|
||||
#define __ABUFFERFIXED_H__
|
||||
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ABufferFixed: public ABuffer {
|
||||
public:
|
||||
|
||||
ABufferFixed();
|
||||
virtual ~ABufferFixed();
|
||||
virtual bool initialize();
|
||||
|
||||
virtual void clear();
|
||||
virtual void preRender();
|
||||
virtual void postRender();
|
||||
|
||||
virtual std::string settings();
|
||||
|
||||
private:
|
||||
|
||||
GLuint *_data;
|
||||
GLuint _anchorPointerTexture;
|
||||
GLuint _anchorPointerTextureInitializer;
|
||||
GLuint _atomicCounterBuffer;
|
||||
GLuint _atomicCounterTexture;
|
||||
GLuint _fragmentBuffer;
|
||||
GLuint _fragmentTexture;
|
||||
|
||||
|
||||
|
||||
|
||||
}; // ABufferFixed
|
||||
} // openspace
|
||||
|
||||
#endif // __ABUFFERFIXED_H__
|
||||
@@ -34,17 +34,34 @@
|
||||
#include <ghoul/opencl/clprogram.h>
|
||||
#include <ghoul/opencl/clkernel.h>
|
||||
|
||||
//#define FLARE_ONLY
|
||||
// #define FLARE_ONLY
|
||||
|
||||
#include <openspace/flare/flare.h>
|
||||
#include <openspace/util/shadercreator.h>
|
||||
|
||||
#define ABUFFER_SINGLE_LINKED 1
|
||||
#define ABUFFER_FIXED 2
|
||||
#define ABUFFER_DYNAMIC 3
|
||||
#define ABUFFER_IMPLEMENTATION ABUFFER_SINGLE_LINKED
|
||||
|
||||
// #define OPENSPACE_VIDEO_EXPORT
|
||||
|
||||
namespace ghoul {
|
||||
namespace cmdparser {
|
||||
class CommandlineParser;
|
||||
class CommandlineCommand;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ScriptEngine;
|
||||
namespace scripting {
|
||||
class ScriptEngine;
|
||||
}
|
||||
|
||||
class OpenSpaceEngine {
|
||||
public:
|
||||
static void create(int argc, char** argv, std::vector<std::string>& sgctArguments);
|
||||
static bool create(int argc, char** argv, std::vector<std::string>& sgctArguments);
|
||||
static void destroy();
|
||||
static OpenSpaceEngine& ref();
|
||||
|
||||
@@ -59,6 +76,8 @@ public:
|
||||
ghoul::opencl::CLContext& clContext();
|
||||
InteractionHandler& interactionHandler();
|
||||
RenderEngine& renderEngine();
|
||||
scripting::ScriptEngine& scriptEngine();
|
||||
ShaderCreator& shaderBuilder();
|
||||
|
||||
// SGCT callbacks
|
||||
bool initializeGL();
|
||||
@@ -70,19 +89,27 @@ public:
|
||||
void mouseButtonCallback(int key, int action);
|
||||
void mousePositionCallback(int x, int y);
|
||||
void mouseScrollWheelCallback(int pos);
|
||||
void externalControlCallback(const char* receivedChars, int size, int clientId);
|
||||
|
||||
void encode();
|
||||
void decode();
|
||||
|
||||
private:
|
||||
OpenSpaceEngine();
|
||||
OpenSpaceEngine(std::string programName);
|
||||
~OpenSpaceEngine();
|
||||
|
||||
bool gatherCommandlineArguments();
|
||||
|
||||
static OpenSpaceEngine* _engine;
|
||||
|
||||
ghoul::Dictionary* _configurationManager;
|
||||
InteractionHandler* _interactionHandler;
|
||||
RenderEngine* _renderEngine;
|
||||
scripting::ScriptEngine* _scriptEngine;
|
||||
ghoul::cmdparser::CommandlineParser* _commandlineParser;
|
||||
#ifdef OPENSPACE_VIDEO_EXPORT
|
||||
bool _doVideoExport;
|
||||
#endif
|
||||
#ifdef FLARE_ONLY
|
||||
Flare* _flare;
|
||||
#endif
|
||||
@@ -90,6 +117,7 @@ private:
|
||||
ghoul::opencl::CLContext _context;
|
||||
|
||||
sgct::SharedVector<char> _synchronizationBuffer;
|
||||
ShaderCreator _shaderBuilder;
|
||||
};
|
||||
|
||||
#define OsEng (openspace::OpenSpaceEngine::ref())
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -56,6 +58,8 @@ public:
|
||||
void mouseButtonCallback(int key, int action);
|
||||
void mousePositionCallback(int x, int y);
|
||||
void mouseScrollWheelCallback(int pos);
|
||||
|
||||
void addKeyCallback(int key, std::function<void(void)> f);
|
||||
|
||||
private:
|
||||
glm::vec3 mapToTrackball(glm::vec2 mousePos);
|
||||
@@ -77,6 +81,8 @@ private:
|
||||
|
||||
// for locking and unlocking
|
||||
std::mutex cameraGuard_;
|
||||
|
||||
std::multimap<int, std::function<void(void)> > _keyCallbacks;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ private:
|
||||
void handleNodes();
|
||||
void loadIntoNodes(const boost::property_tree::ptree& tree, std::string parent = "", const int depth = 0);
|
||||
|
||||
OpenSpaceEngine* _engine;
|
||||
// OpenSpaceEngine* _engine;
|
||||
std::vector<Node> _nodes;
|
||||
};
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ public:
|
||||
NumericalProperty(std::string identifier, std::string guiName, T value,
|
||||
T minimumValue, T maximumValue);
|
||||
|
||||
bool getLua(lua_State* state) const override;
|
||||
bool setLua(lua_State* state) override;
|
||||
int typeLua() const override;
|
||||
|
||||
virtual std::string className() const override;
|
||||
|
||||
using TemplateProperty<T>::operator=;
|
||||
|
||||
@@ -22,43 +22,125 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define REGISTER_NUMERICALPROPERTY_HEADER(CLASS_NAME, TYPE) \
|
||||
typedef NumericalProperty<TYPE> CLASS_NAME; \
|
||||
template <> std::string PropertyDelegate<NumericalProperty<TYPE>>::className(); \
|
||||
template <> std::string PropertyDelegate<TemplateProperty<TYPE>>::className(); \
|
||||
template <> template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultValue<TYPE>(); \
|
||||
template <> template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMinimumValue<TYPE>(); \
|
||||
template <> template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>();
|
||||
#define REGISTER_NUMERICALPROPERTY_HEADER(CLASS_NAME, TYPE) \
|
||||
typedef NumericalProperty<TYPE> CLASS_NAME; \
|
||||
template <> \
|
||||
std::string PropertyDelegate<NumericalProperty<TYPE>>::className(); \
|
||||
template <> \
|
||||
std::string PropertyDelegate<TemplateProperty<TYPE>>::className(); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultValue<TYPE>(); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMinimumValue<TYPE>(); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>(); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue(lua_State* state, \
|
||||
bool& success); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::fromLuaValue(lua_State* state, \
|
||||
bool& success); \
|
||||
template <> \
|
||||
template <> \
|
||||
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue(lua_State* state, \
|
||||
TYPE value); \
|
||||
template <> \
|
||||
template <> \
|
||||
bool PropertyDelegate<NumericalProperty<TYPE>>::toLuaValue(lua_State* state, \
|
||||
TYPE value); \
|
||||
template <> \
|
||||
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua(); \
|
||||
template <> \
|
||||
int PropertyDelegate<NumericalProperty<TYPE>>::typeLua();
|
||||
|
||||
|
||||
#define REGISTER_NUMERICALPROPERTY_SOURCE(CLASS_NAME, TYPE, \
|
||||
DEFAULT_VALUE, DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEPPING) \
|
||||
template <> \
|
||||
std::string PropertyDelegate<NumericalProperty<TYPE>>::className() { \
|
||||
return #CLASS_NAME; \
|
||||
} \
|
||||
template <> \
|
||||
std::string PropertyDelegate<TemplateProperty<TYPE>>::className() { \
|
||||
return #CLASS_NAME; \
|
||||
} \
|
||||
template <> template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultValue<TYPE>() { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
template <> template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMinimumValue<TYPE>() { \
|
||||
return DEFAULT_MIN_VALUE; \
|
||||
} \
|
||||
template <> template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>() { \
|
||||
return DEFAULT_MAX_VALUE; \
|
||||
}
|
||||
#define REGISTER_NUMERICALPROPERTY_SOURCE(CLASS_NAME, TYPE, DEFAULT_VALUE, \
|
||||
DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, \
|
||||
DEFAULT_STEPPING, FROM_LUA_LAMBDA_EXPRESSION, \
|
||||
TO_LUA_LAMBDA_EXPRESSION, LUA_TYPE) \
|
||||
template <> \
|
||||
std::string PropertyDelegate<TemplateProperty<TYPE>>::className() \
|
||||
{ \
|
||||
return #CLASS_NAME; \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
std::string PropertyDelegate<NumericalProperty<TYPE>>::className() \
|
||||
{ \
|
||||
return PropertyDelegate<TemplateProperty<TYPE>>::className(); \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultValue<TYPE>() \
|
||||
{ \
|
||||
return DEFAULT_VALUE; \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMinimumValue<TYPE>() \
|
||||
{ \
|
||||
return DEFAULT_MIN_VALUE; \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::defaultMaximumValue<TYPE>() \
|
||||
{ \
|
||||
return DEFAULT_MAX_VALUE; \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>(lua_State * state, \
|
||||
bool& success) \
|
||||
{ \
|
||||
return FROM_LUA_LAMBDA_EXPRESSION(state, success); \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<NumericalProperty<TYPE>>::fromLuaValue<TYPE>( \
|
||||
lua_State * state, bool& success) \
|
||||
{ \
|
||||
return PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>(state, \
|
||||
success); \
|
||||
\
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State * state, \
|
||||
TYPE value) \
|
||||
{ \
|
||||
return TO_LUA_LAMBDA_EXPRESSION(state, value); \
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
bool PropertyDelegate<NumericalProperty<TYPE>>::toLuaValue<TYPE>(lua_State * state, \
|
||||
TYPE value) \
|
||||
{ \
|
||||
return PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(state, value); \
|
||||
} \
|
||||
template <> \
|
||||
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua() \
|
||||
{ \
|
||||
return LUA_TYPE; \
|
||||
} \
|
||||
template <> \
|
||||
int PropertyDelegate<NumericalProperty<TYPE>>::typeLua() \
|
||||
{ \
|
||||
return PropertyDelegate<TemplateProperty<TYPE>>::typeLua(); \
|
||||
}
|
||||
|
||||
// Delegating constructors are necessary; automatic template deduction cannot
|
||||
// deduce template argument for 'U' if 'default' methods are used as default values in
|
||||
@@ -95,5 +177,28 @@ std::string NumericalProperty<T>::className() const {
|
||||
return PropertyDelegate<NumericalProperty<T>>::className();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool NumericalProperty<T>::setLua(lua_State* state)
|
||||
{
|
||||
bool success;
|
||||
T value = PropertyDelegate<NumericalProperty<T>>::template fromLuaValue<T>(state, success);
|
||||
if (success)
|
||||
TemplateProperty<T>::setValue(value);
|
||||
return success;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool NumericalProperty<T>::getLua(lua_State* state) const
|
||||
{
|
||||
bool success = PropertyDelegate<NumericalProperty<T>>::template toLuaValue<T>(state, TemplateProperty<T>::_value);
|
||||
return success;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int NumericalProperty<T>::typeLua() const {
|
||||
return PropertyDelegate<NumericalProperty<T>>::typeLua();
|
||||
}
|
||||
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
@@ -32,43 +32,223 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
struct lua_State;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
class PropertyOwner;
|
||||
|
||||
/**
|
||||
* A property encapsulates a value which should be user-changeable. A property almost
|
||||
* always belongs to a PropertyOwner who has taken ownership (setPropertyOwner) of the
|
||||
* Property. Per PropertyOwner, the <code>identifier</code> needs to be unique and can be
|
||||
* used as a URI. This class is an abstract base class and each subclass (most notable
|
||||
* TemplateProperty) needs to implement the methods Property::className, Property::get,
|
||||
* Property::set, Property::type(), Property::getLua, Property::setLua, and
|
||||
* Property::typeLua to make full use of the infrastructure.
|
||||
* The most common types can be implemented by creating a specialized instantiation of
|
||||
* TemplateProperty, which provides default implementations for these methods.
|
||||
*
|
||||
* The onChange method can be used by the PropertyOwner to listen to changes that happen
|
||||
* to the Property. The parameter is a function object that gets called after new value
|
||||
* has been set.
|
||||
* The metaData allows the developer to specify additional information about the Property
|
||||
* which might be used in GUI representations. One example would be a glm::vec4 property,
|
||||
* (Vec4Property) that can either represent a 4-dimensional position, a powerscaled
|
||||
* coordinate, a light position, or other things, requiring different GUI representations.
|
||||
* \see TemplateProperty
|
||||
* \see PropertyOwner
|
||||
*/
|
||||
class Property {
|
||||
public:
|
||||
/**
|
||||
* The constructor for the property. The <code>identifier</code> needs to be unique
|
||||
* for each PropertyOwner. The <code>guiName</code> will be stored in the metaData
|
||||
* to be accessed by the GUI elements using the <code>guiName</code> key. The default
|
||||
* visibility settings is <code>true</code>, whereas the default read-only state is
|
||||
* <code>false</code>.
|
||||
* \param identifier A unique identifier for this property. It has to be unique to the
|
||||
* PropertyOwner and cannot contain any <code>.</code>s
|
||||
* \param guiName The human-readable GUI name for this Property
|
||||
*/
|
||||
Property(std::string identifier, std::string guiName);
|
||||
|
||||
/**
|
||||
* The destructor taking care of deallocating all unused memory. This method will not
|
||||
* remove the Property from the PropertyOwner.
|
||||
*/
|
||||
virtual ~Property();
|
||||
|
||||
//virtual Property* create() const = 0;
|
||||
/**
|
||||
* This method returns the class name of the Property. The method is used by the
|
||||
* TemplateFactory to create new instances of Propertys. The returned value is almost
|
||||
* always identical to the C++ class name of the derived class.
|
||||
* \return The class name of the Property
|
||||
*/
|
||||
virtual std::string className() const = 0;
|
||||
|
||||
/**
|
||||
* This method returns the encapsulated value of the Property to the caller. The type
|
||||
* that is returned is determined by the type function and is up to the developer of
|
||||
* the derived class. The default implementation returns an empty boost::any object.
|
||||
* \return The value that is encapsulated by this Property, or an empty boost::any
|
||||
* object if the method was not overritten.
|
||||
*/
|
||||
virtual boost::any get() const;
|
||||
virtual void set(boost::any value);
|
||||
virtual const std::type_info& type() const;
|
||||
|
||||
/**
|
||||
* Sets the value encapsulated by this Property to the <code>value</code> passed to
|
||||
* this function. It is the caller's responsibility to ensure that the type contained
|
||||
* in <code>value</code> is compatible with the concrete subclass of the Property. The
|
||||
* method Property::type will return the desired type for the Property. The default
|
||||
* implementation of this method ignores the input.
|
||||
* \param value The new value that should be stored in this Property
|
||||
*/
|
||||
virtual void set(boost::any value);
|
||||
|
||||
/**
|
||||
* This method returns the type that is requested by this Property for the set method.
|
||||
* The default implementation returns the type of <code>void</code>.
|
||||
* \return The type that is requested by this Property's Property::set method
|
||||
*/
|
||||
virtual const std::type_info& type() const;
|
||||
|
||||
/**
|
||||
* This method encodes the encapsulated value of this Property at the top of the Lua
|
||||
* stack. The specific details of this serialization is up to the property developer
|
||||
* as long as the rest of the stack is unchanged. The implementation has to be
|
||||
* synchronized with the Property::setLua method. The default implementation is a
|
||||
* no-op.
|
||||
* \param state The Lua state to which the value will be encoded
|
||||
* \return <code>true</code> if the encoding succeeded, <code>false</code> otherwise
|
||||
*/
|
||||
virtual bool getLua(lua_State* state) const;
|
||||
|
||||
/**
|
||||
* This method sets the value encapsulated by this Property by deserializing the value
|
||||
* on top of the passed Lua stack. The specific details of the deserialization are up
|
||||
* to the Property developer, but they must only depend on the top element of the
|
||||
* stack and must leave all other elements unchanged. The implementation has to be
|
||||
* synchronized with the Property::getLua method. The default implementation is a
|
||||
* no-op.
|
||||
* \param state The Lua state from which the value will be decoded
|
||||
* \return <code>true</code> if the decoding and setting of the value succeeded,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
virtual bool setLua(lua_State* state);
|
||||
|
||||
/**
|
||||
* Returns the Lua type that will be put onto the stack in the Property::getLua method
|
||||
* and which will be consumed by the Property::setLua method. The returned value
|
||||
* can belong to the set of Lua types: <code>LUA_TNONE</code>, <code>LUA_TNIL</code>,
|
||||
* <code>LUA_TBOOLEAN</code>, <code>LUA_TLIGHTUSERDATA</code>,
|
||||
* <code>LUA_TNUMBER</code>, <code>LUA_TSTRING</code>, <code>LUA_TTABLE</code>,
|
||||
* <code>LUA_TFUNCTION</code>, <code>LUA_TUSERDATA</code>, or
|
||||
* <code>LUA_TTHREAD</code>. The default implementation will return
|
||||
* <code>LUA_TNONE</code>.
|
||||
* \return The Lua type that will be consumed or produced by the Property::getLua and
|
||||
* Property::setLua methods.
|
||||
*/
|
||||
virtual int typeLua() const;
|
||||
|
||||
/**
|
||||
* This method registers a <code>callback</code> function that will be called every
|
||||
* time if either Property:set or Property::setLua was called with a value that is
|
||||
* different from the previously stored value. The callback can be removed my passing
|
||||
* an empty <code>std::function<void()></code> object.
|
||||
* \param callback The callback function that is called when the encapsulated type has
|
||||
* been successfully changed by either the Property::set or Property::setLua methods.
|
||||
*/
|
||||
virtual void onChange(std::function<void()> callback);
|
||||
|
||||
/**
|
||||
* This method returns the unique identifier of this Property.
|
||||
* \return The unique identifier of this Property
|
||||
*/
|
||||
const std::string& identifier() const;
|
||||
const std::string& guiName() const;
|
||||
|
||||
/**
|
||||
* Returns the PropertyOwner of this Property or <code>nullptr</code>, if it does not
|
||||
* have an owner.
|
||||
*\ return The Property of this Property
|
||||
*/
|
||||
PropertyOwner* owner() const;
|
||||
void setPropertyOwner(PropertyOwner* owner);
|
||||
|
||||
/**
|
||||
* Assigned the Property to a new PropertyOwner. This method does not inform the
|
||||
* PropertyOwner of this action.
|
||||
* \param owner The new PropertyOwner for this Property
|
||||
*/
|
||||
void setPropertyOwner(PropertyOwner* owner);
|
||||
|
||||
/**
|
||||
* Returns the human-readable GUI name for this Property that has been set in the
|
||||
* constructor. This method returns the same value as accessing the metaData object
|
||||
* and requesting the <code>std::string</code> stored for the <code>guiName</code>
|
||||
* key.
|
||||
* \return The human-readable GUI name for this Property
|
||||
*/
|
||||
const std::string& guiName() const;
|
||||
|
||||
/**
|
||||
* Sets the identifier of the group that this Property belongs to. Property groups can
|
||||
* be used, for example, by GUI application to visually group different properties,
|
||||
* but it has no impact on the Property itself. The default value for the groupID is
|
||||
* <code>""</code>.
|
||||
* \param groupId The group id that this property should belong to
|
||||
*/
|
||||
void setGroupIdentifier(std::string groupId);
|
||||
|
||||
/**
|
||||
* Returns the group idenfier that this Property belongs to, or <code>""</code> if it
|
||||
* belongs to no group.
|
||||
* \return The group identifier that this Property belongs to
|
||||
*/
|
||||
std::string groupIdentifier() const;
|
||||
|
||||
/**
|
||||
* Determines a hint if this Property should be visible, or hidden. Each application
|
||||
* accessing the properties is free to ignore this hint. It is stored in the metaData
|
||||
* Dictionary with the key: <code>isVisible</code>. The default value is
|
||||
* <code>true</code>.
|
||||
* \param state <code>true</code> if the Property should be visible,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
void setVisible(bool state);
|
||||
bool isVisible() const;
|
||||
|
||||
void setReadOnly(bool state);
|
||||
bool isReadOnly() const;
|
||||
/**
|
||||
* This method determines if this Property should be read-only in external
|
||||
* applications. This setting is only a hint and does not need to be followed by GUI
|
||||
* applications and does not have any effect on the Property::set or Property::setLua
|
||||
* methods. The value is stored in the metaData Dictionary with the key:
|
||||
* <code>isReadOnly</code>. The default value is <code>false</code>.
|
||||
* \param state <code>true</code> if the Property should be read only,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
void setReadOnly(bool state);
|
||||
|
||||
/**
|
||||
* This method allows the developer to give hints to the GUI about different
|
||||
* representations for the GUI. The same Property (for example Vec4Property) can be
|
||||
* used in different ways, each requiring a different input method. These values are
|
||||
* stored in the metaData object using the <code>views.</code> prefix in front of the
|
||||
* <code>option</code> parameter. See Property::ViewOptions for a default list of
|
||||
* possible options. As these are only hints, the GUI is free to ignore any suggestion
|
||||
* by the developer.
|
||||
* \param option The view option that should be modified
|
||||
* \param value Determines if the view option should be active (<code>true</code>) or
|
||||
* deactivated (<code>false</code>)
|
||||
*/
|
||||
void setViewOption(std::string option, bool value = true);
|
||||
bool viewOption(const std::string& option) const;
|
||||
|
||||
/**
|
||||
* Default view options that can be used in the Property::setViewOption method. The
|
||||
* values are: Property::ViewOptions::Color = <code>color</code>,
|
||||
* Property::ViewOptions::LightPosition = <code>lightPosition</code>,
|
||||
* Property::ViewOptions::PowerScaledScalar = <code>powerScaledScalar</code>, and
|
||||
* Property::ViewOptions::PowerScaledCoordinate = <code>powerScaledCoordinate</code>.
|
||||
*/
|
||||
struct ViewOptions {
|
||||
static const std::string Color;
|
||||
static const std::string LightPosition;
|
||||
@@ -76,16 +256,32 @@ public:
|
||||
static const std::string PowerScaledCoordinate;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the metaData that contains all information for external applications to
|
||||
* correctly display information about the Property. No information that is stored in
|
||||
* this Dictionary is necessary for the programmatic use of the Property.
|
||||
* \return The Dictionary containing all meta data information about this Property
|
||||
*/
|
||||
const ghoul::Dictionary& metaData() const;
|
||||
|
||||
protected:
|
||||
PropertyOwner* _owner;
|
||||
/**
|
||||
* This method must be called by all subclasses whenever the encapsulated value has
|
||||
* changed and a potential listener has to be informed.
|
||||
*/
|
||||
void notifyListener();
|
||||
|
||||
/// The PropetyOwner this Property belongs to, or <code>nullptr</code>
|
||||
PropertyOwner* _owner;
|
||||
|
||||
/// The identifier for this Property
|
||||
std::string _identifier;
|
||||
std::string _guiName;
|
||||
|
||||
/// The Dictionary containing all meta data necessary for external applications
|
||||
ghoul::Dictionary _metaData;
|
||||
|
||||
std::vector<std::function<void()>> _onChangeCallbacks;
|
||||
/// The callback function that will be invoked whenever the encapsulated value changes
|
||||
std::function<void()> _onChangeCallback;
|
||||
};
|
||||
|
||||
} // namespace properties
|
||||
|
||||
@@ -27,22 +27,115 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
struct lua_State;
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
/**
|
||||
* The PropertyDelegate class is used by (among others) the TemplateProperty and the
|
||||
* NumericalProperty classes to outsource the definitions of class names, default values,
|
||||
* etc. Using the PropertyDelegate, it is possible to create new TemplateProperty types
|
||||
* without subclassing the TemplateProperty, but rather creating a specialized instance
|
||||
* of PropertyDelegate. See (http://openspace.itn.liu.se/trac/wiki/guides/properties) for
|
||||
* more detailed information.
|
||||
* \see TemplateProperty
|
||||
* \see NumericalProperty
|
||||
* \tparam T The full class for which this specialized instance of PropertyDelegate is
|
||||
* responsible. For example <code>T = TemplateProperty<std::string></code>.
|
||||
*/
|
||||
template <typename T>
|
||||
class PropertyDelegate {
|
||||
public:
|
||||
/**
|
||||
* This method returns the class name for the class <code>T</code>. The default
|
||||
* implementation will lead to a compile-time error if the class method is not
|
||||
* specialized.
|
||||
* \return The class name for the class <code>T</code>
|
||||
*/
|
||||
static std::string className();
|
||||
|
||||
/**
|
||||
* This method will return the preferred default value for the class <code>T</code>.
|
||||
* The default implementation will lead to a compile-time error if the class method is
|
||||
* not specialized.
|
||||
* \return The default value that the class <code>T</code> should use
|
||||
* \tparam U The type by which the class T is specialized. If
|
||||
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
|
||||
*/
|
||||
template <typename U>
|
||||
static U defaultValue();
|
||||
|
||||
/**
|
||||
* This method will return the preferred default minimum value for the class
|
||||
* <code>T</code>. The default implementation will lead to a compile-time error if the
|
||||
* class method is not specialized. This method is not used in TemplateProperty, but
|
||||
* only NumericalProperty, so the TemplateProperty does not require this method to be
|
||||
* specialized.
|
||||
* \return The default minimum value that the class <code>T</code> should use
|
||||
* \tparam U The type by which the class T is specialized. If
|
||||
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
|
||||
*/
|
||||
template <typename U>
|
||||
static U defaultMinimumValue();
|
||||
|
||||
/**
|
||||
* This method will return the preferred default maximum value for the class
|
||||
* <code>T</code>. The default implementation will lead to a compile-time error if the
|
||||
* class method is not specialized. This method is not used in TemplateProperty, but
|
||||
* only NumericalProperty, so the TemplateProperty does not require this method to be
|
||||
* specialized.
|
||||
* \return The default maximum value that the class <code>T</code> should use
|
||||
* \tparam U The type by which the class T is specialized. If
|
||||
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
|
||||
*/
|
||||
template <typename U>
|
||||
static U defaultMaximumValue();
|
||||
|
||||
/**
|
||||
* This method converts the top value from the Lua stack into a value of type
|
||||
* <code>U</code> and reports the <code>success</code> back to the caller. The default
|
||||
* implementation will lead to a compile-time error if the class method is not
|
||||
* specialized.
|
||||
* \param state The Lua state from which the value is retrieved
|
||||
* \param success Will be <code>true</code> if the conversion succeeded;
|
||||
* <code>false</code> otherwise
|
||||
* \return The value that was created by converting the top value from the stack
|
||||
* \tparam U The type by which the class T is specialized. If
|
||||
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
|
||||
*/
|
||||
template <typename U>
|
||||
static U fromLuaValue(lua_State* state, bool& success);
|
||||
|
||||
/**
|
||||
* This method converts the passed <code>value</code>, encodes it and places it on the
|
||||
* top value of the Lua stack and returns the success back to the caller. The default
|
||||
* implementation will lead to a compile-time error if the class method is not
|
||||
* specialized.
|
||||
* \param state The Lua state from which the value is retrieved
|
||||
* \param value The value that will be converted into a Lua object
|
||||
* \return <code>true</code> if the conversion succeeded; <code>false</code> otherwise
|
||||
* \tparam U The type by which the class T is specialized. If
|
||||
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
|
||||
*/
|
||||
template <typename U>
|
||||
static bool toLuaValue(lua_State* state, U value);
|
||||
|
||||
/**
|
||||
* Returns the Lua type that will be put onto the stack in the
|
||||
* PropertyDelegate::toLuaValue method and which will be consumed by the
|
||||
* PropertyDelegate::fromLuaValue method. The returned value can belong to the set of
|
||||
* Lua types: <code>LUA_TNONE</code>, <code>LUA_TNIL</code>,
|
||||
* <code>LUA_TBOOLEAN</code>, <code>LUA_TLIGHTUSERDATA</code>,
|
||||
* <code>LUA_TNUMBER</code>, <code>LUA_TSTRING</code>, <code>LUA_TTABLE</code>,
|
||||
* <code>LUA_TFUNCTION</code>, <code>LUA_TUSERDATA</code>, or
|
||||
* <code>LUA_TTHREAD</code>. The default implementation will return
|
||||
* <code>LUA_TNONE</code>. The default implementation will lead to a compile-time
|
||||
* error if the class method is not specialized.
|
||||
* \return The Lua type that will be consumed or produced by the
|
||||
* PropertyDelegate::toLuaValue and PropertyDelegate::fromLuaValue methods.
|
||||
*/
|
||||
static int typeLua();
|
||||
};
|
||||
|
||||
} // namespace properties
|
||||
|
||||
@@ -24,22 +24,20 @@
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
template <typename T>
|
||||
std::string PropertyDelegate<T>::className() {
|
||||
static_assert(sizeof(T) == 0, "Unimplemented PropertyDelegate::className specialization");
|
||||
static_assert(sizeof(T) == 0,
|
||||
"Unimplemented PropertyDelegate::className specialization");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
U PropertyDelegate<T>::defaultValue() {
|
||||
static_assert(sizeof(T) == 0, "Unimplemented PropertyDelegate::defaultValue specialization");
|
||||
static_assert(sizeof(T) == 0,
|
||||
"Unimplemented PropertyDelegate::defaultValue specialization");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -49,7 +47,6 @@ U PropertyDelegate<T>::defaultMinimumValue() {
|
||||
"Unimplemented PropertyDelegate::defaultMinimumValue specialization");
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
U PropertyDelegate<T>::defaultMaximumValue() {
|
||||
@@ -57,5 +54,25 @@ U PropertyDelegate<T>::defaultMaximumValue() {
|
||||
"Unimplemented PropertyDelegate::defaultMaximumValue specialization");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
U PropertyDelegate<T>::fromLuaValue(lua_State* state, bool& success) {
|
||||
static_assert(sizeof(T) == 0,
|
||||
"Unimplemented PropertyDelegate::fromLuaValue specialization");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
bool PropertyDelegate<T>::toLuaValue(lua_State* state, U value) {
|
||||
static_assert(sizeof(T) == 0,
|
||||
"Unimplemented PropertyDelegate::toLuaValue specialization");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int PropertyDelegate<T>::typeLua() {
|
||||
static_assert(sizeof(T) == 0,
|
||||
"Unimplemented PropertyDelegate::luaType specialization");
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
@@ -33,29 +33,178 @@
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
/**
|
||||
* A PropertyOwner can own Propertys or other PropertyOwner and provide access to both in
|
||||
* a unified way. The <code>identifier</code>s and <code>name</code>s of Propertys and
|
||||
* sub-owners must be unique to this PropertyOwner. A Property cannot have the same name
|
||||
* as a PropertyOwner owned by this PropertyOwner.
|
||||
* Propertys can be added using the Property::addProperty methods and be removed by the
|
||||
* Property::removeProperty method. The same holds true for sub-owners
|
||||
* (Property::addPropertySubOwner, Property::removePropertySubOwner). These methods will
|
||||
* inform the passed object about the new ownership automatically.
|
||||
* Stored properties can be accessed using the Property::properties method or the
|
||||
* Property::property method, providing an URI for the location of the property. If the
|
||||
* URI contains separators (<code>.</code>), the first name before the separator will be
|
||||
* used as a subOwner's name and the search will proceed recursively.
|
||||
*/
|
||||
class PropertyOwner {
|
||||
public:
|
||||
/// The separator that is used while accessing the properties and/or sub-owners
|
||||
static const char URISeparator = '.';
|
||||
|
||||
/// The constructor initializing the PropertyOwner's name to <code>""</code>
|
||||
PropertyOwner();
|
||||
|
||||
/**
|
||||
* The destructor will remove all Propertys and PropertyOwners it owns along with
|
||||
* itself.
|
||||
*/
|
||||
virtual ~PropertyOwner();
|
||||
|
||||
/**
|
||||
* Sets the name for this PropertyOwner. If the PropertyOwner does not have an owner
|
||||
* itself, the name must be globally unique. If the PropertyOwner has an owner, the
|
||||
* name must be unique to the owner (including the owner's properties). No uniqueness
|
||||
* check will be preformed here, but rather in the PropertyOwner::addProperty and
|
||||
* PropertyOwner::addPropertySubOwner methods).
|
||||
* \param name The name of this PropertyOwner. It may not contain any <code>.</code>s
|
||||
*/
|
||||
void setName(std::string name);
|
||||
virtual const std::string& name() const;
|
||||
|
||||
/**
|
||||
* Returns the name of this PropertyOwner.
|
||||
* \return The name of this PropertyOwner
|
||||
*/
|
||||
const std::string& name() const;
|
||||
|
||||
/**
|
||||
* Returns a list of all Propertys directly owned by this PropertyOwner. This list not
|
||||
* include Propertys owned by other sub-owners.
|
||||
* \return A list of all Propertys directly owned by this PropertyOwner
|
||||
*/
|
||||
const std::vector<Property*>& properties() const;
|
||||
Property* property(const std::string& id) const;
|
||||
|
||||
/**
|
||||
* Retrieves a Property identified by <code>URI</code> from this PropertyOwner. If
|
||||
* <code>id</code> does not contain a <code>.</code> the identifier must refer to a
|
||||
* Property directly owned by this PropertyOwner. If the identifier contains one or
|
||||
* more <code>.</code>, the first part of the name will be recursively extracted and
|
||||
* used as a name for a sub-owner and only the last part of the identifier is
|
||||
* referring to a Property owned by PropertyOwner named by the second-but-last name.
|
||||
* \param URI The identifier of the Property that should be extracted. If the Property
|
||||
* cannot be found, <code>nullptr</code> is returned
|
||||
*/
|
||||
Property* property(const std::string& URI) const;
|
||||
|
||||
/**
|
||||
* This method checks if a Property with the provided <code>URI</code> exists in this
|
||||
* PropertyOwner (or any sub-owner). If the identifier contains one or more
|
||||
* <code>.</code>, the first part of the name will be recursively extracted and is
|
||||
* used as a name for a sub-owner and only the last part of the identifier is
|
||||
* referring to a Property owned by PropertyOwner named by the second-but-last name.
|
||||
* \return <code>true</code> if the <code>URI</code> refers to a Property;
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
bool hasProperty(const std::string& URI) const;
|
||||
|
||||
/**
|
||||
* Returns a list of all sub-owners this PropertyOwner has. Each name of a sub-owner
|
||||
* has to be unique with respect to other sub-owners as well as Property's owned by
|
||||
* this PropertyOwner.
|
||||
* \return A list of all sub-owners this PropertyOwner has
|
||||
*/
|
||||
const std::vector<PropertyOwner*>& subOwners() const;
|
||||
|
||||
/**
|
||||
* This method returns the direct sub-owner of this PropertyOwner with the provided
|
||||
* <code>name</code>. This means that <code>name</code> cannot contain any
|
||||
* <code>.</code> as this character is not allowed in PropertyOwner names. If the
|
||||
* <code>name</code> does not name a valid sub-owner of this PropertyOwner, a
|
||||
* <code>nullptr</code> will be returned.
|
||||
* \param name The name of the sub-owner that should be returned
|
||||
* \return The PropertyOwner with the given <code>name</code>, or <code>nullptr</code>
|
||||
*/
|
||||
PropertyOwner* subOwner(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this PropertyOwner owns a sub-owner with the provided
|
||||
* <code>name</code>; returns <code>false</code> otherwise.
|
||||
* \param name The name of the sub-owner that should be looked up
|
||||
* \return <code>true</code> if this PropertyOwner owns a sub-owner with the provided
|
||||
* <code>name</code>; returns <code>false</code> otherwise
|
||||
*/
|
||||
bool hasSubOwner(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* This method converts a provided <code>groupID</code>, used by the Propertys, into a
|
||||
* human-readable <code>name</code> which can be used by some external application.
|
||||
* \param groupID The group identifier whose human-readable name should be set
|
||||
* \param name The human-readable name for the group identifier
|
||||
*/
|
||||
void setPropertyGroupName(std::string groupID, std::string name);
|
||||
|
||||
/**
|
||||
* Returns the human-readable name for the <code>groupID</code> for the Propertys of
|
||||
* this PropertyOwner.
|
||||
* \param groupID The group identifier whose human-readable name should be returned
|
||||
* \return The human readable name for the Propertys identified by
|
||||
* <code>groupID</code>
|
||||
*/
|
||||
const std::string& propertyGroupName(const std::string& groupID) const;
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Assigns the Property <code>prop</code> to this PropertyOwner. This method will
|
||||
* check if the name of the Property is unique amongst Propertys and sub-owners in
|
||||
* this PropertyOwner. This method will also inform the Property about the change in
|
||||
* ownership by calling the Property::setPropertyOwner method.
|
||||
* \param prop The Property whose ownership is changed.
|
||||
*/
|
||||
void addProperty(Property* prop);
|
||||
|
||||
/// \see Property::addProperty(Property*)
|
||||
void addProperty(Property& prop);
|
||||
|
||||
/**
|
||||
* Adds the provided PropertyOwner to the list of sub-owners for this PropertyOwner.
|
||||
* This means that the name of the <code>owner</code> has to be unique amonst the
|
||||
* direct Property's as well as other PropertyOwner's that this PropertyOwner owns.
|
||||
* This uniqueness will be tested in this method.
|
||||
* \param owner The owner that should be assigned to this PropertyOwner
|
||||
*/
|
||||
void addPropertySubOwner(PropertyOwner* owner);
|
||||
|
||||
/// \see PropertyOwner::addPropertySubOwner(PropertyOwner*)
|
||||
void addPropertySubOwner(PropertyOwner& owner);
|
||||
|
||||
/**
|
||||
* Removes the Property from this PropertyOwner. Notifies the Property about this
|
||||
* change by calling the Property::setPropertyOwner method with a <code>nullptr</code>
|
||||
* as parameter.
|
||||
* \param prop The Property that should be removed from this PropertyOwner
|
||||
*/
|
||||
void removeProperty(Property* prop);
|
||||
|
||||
/// \see PropertyOwner::removeProperty(Property*)
|
||||
void removeProperty(Property& prop);
|
||||
|
||||
/**
|
||||
* Removes the sub-owner from this PropertyOwner.
|
||||
* \param owner The PropertyOwner that should be removed
|
||||
*/
|
||||
void removePropertySubOwner(PropertyOwner* owner);
|
||||
|
||||
/// \see PropertyOwner::removePropertySubOwner(PropertyOwner*)
|
||||
void removePropertySubOwner(PropertyOwner& owner);
|
||||
|
||||
private:
|
||||
/// The name of this PropertyOwner
|
||||
std::string _name;
|
||||
/// A list of all owned Property's
|
||||
std::vector<Property*> _properties;
|
||||
/// A list of all sub-owners
|
||||
std::vector<PropertyOwner*> _subOwners;
|
||||
/// The associations between group identifiers of Property's and human-readable names
|
||||
std::map<std::string, std::string> _groupNames;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,23 +30,7 @@
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
class StringProperty : public TemplateProperty<std::string> {
|
||||
public:
|
||||
StringProperty(std::string identifier, std::string guiName);
|
||||
StringProperty(std::string identifier, std::string guiName, std::string value);
|
||||
|
||||
using TemplateProperty<std::string>::operator=;
|
||||
};
|
||||
|
||||
template <>
|
||||
std::string PropertyDelegate<TemplateProperty<std::string>>::className();
|
||||
|
||||
template <>
|
||||
template <>
|
||||
std::string PropertyDelegate<TemplateProperty<std::string>>::defaultValue<std::string>();
|
||||
|
||||
//REGISTER_TEMPLATEPROPERTY_HEADER(StringProperty, std::string);
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_HEADER(StringProperty, std::string);
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
@@ -30,24 +30,144 @@
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
/**
|
||||
* This concrete subclass of Property handles a single parameter value that is of type
|
||||
* <code>T</code>. It provides all the necessary methods to automatically access the
|
||||
* value. One notable instantiation of this class is StringProperty, using
|
||||
* <code>T = std::string</code> while NumericalProperty is a templated subclass dealing
|
||||
* with numerical parameter types.
|
||||
* The accessor operator and assignment operators are overloaded, so that the
|
||||
* TemplateProperty can be used just in the same way as a regular member variable. In the
|
||||
* case that these cannot not be used inline, the Property::get method will work.
|
||||
* The default value for the stored value of this TemplateProperty is retrieved via a call
|
||||
* to the PropertyDelegate::defaultValue method, providing the template parameter
|
||||
* <code>T</code> as argument. When a new TemplateProperty is required, that method needs
|
||||
* to be specialized for the new type or a compile-time error will occur
|
||||
* (See http://openspace.itn.liu.se/trac/wiki/guides/properties).
|
||||
* \tparam T The type of value that is stored in this TemplateProperty
|
||||
* \see Property
|
||||
* \see NumericalProperty
|
||||
* \see PropertyDelegate
|
||||
*/
|
||||
template <typename T>
|
||||
class TemplateProperty : public Property {
|
||||
public:
|
||||
/**
|
||||
* The constructor initializing the TemplateProperty with the provided
|
||||
* <code>identifier</code> and human-readable <code>guiName</code>. The default value
|
||||
* for the stored type <code>T</code> is retrieved using the PropertyDelegate's
|
||||
* PropertyDelegate::defaultValue method, which must be specialized for new types or
|
||||
* a compile-error will occur.
|
||||
* \param identifier The identifier that is used for this TemplateProperty
|
||||
* \param guiName The human-readable GUI name for this TemplateProperty
|
||||
*/
|
||||
TemplateProperty(std::string identifier, std::string guiName);
|
||||
|
||||
/**
|
||||
* The constructor initializing the TemplateProperty with the provided
|
||||
* <code>identifier</code>, human-readable <code>guiName</code> and provided
|
||||
* <code>value</code>.
|
||||
*/
|
||||
TemplateProperty(std::string identifier, std::string guiName, T value);
|
||||
|
||||
/**
|
||||
* Returns the class name for this TemplateProperty. The default implementation makes
|
||||
* a call to the PropertyDelegate::className method with the template parameter
|
||||
* <code>T</code> as argument. For this to work, that method needs to be specialized
|
||||
* to return the correct class name for the new template parameter T, or a
|
||||
* compile-time error will occur.
|
||||
* \return The class name for the TemplateProperty
|
||||
*/
|
||||
virtual std::string className() const override;
|
||||
|
||||
/**
|
||||
* Returns the stored value packed into a <code>boost::any</code> object.
|
||||
* \return The stored value packed into a <code>boost::any</code> object
|
||||
*/
|
||||
virtual boost::any get() const override;
|
||||
|
||||
/**
|
||||
* Sets the value fro the provided <code>boost::any</code> object. If the types
|
||||
* between <code>T</code> and <code>value</code> disagree, an error is logged and the
|
||||
* stored value remains unchanged.
|
||||
*/
|
||||
virtual void set(boost::any value) override;
|
||||
|
||||
/**
|
||||
* Returns the <code>std::type_info</code> describing the template parameter
|
||||
* <code>T</code>. It can be used to test against a <code>boost::any</code> value
|
||||
* before trying to assign it.
|
||||
* \return The type info object describing the template parameter <code>T</code>
|
||||
*/
|
||||
virtual const std::type_info& type() const override;
|
||||
|
||||
/**
|
||||
* This method encodes the stored value into a Lua object and pushes that object onto
|
||||
* the stack. The encoding is performed by calling PropertyDelegate::toLuaValue with
|
||||
* the template parameter <code>T</code> as an argument. This method has to be
|
||||
* specialized for each new type, or a compile-time error will occur.
|
||||
* \param state The Lua state onto which the encoded object will be pushed
|
||||
* \return <code>true</code> if the encoding succeeded; <code>false</code> otherwise
|
||||
*/
|
||||
bool getLua(lua_State* state) const override;
|
||||
|
||||
/**
|
||||
* Sets the value of this TemplateProprty by decoding the object at the top of the Lua
|
||||
* stack and, if successful, assigning it using the Property::set method. The decoding
|
||||
* is performed by calling the PropertyDelegate::fromLuaValue with the template
|
||||
* parameter <code>T</code> as argument. If the decoding is successful, the new value
|
||||
* is set, otherwise it remains unchanged.
|
||||
* \param state The Lua state from which the value will be decoded
|
||||
* \return <code>true</code> if the decoding succeeded; <code>false</code> otherwise
|
||||
*/
|
||||
bool setLua(lua_State* state) override;
|
||||
|
||||
/// \see Property::typeLua
|
||||
int typeLua() const override;
|
||||
|
||||
/**
|
||||
* This operator allows the TemplateProperty to be used almost transparently as if it
|
||||
* was of the type <code>T</code>. It makes assignments such as
|
||||
* <code>T v = property;</code> possible by allowing implicit casts (even though,
|
||||
* internally, not casts are performed. This method is next to zero overhead).
|
||||
* \return The internal representation of the Property
|
||||
*/
|
||||
operator T();
|
||||
|
||||
/**
|
||||
* This operator allows the TemplateProperty to be used almost transparently as if it
|
||||
* was of the type <code>T</code>. It makes assignments such as
|
||||
* <code>T v = property;</code> possible by allowing implicit casts (even though,
|
||||
* internally, not casts are performed. This method is next to zero overhead).
|
||||
* \return The internal representation of the Property
|
||||
*/
|
||||
operator T() const;
|
||||
|
||||
/**
|
||||
* The assignment operator allows the TemplateProperty's value to be set without using
|
||||
* the TemplateProperty::set method. It will be done internally by thos method and it
|
||||
* allows assignments such as <code>prop = T(1)</code>.
|
||||
* \param val The value that should be set.
|
||||
*/
|
||||
TemplateProperty<T>& operator=(T val);
|
||||
|
||||
/**
|
||||
* These method sets the stored value to the provided value <code>val</code>,
|
||||
* moving it into place. This move only happens if the provided value <code>val</code>
|
||||
* is different from the stored value, which needs an operator== to exist for the type
|
||||
* <code>T</code>. If the value are different, the listeners are notified.
|
||||
* \param val The new value for this TemplateProperty
|
||||
*/
|
||||
void setValue(T val);
|
||||
|
||||
/**
|
||||
* Returns the currently stored value.
|
||||
* \return The currently stored value
|
||||
*/
|
||||
T value() const;
|
||||
|
||||
protected:
|
||||
/// The value that this TemplateProperty currently stores
|
||||
T _value;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,26 +25,82 @@
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
// The following macros can be used to quickly generate the necessary PropertyDelegate
|
||||
// specializations required by the TemplateProperty class. Use the
|
||||
// REGISTER_TEMPLATEPROPERTY_HEADER macro in the header file and the
|
||||
// REGISTER_TEMPLATEPROPERTY_SOURCE macro in the source file of your new specialization of
|
||||
// a TemplateProperty
|
||||
|
||||
|
||||
// CLASS_NAME = The string that the Property::className() should return as well as the
|
||||
// C++ class name for which a typedef will be created
|
||||
// TYPE = The template parameter T for which the TemplateProperty is specialized
|
||||
#define REGISTER_TEMPLATEPROPERTY_HEADER(CLASS_NAME, TYPE) \
|
||||
typedef TemplateProperty<TYPE> CLASS_NAME; \
|
||||
template <> \
|
||||
std::string PropertyDelegate<TemplateProperty<TYPE>>::className(); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::defaultValue<TYPE>();
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::defaultValue<TYPE>(); \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue(lua_State* state, \
|
||||
bool& success); \
|
||||
template <> \
|
||||
template <> \
|
||||
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue(lua_State* state, \
|
||||
TYPE value); \
|
||||
template <> \
|
||||
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua();
|
||||
|
||||
#define REGISTER_TEMPLATEPROPERTY_SOURCE(CLASS_NAME, TYPE, DEFAULT_VALUE) \
|
||||
// CLASS_NAME = The string that the Property::className() should return as well as the
|
||||
// C++ class name for which a typedef will be created
|
||||
// TYPE = The template parameter T for which the TemplateProperty is specialized
|
||||
// DEFAULT_VALUE = The value (as type T) which should be used as a default value
|
||||
// FROM_LUA_LAMBDA_EXPRESSION = A lambda expression receiving a lua_State* as the first
|
||||
// parameter, a bool& as the second parameter and returning
|
||||
// a value T. It is used by the fromLua method of
|
||||
// TemplateProperty. The lambda expression must extract the
|
||||
// stored value from the lua_State, return the value and
|
||||
// report success in the second argument
|
||||
// TO_LUA_LAMBDA_EXPRESSION = A lambda expression receiving a lua_State*, a value T and
|
||||
// returning a bool. The lambda expression must encode the
|
||||
// value T onto the lua_State stack and return the success
|
||||
// LUA_TYPE = The Lua type that will be produced/consumed by the previous
|
||||
// Lambda expressions
|
||||
#define REGISTER_TEMPLATEPROPERTY_SOURCE(CLASS_NAME, TYPE, DEFAULT_VALUE, \
|
||||
FROM_LUA_LAMBDA_EXPRESSION, \
|
||||
TO_LUA_LAMBDA_EXPRESSION, LUA_TYPE) \
|
||||
template <> \
|
||||
std::string PropertyDelegate<TemplateProperty<TYPE>>::className() { \
|
||||
std::string PropertyDelegate<TemplateProperty<TYPE>>::className() \
|
||||
{ \
|
||||
return #CLASS_NAME; \
|
||||
\
|
||||
} \
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::defaultValue<TYPE>() { \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::defaultValue<TYPE>() \
|
||||
{ \
|
||||
return DEFAULT_VALUE; \
|
||||
\
|
||||
}
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>(lua_State * state, \
|
||||
bool& success) \
|
||||
{ \
|
||||
return FROM_LUA_LAMBDA_EXPRESSION(state, success); \
|
||||
} \
|
||||
template <> \
|
||||
template <> \
|
||||
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State * state, \
|
||||
TYPE value) \
|
||||
{ \
|
||||
return TO_LUA_LAMBDA_EXPRESSION(state, value); \
|
||||
} \
|
||||
template <> \
|
||||
int PropertyDelegate<TemplateProperty<TYPE>>::typeLua() \
|
||||
{ \
|
||||
return LUA_TYPE; \
|
||||
}
|
||||
|
||||
// Delegating constructors are necessary; automatic template deduction cannot
|
||||
// deduce template argument for 'U' if 'default' methods are used as default values in
|
||||
@@ -52,15 +108,17 @@ namespace properties {
|
||||
|
||||
template <typename T>
|
||||
TemplateProperty<T>::TemplateProperty(std::string identifier, std::string guiName)
|
||||
: TemplateProperty<T>(std::move(identifier), std::move(guiName),
|
||||
PropertyDelegate<TemplateProperty<T>>::template defaultValue<T>()) {
|
||||
: TemplateProperty<T>(
|
||||
std::move(identifier), std::move(guiName),
|
||||
PropertyDelegate<TemplateProperty<T>>::template defaultValue<T>())
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TemplateProperty<T>::TemplateProperty(std::string identifier, std::string guiName,
|
||||
T value)
|
||||
: Property(std::move(identifier), std::move(guiName))
|
||||
, _value(value) {
|
||||
, _value(std::move(value)) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -73,6 +131,11 @@ TemplateProperty<T>::operator T() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TemplateProperty<T>::operator T() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TemplateProperty<T>& TemplateProperty<T>::operator=(T val) {
|
||||
setValue(val);
|
||||
@@ -88,7 +151,11 @@ T openspace::properties::TemplateProperty<T>::value() const
|
||||
template <typename T>
|
||||
void openspace::properties::TemplateProperty<T>::setValue(T val)
|
||||
{
|
||||
_value = val;
|
||||
const bool changed = (val != _value);
|
||||
if (changed) {
|
||||
_value = std::move(val);
|
||||
notifyListener();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,10 +167,15 @@ boost::any TemplateProperty<T>::get() const {
|
||||
template <typename T>
|
||||
void TemplateProperty<T>::set(boost::any value) {
|
||||
try {
|
||||
_value = boost::any_cast<T>(std::move(value));
|
||||
T v = boost::any_cast<T>(std::move(value));
|
||||
if (v != _value) {
|
||||
_value = std::move(v);
|
||||
notifyListener();
|
||||
}
|
||||
}
|
||||
catch (boost::bad_any_cast&) {
|
||||
LERRORC("TemplateProperty", "Illegal cast to '" << typeid(T).name() << "'");
|
||||
LERRORC("TemplateProperty", "Illegal cast from '" << value.type().name()
|
||||
<< "' to '" << typeid(T).name() << "'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,5 +184,27 @@ const std::type_info& TemplateProperty<T>::type() const {
|
||||
return typeid(T);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool TemplateProperty<T>::setLua(lua_State* state)
|
||||
{
|
||||
bool success;
|
||||
T thisValue = PropertyDelegate<TemplateProperty<T>>::template fromLuaValue<T>(state, success);
|
||||
if (success)
|
||||
set(boost::any(thisValue));
|
||||
return success;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool TemplateProperty<T>::getLua(lua_State* state) const
|
||||
{
|
||||
bool success = PropertyDelegate<TemplateProperty<T>>::template toLuaValue<T>(state, _value);
|
||||
return success;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int TemplateProperty<T>::typeLua() const {
|
||||
return PropertyDelegate<TemplateProperty<T>>::typeLua();
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
@@ -49,25 +49,6 @@ REGISTER_NUMERICALPROPERTY_HEADER(UVec2Property, glm::uvec2);
|
||||
REGISTER_NUMERICALPROPERTY_HEADER(UVec3Property, glm::uvec3);
|
||||
REGISTER_NUMERICALPROPERTY_HEADER(UVec4Property, glm::uvec4);
|
||||
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(CharProperty, char);
|
||||
////REGISTER_NUMERICALPROPERTY_HEADER(Char16Property, char16_t);
|
||||
////REGISTER_NUMERICALPROPERTY_HEADER(Char32Property, char32_t);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(WCharProperty, wchar_t);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(SignedCharProperty, signed char);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(UCharProperty, unsigned char);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(ShortProperty, short);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(UShortProperty, unsigned short);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(IntProperty, int);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(UIntProperty, unsigned int);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(LongProperty, long);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(ULongProperty, unsigned long);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(LongLongProperty, long long);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(ULongLongProperty, unsigned long long);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(FloatProperty, float);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(DoubleProperty, double);
|
||||
//REGISTER_NUMERICALPROPERTY_HEADER(LongDoubleProperty, long double);
|
||||
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -29,12 +29,15 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace properties {
|
||||
class Property;
|
||||
}
|
||||
class SceneGraph;
|
||||
class SceneGraphNode;
|
||||
|
||||
SceneGraph* getSceneGraph();
|
||||
|
||||
SceneGraphNode* getSceneGraphNode(const std::string& name);
|
||||
SceneGraph* sceneGraph();
|
||||
SceneGraphNode* sceneGraphNode(const std::string& name);
|
||||
properties::Property* property(const std::string& uri);
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
#ifndef __RENDERABLE_H__
|
||||
#define __RENDERABLE_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/powerscaledscalar.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -51,10 +52,16 @@ public:
|
||||
virtual void render(const Camera* camera, const psc& thisPosition) = 0;
|
||||
virtual void update();
|
||||
|
||||
bool isVisible() const;
|
||||
|
||||
protected:
|
||||
// Renderable();
|
||||
std::string findPath(const std::string& path);
|
||||
|
||||
private:
|
||||
properties::BoolProperty _enabled;
|
||||
|
||||
PowerScaledScalar boundingSphere_;
|
||||
std::string _relativePath;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 RENDERABLEFIELDLINES_H_
|
||||
#define RENDERABLEFIELDLINES_H_
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
namespace openspace {
|
||||
struct LinePoint;
|
||||
|
||||
class RenderableFieldlines : public Renderable {
|
||||
public:
|
||||
RenderableFieldlines(const ghoul::Dictionary& dictionary);
|
||||
~RenderableFieldlines();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
virtual void render(const Camera *camera, const psc& thisPosition);
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
std::vector<std::vector<LinePoint> > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary);
|
||||
|
||||
std::vector<ghoul::Dictionary> _hintsDictionaries;
|
||||
std::vector<std::string> _filenames;
|
||||
std::vector<glm::vec3> _seedPoints;
|
||||
|
||||
ghoul::opengl::ProgramObject *_fieldlinesProgram;
|
||||
GLuint _VAO, _seedpointVAO;
|
||||
|
||||
ghoul::filesystem::File* _vertexSourceFile;
|
||||
ghoul::filesystem::File* _fragmentSourceFile;
|
||||
|
||||
std::vector<GLint> _lineStart;
|
||||
std::vector<GLsizei> _lineCount;
|
||||
|
||||
bool _programUpdateOnSave;
|
||||
bool _update;
|
||||
void safeShaderCompilation();
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif // RENDERABLEFIELDLINES_H_
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/io/rawvolumereader.h>
|
||||
|
||||
@@ -37,23 +36,19 @@ namespace openspace {
|
||||
|
||||
class RenderableVolume: public Renderable {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderableVolume(const ghoul::Dictionary& dictionary);
|
||||
~RenderableVolume();
|
||||
|
||||
protected:
|
||||
std::string findPath(const std::string& path);
|
||||
ghoul::opengl::Texture* loadVolume(const std::string& filepath, const ghoul::Dictionary& hintsDictionary);
|
||||
glm::vec3 getVolumeOffset(const std::string& filepath, const ghoul::Dictionary& hintsDictionary);
|
||||
ghoul::RawVolumeReader::ReadHints readHints(const ghoul::Dictionary& dictionary);
|
||||
ghoul::opengl::Texture* loadTransferFunction(const std::string& filepath);
|
||||
|
||||
private:
|
||||
|
||||
// relative path
|
||||
std::string _relativePath;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,105 +1,106 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __RENDERABLEVOLUMECL_H__
|
||||
#define __RENDERABLEVOLUMECL_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderablevolume.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
#include <ghoul/opencl/clcontext.h>
|
||||
#include <ghoul/opencl/clcommandqueue.h>
|
||||
#include <ghoul/opencl/clprogram.h>
|
||||
#include <ghoul/opencl/clkernel.h>
|
||||
#include <ghoul/opencl/clworksize.h>
|
||||
#include <ghoul/io/rawvolumereader.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
#define SGCT_WINDOWS_INCLUDE
|
||||
#include <sgct.h>
|
||||
|
||||
namespace sgct_utils {
|
||||
class SGCTBox;
|
||||
}
|
||||
|
||||
//#include <vector>
|
||||
//#include <string>
|
||||
#ifdef __APPLE__
|
||||
#include <memory>
|
||||
#else
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderableVolumeCL: public RenderableVolume {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderableVolumeCL(const ghoul::Dictionary& dictionary);
|
||||
~RenderableVolumeCL();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
virtual void render(const Camera *camera, const psc& thisPosition);
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
|
||||
void safeKernelCompilation();
|
||||
|
||||
std::string _filename;
|
||||
ghoul::RawVolumeReader::ReadHints _hints;
|
||||
float _stepSize;
|
||||
ghoul::opengl::FramebufferObject* _fbo;
|
||||
ghoul::opengl::Texture* _backTexture;
|
||||
ghoul::opengl::Texture* _frontTexture;
|
||||
ghoul::opengl::Texture* _volume;
|
||||
ghoul::opengl::Texture* _output;
|
||||
ghoul::opengl::ProgramObject *_fboProgram;
|
||||
ghoul::opengl::ProgramObject *_quadProgram;
|
||||
sgct_utils::SGCTBox* _boundingBox;
|
||||
GLuint _screenQuad;
|
||||
|
||||
ghoul::opencl::CLContext _context;
|
||||
ghoul::opencl::CLCommandQueue _commands;
|
||||
ghoul::opencl::CLProgram _program;
|
||||
ghoul::opencl::CLKernel _kernel;
|
||||
ghoul::opencl::CLWorkSize* _ws;
|
||||
cl_mem _clBackTexture, _clFrontTexture, _clVolume, _clOutput;
|
||||
|
||||
ghoul::filesystem::File* _kernelSourceFile;
|
||||
bool _kernelUpdateOnSave;
|
||||
std::mutex* _kernelMutex;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
// This is still in the repository to be cannibalized for a possible rewrite (ab)
|
||||
///*****************************************************************************************
|
||||
// * *
|
||||
// * OpenSpace *
|
||||
// * *
|
||||
// * Copyright (c) 2014 *
|
||||
// * *
|
||||
// * 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 __RENDERABLEVOLUMECL_H__
|
||||
//#define __RENDERABLEVOLUMECL_H__
|
||||
//
|
||||
//// open space includes
|
||||
//#include <openspace/rendering/renderablevolume.h>
|
||||
//
|
||||
//// ghoul includes
|
||||
//#include <ghoul/opengl/programobject.h>
|
||||
//#include <ghoul/opengl/texture.h>
|
||||
//#include <ghoul/opengl/framebufferobject.h>
|
||||
//#include <ghoul/opencl/clcontext.h>
|
||||
//#include <ghoul/opencl/clcommandqueue.h>
|
||||
//#include <ghoul/opencl/clprogram.h>
|
||||
//#include <ghoul/opencl/clkernel.h>
|
||||
//#include <ghoul/opencl/clworksize.h>
|
||||
//#include <ghoul/io/rawvolumereader.h>
|
||||
//#include <ghoul/filesystem/file.h>
|
||||
//
|
||||
//#define SGCT_WINDOWS_INCLUDE
|
||||
//#include <sgct.h>
|
||||
//
|
||||
//namespace sgct_utils {
|
||||
// class SGCTBox;
|
||||
//}
|
||||
//
|
||||
////#include <vector>
|
||||
////#include <string>
|
||||
//#ifdef __APPLE__
|
||||
// #include <memory>
|
||||
//#else
|
||||
// #include <mutex>
|
||||
//#endif
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//class RenderableVolumeCL: public RenderableVolume {
|
||||
//public:
|
||||
//
|
||||
// // constructors & destructor
|
||||
// RenderableVolumeCL(const ghoul::Dictionary& dictionary);
|
||||
// ~RenderableVolumeCL();
|
||||
//
|
||||
// bool initialize();
|
||||
// bool deinitialize();
|
||||
//
|
||||
// virtual void render(const Camera *camera, const psc& thisPosition);
|
||||
// virtual void update();
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// void safeKernelCompilation();
|
||||
//
|
||||
// std::string _filename;
|
||||
// ghoul::RawVolumeReader::ReadHints _hints;
|
||||
// float _stepSize;
|
||||
// ghoul::opengl::FramebufferObject* _fbo;
|
||||
// ghoul::opengl::Texture* _backTexture;
|
||||
// ghoul::opengl::Texture* _frontTexture;
|
||||
// ghoul::opengl::Texture* _volume;
|
||||
// ghoul::opengl::Texture* _output;
|
||||
// ghoul::opengl::ProgramObject *_fboProgram;
|
||||
// ghoul::opengl::ProgramObject *_quadProgram;
|
||||
// sgct_utils::SGCTBox* _boundingBox;
|
||||
// GLuint _screenQuad;
|
||||
//
|
||||
// ghoul::opencl::CLContext _context;
|
||||
// ghoul::opencl::CLCommandQueue _commands;
|
||||
// ghoul::opencl::CLProgram _program;
|
||||
// ghoul::opencl::CLKernel _kernel;
|
||||
// ghoul::opencl::CLWorkSize* _ws;
|
||||
// cl_mem _clBackTexture, _clFrontTexture, _clVolume, _clOutput;
|
||||
//
|
||||
// ghoul::filesystem::File* _kernelSourceFile;
|
||||
// bool _kernelUpdateOnSave;
|
||||
// std::mutex* _kernelMutex;
|
||||
//
|
||||
//};
|
||||
//
|
||||
//} // namespace openspace
|
||||
//
|
||||
//#endif
|
||||
@@ -1,118 +1,119 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __RENDERABLEVOLUMEEXPERT_H__
|
||||
#define __RENDERABLEVOLUMEEXPERT_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderablevolume.h>
|
||||
#include <openspace/rendering/volumeraycasterbox.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
#include <ghoul/opencl/clcontext.h>
|
||||
#include <ghoul/opencl/clcommandqueue.h>
|
||||
#include <ghoul/opencl/clprogram.h>
|
||||
#include <ghoul/opencl/clkernel.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <memory>
|
||||
#else
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace ghoul {
|
||||
namespace opencl {
|
||||
class CLWorkSize;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderableVolumeExpert: public RenderableVolume {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderableVolumeExpert(const ghoul::Dictionary& dictionary);
|
||||
~RenderableVolumeExpert();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
virtual void render(const Camera *camera, const psc& thisPosition);
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
|
||||
// private methods
|
||||
void safeKernelCompilation();
|
||||
void safeUpdateTexture(const ghoul::filesystem::File& file);
|
||||
|
||||
// Volumes
|
||||
std::vector<std::string> _volumePaths;
|
||||
std::vector<ghoul::Dictionary> _volumeHints;
|
||||
|
||||
// Textures
|
||||
ghoul::opengl::Texture* _output;
|
||||
std::vector<ghoul::opengl::Texture*> _volumes;
|
||||
std::vector<ghoul::opengl::Texture*> _transferFunctions;
|
||||
std::vector<ghoul::filesystem::File*> _transferFunctionsFiles;
|
||||
|
||||
// opencl texture memory pointers
|
||||
cl_mem _clBackTexture;
|
||||
cl_mem _clFrontTexture;
|
||||
cl_mem _clOutput;
|
||||
std::vector<cl_mem> _clVolumes;
|
||||
std::vector<cl_mem> _clTransferFunctions;
|
||||
|
||||
// opencl program
|
||||
ghoul::opencl::CLContext _context;
|
||||
ghoul::opencl::CLCommandQueue _commands;
|
||||
ghoul::opencl::CLProgram _program;
|
||||
ghoul::opencl::CLKernel _kernel;
|
||||
ghoul::opencl::CLWorkSize* _ws;
|
||||
ghoul::filesystem::File* _kernelSourceFile;
|
||||
std::vector<std::pair<ghoul::opencl::CLProgram::Option, bool> > _kernelOptions;
|
||||
std::vector<std::string> _kernelIncludes;
|
||||
std::vector<std::pair<std::string,std::string> > _kernelDefinitions;
|
||||
bool _programUpdateOnSave;
|
||||
|
||||
// mutexes to prevent inconsistencies
|
||||
std::mutex* _kernelLock;
|
||||
std::mutex* _textureLock;
|
||||
|
||||
ghoul::opengl::ProgramObject *_quadProgram;
|
||||
GLuint _screenQuad;
|
||||
|
||||
VolumeRaycasterBox* _colorBoxRenderer;
|
||||
glm::vec3 _boxScaling;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
// This is still in the repository to be cannibalized for a possible rewrite (ab)
|
||||
///*****************************************************************************************
|
||||
// * *
|
||||
// * OpenSpace *
|
||||
// * *
|
||||
// * Copyright (c) 2014 *
|
||||
// * *
|
||||
// * 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 __RENDERABLEVOLUMEEXPERT_H__
|
||||
//#define __RENDERABLEVOLUMEEXPERT_H__
|
||||
//
|
||||
//// open space includes
|
||||
//#include <openspace/rendering/renderablevolume.h>
|
||||
//#include <openspace/rendering/volumeraycasterbox.h>
|
||||
//
|
||||
//// ghoul includes
|
||||
//#include <ghoul/opengl/programobject.h>
|
||||
//#include <ghoul/opengl/texture.h>
|
||||
//#include <ghoul/opengl/framebufferobject.h>
|
||||
//#include <ghoul/opencl/clcontext.h>
|
||||
//#include <ghoul/opencl/clcommandqueue.h>
|
||||
//#include <ghoul/opencl/clprogram.h>
|
||||
//#include <ghoul/opencl/clkernel.h>
|
||||
//#include <ghoul/filesystem/file.h>
|
||||
//
|
||||
//#ifdef __APPLE__
|
||||
// #include <memory>
|
||||
//#else
|
||||
// #include <mutex>
|
||||
//#endif
|
||||
//
|
||||
//namespace ghoul {
|
||||
// namespace opencl {
|
||||
// class CLWorkSize;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//class RenderableVolumeExpert: public RenderableVolume {
|
||||
//public:
|
||||
//
|
||||
// // constructors & destructor
|
||||
// RenderableVolumeExpert(const ghoul::Dictionary& dictionary);
|
||||
// ~RenderableVolumeExpert();
|
||||
//
|
||||
// bool initialize();
|
||||
// bool deinitialize();
|
||||
//
|
||||
// virtual void render(const Camera *camera, const psc& thisPosition);
|
||||
// virtual void update();
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// // private methods
|
||||
// void safeKernelCompilation();
|
||||
// void safeUpdateTexture(const ghoul::filesystem::File& file);
|
||||
//
|
||||
// // Volumes
|
||||
// std::vector<std::string> _volumePaths;
|
||||
// std::vector<ghoul::Dictionary> _volumeHints;
|
||||
//
|
||||
// // Textures
|
||||
// ghoul::opengl::Texture* _output;
|
||||
// std::vector<ghoul::opengl::Texture*> _volumes;
|
||||
// std::vector<ghoul::opengl::Texture*> _transferFunctions;
|
||||
// std::vector<ghoul::filesystem::File*> _transferFunctionsFiles;
|
||||
//
|
||||
// // opencl texture memory pointers
|
||||
// cl_mem _clBackTexture;
|
||||
// cl_mem _clFrontTexture;
|
||||
// cl_mem _clOutput;
|
||||
// std::vector<cl_mem> _clVolumes;
|
||||
// std::vector<cl_mem> _clTransferFunctions;
|
||||
//
|
||||
// // opencl program
|
||||
// ghoul::opencl::CLContext _context;
|
||||
// ghoul::opencl::CLCommandQueue _commands;
|
||||
// ghoul::opencl::CLProgram _program;
|
||||
// ghoul::opencl::CLKernel _kernel;
|
||||
// ghoul::opencl::CLWorkSize* _ws;
|
||||
// ghoul::filesystem::File* _kernelSourceFile;
|
||||
// std::vector<std::pair<ghoul::opencl::CLProgram::Option, bool> > _kernelOptions;
|
||||
// std::vector<std::string> _kernelIncludes;
|
||||
// std::vector<std::pair<std::string,std::string> > _kernelDefinitions;
|
||||
// bool _programUpdateOnSave;
|
||||
//
|
||||
// // mutexes to prevent inconsistencies
|
||||
// std::mutex* _kernelLock;
|
||||
// std::mutex* _textureLock;
|
||||
//
|
||||
// ghoul::opengl::ProgramObject *_quadProgram;
|
||||
// GLuint _screenQuad;
|
||||
//
|
||||
// VolumeRaycasterBox* _colorBoxRenderer;
|
||||
// glm::vec3 _boxScaling;
|
||||
//
|
||||
//};
|
||||
//
|
||||
//} // namespace openspace
|
||||
//
|
||||
//#endif
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __RENDERABLEVOLUMEGL_H__
|
||||
#define __RENDERABLEVOLUMEGL_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderablevolume.h>
|
||||
|
||||
// ghoul includes
|
||||
@@ -35,25 +34,10 @@
|
||||
#include <ghoul/io/rawvolumereader.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
#define SGCT_WINDOWS_INCLUDE
|
||||
#include <sgct.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <memory>
|
||||
#else
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace sgct_utils {
|
||||
class SGCTBox;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderableVolumeGL: public RenderableVolume {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderableVolumeGL(const ghoul::Dictionary& dictionary);
|
||||
~RenderableVolumeGL();
|
||||
|
||||
@@ -64,29 +48,31 @@ public:
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
ghoul::Dictionary _hintsDictionary;
|
||||
|
||||
std::string _filename;
|
||||
ghoul::RawVolumeReader::ReadHints _hints;
|
||||
float _stepSize;
|
||||
ghoul::opengl::FramebufferObject* _fbo;
|
||||
ghoul::opengl::Texture* _backTexture;
|
||||
ghoul::opengl::Texture* _frontTexture;
|
||||
|
||||
std::string _transferFunctionName;
|
||||
std::string _volumeName;
|
||||
|
||||
std::string _transferFunctionPath;
|
||||
std::string _samplerFilename;
|
||||
|
||||
ghoul::filesystem::File* _transferFunctionFile;
|
||||
|
||||
ghoul::opengl::Texture* _volume;
|
||||
ghoul::opengl::ProgramObject *_fboProgram, *_twopassProgram;
|
||||
sgct_utils::SGCTBox* _boundingBox;
|
||||
GLuint _screenQuad;
|
||||
|
||||
std::mutex* _shaderMutex;
|
||||
|
||||
ghoul::filesystem::File* _vertexSourceFile;
|
||||
ghoul::filesystem::File* _fragmentSourceFile;
|
||||
bool _programUpdateOnSave;
|
||||
|
||||
void safeShaderCompilation();
|
||||
ghoul::opengl::Texture* _transferFunction;
|
||||
|
||||
GLuint _boxArray;
|
||||
ghoul::opengl::ProgramObject *_boxProgram;
|
||||
glm::vec3 _boxScaling, _boxOffset;
|
||||
float _w;
|
||||
GLint _MVPLocation, _modelTransformLocation, _typeLocation;
|
||||
|
||||
bool _updateTransferfunction;
|
||||
int _id;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
@@ -45,6 +47,7 @@ public:
|
||||
SceneGraph* sceneGraph();
|
||||
|
||||
Camera* camera() const;
|
||||
ABuffer* abuffer() const;
|
||||
|
||||
// sgct wrapped functions
|
||||
bool initializeGL();
|
||||
@@ -58,6 +61,8 @@ public:
|
||||
private:
|
||||
Camera* _mainCamera;
|
||||
SceneGraph* _sceneGraph;
|
||||
|
||||
ABuffer* _abuffer;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
VolumeRaycasterBox();
|
||||
~VolumeRaycasterBox();
|
||||
bool initialize();
|
||||
void render(const glm::mat4& MVP);
|
||||
void render(const glm::mat4& MVP, const glm::mat4& transform = glm::mat4(1.0), int type = 0);
|
||||
|
||||
ghoul::opengl::Texture* backFace();
|
||||
ghoul::opengl::Texture* frontFace();
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
ghoul::opengl::Texture *_backTexture, *_frontTexture;
|
||||
ghoul::opengl::ProgramObject *_boxProgram;
|
||||
sgct_utils::SGCTBox* _boundingBox;
|
||||
GLint _MVPLocation;
|
||||
GLint _MVPLocation, _modelTransformLocation, _typeLocation;
|
||||
|
||||
glm::size2_t _dimensions;
|
||||
};
|
||||
|
||||
@@ -36,9 +36,9 @@ public:
|
||||
|
||||
Ephemeris(const ghoul::Dictionary& dictionary);
|
||||
virtual ~Ephemeris();
|
||||
virtual bool initialize() = 0;
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const = 0;
|
||||
virtual void update() = 0;
|
||||
virtual void update();
|
||||
|
||||
protected:
|
||||
Ephemeris();
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef SCENEGRAPH_H
|
||||
#define SCENEGRAPH_H
|
||||
#ifndef __SCENEGRAPH_H__
|
||||
#define __SCENEGRAPH_H__
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
@@ -31,12 +31,15 @@
|
||||
|
||||
#include <openspace/util/camera.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
class SceneGraphNode;
|
||||
|
||||
class SceneGraph {
|
||||
@@ -94,6 +97,16 @@ public:
|
||||
*/
|
||||
SceneGraphNode* sceneGraphNode(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to change the
|
||||
* scene graph. The functions contained are
|
||||
* - openspace::luascriptfunctions::property_setValue
|
||||
* - openspace::luascriptfunctions::property_getValue
|
||||
* \return The Lua library that contains all Lua functions available to change the
|
||||
* scene graph
|
||||
*/
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
std::string _focus, _position;
|
||||
|
||||
@@ -105,4 +118,4 @@ private:
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif // __SCENEGRAPH_H__
|
||||
@@ -22,12 +22,13 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef SCENEGRAPHNODE_H
|
||||
#define SCENEGRAPHNODE_H
|
||||
#ifndef __SCENEGRAPHNODE_H__
|
||||
#define __SCENEGRAPHNODE_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scenegraph/ephemeris.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
@@ -40,8 +41,10 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraphNode {
|
||||
class SceneGraphNode : public properties::PropertyOwner {
|
||||
public:
|
||||
static std::string RootNodeName;
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraphNode();
|
||||
~SceneGraphNode();
|
||||
@@ -59,31 +62,30 @@ public:
|
||||
// set & get
|
||||
void addNode(SceneGraphNode* child);
|
||||
|
||||
void setName(const std::string& name);
|
||||
void setParent(SceneGraphNode* parent);
|
||||
const psc& getPosition() const;
|
||||
psc getWorldPosition() const;
|
||||
std::string nodeName() const;
|
||||
const psc& position() const;
|
||||
psc worldPosition() const;
|
||||
|
||||
SceneGraphNode* parent() const;
|
||||
const std::vector<SceneGraphNode*>& children() const;
|
||||
|
||||
// bounding sphere
|
||||
PowerScaledScalar calculateBoundingSphere();
|
||||
PowerScaledScalar boundingSphere() const;
|
||||
|
||||
SceneGraphNode* get(const std::string& name);
|
||||
SceneGraphNode* childNode(const std::string& name);
|
||||
|
||||
void print() const;
|
||||
|
||||
// renderable
|
||||
void setRenderable(Renderable* renderable);
|
||||
const Renderable* getRenderable() const;
|
||||
const Renderable* renderable() const;
|
||||
Renderable* renderable();
|
||||
|
||||
private:
|
||||
// essential
|
||||
std::vector<SceneGraphNode*> _children;
|
||||
SceneGraphNode* _parent;
|
||||
std::string _nodeName;
|
||||
Ephemeris* _ephemeris;
|
||||
|
||||
// renderable
|
||||
@@ -100,4 +102,4 @@ private:
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif // __SCENEGRAPHNODE_H__
|
||||
|
||||
@@ -31,20 +31,20 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SpiceEphemeris: public Ephemeris {
|
||||
class SpiceEphemeris : public Ephemeris {
|
||||
public:
|
||||
SpiceEphemeris(const ghoul::Dictionary& dictionary);
|
||||
virtual ~SpiceEphemeris();
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const;
|
||||
virtual void update();
|
||||
protected:
|
||||
private:
|
||||
|
||||
std::string _targetName, _originName;
|
||||
int _target, _origin;
|
||||
private:
|
||||
std::string _targetName;
|
||||
std::string _originName;
|
||||
int _target;
|
||||
int _origin;
|
||||
psc _position;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -33,14 +33,11 @@ class StaticEphemeris: public Ephemeris {
|
||||
public:
|
||||
StaticEphemeris(const ghoul::Dictionary& dictionary
|
||||
= ghoul::Dictionary());
|
||||
virtual ~StaticEphemeris();
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const;
|
||||
virtual void update();
|
||||
protected:
|
||||
~StaticEphemeris();
|
||||
const psc& position() const;
|
||||
|
||||
private:
|
||||
psc _position;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __SCRIPTENGINE_H__
|
||||
#define __SCRIPTENGINE_H__
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <set>
|
||||
|
||||
/**
|
||||
* \defgroup LuaScripts Lua Scripts
|
||||
*/
|
||||
|
||||
namespace openspace {
|
||||
namespace scripting {
|
||||
|
||||
class ScriptEngine {
|
||||
public:
|
||||
struct LuaLibrary {
|
||||
struct Function {
|
||||
std::string name;
|
||||
lua_CFunction function;
|
||||
std::string helpText;
|
||||
};
|
||||
std::string name;
|
||||
std::vector<Function> functions;
|
||||
|
||||
bool operator<(const LuaLibrary& rhs) const;
|
||||
};
|
||||
|
||||
ScriptEngine();
|
||||
|
||||
bool initialize();
|
||||
void deinitialize();
|
||||
|
||||
bool addLibrary(const LuaLibrary& library);
|
||||
bool hasLibrary(const std::string& name);
|
||||
|
||||
bool runScript(const std::string& script);
|
||||
bool runScriptFile(const std::string& filename);
|
||||
|
||||
private:
|
||||
bool isLibraryNameAllowed(const std::string& name);
|
||||
void addLibraryFunctions(const LuaLibrary& library, bool replace);
|
||||
|
||||
void addBaseLibrary();
|
||||
void remapPrintFunction();
|
||||
|
||||
lua_State* _state;
|
||||
std::set<LuaLibrary> _registeredLibraries;
|
||||
};
|
||||
|
||||
} // namespace scripting
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __SCRIPTENGINE_H__
|
||||
@@ -0,0 +1,151 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 "gtest/gtest.h"
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <openspace/properties/propertydelegate.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/matrixproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
class LuaConversionTest : public testing::Test {
|
||||
protected:
|
||||
lua_State* state;
|
||||
|
||||
LuaConversionTest() {
|
||||
state = luaL_newstate();
|
||||
luaL_openlibs(state);
|
||||
}
|
||||
|
||||
~LuaConversionTest() {
|
||||
lua_close(state);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
lua_close(state);
|
||||
state = luaL_newstate();
|
||||
luaL_openlibs(state);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LuaConversionTest, LuaExecution) {
|
||||
int status = luaL_loadstring(state, "");
|
||||
EXPECT_EQ(status, LUA_OK);
|
||||
}
|
||||
|
||||
#define CONVERSION_TEST_TEMPLATE(__NAME__, __TYPE__, __VALUE__) \
|
||||
TEST_F(LuaConversionTest, __NAME__) \
|
||||
{ \
|
||||
using namespace openspace::properties; \
|
||||
bool success \
|
||||
= PropertyDelegate<TemplateProperty<__TYPE__>>::toLuaValue<__TYPE__>( \
|
||||
state, __VALUE__); \
|
||||
EXPECT_TRUE(success) << "toLuaValue"; \
|
||||
__TYPE__ value = (__TYPE__)(0); \
|
||||
value = PropertyDelegate<TemplateProperty<__TYPE__>>::fromLuaValue<__TYPE__>( \
|
||||
state, success); \
|
||||
EXPECT_TRUE(success) << "fromLuaValue"; \
|
||||
EXPECT_EQ(value, __VALUE__) << "fromLuaValue"; \
|
||||
}
|
||||
|
||||
#define CONVERSION_TEST_NUMERICAL(__NAME__, __TYPE__, __VALUE__) \
|
||||
TEST_F(LuaConversionTest, __NAME__) \
|
||||
{ \
|
||||
using namespace openspace::properties; \
|
||||
bool success \
|
||||
= PropertyDelegate<NumericalProperty<__TYPE__>>::toLuaValue<__TYPE__>( \
|
||||
state, __VALUE__); \
|
||||
EXPECT_TRUE(success) << "toLuaValue"; \
|
||||
__TYPE__ value = (__TYPE__)(0); \
|
||||
value = PropertyDelegate<NumericalProperty<__TYPE__>>::fromLuaValue<__TYPE__>( \
|
||||
state, success); \
|
||||
EXPECT_TRUE(success) << "fromLuaValue"; \
|
||||
EXPECT_EQ(value, __VALUE__) << "fromLuaValue"; \
|
||||
}
|
||||
|
||||
CONVERSION_TEST_TEMPLATE(Bool, bool, true);
|
||||
|
||||
CONVERSION_TEST_NUMERICAL(Char, char, 1);
|
||||
CONVERSION_TEST_NUMERICAL(WChar, wchar_t, 1);
|
||||
CONVERSION_TEST_NUMERICAL(SignedChar, signed char, 1);
|
||||
CONVERSION_TEST_NUMERICAL(UnsignedChar, unsigned char, 1);
|
||||
CONVERSION_TEST_NUMERICAL(Short, short, 1);
|
||||
CONVERSION_TEST_NUMERICAL(UnsignedShort, unsigned short, 1);
|
||||
CONVERSION_TEST_NUMERICAL(Int, int, 1);
|
||||
CONVERSION_TEST_NUMERICAL(UnsignedInt, unsigned int, 1);
|
||||
CONVERSION_TEST_NUMERICAL(Long, long, 1);
|
||||
CONVERSION_TEST_NUMERICAL(UnsignedLong, unsigned long, 1);
|
||||
CONVERSION_TEST_NUMERICAL(LongLong, long long, 1);
|
||||
CONVERSION_TEST_NUMERICAL(UnsignedLongLong, unsigned long long, 1);
|
||||
CONVERSION_TEST_NUMERICAL(Float, float, 1.f);
|
||||
CONVERSION_TEST_NUMERICAL(Double, double, 1.0);
|
||||
CONVERSION_TEST_NUMERICAL(LongDouble, long double, 1.0);
|
||||
|
||||
CONVERSION_TEST_NUMERICAL(Vec2, glm::vec2, glm::vec2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Vec3, glm::vec3, glm::vec3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Vec4, glm::vec4, glm::vec4(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DVec2, glm::dvec2, glm::dvec2(1.0));
|
||||
CONVERSION_TEST_NUMERICAL(DVec3, glm::dvec3, glm::dvec3(1.0));
|
||||
CONVERSION_TEST_NUMERICAL(DVec4, glm::dvec4, glm::dvec4(1.0));
|
||||
CONVERSION_TEST_NUMERICAL(IVec2, glm::ivec2, glm::ivec2(1));
|
||||
CONVERSION_TEST_NUMERICAL(IVec3, glm::ivec3, glm::ivec3(1));
|
||||
CONVERSION_TEST_NUMERICAL(IVec4, glm::ivec4, glm::ivec4(1));
|
||||
CONVERSION_TEST_NUMERICAL(UVec2, glm::uvec2, glm::uvec2(1));
|
||||
CONVERSION_TEST_NUMERICAL(UVec3, glm::uvec3, glm::uvec3(1));
|
||||
CONVERSION_TEST_NUMERICAL(UVec4, glm::uvec4, glm::uvec4(1));
|
||||
|
||||
CONVERSION_TEST_NUMERICAL(Mat2x2, glm::mat2x2, glm::mat2x2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat2x3, glm::mat2x3, glm::mat2x3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat2x4, glm::mat2x4, glm::mat2x4(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat3x2, glm::mat3x2, glm::mat3x2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat3x3, glm::mat3x3, glm::mat3x3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat3x4, glm::mat3x4, glm::mat3x4(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat4x2, glm::mat4x2, glm::mat4x2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat4x3, glm::mat4x3, glm::mat4x3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(Mat4x4, glm::mat4x4, glm::mat4x4(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat2x2, glm::dmat2x2, glm::dmat2x2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat2x3, glm::dmat2x3, glm::dmat2x3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat2x4, glm::dmat2x4, glm::dmat2x4(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat3x2, glm::dmat3x2, glm::dmat3x2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat3x3, glm::dmat3x3, glm::dmat3x3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat3x4, glm::dmat3x4, glm::dmat3x4(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat4x2, glm::dmat4x2, glm::dmat4x2(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat4x3, glm::dmat4x3, glm::dmat4x3(1.f));
|
||||
CONVERSION_TEST_NUMERICAL(DMat4x4, glm::dmat4x4, glm::dmat4x4(1.f));
|
||||
|
||||
TEST_F(LuaConversionTest, String)
|
||||
{
|
||||
using namespace openspace::properties;
|
||||
bool success
|
||||
= PropertyDelegate<TemplateProperty<std::string>>::toLuaValue<std::string>(
|
||||
state, "value");
|
||||
EXPECT_TRUE(success) << "toLuaValue";
|
||||
std::string value = "";
|
||||
value = PropertyDelegate<TemplateProperty<std::string>>::fromLuaValue<std::string>(
|
||||
state, success);
|
||||
EXPECT_TRUE(success) << "fromLuaValue";
|
||||
EXPECT_EQ(value, "value") << "fromLuaValue";
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2012-2014 *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 *
|
||||
@@ -25,6 +24,8 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/powerscaledscalar.h>
|
||||
|
||||
@@ -45,10 +46,10 @@ protected:
|
||||
|
||||
TEST_F(PowerscaleCoordinatesTest, psc) {
|
||||
|
||||
openspace::psc reference(2.0, 1.0, 1.1, 1.0);
|
||||
openspace::psc reference(2.f, 1.f, 1.1f, 1.f);
|
||||
|
||||
openspace::psc first(1.0,0.0,1.0,0.0);
|
||||
openspace::psc second(1.9,1.0,1.0,1.0);
|
||||
openspace::psc first(1.f, 0.f, 1.f, 0.f);
|
||||
openspace::psc second(1.9f, 1.f, 1.f, 1.f);
|
||||
|
||||
EXPECT_EQ(reference, first + second);
|
||||
EXPECT_TRUE(reference == (first + second));
|
||||
@@ -63,10 +64,10 @@ TEST_F(PowerscaleCoordinatesTest, psc) {
|
||||
|
||||
TEST_F(PowerscaleCoordinatesTest, pss) {
|
||||
|
||||
openspace::pss first(1.0,1.0);
|
||||
openspace::pss second(1.0,-1.0);
|
||||
EXPECT_EQ(openspace::pss(1.01,1.0), first + second);
|
||||
EXPECT_EQ(openspace::pss(1.01,1.0), second + first);
|
||||
openspace::pss first(1.f, 1.f);
|
||||
openspace::pss second(1.f, -1.f);
|
||||
EXPECT_EQ(openspace::pss(1.01f, 1.f), first + second);
|
||||
EXPECT_EQ(openspace::pss(1.01f, 1.f), second + first);
|
||||
/*
|
||||
EXPECT_TRUE(first < (first + second));
|
||||
bool retu =(second < (first + second));
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2012-2014 *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 *
|
||||
@@ -55,8 +54,8 @@ TEST_F(SceneGraphTest, SceneGraphNode) {
|
||||
openspace::SceneGraphNode::createFromDictionary(ghoul::Dictionary());
|
||||
|
||||
// Should not have a renderable and position should be 0,0,0,0 (undefined).
|
||||
EXPECT_EQ(nullptr, node->getRenderable());
|
||||
EXPECT_EQ(openspace::psc(), node->getPosition());
|
||||
EXPECT_EQ(nullptr, node->renderable());
|
||||
EXPECT_EQ(openspace::psc(), node->position());
|
||||
|
||||
delete node;
|
||||
ghoul::Dictionary nodeDictionary;
|
||||
@@ -83,10 +82,10 @@ TEST_F(SceneGraphTest, SceneGraphNode) {
|
||||
openspace::SceneGraphNode::createFromDictionary(nodeDictionary);
|
||||
|
||||
// This node should have a renderable (probably no good values but an existing one)
|
||||
EXPECT_TRUE(node->getRenderable());
|
||||
EXPECT_TRUE(node->renderable());
|
||||
|
||||
// position should be initialized
|
||||
EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->getPosition());
|
||||
EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->position());
|
||||
|
||||
delete node;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-2014 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 <ghoul/filesystem/filesystem.h>
|
||||
#include "gtest/gtest.h"
|
||||
#include "openspace/util/spicemanager.h"
|
||||
@@ -49,7 +49,6 @@ protected:
|
||||
const int nrMetaKernels = 9;
|
||||
int which, handle, count = 0;
|
||||
char file[FILLEN], filtyp[TYPLEN], source[SRCLEN];
|
||||
int found;
|
||||
double abs_error = 0.00001;
|
||||
|
||||
|
||||
@@ -77,9 +76,10 @@ std::string fileType(char type[]){
|
||||
TEST_F(SpiceManagerTest, loadSingleKernel){
|
||||
loadLSKKernel();
|
||||
//naif0008.tls is a text file, check if loaded.
|
||||
SpiceBoolean found;
|
||||
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
|
||||
ASSERT_TRUE(found) << "Kernel not loaded";
|
||||
ASSERT_TRUE(found == SPICETRUE) << "Kernel not loaded";
|
||||
unload_c(LSK.c_str());
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ TEST_F(SpiceManagerTest, loadMetaKernel){
|
||||
"TEXT", "CK", "TEXT" };
|
||||
// If one of the kernels does not load we expect a mismatch
|
||||
for (int i = 0; i < nrMetaKernels; i++){
|
||||
SpiceBoolean found;
|
||||
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
EXPECT_EQ(fileType(filtyp), typeArr[i]) << "One or more kernels did not load properly";
|
||||
}
|
||||
@@ -102,29 +103,33 @@ TEST_F(SpiceManagerTest, loadMetaKernel){
|
||||
TEST_F(SpiceManagerTest, unloadKernelString){
|
||||
loadLSKKernel();
|
||||
//naif0008.tls is a text file, check if loaded.
|
||||
SpiceBoolean found;
|
||||
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
ASSERT_TRUE(found);
|
||||
ASSERT_TRUE(found == SPICETRUE);
|
||||
|
||||
//unload using string keyword
|
||||
bool unloaded = openspace::SpiceManager::ref().unloadKernel("LEAPSECONDS");
|
||||
EXPECT_TRUE(unloaded);
|
||||
|
||||
found = SPICEFALSE;
|
||||
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
EXPECT_FALSE(found);
|
||||
EXPECT_FALSE(found == SPICETRUE);
|
||||
}
|
||||
// Try unloading kernel using integer as ID
|
||||
TEST_F(SpiceManagerTest, unloadKernelInteger){
|
||||
int kernelID = loadLSKKernel();
|
||||
//naif0008.tls is a text file, check if loaded.
|
||||
SpiceBoolean found;
|
||||
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
ASSERT_TRUE(found);
|
||||
ASSERT_TRUE(found == SPICETRUE);
|
||||
|
||||
//unload using unique int ID
|
||||
bool unloaded = openspace::SpiceManager::ref().unloadKernel(kernelID);
|
||||
EXPECT_TRUE(unloaded) << "Kernel did not unload";
|
||||
|
||||
found = SPICEFALSE;
|
||||
kdata_c(0, "text", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
EXPECT_FALSE(found) << "One or more kernels still present in kernel-pool";
|
||||
EXPECT_FALSE(found == SPICETRUE) << "One or more kernels still present in kernel-pool";
|
||||
}
|
||||
// Try unloading multiple kernels
|
||||
TEST_F(SpiceManagerTest, unloadMetaKernel){
|
||||
@@ -136,6 +141,7 @@ TEST_F(SpiceManagerTest, unloadMetaKernel){
|
||||
|
||||
for (int i = 0; i < nrMetaKernels; i++){
|
||||
// check kernelpool against typeArr
|
||||
SpiceBoolean found;
|
||||
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
EXPECT_EQ(fileType(filtyp), typeArr[i]) << "One or more kernels did not load properly";
|
||||
}
|
||||
@@ -144,8 +150,9 @@ TEST_F(SpiceManagerTest, unloadMetaKernel){
|
||||
|
||||
for (int i = 0; i < nrMetaKernels; i++){
|
||||
// the values should by now be unloaded
|
||||
SpiceBoolean found;
|
||||
kdata_c(i, "all", FILLEN, TYPLEN, SRCLEN, file, filtyp, source, &handle, &found);
|
||||
EXPECT_FALSE(found) << "Failed unloading kernel";
|
||||
EXPECT_FALSE(found == SPICETRUE) << "Failed unloading kernel";
|
||||
}
|
||||
unload_c(META.c_str());
|
||||
}
|
||||
@@ -153,13 +160,11 @@ TEST_F(SpiceManagerTest, unloadMetaKernel){
|
||||
TEST_F(SpiceManagerTest, hasValue){
|
||||
loadPCKKernel();
|
||||
|
||||
int n;
|
||||
int naifId = 399; //Earth
|
||||
double radii[3];
|
||||
|
||||
std::string kernelPoolValue = "RADII";
|
||||
|
||||
found = openspace::SpiceManager::ref().hasValue(naifId, kernelPoolValue);
|
||||
bool found = openspace::SpiceManager::ref().hasValue(naifId, kernelPoolValue);
|
||||
ASSERT_TRUE(found) << "Could not find value for specified kernel";
|
||||
unload_c(PCK.c_str());
|
||||
}
|
||||
@@ -171,7 +176,7 @@ TEST_F(SpiceManagerTest, getValueFromID_1D){
|
||||
std::string value1D = "MAG_NORTH_POLE_LAT";
|
||||
|
||||
double return1D;
|
||||
found = openspace::SpiceManager::ref().getValueFromID(target, value1D, return1D);
|
||||
bool found = openspace::SpiceManager::ref().getValueFromID(target, value1D, return1D);
|
||||
ASSERT_TRUE(found) << "Could not retrieve value";
|
||||
EXPECT_EQ(return1D, 78.565) << "Value not found / differs from expected return";
|
||||
unload_c(PCK.c_str());
|
||||
@@ -200,14 +205,14 @@ TEST_F(SpiceManagerTest, getValueFromID_ND){
|
||||
|
||||
std::vector<double> returnND;
|
||||
unsigned int nr = 5;
|
||||
found = openspace::SpiceManager::ref().getValueFromID(target, valueND, returnND, nr);
|
||||
bool found = openspace::SpiceManager::ref().getValueFromID(target, valueND, returnND, nr);
|
||||
ASSERT_TRUE(found) << "Could not retrieve value for specified kernel";
|
||||
|
||||
std::vector<double> controlVec{ 189870.0, 256900.0, 9000.0, 9000.0, 0.000003 };
|
||||
|
||||
ASSERT_EQ(controlVec.size(), returnND.size()) << "Vectors differ in size";
|
||||
|
||||
for (int i = 0; i < nr; i++){
|
||||
for (unsigned int i = 0; i < nr; ++i){
|
||||
EXPECT_EQ(controlVec[i], returnND[i]) << "Vector value not equal";
|
||||
}
|
||||
unload_c(PCK.c_str());
|
||||
@@ -218,10 +223,10 @@ TEST_F(SpiceManagerTest, stringToEphemerisTime){
|
||||
|
||||
double ephemerisTime;
|
||||
double control_ephemerisTime;
|
||||
char *date = "Thu Mar 20 12:53:29 PST 1997";
|
||||
char date[SRCLEN] = "Thu Mar 20 12:53:29 PST 1997";
|
||||
str2et_c(date, &control_ephemerisTime);
|
||||
|
||||
ephemerisTime = openspace::SpiceManager::ref().stringToEphemerisTime(date);
|
||||
ephemerisTime = openspace::SpiceManager::ref().convertStringToTdbSeconds(date);
|
||||
|
||||
EXPECT_EQ(ephemerisTime, control_ephemerisTime) << "Ephemeries times differ / not found";
|
||||
unload_c(LSK.c_str());
|
||||
@@ -240,7 +245,7 @@ TEST_F(SpiceManagerTest, getTargetPosition){
|
||||
|
||||
glm::dvec3 targetPosition;
|
||||
double lightTime = 0.0;
|
||||
found = openspace::SpiceManager::ref().getTargetPosition("EARTH", et, "J2000", "LT+S", "CASSINI",
|
||||
bool found = openspace::SpiceManager::ref().getTargetPosition("EARTH", et, "J2000", "LT+S", "CASSINI",
|
||||
targetPosition, lightTime);
|
||||
ASSERT_TRUE(found);
|
||||
EXPECT_DOUBLE_EQ(pos[0], targetPosition[0]) << "Position not found or differs from expected return";
|
||||
@@ -263,7 +268,7 @@ TEST_F(SpiceManagerTest, getTargetState){
|
||||
glm::dvec3 targetPosition;
|
||||
glm::dvec3 targetVelocity;
|
||||
double lightTime = 0.0;
|
||||
found = openspace::SpiceManager::ref().getTargetState("EARTH", et, "J2000", "LT+S", "CASSINI",
|
||||
bool found = openspace::SpiceManager::ref().getTargetState("EARTH", et, "J2000", "LT+S", "CASSINI",
|
||||
targetPosition, targetVelocity, lightTime);
|
||||
ASSERT_TRUE(found);
|
||||
//x,y,z
|
||||
@@ -291,7 +296,7 @@ TEST_F(SpiceManagerTest, getStateTransformMatrix){
|
||||
glm::dvec3 velocity(state[3], state[4], state[5]);
|
||||
|
||||
openspace::transformMatrix stateMatrix(6);
|
||||
found = openspace::SpiceManager::ref().getStateTransformMatrix("J2000",
|
||||
bool found = openspace::SpiceManager::ref().getStateTransformMatrix("J2000",
|
||||
"IAU_PHOEBE",
|
||||
et,
|
||||
stateMatrix);
|
||||
@@ -317,7 +322,6 @@ TEST_F(SpiceManagerTest, getPositionTransformMatrix){
|
||||
loadMetaKernel();
|
||||
|
||||
double et;
|
||||
double lt;
|
||||
double state[3] = { 1.0, 1.0, 1.0 };
|
||||
double state_t[3];
|
||||
double referenceMatrix[3][3];
|
||||
@@ -327,7 +331,7 @@ TEST_F(SpiceManagerTest, getPositionTransformMatrix){
|
||||
|
||||
openspace::transformMatrix positionMatrix(3);
|
||||
glm::dvec3 position(state[0], state[1], state[2]);
|
||||
found = openspace::SpiceManager::ref().getPositionTransformMatrix("CASSINI_HGA",
|
||||
bool found = openspace::SpiceManager::ref().getPositionTransformMatrix("CASSINI_HGA",
|
||||
"J2000",
|
||||
et,
|
||||
positionMatrix);
|
||||
@@ -355,17 +359,16 @@ TEST_F(SpiceManagerTest, getFieldOfView){
|
||||
int n;
|
||||
int cassini_ID;
|
||||
double et;
|
||||
double lt;
|
||||
double boresight[3];
|
||||
double bounds_ref[5][3];
|
||||
char shape_ref[TYPLEN];
|
||||
char name_ref[FILLEN];
|
||||
|
||||
str2et_c("2004 jun 11 19:32:00", &et);
|
||||
SpiceBoolean found;
|
||||
bodn2c_c("CASSINI_ISS_NAC", &cassini_ID, &found);
|
||||
if (!found){
|
||||
printf("error cannot locate ID for Cassini \n");
|
||||
}
|
||||
ASSERT_TRUE(found == SPICETRUE) << "Cannot locate ID for Cassini";
|
||||
|
||||
getfov_c(cassini_ID, 5, TYPLEN, TYPLEN, shape_ref, name_ref, boresight, &n, bounds_ref);
|
||||
|
||||
std::string shape, name;
|
||||
@@ -379,7 +382,7 @@ TEST_F(SpiceManagerTest, getFieldOfView){
|
||||
boresight,
|
||||
bounds,
|
||||
nrReturned);
|
||||
ASSERT_TRUE(found);
|
||||
ASSERT_TRUE(found == SPICETRUE);
|
||||
//check vectors have correct values
|
||||
for (int i = 0; i < nrReturned; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
@@ -399,14 +402,17 @@ TEST_F(SpiceManagerTest, rectangularToLatitudal){
|
||||
obspos[3], point_ref[3];
|
||||
double dist, et, radius_ref, trgepc;
|
||||
int n, naifId;
|
||||
int found;
|
||||
bool found;
|
||||
SpiceBoolean foundSpice;
|
||||
|
||||
// First, find an intersection point to convert to rectangular coordinates
|
||||
str2et_c("2004 jun 11 19:32:00", &et);
|
||||
bodn2c_c("CASSINI_ISS_NAC", &naifId, &found);
|
||||
bodn2c_c("CASSINI_ISS_NAC", &naifId, &foundSpice);
|
||||
ASSERT_TRUE(foundSpice == SPICETRUE);
|
||||
getfov_c(naifId, 4, FILLEN, FILLEN, shape, frame, bsight, &n, bounds);
|
||||
srfxpt_c("Ellipsoid", "PHOEBE", et, "LT+S", "CASSINI", frame, bsight,
|
||||
point_ref, &dist, &trgepc, obspos, &found);
|
||||
point_ref, &dist, &trgepc, obspos, &foundSpice);
|
||||
ASSERT_TRUE(foundSpice == SPICETRUE);
|
||||
|
||||
reclat_c(point_ref, &radius_ref, &lon, &lat);
|
||||
glm::dvec3 point(point_ref[0], point_ref[1], point_ref[2]);
|
||||
@@ -429,13 +435,17 @@ TEST_F(SpiceManagerTest, latitudinalToRectangular){
|
||||
obspos[3], point_ref[3];
|
||||
double dist, et, radius_ref, trgepc;
|
||||
int n, naifId;
|
||||
SpiceBoolean foundSpice;
|
||||
|
||||
// First, find an intersection point to convert to latitudinal coordinates //
|
||||
str2et_c("2004 jun 11 19:32:00", &et);
|
||||
bodn2c_c("CASSINI_ISS_NAC", &naifId, &found);
|
||||
bodn2c_c("CASSINI_ISS_NAC", &naifId, &foundSpice);
|
||||
ASSERT_TRUE(foundSpice == SPICETRUE);
|
||||
getfov_c(naifId, 4, FILLEN, FILLEN, shape, frame, bsight, &n, bounds);
|
||||
foundSpice = SPICEFALSE;
|
||||
srfxpt_c("Ellipsoid", "PHOEBE", et, "LT+S", "CASSINI", frame, bsight,
|
||||
point_ref, &dist, &trgepc, obspos, &found);
|
||||
point_ref, &dist, &trgepc, obspos, &foundSpice);
|
||||
ASSERT_TRUE(foundSpice == SPICETRUE);
|
||||
|
||||
reclat_c(point_ref, &radius_ref, &lon, &lat);
|
||||
|
||||
@@ -449,7 +459,7 @@ TEST_F(SpiceManagerTest, latitudinalToRectangular){
|
||||
latrec_c(radius_ref, lon, lat, rectangular_ref);
|
||||
|
||||
glm::dvec3 coordinates;
|
||||
found = openspace::SpiceManager::ref().latidudinalToRectangular(radius_ref, lon, lat, coordinates);
|
||||
bool found = openspace::SpiceManager::ref().latidudinalToRectangular(radius_ref, lon, lat, coordinates);
|
||||
|
||||
ASSERT_TRUE(found);
|
||||
ASSERT_NEAR(lon_ref, lon, abs_error) << "longitude is not set / has incorrect values";
|
||||
@@ -463,14 +473,16 @@ TEST_F(SpiceManagerTest, planetocentricToRectangular){
|
||||
double lat = -35.0; //initial values
|
||||
double lon = 100.0;
|
||||
double rectangular_ref[3];
|
||||
double radius;
|
||||
int naifId;
|
||||
SpiceBoolean foundSpice;
|
||||
|
||||
bodn2c_c("EARTH", &naifId, &found);
|
||||
bodn2c_c("EARTH", &naifId, &foundSpice);
|
||||
ASSERT_TRUE(foundSpice == SPICETRUE);
|
||||
srfrec_c(naifId, lon*rpd_c(), lat*rpd_c(), rectangular_ref);
|
||||
|
||||
glm::dvec3 rectangular;
|
||||
found = openspace::SpiceManager::ref().planetocentricToRectangular("EARTH", lon, lat, rectangular);
|
||||
bool found = openspace::SpiceManager::ref().planetocentricToRectangular("EARTH", lon, lat, rectangular);
|
||||
ASSERT_TRUE(found);
|
||||
|
||||
for (int i = 0; i < 3; i++){
|
||||
EXPECT_EQ(rectangular[i], rectangular_ref[i]) << "Rectangular coordinates differ from expected output";
|
||||
@@ -481,8 +493,11 @@ TEST_F(SpiceManagerTest, planetocentricToRectangular){
|
||||
TEST_F(SpiceManagerTest, getSubObserverPoint){
|
||||
loadMetaKernel();
|
||||
|
||||
double et, targetEt_ref, targetEt;
|
||||
double radii[3], subObserverPoint_ref[3], vectorToSurfacePoint_ref[3];
|
||||
double et;
|
||||
double targetEt_ref;
|
||||
double targetEt;
|
||||
double subObserverPoint_ref[3];
|
||||
double vectorToSurfacePoint_ref[3];
|
||||
static SpiceChar * method[2] = { "Intercept: ellipsoid", "Near point: ellipsoid" };
|
||||
|
||||
str2et_c("2004 jun 11 19:32:00", &et);
|
||||
@@ -494,7 +509,7 @@ TEST_F(SpiceManagerTest, getSubObserverPoint){
|
||||
subpnt_c(method[i], "phoebe", et, "iau_phoebe",
|
||||
"lt+s", "earth", subObserverPoint_ref, &targetEt_ref, vectorToSurfacePoint_ref);
|
||||
|
||||
found = openspace::SpiceManager::ref().getSubObserverPoint(method[i], "phoebe", et, "iau_phoebe",
|
||||
bool found = openspace::SpiceManager::ref().getSubObserverPoint(method[i], "phoebe", et, "iau_phoebe",
|
||||
"lt+s", "earth", subObserverPoint,
|
||||
targetEt, vectorToSurfacePoint);
|
||||
ASSERT_TRUE(found);
|
||||
@@ -513,7 +528,8 @@ TEST_F(SpiceManagerTest, getSubSolarPoint){
|
||||
loadMetaKernel();
|
||||
|
||||
double et, targetEt_ref, targetEt;
|
||||
double radii[3], subSolarPoint_ref[3], vectorToSurfacePoint_ref[3];
|
||||
double subSolarPoint_ref[3];
|
||||
double vectorToSurfacePoint_ref[3];
|
||||
static SpiceChar * method[2] = { "Intercept: ellipsoid", "Near point: ellipsoid" };
|
||||
|
||||
str2et_c("2004 jun 11 19:32:00", &et);
|
||||
@@ -525,7 +541,7 @@ TEST_F(SpiceManagerTest, getSubSolarPoint){
|
||||
subslr_c(method[i], "phoebe", et, "iau_phoebe",
|
||||
"lt+s", "earth", subSolarPoint_ref, &targetEt_ref, vectorToSurfacePoint_ref);
|
||||
|
||||
found = openspace::SpiceManager::ref().getSubSolarPoint(method[i], "phoebe", et, "iau_phoebe",
|
||||
bool found = openspace::SpiceManager::ref().getSubSolarPoint(method[i], "phoebe", et, "iau_phoebe",
|
||||
"lt+s", "earth", subSolarPoint,
|
||||
targetEt, vectorToSurfacePoint);
|
||||
ASSERT_TRUE(found);
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace openspaceengine {
|
||||
const std::string keyPathScene = "Paths.SCENEPATH";
|
||||
const std::string keyConfigSgct = "SGCTConfig";
|
||||
const std::string keyConfigScene = "Scene";
|
||||
const std::string keyStartupScript = "StartupScripts";
|
||||
const std::string keyConfigTimekernel = "SpiceTimeKernel";
|
||||
} // namespace openspaceengine
|
||||
|
||||
namespace scenegraph {
|
||||
@@ -64,16 +66,33 @@ namespace renderablestars {
|
||||
const std::string keyPathModule = "ModulePath";
|
||||
} // namespace renderablestars
|
||||
|
||||
namespace renderablevolumegl {
|
||||
const std::string keyVolume = "Volume";
|
||||
const std::string keyHints = "Hints";
|
||||
const std::string keyTransferFunction = "TransferFunction";
|
||||
const std::string keySampler = "Sampler";
|
||||
const std::string keyBoxScaling = "BoxScaling";
|
||||
const std::string keyVolumeName = "VolumeName";
|
||||
const std::string keyTransferFunctionName = "TransferFunctionName";
|
||||
} // namespace renderablevolumegl
|
||||
|
||||
namespace planetgeometry {
|
||||
const std::string keyType = "Type";
|
||||
} // namespace planetgeometry
|
||||
|
||||
|
||||
|
||||
namespace ephemeris {
|
||||
const std::string keyType = "Type";
|
||||
} // namespace ephemeris
|
||||
|
||||
namespace staticephemeris {
|
||||
const std::string keyPosition = "Position";
|
||||
} // namespace staticephemeris
|
||||
|
||||
namespace spiceephemeris {
|
||||
const std::string keyBody = "Body";
|
||||
const std::string keyOrigin = "Observer";
|
||||
} // namespace spiceephemeris
|
||||
|
||||
} // namespace constants
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef KAMELEONWRAPPER_H_
|
||||
#define KAMELEONWRAPPER_H_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/std_based_type.hpp>
|
||||
|
||||
namespace ccmc {
|
||||
@@ -35,6 +34,16 @@ namespace ccmc {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct LinePoint {
|
||||
glm::vec3 position;
|
||||
glm::vec4 color;
|
||||
|
||||
LinePoint(glm::vec3 pos, glm::vec4 col) {
|
||||
position = pos;
|
||||
color = col;
|
||||
}
|
||||
};
|
||||
|
||||
class KameleonWrapper {
|
||||
public:
|
||||
|
||||
@@ -43,14 +52,58 @@ public:
|
||||
BATSRUS // Magnetosphere
|
||||
};
|
||||
|
||||
enum class TraceDirection {
|
||||
FORWARD = 1,
|
||||
BACK = -1
|
||||
};
|
||||
|
||||
enum class FieldlineEnd {
|
||||
NORTH,
|
||||
SOUTH,
|
||||
OUT
|
||||
};
|
||||
|
||||
KameleonWrapper(const std::string& filename, Model model);
|
||||
~KameleonWrapper();
|
||||
float* getUniformSampledValues(const std::string& var, glm::size3_t outDimensions);
|
||||
float* getUniformSampledVectorValues(const std::string& xVar, const std::string& yVar,
|
||||
const std::string& zVar, glm::size3_t outDimensions);
|
||||
|
||||
std::vector<std::vector<LinePoint> > getClassifiedFieldLines(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
std::vector<glm::vec3> seedPoints, float stepSize);
|
||||
|
||||
std::vector<std::vector<LinePoint> > getFieldLines(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar,
|
||||
std::vector<glm::vec3> seedPoints, float stepSize, glm::vec4 color);
|
||||
|
||||
std::vector<std::vector<LinePoint> > getLorentzTrajectories(std::vector<glm::vec3> seedPoints,
|
||||
glm::vec4 color, float stepsize);
|
||||
|
||||
glm::vec3 getModelBarycenterOffset();
|
||||
|
||||
private:
|
||||
std::vector<glm::vec3> traceCartesianFieldline(const std::string& xVar,
|
||||
const std::string& yVar, const std::string& zVar, glm::vec3 seedPoint,
|
||||
float stepSize, TraceDirection direction, FieldlineEnd& end);
|
||||
|
||||
std::vector<glm::vec3> traceLorentzTrajectory(glm::vec3 seedPoint,
|
||||
float stepsize, float eCharge);
|
||||
|
||||
void getGridVariables(std::string& x, std::string& y, std::string& z);
|
||||
void progressBar(int current, int end);
|
||||
glm::vec4 classifyFieldline(FieldlineEnd fEnd, FieldlineEnd bEnd);
|
||||
|
||||
ccmc::Model* _model;
|
||||
Model _type;
|
||||
ccmc::Interpolator* _interpolator;
|
||||
|
||||
// Model parameters
|
||||
float _xMin, _xMax, _yMin, _yMax, _zMin, _zMax;
|
||||
std::string _xCoordVar, _yCoordVar, _zCoordVar;
|
||||
|
||||
// For progressbar
|
||||
int _lastiProgress;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __SHADERCREATOR_H__
|
||||
#define __SHADERCREATOR_H__
|
||||
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
class ShaderCreator {
|
||||
|
||||
public:
|
||||
ShaderCreator();
|
||||
~ShaderCreator();
|
||||
|
||||
void createSourceFile(bool b);
|
||||
void sourceFileExtension(const std::string& extension);
|
||||
void sourceFileHeader(const std::string& header);
|
||||
|
||||
ghoul::opengl::ProgramObject* buildShader(const std::string& name, const std::string& vpath, const std::string& fpath, const std::string& gpath = "");
|
||||
|
||||
private:
|
||||
|
||||
void _generateSource(const std::string& filename);
|
||||
std::string _loadSource(const std::string& filename, unsigned int depth = 0);
|
||||
std::string _generateFilename(const std::string& filename);
|
||||
|
||||
bool _createSourceFile;
|
||||
std::string _sourceFileExtension;
|
||||
std::string _sourceFileHeader;
|
||||
unsigned int _maxDepth;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -92,19 +92,19 @@ public:
|
||||
* \param kernelPoolValueName Item for which values are desired. ("RADII", "NUT_PREC_ANGLES", etc. )
|
||||
* \return Whether the function succeeded or not
|
||||
*/
|
||||
bool SpiceManager::getValueFromID(const std::string& bodyname,
|
||||
bool getValueFromID(const std::string& bodyname,
|
||||
const std::string& kernelPoolValueName,
|
||||
double& value) const;
|
||||
/* Overloaded method for 3dim vectors, see above specification.*/
|
||||
bool SpiceManager::getValueFromID(const std::string& bodyname,
|
||||
bool getValueFromID(const std::string& bodyname,
|
||||
const std::string& kernelPoolValueName,
|
||||
glm::dvec3& value) const;
|
||||
/* Overloaded method for 4dim vectors, see above specification.*/
|
||||
bool SpiceManager::getValueFromID(const std::string& bodyname,
|
||||
bool getValueFromID(const std::string& bodyname,
|
||||
const std::string& kernelPoolValueName,
|
||||
glm::dvec4& value) const;
|
||||
/* Overloaded method for Ndim vectors, see above specification.*/
|
||||
bool SpiceManager::getValueFromID(const std::string& bodyname,
|
||||
bool getValueFromID(const std::string& bodyname,
|
||||
const std::string& kernelPoolValueName,
|
||||
std::vector<double>& values, unsigned int num) const;
|
||||
|
||||
@@ -119,7 +119,19 @@ public:
|
||||
* \param epochString, A string representing an epoch.
|
||||
* \return Corresponding ephemeris time, equivalent value in seconds past J2000, TDB.
|
||||
*/
|
||||
double stringToEphemerisTime(const std::string& epochString) const;
|
||||
double convertStringToTdbSeconds(const std::string& epochString) const;
|
||||
|
||||
/**
|
||||
* Convert the number of TDB seconds past the J2000 epoch into a human readable
|
||||
* string representation. Fur further details, please refer to 'timout_c' in SPICE
|
||||
* Documentation
|
||||
*
|
||||
* \param seconds The number of seconds that have passed since the J2000 epoch
|
||||
* \param format The output format of the string
|
||||
* (see ftp://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/timout_c.html)
|
||||
* \return The formatted date string
|
||||
*/
|
||||
std::string convertTdbSecondsToString(double seconds, const std::string& format) const;
|
||||
|
||||
// Computing Positions of Spacecraft and Natural Bodies(SPK) ---------------------------- //
|
||||
|
||||
@@ -337,7 +349,7 @@ private:
|
||||
struct spiceKernel {
|
||||
std::string path;
|
||||
std::string name;
|
||||
int id;
|
||||
unsigned int id;
|
||||
};
|
||||
std::vector<spiceKernel> _loadedKernels;
|
||||
unsigned int _kernelCount = 0;
|
||||
@@ -382,6 +394,21 @@ public:
|
||||
data = new double[N*N];
|
||||
empty = true;
|
||||
}
|
||||
|
||||
void transform(glm::dvec3& position) {
|
||||
assert(!empty); // transformation matrix is empty
|
||||
|
||||
double *state;
|
||||
double *state_t;
|
||||
state = new double[N];
|
||||
state_t = new double[N];
|
||||
|
||||
COPY(state, &position);
|
||||
mxvg_c(data, state, N, N, state_t);
|
||||
|
||||
COPY(&position, state_t);
|
||||
}
|
||||
|
||||
/** As the spice function mxvg_c requires a 6dim vector
|
||||
* the two 3dim state vectors are packed into 'state'.
|
||||
* Transformed values are then copied back from state_t
|
||||
@@ -394,8 +421,8 @@ public:
|
||||
* the method ignores its second argument.
|
||||
*/
|
||||
void transform(glm::dvec3& position,
|
||||
glm::dvec3& velocity = glm::dvec3()){
|
||||
assert(("transformation matrix is empty", !empty));
|
||||
glm::dvec3& velocity) {
|
||||
assert(!empty); // transformation matrix is empty
|
||||
|
||||
double *state;
|
||||
double *state_t;
|
||||
@@ -414,7 +441,7 @@ public:
|
||||
* asserts matrix has been filled
|
||||
*/
|
||||
inline double operator()(int i, int j) const{
|
||||
assert(("transformation matrix is empty", !empty));
|
||||
assert(!empty); // transformation matrix is empty
|
||||
return data[j + i*N];
|
||||
}
|
||||
};
|
||||
|
||||
+153
-17
@@ -1,31 +1,167 @@
|
||||
#ifndef ENGINETIME_H
|
||||
#define ENGINETIME_H
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
#ifndef __TIME_H__
|
||||
#define __TIME_H__
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/**
|
||||
* This singleton class represents the current simulation time in OpenSpace. It
|
||||
* internally stores the time and provides methods to set the time directly
|
||||
* (setTime(double), setTime(std::string)) using a <code>double</code> value using the
|
||||
* number of seconds passed since the J2000 epoch or a <code>string</code> that denotes
|
||||
* a valid date string in accordance to the Spice library
|
||||
* (http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html). The time can
|
||||
* be retrieved as the number of seconds since the J2000 epoch with currentTime() or as a
|
||||
* UTC string following ISO 8601 with the method currentTimeUTC().
|
||||
*
|
||||
* In addition to the time itself, it also stores a delta time value. This value denotes
|
||||
* the number of seconds that pass for each real-time second. This value is set with
|
||||
* setDeltaTime(double), retrieved with deltaTime() and solely used in the
|
||||
* advanceTime(double), which takes a <code>tickTime</code> parameter. The value of the
|
||||
* parameter is dependent on the usage of the class and must be equal to the real-world
|
||||
* time that has passed since the last call to the method. For example, if the
|
||||
* advanceTime(double) method is called each frame, the <code>tickTime</code> has to be
|
||||
* equal to the frame time.
|
||||
*/
|
||||
class Time {
|
||||
public:
|
||||
virtual ~Time();
|
||||
/**
|
||||
* Initializes the Time singleton and loads an LSK spice kernel with the provided
|
||||
* name.
|
||||
* \param lskKernel The name of the kernel that should be loaded during the
|
||||
* initialization. If the parameter is empty, no kernel will be loaded
|
||||
* \return <code>true</code> if the initialization succeeded, <code>false</code>
|
||||
* otherwise
|
||||
*/
|
||||
static bool initialize(const std::string& lskKernel = "");
|
||||
|
||||
static void init();
|
||||
static void deinit();
|
||||
/**
|
||||
* Deinitializes the Time singleton. This method will not unload the kernel that was
|
||||
* possibly loaded during the initialize method.
|
||||
*/
|
||||
static void deinitialize();
|
||||
|
||||
/**
|
||||
* Returns the reference to the Time singleton object.
|
||||
* \return The reference to the Time singleton object
|
||||
*/
|
||||
static Time& ref();
|
||||
static bool isInitialized();
|
||||
|
||||
void setTime(const char* stringTime);
|
||||
double getTime();
|
||||
/**
|
||||
* Returns <code>true</code> if the singleton has been successfully initialized,
|
||||
* <code>false</code> otherwise
|
||||
* \return <code>true</code> if the singleton has been successfully initialized,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
static bool isInitialized();
|
||||
|
||||
/**
|
||||
* Sets the current time to the specified value in seconds past the J2000 epoch. This
|
||||
* value can be negative to represent dates before the epoch.
|
||||
* \param The number of seconds after the J2000 epoch
|
||||
*/
|
||||
void setTime(double value);
|
||||
|
||||
/**
|
||||
* Sets the current time to the specified value given as a Spice compliant string as
|
||||
* described in the Spice documentation
|
||||
* (http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html)
|
||||
* \param time The time to be set as a date string
|
||||
*/
|
||||
void setTime(std::string time);
|
||||
|
||||
/**
|
||||
* Returns the current time as the number of seconds past the J2000 epoch. If the
|
||||
* current time is a date before that epoch, the returned value will be negative.
|
||||
* \return The current time as the number of seconds past the J2000 epoch
|
||||
*/
|
||||
double currentTime() const;
|
||||
|
||||
/**
|
||||
* Returns the current time as a formatted date string compliant with ISO 8601 and
|
||||
* thus also compliant with the Spice library.
|
||||
* \return The current time as a formatted date string
|
||||
*/
|
||||
std::string currentTimeUTC() const;
|
||||
|
||||
/**
|
||||
* Sets the delta time value that is the number of seconds that should pass for each
|
||||
* real-time second. This value is used in the advanceTime(double) method to easily
|
||||
* advance the simulation time.
|
||||
* \param deltaT The number of seconds that should pass for each real-time second
|
||||
*/
|
||||
void setDeltaTime(double deltaT);
|
||||
|
||||
/**
|
||||
* Returns the delta time, that is the number of seconds that pass in the simulation
|
||||
* for each real-time second
|
||||
* \return The number of seconds that pass for each real-time second
|
||||
*/
|
||||
double deltaTime() const;
|
||||
|
||||
/**
|
||||
* Advances the simulation time using the deltaTime() and the <code>tickTime</code>.
|
||||
* The deltaTime() is the number of simulation seconds that pass for each real-time
|
||||
* second. <code>tickTime</code> is the number of real-time seconds that passed since
|
||||
* the last call to this method. If this method is called in the render loop, the
|
||||
* <code>tickTime</code> should be equivalent to the frame time.
|
||||
* \param tickTime The number of real-time seconds that passed since the last call
|
||||
* to this method
|
||||
* \return The new time value after advancing the time
|
||||
*/
|
||||
double advanceTime(double tickTime);
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to change the
|
||||
* current time, retrieve the current time etc. The functions contained are
|
||||
* - openspace::luascriptfunctions::time_setDeltaTime
|
||||
* - openspace::luascriptfunctions::time_deltaTime
|
||||
* - openspace::luascriptfunctions::time_setTime
|
||||
* - openspace::luascriptfunctions::time_currentTime
|
||||
* - openspace::luascriptfunctions::time_currentTimeUTC
|
||||
* \return The Lua library that contains all Lua functions available to change the
|
||||
* Time singleton
|
||||
*/
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
static Time* this_;
|
||||
Time(void);
|
||||
Time(const Time& src);
|
||||
Time& operator=(const Time& rhs);
|
||||
/// Creates the time object. Only used in the initialize() method
|
||||
Time();
|
||||
Time(const Time& src) = delete;
|
||||
Time& operator=(const Time& rhs) = delete;
|
||||
|
||||
double time_;
|
||||
static Time* _instance; ///< The singleton instance
|
||||
double _time; ///< The time stored as the number of seconds past the J2000 epoch
|
||||
|
||||
double _deltaTimePerSecond; ///< The delta time that is used to advance the time
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif // __TIME_H__
|
||||
|
||||
Reference in New Issue
Block a user