mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 12:29:04 -06:00
Add functions to recursively parse and add color layers described in .info files
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
-- Add folders to this list that contain .info files describing HiRISE patches
|
||||
local mars_folders = {
|
||||
-- "C:/ab7512/Mars/map_datasets/HiRISE",
|
||||
}
|
||||
|
||||
function preInitialization()
|
||||
--[[
|
||||
The scripts in this function are executed after the scene is loaded but before the
|
||||
@@ -80,6 +85,11 @@ function postInitialization()
|
||||
openspace.globebrowsing.goToGeo(58.5877, 16.1924, 20000000)
|
||||
|
||||
openspace.printInfo("Done setting default values")
|
||||
|
||||
-- Add the HiRISE patches described at the top of this file
|
||||
for _, file in pairs(mars_folders) do
|
||||
openspace.globebrowsing.addBlendingLayersFromDirectory(file, "Mars")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
openspace.globebrowsing.documentation = {
|
||||
{
|
||||
Name = "createTextureLayers",
|
||||
Arguments = "table",
|
||||
Documentation = "Creates a table used in the 'ColorLayers', 'GrayScaleLayers', or 'GrayScaleColorOverlays' of a RenderableGlobe."
|
||||
},
|
||||
{
|
||||
Name = "createHeightLayers",
|
||||
Arguments = "table",
|
||||
Documentation = "Creates a table used in the 'HeightLayers' of a RenderableGlobe."
|
||||
},
|
||||
{
|
||||
Name = "createTemporalGibsGdalXml",
|
||||
Arguments = "string, string, string, string, string, string",
|
||||
@@ -57,34 +47,31 @@ openspace.globebrowsing.documentation = {
|
||||
")" ..
|
||||
"}" ..
|
||||
")"
|
||||
},
|
||||
{
|
||||
Name = "parseInfoFile",
|
||||
Arguments = "string",
|
||||
Documentation =
|
||||
"Parses the passed info file and returns two tables. The first return value " ..
|
||||
"contains the table for the color layer of a RenderableGlobe. The second " ..
|
||||
"return value contains the table for the height layer of a RenderableGlobe." ..
|
||||
"Usage: local color, height = openspace.globebrowsing.parseInfoFile(file)" ..
|
||||
"openspace.globebrowsing.addLayer('Earth', 'ColorLayers', color)" ..
|
||||
"openspace.globebrowsing.addLayer('Earth', 'HeightLayers', height)"
|
||||
|
||||
},
|
||||
{
|
||||
Name = "addBlendingLayersFromDirectory",
|
||||
Arguments = "string, string",
|
||||
Documentation =
|
||||
"Retrieves all info files recursively in the directory passed as the first " ..
|
||||
"argument to this function. The color and height tables retrieved from these " ..
|
||||
"info files are then added to the RenderableGlobe identified by name passed " ..
|
||||
"to the second argument." ..
|
||||
"Usage: openspace.globebrowsing.addBlendingLayersFromDirectory(directory, 'Earth')"
|
||||
}
|
||||
}
|
||||
|
||||
-- Creates a table used in the 'ColorLayers', 'GrayScaleLayers', or 'GrayScaleColorOverlays'
|
||||
-- of a RenderableGlobe
|
||||
-- Usage:
|
||||
-- table.unpack(openspace.globebrowsing.createTextureLayers(p))
|
||||
-- where p is an array that contains tables with 'Name' and 'Texture' values
|
||||
openspace.globebrowsing.createTextureLayers = function (patches)
|
||||
result = {}
|
||||
for k,v in pairs(patches) do
|
||||
table.insert(result, { Name = v["Name"], FilePath = v["Texture"] })
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Creates a table used in the 'HeightLayers' of a RenderableGlobe
|
||||
-- Usage:
|
||||
-- table.unpack(openspace.globebrowsing.openspace.globebrowsing.createHeightLayers(p))
|
||||
-- where p is an array that contains tables with 'Name' and 'Height' values
|
||||
openspace.globebrowsing.createHeightLayers = function (patches)
|
||||
result = {}
|
||||
for k,v in pairs(patches) do
|
||||
table.insert(result, { Name = v["Name"], FilePath = v["Height"], TilePixelSize = 90, PerformPreProcessing = true })
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
openspace.globebrowsing.createTemporalGibsGdalXml = function (layerName, startDate, endDate, timeResolution, resolution, format)
|
||||
temporalTemplate =
|
||||
"<OpenSpaceTemporalGDALDataset>" ..
|
||||
@@ -162,4 +149,36 @@ openspace.globebrowsing.createGibsGdalXml = function (layerName, date, resolutio
|
||||
"</GDAL_WMS>"
|
||||
|
||||
return gdalWmsTemplate
|
||||
end
|
||||
|
||||
openspace.globebrowsing.parseInfoFile = function (file)
|
||||
local dir = openspace.directoryForPath(file)
|
||||
dofile(file)
|
||||
|
||||
local color = {
|
||||
Name = Name,
|
||||
FilePath = dir .. '/' .. ColorFile,
|
||||
BlendMode = "Color"
|
||||
}
|
||||
|
||||
local height = {
|
||||
Name = Name,
|
||||
FilePath = dir .. '/' .. HeightFile,
|
||||
TilePixelSize = 90
|
||||
}
|
||||
|
||||
return color, height
|
||||
end
|
||||
|
||||
openspace.globebrowsing.addBlendingLayersFromDirectory = function (dir, node_name)
|
||||
local files = openspace.walkDirectoryFiles(dir, true, true)
|
||||
|
||||
for _, file in pairs(files) do
|
||||
if file:find('.info') then
|
||||
c, h = openspace.globebrowsing.parseInfoFile(file)
|
||||
|
||||
openspace.globebrowsing.addLayer(node_name, "ColorLayers", c)
|
||||
openspace.globebrowsing.addLayer(node_name, "HeightLayers", h)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -408,100 +408,114 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, bo
|
||||
}
|
||||
|
||||
void ScriptEngine::addBaseLibrary() {
|
||||
LuaLibrary lib = {
|
||||
"",
|
||||
LuaLibrary lib = {
|
||||
"",
|
||||
{
|
||||
{
|
||||
{
|
||||
"printTrace",
|
||||
&luascriptfunctions::printTrace,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Trace'"
|
||||
},
|
||||
{
|
||||
"printDebug",
|
||||
&luascriptfunctions::printDebug,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Debug'"
|
||||
},
|
||||
{
|
||||
"printInfo",
|
||||
&luascriptfunctions::printInfo,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Info'"
|
||||
},
|
||||
{
|
||||
"printWarning",
|
||||
&luascriptfunctions::printWarning,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Warning'"
|
||||
},
|
||||
{
|
||||
"printError",
|
||||
&luascriptfunctions::printError,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Error'"
|
||||
},
|
||||
{
|
||||
"printFatal",
|
||||
&luascriptfunctions::printFatal,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Fatal'"
|
||||
},
|
||||
{
|
||||
"absPath",
|
||||
&luascriptfunctions::absolutePath,
|
||||
"string",
|
||||
"Returns the absolute path to the passed path, resolving path tokens as "
|
||||
"well as resolving relative paths"
|
||||
},
|
||||
{
|
||||
"fileExists",
|
||||
&luascriptfunctions::fileExists,
|
||||
"string",
|
||||
"Checks whether the provided file exists."
|
||||
},
|
||||
{
|
||||
"setPathToken",
|
||||
&luascriptfunctions::setPathToken,
|
||||
"string, string",
|
||||
"Registers a new path token provided by the first argument to the path "
|
||||
"provided in the second argument"
|
||||
},
|
||||
{
|
||||
"walkDirectory",
|
||||
&luascriptfunctions::walkDirectory,
|
||||
"string [bool, bool]",
|
||||
"Walks a directory and returns all contents (files and directories) of "
|
||||
"the directory as absolute paths. The first argument is the path of the "
|
||||
"directory that should be walked, the second argument determines if the "
|
||||
"walk is recursive and will continue in contained directories. The third "
|
||||
"argument determines whether the table that is returned is sorted."
|
||||
},
|
||||
{
|
||||
"walkDirectoryFiles",
|
||||
&luascriptfunctions::walkDirectoryFiles,
|
||||
"string [bool, bool]",
|
||||
"Walks a directory and returns the files of the directory as absolute "
|
||||
"paths. The first argument is the path of the directory that should be "
|
||||
"walked, the second argument determines if the walk is recursive and "
|
||||
"will continue in contained directories. The third argument determines "
|
||||
"whether the table that is returned is sorted."
|
||||
},
|
||||
{
|
||||
"walkDirectoryFolder",
|
||||
&luascriptfunctions::walkDirectoryFolder,
|
||||
"string [bool, bool]",
|
||||
"Walks a directory and returns the subfolders of the directory as "
|
||||
"absolute paths. The first argument is the path of the directory that "
|
||||
"should be walked, the second argument determines if the walk is "
|
||||
"recursive and will continue in contained directories. The third "
|
||||
"argument determines whether the table that is returned is sorted."
|
||||
"printTrace",
|
||||
&luascriptfunctions::printTrace,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Trace'"
|
||||
},
|
||||
{
|
||||
"printDebug",
|
||||
&luascriptfunctions::printDebug,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Debug'"
|
||||
},
|
||||
{
|
||||
"printInfo",
|
||||
&luascriptfunctions::printInfo,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Info'"
|
||||
},
|
||||
{
|
||||
"printWarning",
|
||||
&luascriptfunctions::printWarning,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Warning'"
|
||||
},
|
||||
{
|
||||
"printError",
|
||||
&luascriptfunctions::printError,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Error'"
|
||||
},
|
||||
{
|
||||
"printFatal",
|
||||
&luascriptfunctions::printFatal,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a LogLevel of "
|
||||
"'Fatal'"
|
||||
},
|
||||
{
|
||||
"absPath",
|
||||
&luascriptfunctions::absolutePath,
|
||||
"string",
|
||||
"Returns the absolute path to the passed path, resolving path tokens as "
|
||||
"well as resolving relative paths"
|
||||
},
|
||||
{
|
||||
"fileExists",
|
||||
&luascriptfunctions::fileExists,
|
||||
"string",
|
||||
"Checks whether the provided file exists."
|
||||
},
|
||||
{
|
||||
"directoryExists",
|
||||
&luascriptfunctions::directoryExists,
|
||||
"string",
|
||||
"Chckes whether the provided directory exists."
|
||||
},
|
||||
{
|
||||
"setPathToken",
|
||||
&luascriptfunctions::setPathToken,
|
||||
"string, string",
|
||||
"Registers a new path token provided by the first argument to the path "
|
||||
"provided in the second argument"
|
||||
},
|
||||
{
|
||||
"walkDirectory",
|
||||
&luascriptfunctions::walkDirectory,
|
||||
"string [bool, bool]",
|
||||
"Walks a directory and returns all contents (files and directories) of "
|
||||
"the directory as absolute paths. The first argument is the path of the "
|
||||
"directory that should be walked, the second argument determines if the "
|
||||
"walk is recursive and will continue in contained directories. The third "
|
||||
"argument determines whether the table that is returned is sorted."
|
||||
},
|
||||
{
|
||||
"walkDirectoryFiles",
|
||||
&luascriptfunctions::walkDirectoryFiles,
|
||||
"string [bool, bool]",
|
||||
"Walks a directory and returns the files of the directory as absolute "
|
||||
"paths. The first argument is the path of the directory that should be "
|
||||
"walked, the second argument determines if the walk is recursive and "
|
||||
"will continue in contained directories. The third argument determines "
|
||||
"whether the table that is returned is sorted."
|
||||
},
|
||||
{
|
||||
"walkDirectoryFolder",
|
||||
&luascriptfunctions::walkDirectoryFolder,
|
||||
"string [bool, bool]",
|
||||
"Walks a directory and returns the subfolders of the directory as "
|
||||
"absolute paths. The first argument is the path of the directory that "
|
||||
"should be walked, the second argument determines if the walk is "
|
||||
"recursive and will continue in contained directories. The third "
|
||||
"argument determines whether the table that is returned is sorted."
|
||||
},
|
||||
{
|
||||
"directoryForPath",
|
||||
&luascriptfunctions::directoryForPath,
|
||||
"string",
|
||||
"This function extracts the directory part of the passed path. For "
|
||||
"example, if the parameter is 'C:\\OpenSpace\\foobar\\foo.txt', this "
|
||||
"function returns 'C:\\OpenSpace\\foobar'."
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -226,12 +226,8 @@ int setPathToken(lua_State* L) {
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* walkDirectory(string, bool, bool):
|
||||
* Walks a directory and returns the contents of the directory as absolute paths. The
|
||||
* first argument is the path of the directory that should be walked, the second argument
|
||||
* determines if the walk is recursive and will continue in contained directories. The
|
||||
* default value for this parameter is "false". The third argument determines whether the
|
||||
* table that is returned is sorted. The default value for this parameter is "false".
|
||||
* fileExists(string):
|
||||
* Checks whether the provided file exists
|
||||
*/
|
||||
int fileExists(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
@@ -241,10 +237,24 @@ int fileExists(lua_State* L) {
|
||||
|
||||
const std::string file = luaL_checkstring(L, -1);
|
||||
const bool e = FileSys.fileExists(absPath(file));
|
||||
lua_pushboolean(
|
||||
L,
|
||||
e ? 1 : 0
|
||||
);
|
||||
lua_pushboolean(L, (e ? 1 : 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* directoryExists(string):
|
||||
* Checks whether the provided file exists
|
||||
*/
|
||||
int directoryExists(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
const std::string file = luaL_checkstring(L, -1);
|
||||
const bool e = FileSys.directoryExists(absPath(file));
|
||||
lua_pushboolean(L, (e ? 1 : 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -286,7 +296,26 @@ int walkDirectoryFiles(lua_State* L) {
|
||||
*/
|
||||
int walkDirectoryFolder(lua_State* L) {
|
||||
return walkCommon(L, &ghoul::filesystem::Directory::readDirectories);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* directoryForPath(string):
|
||||
* This function extracts the directory part of the passed path. For example, if the
|
||||
* parameter is 'C:\\OpenSpace\\foobar\\foo.txt', this function returns
|
||||
* 'C:\\OpenSpace\\foobar'."
|
||||
*/
|
||||
int directoryForPath(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
const std::string file = luaL_checkstring(L, -1);
|
||||
const std::string path = ghoul::filesystem::File(file).directoryName();
|
||||
lua_pushstring(L, path.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace openspace::luascriptfunctions
|
||||
|
||||
Reference in New Issue
Block a user