Feature/cleanup (#1608)

* Revert screenlog back to showing Info and above messages
 * Various code cleanup
This commit is contained in:
Alexander Bock
2021-05-25 14:08:33 +02:00
committed by GitHub
parent 53d0b49f6b
commit c3ba532bdb
183 changed files with 4267 additions and 6072 deletions
@@ -41,13 +41,12 @@ namespace {
constexpr const char* ProgramName = "FovProgram";
constexpr const std::array<const char*, 9> UniformNames = {
"modelViewProjectionTransform", "defaultColorStart", "defaultColorEnd",
"modelViewProjectionTransform", "colorStart", "colorEnd",
"activeColor", "targetInFieldOfViewColor", "intersectionStartColor",
"intersectionEndColor", "squareColor", "interpolation"
};
constexpr const int InterpolationSteps = 5;
constexpr const double Epsilon = 1e-4;
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
@@ -145,6 +144,7 @@ namespace {
return 0.5 * bisect(p1, half, testFunction, half);
}
}
// Needs support for std::map first for the frameConversions
struct [[codegen::Dictionary(RenderableFov)]] Parameters {
// The SPICE name of the source body for which the field of view should be
@@ -197,37 +197,15 @@ documentation::Documentation RenderableFov::Documentation() {
return doc;
}
RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lineWidth(LineWidthInfo, 1.f, 1.f, 20.f)
, _drawSolid(DrawSolidInfo, false)
, _standOffDistance(StandoffDistanceInfo, 0.9999, 0.99, 1.0, 0.000001)
, _colors({
{
DefaultStartColorInfo,
glm::vec3(0.4f),
glm::vec3(0.f),
glm::vec3(1.f)
},
{
DefaultEndColorInfo,
glm::vec3(0.85f),
glm::vec3(0.f),
glm::vec3(1.f)
},
{
ActiveColorInfo,
glm::vec3(0.f, 1.f, 0.f),
glm::vec3(0.f),
glm::vec3(1.f)
},
{
TargetInFovInfo,
glm::vec3(0.f, 0.5f, 0.7f),
glm::vec3(0.f),
glm::vec3(1.f)
},
{ DefaultStartColorInfo, glm::vec3(0.4f), glm::vec3(0.f), glm::vec3(1.f) },
{ DefaultEndColorInfo, glm::vec3(0.85f), glm::vec3(0.f), glm::vec3(1.f) },
{ ActiveColorInfo, glm::vec3(0.f, 1.f, 0.f), glm::vec3(0.f), glm::vec3(1.f) },
{ TargetInFovInfo, glm::vec3(0.f, 0.5f, 0.7f), glm::vec3(0.f), glm::vec3(1.f) },
{
IntersectionStartInfo,
glm::vec3(1.f, 0.89f, 0.f),
@@ -240,12 +218,7 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
glm::vec3(0.f),
glm::vec3(1.f)
},
{
SquareColorInfo,
glm::vec3(0.85f),
glm::vec3(0.f),
glm::vec3(1.f)
}
{ SquareColorInfo, glm::vec3(0.85f), glm::vec3(0.f), glm::vec3(1.f) }
})
{
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -278,8 +251,6 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
_simplifyBounds = p.simplifyBounds.value_or(_simplifyBounds);
addProperty(_drawSolid);
addProperty(_colors.defaultStart);
addProperty(_colors.defaultEnd);
addProperty(_colors.active);
@@ -290,17 +261,16 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
}
void RenderableFov::initializeGL() {
_program =
SpacecraftInstrumentsModule::ProgramObjectManager.request(
ProgramName,
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
return global::renderEngine->buildRenderProgram(
ProgramName,
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_vs.glsl"),
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_fs.glsl")
);
}
);
_program = SpacecraftInstrumentsModule::ProgramObjectManager.request(
ProgramName,
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
return global::renderEngine->buildRenderProgram(
ProgramName,
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_vs.glsl"),
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_fs.glsl")
);
}
);
ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames);
@@ -402,7 +372,7 @@ void RenderableFov::initializeGL() {
1,
GL_INT,
sizeof(RenderInformation::VBOData),
reinterpret_cast<void*>(offsetof(RenderInformation::VBOData, color)) // NOLINT
reinterpret_cast<void*>(offsetof(RenderInformation::VBOData, color))
);
// Orthogonal Plane
@@ -432,7 +402,7 @@ void RenderableFov::initializeGL() {
1,
GL_INT,
sizeof(RenderInformation::VBOData),
reinterpret_cast<void*>(offsetof(RenderInformation::VBOData, color)) // NOLINT
reinterpret_cast<void*>(offsetof(RenderInformation::VBOData, color))
);
glBindVertexArray(0);
@@ -478,7 +448,7 @@ glm::dvec3 RenderableFov::orthogonalProjection(const glm::dvec3& vecFov, double
return p * 1000.0; // km -> m
}
void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& target,
void RenderableFov::computeIntercepts(double time, const std::string& target,
bool isInFov)
{
auto makeBodyFixedReferenceFrame =
@@ -488,22 +458,16 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
if (convert) {
SpacecraftInstrumentsModule* m =
global::moduleEngine->module<SpacecraftInstrumentsModule>();
return {
m->frameFromBody(target),
true
};
return { m->frameFromBody(target), true };
}
else {
return { ref, false };
}
};
//std::vector<bool> intersects(_instrument.bounds.size());
// First we fill the field-of-view bounds array by testing each bounds vector against
// the object. We need to test it against the object (rather than using a fixed
// distance) as the field of view rendering should stop at the surface and not
// continue
// distance) as the field of view rendering should stop at the surface
for (size_t i = 0; i < _instrument.bounds.size(); ++i) {
const glm::dvec3& bound = _instrument.bounds[i];
@@ -517,11 +481,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
if (!isInFov) {
// If the target is not in the field of view, we don't need to perform any
// surface intercepts
const glm::vec3 o = orthogonalProjection(
bound,
data.time.j2000Seconds(),
target
);
const glm::vec3 o = orthogonalProjection(bound, time, target);
second = {
{ o.x, o.y, o.z },
@@ -542,12 +502,10 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
_instrument.name,
ref.first,
_instrument.aberrationCorrection,
data.time.j2000Seconds(),
time,
bound
);
//intersects[i] = r.interceptFound;
if (r.interceptFound) {
// This point intersected the target
first.color = RenderInformation::VertexColorTypeIntersectionStart;
@@ -558,7 +516,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
r.surfaceVector = SpiceManager::ref().frameTransformationMatrix(
ref.first,
_instrument.referenceFrame,
data.time.j2000Seconds()
time
) * r.surfaceVector;
}
@@ -575,11 +533,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
else {
// This point did not intersect the target though others did
const glm::vec3 o = orthogonalProjection(
bound,
data.time.j2000Seconds(),
target
);
const glm::vec3 o = orthogonalProjection(bound, time, target);
second = {
{ o.x, o.y, o.z },
RenderInformation::VertexColorTypeInFieldOfView
@@ -593,9 +547,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
// earlier
// Each boundary in _instrument.bounds has 'InterpolationSteps' steps between
auto indexForBounds = [](size_t idx) -> size_t {
return idx * InterpolationSteps;
};
auto indexForBounds = [](size_t idx) -> size_t { return idx * InterpolationSteps; };
auto copyFieldOfViewValues = [&](size_t iBound, size_t begin, size_t end) -> void {
std::fill(
@@ -630,7 +582,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
_instrument.name,
makeBodyFixedReferenceFrame(_instrument.referenceFrame).first,
_instrument.aberrationCorrection,
data.time.j2000Seconds(),
time,
probe
).interceptFound;
};
@@ -646,7 +598,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
_instrument.name,
ref.first,
_instrument.aberrationCorrection,
data.time.j2000Seconds(),
time,
probe
);
@@ -654,7 +606,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
r.surfaceVector = SpiceManager::ref().frameTransformationMatrix(
ref.first,
_instrument.referenceFrame,
data.time.j2000Seconds()
time
) * r.surfaceVector;
}
@@ -675,12 +627,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
};
}
else {
const glm::vec3 o = orthogonalProjection(
tBound,
data.time.j2000Seconds(),
target
);
const glm::vec3 o = orthogonalProjection(tBound, time, target);
_orthogonalPlane.data[indexForBounds(i) + m] = {
{ o.x, o.y, o.z },
RenderInformation::VertexColorTypeSquare
@@ -707,7 +654,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
_instrument.name,
makeBodyFixedReferenceFrame(_instrument.referenceFrame).first,
_instrument.aberrationCorrection,
data.time,
time,
probe
).interceptFound;
};
@@ -787,61 +734,52 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
}
void RenderableFov::render(const RenderData& data, RendererTasks&) {
if (_drawFOV) {
_program->activate();
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
glm::mat4 modelViewProjectionTransform =
data.camera.projectionMatrix() *
glm::mat4(data.camera.combinedViewMatrix() * modelTransform);
_program->setUniform(
_uniformCache.modelViewProjection,
modelViewProjectionTransform
);
_program->setUniform(_uniformCache.defaultColorStart, _colors.defaultStart);
_program->setUniform(_uniformCache.defaultColorEnd, _colors.defaultEnd);
_program->setUniform(_uniformCache.activeColor, _colors.active);
_program->setUniform(
_uniformCache.targetInFieldOfViewColor,
_colors.targetInFieldOfView
);
_program->setUniform(
_uniformCache.intersectionStartColor,
_colors.intersectionStart
);
_program->setUniform(
_uniformCache.intersectionEndColor,
_colors.intersectionEnd
);
_program->setUniform(_uniformCache.squareColor, _colors.square);
_program->setUniform(_uniformCache.interpolation, _interpolationTime);
GLenum mode = _drawSolid ? GL_TRIANGLE_STRIP : GL_LINES;
glLineWidth(_lineWidth);
glBindVertexArray(_fieldOfViewBounds.vao);
glDrawArrays(mode, 0, static_cast<int>(_fieldOfViewBounds.data.size()));
glLineWidth(2.f);
glBindVertexArray(_orthogonalPlane.vao);
glDrawArrays(GL_LINE_LOOP, 0, static_cast<int>(_orthogonalPlane.data.size()));
glBindVertexArray(0);
glLineWidth(1.f);
_program->deactivate();
if (!_drawFOV) {
return;
}
_program->activate();
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
glm::mat4 modelViewProjectionTransform =
data.camera.projectionMatrix() *
glm::mat4(data.camera.combinedViewMatrix() * modelTransform);
_program->setUniform(_uniformCache.modelViewProjection, modelViewProjectionTransform);
_program->setUniform(_uniformCache.defaultColorStart, _colors.defaultStart);
_program->setUniform(_uniformCache.defaultColorEnd, _colors.defaultEnd);
_program->setUniform(_uniformCache.activeColor, _colors.active);
_program->setUniform(
_uniformCache.targetInFieldOfViewColor,
_colors.targetInFieldOfView
);
_program->setUniform(_uniformCache.intersectionStartColor, _colors.intersectionStart);
_program->setUniform(_uniformCache.intersectionEndColor, _colors.intersectionEnd);
_program->setUniform(_uniformCache.squareColor, _colors.square);
_program->setUniform(_uniformCache.interpolation, _interpolationTime);
glLineWidth(_lineWidth);
glBindVertexArray(_fieldOfViewBounds.vao);
glDrawArrays(GL_LINES, 0, static_cast<int>(_fieldOfViewBounds.data.size()));
glLineWidth(2.f);
glBindVertexArray(_orthogonalPlane.vao);
glDrawArrays(GL_LINE_LOOP, 0, static_cast<int>(_orthogonalPlane.data.size()));
glBindVertexArray(0);
glLineWidth(1.f);
_program->deactivate();
}
void RenderableFov::update(const UpdateData& data) {
_drawFOV = false;
if (openspace::ImageSequencer::ref().isReady()) {
if (ImageSequencer::ref().isReady()) {
_drawFOV = ImageSequencer::ref().isInstrumentActive(
data.time.j2000Seconds(),
_instrument.name
@@ -852,7 +790,7 @@ void RenderableFov::update(const UpdateData& data) {
if (_drawFOV /* && time changed */) {
const std::pair<std::string, bool>& t = determineTarget(data.time.j2000Seconds());
computeIntercepts(data, t.first, t.second);
computeIntercepts(data.time.j2000Seconds(), t.first, t.second);
updateGPU();
const double t2 = ImageSequencer::ref().nextCaptureTime(data.time.j2000Seconds());