Added missing include and merged master into NewAtmosphere.

This commit is contained in:
Jonathas Costa
2017-11-25 22:39:18 -05:00
142 changed files with 5565 additions and 4414 deletions

4
.gitignore vendored
View File

@@ -87,6 +87,9 @@ data/scene/missions/rosetta/67P/rosettaimages
data/scene/missions/rosetta/67P/textures
data/scene/missions/rosetta/rosetta/rosetta
data/scene/missions/rosetta/rosetta/textures
data/scene/missions/voyager/**/*.png
data/scene/missions/voyager/**/*.jpg
data/scene/missions/voyager/**/*.obj
data/scene/moon/textures
data/scene/neptune/textures
data/scene/pluto/textures
@@ -117,6 +120,7 @@ data/spice/nh_kernels
data/spice/OsirisRexKernels
data/spice/plu055.bsp
data/spice/Rosetta
data/spice/voyager
data/spice/sat375.bsp
data/spice/new_horizons/
data/scene/mars/map_datasets/mars_COL_v006_mars2000_rgb.tif

View File

@@ -0,0 +1,20 @@
<GDAL_WMS>
<Service name="TMS">
<ServerUrl>http://openspace.sci.utah.edu/Mars/MolaHRSC/tile/${z}/${y}/${x}</ServerUrl>
</Service>
<DataWindow>
<UpperLeftX>-180.0</UpperLeftX>
<UpperLeftY>90.0</UpperLeftY>
<LowerRightX>180.0</LowerRightX>
<LowerRightY>-90.0</LowerRightY>
<SizeX>106694</SizeX>
<SizeY>53347</SizeY>
<TileLevel>7</TileLevel>
<YOrigin>top</YOrigin> <!-- fail: bottom -->
</DataWindow>
<!-- <Projection>GEOGCS["GCS_Mars_2000_Sphere",DATUM["D_Mars_2000_Sphere",SPHEROID["Mars_2000_Sphere_IAU_IAG",3396190.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]]</Projection> -->
<BlockSizeX>512</BlockSizeX>
<BlockSizeY>512</BlockSizeY>
<BandsCount>3</BandsCount>
<MaxConnections>10</MaxConnections>
</GDAL_WMS>

View File

@@ -51,6 +51,10 @@ return {
Name = "MOLA Pseudo Color",
FilePath = "map_service_configs/Utah/Mola_PseudoColor.xml"
},
{
Name = "MOLA HRSC",
FilePath = "map_service_configs/Utah/Mola_HRSC.xml"
},
{
Name = "Viking MDIM [Utah]",
FilePath = "map_service_configs/Utah/Mdim.xml"

View File

@@ -0,0 +1,6 @@
return {
FileRequest = {
{ Identifier = "voyager1_model", Destination = ".", Version = 1 },
{ Identifier = "voyager1_spice", Destination = "${SPICE}/voyager", Version = 1 }
}
}

View File

@@ -0,0 +1,163 @@
local Kernels = {
'${SPICE}/voyager/vg1_v02.tf',
'${SPICE}/voyager/vg100019.tsc',
'${SPICE}/voyager/Voyager_1.a54206u_V0.2_merged.bsp',
'${SPICE}/voyager/voyager_1.ST+1991_a54418u.merged.bsp',
'${SPICE}/voyager/vgr1_jup230.bsp',
'${SPICE}/voyager/vgr1_sat337.bsp',
'${SPICE}/voyager/vgr1_super.bc',
'${SPICE}/voyager/vgr1_super_v2.bc'
}
local RotationMatrix = {
-1, 0, 0,
0, 0, -1,
0, -1, 0
}
return {
{
Name = "Voyager 1",
Parent = "SolarSystemBarycenter",
Transform = {
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 1",
Observer = "SUN",
Kernels = Kernels
},
Rotation = {
Type = "SpiceRotation",
SourceFrame = "VG1_SC_BUS",
DestinationFrame = "GALACTIC"
}
},
GuiPath = "/Solar System/Missions/Voyager 1"
},
{
Name = "Voyager 1 Main",
Parent = "Voyager 1",
Renderable = {
Type = "RenderableModel",
Geometry = {
Type = "MultiModelGeometry",
GeometryFile = "voyager-main.obj"
},
ColorTexture = "voyager-main.jpg",
ModelTransform = RotationMatrix
},
GuiPath = "/Solar System/Missions/Voyager 1"
},
{
Name = "Voyager 1 Antanna",
Parent = "Voyager 1",
Renderable = {
Type = "RenderableModel",
Geometry = {
Type = "MultiModelGeometry",
GeometryFile = "voyager-antenna.obj"
},
ColorTexture = "voyager-antenna.png",
ModelTransform = RotationMatrix
},
GuiPath = "/Solar System/Missions/Voyager 1"
},
-- The trails are organized as follows. The cruise phases can be resolved in relatively
-- low resolution since they are just straight lines
-- The encounter phases should be much higher resolution or otherwise artifacts would appear
{
Name = "Voyager 1 Trail Cruise Earth-Jupiter",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 1",
Observer = "SUN",
Kernels = Kernels
},
Color = { 0.70,0.50,0.20 },
StartTime = "1977 SEP 05",
EndTime = "1979 MAR 04",
SampleInterval = 545 * 2 -- 545 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 1"
},
{
Name = "Voyager 1 Trail Encounter Jupiter",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 1",
Observer = "SUN",
Kernels = Kernels
},
Color = { 0.70,0.50,0.20 },
EnableFade = false,
StartTime = "1979 MAR 03 23:24:00", -- @TODO: Probably an off-by-one bug in RenderableTrailTrajectory?
EndTime = "1979 MAR 09",
SampleInterval = 100
},
GuiName = "/Solar System/Missions/Voyager 1"
},
{
Name = "Voyager 1 Trail Cruise Jupiter-Saturn",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 1",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1979 MAR 09",
EndTime = "1980 NOV 11",
SampleInterval = 618 * 2 -- 618 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 1"
},
{
Name = "Voyager 1 Trail Encounter Saturn",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 1",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1980 NOV 10 23:08:30", -- @TODO: Probably an off-by-one bug in RenderableTrailTrajectory?
EndTime = "1980 NOV 16",
SampleInterval = 100
},
GuiName = "/Solar System/Missions/Voyager 1"
},
{
Name = "Voyager 1 Trail Cruise Saturn-Inf",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 1",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1980 NOV 16",
EndTime = "2021 JAN 01",
SampleInterval = 14656 * 2 -- 14656 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 1"
}
}

View File

@@ -0,0 +1,6 @@
return {
FileRequest = {
{ Identifier = "voyager2_model", Destination = ".", Version = 1 },
{ Identifier = "voyager2_spice", Destination = "${SPICE}/voyager", Version = 1 }
}
}

View File

@@ -0,0 +1,241 @@
local Kernels = {
'${SPICE}/voyager/vg2_v02.tf',
'${SPICE}/voyager/vg200022.tsc',
'${SPICE}/voyager/Voyager_2.m05016u.merged.bsp',
'${SPICE}/voyager/voyager_2.ST+1992_m05208u.merged.bsp',
'${SPICE}/voyager/vgr2_jup230.bsp',
'${SPICE}/voyager/vgr2_sat337.bsp',
'${SPICE}/voyager/vgr2_ura083.bsp',
'${SPICE}/voyager/vgr2_nep081.bsp',
'${SPICE}/voyager/vgr2_super.bc',
'${SPICE}/voyager/vgr2_super_v2.bc'
}
local RotationMatrix = {
-1, 0, 0,
0, 0, -1,
0, -1, 0
}
return {
{
Name = "Voyager 2",
Parent = "SolarSystemBarycenter",
Transform = {
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
Rotation = {
Type = "SpiceRotation",
SourceFrame = "VG2_SC_BUS",
DestinationFrame = "GALACTIC"
}
},
GuiPath = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Main",
Parent = "Voyager 2",
Renderable = {
Type = "RenderableModel",
Geometry = {
Type = "MultiModelGeometry",
GeometryFile = "voyager-main.obj"
},
ColorTexture = "voyager-main.jpg",
ModelTransform = RotationMatrix
},
GuiPath = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Antanna",
Parent = "Voyager 2",
Renderable = {
Type = "RenderableModel",
Geometry = {
Type = "MultiModelGeometry",
GeometryFile = "voyager-antenna.obj"
},
ColorTexture = "voyager-antenna.png",
ModelTransform = RotationMatrix
},
GuiPath = "/Solar System/Missions/Voyager 2"
},
-- The trails are organized as follows. The cruise phases can be resolved in relatively
-- low resolution since they are just straight lines
-- The encounter phases should be much higher resolution or otherwise artifacts would appear
{
Name = "Voyager 2 Trail Cruise Earth-Jupiter",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
Color = { 0.70,0.50,0.20 },
StartTime = "1977 SEP 05",
EndTime = "1979 JUL 06",
SampleInterval = 669 * 2 -- 669 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Encounter Jupiter",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
Color = { 0.70,0.50,0.20 },
EnableFade = false,
StartTime = "1979 JUL 05 23:24:00", -- @TODO: Probably an off-by-one bug in RenderableTrailTrajectory?
EndTime = "1979 JUL 15",
SampleInterval = 100
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Cruise Jupiter-Saturn",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1979 JUL 15",
EndTime = "1981 AUG 23",
SampleInterval = 770 * 2 -- 770 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Encounter Saturn",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1981 AUG 22 23:08:30", -- @TODO: Probably an off-by-one bug in RenderableTrailTrajectory?
EndTime = "1981 AUG 30",
SampleInterval = 100
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Cruise Saturn-Uranus",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1981 AUG 30",
EndTime = "1986 JAN 22",
SampleInterval = 1971 * 2 -- 1971 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Encounter Uranus",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1986 JAN 21 23:30:00", -- @TODO: Probably an off-by-one bug in RenderableTrailTrajectory?
EndTime = "1986 JAN 27",
SampleInterval = 100
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Cruise Uranus-Neptune",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1986 JAN 27",
EndTime = "1989 AUG 24",
SampleInterval = 1305 * 2 -- 1305 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Encounter Neptune",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1989 AUG 23 23:30:00", -- @TODO: Probably an off-by-one bug in RenderableTrailTrajectory?
EndTime = "1989 AUG 26",
SampleInterval = 100
},
GuiName = "/Solar System/Missions/Voyager 2"
},
{
Name = "Voyager 2 Trail Cruise Neptune-Inf",
Parent = "SolarSystemBarycenter",
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = "SpiceTranslation",
Target = "VOYAGER 2",
Observer = "SUN",
Kernels = Kernels
},
EnableFade = false,
Color = { 0.70,0.50,0.20 },
StartTime = "1989 AUG 26",
EndTime = "2021 JAN 01",
SampleInterval = 11451 * 2 -- 11451 is the number of days between the Start and End time
},
GuiName = "/Solar System/Missions/Voyager 2"
},
}

View File

@@ -54,7 +54,18 @@ return {
Observer = "SUN"
},
Color = {0.2, 0.5, 1.0 },
Period = 60200,
-- Period = 60200,
-- Yes, this period is wrong, but the SPICE kernel we load by default only
-- goes back to 1850. Neptunes orbit is 164 years, which would mean that we
-- exceed the SPICE kernel if we go back before 2014, if we try to compute the
-- entire orbit. Cutting the orbit length to 100 years allows us to go back
-- to 1950 instead, which is good enough.
-- If the positions are needed before that, a different set of kernels are
-- needed, namely:
-- https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de431_part-1.bsp
-- https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de431_part-2.bsp
-- that cover a larger time span: -13201-MAY-06 00:00 to 17191-MAR-15 00:00
Period = 36500,
Resolution = 1000
},
Tag = { "planetTrail_solarSystem", "planetTrail_giants" },

67
data/scene/voyager.scene Normal file
View File

@@ -0,0 +1,67 @@
dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua'))
function preInitialization()
--[[
The scripts in this function are executed after the scene is loaded but before the
scene elements have been initialized, thus they should be used to set the time at
which the scene should start and other settings that might determine initialization
critical objects.
]]--
openspace.spice.loadKernel("${SPICE}/naif0012.tls")
openspace.spice.loadKernel("${SPICE}/pck00010.tpc")
-- openspace.time.setTime(openspace.time.currentWallTime())
openspace.time.setTime("1977 SEP 10 12:00:00")
dofile(openspace.absPath('${SCRIPTS}/bind_common_keys.lua'))
end
function postInitialization()
openspace.printInfo("Setting default values")
openspace.setPropertyValueSingle("Global Properties.GlobeBrowsing.GdalWrapper.LogGdalErrors", false)
openspace.setPropertyValueSingle("Earth.RenderableGlobe.Debug.LevelByProjectedAreaElseDistance", false)
openspace.globebrowsing.goToGeo(58.5877, 16.1924, 20000000)
openspace.printInfo("Done setting default values")
-- Defined in scene_helper.lua
-- Used to create focus buttons for a subset of scenegraph nodes
mark_interesting_nodes({
"Earth", "Voyager 1", "Voyager 2", "Jupiter", "Saturn", "Uranus", "Neptune"
})
end
return {
ScenePath = ".",
CommonFolder = "common",
Camera = {
Focus = "Earth",
Position = {0, 0, 0},
Rotation = {0.758797, 0.221490, -0.605693, -0.091135},
},
Modules = {
-- # Solar system objects
"sun",
"mercury",
"venus",
"earth",
"moon",
"mars",
"jupiter",
"saturn",
"uranus",
"neptune",
-- "satellites",
-- "grids",
-- "digitaluniverse",
"stars/digitaluniverse",
"milkyway/digitaluniverse",
"missions/voyager"
}
}

View File

@@ -81,6 +81,9 @@ public:
void swapBuffer() const override;
int nWindows() const override;
int currentWindowId() const override;
private:
properties::FloatProperty _eyeSeparation;
properties::BoolProperty _showStatsGraph;

View File

@@ -271,8 +271,21 @@ public:
*/
virtual void takeScreenshot(bool applyWarping = false) const;
/**
* Encourages the windowing system to swap the back- and front buffers
*/
virtual void swapBuffer() const;
/**
* Returns the number of windows that are currently instantiated
*/
virtual int nWindows() const;
/**
* Returns the id of the current window (in the range [0, nWindows -1])
*/
virtual int currentWindowId() const;
struct WindowWrapperException : public ghoul::RuntimeError {
explicit WindowWrapperException(const std::string& msg);
};

View File

@@ -159,17 +159,17 @@ namespace openspace::properties {
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State* lua, \
TYPE value) \
TYPE val) \
{ \
return TO_LUA_LAMBDA_EXPRESSION(lua, value); \
return TO_LUA_LAMBDA_EXPRESSION(lua, val); \
} \
\
template <> \
template <> \
bool PropertyDelegate<NumericalProperty<TYPE>>::toLuaValue<TYPE>(lua_State* state, \
TYPE value) \
TYPE val) \
{ \
return PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(state, value); \
return PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(state, val); \
} \
\
template <> \

View File

