mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 11:39:49 -06:00
Feature/textured points (#3068)
* WIP: Start usign texture arrays instead of just a single texture Now the texture array is sucessfully created, sent over and sampled on the GPU * Include information about the texture format alpha channel and do a conversion * Make one draw wcall per texture array * Add scale to size mapping and move to a separate component * WIP: Make single textures work again, with texture array Although this breaks the polygon cloud.. * Also make the polygon cloud work again * Refactor rendering code * handle array layer seprately from texture coordinates * Make sure use size mapping uniform is always set Fixes point cloud disappearing when multi-textures points are enabled * Add has value check to size mapping * Fix indentation * Make sure points are rendered even when no texture is used * Clean up texture handling a bit and add comment about storage creation * Add comment and temporary asset changes * Clean up handling of color mode (number of colro channels) * Make interpolated points work with new rendering code * Refactor * Bring back check for valid index for color and size data * Make sure to check if the provided data file exists * Fix full path ont showing in error message * Refactor rendering code a bit * Change how the multitexture setup is configured in the asset and add documentation Separating made documentation a lot easier.. * Add a todo comment for future discussion * Add settings for texture compression * Preserve aspects ratio of rendered textures * Restructure input parameters for texture details * Simplify color mode - we decided to not support grayscale * Add option to set "useAlpha" from asset * Enable texture per default and fix aspect ratio problem when no texture is used * tiny refactor * Fix polygon rendering that broke when adding texture compression * Remove color in polygon shader The color would be applied twice in rendering * Restructure textures code and prevent loading the same texture twice * Better handling of extra texture parameter in speck files That does not lead to limitations in using dashes in texture names * Add some docs and communicate texture mode to the user * Fix so that single texture can be changed during runtime * Allow changing compression and usealpha during runtime * Update texture storage allocation to something that works in older OpenGL versions * Add a check that checks if we use more texture layers than allowed * Even more robust check of texture line in speck file (allow extra whitespaces) * Update data mapping to include texture information and clean up code a bit * Error handling and prevent loading non-used textures in texture map * Update some docs * Small cleanup * Add one more error message for fault texture map file format * Remove test version of tully images dataset * Small refactor * Add example asset * Update Ghoul - for larger uniform cache * Purge texture from ram when we're done with it * Cleanup (comments, ugly png check, etc) * Apply suggestions from code review Co-authored-by: Alexander Bock <alexander.bock@liu.se> * Apply suggestions from code review * Adress some more review comments and fix broken asset * More code review fixes * Read provided sizemapping parameter from asset * Fix warnings from trying to shift 16 bit int 32 bits :) * simplify datamapping hash string * Update comment that was not 100% correct. The file names may be specified as relative paths to a folder * Small update based on previous code review comments * Fix multi textured points gui path not same as other points * Update Folder description to reduce some confusion * Apply suggestions from code review Co-authored-by: Ylva Selling <ylva.selling@gmail.com> * Prevent updates to polygon cloud texture during runtime This lead to rendering problems. * Add describing comments to data files * Clarify why speck version is disabled per default * Update and clarify confusing size mapping parameters * Apply suggestions from code review Co-authored-by: Ylva Selling <ylva.selling@gmail.com> * Apply suggestions from code review --------- Co-authored-by: Alexander Bock <alexander.bock@liu.se> Co-authored-by: Ylva Selling <ylva.selling@gmail.com>
This commit is contained in:
@@ -130,6 +130,10 @@ namespace {
|
||||
// the first set of positions for the objects, the next N rows to the second set of
|
||||
// positions, and so on. The number of objects in the dataset must be specified in the
|
||||
// asset.
|
||||
//
|
||||
// MultiTexture:
|
||||
// Note that if using multiple textures for the points based on values in the dataset,
|
||||
// the used texture will be decided based on the first N set of points.
|
||||
struct [[codegen::Dictionary(RenderableInterpolatedPoints)]] Parameters {
|
||||
// The number of objects to read from the dataset. Every N:th datapoint will
|
||||
// be interpreted as the same point, but at a different step in the interpolation
|
||||
@@ -328,13 +332,12 @@ void RenderableInterpolatedPoints::deinitializeShaders() {
|
||||
_program = nullptr;
|
||||
}
|
||||
|
||||
void RenderableInterpolatedPoints::bindDataForPointRendering() {
|
||||
RenderablePointCloud::bindDataForPointRendering();
|
||||
|
||||
void RenderableInterpolatedPoints::setExtraUniforms() {
|
||||
float t0 = computeCurrentLowerValue();
|
||||
float t = glm::clamp(_interpolation.value - t0, 0.f, 1.f);
|
||||
|
||||
_program->setUniform("interpolationValue", t);
|
||||
_program->setUniform("useSpline", _interpolation.useSpline);
|
||||
_program->setUniform("useSpline", useSplineInterpolation());
|
||||
}
|
||||
|
||||
void RenderableInterpolatedPoints::preUpdate() {
|
||||
@@ -346,103 +349,96 @@ void RenderableInterpolatedPoints::preUpdate() {
|
||||
|
||||
int RenderableInterpolatedPoints::nAttributesPerPoint() const {
|
||||
int n = RenderablePointCloud::nAttributesPerPoint();
|
||||
// Need twice as much information as the regular points
|
||||
n *= 2;
|
||||
if (_interpolation.useSpline) {
|
||||
|
||||
// Always at least three extra position values (xyz)
|
||||
n += 3;
|
||||
if (useSplineInterpolation()) {
|
||||
// Use two more positions (xyz)
|
||||
n += 2 * 3;
|
||||
}
|
||||
// And potentially some more color and size data
|
||||
n += _hasColorMapFile ? 1 : 0;
|
||||
n += _hasDatavarSize ? 1 : 0;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
std::vector<float> RenderableInterpolatedPoints::createDataSlice() {
|
||||
ZoneScoped;
|
||||
bool RenderableInterpolatedPoints::useSplineInterpolation() const {
|
||||
return _interpolation.useSpline && _interpolation.nSteps > 1;
|
||||
}
|
||||
|
||||
if (_dataset.entries.empty()) {
|
||||
return std::vector<float>();
|
||||
void RenderableInterpolatedPoints::addPositionDataForPoint(unsigned int index,
|
||||
std::vector<float>& result,
|
||||
double& maxRadius) const
|
||||
{
|
||||
using namespace dataloader;
|
||||
auto [firstIndex, secondIndex] = interpolationIndices(index);
|
||||
|
||||
const Dataset::Entry& e0 = _dataset.entries[firstIndex];
|
||||
const Dataset::Entry& e1 = _dataset.entries[secondIndex];
|
||||
|
||||
glm::dvec3 position0 = transformedPosition(e0);
|
||||
glm::dvec3 position1 = transformedPosition(e1);
|
||||
|
||||
const double r = glm::max(glm::length(position0), glm::length(position1));
|
||||
maxRadius = glm::max(maxRadius, r);
|
||||
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
result.push_back(static_cast<float>(position0[j]));
|
||||
}
|
||||
|
||||
std::vector<float> result;
|
||||
result.reserve(nAttributesPerPoint() * _nDataPoints);
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
result.push_back(static_cast<float>(position1[j]));
|
||||
}
|
||||
|
||||
// Find the information we need for the interpolation and to identify the points,
|
||||
// and make sure these result in valid indices in all cases
|
||||
float t0 = computeCurrentLowerValue();
|
||||
float t1 = t0 + 1.f;
|
||||
t1 = glm::clamp(t1, 0.f, _interpolation.value.maxValue());
|
||||
unsigned int t0Index = static_cast<unsigned int>(t0);
|
||||
unsigned int t1Index = static_cast<unsigned int>(t1);
|
||||
if (useSplineInterpolation()) {
|
||||
// Compute the extra positions, before and after the other ones. But make sure
|
||||
// we do not overflow the allowed bound for the current interpolation step
|
||||
int beforeIndex = glm::max(static_cast<int>(firstIndex - _nDataPoints), 0);
|
||||
int maxT = static_cast<int>(_interpolation.value.maxValue() - 1.f);
|
||||
int maxAllowedindex = maxT * _nDataPoints + index;
|
||||
int afterIndex = glm::min(
|
||||
static_cast<int>(secondIndex + _nDataPoints),
|
||||
maxAllowedindex
|
||||
);
|
||||
|
||||
const Dataset::Entry& e00 = _dataset.entries[beforeIndex];
|
||||
const Dataset::Entry& e11 = _dataset.entries[afterIndex];
|
||||
glm::dvec3 positionBefore = transformedPosition(e00);
|
||||
glm::dvec3 positionAfter = transformedPosition(e11);
|
||||
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
result.push_back(static_cast<float>(positionBefore[j]));
|
||||
}
|
||||
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
result.push_back(static_cast<float>(positionAfter[j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableInterpolatedPoints::addColorAndSizeDataForPoint(unsigned int index,
|
||||
std::vector<float>& result) const
|
||||
{
|
||||
using namespace dataloader;
|
||||
auto [firstIndex, secondIndex] = interpolationIndices(index);
|
||||
const Dataset::Entry& e0 = _dataset.entries[firstIndex];
|
||||
const Dataset::Entry& e1 = _dataset.entries[secondIndex];
|
||||
|
||||
// What datavar is in use for the index color
|
||||
int colorParamIndex = currentColorParameterIndex();
|
||||
|
||||
// What datavar is in use for the size scaling (if present)
|
||||
int sizeParamIndex = currentSizeParameterIndex();
|
||||
|
||||
double maxRadius = 0.0;
|
||||
|
||||
for (unsigned int i = 0; i < _nDataPoints; i++) {
|
||||
using namespace dataloader;
|
||||
const Dataset::Entry& e0 = _dataset.entries[t0Index * _nDataPoints + i];
|
||||
const Dataset::Entry& e1 = _dataset.entries[t1Index * _nDataPoints + i];
|
||||
glm::dvec3 position0 = transformedPosition(e0);
|
||||
glm::dvec3 position1 = transformedPosition(e1);
|
||||
|
||||
const double r = glm::max(glm::length(position0), glm::length(position1));
|
||||
maxRadius = glm::max(maxRadius, r);
|
||||
|
||||
// Positions
|
||||
for (int j = 0; j < 3; j++) {
|
||||
result.push_back(static_cast<float>(position0[j]));
|
||||
}
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
result.push_back(static_cast<float>(position1[j]));
|
||||
}
|
||||
|
||||
if (_interpolation.useSpline && _interpolation.nSteps > 1) {
|
||||
// Compute the extra positions, before and after the other ones
|
||||
unsigned int beforeIndex = static_cast<unsigned int>(
|
||||
glm::max(t0 - 1.f, 0.f)
|
||||
);
|
||||
unsigned int afterIndex = static_cast<unsigned int>(
|
||||
glm::min(t1 + 1.f, _interpolation.value.maxValue() - 1.f)
|
||||
);
|
||||
|
||||
const Dataset::Entry& e00 = _dataset.entries[beforeIndex * _nDataPoints + i];
|
||||
const Dataset::Entry& e11 = _dataset.entries[afterIndex * _nDataPoints + i];
|
||||
glm::dvec3 positionBefore = transformedPosition(e00);
|
||||
glm::dvec3 positionAfter = transformedPosition(e11);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
result.push_back(static_cast<float>(positionBefore[j]));
|
||||
}
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
result.push_back(static_cast<float>(positionAfter[j]));
|
||||
}
|
||||
}
|
||||
|
||||
// Colors
|
||||
if (_hasColorMapFile) {
|
||||
result.push_back(e0.data[colorParamIndex]);
|
||||
result.push_back(e1.data[colorParamIndex]);
|
||||
}
|
||||
|
||||
// Size data
|
||||
if (_hasDatavarSize) {
|
||||
// @TODO: Consider more detailed control over the scaling. Currently the value
|
||||
// is multiplied with the value as is. Should have similar mapping properties
|
||||
// as the color mapping
|
||||
result.push_back(e0.data[sizeParamIndex]);
|
||||
result.push_back(e1.data[sizeParamIndex]);
|
||||
}
|
||||
|
||||
// @TODO: Also need to update label positions, if we have created labels from the dataset
|
||||
// And make sure these are created from only the first set of points..
|
||||
if (_hasColorMapFile && colorParamIndex >= 0) {
|
||||
result.push_back(e0.data[colorParamIndex]);
|
||||
result.push_back(e1.data[colorParamIndex]);
|
||||
}
|
||||
|
||||
int sizeParamIndex = currentSizeParameterIndex();
|
||||
if (_hasDatavarSize && sizeParamIndex >= 0) {
|
||||
// @TODO: Consider more detailed control over the scaling. Currently the value
|
||||
// is multiplied with the value as is. Should have similar mapping properties
|
||||
// as the color mapping
|
||||
result.push_back(e0.data[sizeParamIndex]);
|
||||
result.push_back(e1.data[sizeParamIndex]);
|
||||
}
|
||||
setBoundingSphere(maxRadius);
|
||||
return result;
|
||||
}
|
||||
|
||||
void RenderableInterpolatedPoints::initializeBufferData() {
|
||||
@@ -463,40 +459,28 @@ void RenderableInterpolatedPoints::initializeBufferData() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
int attributeOffset = 0;
|
||||
int offset = 0;
|
||||
|
||||
auto addFloatAttribute = [&](const std::string& name, GLint nValues) {
|
||||
GLint attrib = _program->attributeLocation(name);
|
||||
glEnableVertexAttribArray(attrib);
|
||||
glVertexAttribPointer(
|
||||
attrib,
|
||||
nValues,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
attibutesPerPoint * sizeof(float),
|
||||
(attributeOffset > 0) ?
|
||||
reinterpret_cast<void*>(attributeOffset * sizeof(float)) :
|
||||
nullptr
|
||||
);
|
||||
attributeOffset += nValues;
|
||||
};
|
||||
offset = bufferVertexAttribute("in_position0", 3, attibutesPerPoint, offset);
|
||||
offset = bufferVertexAttribute("in_position1", 3, attibutesPerPoint, offset);
|
||||
|
||||
addFloatAttribute("in_position0", 3);
|
||||
addFloatAttribute("in_position1", 3);
|
||||
|
||||
if (_interpolation.useSpline) {
|
||||
addFloatAttribute("in_position_before", 3);
|
||||
addFloatAttribute("in_position_after", 3);
|
||||
if (useSplineInterpolation()) {
|
||||
offset = bufferVertexAttribute("in_position_before", 3, attibutesPerPoint, offset);
|
||||
offset = bufferVertexAttribute("in_position_after", 3, attibutesPerPoint, offset);
|
||||
}
|
||||
|
||||
if (_hasColorMapFile) {
|
||||
addFloatAttribute("in_colorParameter0", 1);
|
||||
addFloatAttribute("in_colorParameter1", 1);
|
||||
offset = bufferVertexAttribute("in_colorParameter0", 1, attibutesPerPoint, offset);
|
||||
offset = bufferVertexAttribute("in_colorParameter1", 1, attibutesPerPoint, offset);
|
||||
}
|
||||
|
||||
if (_hasDatavarSize) {
|
||||
addFloatAttribute("in_scalingParameter0", 1);
|
||||
addFloatAttribute("in_scalingParameter1", 1);
|
||||
offset = bufferVertexAttribute("in_scalingParameter0", 1, attibutesPerPoint, offset);
|
||||
offset = bufferVertexAttribute("in_scalingParameter1", 1, attibutesPerPoint, offset);
|
||||
}
|
||||
|
||||
if (_hasSpriteTexture) {
|
||||
offset = bufferVertexAttribute("in_textureLayer", 1, attibutesPerPoint, offset);
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
@@ -541,4 +525,25 @@ float RenderableInterpolatedPoints::computeCurrentLowerValue() const {
|
||||
return t0;
|
||||
}
|
||||
|
||||
float RenderableInterpolatedPoints::computeCurrentUpperValue() const {
|
||||
float t0 = computeCurrentLowerValue();
|
||||
float t1 = t0 + 1.f;
|
||||
t1 = glm::clamp(t1, 0.f, _interpolation.value.maxValue());
|
||||
return t1;
|
||||
}
|
||||
|
||||
std::pair<size_t, size_t>
|
||||
RenderableInterpolatedPoints::interpolationIndices(unsigned int index) const
|
||||
{
|
||||
float t0 = computeCurrentLowerValue();
|
||||
float t1 = computeCurrentUpperValue();
|
||||
unsigned int t0Index = static_cast<unsigned int>(t0);
|
||||
unsigned int t1Index = static_cast<unsigned int>(t1);
|
||||
|
||||
size_t lower = size_t(t0Index * _nDataPoints + index);
|
||||
size_t upper = size_t(t1Index * _nDataPoints + index);
|
||||
|
||||
return { lower, upper };
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -52,20 +52,34 @@ public:
|
||||
protected:
|
||||
void initializeShadersAndGlExtras() override;
|
||||
void deinitializeShaders() override;
|
||||
void bindDataForPointRendering() override;
|
||||
void setExtraUniforms() override;
|
||||
void preUpdate() override;
|
||||
|
||||
int nAttributesPerPoint() const override;
|
||||
|
||||
bool useSplineInterpolation() const;
|
||||
|
||||
/**
|
||||
* Create the data slice to use for rendering the points. Compared to the regular
|
||||
* point cloud, the data slice for an interpolated set of points will have to be
|
||||
* recreated when the interpolation value changes, and will only include a subset of
|
||||
* the points in the entire dataset
|
||||
* Create the rendering data for the positions for the point with the given index
|
||||
* and append that to the result. Compared to the base class, this class may require
|
||||
* 2-4 positions, depending on if * spline interpolation is used or not.
|
||||
*
|
||||
* \return The dataslice to use for rendering the points
|
||||
* The values are computed based on the current interpolation value.
|
||||
*
|
||||
* Also, compute the maxRadius to use for setting the bounding sphere.
|
||||
*/
|
||||
std::vector<float> createDataSlice() override;
|
||||
void addPositionDataForPoint(unsigned int index, std::vector<float>& result,
|
||||
double& maxRadius) const override;
|
||||
|
||||
/**
|
||||
* Create the rendering data for the color and size data for the point with the given
|
||||
* index and append that to the result. Compared to the base class, this class require
|
||||
* 2 values per data value, to use for interpolation.
|
||||
*
|
||||
* The values are computed based on the current interpolation value.
|
||||
*/
|
||||
void addColorAndSizeDataForPoint(unsigned int index,
|
||||
std::vector<float>& result) const override;
|
||||
|
||||
void initializeBufferData();
|
||||
void updateBufferData() override;
|
||||
@@ -73,6 +87,8 @@ protected:
|
||||
private:
|
||||
bool isAtKnot() const;
|
||||
float computeCurrentLowerValue() const;
|
||||
float computeCurrentUpperValue() const;
|
||||
std::pair<size_t, size_t> interpolationIndices(unsigned int index) const;
|
||||
|
||||
struct Interpolation : public properties::PropertyOwner {
|
||||
Interpolation();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <modules/base/rendering/pointcloud/sizemappingcomponent.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
@@ -52,6 +53,16 @@ namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
struct TextureFormat {
|
||||
glm::uvec2 resolution;
|
||||
bool useAlpha = false;
|
||||
|
||||
friend bool operator==(const TextureFormat& l, const TextureFormat& r);
|
||||
};
|
||||
struct TextureFormatHash {
|
||||
size_t operator()(const TextureFormat& k) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class describes a point cloud renderable that can be used to draw billboraded
|
||||
* points based on a data file with 3D positions. Alternatively the points can also
|
||||
@@ -74,15 +85,30 @@ public:
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
protected:
|
||||
enum class TextureInputMode {
|
||||
Single = 0,
|
||||
Multi,
|
||||
Other // For subclasses that need to handle their own texture
|
||||
};
|
||||
|
||||
virtual void initializeShadersAndGlExtras();
|
||||
virtual void deinitializeShaders();
|
||||
virtual void bindDataForPointRendering();
|
||||
virtual void setExtraUniforms();
|
||||
virtual void preUpdate();
|
||||
|
||||
glm::dvec3 transformedPosition(const dataloader::Dataset::Entry& e) const;
|
||||
|
||||
virtual int nAttributesPerPoint() const;
|
||||
|
||||
/**
|
||||
* Helper function to buffer the vertex attribute with the given name and number
|
||||
* of values. Assumes that the value is a float value.
|
||||
*
|
||||
* Returns the updated offset after this attribute is added
|
||||
*/
|
||||
int bufferVertexAttribute(const std::string& name, GLint nValues,
|
||||
int nAttributesPerPoint, int offset) const;
|
||||
|
||||
virtual void updateBufferData();
|
||||
void updateSpriteTexture();
|
||||
|
||||
@@ -91,17 +117,42 @@ protected:
|
||||
/// Find the index of the currently chosen size parameter in the dataset
|
||||
int currentSizeParameterIndex() const;
|
||||
|
||||
virtual std::vector<float> createDataSlice();
|
||||
virtual void addPositionDataForPoint(unsigned int index, std::vector<float>& result,
|
||||
double& maxRadius) const;
|
||||
virtual void addColorAndSizeDataForPoint(unsigned int index,
|
||||
std::vector<float>& result) const;
|
||||
|
||||
virtual void bindTextureForRendering() const;
|
||||
std::vector<float> createDataSlice();
|
||||
|
||||
/**
|
||||
* A function that subclasses could override to initialize their own textures to
|
||||
* use for rendering, when the `_textureMode` is set to Other
|
||||
*/
|
||||
virtual void initializeCustomTexture();
|
||||
void initializeSingleTexture();
|
||||
void initializeMultiTextures();
|
||||
void clearTextureDataStructures();
|
||||
|
||||
void loadTexture(const std::filesystem::path& path, int index);
|
||||
|
||||
void initAndAllocateTextureArray(unsigned int textureId,
|
||||
glm::uvec2 resolution, size_t nLayers, bool useAlpha);
|
||||
|
||||
void fillAndUploadTextureLayer(unsigned int arrayindex, unsigned int layer,
|
||||
size_t textureIndex, glm::uvec2 resolution, bool useAlpha, const void* pixelData);
|
||||
|
||||
void generateArrayTextures();
|
||||
|
||||
float computeDistanceFadeValue(const RenderData& data) const;
|
||||
|
||||
void renderBillboards(const RenderData& data, const glm::dmat4& modelMatrix,
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
|
||||
|
||||
gl::GLenum internalGlFormat(bool useAlpha) const;
|
||||
ghoul::opengl::Texture::Format glFormat(bool useAlpha) const;
|
||||
|
||||
bool _dataIsDirty = true;
|
||||
bool _spriteTextureIsDirty = true;
|
||||
bool _spriteTextureIsDirty = false;
|
||||
bool _cmapIsDirty = true;
|
||||
|
||||
bool _hasSpriteTexture = false;
|
||||
@@ -113,12 +164,7 @@ protected:
|
||||
struct SizeSettings : properties::PropertyOwner {
|
||||
explicit SizeSettings(const ghoul::Dictionary& dictionary);
|
||||
|
||||
struct SizeMapping : properties::PropertyOwner {
|
||||
SizeMapping();
|
||||
properties::BoolProperty enabled;
|
||||
properties::OptionProperty parameterOption;
|
||||
};
|
||||
SizeMapping sizeMapping;
|
||||
std::unique_ptr<SizeMappingComponent> sizeMapping;
|
||||
|
||||
properties::FloatProperty scaleExponent;
|
||||
properties::FloatProperty scaleFactor;
|
||||
@@ -146,9 +192,6 @@ protected:
|
||||
};
|
||||
Fading _fading;
|
||||
|
||||
properties::BoolProperty _useSpriteTexture;
|
||||
properties::StringProperty _spriteTexturePath;
|
||||
|
||||
properties::BoolProperty _useAdditiveBlending;
|
||||
|
||||
properties::BoolProperty _drawElements;
|
||||
@@ -156,7 +199,18 @@ protected:
|
||||
|
||||
properties::UIntProperty _nDataPoints;
|
||||
|
||||
ghoul::opengl::Texture* _spriteTexture = nullptr;
|
||||
struct Texture : properties::PropertyOwner {
|
||||
Texture();
|
||||
properties::BoolProperty enabled;
|
||||
properties::BoolProperty allowCompression;
|
||||
properties::BoolProperty useAlphaChannel;
|
||||
properties::StringProperty spriteTexturePath;
|
||||
properties::StringProperty inputMode;
|
||||
};
|
||||
Texture _texture;
|
||||
TextureInputMode _textureMode = TextureInputMode::Single;
|
||||
std::filesystem::path _texturesDirectory;
|
||||
|
||||
ghoul::opengl::ProgramObject* _program = nullptr;
|
||||
|
||||
UniformCache(
|
||||
@@ -165,7 +219,8 @@ protected:
|
||||
right, fadeInValue, hasSpriteTexture, spriteTexture, useColormap, colorMapTexture,
|
||||
cmapRangeMin, cmapRangeMax, nanColor, useNanColor, hideOutsideRange,
|
||||
enableMaxSizeControl, aboveRangeColor, useAboveRangeColor, belowRangeColor,
|
||||
useBelowRangeColor, hasDvarScaling, enableOutline, outlineColor, outlineWeight
|
||||
useBelowRangeColor, hasDvarScaling, dvarScaleFactor, enableOutline, outlineColor,
|
||||
outlineWeight, aspectRatioScale
|
||||
) _uniformCache;
|
||||
|
||||
std::string _dataFile;
|
||||
@@ -181,6 +236,33 @@ protected:
|
||||
|
||||
GLuint _vao = 0;
|
||||
GLuint _vbo = 0;
|
||||
|
||||
// List of (unique) loaded textures. The other maps refer to the index in this vector
|
||||
std::vector<std::unique_ptr<ghoul::opengl::Texture>> _textures;
|
||||
std::unordered_map<std::string, size_t> _textureNameToIndex;
|
||||
|
||||
// Texture index in dataset to index in vector of textures
|
||||
std::unordered_map<int, size_t> _indexInDataToTextureIndex;
|
||||
|
||||
// Resolution/format to index in textures vector (used to generate one texture
|
||||
// array per unique format)
|
||||
std::unordered_map<TextureFormat, std::vector<size_t>, TextureFormatHash>
|
||||
_textureMapByFormat;
|
||||
|
||||
// One per resolution above
|
||||
struct TextureArrayInfo {
|
||||
GLuint renderId;
|
||||
GLint startOffset = -1;
|
||||
int nPoints = -1;
|
||||
glm::vec2 aspectRatioScale = glm::vec2(1.f);
|
||||
};
|
||||
std::vector<TextureArrayInfo> _textureArrays;
|
||||
|
||||
struct TextureId {
|
||||
unsigned int arrayId;
|
||||
unsigned int layer;
|
||||
};
|
||||
std::unordered_map<size_t, TextureId> _textureIndexToArrayMap;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -38,8 +38,9 @@ namespace {
|
||||
// A RenderablePolygonCloud is a RenderablePointCloud where the shape of the points
|
||||
// is a uniform polygon with a given number of sides instead of a texture. For
|
||||
// instance, PolygonSides = 5 results in the points being rendered as pentagons.
|
||||
// Note that while this renderable inherits the texture property from
|
||||
// RenderablePointCloud, any added texture value will be ignored in favor of the
|
||||
//
|
||||
// Note that while this renderable inherits the texture component from
|
||||
// RenderablePointCloud, any added texture information will be ignored in favor of the
|
||||
// polygon shape.
|
||||
//
|
||||
// See documentation of RenderablePointCloud for details on the other parts of the
|
||||
@@ -70,15 +71,11 @@ RenderablePolygonCloud::RenderablePolygonCloud(const ghoul::Dictionary& dictiona
|
||||
_nPolygonSides = p.polygonSides.value_or(_nPolygonSides);
|
||||
|
||||
// The texture to use for the rendering will be generated in initializeGl. Make sure
|
||||
// we use it in the rnedering
|
||||
// we use it in the rendering
|
||||
_hasSpriteTexture = true;
|
||||
}
|
||||
|
||||
void RenderablePolygonCloud::initializeGL() {
|
||||
ZoneScoped;
|
||||
|
||||
RenderablePointCloud::initializeGL();
|
||||
createPolygonTexture();
|
||||
_textureMode = TextureInputMode::Other;
|
||||
removePropertySubOwner(_texture);
|
||||
}
|
||||
|
||||
void RenderablePolygonCloud::deinitializeGL() {
|
||||
@@ -92,16 +89,24 @@ void RenderablePolygonCloud::deinitializeGL() {
|
||||
RenderablePointCloud::deinitializeGL();
|
||||
}
|
||||
|
||||
void RenderablePolygonCloud::bindTextureForRendering() const {
|
||||
glBindTexture(GL_TEXTURE_2D, _pTexture);
|
||||
}
|
||||
|
||||
void RenderablePolygonCloud::createPolygonTexture() {
|
||||
void RenderablePolygonCloud::initializeCustomTexture() {
|
||||
ZoneScoped;
|
||||
|
||||
if (_textureIsInitialized) {
|
||||
LWARNING("RenderablePolygonCloud texture cannot be updated during runtime");
|
||||
return;
|
||||
}
|
||||
|
||||
LDEBUG("Creating Polygon Texture");
|
||||
constexpr gl::GLsizei TexSize = 512;
|
||||
|
||||
// We don't use the helper function for the format and internal format here,
|
||||
// as we don't want the compression to be used for the polygon texture and we
|
||||
// always want alpha. This is also why we do not need to update the texture
|
||||
bool useAlpha = true;
|
||||
gl::GLenum format = gl::GLenum(glFormat(useAlpha));
|
||||
gl::GLenum internalFormat = GL_RGBA8;
|
||||
|
||||
glGenTextures(1, &_pTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, _pTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
@@ -113,16 +118,35 @@ void RenderablePolygonCloud::createPolygonTexture() {
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
internalFormat,
|
||||
TexSize,
|
||||
TexSize,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_BYTE,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
nullptr
|
||||
);
|
||||
|
||||
renderToTexture(_pTexture, TexSize, TexSize);
|
||||
|
||||
// Download the data and use it to intialize the data we need to rendering.
|
||||
// Allocate memory: N channels, with one byte each
|
||||
constexpr unsigned int nChannels = 4;
|
||||
unsigned int arraySize = TexSize * TexSize * nChannels;
|
||||
std::vector<GLubyte> pixelData;
|
||||
pixelData.resize(arraySize);
|
||||
glBindTexture(GL_TEXTURE_2D, _pTexture);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, format, GL_UNSIGNED_BYTE, pixelData.data());
|
||||
|
||||
// Create array from data, size and format
|
||||
unsigned int id = 0;
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, id);
|
||||
initAndAllocateTextureArray(id, glm::uvec2(TexSize), 1, useAlpha);
|
||||
fillAndUploadTextureLayer(0, 0, 0, glm::uvec2(TexSize), useAlpha, pixelData.data());
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
|
||||
|
||||
_textureIsInitialized = true;
|
||||
}
|
||||
|
||||
void RenderablePolygonCloud::renderToTexture(GLuint textureToRenderTo,
|
||||
@@ -191,7 +215,6 @@ void RenderablePolygonCloud::renderPolygonGeometry(GLuint vao) {
|
||||
glClearBufferfv(GL_COLOR, 0, glm::value_ptr(Black));
|
||||
|
||||
program->setUniform("sides", _nPolygonSides);
|
||||
program->setUniform("polygonColor", _colorSettings.pointColor);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_POINTS, 0, 1);
|
||||
|
||||
@@ -44,25 +44,24 @@ public:
|
||||
explicit RenderablePolygonCloud(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePolygonCloud() override = default;
|
||||
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
void createPolygonTexture();
|
||||
void initializeCustomTexture() override;
|
||||
void renderToTexture(GLuint textureToRenderTo, GLuint textureWidth,
|
||||
GLuint textureHeight);
|
||||
void renderPolygonGeometry(GLuint vao);
|
||||
|
||||
void bindTextureForRendering() const override;
|
||||
|
||||
int _nPolygonSides = 3;
|
||||
|
||||
GLuint _pTexture = 0;
|
||||
|
||||
GLuint _polygonVao = 0;
|
||||
GLuint _polygonVbo = 0;
|
||||
|
||||
bool _textureIsInitialized = false;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
131
modules/base/rendering/pointcloud/sizemappingcomponent.cpp
Normal file
131
modules/base/rendering/pointcloud/sizemappingcomponent.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2024 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/base/rendering/pointcloud/sizemappingcomponent.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
namespace {
|
||||
constexpr std::string_view _loggerCat = "SizeMapping";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo EnabledInfo = {
|
||||
"Enabled",
|
||||
"Size Mapping Enabled",
|
||||
"If this value is set to 'true' and at least one column was loaded as an option "
|
||||
"for size mapping, the chosen data column will be used to scale the size of the "
|
||||
"points. The first option in the list is selected per default.",
|
||||
openspace::properties::Property::Visibility::NoviceUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo OptionInfo = {
|
||||
"Parameter",
|
||||
"Parameter Option",
|
||||
"This value determines which parameter is used for scaling of the point. The "
|
||||
"parameter value will be used as a multiplicative factor to scale the size of "
|
||||
"the points. Note that they may however still be scaled by max size adjustment "
|
||||
"effects.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo ScaleFactorInfo = {
|
||||
"ScaleFactor",
|
||||
"Scale Factor",
|
||||
"This value is a multiplicative factor that is applied to the data values that "
|
||||
"are used to scale the points, when size mapping is applied.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(SizeMappingComponent)]] Parameters {
|
||||
// [[codegen::verbatim(EnabledInfo.description)]]
|
||||
std::optional<bool> enabled;
|
||||
|
||||
// A list specifying all parameters that may be used for size mapping, i.e.
|
||||
// scaling the points based on the provided data columns
|
||||
std::optional<std::vector<std::string>> parameterOptions;
|
||||
|
||||
// [[codegen::verbatim(OptionInfo.description)]]
|
||||
std::optional<std::string> parameter;
|
||||
|
||||
// [[codegen::verbatim(ScaleFactorInfo.description)]]
|
||||
std::optional<float> scaleFactor;
|
||||
};
|
||||
#include "sizemappingcomponent_codegen.cpp"
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation SizeMappingComponent::Documentation() {
|
||||
return codegen::doc<Parameters>("base_sizemappingcomponent");
|
||||
}
|
||||
|
||||
SizeMappingComponent::SizeMappingComponent()
|
||||
: properties::PropertyOwner({ "SizeMapping", "Size Mapping", "" })
|
||||
, enabled(EnabledInfo, true)
|
||||
, parameterOption(
|
||||
OptionInfo,
|
||||
properties::OptionProperty::DisplayType::Dropdown
|
||||
)
|
||||
, scaleFactor(ScaleFactorInfo, 1.f, 0.f, 1000.f)
|
||||
{
|
||||
addProperty(enabled);
|
||||
addProperty(parameterOption);
|
||||
addProperty(scaleFactor);
|
||||
}
|
||||
|
||||
SizeMappingComponent::SizeMappingComponent(const ghoul::Dictionary& dictionary)
|
||||
: SizeMappingComponent()
|
||||
{
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
enabled = p.enabled.value_or(enabled);
|
||||
|
||||
int indexOfProvidedOption = -1;
|
||||
|
||||
if (p.parameterOptions.has_value()) {
|
||||
std::vector<std::string> opts = *p.parameterOptions;
|
||||
for (size_t i = 0; i < opts.size(); ++i) {
|
||||
// Note that options are added in order
|
||||
parameterOption.addOption(static_cast<int>(i), opts[i]);
|
||||
|
||||
if (p.parameter.has_value() && *p.parameter == opts[i]) {
|
||||
indexOfProvidedOption = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (indexOfProvidedOption >= 0) {
|
||||
parameterOption = indexOfProvidedOption;
|
||||
}
|
||||
else if (p.parameter.has_value()) {
|
||||
LERROR(fmt::format(
|
||||
"Error when reading Parameter. Could not find provided parameter '{}' in "
|
||||
"list of parameter options. Using default.", *p.parameter
|
||||
));
|
||||
}
|
||||
|
||||
scaleFactor = p.scaleFactor.value_or(scaleFactor);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
56
modules/base/rendering/pointcloud/sizemappingcomponent.h
Normal file
56
modules/base/rendering/pointcloud/sizemappingcomponent.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2024 *
|
||||
* *
|
||||
* 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_BASE___SIZEMAPPINGCOMPONENT___H__
|
||||
#define __OPENSPACE_MODULE_BASE___SIZEMAPPINGCOMPONENT___H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
/**
|
||||
* This is a component that can be used to hold parameters and properties for scaling
|
||||
* point cloud points (or other data-based entities) based a parameter in a dataset.
|
||||
*/
|
||||
struct SizeMappingComponent : public properties::PropertyOwner {
|
||||
SizeMappingComponent();
|
||||
explicit SizeMappingComponent(const ghoul::Dictionary& dictionary);
|
||||
~SizeMappingComponent() override = default;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
properties::BoolProperty enabled;
|
||||
properties::OptionProperty parameterOption;
|
||||
properties::FloatProperty scaleFactor;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_BASE___SIZEMAPPINGCOMPONENT___H__
|
||||
Reference in New Issue
Block a user