volume sequences can be made, and they will use a global min and max value

This commit is contained in:
Elon
2019-06-04 16:44:14 -06:00
parent a043ae0c44
commit 3ae183b997
12 changed files with 161 additions and 181 deletions

View File

@@ -14,7 +14,7 @@ local volume = {
Parent = transforms.EarthInertial.Identifier,
Renderable = {
Type = "RenderableTimeVaryingVolume",
SourceDirectory = asset.localResource("generatedSequence"),
SourceDirectory = asset.localResource("generated"),
TransferFunction = asset.localResource("transferfunction.txt"),
StepSize = 0.01,
MinValue = 0,

View File

@@ -1,6 +1,6 @@
width 1024
lower 0.0
upper 1.0
mappingkey 0.08 40 160 40 0
mappingkey 0.02 40 160 40 0
mappingkey 0.14 40 40 240 50
mappingkey 0.3 200 80 0 250

View File

@@ -1,4 +1,4 @@
asset.request('./debris/debris_asat')
--asset.request('./debris/debris_asat')
asset.request('./debris/debris_breezem')
--asset.request('./debris/debris_fengyun')
--asset.request('./debris/debris_iridium33')

View File

@@ -1,2 +1,2 @@
asset.request('./debris/debris_breezem_old')
asset.request('./debris/debris_asat_old')
-- asset.request('./debris/debris_asat_old')

View File

@@ -1,10 +1,12 @@
return {{
Type = "GenerateDebrisVolumeTask",
Dimensions = {64, 64, 64},
Dimensions = {28, 28, 28},
LowerDomainBound = {-0.5, -0.5, -0.5},
UpperDomainBound = {0.5, 0.5, 0.5},
InputPath = "${SYNC}/url/satellite_tle_data_BreezeMBreakup(18391204735368316775)/files/2012-044.txt",
InputPath = "${SYNC}/url/satellite_tle_data_DebrisAll/files/allDebrisInOneTLE.txt",
StartTime = "2018-05-04T00:00:00",
TimeStep = "0.4",
EndTime = "2018-05-04T00:04:00",
RawVolumeOutput = "${DATA}/assets/scene/solarsystem/planets/earth/satellites/debris/volume/generated/singleDebris.rawvolume",
DictionaryOutput = "${DATA}/assets/scene/solarsystem/planets/earth/satellites/debris/volume/generated/singleDebris.dictionary"
}}

View File

@@ -622,9 +622,9 @@ void RenderableSatellites::updateBuffers() {
glm::dvec3 position = _keplerTranslator.debrisPos(timeOffset + orbit.epoch);
double positionX = position.x / 10000000; // 10 miljon
double positionY = position.y / 10000000; // 10 miljon
double positionZ = position.z / 10000000; // 10 miljon
double positionX = position.x; // 10 miljon
double positionY = position.y; // 10 miljon
double positionZ = position.z; // 10 miljon
_vertexBufferData[index].x = static_cast<float>(positionX);
_vertexBufferData[index].y = static_cast<float>(positionY);

View File

@@ -31,6 +31,7 @@ uniform float opacity = 1.0;
uniform float lineFade;
// uniform int numberOfSegments;
in vec4 viewSpacePosition;
in vec4 vs_position;
@@ -38,7 +39,13 @@ in float periodFraction_f;
in float offsetPeriods;
// in float vertexID_f;
// debuggers :
// in float offset;
// in float epoch;
// in float period;
// in flat double tajm;
Fragment getFragment() {
// float offsetPeriods = offset / period;
// This is now done in the fragment shader instead
// to make smooth movement between vertecies.
// We want vertexDistance to be double up to this point, I think.
@@ -63,10 +70,13 @@ Fragment getFragment() {
frag.color = vec4(color, fade * opacity);
frag.depth = vs_position.w;
frag.gPosition = viewSpacePosition;
frag.gNormal = vec4(1, 1, 1 , 0);
frag.gNormal = vec4(1, 1, 1, 0);
// frag.blend = BLEND_MODE_ADDITIVE;
// to debug using colors use this if-statment.
// if( vertexDistance < 0.0 || vertexDistance >= 0.0){
// float ep = 0.001;
// if(vertexDistance_f < ep ){ //periodFraction < ep
// frag.color = vec4(1, 0, 0, 1);
// }

View File

@@ -42,8 +42,15 @@ out float periodFraction_f;
out float offsetPeriods;
// out float vertexID_f;
// debugers :
// out float offset;
// out float epoch;
// out float period;
// out double tajm;
void main() {
// tajm = inGameTime;
/** The way the position and line fade is calculated is:
* By using inGameTime, epoch and period of this orbit,
* we get how many revolutions it has done since epoch.
@@ -71,7 +78,7 @@ void main() {
// offsetPeriods can also be calculated by passing the vertexID as a float
// to the fragment shader and deviding it by nrOfSegments.
// vertexID_f = float(gl_VertexID);
dvec3 positions = dvec3(vertex_data.x*10000000, vertex_data.y*10000000, vertex_data.z*10000000);
dvec3 positions = dvec3(vertex_data.x, vertex_data.y, vertex_data.z);
dvec4 vertexPosition = dvec4(positions, 1);
viewSpacePosition = vec4(modelViewTransform * vertexPosition);
vs_position = z_normalization( projectionTransform * viewSpacePosition);

View File

@@ -39,6 +39,8 @@
#include <ghoul/misc/defer.h>
#include <fstream>
#include <queue>
namespace {
@@ -50,7 +52,8 @@ namespace {
constexpr const char* KeyDictionaryOutput = "DictionaryOutput";
constexpr const char* KeyDimensions = "Dimensions";
constexpr const char* KeyStartTime = "StartTime";
//constexpr const char* KeyEndTime = "EndTime";
constexpr const char* KeyTimeStep = "TimeStep";
constexpr const char* KeyEndTime = "EndTime";
constexpr const char* KeyInputPath = "InputPath";
// constexpr const char* KeyInputPath1 = "InputPath1";
@@ -373,7 +376,7 @@ std::vector<KeplerParameters> readTLEFile(const std::string& filename){
return data;
}
std::vector<glm::dvec3> getPositionBuffer(std::vector<KeplerParameters> tleData, std::string& timeStamp) {
std::vector<glm::dvec3> getPositionBuffer(std::vector<KeplerParameters> tleData, double timeInSeconds) {
std::vector<glm::dvec3> positionBuffer;
for(const auto& orbit : tleData) {
@@ -388,7 +391,7 @@ std::vector<glm::dvec3> getPositionBuffer(std::vector<KeplerParameters> tleData,
orbit.period,
orbit.epoch
);
double timeInSeconds = Time::convertTime(timeStamp);
// double timeInSeconds = Time::convertTime(timeStamp);
glm::dvec3 position = keplerTranslator.debrisPos(timeInSeconds);
positionBuffer.push_back(position);
@@ -397,18 +400,18 @@ std::vector<glm::dvec3> getPositionBuffer(std::vector<KeplerParameters> tleData,
return positionBuffer;
}
std::vector<glm::dvec3> generatePositions(int numberOfPositions) {
std::vector<glm::dvec3> positions;
// std::vector<glm::dvec3> generatePositions(int numberOfPositions) {
// std::vector<glm::dvec3> positions;
float radius = 700000; // meter
float degreeStep = 360 / numberOfPositions;
// float radius = 700000; // meter
// float degreeStep = 360 / numberOfPositions;
for(int i=0 ; i<= 360 ; i += degreeStep){
glm::dvec3 singlePosition = glm::dvec3(radius* sin(i), radius*cos(i), 0.0);
positions.push_back(singlePosition);
}
return positions;
}
// for(int i=0 ; i<= 360 ; i += degreeStep){
// glm::dvec3 singlePosition = glm::dvec3(radius* sin(i), radius*cos(i), 0.0);
// positions.push_back(singlePosition);
// }
// return positions;
// }
float getDensityAt(glm::uvec3 cell, int* densityArray, RawVolume<float>& raw) {
float value;
@@ -447,8 +450,7 @@ int getIndexFromPosition(glm::dvec3 position, glm::uvec3 dim, float maxApogee){
return coordinateIndex.z * (dim.x * dim.y) + coordinateIndex.y * dim.x + coordinateIndex.x;
}
int* mapDensityToVoxels(int* densityArray, std::vector<glm::dvec3> positions,
glm::uvec3 dim, float maxApogee) {
int* mapDensityToVoxels(int* densityArray, std::vector<glm::dvec3> positions, glm::uvec3 dim, float maxApogee) {
for(const glm::dvec3& position : positions) {
int index = getIndexFromPosition(position, dim, maxApogee);
@@ -467,18 +469,20 @@ GenerateDebrisVolumeTask::GenerateDebrisVolumeTask(const ghoul::Dictionary& dict
_rawVolumeOutputPath = absPath(dictionary.value<std::string>(KeyRawVolumeOutput));
_dictionaryOutputPath = absPath(dictionary.value<std::string>(KeyDictionaryOutput));
_dimensions = dictionary.value<glm::vec3>(KeyDimensions);
_dimensions = dictionary.value<glm::vec3>(KeyDimensions); // must not be <glm::uvec3> for some reason.
_startTime = dictionary.value<std::string>(KeyStartTime);
//_endTime = dictionary.value<std::string>(KeyEndTime);
_timeStep = dictionary.value<std::string>(KeyTimeStep); // Todo: send KeyTimeStep in as a int or float correctly.
_endTime = dictionary.value<std::string>(KeyEndTime);
// since _inputPath is past from task,
// there will have to be either one task per dataset,
// or you need to combine the datasets into one file.
_inputPath = absPath(dictionary.value<std::string>(KeyInputPath));
_lowerDomainBound = dictionary.value<glm::vec3>(KeyLowerDomainBound);
_upperDomainBound = dictionary.value<glm::vec3>(KeyUpperDomainBound);
_TLEDataVector = {};
_TLEDataVector = readTLEFile(_inputPath);
_maxApogee = getMaxApogee(_TLEDataVector);
}
std::string GenerateDebrisVolumeTask::description() {
@@ -508,88 +512,120 @@ void GenerateDebrisVolumeTask::perform(const Task::ProgressCallback& progressCal
// _TLEDataVector.insert(_TLEDataVector.end(), TLEDataVector3.begin(), TLEDataVector3.end());
// _TLEDataVector.insert(_TLEDataVector.end(), TLEDataVector4.begin(), TLEDataVector4.end());
// ----- or ----- if only one
_TLEDataVector = readTLEFile(_inputPath);
//////////
std::vector<glm::dvec3> startPositionBuffer = getPositionBuffer(_TLEDataVector, _startTime);
// if we deside to integrate the density over time
// std::vector<glm::dvec3> endPositionBuffer = getPositionBuffer(_TLEDataVector, _endTime);
//int numberOfPoints = 40;
//Needs to be looked at, caused my computer to crash...
//std::vector<glm::dvec3> generatedPositions = generatePositions(numberOfPoints);
float maxApogee = getMaxApogee(_TLEDataVector);
LINFO(fmt::format("Max Apogee: {} ", maxApogee));
const int size = _dimensions.x *_dimensions.y *_dimensions.z;
int *densityArrayp = new int[size]();
//densityArrayp = mapDensityToVoxels(densityArrayp, generatedPositions, _dimensions, maxApogee);
densityArrayp = mapDensityToVoxels(densityArrayp, startPositionBuffer, _dimensions, maxApogee);
// create object rawVolume
volume::RawVolume<float> rawVolume(_dimensions);
//glm::vec3 domainSize = _upperDomainBound - _lowerDomainBound;
// _TLEDataVector = readTLEFile(_inputPath);
//////////
// float maxApogee = getMaxApogee(_TLEDataVector);
LINFO(fmt::format("Max Apogee: {} ", _maxApogee));
/** SEQUENCE
* 1. handle timeStep
* 1.1 either ignore last timeperiod from the latest whole timestep to _endTime
* 1.2 or extend endTime to be equal to next full timestep
* 2. loop to create a rawVolume for each timestep.
*/
// 1
double startTimeInSeconds = Time::convertTime(_startTime);
double endTimeInSeconds = Time::convertTime(_endTime);
double timeSpan = endTimeInSeconds - startTimeInSeconds;
float timeStep = std::stof(_timeStep);
// 1.1
int numberOfIterations = static_cast<int>(timeSpan/timeStep);
LINFO(fmt::format("timestep: {} ", numberOfIterations));
std::queue<volume::RawVolume<float>> rawVolumeQueue = {};
const int size = _dimensions.x *_dimensions.y *_dimensions.z;
float minVal = std::numeric_limits<float>::max();
float maxVal = std::numeric_limits<float>::min();
// TODO: Create a forEachSatallite and set(cell, value) to combine mapDensityToVoxel
// and forEachVoxel for less time complexity.
rawVolume.forEachVoxel([&](glm::uvec3 cell, float) {
// glm::vec3 coord = _lowerDomainBound +
// glm::vec3(cell) / glm::vec3(_dimensions) * domainSize;
float value = getDensityAt(cell, densityArrayp, rawVolume); // (coord)
//LINFO(fmt::format("EachVoxel: {} ", value));
// if((cell.x + cell.y + cell.z) % 8 == 0)
// value = 1;
// else
// value = 0;
// 2.
for(int i=0 ; i<=numberOfIterations ; ++i) {
rawVolume.set(cell, value);
std::vector<glm::dvec3> startPositionBuffer = getPositionBuffer(_TLEDataVector, startTimeInSeconds+(i*timeStep)); //+(i*timeStep)
minVal = std::min(minVal, value);
maxVal = std::max(maxVal, value);
/*LINFO(fmt::format("min: {} ", minVal));
LINFO(fmt::format("max: {} ", maxVal));*/
});
int *densityArrayp = new int[size]();
//densityArrayp = mapDensityToVoxels(densityArrayp, generatedPositions, _dimensions, maxApogee);
densityArrayp = mapDensityToVoxels(densityArrayp, startPositionBuffer, _dimensions, _maxApogee);
// create object rawVolume
volume::RawVolume<float> rawVolume(_dimensions);
//glm::vec3 domainSize = _upperDomainBound - _lowerDomainBound;
// TODO: Create a forEachSatallite and set(cell, value) to combine mapDensityToVoxel
// and forEachVoxel for less time complexity.
rawVolume.forEachVoxel([&](glm::uvec3 cell, float) {
// glm::vec3 coord = _lowerDomainBound +
// glm::vec3(cell) / glm::vec3(_dimensions) * domainSize;
float value = getDensityAt(cell, densityArrayp, rawVolume); // (coord)
//LINFO(fmt::format("EachVoxel: {} ", value));
// if((cell.x + cell.y + cell.z) % 8 == 0)
// value = 1;
// else
// value = 0;
ghoul::filesystem::File file(_rawVolumeOutputPath);
const std::string directory = file.directoryName();
if (!FileSys.directoryExists(directory)) {
FileSys.createDirectory(directory, ghoul::filesystem::FileSystem::Recursive::Yes);
rawVolume.set(cell, value);
minVal = std::min(minVal, value);
maxVal = std::max(maxVal, value);
/*LINFO(fmt::format("min: {} ", minVal));
LINFO(fmt::format("max: {} ", maxVal));*/
});
rawVolumeQueue.push(rawVolume);
delete[] densityArrayp;
}
volume::RawVolumeWriter<float> writer(_rawVolumeOutputPath);
writer.write(rawVolume);
// two loops is used to get a global min and max value for voxels.
for(int i=0 ; i<=numberOfIterations ; ++i){
// LINFO(fmt::format("raw file output name: {} ", _rawVolumeOutputPath));
size_t lastIndex = _rawVolumeOutputPath.find_last_of(".");
std::string rawOutputName = _rawVolumeOutputPath.substr(0, lastIndex);
rawOutputName += std::to_string(i) + ".rawvolume";
lastIndex = _dictionaryOutputPath.find_last_of(".");
std::string dictionaryOutputName = _dictionaryOutputPath.substr(0, lastIndex);
dictionaryOutputName += std::to_string(i) + ".dictionary";
ghoul::filesystem::File file(rawOutputName);
const std::string directory = file.directoryName();
if (!FileSys.directoryExists(directory)) {
FileSys.createDirectory(directory, ghoul::filesystem::FileSystem::Recursive::Yes);
}
RawVolumeMetadata metadata;
// alternatively metadata.hasTime = false;
metadata.time = Time::convertTime(_startTime);
metadata.dimensions = _dimensions;
metadata.hasDomainUnit = false;
metadata.hasValueUnit = false;
metadata.gridType = VolumeGridType::Cartesian;
metadata.hasDomainBounds = true;
metadata.lowerDomainBound = _lowerDomainBound;
metadata.upperDomainBound = _upperDomainBound;
metadata.hasValueRange = true;
metadata.minValue = minVal;
metadata.maxValue = maxVal;
volume::RawVolumeWriter<float> writer(rawOutputName);
writer.write(rawVolumeQueue.front());
rawVolumeQueue.pop();
RawVolumeMetadata metadata;
// alternatively metadata.hasTime = false;
metadata.time = Time::convertTime(_startTime)+(i*timeStep);
metadata.dimensions = _dimensions;
metadata.hasDomainUnit = false;
metadata.hasValueUnit = false;
metadata.gridType = VolumeGridType::Cartesian;
metadata.hasDomainBounds = true;
metadata.lowerDomainBound = _lowerDomainBound;
metadata.upperDomainBound = _upperDomainBound;
metadata.hasValueRange = true;
metadata.minValue = minVal;
metadata.maxValue = maxVal;
/*LINFO(fmt::format("min2: {} ", minVal));
LINFO(fmt::format("max2: {} ", maxVal));*/
/*LINFO(fmt::format("min2: {} ", minVal));
LINFO(fmt::format("max2: {} ", maxVal));*/
ghoul::Dictionary outputDictionary = metadata.dictionary();
ghoul::DictionaryLuaFormatter formatter;
std::string metadataString = formatter.format(outputDictionary);
ghoul::Dictionary outputDictionary = metadata.dictionary();
ghoul::DictionaryLuaFormatter formatter;
std::string metadataString = formatter.format(outputDictionary);
std::fstream f(_dictionaryOutputPath, std::ios::out);
f << "return " << metadataString;
f.close();
delete[] densityArrayp;
std::fstream f(dictionaryOutputName, std::ios::out);
f << "return " << metadataString;
f.close();
}
}
documentation::Documentation GenerateDebrisVolumeTask::documentation() {

View File

@@ -51,6 +51,7 @@ private:
std::string _rawVolumeOutputPath;
std::string _dictionaryOutputPath;
std::string _startTime;
std::string _timeStep;
std::string _endTime;
std::string _inputPath;
@@ -60,6 +61,8 @@ private:
std::vector<KeplerParameters> _TLEDataVector;
float _maxApogee;
// not sure if it should be local function or hidden function.
//std::vector<KeplerParameters> readTLEFile(const std::string& filename);

View File

@@ -1,78 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* 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_MODULE_SPACE___GENERATERDEBRISVOLUMETASK___H__
#define __OPENSPACE_MODULE_SPACE___GENERATERDEBRISVOLUMETASK___H__
#include <openspace/util/task.h>
#include <openspace/util/time.h>
#include <modules/space/rendering/renderablesatellites.h>
#include <modules/space/translation/keplertranslation.h>
#include <ghoul/glm.h>
#include <string>
#include <vector>
namespace openspace {
namespace volume {
class GenerateDebrisVolumeTask : public Task {
public:
GenerateDebrisVolumeTask(const ghoul::Dictionary& dictionary);
std::string description() override;
void perform(const Task::ProgressCallback& progressCallback) override;
static documentation::Documentation documentation();
private:
std::string _rawVolumeOutputPath;
std::string _dictionaryOutputPath;
std::string _startTime;
std::string _endTime;
std::string _inputPath;
// std::string _inputPath1;
// std::string _inputPath2;
// std::string _inputPath3;
// std::string _inputPath4;
glm::uvec3 _dimensions;
glm::vec3 _lowerDomainBound;
glm::vec3 _upperDomainBound;
std::vector<KeplerParameters> _TLEDataVector;
// not sure if it should be local function or hidden function.
//std::vector<KeplerParameters> readTLEFile(const std::string& filename);
};
} // namespace volume
} // namespace openspace
#endif // __OPENSPACE_MODULE_SPACE___GENERATEDEBRISVOLUMETASK___H__

View File

@@ -265,7 +265,7 @@ void RenderableTimeVaryingVolume::initializeGL() {
data[i] = glm::clamp((data[i] - min) / diff, 0.f, 1.f);
if (data[i] > 0)
{
LINFO(fmt::format("test: {} ", data[i]));
// LINFO(fmt::format("test: {} ", data[i]));
}
}