@@ -106,16 +106,17 @@ namespace openspace::properties {
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromLuaValue<TYPE>(lua_State* l, \
bool& s) \
bool& successful) \
{ \
return FROM_LUA_LAMBDA_EXPRESSION(l, s); \
return FROM_LUA_LAMBDA_EXPRESSION(l, successful); \
} \
\
template <> \
template <> \
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State* l, TYPE v)\
bool PropertyDelegate<TemplateProperty<TYPE>>::toLuaValue<TYPE>(lua_State* l, \
TYPE value) \
{ \
return TO_LUA_LAMBDA_EXPRESSION(l, v); \
return TO_LUA_LAMBDA_EXPRESSION(l, value); \
} \
\
template <> \
@@ -125,10 +126,10 @@ namespace openspace::properties {
\
template <> \
template <> \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromString(std::string v, \
bool& s) \
TYPE PropertyDelegate<TemplateProperty<TYPE>>::fromString(std::string value, \
bool& successful) \
{ \
return FROM_STRING_LAMBDA_EXPRESSION(v, s); \
return FROM_STRING_LAMBDA_EXPRESSION(value, successful); \
} \
\
template <> \

View File

@@ -77,6 +77,7 @@ public:
void initialize();
void initializeGL();
void deinitialize();
void deinitializeGL();
void setScene(Scene* scene);
Scene* scene();

View File

@@ -64,7 +64,7 @@ public:
virtual bool deinitialize();
virtual bool deinitializeGL();
virtual void update() = 0;
virtual void update();
virtual bool isReady() const;
bool isEnabled() const;

View File

@@ -25,15 +25,14 @@
#ifndef __OPENSPACE_CORE___DISTANCECONSTANTS___H__
#define __OPENSPACE_CORE___DISTANCECONSTANTS___H__
namespace openspace {
namespace distanceconstants {
const float EarthRadius = 6371;
const float LightYear = 9.4607304725808E15;
const float AstronomicalUnit = 1.495978707E11;
const float Parsec = 3.0856776E16;
}
}
namespace openspace::distanceconstants {
constexpr double EarthRadius = 6371;
constexpr double LightYear = 9.4607304725808E15;
constexpr double LightMonth = LightYear / 12;
constexpr double LightDay = LightYear / 365;
constexpr double LightHour = LightDay / 24;
constexpr double AstronomicalUnit = 1.495978707E11;
constexpr double Parsec = 3.0856776E16;
} // openspace::distanceconstants
#endif // __OPENSPACE_CORE___DISTANCECONSTANTS___H__

View File

@@ -0,0 +1,37 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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 __OPENSPACE_CORE___DISTANCECONVERSION___H__
#define __OPENSPACE_CORE___DISTANCECONVERSION___H__
#include <string>
#include <utility>
namespace openspace {
std::pair<double, std::string> simplifyDistance(double meters);
} // namespace openspace
#endif // __OPENSPACE_CORE___DISTANCECONVERSION___H__

View File

@@ -0,0 +1,37 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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 __OPENSPACE_CORE___TIMECONVERSION___H__
#define __OPENSPACE_CORE___TIMECONVERSION___H__
#include <string>
#include <utility>
namespace openspace {
std::pair<double, std::string> simplifyTime(double seconds);
} // namespace openspace
#endif // __OPENSPACE_CORE___TIMECONVERSION___H__

View File

@@ -66,7 +66,12 @@ ScreenSpaceFramebuffer::ScreenSpaceFramebuffer(const ghoul::Dictionary& dictiona
);
_id = id();
setName("ScreenSpaceFramebuffer" + std::to_string(_id));
if (_id == 0) {
setName("ScreenSpaceFramebuffer");
}
else {
setName("ScreenSpaceFramebuffer " + std::to_string(_id));
}
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
addProperty(_size);

View File

@@ -89,7 +89,12 @@ ScreenSpaceImageLocal::ScreenSpaceImageLocal(const ghoul::Dictionary& dictionary
}
else {
static int id = 0;
setName("ScreenSpaceImageLocal " + std::to_string(id));
if (id == 0) {
setName("ScreenSpaceImageLocal");
}
else {
setName("ScreenSpaceImageLocal " + std::to_string(id));
}
++id;
}

View File

@@ -89,7 +89,12 @@ ScreenSpaceImageOnline::ScreenSpaceImageOnline(const ghoul::Dictionary& dictiona
}
else {
static int id = 0;
setName("ScreenSpaceImageOnline " + std::to_string(id));
if (id == 0) {
setName("ScreenSpaceImageOnline");
}
else {
setName("ScreenSpaceImageOnline " + std::to_string(id));
}
++id;
}

View File

@@ -544,7 +544,7 @@ void FixedRotation::update(const UpdateData&) {
glm::vec3 y = yAxis();
glm::vec3 z = zAxis();
static const float Epsilon = 1e-3;
static const float Epsilon = 1e-3f;
if (glm::dot(x, y) > 1.f - Epsilon ||
glm::dot(y, z) > 1.f - Epsilon ||

View File

@@ -110,7 +110,9 @@ void LuaRotation::update(const UpdateData& data) {
auto now = high_resolution_clock::now();
lua_pushnumber(
_state,
duration_cast<milliseconds>(now.time_since_epoch()).count()
static_cast<lua_Number>(
duration_cast<milliseconds>(now.time_since_epoch()).count()
)
);
// Execute the scaling function

View File

@@ -64,7 +64,7 @@ documentation::Documentation StaticRotation::Documentation() {
}
StaticRotation::StaticRotation()
: _rotationMatrix(RotationInfo, glm::dmat3(1.0))
: _rotationMatrix(RotationInfo, glm::dmat3(1.0), glm::dmat3(-1.0), glm::dmat3(1.0))
{
addProperty(_rotationMatrix);
_rotationMatrix.onChange([this]() { _matrix = _rotationMatrix; });

View File

@@ -101,7 +101,9 @@ void LuaScale::update(const UpdateData& data) {
auto now = high_resolution_clock::now();
lua_pushnumber(
_state,
duration_cast<milliseconds>(now.time_since_epoch()).count()
static_cast<lua_Number>(
duration_cast<milliseconds>(now.time_since_epoch()).count()
)
);
// Execute the scaling function

View File

@@ -118,7 +118,9 @@ void LuaTranslation::update(const UpdateData& data) {
auto now = high_resolution_clock::now();
lua_pushnumber(
_state,
duration_cast<milliseconds>(now.time_since_epoch()).count()
static_cast<lua_Number>(
duration_cast<milliseconds>(now.time_since_epoch()).count()
)
);
// Execute the scaling function

View File

@@ -303,8 +303,12 @@ bool RenderableFieldlinesSequence::extractMandatoryInfoFromDictionary(
LERROR(_name << ": The field " << std::string(KeyInputFileType) << " is missing!");
return false;
} else {
std::transform(inputFileTypeString.begin(), inputFileTypeString.end(),
inputFileTypeString.begin(), ::tolower);
std::transform(
inputFileTypeString.begin(),
inputFileTypeString.end(),
inputFileTypeString.begin(),
[](char c) { return static_cast<char>(tolower(c)); }
);
// Verify that the input type is correct
if (inputFileTypeString == ValueInputFileTypeCdf) {
sourceFileType = SourceFileType::Cdf;

View File

@@ -373,7 +373,7 @@ void FieldlinesState::saveStateToJson(const std::string& absPath) {
// Returns one of the extra quantity vectors, _extraQuantities[index].
// If index is out of scope an empty vector is returned and the referenced bool is false.
const std::vector<float>& FieldlinesState::extraQuantity(const size_t index,
std::vector<float> FieldlinesState::extraQuantity(const size_t index,
bool& isSuccessful) const {
if (index < _extraQuantities.size()) {
isSuccessful = true;

View File

@@ -64,7 +64,7 @@ public:
const std::vector<glm::vec3>& vertexPositions() const;
// Special getter. Returns extraQuantities[INDEX].
const std::vector<float>& extraQuantity(const size_t INDEX, bool& isSuccesful) const;
std::vector<float> extraQuantity(const size_t INDEX, bool& isSuccesful) const;
void setModel(const fls::Model m) { _model = m; }
void setTriggerTime(const double t) { _triggerTime = t; }

View File

@@ -115,9 +115,7 @@ void GalaxyRaycaster::preRaycast(const RaycastData& data,
program.setUniform(galaxyTextureUniformName, *_textureUnit);
}
void GalaxyRaycaster::postRaycast(const RaycastData& data,
ghoul::opengl::ProgramObject& program)
{
void GalaxyRaycaster::postRaycast(const RaycastData&, ghoul::opengl::ProgramObject&) {
_textureUnit = nullptr; // release texture unit.
}

View File

@@ -340,22 +340,22 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z);
float lowerRampStart = maxDim * 0.02;
float lowerRampEnd = maxDim * 0.5;
float lowerRampStart = maxDim * 0.02f;
float lowerRampEnd = maxDim * 0.5f;
float upperRampStart = maxDim * 2.0;
float upperRampEnd = maxDim * 10;
float upperRampStart = maxDim * 2.f;
float upperRampEnd = maxDim * 10.f;
float opacityCoefficient = 1.0;
float opacityCoefficient = 1.f;
if (length < lowerRampStart) {
opacityCoefficient = 0; // camera really close
opacityCoefficient = 0.f; // camera really close
} else if (length < lowerRampEnd) {
opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart);
} else if (length < upperRampStart) {
opacityCoefficient = 1.0; // sweet spot (max)
opacityCoefficient = 1.f; // sweet spot (max)
} else if (length < upperRampEnd) {
opacityCoefficient = 1.0 - (length - upperRampStart) /
opacityCoefficient = 1.f - (length - upperRampStart) /
(upperRampEnd - upperRampStart); //fade out
} else {
opacityCoefficient = 0;
@@ -363,7 +363,7 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
_opacityCoefficient = opacityCoefficient;
ghoul_assert(
_opacityCoefficient >= 0.0 && _opacityCoefficient <= 1.0,
_opacityCoefficient >= 0.f && _opacityCoefficient <= 1.f,
"Opacity coefficient was not between 0 and 1"
);
if (opacityCoefficient > 0) {

View File

@@ -301,7 +301,8 @@ void MemoryAwareTileCache::update() {
size_t MemoryAwareTileCache::getGPUAllocatedDataSize() const {
return std::accumulate(
_textureContainerMap.cbegin(),
_textureContainerMap.cend(), 0,
_textureContainerMap.cend(),
size_t(0),
[](size_t s, const std::pair<const TileTextureInitData::HashKey,
TextureContainerTileCache>& p)
{
@@ -316,7 +317,8 @@ size_t MemoryAwareTileCache::getGPUAllocatedDataSize() const {
size_t MemoryAwareTileCache::getCPUAllocatedDataSize() const {
size_t dataSize = std::accumulate(
_textureContainerMap.cbegin(),
_textureContainerMap.cend(), 0,
_textureContainerMap.cend(),
size_t(0),
[](size_t s, const std::pair<const TileTextureInitData::HashKey,
TextureContainerTileCache>& p)
{

View File

@@ -162,8 +162,8 @@ int goToGeo(lua_State* L) {
return luaL_error(L, "Expected 2 or 3 arguments.");
}
double latitude = static_cast<double>(lua_tonumber(L, 1));
double longitude = static_cast<double>(lua_tonumber(L, 2));
double latitude = lua_tonumber(L, 1);
double longitude = lua_tonumber(L, 2);
if (nArguments == 2) {
OsEng.moduleEngine().module<GlobeBrowsingModule>()->goToGeo(latitude, longitude);

View File

@@ -87,7 +87,7 @@ void TriangleSoup::setElements(std::vector<unsigned int> elements) {
_elementData.resize(elements.size());
_gpuDataNeedUpdate = true;
for (size_t i = 0; i < elements.size(); i++) {
_elementData[i] = static_cast<GLuint>(elements[i]);
_elementData[i] = elements[i];
}
}
@@ -128,8 +128,8 @@ bool TriangleSoup::updateDataOnGPU() {
// Positions at location 0
if (_useVertexPositions) {
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, position)));
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);
//reinterpret_cast<const GLvoid*>(offsetof(Vertex, position)));
}
// Textures at location 1
if (_useTextureCoordinates) {

View File

@@ -38,7 +38,7 @@ PixelBuffer::PixelBuffer(size_t numBytes, Usage usage)
{
glGenBuffers(1, &_id);
bind();
glBufferData(GL_PIXEL_UNPACK_BUFFER, _numBytes, 0, static_cast<GLenum>(_usage));
glBufferData(GL_PIXEL_UNPACK_BUFFER, _numBytes, nullptr, static_cast<GLenum>(_usage));
unbind();
}

View File

@@ -399,7 +399,7 @@ void ChunkRenderer::renderChunkLocally(const Chunk& chunk, const RenderData& dat
glm::dvec3 cornerModelSpace = ellipsoid.cartesianSurfacePosition(corner);
cornersModelSpace[i] = cornerModelSpace;
glm::dvec3 cornerCameraSpace =
glm::dvec3(dmat4(modelViewTransform) * glm::dvec4(cornerModelSpace, 1));
glm::dvec3(modelViewTransform * glm::dvec4(cornerModelSpace, 1));
cornersCameraSpace[i] = cornerCameraSpace;
programObject->setUniform(cornerNames[i], vec3(cornerCameraSpace));

View File

@@ -118,12 +118,12 @@ void PixelRegion::scale(double s) {
void PixelRegion::downscalePow2(int exponent, PixelCoordinate wrt) {
start += wrt;
start.x = ceil(start.x / static_cast<float>(pow(2, exponent)));// >>= exponent;
start.y = ceil(start.y / static_cast<float>(pow(2, exponent)));// >>= exponent;
start.x = static_cast<int>(ceil(start.x / static_cast<float>(pow(2, exponent))));
start.y = static_cast<int>(ceil(start.y / static_cast<float>(pow(2, exponent))));
numPixels.x =
ceil(numPixels.x / static_cast<float>(pow(2, exponent)));// >>= exponent;
static_cast<int>(ceil(numPixels.x / static_cast<float>(pow(2, exponent))));
numPixels.y =
ceil(numPixels.y / static_cast<float>(pow(2, exponent)));// >>= exponent;
static_cast<int>(ceil(numPixels.y / static_cast<float>(pow(2, exponent))));
start -= wrt;
}

View File

@@ -126,12 +126,17 @@ void GdalRawTileDataReader::initialize() {
// Assume all raster bands have the same data type
_gdalDatasetMetaDataCached.rasterCount = _dataset->GetRasterCount();
_gdalDatasetMetaDataCached.scale = _dataset->GetRasterBand(1)->GetScale();
_gdalDatasetMetaDataCached.offset = _dataset->GetRasterBand(1)->GetOffset();
_gdalDatasetMetaDataCached.scale = static_cast<float>(
_dataset->GetRasterBand(1)->GetScale()
);
_gdalDatasetMetaDataCached.offset = static_cast<float>(
_dataset->GetRasterBand(1)->GetOffset()
);
_gdalDatasetMetaDataCached.rasterXSize = _dataset->GetRasterXSize();
_gdalDatasetMetaDataCached.rasterYSize = _dataset->GetRasterYSize();
_gdalDatasetMetaDataCached.noDataValue =
_dataset->GetRasterBand(1)->GetNoDataValue();
_gdalDatasetMetaDataCached.noDataValue = static_cast<float>(
_dataset->GetRasterBand(1)->GetNoDataValue()
);
_gdalDatasetMetaDataCached.dataType =
tiledatatype::getGdalDataType(_initData.glType());
@@ -145,7 +150,7 @@ void GdalRawTileDataReader::initialize() {
calculateTileLevelDifference(_initData.dimensions().x);
int numOverviews = _dataset->GetRasterBand(1)->GetOverviewCount();
_cached._maxLevel = -_cached._tileLevelDifference;
_cached._maxLevel = static_cast<int>(-_cached._tileLevelDifference);
if (numOverviews > 0) {
_cached._maxLevel += numOverviews - 1;
}
@@ -162,7 +167,7 @@ RawTile::ReadError GdalRawTileDataReader::rasterRead(
);
PixelRegion::PixelCoordinate end = io.write.region.end();
size_t largestIndex =
[[maybe_unused]] size_t largestIndex =
(end.y - 1) * io.write.bytesPerLine + (end.x - 1) * _initData.bytesPerPixel();
ghoul_assert(largestIndex <= io.write.totalNumBytes, "Invalid write region");
@@ -191,7 +196,7 @@ RawTile::ReadError GdalRawTileDataReader::rasterRead(
io.write.region.numPixels.y, // width to write y in destination
_gdalDatasetMetaDataCached.dataType, // Type
static_cast<int>(_initData.bytesPerPixel()), // Pixel spacing
static_cast<int>(-io.write.bytesPerLine) // Line spacing
-static_cast<int>(io.write.bytesPerLine) // Line spacing
);
// Convert error to RawTile::ReadError
@@ -236,7 +241,7 @@ int GdalRawTileDataReader::calculateTileLevelDifference(int minimumPixelSize) co
}
int sizeLevel0 = maxOverview->GetXSize();
double diff = log2(minimumPixelSize) - log2(sizeLevel0);
return diff;
return static_cast<int>(diff);
}
} // namespace openspace::globebrowsing

View File

@@ -577,7 +577,7 @@ TileDepthTransform RawTileDataReader::calculateTileDepthTransform() {
TileDepthTransform transform;
transform.depthOffset = depthOffset();
transform.depthScale = depthScale() * maximumValue;
transform.depthScale = static_cast<float>(depthScale() * maximumValue);
return transform;
}

View File

@@ -115,14 +115,16 @@ RawTile::ReadError SimpleRawTileDataReader::rasterRead(
y * _initData.bytesPerLine() +
x * _initData.bytesPerPixel();
int xInSource =
int xInSource = static_cast<int>(
io.read.region.start.x +
static_cast<float>(x) / io.write.region.numPixels.x *
io.read.region.numPixels.x;
int yInSource =
io.read.region.numPixels.x
);
int yInSource = static_cast<int>(
io.read.region.start.y +
static_cast<float>(y) / io.write.region.numPixels.y *
io.read.region.numPixels.y;
io.read.region.numPixels.y
);
glm::vec4 sourceTexel = _dataTexture->texelAsFloat(xInSource, yInSource);
@@ -141,7 +143,7 @@ RawTile::ReadError SimpleRawTileDataReader::rasterRead(
char value = static_cast<char>(
sourceTexel[rasterBand - 1] * 255
);
*reinterpret_cast<char*>(pixelWriteDestination) = value;
*pixelWriteDestination = value;
break;
}
case GL_UNSIGNED_SHORT: {

View File

@@ -141,6 +141,7 @@ TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType) {
// break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
case 2:
@@ -169,6 +170,7 @@ TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType) {
break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
case 3:
@@ -198,6 +200,7 @@ TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType) {
// break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
case 4:
@@ -227,11 +230,12 @@ TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType) {
// break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
default:
LERROR("Unknown number of channels for OpenGL texture: " << rasterCount);
break;
throw ghoul::MissingCaseException();
}
return format;
}
@@ -267,6 +271,7 @@ TextureFormat getTextureFormatOptimized(int rasterCount, GDALDataType gdalType)
// break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
case 2:
@@ -295,6 +300,7 @@ TextureFormat getTextureFormatOptimized(int rasterCount, GDALDataType gdalType)
break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
case 3:
@@ -324,6 +330,7 @@ TextureFormat getTextureFormatOptimized(int rasterCount, GDALDataType gdalType)
// break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
case 4:
@@ -353,11 +360,12 @@ TextureFormat getTextureFormatOptimized(int rasterCount, GDALDataType gdalType)
// break;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
throw ghoul::MissingCaseException();
}
break;
default:
LERROR("Unknown number of channels for OpenGL texture: " << rasterCount);
break;
throw ghoul::MissingCaseException();
}
return format;
}
@@ -380,7 +388,7 @@ GLenum getOpenGLDataType(GDALDataType gdalType) {
return GL_DOUBLE;
default:
LERROR("GDAL data type unknown to OpenGL: " << gdalType);
return GL_UNSIGNED_BYTE;
throw ghoul::MissingCaseException();
}
}
@@ -402,7 +410,7 @@ GDALDataType getGdalDataType(GLenum glType) {
return GDT_Float64;
default:
LERROR("OpenGL data type unknown to GDAL: " << glType);
return GDT_Unknown;
throw ghoul::MissingCaseException();
}
}
@@ -410,12 +418,16 @@ GDALDataType getGdalDataType(GLenum glType) {
size_t numberOfRasters(ghoul::opengl::Texture::Format format) {
switch (format) {
case ghoul::opengl::Texture::Format::Red: return 1;
case ghoul::opengl::Texture::Format::RG: return 2;
case ghoul::opengl::Texture::Format::RGB:;
[[fallthrough]]; case ghoul::opengl::Texture::Format::BGR: return 3;
case ghoul::opengl::Texture::Format::RGBA:;
[[fallthrough]]; case ghoul::opengl::Texture::Format::BGRA: return 4;
case ghoul::opengl::Texture::Format::Red:
return 1;
case ghoul::opengl::Texture::Format::RG:
return 2;
case ghoul::opengl::Texture::Format::RGB:
case ghoul::opengl::Texture::Format::BGR:
return 3;
case ghoul::opengl::Texture::Format::RGBA:
case ghoul::opengl::Texture::Format::BGRA:
return 4;
default: {
ghoul_assert(false, "Unknown format");
return 0;
@@ -436,7 +448,7 @@ size_t numberOfBytes(GLenum glType) {
case GL_DOUBLE: return sizeof(GLdouble);
default: {
ghoul_assert(false, "Unknown data type");
return 0;
throw ghoul::MissingCaseException();
}
}
}
@@ -455,7 +467,7 @@ size_t getMaximumValue(GLenum glType) {
return 1ULL << 31ULL;
default: {
ghoul_assert(false, "Unknown data type");
return 0ULL;
throw ghoul::MissingCaseException();
}
}
}
@@ -480,7 +492,7 @@ float interpretFloat(GLenum glType, const char* src) {
return static_cast<float>(*reinterpret_cast<const GLdouble*>(src));
default: {
ghoul_assert(false, "Unknown data type");
return 0;
throw ghoul::MissingCaseException();
}
}
}
@@ -504,7 +516,7 @@ GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format) {
default:
ghoul_assert(false, "glType data type unknown");
LERROR("glType data type unknown: " << glType);
return GLenum(0);
throw ghoul::MissingCaseException();
}
case ghoul::opengl::Texture::Format::RG:
switch (glType) {
@@ -523,7 +535,7 @@ GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format) {
default:
ghoul_assert(false, "glType data type unknown");
LERROR("glType data type unknown: " << glType);
return GLenum(0);
throw ghoul::MissingCaseException();
}
case ghoul::opengl::Texture::Format::RGB:
switch (glType) {
@@ -542,7 +554,7 @@ GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format) {
default:
ghoul_assert(false, "glType data type unknown");
LERROR("glType data type unknown: " << glType);
return GLenum(0);
throw ghoul::MissingCaseException();
}
case ghoul::opengl::Texture::Format::RGBA:
switch (glType) {
@@ -561,7 +573,7 @@ GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format) {
default:
ghoul_assert(false, "glType data type unknown");
LERROR("glType data type unknown: " << glType);
return GLenum(0);
throw ghoul::MissingCaseException();
}
case ghoul::opengl::Texture::Format::BGR:
switch (glType) {
@@ -580,7 +592,7 @@ GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format) {
default:
ghoul_assert(false, "glType data type unknown");
LERROR("glType data type unknown: " << glType);
return GLenum(0);
throw ghoul::MissingCaseException();
}
case ghoul::opengl::Texture::Format::BGRA:
switch (glType) {
@@ -599,16 +611,16 @@ GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format) {
default:
ghoul_assert(false, "glType data type unknown");
LERROR("glType data type unknown: " << glType);
return GLenum(0);
throw ghoul::MissingCaseException();
}
default:
LERROR(
"Unknown format for OpenGL texture: " <<
static_cast<std::underlying_type_t<
ghoul::opengl::Texture::Format>
>(format)
static_cast<std::underlying_type_t<ghoul::opengl::Texture::Format>>(
format
)
);
return GLenum(0);
throw ghoul::MissingCaseException();
}
}

View File

@@ -46,8 +46,8 @@ TileIndex::TileIndex(const TileIndex& other)
: x(other.x), y(other.y), level(other.level)
{}
TileIndex::TileIndex(const Geodetic2& point, int level)
: level(level)
TileIndex::TileIndex(const Geodetic2& point, int level_)
: level(level_)
{
int numIndicesAtLevel = 1 << level;
double u = 0.5 + point.lon / (2 * glm::pi<double>());
@@ -55,8 +55,8 @@ TileIndex::TileIndex(const Geodetic2& point, int level)
double xIndexSpace = u * numIndicesAtLevel;
double yIndexSpace = v * numIndicesAtLevel;
x = floor(xIndexSpace);
y = floor(yIndexSpace);
x = static_cast<int>(floor(xIndexSpace));
y = static_cast<int>(floor(yIndexSpace));
}
TileIndex::TileIndex(const ghoul::Dictionary& dict) {

View File

@@ -500,7 +500,7 @@ std::vector<Time> TimeQuantizer::quantized(const Time& start, const Time& end) c
const double delta = endSeconds - startSeconds;
ghoul_assert(int(delta) % int(_resolution) == 0, "Quantization error");
const int nSteps = delta / _resolution;
const int nSteps = static_cast<int>(delta / _resolution);
std::vector<Time> result(nSteps + 1);
for (int i = 0; i <= nSteps; ++i) {

View File

@@ -61,7 +61,7 @@ TileProviderByLevel::TileProviderByLevel(const ghoul::Dictionary& dictionary) {
"Must define key '" + std::string(KeyMaxLevel) + "'"
);
}
maxLevel = std::round(floatMaxLevel);
maxLevel = static_cast<int>(std::round(floatMaxLevel));
ghoul::Dictionary providerDict;
if (!levelProviderDict.getValue<ghoul::Dictionary>(KeyTileProvider, providerDict))

View File

@@ -189,7 +189,7 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
OsEng.registerModuleKeyboardCallback(
[&](Key key, KeyModifier mod, KeyAction action) -> bool {
if (gui.isEnabled()) {
if (gui.isEnabled() || gui._performance.isEnabled()) {
return gui.keyCallback(key, mod, action);
}
else {
@@ -200,7 +200,7 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
OsEng.registerModuleCharCallback(
[&](unsigned int codepoint, KeyModifier modifier) -> bool {
if (gui.isEnabled()) {
if (gui.isEnabled() || gui._performance.isEnabled()) {
return gui.charCallback(codepoint, modifier);
}
else {
@@ -211,7 +211,7 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
OsEng.registerModuleMouseButtonCallback(
[&](MouseButton button, MouseAction action) -> bool {
if (gui.isEnabled()) {
if (gui.isEnabled() || gui._performance.isEnabled()) {
return gui.mouseButtonCallback(button, action);
}
else {
@@ -222,7 +222,7 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) {
OsEng.registerModuleMouseScrollWheelCallback(
[&](double, double posY) -> bool {
if (gui.isEnabled()) {
if (gui.isEnabled() || gui._performance.isEnabled()) {
return gui.mouseWheelCallback(posY);
}
else {

View File

@@ -41,6 +41,8 @@
#include <openspace/util/keys.h>
#include <openspace/util/mouse.h>
struct ImGuiContext;
namespace openspace::gui {
class GUI : public GuiComponent {
@@ -85,11 +87,15 @@ public:
bool _showInternals;
properties::BoolProperty _showHelpText;
private:
void renderAndUpdatePropertyVisibility();
properties::Property::Visibility _currentVisibility;
std::vector<ImGuiContext*> _contexts;
};
void CaptionText(const char* text);

View File

@@ -59,6 +59,7 @@ public:
void setVisibility(properties::Property::Visibility visibility);
void setHasRegularProperties(bool hasOnlyRegularProperties);
void setShowHelpTooltip(bool showHelpTooltip);
void render() override;
@@ -76,6 +77,7 @@ protected:
UseTreeLayout _useTreeLayout;
bool _currentUseTreeLayout;
IsTopLevelWindow _isTopLevel;
bool _showHelpTooltip;
};
} // namespace openspace::gui

View File

@@ -36,60 +36,90 @@ namespace openspace::properties {
namespace openspace {
using IsRegularProperty = ghoul::Boolean;
using ShowToolTip = ghoul::Boolean;
void executeScript(const std::string& id, const std::string& value,
IsRegularProperty isRegular = IsRegularProperty::Yes);
void renderBoolProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderOptionProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderSelectionProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderStringProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDoubleProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderIntProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderIVec2Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderIVec3Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderIVec4Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderFloatProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderVec2Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderVec3Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderVec4Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDVec2Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDVec3Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDVec4Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDMat2Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDMat3Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderDMat4Property(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
void renderTriggerProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular = IsRegularProperty::Yes);
IsRegularProperty isRegular = IsRegularProperty::Yes,
ShowToolTip showTooltip = ShowToolTip::Yes);
} // namespace openspace

View File

@@ -27,6 +27,7 @@
#include <modules/imgui/imguimodule.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/mission/missionmanager.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/keys.h>
@@ -245,6 +246,13 @@ void addScreenSpaceRenderableOnline(std::string texturePath) {
);
}
static const openspace::properties::Property::PropertyInfo ShowHelpInfo = {
"ShowHelpText",
"Show tooltip help",
"If this value is enabled these kinds of tooltips are shown for most properties "
"explaining what impact they have on the visuals."
};
} // namespace
namespace openspace::gui {
@@ -268,6 +276,7 @@ GUI::GUI()
GuiPropertyComponent::UseTreeLayout::No,
GuiPropertyComponent::IsTopLevelWindow::Yes)
, _showInternals(false)
, _showHelpText(ShowHelpInfo, true)
, _currentVisibility(properties::Property::Visibility::Developer)
{
addPropertySubOwner(_help);
@@ -285,6 +294,14 @@ GUI::GUI()
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
addPropertySubOwner(_iswa);
#endif // OPENSPACE_MODULE_ISWA_ENABLED
addProperty(_showHelpText);
_showHelpText.onChange([this](){
_globalProperty.setShowHelpTooltip(_showHelpText);
_property.setShowHelpTooltip(_showHelpText);
_screenSpaceProperty.setShowHelpTooltip(_showHelpText);
_virtualProperty.setShowHelpTooltip(_showHelpText);
});
}
void GUI::initialize() {
@@ -300,96 +317,105 @@ void GUI::initialize() {
strcpy(iniFileBuffer, cachedFile.c_str());
#endif
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = iniFileBuffer;
io.DeltaTime = 1.f / 60.f;
io.KeyMap[ImGuiKey_Tab] = static_cast<int>(Key::Tab);
io.KeyMap[ImGuiKey_LeftArrow] = static_cast<int>(Key::Left);
io.KeyMap[ImGuiKey_RightArrow] = static_cast<int>(Key::Right);
io.KeyMap[ImGuiKey_UpArrow] = static_cast<int>(Key::Up);
io.KeyMap[ImGuiKey_DownArrow] = static_cast<int>(Key::Down);
io.KeyMap[ImGuiKey_Home] = static_cast<int>(Key::Home);
io.KeyMap[ImGuiKey_End] = static_cast<int>(Key::End);
io.KeyMap[ImGuiKey_Delete] = static_cast<int>(Key::Delete);
io.KeyMap[ImGuiKey_Backspace] = static_cast<int>(Key::BackSpace);
io.KeyMap[ImGuiKey_Enter] = static_cast<int>(Key::Enter);
io.KeyMap[ImGuiKey_Escape] = static_cast<int>(Key::Escape);
io.KeyMap[ImGuiKey_A] = static_cast<int>(Key::A);
io.KeyMap[ImGuiKey_C] = static_cast<int>(Key::C);
io.KeyMap[ImGuiKey_V] = static_cast<int>(Key::V);
io.KeyMap[ImGuiKey_X] = static_cast<int>(Key::X);
io.KeyMap[ImGuiKey_Y] = static_cast<int>(Key::Y);
io.KeyMap[ImGuiKey_Z] = static_cast<int>(Key::Z);
int nWindows = OsEng.windowWrapper().nWindows();
_contexts.resize(nWindows);
io.RenderDrawListsFn = RenderDrawLists;
io.Fonts->AddFontFromFileTTF(
absPath(GuiFont).c_str(),
FontSize
);
for (int i = 0; i < nWindows; ++i) {
_contexts[i] = ImGui::CreateContext();
ImGui::SetCurrentContext(_contexts[i]);
//}
captionFont = io.Fonts->AddFontFromFileTTF(
absPath(GuiFont).c_str(),
FontSize * 1.5f
);
ImGuiStyle& style = ImGui::GetStyle();
style.WindowPadding = { 4.f, 4.f };
style.WindowRounding = 0.f;
style.FramePadding = { 3.f, 3.f };
style.FrameRounding = 0.f;
style.ItemSpacing = { 3.f, 2.f };
style.ItemInnerSpacing = { 3.f, 2.f };
style.TouchExtraPadding = { 1.f, 1.f };
style.IndentSpacing = 15.f;
style.ScrollbarSize = 10.f;
style.ScrollbarRounding = 0.f;
style.GrabMinSize = 10.f;
style.GrabRounding = 16.f;
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = iniFileBuffer;
io.DeltaTime = 1.f / 60.f;
io.KeyMap[ImGuiKey_Tab] = static_cast<int>(Key::Tab);
io.KeyMap[ImGuiKey_LeftArrow] = static_cast<int>(Key::Left);
io.KeyMap[ImGuiKey_RightArrow] = static_cast<int>(Key::Right);
io.KeyMap[ImGuiKey_UpArrow] = static_cast<int>(Key::Up);
io.KeyMap[ImGuiKey_DownArrow] = static_cast<int>(Key::Down);
io.KeyMap[ImGuiKey_Home] = static_cast<int>(Key::Home);
io.KeyMap[ImGuiKey_End] = static_cast<int>(Key::End);
io.KeyMap[ImGuiKey_Delete] = static_cast<int>(Key::Delete);
io.KeyMap[ImGuiKey_Backspace] = static_cast<int>(Key::BackSpace);
io.KeyMap[ImGuiKey_Enter] = static_cast<int>(Key::Enter);
io.KeyMap[ImGuiKey_Escape] = static_cast<int>(Key::Escape);
io.KeyMap[ImGuiKey_A] = static_cast<int>(Key::A);
io.KeyMap[ImGuiKey_C] = static_cast<int>(Key::C);
io.KeyMap[ImGuiKey_V] = static_cast<int>(Key::V);
io.KeyMap[ImGuiKey_X] = static_cast<int>(Key::X);
io.KeyMap[ImGuiKey_Y] = static_cast<int>(Key::Y);
io.KeyMap[ImGuiKey_Z] = static_cast<int>(Key::Z);
style.Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.13f, 0.13f, 0.96f);
style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
style.Colors[ImGuiCol_Border] = ImVec4(0.65f, 0.65f, 0.65f, 0.59f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.91f, 0.94f, 0.99f, 0.40f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.45f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.71f, 0.81f, 1.00f, 0.45f);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.71f, 0.81f, 1.00f, 0.45f);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.51f, 0.69f, 1.00f, 0.63f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.26f, 0.27f, 0.33f, 0.80f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.75f, 0.80f, 0.43f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.75f, 0.80f, 0.65f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.40f, 0.75f, 0.80f, 0.65f);
style.Colors[ImGuiCol_ComboBg] = ImVec4(0.36f, 0.46f, 0.56f, 1.00f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.50f, 0.80f, 0.76f, 1.00f);
style.Colors[ImGuiCol_Button] = ImVec4(0.36f, 0.54f, 0.68f, 0.62f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.36f, 0.54f, 0.68f, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.36f, 0.61f, 0.81f, 1.00f);
style.Colors[ImGuiCol_Header] = ImVec4(0.69f, 0.69f, 0.69f, 0.45f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.36f, 0.54f, 0.68f, 0.62f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.63f, 0.87f, 0.80f);
style.Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.70f, 0.60f, 0.60f, 1.00f);
style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.90f, 0.70f, 0.70f, 1.00f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
style.Colors[ImGuiCol_CloseButton] = ImVec4(0.75f, 0.75f, 0.75f, 1.00f);
style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.52f, 0.52f, 0.52f, 0.60f);
style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.44f, 0.63f, 1.00f, 0.35f);
style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
io.RenderDrawListsFn = RenderDrawLists;
io.Fonts->AddFontFromFileTTF(
absPath(GuiFont).c_str(),
FontSize
);
captionFont = io.Fonts->AddFontFromFileTTF(
absPath(GuiFont).c_str(),
FontSize * 1.5f
);
ImGuiStyle& style = ImGui::GetStyle();
style.WindowPadding = { 4.f, 4.f };
style.WindowRounding = 0.f;
style.FramePadding = { 3.f, 3.f };
style.FrameRounding = 0.f;
style.ItemSpacing = { 3.f, 2.f };
style.ItemInnerSpacing = { 3.f, 2.f };
style.TouchExtraPadding = { 1.f, 1.f };
style.IndentSpacing = 15.f;
style.ScrollbarSize = 10.f;
style.ScrollbarRounding = 0.f;
style.GrabMinSize = 10.f;
style.GrabRounding = 16.f;
style.Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.13f, 0.13f, 0.96f);
style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
style.Colors[ImGuiCol_Border] = ImVec4(0.65f, 0.65f, 0.65f, 0.59f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.91f, 0.94f, 0.99f, 0.40f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.45f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.71f, 0.81f, 1.00f, 0.45f);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.71f, 0.81f, 1.00f, 0.45f);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.51f, 0.69f, 1.00f, 0.63f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.26f, 0.27f, 0.33f, 0.80f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.75f, 0.80f, 0.43f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.75f, 0.80f, 0.65f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.40f, 0.75f, 0.80f, 0.65f);
style.Colors[ImGuiCol_ComboBg] = ImVec4(0.36f, 0.46f, 0.56f, 1.00f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.50f, 0.80f, 0.76f, 1.00f);
style.Colors[ImGuiCol_Button] = ImVec4(0.36f, 0.54f, 0.68f, 0.62f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.36f, 0.54f, 0.68f, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.36f, 0.61f, 0.81f, 1.00f);
style.Colors[ImGuiCol_Header] = ImVec4(0.69f, 0.69f, 0.69f, 0.45f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.36f, 0.54f, 0.68f, 0.62f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.63f, 0.87f, 0.80f);
style.Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.70f, 0.60f, 0.60f, 1.00f);
style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.90f, 0.70f, 0.70f, 1.00f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
style.Colors[ImGuiCol_CloseButton] = ImVec4(0.75f, 0.75f, 0.75f, 1.00f);
style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.52f, 0.52f, 0.52f, 0.60f);
style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.44f, 0.63f, 1.00f, 0.35f);
style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
}
_property.initialize();
_property.setHasRegularProperties(true);
_screenSpaceProperty.initialize();
@@ -415,6 +441,11 @@ void GUI::initialize() {
void GUI::deinitialize() {
ImGui::Shutdown();
int nWindows = OsEng.windowWrapper().nWindows();
for (int i = 0; i < nWindows; ++i) {
ImGui::DestroyContext(_contexts[i]);
}
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
_iswa.deinitialize();
#endif // OPENSPACE_MODULE_ISWA_ENABLED
@@ -447,8 +478,13 @@ void GUI::initializeGL() {
unsigned char* pngData;
glm::ivec2 textureSize;
ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pngData, &textureSize.x, &textureSize.y);
int nWindows = OsEng.windowWrapper().nWindows();
for (int i = 0; i < nWindows; ++i) {
//_contexts[i] = ImGui::CreateContext();
ImGui::SetCurrentContext(_contexts[i]);
ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pngData, &textureSize.x, &textureSize.y);
}
_fontTexture = std::make_unique<ghoul::opengl::Texture>(
pngData,
glm::uvec3(textureSize.x, textureSize.y, 1)
@@ -458,7 +494,12 @@ void GUI::initializeGL() {
_fontTexture->uploadTexture();
GLuint id = *_fontTexture;
uint64_t tmp = id;
ImGui::GetIO().Fonts->TexID = reinterpret_cast<void*>(tmp);
for (int i = 0; i < nWindows; ++i) {
//_contexts[i] = ImGui::CreateContext();
ImGui::SetCurrentContext(_contexts[i]);
ImGui::GetIO().Fonts->TexID = reinterpret_cast<void*>(tmp);
}
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
@@ -553,6 +594,9 @@ void GUI::startFrame(float deltaTime, const glm::vec2& windowSize,
const glm::vec2& dpiScaling, const glm::vec2& mousePos,
uint32_t mouseButtonsPressed)
{
int iWindow = OsEng.windowWrapper().currentWindowId();
ImGui::SetCurrentContext(_contexts[iWindow]);
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2(windowSize.x, windowSize.y);
io.DisplayFramebufferScale = ImVec2(dpiScaling.x, dpiScaling.y);
@@ -571,7 +615,10 @@ void GUI::endFrame() {
_program->rebuildFromFile();
}
if (OsEng.renderEngine().doesPerformanceMeasurements()) {
bool perf = OsEng.renderEngine().doesPerformanceMeasurements();
_performance.setEnabled(perf);
if (_performance.isEnabled()) {
_performance.render();
}

View File

@@ -35,7 +35,7 @@
#include <openspace/util/timemanager.h>
namespace {
const ImVec2 size = ImVec2(350, 500);
static const ImVec2 Size = ImVec2(350, 500);
void renderMission(const openspace::Mission& mission) {
// The hashname is necessary since ImGui computes a hash based off the name of the
@@ -99,7 +99,7 @@ GuiMissionComponent::GuiMissionComponent() : GuiComponent("Mission Information")
void GuiMissionComponent::render() {
bool v = _isEnabled;
ImGui::Begin(name().c_str(), &v, size, 0.75f);
ImGui::Begin(name().c_str(), &v, Size, 0.75f);
_isEnabled = v;
ghoul_assert(

View File

@@ -166,6 +166,10 @@ void GuiPropertyComponent::setHasRegularProperties(bool hasOnlyRegularProperties
_hasOnlyRegularProperties = hasOnlyRegularProperties;
}
void GuiPropertyComponent::setShowHelpTooltip(bool showHelpTooltip) {
_showHelpTooltip = showHelpTooltip;
}
void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner) {
if (owner->propertiesRecursive().empty()) {
return;
@@ -263,6 +267,7 @@ void GuiPropertyComponent::render() {
dynamic_cast<SceneGraphNode*>(owner),
"When using the tree layout, all owners must be SceneGraphNodes"
);
(void)owner; // using [[maybe_unused]] in the for loop gives an error
}
// Sort:
@@ -373,7 +378,7 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop,
properties::PropertyOwner* owner)
{
using Func = std::function<
void(properties::Property*, const std::string&, IsRegularProperty)
void(properties::Property*, const std::string&, IsRegularProperty, ShowToolTip)
>;
static const std::map<std::string, Func> FunctionMapping = {
{ "BoolProperty", &renderBoolProperty },
@@ -389,6 +394,9 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop,
{ "DVec2Property", &renderDVec2Property },
{ "DVec3Property", &renderDVec3Property },
{ "DVec4Property", &renderDVec4Property },
{ "DMat2Property", &renderDMat2Property },
{ "DMat3Property", &renderDMat3Property },
{ "DMat4Property", &renderDMat4Property },
{ "StringProperty", &renderStringProperty },
{ "OptionProperty", &renderOptionProperty },
{ "TriggerProperty", &renderTriggerProperty },
@@ -406,14 +414,16 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop,
it->second(
prop,
owner->name(),
IsRegularProperty(_hasOnlyRegularProperties)
IsRegularProperty(_hasOnlyRegularProperties),
ShowToolTip(_showHelpTooltip)
);
}
else {
it->second(
prop,
"",
IsRegularProperty(_hasOnlyRegularProperties)
IsRegularProperty(_hasOnlyRegularProperties),
ShowToolTip(_showHelpTooltip)
);
}
}

View File

@@ -37,7 +37,7 @@
#include <openspace/scene/scene.h>
namespace {
const ImVec2 size = ImVec2(350, 500);
static const ImVec2 Size = ImVec2(350, 500);
} // namespace
namespace openspace::gui {
@@ -45,7 +45,7 @@ namespace openspace::gui {
GuiSpaceTimeComponent::GuiSpaceTimeComponent() : GuiComponent("Space/Time") {}
void GuiSpaceTimeComponent::render() {
ImGui::Begin(name().c_str(), nullptr, size, 0.5f, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Begin(name().c_str(), nullptr, Size, 0.5f, ImGuiWindowFlags_AlwaysAutoResize);
std::vector<SceneGraphNode*> nodes =
OsEng.renderEngine().scene()->allSceneGraphNodes();

View File

@@ -28,6 +28,7 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/matrixproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/stringproperty.h>
@@ -35,6 +36,7 @@
#include <openspace/scripting/scriptengine.h>
#include <ghoul/filesystem/filesystem.h>
#include <glm/ext.hpp>
namespace openspace {
@@ -85,7 +87,7 @@ void executeScript(const std::string& id, const std::string& value,
}
void renderBoolProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
BoolProperty* p = static_cast<BoolProperty*>(prop);
@@ -94,7 +96,9 @@ void renderBoolProperty(Property* prop, const std::string& ownerName,
BoolProperty::ValueType value = *p;
ImGui::Checkbox(name.c_str(), &value);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(p->fullyQualifiedIdentifier(), value ? "true" : "false", isRegular);
@@ -103,7 +107,7 @@ void renderBoolProperty(Property* prop, const std::string& ownerName,
}
void renderOptionProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
OptionProperty* p = static_cast<OptionProperty*>(prop);
@@ -120,7 +124,9 @@ void renderOptionProperty(Property* prop, const std::string& ownerName,
ImGui::Separator();
for (const OptionProperty::Option& o : options) {
ImGui::RadioButton(o.description.c_str(), &value, o.value);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
}
ImGui::Separator();
break;
@@ -134,13 +140,13 @@ void renderOptionProperty(Property* prop, const std::string& ownerName,
}
nodeNames += '\0';
int idx = std::distance(
int idx = static_cast<int>(std::distance(
options.begin(),
std::find_if(
options.begin(),
options.end(),
[value](const OptionProperty::Option& o) { return o.value == value; }
));
)));
int oldIdx = idx;
ImGui::Combo(name.c_str(), &idx, nodeNames.c_str());
@@ -159,7 +165,7 @@ void renderOptionProperty(Property* prop, const std::string& ownerName,
}
void renderSelectionProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
SelectionProperty* p = static_cast<SelectionProperty*>(prop);
@@ -179,7 +185,9 @@ void renderSelectionProperty(Property* prop, const std::string& ownerName,
) != selectedIndices.end();
ImGui::Checkbox(description.c_str(), &selected);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (selected) {
newSelectedIndices.push_back(i);
@@ -200,14 +208,14 @@ void renderSelectionProperty(Property* prop, const std::string& ownerName,
}
void renderStringProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
StringProperty* p = static_cast<StringProperty*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
std::string value = FileSys.convertPathSeparator(p->value(), '/');
const std::string value = p->value();
static const int bufferSize = 256;
static char buffer[bufferSize];
@@ -222,13 +230,14 @@ void renderStringProperty(Property* prop, const std::string& ownerName,
bufferSize,
ImGuiInputTextFlags_EnterReturnsTrue
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (hasNewValue) {
executeScript(
p->fullyQualifiedIdentifier(),
"'" + std::string(buffer) + "'",
"[[" + std::string(buffer) + "]]",
isRegular
);
}
@@ -237,7 +246,7 @@ void renderStringProperty(Property* prop, const std::string& ownerName,
}
void renderDoubleProperty(properties::Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DoubleProperty* p = static_cast<DoubleProperty*>(prop);
@@ -249,7 +258,9 @@ void renderDoubleProperty(properties::Property* prop, const std::string& ownerNa
float max = static_cast<float>(p->maxValue());
ImGui::SliderFloat(name.c_str(), &value, min, max, "%.5f");
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != static_cast<float>(p->value())) {
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value), isRegular);
@@ -259,7 +270,7 @@ void renderDoubleProperty(properties::Property* prop, const std::string& ownerNa
}
void renderIntProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
IntProperty* p = static_cast<IntProperty*>(prop);
@@ -271,7 +282,9 @@ void renderIntProperty(Property* prop, const std::string& ownerName,
int max = p->maxValue();
ImGui::SliderInt(name.c_str(), &value, min, max);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value), isRegular);
@@ -281,7 +294,7 @@ void renderIntProperty(Property* prop, const std::string& ownerName,
}
void renderIVec2Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
IVec2Property* p = static_cast<IVec2Property*>(prop);
@@ -289,20 +302,22 @@ void renderIVec2Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
IVec2Property::ValueType value = *p;
int min = std::min(p->minValue().x, p->minValue().y);
int max = std::max(p->maxValue().x, p->maxValue().y);
int min = glm::compMin(p->minValue());
int max = glm::compMax(p->maxValue());
ImGui::SliderInt2(
name.c_str(),
&value.x,
min,
max
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}",
std::to_string(value),
isRegular
);
}
@@ -311,7 +326,7 @@ void renderIVec2Property(Property* prop, const std::string& ownerName,
}
void renderIVec3Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
IVec3Property* p = static_cast<IVec3Property*>(prop);
@@ -319,8 +334,8 @@ void renderIVec3Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
IVec3Property::ValueType value = *p;
int min = std::min(std::min(p->minValue().x, p->minValue().y), p->minValue().z);
int max = std::max(std::max(p->maxValue().x, p->maxValue().y), p->maxValue().z);
int min = glm::compMin(p->minValue());
int max = glm::compMax(p->maxValue());
ImGui::SliderInt3(
name.c_str(),
@@ -328,13 +343,14 @@ void renderIVec3Property(Property* prop, const std::string& ownerName,
min,
max
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "," +
std::to_string(value.z) + "}",
std::to_string(value),
isRegular
);
}
@@ -342,7 +358,7 @@ void renderIVec3Property(Property* prop, const std::string& ownerName,
}
void renderIVec4Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
IVec4Property* p = static_cast<IVec4Property*>(prop);
@@ -350,12 +366,8 @@ void renderIVec4Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
IVec4Property::ValueType value = *p;
int min = std::min(std::min(std::min(
p->minValue().x, p->minValue().y), p->minValue().z), p->minValue().w
);
int max = std::max(std::max(std::max(
p->maxValue().x, p->maxValue().y), p->maxValue().z), p->maxValue().w
);
int min = glm::compMin(p->minValue());
int max = glm::compMax(p->maxValue());
ImGui::SliderInt4(
name.c_str(),
@@ -363,15 +375,14 @@ void renderIVec4Property(Property* prop, const std::string& ownerName,
min,
max
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}",
std::to_string(value),
isRegular
);
}
@@ -379,7 +390,7 @@ void renderIVec4Property(Property* prop, const std::string& ownerName,
}
void renderFloatProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
FloatProperty* p = static_cast<FloatProperty*>(prop);
@@ -390,7 +401,9 @@ void renderFloatProperty(Property* prop, const std::string& ownerName,
float min = p->minValue();
float max = p->maxValue();
ImGui::SliderFloat(name.c_str(), &value, min, max, "%.5f");
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value), isRegular);
@@ -400,7 +413,7 @@ void renderFloatProperty(Property* prop, const std::string& ownerName,
}
void renderVec2Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
Vec2Property* p = static_cast<Vec2Property*>(prop);
@@ -408,8 +421,9 @@ void renderVec2Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
Vec2Property::ValueType value = *p;
float min = std::min(p->minValue().x, p->minValue().y);
float max = std::max(p->maxValue().x, p->maxValue().y);
float min = static_cast<float>(glm::compMin(p->minValue()));
float max = static_cast<float>(glm::compMax(p->maxValue()));
ImGui::SliderFloat2(
name.c_str(),
&value.x,
@@ -417,12 +431,14 @@ void renderVec2Property(Property* prop, const std::string& ownerName,
max,
"%.5f"
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}",
std::to_string(value),
isRegular
);
}
@@ -431,7 +447,7 @@ void renderVec2Property(Property* prop, const std::string& ownerName,
}
void renderVec3Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
Vec3Property* p = static_cast<Vec3Property*>(prop);
@@ -439,10 +455,8 @@ void renderVec3Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
Vec3Property::ValueType value = *p;
float min = std::min(std::min(p->minValue().x, p->minValue().y), p->minValue().z);
float max = std::max(std::max(p->maxValue().x, p->maxValue().y), p->maxValue().z);
float min = static_cast<float>(glm::compMin(p->minValue()));
float max = static_cast<float>(glm::compMax(p->maxValue()));
if (prop->viewOption(Property::ViewOptions::Color)) {
ImGui::ColorEdit3(
@@ -459,14 +473,14 @@ void renderVec3Property(Property* prop, const std::string& ownerName,
"%.5f"
);
}
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "}",
std::to_string(value),
isRegular
);
}
@@ -475,7 +489,7 @@ void renderVec3Property(Property* prop, const std::string& ownerName,
}
void renderVec4Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
Vec4Property* p = static_cast<Vec4Property*>(prop);
@@ -483,10 +497,8 @@ void renderVec4Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
Vec4Property::ValueType value = *p;
float min = std::min(std::min(std::min(
p->minValue().x, p->minValue().y), p->minValue().z), p->minValue().w);
float max = std::max(std::max(std::max(
p->maxValue().x, p->maxValue().y), p->maxValue().z), p->maxValue().w);
float min = static_cast<float>(glm::compMin(p->minValue()));
float max = static_cast<float>(glm::compMax(p->maxValue()));
if (prop->viewOption(Property::ViewOptions::Color)) {
ImGui::ColorEdit4(
@@ -503,16 +515,14 @@ void renderVec4Property(Property* prop, const std::string& ownerName,
"%.5f"
);
}
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (value != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}",
std::to_string(value),
isRegular
);
}
@@ -521,7 +531,7 @@ void renderVec4Property(Property* prop, const std::string& ownerName,
}
void renderDVec2Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DVec2Property* p = static_cast<DVec2Property*>(prop);
@@ -529,8 +539,8 @@ void renderDVec2Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
glm::vec2 value = glm::dvec2(*p);
float min = static_cast<float>(std::min(p->minValue().x, p->minValue().y));
float max = static_cast<float>(std::max(p->maxValue().x, p->maxValue().y));
float min = static_cast<float>(glm::compMin(p->minValue()));
float max = static_cast<float>(glm::compMax(p->maxValue()));
ImGui::SliderFloat2(
name.c_str(),
&value.x,
@@ -538,12 +548,14 @@ void renderDVec2Property(Property* prop, const std::string& ownerName,
max,
"%.5f"
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (glm::dvec2(value) != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}",
std::to_string(value),
isRegular
);
}
@@ -552,7 +564,7 @@ void renderDVec2Property(Property* prop, const std::string& ownerName,
}
void renderDVec3Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DVec3Property* p = static_cast<DVec3Property*>(prop);
@@ -560,12 +572,8 @@ void renderDVec3Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
glm::vec3 value = glm::dvec3(*p);
float min = static_cast<float>(
std::min(std::min(p->minValue().x, p->minValue().y), p->minValue().z)
);
float max = static_cast<float>(
std::max(std::max(p->maxValue().x, p->maxValue().y), p->maxValue().z)
);
float min = static_cast<float>(glm::compMin(p->minValue()));
float max = static_cast<float>(glm::compMax(p->maxValue()));
bool changed = ImGui::SliderFloat3(
name.c_str(),
@@ -574,14 +582,14 @@ void renderDVec3Property(Property* prop, const std::string& ownerName,
max,
"%.5f"
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (changed) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "}",
std::to_string(value),
isRegular
);
}
@@ -590,7 +598,7 @@ void renderDVec3Property(Property* prop, const std::string& ownerName,
}
void renderDVec4Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DVec4Property* p = static_cast<DVec4Property*>(prop);
@@ -598,16 +606,8 @@ void renderDVec4Property(Property* prop, const std::string& ownerName,
ImGui::PushID((ownerName + "." + name).c_str());
glm::vec4 value = glm::dvec4(*p);
float min = static_cast<float>(
std::min(std::min(std::min(
p->minValue().x, p->minValue().y), p->minValue().z), p->minValue().w
)
);
float max = static_cast<float>(
std::max(std::max(std::max(
p->maxValue().x, p->maxValue().y), p->maxValue().z), p->maxValue().w
)
);
float min = static_cast<float>(glm::compMin(p->minValue()));
float max = static_cast<float>(glm::compMax(p->maxValue()));
ImGui::SliderFloat4(
name.c_str(),
@@ -616,15 +616,148 @@ void renderDVec4Property(Property* prop, const std::string& ownerName,
max,
"%.5f"
);
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
if (glm::dvec4(value) != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}",
std::to_string(value),
isRegular
);
}
ImGui::PopID();
}
void renderDMat2Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DMat2Property* p = static_cast<DMat2Property*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
ImGui::Text("%s", name.c_str());
glm::mat2 value = glm::dmat2(*p);
glm::dvec2 minValues = {
glm::compMin(p->minValue()[0]),
glm::compMin(p->minValue()[1])
};
float min = static_cast<float>(glm::compMin(minValues));
glm::dvec2 maxValues = {
glm::compMax(p->maxValue()[0]),
glm::compMax(p->maxValue()[1])
};
float max = static_cast<float>(glm::compMax(maxValues));
ImGui::SliderFloat2("[0]", glm::value_ptr(value[0]), min, max);
ImGui::SliderFloat2("[1]", glm::value_ptr(value[1]), min, max);
if (showTooltip) {
renderTooltip(prop);
}
if (glm::dmat2(value) != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
std::to_string(value),
isRegular
);
}
ImGui::PopID();
}
void renderDMat3Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DMat3Property* p = static_cast<DMat3Property*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
ImGui::Text("%s", name.c_str());
glm::mat3 value = glm::dmat3(*p);
glm::dvec3 minValues = {
glm::compMin(p->minValue()[0]),
glm::compMin(p->minValue()[1]),
glm::compMin(p->minValue()[2])
};
float min = static_cast<float>(glm::compMin(minValues));
glm::dvec3 maxValues = {
glm::compMax(p->maxValue()[0]),
glm::compMax(p->maxValue()[1]),
glm::compMax(p->maxValue()[2])
};
float max = static_cast<float>(glm::compMax(maxValues));
ImGui::SliderFloat3("[0]", glm::value_ptr(value[0]), min, max);
ImGui::SliderFloat3("[1]", glm::value_ptr(value[1]), min, max);
ImGui::SliderFloat3("[2]", glm::value_ptr(value[2]), min, max);
if (showTooltip) {
renderTooltip(prop);
}
if (glm::dmat3(value) != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
std::to_string(value),
isRegular
);
}
ImGui::PopID();
}
void renderDMat4Property(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
DMat4Property* p = static_cast<DMat4Property*>(prop);
std::string name = p->guiName();
ImGui::PushID((ownerName + "." + name).c_str());
ImGui::Text("%s", name.c_str());
glm::mat4 value = glm::dmat4(*p);
glm::dvec4 minValues = {
glm::compMin(p->minValue()[0]),
glm::compMin(p->minValue()[1]),
glm::compMin(p->minValue()[2]),
glm::compMin(p->minValue()[3])
};
float min = static_cast<float>(glm::compMin(minValues));
glm::dvec4 maxValues = {
glm::compMax(p->maxValue()[0]),
glm::compMax(p->maxValue()[1]),
glm::compMax(p->maxValue()[2]),
glm::compMax(p->maxValue()[3])
};
float max = static_cast<float>(glm::compMax(maxValues));
ImGui::SliderFloat4("[0]", glm::value_ptr(value[0]), min, max);
ImGui::SliderFloat4("[1]", glm::value_ptr(value[1]), min, max);
ImGui::SliderFloat4("[2]", glm::value_ptr(value[2]), min, max);
ImGui::SliderFloat4("[3]", glm::value_ptr(value[3]), min, max);
if (showTooltip) {
renderTooltip(prop);
}
if (glm::dmat4(value) != p->value()) {
executeScript(
p->fullyQualifiedIdentifier(),
std::to_string(value),
isRegular
);
}
@@ -633,7 +766,7 @@ void renderDVec4Property(Property* prop, const std::string& ownerName,
}
void renderTriggerProperty(Property* prop, const std::string& ownerName,
IsRegularProperty isRegular)
IsRegularProperty isRegular, ShowToolTip showTooltip)
{
ghoul_assert(prop, "prop must not be nullptr");
std::string name = prop->guiName();
@@ -643,7 +776,9 @@ void renderTriggerProperty(Property* prop, const std::string& ownerName,
if (pressed) {
executeScript(prop->fullyQualifiedIdentifier(), "nil", isRegular);
}
renderTooltip(prop);
if (showTooltip) {
renderTooltip(prop);
}
ImGui::PopID();
}

View File

@@ -148,9 +148,7 @@ void DataProcessor::initializeVectors(int numOptions){
}
void DataProcessor::calculateFilterValues(std::vector<int> selectedOptions) {
int numSelected = selectedOptions.size();
std::shared_ptr<Histogram> histogram;
float mean, standardDeviation, filterMid, filterWidth;
int numSelected = static_cast<int>(selectedOptions.size());
_filterValues = glm::vec2(0.0);
if (numSelected <= 0) {
@@ -159,10 +157,12 @@ void DataProcessor::calculateFilterValues(std::vector<int> selectedOptions) {
if (!_histograms.empty()) {
for (int option : selectedOptions) {
float filterMid;
float filterWidth;
if (!_useHistogram) {
mean = (1.0/_numValues[option])*_sum[option];
standardDeviation = _standardDeviation[option];
histogram = _histograms[option];
float mean = (1.f / _numValues[option]) * _sum[option];
float standardDeviation = _standardDeviation[option];
std::shared_ptr<Histogram> histogram = _histograms[option];
filterMid = histogram->highestBinValue(_useHistogram);
filterWidth = mean+histogram->binWidth();
@@ -196,13 +196,13 @@ void DataProcessor::calculateFilterValues(std::vector<int> selectedOptions) {
void DataProcessor::add(std::vector<std::vector<float>>& optionValues,
std::vector<float>& sum)
{
int numOptions = optionValues.size();
int numOptions = static_cast<int>(optionValues.size());
int numValues;
float mean, value, variance, standardDeviation;
for (int i=0; i<numOptions; i++) {
std::vector<float> values = optionValues[i];
numValues = values.size();
numValues = static_cast<int>(values.size());
variance = 0;
mean = (1.0f/numValues)*sum[i];

View File

@@ -68,7 +68,7 @@ std::vector<std::string> DataProcessorJson::readMetadata(std::string data,
void DataProcessorJson::addDataValues(std::string data,
properties::SelectionProperty& dataOptions)
{
int numOptions = dataOptions.options().size();
int numOptions = static_cast<int>(dataOptions.options().size());
initializeVectors(numOptions);
if (!data.empty()) {
@@ -87,7 +87,7 @@ void DataProcessorJson::addDataValues(std::string data,
for(int y=0; y<row.size(); y++){
json col = row.at(y);
int colsize = col.size();
int colsize = static_cast<int>(col.size());
for(int x=0; x<colsize; x++){
value = col.at(x);
@@ -105,32 +105,33 @@ void DataProcessorJson::addDataValues(std::string data,
}
std::vector<float*> DataProcessorJson::processData(std::string data,
properties::SelectionProperty& dataOptions,
properties::SelectionProperty& optionProp,
glm::size3_t& dimensions)
{
if (!data.empty()) {
json j = json::parse(data);
json variables = j["variables"];
std::vector<int> selectedOptions = dataOptions.value();
std::vector<int> selectedOptions = optionProp.value();
// int numSelected = selectedOptions.size();
auto options = dataOptions.options();
int numOptions = options.size();
const std::vector<properties::SelectionProperty::Option>& options =
optionProp.options();
int numOptions = static_cast<int>(options.size());
float value;
int rowsize, colsize, i;
std::vector<float*> dataOptions(numOptions, nullptr);
for(int option : selectedOptions){
dataOptions[option] = new float[dimensions.x*dimensions.y]{0.f};
dataOptions[option] = new float[dimensions.x*dimensions.y]{ 0.f };
json row = variables[options[option].description];
rowsize = row.size();
rowsize = static_cast<int>(row.size());
for(int y=0; y<rowsize; y++){
json col = row.at(y);
colsize = col.size();
colsize = static_cast<int>(col.size());
for(int x=0; x<colsize; x++){
value = col.at(x);

View File

@@ -25,6 +25,7 @@
#include <modules/iswa/util/dataprocessorkameleon.h>
//#include <algorithm>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/glm.h>
namespace {
const char* _loggerCat = "DataProcessorKameleon";
@@ -43,7 +44,7 @@ DataProcessorKameleon::DataProcessorKameleon()
DataProcessorKameleon::~DataProcessorKameleon(){}
std::vector<std::string> DataProcessorKameleon::readMetadata(std::string path,
glm::size3_t& dimensions)
glm::size3_t&)
{
if (!path.empty()) {
if (path != _kwPath || !_kw) {
@@ -71,7 +72,7 @@ std::vector<std::string> DataProcessorKameleon::readMetadata(std::string path,
void DataProcessorKameleon::addDataValues(std::string path,
properties::SelectionProperty& dataOptions)
{
int numOptions = dataOptions.options().size();
int numOptions = static_cast<int>(dataOptions.options().size());
initializeVectors(numOptions);
if (!path.empty()) {
@@ -83,7 +84,7 @@ void DataProcessorKameleon::addDataValues(std::string path,
std::vector<std::vector<float>> optionValues(numOptions, std::vector<float>());
auto options = dataOptions.options();
int numValues = _dimensions.x*_dimensions.y*_dimensions.z;
int numValues = static_cast<int>(_dimensions.x * _dimensions.y * _dimensions.z);
float* values;
float value;
@@ -120,23 +121,23 @@ std::vector<float*> DataProcessorKameleon::processData(std::string path,
}
std::vector<float*> DataProcessorKameleon::processData(std::string path,
properties::SelectionProperty& dataOptions,
properties::SelectionProperty& optionProp,
glm::size3_t& dimensions)
{
int numOptions = dataOptions.options().size();
int numOptions = static_cast<int>(optionProp.options().size());
if (!path.empty()) {
if (path != _kwPath || !_kw) {
initializeKameleonWrapper(path);
}
std::vector<int> selectedOptions = dataOptions.value();
std::vector<int> selectedOptions = optionProp.value();
// int numSelected = selectedOptions.size();
auto options = dataOptions.options();
int numOptions = options.size();
const std::vector<properties::SelectionProperty::Option>& options =
optionProp.options();
int numValues = dimensions.x*dimensions.y*dimensions.z;
int numValues = static_cast<int>(glm::compMul(dimensions));
float value;
@@ -148,7 +149,7 @@ std::vector<float*> DataProcessorKameleon::processData(std::string path,
_slice
);
for (int i=0; i<numValues; i++) {
for (int i = 0; i < numValues; i++) {
value = dataOptions[option][i];
dataOptions[option][i] = processDataPoint(value, option);
}

View File

@@ -91,7 +91,7 @@ std::vector<std::string> DataProcessorText::readMetadata(std::string data,
void DataProcessorText::addDataValues(std::string data,
properties::SelectionProperty& dataOptions)
{
int numOptions = dataOptions.options().size();
int numOptions = static_cast<int>(dataOptions.options().size());
initializeVectors(numOptions);
if (!data.empty()) {
@@ -147,16 +147,16 @@ void DataProcessorText::addDataValues(std::string data,
}
std::vector<float*> DataProcessorText::processData(std::string data,
properties::SelectionProperty& dataOptions,
properties::SelectionProperty& options,
glm::size3_t& dimensions)
{
if (!data.empty()) {
std::string line;
std::stringstream memorystream(data);
std::vector<int> selectedOptions = dataOptions.value();
std::vector<int> selectedOptions = options.value();
// int numSelected = selectedOptions.size();
int numOptions = dataOptions.options().size();
int numOptions = static_cast<int>(options.options().size());
std::vector<float> values;
float value;
@@ -164,8 +164,8 @@ std::vector<float*> DataProcessorText::processData(std::string data,
int first, last, option, lineSize;
std::vector<float*> dataOptions(numOptions, nullptr);
for (int option : selectedOptions) {
dataOptions[option] = new float[dimensions.x*dimensions.y]{0.0f};
for (int o : selectedOptions) {
dataOptions[o] = new float[dimensions.x * dimensions.y] { 0.f };
}
int numValues = 0;
@@ -203,12 +203,11 @@ std::vector<float*> DataProcessorText::processData(std::string data,
// first = 0;
last = 0;
option = -3;
lineSize = line.size();
lineSize = static_cast<int>(line.size());
while (last < lineSize) {
first = line.find_first_not_of(" \t", last);
last = line.find_first_of(" \t", first);
first = static_cast<int>(line.find_first_not_of(" \t", last));
last = static_cast<int>(line.find_first_of(" \t", first));
last = (last > 0)? last : lineSize;
auto it = std::find(

View File

@@ -184,12 +184,12 @@ bool KameleonWrapper::open(const std::string& filename) {
}
void KameleonWrapper::close() {
if (_kameleon)
if (_kameleon) {
_kameleon->close();
if (_interpolator)
delete _interpolator;
if (_kameleon)
delete _kameleon;
}
delete _interpolator;
delete _kameleon;
_kameleon = nullptr;
_interpolator = nullptr;
@@ -202,8 +202,7 @@ float* KameleonWrapper::getUniformSampledValues(
const std::string& var,
const glm::size3_t& outDimensions)
{
assert(_model && _interpolator);
assert(outDimensions.x > 0 && outDimensions.y > 0 && outDimensions.z > 0);
ghoul_assert(_model && _interpolator, "Model and interpolator must exist");
LINFO("Loading variable " << var << " from CDF data with a uniform sampling");
unsigned int size = static_cast<unsigned int>(
@@ -384,8 +383,7 @@ float* KameleonWrapper::getUniformSliceValues(const std::string& var,
const glm::size3_t& outDimensions,
const float& slice)
{
assert(_model && _interpolator);
assert(outDimensions.x > 0 && outDimensions.y > 0 && outDimensions.z > 0);
ghoul_assert(_model && _interpolator, "Model and interpolator must exist");
LINFO("Loading variable " << var << " from CDF data with a uniform sampling");
unsigned int size = static_cast<unsigned int>(
@@ -414,8 +412,8 @@ float* KameleonWrapper::getUniformSliceValues(const std::string& var,
LDEBUG(var << "Min: " << varMin);
LDEBUG(var << "Max: " << varMax);
double maxValue = 0.0;
double minValue = std::numeric_limits<double>::max();
//double maxValue = 0.0;
//double minValue = std::numeric_limits<double>::max();
float missingValue = _model->getMissingValue();
@@ -517,8 +515,7 @@ float* KameleonWrapper::getUniformSampledVectorValues(const std::string& xVar,
const std::string& zVar,
const glm::size3_t& outDimensions)
{
assert(_model && _interpolator);
assert(outDimensions.x > 0 && outDimensions.y > 0 && outDimensions.z > 0);
ghoul_assert(_model && _interpolator, "Model and interpolator must exist");
LINFO(
"Loading variables " << xVar << " " << yVar << " " << zVar <<
" from CDF data with a uniform sampling"
@@ -597,7 +594,7 @@ KameleonWrapper::Fieldlines KameleonWrapper::getClassifiedFieldLines(
const std::vector<glm::vec3>& seedPoints,
float stepSize )
{
assert(_model && _interpolator);
ghoul_assert(_model && _interpolator, "Model and interpolator must exist");
LINFO(
"Creating " << seedPoints.size() << " fieldlines from variables " <<
xVar << " " << yVar << " " << zVar
@@ -654,7 +651,7 @@ KameleonWrapper::Fieldlines KameleonWrapper::getFieldLines(const std::string& xV
const std::string& yVar, const std::string& zVar,
const std::vector<glm::vec3>& seedPoints, float stepSize, const glm::vec4& color)
{
assert(_model && _interpolator);
ghoul_assert(_model && _interpolator, "Model and interpolator must exist");
LINFO(
"Creating " << seedPoints.size() << " fieldlines from variables " <<
xVar << " " << yVar << " " << zVar
@@ -744,7 +741,7 @@ KameleonWrapper::Fieldlines KameleonWrapper::getLorentzTrajectories(
glm::vec3 KameleonWrapper::getModelBarycenterOffset() {
// ENLIL is centered, no need for offset
if (_type == Model::ENLIL) {
return glm::vec3(0,0,0);
return glm::vec3(0.f);
}
glm::vec3 offset;
@@ -770,8 +767,9 @@ glm::vec4 KameleonWrapper::getModelBarycenterOffsetScaled() {
}
glm::vec3 KameleonWrapper::getModelScale() {
if (_type == Model::ENLIL)
return glm::vec3(1.0f, 1.0f, 1.0f);
if (_type == Model::ENLIL) {
return glm::vec3(1.f);
}
glm::vec3 scale;
scale.x = _xMax - _xMin;

View File

@@ -394,8 +394,8 @@ void RenderableKameleonVolume::loadCdf(const std::string& path) {
KameleonVolumeReader reader(path);
if (_autoValueBounds) {
_lowerValueBound = reader.minValue(_variable);
_upperValueBound = reader.maxValue(_variable);
_lowerValueBound = static_cast<float>(reader.minValue(_variable));
_upperValueBound = static_cast<float>(reader.maxValue(_variable));
}
std::vector<std::string> variables = reader.gridVariableNames();

View File

@@ -130,8 +130,14 @@ void KameleonVolumeToRawTask::perform(const Task::ProgressCallback& progressCall
outputMetadata.setValue<glm::vec3>(KeyDimensions, _dimensions);
outputMetadata.setValue<glm::vec3>(KeyLowerDomainBound, _lowerDomainBound);
outputMetadata.setValue<glm::vec3>(KeyUpperDomainBound, _upperDomainBound);
outputMetadata.setValue<float>(KeyMinValue, reader.minValue(_variable));
outputMetadata.setValue<float>(KeyMaxValue, reader.maxValue(_variable));
outputMetadata.setValue<float>(
KeyMinValue,
static_cast<float>(reader.minValue(_variable))
);
outputMetadata.setValue<float>(
KeyMaxValue,
static_cast<float>(reader.maxValue(_variable))
);
ghoul::DictionaryLuaFormatter formatter;
std::string metadataString = formatter.format(outputMetadata);

View File

@@ -170,7 +170,7 @@ void AtlasManager::addToAtlas(int firstBrickIndex, int lastBrickIndex, float* ma
unsigned int atlasCoords = _freeAtlasCoords.back();
_freeAtlasCoords.pop_back();
int level = _nOtLevels - floor(log((7.0 * (float(brickIndex % _nOtNodes)) + 1.0))/log(8)) - 1;
assert(atlasCoords <= 0x0FFFFFFF);
ghoul_assert(atlasCoords <= 0x0FFFFFFF, "@MISSING");
unsigned int atlasData = (level << 28) + atlasCoords;
_brickMap.insert(std::pair<unsigned int, unsigned int>(brickIndex, atlasData));
_nStreamedBricks++;

View File

@@ -358,8 +358,8 @@ bool LocalTfBrickSelector::calculateBrickErrors() {
for (int i = 0; i < gradients.size(); i++) {
float x = (i + 0.5f) / tfWidth;
float sample = histogram->interpolate(x);
assert(sample >= 0);
assert(gradients[i] >= 0);
ghoul_assert(sample >= 0, "@MISSING");
ghoul_assert(gradients[i] >= 0, "@MISSING");
error += sample * gradients[i];
}
_brickErrors[brickIndex].spatial = error;
@@ -375,8 +375,8 @@ bool LocalTfBrickSelector::calculateBrickErrors() {
for (int i = 0; i < gradients.size(); i++) {
float x = (i + 0.5f) / tfWidth;
float sample = histogram->interpolate(x);
assert(sample >= 0);
assert(gradients[i] >= 0);
ghoul_assert(sample >= 0, "@MISSING");
ghoul_assert(gradients[i] >= 0, "@MISSING");
error += sample * gradients[i];
}
_brickErrors[brickIndex].temporal = error;

View File

@@ -187,8 +187,6 @@ RenderableMultiresVolume::RenderableMultiresVolume (const ghoul::Dictionary& dic
, _rotation(RotationInfo, glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f), glm::vec3(6.28f))
{
std::string name;
//bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
//assert(success);
_filename = "";
bool success = dictionary.getValue(KeyDataSource, _filename);
@@ -513,7 +511,8 @@ bool RenderableMultiresVolume::initializeSelector() {
} else {
// Build histograms from tsp file.
LWARNING("Failed to open " << cacheFilename);
if (success &= _errorHistogramManager->buildHistograms(nHistograms)) {
success &= _errorHistogramManager->buildHistograms(nHistograms);
if (success) {
LINFO("Writing cache to " << cacheFilename);
_errorHistogramManager->saveToFile(cacheFilename);
}
@@ -539,7 +538,11 @@ bool RenderableMultiresVolume::initializeSelector() {
} else {
// Build histograms from tsp file.
LWARNING("Failed to open " << cacheFilename);
if (success &= _histogramManager->buildHistograms(_tsp.get(), nHistograms)) {
success &= _histogramManager->buildHistograms(
_tsp.get(),
nHistograms
);
if (success) {
LINFO("Writing cache to " << cacheFilename);
_histogramManager->saveToFile(cacheFilename);
}
@@ -565,7 +568,8 @@ bool RenderableMultiresVolume::initializeSelector() {
} else {
// Build histograms from tsp file.
LWARNING("Failed to open " << cacheFilename);
if (success &= _localErrorHistogramManager->buildHistograms(nHistograms)) {
success &= _localErrorHistogramManager->buildHistograms(nHistograms);
if (success) {
LINFO("Writing cache to " << cacheFilename);
_localErrorHistogramManager->saveToFile(cacheFilename);
}
@@ -678,7 +682,7 @@ void RenderableMultiresVolume::update(const UpdateData& data) {
}
else if (_useGlobalTime) {
double t = (_time - _startTime) / (_endTime - _startTime);
currentTimestep = t * numTimesteps;
currentTimestep = static_cast<int>(t * numTimesteps);
visible = currentTimestep >= 0 && currentTimestep < numTimesteps;
}
else {

View File

@@ -311,7 +311,7 @@ bool SimpleTfBrickSelector::calculateBrickImportances() {
float x = static_cast<float>(i) / static_cast<float>(tfWidth);
float sample = histogram->interpolate(x);
assert(sample >= 0);
ghoul_assert(sample >= 0, "@MISSING");
dotProduct += sample * tf->sample(i).w;
}
_brickImportances[brickIndex] = dotProduct;

View File

@@ -367,8 +367,8 @@ bool TfBrickSelector::calculateBrickErrors() {
for (int i = 0; i < gradients.size(); i++) {
float x = (i + 0.5f) / tfWidth;
float sample = histogram->interpolate(x);
assert(sample >= 0);
assert(gradients[i] >= 0);
ghoul_assert(sample >= 0, "@MISSING");
ghoul_assert(gradients[i] >= 0, "@MISSING");
error += sample * gradients[i];
}
_brickErrors[brickIndex] = error;

View File

@@ -360,7 +360,6 @@ void TouchInteraction::directControl(const std::vector<TuioCursor>& list) {
dvec3 centerPos = ptr->node->worldPosition();
dvec3 directionToCenter = normalize(centerPos - camPos);
dvec3 centerToCamera = camPos - centerPos;
dvec3 lookUp = ptr->camera->lookUpVectorWorldSpace();
dvec3 camDirection = ptr->camera->viewDirectionWorldSpace();
@@ -386,6 +385,8 @@ void TouchInteraction::directControl(const std::vector<TuioCursor>& list) {
{ // Orbit (global rotation)
dvec3 eulerAngles(q[1], q[0], 0);
dquat rotationDiffCamSpace = dquat(eulerAngles);
dvec3 centerToCamera = camPos - centerPos;
dquat rotationDiffWorldSpace =
globalCamRot * rotationDiffCamSpace * inverse(globalCamRot);
@@ -393,11 +394,11 @@ void TouchInteraction::directControl(const std::vector<TuioCursor>& list) {
centerToCamera * rotationDiffWorldSpace - centerToCamera;
camPos += rotationDiffVec3;
dvec3 centerToCamera = camPos - centerPos;
centerToCamera = camPos - centerPos;
directionToCenter = normalize(-centerToCamera);
dvec3 lookUpWhenFacingCenter =
globalCamRot * dvec3(ptr->camera->lookUpVectorCameraSpace());
dmat4 lookAtMat = lookAt(
lookAtMat = lookAt(
dvec3(0, 0, 0),
directionToCenter,
lookUpWhenFacingCenter);
@@ -757,12 +758,12 @@ int TouchInteraction::interpretInteraction(const std::vector<TuioCursor>& list,
double minDiff = 1000;
int id = 0;
for (const TuioCursor& c : list) {
TuioPoint point = std::find_if(
TuioPoint itPoint = std::find_if(
lastProcessed.begin(),
lastProcessed.end(),
[&c](const Point& p) { return p.first == c.getSessionID(); }
)->second;
double diff = c.getX() - point.getX() + c.getY() - point.getY();
double diff = c.getX() - itPoint.getX() + c.getY() - itPoint.getY();
if (!c.isMoving()) {
diff = minDiff = 0.0;
id = c.getSessionID();
@@ -784,8 +785,14 @@ int TouchInteraction::interpretInteraction(const std::vector<TuioCursor>& list,
[&c](const Point& p) { return p.first == c.getSessionID(); }
)->second;
double res = 0.0;
float lastAngle = point.getAngle(_centroid.x, _centroid.y);
float currentAngle = c.getAngle(_centroid.x, _centroid.y);
float lastAngle = point.getAngle(
static_cast<float>(_centroid.x),
static_cast<float>(_centroid.y)
);
float currentAngle = c.getAngle(
static_cast<float>(_centroid.x),
static_cast<float>(_centroid.y)
);
if (lastAngle > currentAngle + 1.5 * M_PI) {
res = currentAngle + (2 * M_PI - lastAngle);
}
@@ -811,7 +818,9 @@ int TouchInteraction::interpretInteraction(const std::vector<TuioCursor>& list,
return ROT;
}
else {
float avgDistance = std::abs(dist - lastDist) / list.at(0).getMotionSpeed();
float avgDistance = static_cast<float>(
std::abs(dist - lastDist) / list.at(0).getMotionSpeed()
);
// if average distance between 3 fingers are constant we have panning
if (avgDistance < _interpretPan && list.size() == 3) {
return PAN;
@@ -854,7 +863,10 @@ void TouchInteraction::computeVelocities(const std::vector<TuioCursor>& list,
list.end(),
0.0,
[&](double d, const TuioCursor& c) {
return d + c.getDistance(_centroid.x, _centroid.y);
return d + c.getDistance(
static_cast<float>(_centroid.x),
static_cast<float>(_centroid.y)
);
}
) / list.size();
double lastDistance = std::accumulate(
@@ -862,7 +874,10 @@ void TouchInteraction::computeVelocities(const std::vector<TuioCursor>& list,
lastProcessed.end(),
0.0f,
[&](float d, const Point& p) {
return d + p.second.getDistance(_centroid.x, _centroid.y);
return d + p.second.getDistance(
static_cast<float>(_centroid.x),
static_cast<float>(_centroid.y)
);
}
) / lastProcessed.size();
@@ -886,8 +901,14 @@ void TouchInteraction::computeVelocities(const std::vector<TuioCursor>& list,
[&c](const Point& p) { return p.first == c.getSessionID(); }
)->second;
double res = diff;
double lastAngle = point.getAngle(_centroid.x, _centroid.y);
double currentAngle = c.getAngle(_centroid.x, _centroid.y);
double lastAngle = point.getAngle(
static_cast<float>(_centroid.x),
static_cast<float>(_centroid.y)
);
double currentAngle = c.getAngle(
static_cast<float>(_centroid.x),
static_cast<float>(_centroid.y)
);
// if's used to set angles 359 + 1 = 0 and 0 - 1 = 359
if (lastAngle > currentAngle + 1.5 * M_PI) {
res += currentAngle + (2 * M_PI - lastAngle);
@@ -1009,8 +1030,8 @@ void TouchInteraction::step(double dt) {
centerToCamera;
camPos += rotationDiffVec3;
dvec3 centerToCamera = camPos - centerPos;
directionToCenter = normalize(-centerToCamera);
dvec3 centerToCam = camPos - centerPos;
directionToCenter = normalize(-centerToCam);
dvec3 lookUpWhenFacingCenter = globalCamRot *
dvec3(_camera->lookUpVectorCameraSpace());
dmat4 lookAtMat = lookAt(
@@ -1021,11 +1042,11 @@ void TouchInteraction::step(double dt) {
}
{ // Zooming
centerToBoundingSphere = -directionToCenter * boundingSphere;
dvec3 centerToCamera = camPos - centerPos;
double distToSurface = length(centerToCamera - centerToBoundingSphere);
dvec3 centerToCam = camPos - centerPos;
double distToSurface = length(centerToCam - centerToBoundingSphere);
if (length(_vel.zoom * dt) < distToSurface &&
length(centerToCamera + directionToCenter*_vel.zoom * dt) >
length(centerToCam + directionToCenter*_vel.zoom * dt) >
length(centerToBoundingSphere))
{
camPos += directionToCenter * _vel.zoom * dt;
@@ -1054,12 +1075,12 @@ void TouchInteraction::unitTest() {
// set _selected pos and new pos (on screen)
std::vector<TuioCursor> lastFrame = {
{ TuioCursor(0, 10, 0.45, 0.4) }, // session id, cursor id, x, y
{ TuioCursor(1, 11, 0.55, 0.6) }
{ TuioCursor(0, 10, 0.45f, 0.4f) }, // session id, cursor id, x, y
{ TuioCursor(1, 11, 0.55f, 0.6f) }
};
std::vector<TuioCursor> currFrame = {
{ TuioCursor(0, 10, 0.2, 0.6) }, // (-0.6,-0.2)
{ TuioCursor(1, 11, 0.8, 0.4) } // (0.6, 0.2)
{ TuioCursor(0, 10, 0.2f, 0.6f) }, // (-0.6,-0.2)
{ TuioCursor(1, 11, 0.8f, 0.4f) } // (0.6, 0.2)
};
// call update
@@ -1098,7 +1119,7 @@ void TouchInteraction::decelerate(double dt) {
double frequency = 1.0 / _deceleratesPerSecond;
// Number of times velocities should decelerate, depending on chosen frequency and
// time slack over from last frame
int times = (dt + _timeSlack) / frequency;
int times = static_cast<int>((dt + _timeSlack) / frequency);
// Save the new time slack for the next frame
_timeSlack = fmod((dt + _timeSlack), frequency);

View File

@@ -68,7 +68,7 @@ void RawVolumeWriter<VoxelType>::write(
std::vector<VoxelType> buffer(_bufferSize);
std::ofstream file(_path, std::ios::binary);
int nChunks = size / _bufferSize;
int nChunks = static_cast<int>(size / _bufferSize);
if (size % _bufferSize > 0) {
nChunks++;
}

View File

@@ -157,20 +157,20 @@ RenderableTimeVaryingVolume::RenderableTimeVaryingVolume(
const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _clipPlanes(nullptr)
, _stepSize(StepSizeInfo, 0.02, 0.01, 1)
, _stepSize(StepSizeInfo, 0.02f, 0.001f, 1.f)
, _gridType(GridTypeInfo, properties::OptionProperty::DisplayType::Dropdown)
, _secondsBefore(SecondsBeforeInfo, 0.0, 0.01, SecondsInOneDay)
, _secondsAfter(SecondsAfterInfo, 0.0, 0.01, SecondsInOneDay)
, _secondsBefore(SecondsBeforeInfo, 0.f, 0.01f, SecondsInOneDay)
, _secondsAfter(SecondsAfterInfo, 0.f, 0.01f, SecondsInOneDay)
, _sourceDirectory(SourceDirectoryInfo)
, _transferFunctionPath(TransferFunctionInfo)
, _triggerTimeJump(TriggerTimeJumpInfo)
, _jumpToTimestep(JumpToTimestepInfo, 0, 0, 256)
, _currentTimestep(CurrentTimeStepInfo, 0, 0, 256)
, _opacity(OpacityInfo, 10.0f, 0.0f, 50.0f)
, _rNormalization(rNormalizationInfo, 0.0f, 0.0f, 2.0f)
, _rUpperBound(rUpperBoundInfo, 1.0f, 0.0f, 2.0f)
, _lowerValueBound(lowerValueBoundInfo, 0.0f, 0.0f, 1000000.0f)
, _upperValueBound(upperValueBoundInfo, 0.0f, 0.0f, 1000000.0f)
, _opacity(OpacityInfo, 10.f, 0.f, 500.f)
, _rNormalization(rNormalizationInfo, 0.f, 0.f, 2.f)
, _rUpperBound(rUpperBoundInfo, 1.f, 0.f, 2.f)
, _lowerValueBound(lowerValueBoundInfo, 0.f, 0.f, 1000000.f)
, _upperValueBound(upperValueBoundInfo, 0.f, 0.f, 1000000.f)
, _raycaster(nullptr)
, _transferFunction(nullptr)
{
@@ -192,6 +192,10 @@ RenderableTimeVaryingVolume::RenderableTimeVaryingVolume(
});
_gridType.setValue(static_cast<int>(volume::VolumeGridType::Cartesian));
if (dictionary.hasValue<float>(KeyStepSize)) {
_stepSize = dictionary.value<float>(KeyStepSize);
}
if (dictionary.hasValue<float>(KeySecondsBefore)) {
_secondsBefore = dictionary.value<float>(KeySecondsBefore);
}
@@ -296,7 +300,7 @@ void RenderableTimeVaryingVolume::initializeGL() {
});
const int lastTimestep = (_volumeTimesteps.size() > 0) ?
(_volumeTimesteps.size() - 1) :
static_cast<int>(_volumeTimesteps.size() - 1) :
0;
_currentTimestep.setMaxValue(lastTimestep);
_jumpToTimestep.setMaxValue(lastTimestep);
@@ -326,6 +330,12 @@ void RenderableTimeVaryingVolume::initializeGL() {
VolumeGridType::Cartesian
);
});
_transferFunctionPath.onChange([this] {
_transferFunction =
std::make_shared<TransferFunction>(_transferFunctionPath);
_raycaster->setTransferFunction(_transferFunction);
});
}
void RenderableTimeVaryingVolume::loadTimestepMetadata(const std::string& path) {
@@ -425,7 +435,8 @@ void RenderableTimeVaryingVolume::jumpToTimestep(int target) {
OsEng.timeManager().setTimeNextFrame(t->time);
}
void RenderableTimeVaryingVolume::update(const UpdateData& data) {
void RenderableTimeVaryingVolume::update(const UpdateData&) {
_transferFunction->update();
if (_raycaster) {
Timestep* t = currentTimestep();
_currentTimestep = timestepIndex(t);

View File

@@ -22,8 +22,8 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_VOLUME___RENDERABLEKAMELEONVOLUME___H__
#define __OPENSPACE_MODULE_VOLUME___RENDERABLEKAMELEONVOLUME___H__
#ifndef __OPENSPACE_MODULE_VOLUME___RENDERABLETIMEVARYINGVOLUME___H__
#define __OPENSPACE_MODULE_VOLUME___RENDERABLETIMEVARYINGVOLUME___H__
#include <openspace/rendering/renderable.h>
@@ -106,4 +106,4 @@ private:
} // namespace volume
} // namespace openspace
#endif // __OPENSPACE_MODULE_KAMELEONVOLUME___RENDERABLEKAMELEONVOLUME___H__
#endif // __OPENSPACE_MODULE_VOLUME___RENDERABLETIMEVARYINGVOLUME___H__

View File

@@ -43,6 +43,8 @@ public:
TextureSliceVolumeReader(std::vector<std::string> paths, size_t sliceCacheMaxItems,
size_t sliceCacheSize);
virtual ~TextureSliceVolumeReader() = default;
VoxelType get(const glm::ivec3& coordinates) const;
virtual glm::ivec3 dimensions() const;
void setPaths(const std::vector<std::string> paths);

View File

@@ -56,20 +56,20 @@ typename VolumeType::VoxelType VolumeSampler<VolumeType>::sample(
for (int y = minCoords.y; y <= maxCoords.y; y++) {
for (int x = minCoords.x; x <= maxCoords.x; x++) {
glm::ivec3 sampleCoords = glm::ivec3(x, y, z);
float filterCoefficient = 1.0;
float filterCoefficient = 1.f;
if (x == minCoords.x) {
filterCoefficient *= (1.0 - t.x);
filterCoefficient *= (1.f - t.x);
} else if (x == maxCoords.x) {
filterCoefficient *= t.x;
}
if (y == minCoords.y) {
filterCoefficient *= (1.0 - t.y);
filterCoefficient *= (1.f - t.y);
} else if (y == maxCoords.y) {
filterCoefficient *= t.y;
}
if (z == minCoords.z) {
filterCoefficient *= (1.0 - t.z);
filterCoefficient *= (1.f - t.z);
} else if (z == maxCoords.z) {
filterCoefficient *= t.z;
}

View File

@@ -149,6 +149,7 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/util/blockplaneintersectiongeometry.cpp
${OPENSPACE_BASE_DIR}/src/util/boxgeometry.cpp
${OPENSPACE_BASE_DIR}/src/util/camera.cpp
${OPENSPACE_BASE_DIR}/src/util/distanceconversion.cpp
${OPENSPACE_BASE_DIR}/src/util/factorymanager.cpp
${OPENSPACE_BASE_DIR}/src/util/keys.cpp
${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp
@@ -165,6 +166,7 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/util/taskloader.cpp
${OPENSPACE_BASE_DIR}/src/util/threadpool.cpp
${OPENSPACE_BASE_DIR}/src/util/time.cpp
${OPENSPACE_BASE_DIR}/src/util/timeconversion.cpp
${OPENSPACE_BASE_DIR}/src/util/timeline.cpp
${OPENSPACE_BASE_DIR}/src/util/timemanager.cpp
${OPENSPACE_BASE_DIR}/src/util/time_lua.inl
@@ -318,6 +320,8 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/util/concurrentjobmanager.inl
${OPENSPACE_BASE_DIR}/include/openspace/util/concurrentqueue.h
${OPENSPACE_BASE_DIR}/include/openspace/util/concurrentqueue.inl
${OPENSPACE_BASE_DIR}/include/openspace/util/distanceconstants.h
${OPENSPACE_BASE_DIR}/include/openspace/util/distanceconversion.h
${OPENSPACE_BASE_DIR}/include/openspace/util/factorymanager.h
${OPENSPACE_BASE_DIR}/include/openspace/util/factorymanager.inl
${OPENSPACE_BASE_DIR}/include/openspace/util/keys.h
@@ -334,6 +338,7 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/util/task.h
${OPENSPACE_BASE_DIR}/include/openspace/util/taskloader.h
${OPENSPACE_BASE_DIR}/include/openspace/util/time.h
${OPENSPACE_BASE_DIR}/include/openspace/util/timeconversion.h
${OPENSPACE_BASE_DIR}/include/openspace/util/timeline.h
${OPENSPACE_BASE_DIR}/include/openspace/util/timeline.inl
${OPENSPACE_BASE_DIR}/include/openspace/util/timemanager.h

View File

@@ -421,6 +421,8 @@ void OpenSpaceEngine::destroy() {
_engine->_syncEngine->removeSyncables(_engine->_renderEngine->getSyncables());
_engine->_syncEngine->removeSyncable(_engine->_scriptEngine.get());
_engine->_renderEngine->deinitializeGL();
_engine->_moduleEngine->deinitialize();
_engine->_console->deinitialize();

View File

@@ -115,9 +115,9 @@ uint32_t SGCTWindowWrapper::mouseButtons(int maxNumber) const {
uint32_t result = 0;
for (int i = 0; i < maxNumber; ++i) {
bool button = (sgct::Engine::instance()->getMouseButton(id, i) != 0);
if (button)
if (button) {
result |= (1 << i);
}
}
return result;
}
@@ -269,4 +269,12 @@ void SGCTWindowWrapper::swapBuffer() const {
glfwPollEvents();
}
int SGCTWindowWrapper::nWindows() const {
return static_cast<int>(sgct::Engine::instance()->getNumberOfWindows());
}
int SGCTWindowWrapper::currentWindowId() const {
return sgct::Engine::instance()->getCurrentWindowPtr()->getId();
}
} // namespace openspace

View File

@@ -186,4 +186,13 @@ void WindowWrapper::takeScreenshot(bool) const {}
void WindowWrapper::swapBuffer() const {}
int WindowWrapper::nWindows() const {
return 0;
}
int WindowWrapper::currentWindowId() const {
return 0;
}
} // namespace openspace

View File

@@ -103,7 +103,7 @@ OrbitalNavigator::Friction::Friction()
OrbitalNavigator::OrbitalNavigator()
: properties::PropertyOwner({ "OrbitalNavigator" })
, _followFocusNodeRotationDistance(FollowFocusNodeInfo, 2.0f, 0.0f, 10.f)
, _followFocusNodeRotationDistance(FollowFocusNodeInfo, 5.0f, 0.0f, 20.f)
, _minimumAllowedDistance(MinimumDistanceInfo, 10.0f, 0.0f, 10000.f)
, _sensitivity(SensitivityInfo, 20.0f, 1.0f, 50.f)
, _mouseStates(_sensitivity * pow(10.0, -4), 1 / (_friction.friction + 0.0000001))

View File

@@ -75,6 +75,8 @@ NSArray* focusIdentifiers;
- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
(void)touchBar;
if ([identifier isEqualToString:pauseResultId]) {
NSButton* button = [NSButton
buttonWithTitle:NSLocalizedString(
@@ -144,13 +146,13 @@ NSArray* focusIdentifiers;
openspace::scripting::ScriptEngine::RemoteScripting::Yes
);
NSButton* button = (NSButton*)sender;
NSButton* button = static_cast<NSButton*>(sender);
// This check is inverted since the togglePause script has not run yet
[button setTitle: OsEng.timeManager().time().paused() ? @"Pause" : @"Resume"];
}
- (void)focusObjectAction:(id)sender {
NSButton* button = (NSButton*)sender;
NSButton* button = static_cast<NSButton*>(sender);
NSString* title = [button title];
@@ -162,6 +164,7 @@ NSArray* focusIdentifiers;
}
- (void)guiButtonAction:(id)sender {
(void)sender;
OsEng.scriptEngine().queueScript(
"openspace.setPropertyValue('Global Properties.ImGUI.Main.Enabled', \
not openspace.getPropertyValue('Global Properties.ImGUI.Main.Enabled'));",

View File

@@ -30,109 +30,100 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat2x2 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat2x2(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat2x2 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat2x2 fromStringConversion(std::string val, bool& success) {
glm::dmat2x2 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat2x2>::value * ghoul::glm_cols<glm::dmat2x2>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat2x2::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat2x2 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0),
glm::dmat2x2(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat2x2(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat2x2(
0.01, 0.01,
0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x2),
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x2),
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x2),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat2Property,
glm::dmat2x2,
glm::dmat2x2(0),
glm::dmat2x2(nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()),
glm::dmat2x2(nl::max(), nl::max(), nl::max(), nl::max()),
glm::dmat2x2(0.01, 0.01, 0.01, 0.01),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,113 +30,108 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat2x3 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat2x3 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat2x3(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat2x3 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat2x3 fromStringConversion(std::string val, bool& success) {
glm::dmat2x3 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat2x3>::value * ghoul::glm_cols<glm::dmat2x3>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat2x3::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat2x3 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0),
glm::dmat2x3(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat2x3(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat2x3(
0.01, 0.01, 0.01,
0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x3),
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x3),
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x3),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat2x3Property,
glm::dmat2x3,
glm::dmat2x3(0),
glm::dmat2x3(
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest()
),
glm::dmat2x3(
nl::max(), nl::max(),
nl::max(), nl::max(),
nl::max(), nl::max()
),
glm::dmat2x3(0.01, 0.01, 0.01, 0.01, 0.01, 0.01),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,117 +30,110 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat2x4 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat2x4 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat2x4(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat2x4 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat2x4 fromStringConversion(std::string val, bool& success) {
glm::dmat2x4 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat2x4>::value * ghoul::glm_cols<glm::dmat2x4>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat2x4::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat2x4 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0),
glm::dmat2x4(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat2x4(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat2x4(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x4),
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x4),
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x4),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat2x4Property,
glm::dmat2x4,
glm::dmat2x4(0),
glm::dmat2x4(
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest()
),
glm::dmat2x4(
nl::max(), nl::max(),
nl::max(), nl::max(),
nl::max(), nl::max(),
nl::max(), nl::max()
),
glm::dmat2x4(0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,120 +30,113 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat3x3 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat3x3(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat3x3 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat3x3 fromStringConversion(std::string val, bool& success) {
glm::dmat3x3 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat3x3>::value * ghoul::glm_cols<glm::dmat3x3>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat3x3::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat3x3 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0),
glm::dmat3x3(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat3x3(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat3x3(
0.01, 0.01, 0.01,
0.01, 0.01, 0.01,
0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x3),
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x3),
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x3),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat3Property,
glm::dmat3x3,
glm::dmat3x3(0),
glm::dmat3x3(
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest()
),
glm::dmat3x3(
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max()
),
glm::dmat3x3(
0.01, 0.01, 0.01,
0.01, 0.01, 0.01,
0.01, 0.01, 0.01
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,113 +30,109 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat3x2 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat3x2 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat3x2(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat3x2 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat3x2 fromStringConversion(std::string val, bool& success) {
glm::dmat3x2 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat3x2>::value * ghoul::glm_cols<glm::dmat3x2>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat3x2::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat3x2 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0),
glm::dmat3x2(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat3x2(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat3x2(
0.01, 0.01, 0.01,
0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x2),
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x2),
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x2),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat3x2Property,
glm::dmat3x2,
glm::dmat3x2(0),
glm::dmat3x2(
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest()
),
glm::dmat3x2(
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max()
),
glm::dmat3x2(
0.01, 0.01, 0.01,
0.01, 0.01, 0.01
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,126 +30,116 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat3x4 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat3x4 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat3x4(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat3x4 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat3x4 fromStringConversion(std::string val, bool& success) {
glm::dmat3x4 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat3x4>::value * ghoul::glm_cols<glm::dmat3x4>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat3x4::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat3x4 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0),
glm::dmat3x4(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat3x4(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat3x4(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x4),
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x4),
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x4),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat3x4Property,
glm::dmat3x4,
glm::dmat3x4(0),
glm::dmat3x4(
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest()
),
glm::dmat3x4(
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max()
),
glm::dmat3x4(
0.01, 0.01, 0.01,
0.01, 0.01, 0.01,
0.01, 0.01, 0.01,
0.01, 0.01, 0.01
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,135 +30,115 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat4x4 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat4x4(0);
}
else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat4x4 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat4x4 fromStringConversion(std::string val, bool& success) {
glm::dmat4x4 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat4x4>::value * ghoul::glm_cols<glm::dmat4x4>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat4x4::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat4x4 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0),
glm::dmat4x4(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat4x4(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat4x4(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x4),
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x4),
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x4),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat4Property,
glm::dmat4x4,
glm::dmat4x4(0),
glm::dmat4x4(
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
),
glm::dmat4x4(
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max()
),
glm::dmat4x4(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,117 +30,108 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat4x2 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat4x2 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat4x2(0);
} else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat4x2 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat4x2 fromStringConversion(std::string val, bool& success) {
glm::dmat4x2 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat4x2>::value * ghoul::glm_cols<glm::dmat4x2>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat4x2::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat4x2 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0),
glm::dmat4x2(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat4x2(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat4x2(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x2),
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x2),
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x2),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat4x2Property,
glm::dmat4x2,
glm::dmat4x2(0),
glm::dmat4x2(
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
),
glm::dmat4x2(
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max()
),
glm::dmat4x2(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,126 +30,111 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::dmat4x3 fromLuaConversion(lua_State* state, bool& success) {
glm::dmat4x3 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::dmat4x3(0);
} else {
result[i][j] = lua_tonumber(state, -1);
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::dmat4x3 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
lua_pushnumber(state, value[i][j]);
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::dmat4x3 fromStringConversion(std::string val, bool& success) {
glm::dmat4x3 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::dmat4x3>::value * ghoul::glm_cols<glm::dmat4x3>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
std::stringstream s(tokens[number]);
glm::dmat4x3::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::dmat4x3 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<double>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0),
glm::dmat4x3(
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest(),
numeric_limits<double>::lowest()
),
glm::dmat4x3(
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max(),
numeric_limits<double>::max()
),
glm::dmat4x3(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x3),
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3),
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x3),
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x3),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
DMat4x3Property,
glm::dmat4x3,
glm::dmat4x3(0),
glm::dmat4x3(
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
),
glm::dmat4x3(
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max()
),
glm::dmat4x3(
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01, 0.01
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,109 +30,109 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) {
glm::mat2x2 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat2x2(0);
} else {
result[i][j]
= static_cast<glm::mat2x2::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat2x2 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat2x2 fromStringConversion(std::string val, bool& success) {
glm::mat2x2 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat2x2>::value * ghoul::glm_cols<glm::mat2x2>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat2x2::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat2x2 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0),
glm::mat2x2(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat2x2(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat2x2(
0.01f, 0.01f,
0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x2),
DEFAULT_TO_LUA_LAMBDA(glm::mat2x2),
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x2),
DEFAULT_TO_STRING_LAMBDA(glm::mat2x2),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat2Property,
glm::mat2x2,
glm::mat2x2(0),
glm::mat2x2(
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest()
),
glm::mat2x2(
nl::max(), nl::max(),
nl::max(), nl::max()
),
glm::mat2x2(
0.01f, 0.01f,
0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -32,111 +32,112 @@
using std::numeric_limits;
namespace {
glm::mat2x3 fromLuaConversion(lua_State* state, bool& success) {
glm::mat2x3 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat2x3(0);
}
else {
result[i][j]
= static_cast<glm::mat2x3::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat2x3 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat2x3 fromStringConversion(std::string val, bool& success) {
glm::mat2x3 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat2x3>::value * ghoul::glm_cols<glm::mat2x3>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat2x3::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat2x3 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0),
glm::mat2x3(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat2x3(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat2x3(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x3),
DEFAULT_TO_LUA_LAMBDA(glm::mat2x3),
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x3),
DEFAULT_TO_STRING_LAMBDA(glm::mat2x3),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat2x3Property,
glm::mat2x3,
glm::mat2x3(0),
glm::mat2x3(
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest()
),
glm::mat2x3(
nl::max(), nl::max(),
nl::max(), nl::max(),
nl::max(), nl::max()
),
glm::mat2x3(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,117 +30,116 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat2x4 fromLuaConversion(lua_State* state, bool& success) {
glm::mat2x4 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat2x4(0);
}
else {
result[i][j]
= static_cast<glm::mat2x4::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat2x4 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat2x4 fromStringConversion(std::string val, bool& success) {
glm::mat2x4 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat2x4>::value * ghoul::glm_cols<glm::mat2x4>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat2x4::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat2x4 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0),
glm::mat2x4(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat2x4(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat2x4(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x4),
DEFAULT_TO_LUA_LAMBDA(glm::mat2x4),
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x4),
DEFAULT_TO_STRING_LAMBDA(glm::mat2x4),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat2x4Property,
glm::mat2x4,
glm::mat2x4(0),
glm::mat2x4(
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest()
),
glm::mat2x4(
nl::max(), nl::max(),
nl::max(), nl::max(),
nl::max(), nl::max(),
nl::max(), nl::max()
),
glm::mat2x4(
0.01f, 0.01f,
0.01f, 0.01f,
0.01f, 0.01f,
0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,120 +30,112 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) {
glm::mat3x3 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat3x3(0);
} else {
result[i][j]
= static_cast<glm::mat3x3::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat3x3 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat3x3 fromStringConversion(std::string val, bool& success) {
glm::mat3x3 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat3x3>::value * ghoul::glm_cols<glm::mat3x3>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat3x3::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat3x3 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0),
glm::mat3x3(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat3x3(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat3x3(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x3),
DEFAULT_TO_LUA_LAMBDA(glm::mat3x3),
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x3),
DEFAULT_TO_STRING_LAMBDA(glm::mat3x3),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat3Property,
glm::mat3x3,
glm::mat3x3(0),
glm::mat3x3(
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest()
),
glm::mat3x3(
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max()
),
glm::mat3x3(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,113 +30,109 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat3x2 fromLuaConversion(lua_State* state, bool& success) {
glm::mat3x2 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat3x2(0);
} else {
result[i][j]
= static_cast<glm::mat3x2::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat3x2 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat3x2 fromStringConversion(std::string val, bool& success) {
glm::mat3x2 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat3x2>::value * ghoul::glm_cols<glm::mat3x2>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat3x2::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat3x2 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0),
glm::mat3x2(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat3x2(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat3x2(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x2),
DEFAULT_TO_LUA_LAMBDA(glm::mat3x2),
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x2),
DEFAULT_TO_STRING_LAMBDA(glm::mat3x2),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat3x2Property,
glm::mat3x2,
glm::mat3x2(0),
glm::mat3x2(
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest()
),
glm::mat3x2(
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max()
),
glm::mat3x2(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,126 +30,115 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat3x4 fromLuaConversion(lua_State* state, bool& success) {
glm::mat3x4 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat3x4(0);
} else {
result[i][j]
= static_cast<glm::mat3x4::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat3x4 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat3x4 fromStringConversion(std::string val, bool& success) {
glm::mat3x4 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat3x4>::value * ghoul::glm_cols<glm::mat3x4>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat3x4::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat3x4 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0),
glm::mat3x4(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat3x4(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat3x4(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x4),
DEFAULT_TO_LUA_LAMBDA(glm::mat3x4),
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x4),
DEFAULT_TO_STRING_LAMBDA(glm::mat3x4),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat3x4Property,
glm::mat3x4,
glm::mat3x4(0),
glm::mat3x4(
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest()
),
glm::mat3x4(
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max()
),
glm::mat3x4(
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -32,133 +32,115 @@
using std::numeric_limits;
namespace {
glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) {
glm::mat4x4 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat4x4(0);
} else {
result[i][j]
= static_cast<glm::mat4x4::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat4x4 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat4x4 fromStringConversion(std::string val, bool& success) {
glm::mat4x4 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat4x4>::value * ghoul::glm_cols<glm::mat4x4>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat4x4::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat4x4 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0),
glm::mat4x4(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat4x4(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat4x4(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x4),
DEFAULT_TO_LUA_LAMBDA(glm::mat4x4),
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x4),
DEFAULT_TO_STRING_LAMBDA(glm::mat4x4),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat4Property,
glm::mat4x4,
glm::mat4x4(0),
glm::mat4x4(
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
),
glm::mat4x4(
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max()
),
glm::mat4x4(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,117 +30,109 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat4x2 fromLuaConversion(lua_State* state, bool& success) {
glm::mat4x2 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat4x2(0);
} else {
result[i][j]
= static_cast<glm::mat4x2::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat4x2 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat4x2 fromStringConversion(std::string val, bool& success) {
glm::mat4x2 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat4x2>::value * ghoul::glm_cols<glm::mat4x2>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat4x2::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat4x2 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0),
glm::mat4x2(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat4x2(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat4x2(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x2),
DEFAULT_TO_LUA_LAMBDA(glm::mat4x2),
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x2),
DEFAULT_TO_STRING_LAMBDA(glm::mat4x2),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat4x2Property,
glm::mat4x2,
glm::mat4x2(0),
glm::mat4x2(
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
),
glm::mat4x2(
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max()
),
glm::mat4x2(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -30,126 +30,112 @@
#include <sstream>
#include <vector>
using std::numeric_limits;
namespace {
glm::mat4x3 fromLuaConversion(lua_State* state, bool& success) {
glm::mat4x3 result;
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
lua_getfield(state, -1, std::to_string(number).c_str());
if (lua_isnumber(state, -1) != 1) {
success = false;
return glm::mat4x3(0);
} else {
result[i][j]
= static_cast<glm::mat4x3::value_type>(lua_tonumber(state, -1));
lua_pop(state, 1);
++number;
}
}
}
success = true;
return result;
}
bool toLuaConversion(lua_State* state, glm::mat4x3 value) {
lua_newtable(state);
int number = 1;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
lua_setfield(state, -2, std::to_string(number).c_str());
++number;
}
}
return true;
}
glm::mat4x3 fromStringConversion(std::string val, bool& success) {
glm::mat4x3 result;
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
if (tokens.size() !=
(ghoul::glm_rows<glm::mat4x3>::value * ghoul::glm_cols<glm::mat4x3>::value))
{
success = false;
return result;
}
int number = 0;
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
std::stringstream s(tokens[number]);
glm::mat4x3::value_type v;
s >> v;
if (s.fail()) {
success = false;
return result;
}
else {
result[i][j] = v;
++number;
}
}
}
success = true;
return result;
}
bool toStringConversion(std::string& outValue, glm::mat4x3 inValue) {
outValue = "";
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
outValue += std::to_string(inValue[i][j]) + ",";
}
outValue.pop_back();
}
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
return __TYPE__(0); \
} else { \
result[i][j] \
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
lua_pop(state, 1); \
++number; \
} \
} \
} \
success = true; \
return result; \
}
using nl = std::numeric_limits<float>;
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
} \
} \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
[](std::string v, bool& success) -> __TYPE__ { \
__TYPE__ result; \
std::vector<std::string> tokens = ghoul::tokenizeString(v, ','); \
if (tokens.size() != \
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
{ \
success = false; \
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
if (s.fail()) { \
success = false; \
return result; \
} \
else { \
result[i][j] = v; \
++number; \
} \
} \
} \
success = true; \
return result; \
}
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \
} \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0),
glm::mat4x3(
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest(),
numeric_limits<float>::lowest()
),
glm::mat4x3(
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max(),
numeric_limits<float>::max()
),
glm::mat4x3(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x3),
DEFAULT_TO_LUA_LAMBDA(glm::mat4x3),
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x3),
DEFAULT_TO_STRING_LAMBDA(glm::mat4x3),
LUA_TTABLE)
REGISTER_NUMERICALPROPERTY_SOURCE(
Mat4x3Property,
glm::mat4x3,
glm::mat4x3(0),
glm::mat4x3(
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
),
glm::mat4x3(
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max(),
nl::max(), nl::max(), nl::max(), nl::max()
),
glm::mat4x3(
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f,
0.01f, 0.01f, 0.01f, 0.01f
),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TTABLE
)
} // namespace openspace::properties

View File

@@ -29,38 +29,53 @@
#include <limits>
#include <sstream>
namespace {
bool fromLuaConversion(lua_State* state, bool& success) {
success = (lua_isboolean(state, -1) == 1);
if (success) {
return lua_toboolean(state, -1) == 1;
}
else {
return false;
}
}
bool toLuaConversion(lua_State* state, bool value) {
lua_pushboolean(state, value);
return true;
}
bool fromStringConversion(std::string val, bool& success) {
std::stringstream s(val);
bool v;
s >> v;
success = !s.fail();
if (success) {
return v;
}
else {
throw ghoul::RuntimeError("Conversion error for string: " + val);
}
}
bool toStringConversion(std::string& outValue, bool inValue) {
outValue = inValue ? "true" : "false";
return true;
}
} // namespace
namespace openspace::properties {
REGISTER_TEMPLATEPROPERTY_SOURCE(BoolProperty, bool, false,
[](lua_State* state, bool& success) -> bool {
success = (lua_isboolean(state, -1) == 1);
if (success) {
return lua_toboolean(state, -1) == 1;
}
else {
return false;
}
},
[](lua_State* state, bool value) -> bool {
lua_pushboolean(state, value);
return true;
},
[](std::string value, bool& success) -> bool {
std::stringstream s(value);
bool v;
s >> v;
success = !s.fail();
if (success) {
return v;
}
else {
throw ghoul::RuntimeError("Conversion error for string: " + value);
}
},
[](std::string& outValue, bool inValue) -> bool {
outValue = inValue ? "true" : "false";
return true;
},
REGISTER_TEMPLATEPROPERTY_SOURCE(
BoolProperty,
bool,
false,
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TBOOLEAN
)

View File

@@ -29,54 +29,57 @@
#include <limits>
#include <sstream>
using std::numeric_limits;
namespace {
char fromLuaConversion(lua_State* state, bool& success) {
success = (lua_isnumber(state, -1) == 1);
if (success) {
return static_cast<char>(lua_tonumber(state, -1));
}
else {
return char(0);
}
}
bool toLuaConversion(lua_State* state, char value) {
lua_pushnumber(state, static_cast<lua_Number>(value));
return true;
}
char fromStringConversion(std::string val, bool& success) {
std::stringstream s(val);
char v;
s >> v;
success = !s.fail();
if (success) {
return v;
}
else {
throw ghoul::RuntimeError("Conversion error for string: " + val);
}
}
bool toStringConversion(std::string& outValue, char inValue) {
outValue = std::to_string(inValue);
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
[](lua_State* state, bool& success) -> TYPE { \
success = (lua_isnumber(state, -1) == 1); \
if (success) { \
return static_cast<TYPE>(lua_tonumber(state, -1)); \
} \
else { \
return DEFAULT_VALUE; \
} \
}
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
[](lua_State* state, TYPE value) -> bool { \
lua_pushnumber(state, static_cast<lua_Number>(value)); \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
[](std::string val, bool& success) -> TYPE { \
std::stringstream s(val); \
TYPE v; \
s >> v; \
success = !s.fail(); \
if (success) { \
return v; \
} \
else { \
throw ghoul::RuntimeError("Conversion error for string: " + val); \
} \
}
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
[](std::string& outValue, TYPE inValue) -> bool { \
outValue = std::to_string(inValue); \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0),
numeric_limits<char>::lowest(),
numeric_limits<char>::max(), char(1),
DEFAULT_FROM_LUA_LAMBDA(char, char(0)),
DEFAULT_TO_LUA_LAMBDA(char),
DEFAULT_FROM_STRING_LAMBDA(char, char(0)),
DEFAULT_TO_STRING_LAMBDA(char),
LUA_TNUMBER)
REGISTER_NUMERICALPROPERTY_SOURCE(
CharProperty,
char,
char(0),
std::numeric_limits<char>::lowest(),
std::numeric_limits<char>::max(),
char(1),
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TNUMBER
)
} // namespace openspace::properties

View File

@@ -29,54 +29,57 @@
#include <limits>
#include <sstream>
using std::numeric_limits;
namespace {
double fromLuaConversion(lua_State* state, bool& success) {
success = (lua_isnumber(state, -1) == 1);
if (success) {
return lua_tonumber(state, -1);
}
else {
return 0.0;
}
}
bool toLuaConversion(lua_State* state, double value) {
lua_pushnumber(state, value);
return true;
}
double fromStringConversion(std::string val, bool& success) {
std::stringstream s(val);
double v;
s >> v;
success = !s.fail();
if (success) {
return v;
}
else {
throw ghoul::RuntimeError("Conversion error for string: " + val);
}
}
bool toStringConversion(std::string& outValue, double inValue) {
outValue = std::to_string(inValue);
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
[](lua_State* state, bool& success) -> TYPE { \
success = (lua_isnumber(state, -1) == 1); \
if (success) { \
return static_cast<TYPE>(lua_tonumber(state, -1)); \
} \
else { \
return DEFAULT_VALUE; \
} \
}
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
[](lua_State* state, TYPE value) -> bool { \
lua_pushnumber(state, static_cast<lua_Number>(value)); \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
[](std::string val, bool& success) -> TYPE { \
std::stringstream s(val); \
TYPE v; \
s >> v; \
success = !s.fail(); \
if (success) { \
return v; \
} \
else { \
throw ghoul::RuntimeError("Conversion error for string: " + val); \
} \
}
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
[](std::string& outValue, TYPE inValue) -> bool { \
outValue = std::to_string(inValue); \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(DoubleProperty, double, 0.0,
numeric_limits<double>::lowest(),
numeric_limits<double>::max(), 0.01,
DEFAULT_FROM_LUA_LAMBDA(double, double(0)),
DEFAULT_TO_LUA_LAMBDA(double),
DEFAULT_FROM_STRING_LAMBDA(double, double(0)),
DEFAULT_TO_STRING_LAMBDA(double),
LUA_TNUMBER)
REGISTER_NUMERICALPROPERTY_SOURCE(
DoubleProperty,
double,
0.0,
std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::max(),
0.01,
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TNUMBER
)
} // namespace openspace::properties

View File

@@ -29,54 +29,57 @@
#include <limits>
#include <sstream>
using std::numeric_limits;
namespace {
float fromLuaConversion(lua_State* state, bool& success) {
success = (lua_isnumber(state, -1) == 1);
if (success) {
return static_cast<float>(lua_tonumber(state, -1));
}
else {
return 0.f;
}
}
bool toLuaConversion(lua_State* state, float value) {
lua_pushnumber(state, static_cast<lua_Number>(value));
return true;
}
float fromStringConversion(std::string val, bool& success) {
std::stringstream s(val);
float v;
s >> v;
success = !s.fail();
if (success) {
return v;
}
else {
throw ghoul::RuntimeError("Conversion error for string: " + val);
}
}
bool toStringConversion(std::string& outValue, float inValue) {
outValue = std::to_string(inValue);
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
[](lua_State* state, bool& success) -> TYPE { \
success = (lua_isnumber(state, -1) == 1); \
if (success) { \
return static_cast<TYPE>(lua_tonumber(state, -1)); \
} \
else { \
return DEFAULT_VALUE; \
} \
}
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
[](lua_State* state, TYPE value) -> bool { \
lua_pushnumber(state, static_cast<lua_Number>(value)); \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
[](std::string val, bool& success) -> TYPE { \
std::stringstream s(val); \
TYPE v; \
s >> v; \
success = !s.fail(); \
if (success) { \
return v; \
} \
else { \
throw ghoul::RuntimeError("Conversion error for string: " + val); \
} \
}
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
[](std::string& outValue, TYPE inValue) -> bool { \
outValue = std::to_string(inValue); \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(FloatProperty, float, 0.f,
numeric_limits<float>::lowest(),
numeric_limits<float>::max(), 0.01f,
DEFAULT_FROM_LUA_LAMBDA(float, float(0)),
DEFAULT_TO_LUA_LAMBDA(float),
DEFAULT_FROM_STRING_LAMBDA(float, float(0)),
DEFAULT_TO_STRING_LAMBDA(float),
LUA_TNUMBER)
REGISTER_NUMERICALPROPERTY_SOURCE(
FloatProperty,
float,
0.f,
std::numeric_limits<float>::lowest(),
std::numeric_limits<float>::max(),
0.01f,
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TNUMBER
)
} // namespace openspace::properties

View File

@@ -29,53 +29,57 @@
#include <limits>
#include <sstream>
using std::numeric_limits;
namespace {
int fromLuaConversion(lua_State* state, bool& success) {
success = (lua_isnumber(state, -1) == 1);
if (success) {
return static_cast<int>(lua_tonumber(state, -1));
}
else {
return 0;
}
}
bool toLuaConversion(lua_State* state, int value) {
lua_pushnumber(state, static_cast<lua_Number>(value));
return true;
}
int fromStringConversion(std::string val, bool& success) {
std::stringstream s(val);
int v;
s >> v;
success = !s.fail();
if (success) {
return v;
}
else {
throw ghoul::RuntimeError("Conversion error for string: " + val);
}
}
bool toStringConversion(std::string& outValue, int inValue) {
outValue = std::to_string(inValue);
return true;
}
} // namespace
namespace openspace::properties {
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
[](lua_State* state, bool& success) -> TYPE { \
success = (lua_isnumber(state, -1) == 1); \
if (success) { \
return static_cast<TYPE>(lua_tonumber(state, -1)); \
} \
else { \
return DEFAULT_VALUE; \
} \
}
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
[](lua_State* state, TYPE value) -> bool { \
lua_pushnumber(state, static_cast<lua_Number>(value)); \
return true; \
}
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
[](std::string val, bool& success) -> TYPE { \
std::stringstream s(val); \
TYPE v; \
s >> v; \
success = !s.fail(); \
if (success) { \
return v; \
} \
else { \
throw ghoul::RuntimeError("Conversion error for string: " + val); \
} \
}
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
[](std::string& outValue, TYPE inValue) -> bool { \
outValue = std::to_string(inValue); \
return true; \
}
REGISTER_NUMERICALPROPERTY_SOURCE(IntProperty, int, int(0), numeric_limits<int>::lowest(),
numeric_limits<int>::max(), int(1),
DEFAULT_FROM_LUA_LAMBDA(int, int(0)),
DEFAULT_TO_LUA_LAMBDA(int),
DEFAULT_FROM_STRING_LAMBDA(int, int(0)),
DEFAULT_TO_STRING_LAMBDA(int),
LUA_TNUMBER)
REGISTER_NUMERICALPROPERTY_SOURCE(
IntProperty,
int,
0,
std::numeric_limits<int>::lowest(),
std::numeric_limits<int>::max(),
1,
fromLuaConversion,
toLuaConversion,
fromStringConversion,
toStringConversion,
LUA_TNUMBER
)
} // namespace openspace::properties

Some files were not shown because too many files have changed in this diff Show More