merge after rebase

This commit is contained in:
ElonOlsson
2019-05-31 09:58:44 -06:00
15 changed files with 168 additions and 120 deletions

View File

@@ -23,7 +23,7 @@
****************************************************************************************/
#include <fstream>
#include <chrono>
#include <vector>
#include <vector>
#include <modules/space/rendering/renderablesatellites.h>
#include <modules/space/translation/keplertranslation.h>
@@ -476,7 +476,7 @@ RenderableSatellites::~RenderableSatellites() {
void RenderableSatellites::initialize() {
updateBuffers();
// updateBuffers();
//_path.onChange([this]() {
// readTLEFile(_path);
@@ -534,9 +534,8 @@ void RenderableSatellites::deinitializeGL() {
SpaceModule::ProgramObjectManager.release(ProgramName);
glDeleteBuffers(1, &_vertexBuffer);
glDeleteBuffers(1, &_indexBuffer);
//glDeleteBuffers(1, &_indexBuffer);
glDeleteVertexArrays(1, &_vertexArray);
_vertexArray = 0;
}
@@ -576,8 +575,7 @@ void RenderableSatellites::render(const RenderData& data, RendererTasks&) {
_programObject->setUniform(_uniformCache.numberOfSegments, static_cast<int>(_nSegments));
//glEnableVertexAttribArray(0); // We like submitting vertices on stream 0 for no special reason
//glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), 0);
glLineWidth(_appearance.lineWidth);
const size_t nrOrbits = _TLEData.size();
gl::GLint vertices = 0;
@@ -599,7 +597,6 @@ void RenderableSatellites::render(const RenderData& data, RendererTasks&) {
void RenderableSatellites::updateBuffers() {
_TLEData = readTLEFile(_path);
LINFO(fmt::format("Pathpath: {} ", _path));
const size_t nVerticesPerOrbit = _nSegments + 1;
_vertexBufferData.resize(_TLEData.size() * nVerticesPerOrbit);

View File

@@ -32,7 +32,6 @@ uniform float lineFade;
// uniform int numberOfSegments;
in vec4 viewSpacePosition;
in vec4 vs_position;
in float periodFraction_f;

View File

@@ -28,9 +28,9 @@ layout(location = 0) in vec4 vertexData;
uniform dmat4 modelViewTransform;
uniform mat4 projectionTransform;
uniform bool useLineFade;
uniform float lineFade;
uniform int vertexSortingMethod;
// uniform bool useLineFade;
// uniform float lineFade;
// uniform int vertexSortingMethod;
uniform int pointSize;
out vec4 viewSpacePosition;

View File

@@ -30,6 +30,7 @@
#include <openspace/documentation/verifier.h>
#include <ghoul/misc/dictionaryluaformatter.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/file.h>
@@ -49,11 +50,17 @@ namespace {
constexpr const char* KeyDictionaryOutput = "DictionaryOutput";
constexpr const char* KeyDimensions = "Dimensions";
constexpr const char* KeyStartTime = "StartTime";
// constexpr const char* KeyEndTime = "EndTime";
//constexpr const char* KeyEndTime = "EndTime";
constexpr const char* KeyInputPath = "InputPath";
// constexpr const char* KeyLowerDomainBound = "LowerDomainBound";
// constexpr const char* KeyUpperDomainBound = "UpperDomainBound";
constexpr const char* _loggerCat = "SpaceDebris";
// constexpr const char* KeyInputPath1 = "InputPath1";
// constexpr const char* KeyInputPath2 = "InputPath2";
// constexpr const char* KeyInputPath3 = "InputPath3";
// constexpr const char* KeyInputPath4 = "InputPath4";
constexpr const char* KeyLowerDomainBound = "LowerDomainBound";
constexpr const char* KeyUpperDomainBound = "UpperDomainBound";
}
@@ -396,14 +403,14 @@ std::vector<glm::dvec3> generatePositions(int numberOfPositions) {
float radius = 700000; // meter
float degreeStep = 360 / numberOfPositions;
for(int i=0 ; i<= 360 ; i == degreeStep){
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) {
float getDensityAt(glm::uvec3 cell, int* densityArray, RawVolume<float>& raw) {
float value;
// return value at position cell from _densityPerVoxel
size_t index = raw.coordsToIndex(cell);
@@ -463,7 +470,6 @@ GenerateDebrisVolumeTask::GenerateDebrisVolumeTask(const ghoul::Dictionary& dict
_dimensions = dictionary.value<glm::vec3>(KeyDimensions);
_startTime = dictionary.value<std::string>(KeyStartTime);
//_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.
@@ -473,8 +479,6 @@ GenerateDebrisVolumeTask::GenerateDebrisVolumeTask(const ghoul::Dictionary& dict
_TLEDataVector = {};
_lowerDomainBound = dictionary.value<glm::vec3>(KeyLowerDomainBound);
_upperDomainBound = dictionary.value<glm::vec3>(KeyUpperDomainBound);
}
std::string GenerateDebrisVolumeTask::description() {
@@ -489,26 +493,39 @@ void GenerateDebrisVolumeTask::perform(const Task::ProgressCallback& progressCal
SpiceManager::ref().unloadKernel(kernel);
};
//////////
//1. read TLE-data and position of debris elements.
// std::vector<KeplerParameters>TLEDataVector = readTLEFile(_inputPath);
// std::vector<KeplerParameters>TLEDataVector1 = readTLEFile(_inputPath1);
// std::vector<KeplerParameters>TLEDataVector2 = readTLEFile(_inputPath2);
// std::vector<KeplerParameters>TLEDataVector3 = readTLEFile(_inputPath3);
// std::vector<KeplerParameters>TLEDataVector4 = readTLEFile(_inputPath4);
// _TLEDataVector.reserve( TLEDataVector.size() + TLEDataVector1.size() + TLEDataVector2.size() + TLEDataVector3.size() + TLEDataVector4.size());
// _TLEDataVector.insert(_TLEDataVector.end(), TLEDataVector.begin(), TLEDataVector.end());
// _TLEDataVector.insert(_TLEDataVector.end(), TLEDataVector1.begin(), TLEDataVector1.end());
// _TLEDataVector.insert(_TLEDataVector.end(), TLEDataVector2.begin(), TLEDataVector2.end());
// _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;
//int numberOfPoints = 40;
//Needs to be looked at, caused my computer to crash...
//std::vector<glm::dvec3> generatedPositions = generatePositions(numberOfPoints);
const int size = _dimensions.x *_dimensions.y *_dimensions.z;
int *densityArrayp = new int[size];
for (int i = 0; i < size; ++i) {
densityArrayp[i] = 0;
}
LINFO(fmt::format("densityArray: {} ", densityArrayp[0]));
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);
@@ -539,44 +556,14 @@ void GenerateDebrisVolumeTask::perform(const Task::ProgressCallback& progressCal
LINFO(fmt::format("max: {} ", maxVal));*/
});
// indexed grid with cooresponding xyz: gridIndex
// int array with number of slots = number of voxels: densityArray = {0,0,0,0,0,0}
for(const glm::dvec3& debris : startPositionBuffer) {
// call function to increment densityArray where debris position ~= voxel position
ghoul::filesystem::File file(_rawVolumeOutputPath);
const std::string directory = file.directoryName();
if (!FileSys.directoryExists(directory)) {
FileSys.createDirectory(directory, ghoul::filesystem::FileSystem::Recursive::Yes);
}
// make raw volume of densityArray.
//2. create a grid using dimensions and other .task-parameters.
//3. calculate what voxel each debris is within for each time step.
// and increment density with one for each debris in that voxel.
glm::vec3 domainSize = _upperDomainBound - _lowerDomainBound;
rawVolume.forEachVoxel([&](glm::uvec3 cell, float) {
glm::vec3 coord = _lowerDomainBound +
glm::vec3(cell) / glm::vec3(_dimensions) * domainSize;
// TODO: coord is relative to the dimensions of the volume
// and the points from getPositionBuffer is relative
// to the earth (i think) so we need to convert them to be in the same
// coordinate system to be able to compare them
});
//4.
volume::RawVolumeWriter<float> writer(_rawVolumeOutputPath);
writer.write(rawVolume);
RawVolumeMetadata metadata;
// alternatively metadata.hasTime = false;

View File

@@ -0,0 +1,78 @@
/*****************************************************************************************
* *
* 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

@@ -324,27 +324,6 @@ glm::dvec3 KeplerTranslation::debrisPos(const double& time) const {
return _orbitPlaneRotation * p;
}
// Is only used in renderableDebris so far.
glm::dvec3 KeplerTranslation::position(const Time& time) const {
if (_orbitPlaneDirty) {
computeOrbitPlane();
_orbitPlaneDirty = false;
}
const double t = time.j2000Seconds() - _epoch;
const double meanMotion = glm::two_pi<double>() / _period;
const double meanAnomaly = glm::radians(_meanAnomalyAtEpoch.value()) + t * meanMotion;
const double e = eccentricAnomaly(meanAnomaly);
// Use the eccentric anomaly to compute the actual location
const glm::dvec3 p = {
_semiMajorAxis * 1000.0 * (cos(e) - _eccentricity),
_semiMajorAxis * 1000.0 * sin(e) * sqrt(1.0 - _eccentricity * _eccentricity),
0.0
};
return _orbitPlaneRotation * p;
}
void KeplerTranslation::computeOrbitPlane() const {
// We assume the following coordinate system:
// z = axis of rotation

View File

@@ -155,12 +155,6 @@ public:
protected:
private:
protected:
private: