Merge branch 'master' into feature/statlogs

* master:
  Make console work with Fisheye rendering
  Correctly position Screenspace renderable if a scene tag is specified
  Move SGCT config files into main config folder and remove unused transferfunctions
  Increasing warning level
This commit is contained in:
Matthew Territo
2017-07-09 23:16:32 -06:00
35 changed files with 7233 additions and 7253 deletions

View File

@@ -1,84 +1,84 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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/globebrowsing/other/pixelbuffer.h>
#include <ghoul/logging/logmanager.h>
namespace {
const char* _loggerCat = "PixelBuffer";
};
using namespace openspace::globebrowsing;
PixelBuffer::PixelBuffer(size_t numBytes, Usage usage)
: _numBytes(numBytes)
, _usage(usage)
, _isMapped(false)
{
glGenBuffers(1, &_id);
bind();
glBufferData(GL_PIXEL_UNPACK_BUFFER, _numBytes, 0, static_cast<GLenum>(_usage));
unbind();
}
PixelBuffer::~PixelBuffer() {
glDeleteBuffers(1, &_id);
}
void* PixelBuffer::mapBuffer(Access access) {
void* dataPtr = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, static_cast<GLenum>(access));
_isMapped = dataPtr ? true : false;
return dataPtr;
}
void* PixelBuffer::mapBufferRange(GLintptr offset, GLsizeiptr length, BufferAccessMask access) {
void* dataPtr = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, offset, length, access);
_isMapped = dataPtr ? true : false;
return dataPtr;
}
bool PixelBuffer::unMapBuffer() {
GLboolean success = glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
if (!success) {
LERROR("Unable to unmap pixel buffer, data may be corrupt!");
}
_isMapped = false;
return success == GL_TRUE;
}
void PixelBuffer::bind() {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _id);
}
void PixelBuffer::unbind() {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
bool PixelBuffer::isMapped() const {
return _isMapped;
}
PixelBuffer::operator GLuint() const {
return _id;
}
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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/globebrowsing/other/pixelbuffer.h>
#include <ghoul/logging/logmanager.h>
namespace {
const char* _loggerCat = "PixelBuffer";
};
using namespace openspace::globebrowsing;
PixelBuffer::PixelBuffer(size_t numBytes, Usage usage)
: _numBytes(numBytes)
, _usage(usage)
, _isMapped(false)
{
glGenBuffers(1, &_id);
bind();
glBufferData(GL_PIXEL_UNPACK_BUFFER, _numBytes, 0, static_cast<GLenum>(_usage));
unbind();
}
PixelBuffer::~PixelBuffer() {
glDeleteBuffers(1, &_id);
}
void* PixelBuffer::mapBuffer(Access access) {
void* dataPtr = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, static_cast<GLenum>(access));
_isMapped = dataPtr ? true : false;
return dataPtr;
}
void* PixelBuffer::mapBufferRange(GLintptr offset, GLsizeiptr length, BufferAccessMask access) {
void* dataPtr = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, offset, length, access);
_isMapped = dataPtr ? true : false;
return dataPtr;
}
bool PixelBuffer::unMapBuffer() {
GLboolean success = glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
if (!success) {
LERROR("Unable to unmap pixel buffer, data may be corrupt!");
}
_isMapped = false;
return success == GL_TRUE;
}
void PixelBuffer::bind() {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _id);
}
void PixelBuffer::unbind() {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
bool PixelBuffer::isMapped() const {
return _isMapped;
}
PixelBuffer::operator GLuint() const {
return _id;
}

View File

@@ -1,140 +1,140 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___PIXEL_BUFFER___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER___H__
#include <ghoul/opengl/ghoul_gl.h>
namespace openspace {
namespace globebrowsing {
/**
* Handles an OpenGL pixel buffer which contains data allocated on the GPU. A simple
* class that wraps the standard functionality of OpenGL pixel buffer objects. Once
* the PixelBuffer is created, data is allocated on the GPU. When mapping data to a
* address pointer, the user needs to ensure the data is unmapped before the data can
* be used on the GPU / CPU depending on Usage.
*/
class PixelBuffer
{
public:
/**
* All kinds of usage for pixel buffer objects as defined by the OpenGL standard.
* See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferData.xhtml
*/
enum class Usage : std::underlying_type_t<GLenum> {
StreamDraw = static_cast<std::underlying_type_t<GLenum>>(GL_STREAM_DRAW),
StreamRead = static_cast<std::underlying_type_t<GLenum>>(GL_STREAM_READ),
StreamCopy = static_cast<std::underlying_type_t<GLenum>>(GL_STREAM_COPY),
StaticDraw = static_cast<std::underlying_type_t<GLenum>>(GL_STATIC_DRAW),
StaticRead = static_cast<std::underlying_type_t<GLenum>>(GL_STATIC_READ),
StaticCopy = static_cast<std::underlying_type_t<GLenum>>(GL_STATIC_COPY),
DynamicDraw = static_cast<std::underlying_type_t<GLenum>>(GL_DYNAMIC_DRAW),
DynamicRead = static_cast<std::underlying_type_t<GLenum>>(GL_DYNAMIC_READ),
DynamicCopy = static_cast<std::underlying_type_t<GLenum>>(GL_DYNAMIC_COPY)
};
/**
* Access hints for OpenGL buffer mapping
* See: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glMapBuffer.xml
*/
enum class Access : std::underlying_type_t<GLenum> {
ReadOnly = static_cast<std::underlying_type_t<GLenum>>(GL_READ_ONLY),
WriteOnly = static_cast<std::underlying_type_t<GLenum>>(GL_WRITE_ONLY),
ReadWrite = static_cast<std::underlying_type_t<GLenum>>(GL_READ_WRITE)
};
/**
* Allocates <code>numBytes</code> bytes on the GPU and creates an ID for the pixel
* buffer object.
* \param numBytes is the number of bytes to be allocated on GPU memory
* \param usage is the <code>Usage</code> for the pixel buffer
*/
PixelBuffer(size_t numBytes, Usage usage);
/**
* calls glDeleteBuffers().
*/
~PixelBuffer();
/**
* Maps an address pointer to GPU direct memory access. The user must make sure the
* buffer is bound before calling this function.
* \param access is the access to which can be any of <code>GL_READ_ONLY</code>,
* <code>GL_WRITE_ONLY</code>, or <code>GL_READ_WRITE</code>
* \returns the DMA address to the mapped buffer. Returns nullptr if the mapping
* failed
*/
void* mapBuffer(Access access);
/**
* Maps an address pointer to GPU direct memory access. Gives access to a range of
* the buffer. The user must make sure the buffer is bound before calling this
* function.
* \param offet is the number of bytes to the first address to get in the buffer
* \param length is the number of bytes to access in the buffer
* \param access is a bitfield describing the access as described in:
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glMapBufferRange.xhtml
* \returns the DMA address to the mapped buffer. Returns nullptr if the mapping
* failed
*/
void* mapBufferRange(GLintptr offset, GLsizeiptr length, BufferAccessMask access);
/**
* Maps the default buffer and makes the data available on the GPU
*/
bool unMapBuffer();
/**
* Calls glBindBuffer()
*/
void bind();
/**
* Calls glBindBuffer() with argument 0 to unmap any pixel buffer
*/
void unbind();
/**
* \returns true of the buffer is mapped, otherwise false
*/
bool isMapped() const;
/**
* \returns the OpenGL id of the pixel buffer object
*/
operator GLuint() const;
private:
GLuint _id;
const size_t _numBytes;
const Usage _usage;
bool _isMapped;
};
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER___H__
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___PIXEL_BUFFER___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER___H__
#include <ghoul/opengl/ghoul_gl.h>
namespace openspace {
namespace globebrowsing {
/**
* Handles an OpenGL pixel buffer which contains data allocated on the GPU. A simple
* class that wraps the standard functionality of OpenGL pixel buffer objects. Once
* the PixelBuffer is created, data is allocated on the GPU. When mapping data to a
* address pointer, the user needs to ensure the data is unmapped before the data can
* be used on the GPU / CPU depending on Usage.
*/
class PixelBuffer
{
public:
/**
* All kinds of usage for pixel buffer objects as defined by the OpenGL standard.
* See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferData.xhtml
*/
enum class Usage : std::underlying_type_t<GLenum> {
StreamDraw = static_cast<std::underlying_type_t<GLenum>>(GL_STREAM_DRAW),
StreamRead = static_cast<std::underlying_type_t<GLenum>>(GL_STREAM_READ),
StreamCopy = static_cast<std::underlying_type_t<GLenum>>(GL_STREAM_COPY),
StaticDraw = static_cast<std::underlying_type_t<GLenum>>(GL_STATIC_DRAW),
StaticRead = static_cast<std::underlying_type_t<GLenum>>(GL_STATIC_READ),
StaticCopy = static_cast<std::underlying_type_t<GLenum>>(GL_STATIC_COPY),
DynamicDraw = static_cast<std::underlying_type_t<GLenum>>(GL_DYNAMIC_DRAW),
DynamicRead = static_cast<std::underlying_type_t<GLenum>>(GL_DYNAMIC_READ),
DynamicCopy = static_cast<std::underlying_type_t<GLenum>>(GL_DYNAMIC_COPY)
};
/**
* Access hints for OpenGL buffer mapping
* See: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glMapBuffer.xml
*/
enum class Access : std::underlying_type_t<GLenum> {
ReadOnly = static_cast<std::underlying_type_t<GLenum>>(GL_READ_ONLY),
WriteOnly = static_cast<std::underlying_type_t<GLenum>>(GL_WRITE_ONLY),
ReadWrite = static_cast<std::underlying_type_t<GLenum>>(GL_READ_WRITE)
};
/**
* Allocates <code>numBytes</code> bytes on the GPU and creates an ID for the pixel
* buffer object.
* \param numBytes is the number of bytes to be allocated on GPU memory
* \param usage is the <code>Usage</code> for the pixel buffer
*/
PixelBuffer(size_t numBytes, Usage usage);
/**
* calls glDeleteBuffers().
*/
~PixelBuffer();
/**
* Maps an address pointer to GPU direct memory access. The user must make sure the
* buffer is bound before calling this function.
* \param access is the access to which can be any of <code>GL_READ_ONLY</code>,
* <code>GL_WRITE_ONLY</code>, or <code>GL_READ_WRITE</code>
* \returns the DMA address to the mapped buffer. Returns nullptr if the mapping
* failed
*/
void* mapBuffer(Access access);
/**
* Maps an address pointer to GPU direct memory access. Gives access to a range of
* the buffer. The user must make sure the buffer is bound before calling this
* function.
* \param offet is the number of bytes to the first address to get in the buffer
* \param length is the number of bytes to access in the buffer
* \param access is a bitfield describing the access as described in:
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glMapBufferRange.xhtml
* \returns the DMA address to the mapped buffer. Returns nullptr if the mapping
* failed
*/
void* mapBufferRange(GLintptr offset, GLsizeiptr length, BufferAccessMask access);
/**
* Maps the default buffer and makes the data available on the GPU
*/
bool unMapBuffer();
/**
* Calls glBindBuffer()
*/
void bind();
/**
* Calls glBindBuffer() with argument 0 to unmap any pixel buffer
*/
void unbind();
/**
* \returns true of the buffer is mapped, otherwise false
*/
bool isMapped() const;
/**
* \returns the OpenGL id of the pixel buffer object
*/
operator GLuint() const;
private:
GLuint _id;
const size_t _numBytes;
const Usage _usage;
bool _isMapped;
};
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER___H__

View File

@@ -1,115 +1,115 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___PIXEL_BUFFER_CONTAINER___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER_CONTAINER___H__
#include <modules/globebrowsing/other/pixelbuffer.h>
#include <map>
namespace openspace {
namespace globebrowsing {
/**
* Templated class which owns one or many <code>PixelBuffer</code>s. The
* <code>KeyType</code> is used to map a pixel buffer but only if it is not already
* mapped.
*/
template <class KeyType>
class PixelBufferContainer
{
public:
/**
* Creates numPixelBuffers pixel buffer objects, each with numBytesPerBuffer bytes
* allocated on the GPU.
* \param numBytesPerBuffer is the number of bytes per pixel buffer. All pixel
* buffers within a <code>PixelBufferContainer</code> have the same number of bytes
* \param usage is the <code>Usage</code> as described by <code>PixelBuffer</code>
* \param numPixelBuffers is the number of pixel buffers to create for this container.
* If numPixelBuffers is omitted, no pixel buffers are created.
*/
PixelBufferContainer(size_t numBytesPerBuffer,
globebrowsing::PixelBuffer::Usage usage, size_t numPixelBuffers = 0);
~PixelBufferContainer() = default;
/**
* Finds a Pixel buffer and maps it if it is available.
* \param key is the identifier for the pixel buffer which can be used later when
* unmapping the mapped pixel buffer.
* \param access is the access as described by <code>PixelBuffer</code>
* \returns an address pointer to DMA if the mapping succeeded. Otherwise a nullptr
* is returned. The mapping can fail if the buffer identified with <code>key</code>
* is already mapped or if something else failed.
*/
void* mapBuffer(KeyType key, PixelBuffer::Access access);
/**
* Finds a Pixel buffer and maps a range of it if it is available.
* \param key is the identifier for the pixel buffer which can be used later when
* unmapping the mapped pixel buffer.
* \param offet is the number of bytes to the first address to get in the buffer
* \param length is the number of bytes to access in the buffer
* \param access is the access as described by <code>PixelBuffer</code>
* \returns an address pointer to DMA if the mapping succeeded. Otherwise a nullptr
* is returned. The mapping can fail if the buffer identified with <code>key</code>
* is already mapped or if something else failed.
*/
void* mapBufferRange(KeyType key, GLintptr offset, GLsizeiptr length,
BufferAccessMask access);
/**
* Unmaps all buffers in the PixelBufferContainer.
* \returns true if the unmapping succeeded, otherwise false.
*/
bool resetMappedBuffers();
/**
* Unmaps a buffer that has previously been mapped. This buffer is identified using
* <code>key</code>.
* \param key is the identifier of the mapped buffer.
* \returns true if the unmapping succeeded, otherwise false.
*/
bool unMapBuffer(KeyType key);
/**
* \returns the <code>GLuint</code> id of a pixel buffer identified by <code>key</code>
* if it currently is mapped.
*/
GLuint idOfMappedBuffer(KeyType key);
private:
const globebrowsing::PixelBuffer::Usage _usage;
std::vector<std::unique_ptr<PixelBuffer>> _pixelBuffers;
// Maps from KeyType to index of mapped buffers
std::map<KeyType, int> _indexMap;
};
} // namespace globebrowsing
} // namespace openspace
#include "pixelbuffercontainer.inl"
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER_CONTAINER___H__
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___PIXEL_BUFFER_CONTAINER___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER_CONTAINER___H__
#include <modules/globebrowsing/other/pixelbuffer.h>
#include <map>
namespace openspace {
namespace globebrowsing {
/**
* Templated class which owns one or many <code>PixelBuffer</code>s. The
* <code>KeyType</code> is used to map a pixel buffer but only if it is not already
* mapped.
*/
template <class KeyType>
class PixelBufferContainer
{
public:
/**
* Creates numPixelBuffers pixel buffer objects, each with numBytesPerBuffer bytes
* allocated on the GPU.
* \param numBytesPerBuffer is the number of bytes per pixel buffer. All pixel
* buffers within a <code>PixelBufferContainer</code> have the same number of bytes
* \param usage is the <code>Usage</code> as described by <code>PixelBuffer</code>
* \param numPixelBuffers is the number of pixel buffers to create for this container.
* If numPixelBuffers is omitted, no pixel buffers are created.
*/
PixelBufferContainer(size_t numBytesPerBuffer,
globebrowsing::PixelBuffer::Usage usage, size_t numPixelBuffers = 0);
~PixelBufferContainer() = default;
/**
* Finds a Pixel buffer and maps it if it is available.
* \param key is the identifier for the pixel buffer which can be used later when
* unmapping the mapped pixel buffer.
* \param access is the access as described by <code>PixelBuffer</code>
* \returns an address pointer to DMA if the mapping succeeded. Otherwise a nullptr
* is returned. The mapping can fail if the buffer identified with <code>key</code>
* is already mapped or if something else failed.
*/
void* mapBuffer(KeyType key, PixelBuffer::Access access);
/**
* Finds a Pixel buffer and maps a range of it if it is available.
* \param key is the identifier for the pixel buffer which can be used later when
* unmapping the mapped pixel buffer.
* \param offet is the number of bytes to the first address to get in the buffer
* \param length is the number of bytes to access in the buffer
* \param access is the access as described by <code>PixelBuffer</code>
* \returns an address pointer to DMA if the mapping succeeded. Otherwise a nullptr
* is returned. The mapping can fail if the buffer identified with <code>key</code>
* is already mapped or if something else failed.
*/
void* mapBufferRange(KeyType key, GLintptr offset, GLsizeiptr length,
BufferAccessMask access);
/**
* Unmaps all buffers in the PixelBufferContainer.
* \returns true if the unmapping succeeded, otherwise false.
*/
bool resetMappedBuffers();
/**
* Unmaps a buffer that has previously been mapped. This buffer is identified using
* <code>key</code>.
* \param key is the identifier of the mapped buffer.
* \returns true if the unmapping succeeded, otherwise false.
*/
bool unMapBuffer(KeyType key);
/**
* \returns the <code>GLuint</code> id of a pixel buffer identified by <code>key</code>
* if it currently is mapped.
*/
GLuint idOfMappedBuffer(KeyType key);
private:
const globebrowsing::PixelBuffer::Usage _usage;
std::vector<std::unique_ptr<PixelBuffer>> _pixelBuffers;
// Maps from KeyType to index of mapped buffers
std::map<KeyType, int> _indexMap;
};
} // namespace globebrowsing
} // namespace openspace
#include "pixelbuffercontainer.inl"
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___PIXEL_BUFFER_CONTAINER___H__

View File

@@ -1,130 +1,130 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
namespace openspace {
namespace globebrowsing {
template <class KeyType>
PixelBufferContainer<KeyType>::PixelBufferContainer(size_t numBytesPerBuffer,
PixelBuffer::Usage usage, size_t numPixelBuffers)
: _usage(usage)
{
for (size_t i = 0; i < numPixelBuffers; ++i) {
_pixelBuffers.push_back(std::make_unique<PixelBuffer>(numBytesPerBuffer, _usage));
}
}
template <class KeyType>
void* PixelBufferContainer<KeyType>::mapBuffer(KeyType key, PixelBuffer::Access access) {
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
const bool notFoundAmongMappedBuffers = (iter == _indexMap.end());
if (!notFoundAmongMappedBuffers) { // This PBO is already mapped
ghoul_assert(_pixelBuffers[iter->second], "Incorrect index map");
return nullptr;
}
// Find a pixel buffer that is unmapped
for (size_t i = 0; i < _pixelBuffers.size(); ++i) {
if (!_pixelBuffers[i]->isMapped()) {
_pixelBuffers[i]->bind();
void* dataPtr = _pixelBuffers[i]->mapBuffer(access);
_pixelBuffers[i]->unbind();
if (dataPtr) { // Success in mapping
// Add this index to the map of mapped pixel buffers
_indexMap.emplace(key, i);
return dataPtr;
}
}
}
return nullptr;
}
template <class KeyType>
void* PixelBufferContainer<KeyType>::mapBufferRange(KeyType key, GLintptr offset,
GLsizeiptr length, BufferAccessMask access)
{
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
bool notFoundAmongMappedBuffers = iter == _indexMap.end();
if (!notFoundAmongMappedBuffers) { // This PBO is already mapped
ghoul_assert(_pixelBuffers[iter->second], "Incorrect index map");
return nullptr;
}
// Find a pixel buffer that is unmapped
for (int i = 0; i < _pixelBuffers.size(); ++i) {
bool bufferIsMapped = _pixelBuffers[i]->isMapped();
if (!bufferIsMapped) {
_pixelBuffers[i]->bind();
void* dataPtr = _pixelBuffers[i]->mapBufferRange(offset, length, access);
_pixelBuffers[i]->unbind();
if (dataPtr) { // Success in mapping
_indexMap.emplace(key, i);
return dataPtr;
}
}
}
return nullptr;
}
template <class KeyType>
bool PixelBufferContainer<KeyType>::resetMappedBuffers() {
bool success = true;
for (auto iter = _indexMap.begin(); iter != _indexMap.end(); iter++) {
int index = iter->second; // Index where the mapped buffer is stored
_pixelBuffers[index]->bind();
success &= _pixelBuffers[index]->unMapBuffer();
_pixelBuffers[index]->unbind();
_indexMap.erase(iter); // This key should no longer be among the mapped buffers
}
return success;
}
template <class KeyType>
bool PixelBufferContainer<KeyType>::unMapBuffer(KeyType key) {
bool success = false;
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
if (iter != _indexMap.end()) { // Found a mapped pixel buffer
int index = iter->second; // Index where the mapped buffer is stored
_pixelBuffers[index]->bind();
success = _pixelBuffers[index]->unMapBuffer();
_pixelBuffers[index]->unbind();
_indexMap.erase(iter); // This key should no longer be among the mapped buffers
}
return success;
}
template <class KeyType>
GLuint PixelBufferContainer<KeyType>::idOfMappedBuffer(KeyType key) {
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
if (iter != _indexMap.end()) { // Found a mapped pixel buffer
int index = iter->second; // Index where the mapped buffer is stored
return *_pixelBuffers[index];
}
return 0;
}
} // namespace globebrowsing
} // namespace openspace
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
namespace openspace {
namespace globebrowsing {
template <class KeyType>
PixelBufferContainer<KeyType>::PixelBufferContainer(size_t numBytesPerBuffer,
PixelBuffer::Usage usage, size_t numPixelBuffers)
: _usage(usage)
{
for (size_t i = 0; i < numPixelBuffers; ++i) {
_pixelBuffers.push_back(std::make_unique<PixelBuffer>(numBytesPerBuffer, _usage));
}
}
template <class KeyType>
void* PixelBufferContainer<KeyType>::mapBuffer(KeyType key, PixelBuffer::Access access) {
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
const bool notFoundAmongMappedBuffers = (iter == _indexMap.end());
if (!notFoundAmongMappedBuffers) { // This PBO is already mapped
ghoul_assert(_pixelBuffers[iter->second], "Incorrect index map");
return nullptr;
}
// Find a pixel buffer that is unmapped
for (size_t i = 0; i < _pixelBuffers.size(); ++i) {
if (!_pixelBuffers[i]->isMapped()) {
_pixelBuffers[i]->bind();
void* dataPtr = _pixelBuffers[i]->mapBuffer(access);
_pixelBuffers[i]->unbind();
if (dataPtr) { // Success in mapping
// Add this index to the map of mapped pixel buffers
_indexMap.emplace(key, i);
return dataPtr;
}
}
}
return nullptr;
}
template <class KeyType>
void* PixelBufferContainer<KeyType>::mapBufferRange(KeyType key, GLintptr offset,
GLsizeiptr length, BufferAccessMask access)
{
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
bool notFoundAmongMappedBuffers = iter == _indexMap.end();
if (!notFoundAmongMappedBuffers) { // This PBO is already mapped
ghoul_assert(_pixelBuffers[iter->second], "Incorrect index map");
return nullptr;
}
// Find a pixel buffer that is unmapped
for (int i = 0; i < _pixelBuffers.size(); ++i) {
bool bufferIsMapped = _pixelBuffers[i]->isMapped();
if (!bufferIsMapped) {
_pixelBuffers[i]->bind();
void* dataPtr = _pixelBuffers[i]->mapBufferRange(offset, length, access);
_pixelBuffers[i]->unbind();
if (dataPtr) { // Success in mapping
_indexMap.emplace(key, i);
return dataPtr;
}
}
}
return nullptr;
}
template <class KeyType>
bool PixelBufferContainer<KeyType>::resetMappedBuffers() {
bool success = true;
for (auto iter = _indexMap.begin(); iter != _indexMap.end(); iter++) {
int index = iter->second; // Index where the mapped buffer is stored
_pixelBuffers[index]->bind();
success &= _pixelBuffers[index]->unMapBuffer();
_pixelBuffers[index]->unbind();
_indexMap.erase(iter); // This key should no longer be among the mapped buffers
}
return success;
}
template <class KeyType>
bool PixelBufferContainer<KeyType>::unMapBuffer(KeyType key) {
bool success = false;
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
if (iter != _indexMap.end()) { // Found a mapped pixel buffer
int index = iter->second; // Index where the mapped buffer is stored
_pixelBuffers[index]->bind();
success = _pixelBuffers[index]->unMapBuffer();
_pixelBuffers[index]->unbind();
_indexMap.erase(iter); // This key should no longer be among the mapped buffers
}
return success;
}
template <class KeyType>
GLuint PixelBufferContainer<KeyType>::idOfMappedBuffer(KeyType key) {
typename std::map<KeyType, int>::const_iterator iter = _indexMap.find(key);
if (iter != _indexMap.end()) { // Found a mapped pixel buffer
int index = iter->second; // Index where the mapped buffer is stored
return *_pixelBuffers[index];
}
return 0;
}
} // namespace globebrowsing
} // namespace openspace

View File

@@ -1,339 +1,339 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#ifdef GLOBEBROWSING_USE_GDAL
#include <modules/globebrowsing/tile/rawtiledatareader/gdalrawtiledatareader.h>
#include <modules/globebrowsing/geometry/geodetic2.h>
#include <modules/globebrowsing/geometry/geodeticpatch.h>
#include <modules/globebrowsing/geometry/angle.h>
#include <modules/globebrowsing/tile/rawtiledatareader/tiledatatype.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h> // abspath
#include <ghoul/filesystem/file.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/dictionary.h>
#include <ogr_featurestyle.h>
#include <ogr_spatialref.h>
#include <cpl_virtualmem.h>
#include <gdal_priv.h>
#include <algorithm>
namespace {
const std::string _loggerCat = "GdalRawTileDataReader";
}
namespace openspace {
namespace globebrowsing {
std::ostream& operator<<(std::ostream& os, const PixelRegion& pr) {
return os << pr.start.x << ", " << pr.start.y << " with size " << pr.numPixels.x <<
", " << pr.numPixels.y;
}
GdalRawTileDataReader::GdalRawTileDataReader(const std::string& filePath,
const TileTextureInitData& initData,
const std::string& baseDirectory,
RawTileDataReader::PerformPreprocessing preprocess)
: RawTileDataReader(initData, preprocess)
, _dataset(nullptr)
{
_initDirectory = baseDirectory.empty() ? CPLGetCurrentDir() : baseDirectory;
_datasetFilePath = filePath;
{ // Aquire lock
std::lock_guard<std::mutex> lockGuard(_datasetLock);
initialize();
}
}
GdalRawTileDataReader::~GdalRawTileDataReader() {
std::lock_guard<std::mutex> lockGuard(_datasetLock);
if (_dataset != nullptr) {
GDALClose(_dataset);
_dataset = nullptr;
}
}
void GdalRawTileDataReader::reset() {
std::lock_guard<std::mutex> lockGuard(_datasetLock);
_cached._maxLevel = -1;
if (_dataset != nullptr) {
GDALClose(_dataset);
_dataset = nullptr;
}
initialize();
}
int GdalRawTileDataReader::maxChunkLevel() const {
return _cached._maxLevel;
}
float GdalRawTileDataReader::noDataValueAsFloat() const {
return _gdalDatasetMetaDataCached.noDataValue;
}
int GdalRawTileDataReader::rasterXSize() const {
return _gdalDatasetMetaDataCached.rasterXSize;
}
int GdalRawTileDataReader::rasterYSize() const {
return _gdalDatasetMetaDataCached.rasterYSize;
}
float GdalRawTileDataReader::depthOffset() const {
return _gdalDatasetMetaDataCached.offset;
}
float GdalRawTileDataReader::depthScale() const {
return _gdalDatasetMetaDataCached.scale;
}
std::array<double, 6> GdalRawTileDataReader::getGeoTransform() const {
return _gdalDatasetMetaDataCached.padfTransform;
}
IODescription GdalRawTileDataReader::getIODescription(const TileIndex& tileIndex) const {
IODescription io;
io.read.region = highestResPixelRegion(tileIndex);
// write region starts in origin
io.write.region.start = PixelRegion::PixelCoordinate(0, 0);
io.write.region.numPixels = PixelRegion::PixelCoordinate(
_initData.dimensionsWithoutPadding().x, _initData.dimensionsWithoutPadding().y);
io.read.overview = 0;
io.read.fullRegion = fullPixelRegion();
// For correct sampling in dataset, we need to pad the texture tile
PixelRegion scaledPadding = padding;
double scale =
io.read.region.numPixels.x / static_cast<double>(io.write.region.numPixels.x);
scaledPadding.numPixels *= scale;
scaledPadding.start *= scale;
io.read.region.pad(scaledPadding);
io.write.region.pad(padding);
io.write.region.start = PixelRegion::PixelCoordinate(0, 0);
io.write.bytesPerLine = _initData.bytesPerLine();
io.write.totalNumBytes = _initData.totalNumBytes();
ghoul_assert(io.write.region.numPixels.x == io.write.region.numPixels.y, "");
ghoul_assert(io.write.region.numPixels.x == _initData.dimensionsWithPadding().x, "");
return io;
}
void GdalRawTileDataReader::initialize() {
_dataset = openGdalDataset(_datasetFilePath);
// Assume all raster bands have the same data type
_gdalDatasetMetaDataCached.rasterCount = _dataset->GetRasterCount();
_gdalDatasetMetaDataCached.scale = _dataset->GetRasterBand(1)->GetScale();
_gdalDatasetMetaDataCached.offset = _dataset->GetRasterBand(1)->GetOffset();
_gdalDatasetMetaDataCached.rasterXSize = _dataset->GetRasterXSize();
_gdalDatasetMetaDataCached.rasterYSize = _dataset->GetRasterYSize();
_gdalDatasetMetaDataCached.noDataValue = _dataset->GetRasterBand(1)->GetNoDataValue();
_gdalDatasetMetaDataCached.dataType = tiledatatype::getGdalDataType(_initData.glType());
CPLErr err = _dataset->GetGeoTransform(&_gdalDatasetMetaDataCached.padfTransform[0]);
if (err == CE_Failure) {
_gdalDatasetMetaDataCached.padfTransform = RawTileDataReader::getGeoTransform();
}
_depthTransform = calculateTileDepthTransform();
_cached._tileLevelDifference =
calculateTileLevelDifference(_initData.dimensionsWithoutPadding().x);
int numOverviews = _dataset->GetRasterBand(1)->GetOverviewCount();
_cached._maxLevel = -_cached._tileLevelDifference;
if (numOverviews > 0) {
_cached._maxLevel += numOverviews - 1;
}
}
void GdalRawTileDataReader::readImageData(
IODescription& io, RawTile::ReadError& worstError, char* imageDataDest) const {
// Only read the minimum number of rasters
int nRastersToRead = std::min(_gdalDatasetMetaDataCached.rasterCount,
static_cast<int>(_initData.nRasters()));
switch (_initData.ghoulTextureFormat()) {
case ghoul::opengl::Texture::Format::Red:
case ghoul::opengl::Texture::Format::RG:
case ghoul::opengl::Texture::Format::RGB:
case ghoul::opengl::Texture::Format::RGBA: {
// Read the data (each rasterband is a separate channel)
for (int i = 0; i < nRastersToRead; i++) {
// The final destination pointer is offsetted by one datum byte size
// for every raster (or data channel, i.e. R in RGB)
char* dataDestination = imageDataDest + (i * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(i + 1, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
break;
}
case ghoul::opengl::Texture::Format::BGR: {
// Read the data (each rasterband is a separate channel)
for (int i = 0; i < 3 && i < nRastersToRead; i++) {
// The final destination pointer is offsetted by one datum byte size
// for every raster (or data channel, i.e. R in RGB)
char* dataDestination = imageDataDest + (i * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(3 - i, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
break;
}
case ghoul::opengl::Texture::Format::BGRA: {
for (int i = 0; i < 3 && i < nRastersToRead; i++) {
// The final destination pointer is offsetted by one datum byte size
// for every raster (or data channel, i.e. R in RGB)
char* dataDestination = imageDataDest + (i * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(3 - i, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
if (nRastersToRead > 3) { // Alpha channel exists
// Last read is the alpha channel
char* dataDestination = imageDataDest + (3 * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(4, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
break;
}
default: {
ghoul_assert(false, "Texture format not supported for tiles");
break;
}
}
}
RawTile::ReadError GdalRawTileDataReader::rasterRead(
int rasterBand, const IODescription& io, char* dataDestination) const
{
ghoul_assert(io.read.region.isInside(io.read.fullRegion), "write region of bounds!");
ghoul_assert(
io.write.region.start.x >= 0 && io.write.region.start.y >= 0,
"Invalid write region"
);
PixelRegion::PixelCoordinate end = io.write.region.end();
size_t largestIndex =
(end.y - 1) * io.write.bytesPerLine + (end.x - 1) * _initData.bytesPerPixel();
ghoul_assert(largestIndex <= io.write.totalNumBytes, "Invalid write region");
char* dataDest = dataDestination;
// GDAL reads pixels top to bottom, but we want our pixels bottom to top.
// Therefore, we increment the destination pointer to the last line on in the
// buffer, and the we specify in the rasterIO call that we want negative line
// spacing. Doing this compensates the flipped Y axis
dataDest += (io.write.totalNumBytes - io.write.bytesPerLine);
// handle requested write region. Note -= since flipped y axis
dataDest -= io.write.region.start.y * io.write.bytesPerLine;
dataDest += io.write.region.start.x * _initData.bytesPerPixel();
GDALRasterBand* gdalRasterBand = _dataset->GetRasterBand(rasterBand);
CPLErr readError = CE_Failure;
readError = gdalRasterBand->RasterIO(
GF_Read,
io.read.region.start.x, // Begin read x
io.read.region.start.y, // Begin read y
io.read.region.numPixels.x, // width to read x
io.read.region.numPixels.y, // width to read y
dataDest, // Where to put data
io.write.region.numPixels.x, // width to write x in destination
io.write.region.numPixels.y, // width to write y in destination
_gdalDatasetMetaDataCached.dataType, // Type
_initData.bytesPerPixel(), // Pixel spacing
-io.write.bytesPerLine // Line spacing
);
// Convert error to RawTile::ReadError
RawTile::ReadError error;
switch (readError) {
case CE_None: error = RawTile::ReadError::None; break;
case CE_Debug: error = RawTile::ReadError::Debug; break;
case CE_Warning: error = RawTile::ReadError::Warning; break;
case CE_Failure: error = RawTile::ReadError::Failure; break;
case CE_Fatal: error = RawTile::ReadError::Fatal; break;
default: error = RawTile::ReadError::Failure; break;
}
return error;
}
GDALDataset* GdalRawTileDataReader::openGdalDataset(const std::string& filePath) {
GDALDataset* dataset = static_cast<GDALDataset*>(
GDALOpen(filePath.c_str(), GA_ReadOnly));
if (!dataset) {
using namespace ghoul::filesystem;
std::string correctedPath = FileSystem::ref().pathByAppendingComponent(
_initDirectory, filePath
);
dataset = static_cast<GDALDataset*>(GDALOpen(correctedPath.c_str(), GA_ReadOnly));
if (!dataset) {
throw ghoul::RuntimeError("Failed to load dataset:\n" + filePath);
}
}
return dataset;
}
int GdalRawTileDataReader::calculateTileLevelDifference(int minimumPixelSize) const {
GDALRasterBand* firstBand = _dataset->GetRasterBand(1);
GDALRasterBand* maxOverview;
int numOverviews = firstBand->GetOverviewCount();
int sizeLevel0;
if (numOverviews <= 0) { // No overviews. Use first band.
maxOverview = firstBand;
}
else { // Pick the highest overview.
maxOverview = firstBand->GetOverview(numOverviews - 1);
}
sizeLevel0 = maxOverview->GetXSize();
double diff = log2(minimumPixelSize) - log2(sizeLevel0);
return diff;
}
} // namespace globebrowsing
} // namespace openspace
#endif // GLOBEBROWSING_USE_GDAL
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#ifdef GLOBEBROWSING_USE_GDAL
#include <modules/globebrowsing/tile/rawtiledatareader/gdalrawtiledatareader.h>
#include <modules/globebrowsing/geometry/geodetic2.h>
#include <modules/globebrowsing/geometry/geodeticpatch.h>
#include <modules/globebrowsing/geometry/angle.h>
#include <modules/globebrowsing/tile/rawtiledatareader/tiledatatype.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h> // abspath
#include <ghoul/filesystem/file.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/dictionary.h>
#include <ogr_featurestyle.h>
#include <ogr_spatialref.h>
#include <cpl_virtualmem.h>
#include <gdal_priv.h>
#include <algorithm>
namespace {
const std::string _loggerCat = "GdalRawTileDataReader";
}
namespace openspace {
namespace globebrowsing {
std::ostream& operator<<(std::ostream& os, const PixelRegion& pr) {
return os << pr.start.x << ", " << pr.start.y << " with size " << pr.numPixels.x <<
", " << pr.numPixels.y;
}
GdalRawTileDataReader::GdalRawTileDataReader(const std::string& filePath,
const TileTextureInitData& initData,
const std::string& baseDirectory,
RawTileDataReader::PerformPreprocessing preprocess)
: RawTileDataReader(initData, preprocess)
, _dataset(nullptr)
{
_initDirectory = baseDirectory.empty() ? CPLGetCurrentDir() : baseDirectory;
_datasetFilePath = filePath;
{ // Aquire lock
std::lock_guard<std::mutex> lockGuard(_datasetLock);
initialize();
}
}
GdalRawTileDataReader::~GdalRawTileDataReader() {
std::lock_guard<std::mutex> lockGuard(_datasetLock);
if (_dataset != nullptr) {
GDALClose(_dataset);
_dataset = nullptr;
}
}
void GdalRawTileDataReader::reset() {
std::lock_guard<std::mutex> lockGuard(_datasetLock);
_cached._maxLevel = -1;
if (_dataset != nullptr) {
GDALClose(_dataset);
_dataset = nullptr;
}
initialize();
}
int GdalRawTileDataReader::maxChunkLevel() const {
return _cached._maxLevel;
}
float GdalRawTileDataReader::noDataValueAsFloat() const {
return _gdalDatasetMetaDataCached.noDataValue;
}
int GdalRawTileDataReader::rasterXSize() const {
return _gdalDatasetMetaDataCached.rasterXSize;
}
int GdalRawTileDataReader::rasterYSize() const {
return _gdalDatasetMetaDataCached.rasterYSize;
}
float GdalRawTileDataReader::depthOffset() const {
return _gdalDatasetMetaDataCached.offset;
}
float GdalRawTileDataReader::depthScale() const {
return _gdalDatasetMetaDataCached.scale;
}
std::array<double, 6> GdalRawTileDataReader::getGeoTransform() const {
return _gdalDatasetMetaDataCached.padfTransform;
}
IODescription GdalRawTileDataReader::getIODescription(const TileIndex& tileIndex) const {
IODescription io;
io.read.region = highestResPixelRegion(tileIndex);
// write region starts in origin
io.write.region.start = PixelRegion::PixelCoordinate(0, 0);
io.write.region.numPixels = PixelRegion::PixelCoordinate(
_initData.dimensionsWithoutPadding().x, _initData.dimensionsWithoutPadding().y);
io.read.overview = 0;
io.read.fullRegion = fullPixelRegion();
// For correct sampling in dataset, we need to pad the texture tile
PixelRegion scaledPadding = padding;
double scale =
io.read.region.numPixels.x / static_cast<double>(io.write.region.numPixels.x);
scaledPadding.numPixels *= scale;
scaledPadding.start *= scale;
io.read.region.pad(scaledPadding);
io.write.region.pad(padding);
io.write.region.start = PixelRegion::PixelCoordinate(0, 0);
io.write.bytesPerLine = _initData.bytesPerLine();
io.write.totalNumBytes = _initData.totalNumBytes();
ghoul_assert(io.write.region.numPixels.x == io.write.region.numPixels.y, "");
ghoul_assert(io.write.region.numPixels.x == _initData.dimensionsWithPadding().x, "");
return io;
}
void GdalRawTileDataReader::initialize() {
_dataset = openGdalDataset(_datasetFilePath);
// Assume all raster bands have the same data type
_gdalDatasetMetaDataCached.rasterCount = _dataset->GetRasterCount();
_gdalDatasetMetaDataCached.scale = _dataset->GetRasterBand(1)->GetScale();
_gdalDatasetMetaDataCached.offset = _dataset->GetRasterBand(1)->GetOffset();
_gdalDatasetMetaDataCached.rasterXSize = _dataset->GetRasterXSize();
_gdalDatasetMetaDataCached.rasterYSize = _dataset->GetRasterYSize();
_gdalDatasetMetaDataCached.noDataValue = _dataset->GetRasterBand(1)->GetNoDataValue();
_gdalDatasetMetaDataCached.dataType = tiledatatype::getGdalDataType(_initData.glType());
CPLErr err = _dataset->GetGeoTransform(&_gdalDatasetMetaDataCached.padfTransform[0]);
if (err == CE_Failure) {
_gdalDatasetMetaDataCached.padfTransform = RawTileDataReader::getGeoTransform();
}
_depthTransform = calculateTileDepthTransform();
_cached._tileLevelDifference =
calculateTileLevelDifference(_initData.dimensionsWithoutPadding().x);
int numOverviews = _dataset->GetRasterBand(1)->GetOverviewCount();
_cached._maxLevel = -_cached._tileLevelDifference;
if (numOverviews > 0) {
_cached._maxLevel += numOverviews - 1;
}
}
void GdalRawTileDataReader::readImageData(
IODescription& io, RawTile::ReadError& worstError, char* imageDataDest) const {
// Only read the minimum number of rasters
int nRastersToRead = std::min(_gdalDatasetMetaDataCached.rasterCount,
static_cast<int>(_initData.nRasters()));
switch (_initData.ghoulTextureFormat()) {
case ghoul::opengl::Texture::Format::Red:
case ghoul::opengl::Texture::Format::RG:
case ghoul::opengl::Texture::Format::RGB:
case ghoul::opengl::Texture::Format::RGBA: {
// Read the data (each rasterband is a separate channel)
for (int i = 0; i < nRastersToRead; i++) {
// The final destination pointer is offsetted by one datum byte size
// for every raster (or data channel, i.e. R in RGB)
char* dataDestination = imageDataDest + (i * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(i + 1, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
break;
}
case ghoul::opengl::Texture::Format::BGR: {
// Read the data (each rasterband is a separate channel)
for (int i = 0; i < 3 && i < nRastersToRead; i++) {
// The final destination pointer is offsetted by one datum byte size
// for every raster (or data channel, i.e. R in RGB)
char* dataDestination = imageDataDest + (i * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(3 - i, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
break;
}
case ghoul::opengl::Texture::Format::BGRA: {
for (int i = 0; i < 3 && i < nRastersToRead; i++) {
// The final destination pointer is offsetted by one datum byte size
// for every raster (or data channel, i.e. R in RGB)
char* dataDestination = imageDataDest + (i * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(3 - i, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
if (nRastersToRead > 3) { // Alpha channel exists
// Last read is the alpha channel
char* dataDestination = imageDataDest + (3 * _initData.bytesPerDatum());
RawTile::ReadError err = repeatedRasterRead(4, io, dataDestination);
// CE_None = 0, CE_Debug = 1, CE_Warning = 2, CE_Failure = 3, CE_Fatal = 4
worstError = std::max(worstError, err);
}
break;
}
default: {
ghoul_assert(false, "Texture format not supported for tiles");
break;
}
}
}
RawTile::ReadError GdalRawTileDataReader::rasterRead(
int rasterBand, const IODescription& io, char* dataDestination) const
{
ghoul_assert(io.read.region.isInside(io.read.fullRegion), "write region of bounds!");
ghoul_assert(
io.write.region.start.x >= 0 && io.write.region.start.y >= 0,
"Invalid write region"
);
PixelRegion::PixelCoordinate end = io.write.region.end();
size_t largestIndex =
(end.y - 1) * io.write.bytesPerLine + (end.x - 1) * _initData.bytesPerPixel();
ghoul_assert(largestIndex <= io.write.totalNumBytes, "Invalid write region");
char* dataDest = dataDestination;
// GDAL reads pixels top to bottom, but we want our pixels bottom to top.
// Therefore, we increment the destination pointer to the last line on in the
// buffer, and the we specify in the rasterIO call that we want negative line
// spacing. Doing this compensates the flipped Y axis
dataDest += (io.write.totalNumBytes - io.write.bytesPerLine);
// handle requested write region. Note -= since flipped y axis
dataDest -= io.write.region.start.y * io.write.bytesPerLine;
dataDest += io.write.region.start.x * _initData.bytesPerPixel();
GDALRasterBand* gdalRasterBand = _dataset->GetRasterBand(rasterBand);
CPLErr readError = CE_Failure;
readError = gdalRasterBand->RasterIO(
GF_Read,
io.read.region.start.x, // Begin read x
io.read.region.start.y, // Begin read y
io.read.region.numPixels.x, // width to read x
io.read.region.numPixels.y, // width to read y
dataDest, // Where to put data
io.write.region.numPixels.x, // width to write x in destination
io.write.region.numPixels.y, // width to write y in destination
_gdalDatasetMetaDataCached.dataType, // Type
_initData.bytesPerPixel(), // Pixel spacing
-io.write.bytesPerLine // Line spacing
);
// Convert error to RawTile::ReadError
RawTile::ReadError error;
switch (readError) {
case CE_None: error = RawTile::ReadError::None; break;
case CE_Debug: error = RawTile::ReadError::Debug; break;
case CE_Warning: error = RawTile::ReadError::Warning; break;
case CE_Failure: error = RawTile::ReadError::Failure; break;
case CE_Fatal: error = RawTile::ReadError::Fatal; break;
default: error = RawTile::ReadError::Failure; break;
}
return error;
}
GDALDataset* GdalRawTileDataReader::openGdalDataset(const std::string& filePath) {
GDALDataset* dataset = static_cast<GDALDataset*>(
GDALOpen(filePath.c_str(), GA_ReadOnly));
if (!dataset) {
using namespace ghoul::filesystem;
std::string correctedPath = FileSystem::ref().pathByAppendingComponent(
_initDirectory, filePath
);
dataset = static_cast<GDALDataset*>(GDALOpen(correctedPath.c_str(), GA_ReadOnly));
if (!dataset) {
throw ghoul::RuntimeError("Failed to load dataset:\n" + filePath);
}
}
return dataset;
}
int GdalRawTileDataReader::calculateTileLevelDifference(int minimumPixelSize) const {
GDALRasterBand* firstBand = _dataset->GetRasterBand(1);
GDALRasterBand* maxOverview;
int numOverviews = firstBand->GetOverviewCount();
int sizeLevel0;
if (numOverviews <= 0) { // No overviews. Use first band.
maxOverview = firstBand;
}
else { // Pick the highest overview.
maxOverview = firstBand->GetOverview(numOverviews - 1);
}
sizeLevel0 = maxOverview->GetXSize();
double diff = log2(minimumPixelSize) - log2(sizeLevel0);
return diff;
}
} // namespace globebrowsing
} // namespace openspace
#endif // GLOBEBROWSING_USE_GDAL

File diff suppressed because it is too large Load Diff

View File

@@ -1,61 +1,61 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___TILE_DATA_TYPE___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILE_DATA_TYPE___H__
#include <modules/globebrowsing/tile/tile.h>
#include <modules/globebrowsing/tile/textureformat.h>
#include <ghoul/opengl/ghoul_gl.h>
#ifdef GLOBEBROWSING_USE_GDAL
#include <gdal.h>
#endif // GLOBEBROWSING_USE_GDAL
namespace openspace {
namespace globebrowsing {
namespace tiledatatype {
#ifdef GLOBEBROWSING_USE_GDAL
GLenum getOpenGLDataType(GDALDataType gdalType);
GDALDataType getGdalDataType(GLenum glType);
TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType);
TextureFormat getTextureFormatOptimized(int rasterCount, GDALDataType gdalType);
size_t getMaximumValue(GDALDataType gdalType);
size_t numberOfBytes(GDALDataType gdalType);
float interpretFloat(GDALDataType gdalType, const char* src);
#endif // GLOBEBROWSING_USE_GDAL
GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format);
size_t numberOfRasters(ghoul::opengl::Texture::Format format);
size_t numberOfBytes(GLenum glType);
size_t getMaximumValue(GLenum glType);
float interpretFloat(GLenum glType, const char* src);
} // namespace tiledatatype
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TILE_DATA_TYPE___H__
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___TILE_DATA_TYPE___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILE_DATA_TYPE___H__
#include <modules/globebrowsing/tile/tile.h>
#include <modules/globebrowsing/tile/textureformat.h>
#include <ghoul/opengl/ghoul_gl.h>
#ifdef GLOBEBROWSING_USE_GDAL
#include <gdal.h>
#endif // GLOBEBROWSING_USE_GDAL
namespace openspace {
namespace globebrowsing {
namespace tiledatatype {
#ifdef GLOBEBROWSING_USE_GDAL
GLenum getOpenGLDataType(GDALDataType gdalType);
GDALDataType getGdalDataType(GLenum glType);
TextureFormat getTextureFormat(int rasterCount, GDALDataType gdalType);
TextureFormat getTextureFormatOptimized(int rasterCount, GDALDataType gdalType);
size_t getMaximumValue(GDALDataType gdalType);
size_t numberOfBytes(GDALDataType gdalType);
float interpretFloat(GDALDataType gdalType, const char* src);
#endif // GLOBEBROWSING_USE_GDAL
GLenum glTextureFormat(GLenum glType, ghoul::opengl::Texture::Format format);
size_t numberOfRasters(ghoul::opengl::Texture::Format format);
size_t numberOfBytes(GLenum glType);
size_t getMaximumValue(GLenum glType);
float interpretFloat(GLenum glType, const char* src);
} // namespace tiledatatype
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TILE_DATA_TYPE___H__

View File

@@ -1,43 +1,43 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___TEXTUREFORMAT___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__
#include <ghoul/glm.h>
#include <ghoul/opengl/texture.h>
namespace openspace {
namespace globebrowsing {
struct TextureFormat {
ghoul::opengl::Texture::Format ghoulFormat;
GLenum glFormat;
};
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___TEXTUREFORMAT___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__
#include <ghoul/glm.h>
#include <ghoul/opengl/texture.h>
namespace openspace {
namespace globebrowsing {
struct TextureFormat {
ghoul::opengl::Texture::Format ghoulFormat;
GLenum glFormat;
};
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TEXTUREFORMAT___H__

View File

@@ -1,152 +1,152 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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/globebrowsing/tile/tiletextureinitdata.h>
#include <modules/globebrowsing/tile/rawtiledatareader/tiledatatype.h>
namespace openspace {
namespace globebrowsing {
const glm::ivec2 TileTextureInitData::tilePixelStartOffset = glm::ivec2(-2);
const glm::ivec2 TileTextureInitData::tilePixelSizeDifference = glm::ivec2(4);
TileTextureInitData::TileTextureInitData(size_t width, size_t height, GLenum glType,
Format textureFormat, ShouldAllocateDataOnCPU shouldAllocateDataOnCPU)
: _glType(glType)
, _ghoulTextureFormat(textureFormat)
, _shouldAllocateDataOnCPU(shouldAllocateDataOnCPU)
{
_dimensionsWithoutPadding = glm::ivec3(width, height, 1);
_dimensionsWithPadding = glm::ivec3(
width + tilePixelSizeDifference.x, height + tilePixelSizeDifference.y, 1);
_nRasters = tiledatatype::numberOfRasters(_ghoulTextureFormat);
_bytesPerDatum = tiledatatype::numberOfBytes(glType);
_bytesPerPixel = _nRasters * _bytesPerDatum;
_bytesPerLine = _bytesPerPixel * _dimensionsWithPadding.x;
_totalNumBytes = _bytesPerLine * _dimensionsWithPadding.y;
_glTextureFormat = tiledatatype::glTextureFormat(_glType,
_ghoulTextureFormat);
calculateHashKey();
};
TileTextureInitData::TileTextureInitData(const TileTextureInitData& original)
: TileTextureInitData(
original.dimensionsWithoutPadding().x,
original.dimensionsWithoutPadding().y,
original.glType(),
original.ghoulTextureFormat(),
original.shouldAllocateDataOnCPU() ? ShouldAllocateDataOnCPU::Yes : ShouldAllocateDataOnCPU::No)
{ };
glm::ivec3 TileTextureInitData::dimensionsWithPadding() const {
return _dimensionsWithPadding;
}
glm::ivec3 TileTextureInitData::dimensionsWithoutPadding() const {
return _dimensionsWithoutPadding;
}
size_t TileTextureInitData::nRasters() const {
return _nRasters;
}
size_t TileTextureInitData::bytesPerDatum() const {
return _bytesPerDatum;
}
size_t TileTextureInitData::bytesPerPixel() const {
return _bytesPerPixel;
}
size_t TileTextureInitData::bytesPerLine() const {
return _bytesPerLine;
}
size_t TileTextureInitData::totalNumBytes() const {
return _totalNumBytes;
}
GLenum TileTextureInitData::glType() const {
return _glType;
}
TileTextureInitData::Format TileTextureInitData::ghoulTextureFormat() const {
return _ghoulTextureFormat;
}
GLenum TileTextureInitData::glTextureFormat() const {
return _glTextureFormat;
}
bool TileTextureInitData::shouldAllocateDataOnCPU() const {
return _shouldAllocateDataOnCPU;
}
TileTextureInitData::HashKey TileTextureInitData::hashKey() const {
return _hashKey;
}
void TileTextureInitData::calculateHashKey() {
ghoul_assert(_dimensionsWithoutPadding.x > 0, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.y > 0, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.x <= 1024, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.y <= 1024, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.z == 1, "Incorrect dimension");
unsigned int format = getUniqueIdFromTextureFormat(_ghoulTextureFormat);
ghoul_assert(format < 256, "Incorrect format");
_hashKey = 0LL;
_hashKey |= _dimensionsWithoutPadding.x;
_hashKey |= _dimensionsWithoutPadding.y << 10;
_hashKey |= static_cast<std::underlying_type_t<GLenum>>(_glType) << (10 + 16);
_hashKey |= format << (10 + 16 + 4);
};
unsigned int TileTextureInitData::getUniqueIdFromTextureFormat(
Format textureFormat) const
{
using Format = Format;
switch (textureFormat) {
case Format::Red:
return 0;
case Format::RG:
return 1;
case Format::RGB:
return 2;
case Format::BGR:
return 3;
case Format::RGBA:
return 4;
case Format::BGRA:
return 5;
case Format::DepthComponent:
return 6;
default:
ghoul_assert(false, "Unknown texture format");
}
}
} // namespace globebrowsing
} // namespace openspace
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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/globebrowsing/tile/tiletextureinitdata.h>
#include <modules/globebrowsing/tile/rawtiledatareader/tiledatatype.h>
namespace openspace {
namespace globebrowsing {
const glm::ivec2 TileTextureInitData::tilePixelStartOffset = glm::ivec2(-2);
const glm::ivec2 TileTextureInitData::tilePixelSizeDifference = glm::ivec2(4);
TileTextureInitData::TileTextureInitData(size_t width, size_t height, GLenum glType,
Format textureFormat, ShouldAllocateDataOnCPU shouldAllocateDataOnCPU)
: _glType(glType)
, _ghoulTextureFormat(textureFormat)
, _shouldAllocateDataOnCPU(shouldAllocateDataOnCPU)
{
_dimensionsWithoutPadding = glm::ivec3(width, height, 1);
_dimensionsWithPadding = glm::ivec3(
width + tilePixelSizeDifference.x, height + tilePixelSizeDifference.y, 1);
_nRasters = tiledatatype::numberOfRasters(_ghoulTextureFormat);
_bytesPerDatum = tiledatatype::numberOfBytes(glType);
_bytesPerPixel = _nRasters * _bytesPerDatum;
_bytesPerLine = _bytesPerPixel * _dimensionsWithPadding.x;
_totalNumBytes = _bytesPerLine * _dimensionsWithPadding.y;
_glTextureFormat = tiledatatype::glTextureFormat(_glType,
_ghoulTextureFormat);
calculateHashKey();
};
TileTextureInitData::TileTextureInitData(const TileTextureInitData& original)
: TileTextureInitData(
original.dimensionsWithoutPadding().x,
original.dimensionsWithoutPadding().y,
original.glType(),
original.ghoulTextureFormat(),
original.shouldAllocateDataOnCPU() ? ShouldAllocateDataOnCPU::Yes : ShouldAllocateDataOnCPU::No)
{ };
glm::ivec3 TileTextureInitData::dimensionsWithPadding() const {
return _dimensionsWithPadding;
}
glm::ivec3 TileTextureInitData::dimensionsWithoutPadding() const {
return _dimensionsWithoutPadding;
}
size_t TileTextureInitData::nRasters() const {
return _nRasters;
}
size_t TileTextureInitData::bytesPerDatum() const {
return _bytesPerDatum;
}
size_t TileTextureInitData::bytesPerPixel() const {
return _bytesPerPixel;
}
size_t TileTextureInitData::bytesPerLine() const {
return _bytesPerLine;
}
size_t TileTextureInitData::totalNumBytes() const {
return _totalNumBytes;
}
GLenum TileTextureInitData::glType() const {
return _glType;
}
TileTextureInitData::Format TileTextureInitData::ghoulTextureFormat() const {
return _ghoulTextureFormat;
}
GLenum TileTextureInitData::glTextureFormat() const {
return _glTextureFormat;
}
bool TileTextureInitData::shouldAllocateDataOnCPU() const {
return _shouldAllocateDataOnCPU;
}
TileTextureInitData::HashKey TileTextureInitData::hashKey() const {
return _hashKey;
}
void TileTextureInitData::calculateHashKey() {
ghoul_assert(_dimensionsWithoutPadding.x > 0, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.y > 0, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.x <= 1024, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.y <= 1024, "Incorrect dimension");
ghoul_assert(_dimensionsWithoutPadding.z == 1, "Incorrect dimension");
unsigned int format = getUniqueIdFromTextureFormat(_ghoulTextureFormat);
ghoul_assert(format < 256, "Incorrect format");
_hashKey = 0LL;
_hashKey |= _dimensionsWithoutPadding.x;
_hashKey |= _dimensionsWithoutPadding.y << 10;
_hashKey |= static_cast<std::underlying_type_t<GLenum>>(_glType) << (10 + 16);
_hashKey |= format << (10 + 16 + 4);
};
unsigned int TileTextureInitData::getUniqueIdFromTextureFormat(
Format textureFormat) const
{
using Format = Format;
switch (textureFormat) {
case Format::Red:
return 0;
case Format::RG:
return 1;
case Format::RGB:
return 2;
case Format::BGR:
return 3;
case Format::RGBA:
return 4;
case Format::BGRA:
return 5;
case Format::DepthComponent:
return 6;
default:
ghoul_assert(false, "Unknown texture format");
}
}
} // namespace globebrowsing
} // namespace openspace

View File

@@ -1,91 +1,91 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___TILE_TEXTURE_INIT_DATA___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILE_TEXTURE_INIT_DATA___H__
#include <ghoul/glm.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/texture.h>
#include <string>
namespace openspace {
namespace globebrowsing {
/**
* All information needed to create a texture used for a Tile.
*/
class TileTextureInitData
{
public:
using HashKey = unsigned long long;
using ShouldAllocateDataOnCPU = ghoul::Boolean;
using Format = ghoul::opengl::Texture::Format;
TileTextureInitData(size_t width, size_t height, GLenum glType, Format textureFormat,
ShouldAllocateDataOnCPU shouldAllocateDataOnCPU = ShouldAllocateDataOnCPU::No);
TileTextureInitData(const TileTextureInitData& original);
~TileTextureInitData() = default;
glm::ivec3 dimensionsWithPadding() const;
glm::ivec3 dimensionsWithoutPadding() const;
size_t nRasters() const;
size_t bytesPerDatum() const;
size_t bytesPerPixel() const;
size_t bytesPerLine() const;
size_t totalNumBytes() const;
GLenum glType() const;
Format ghoulTextureFormat() const;
GLenum glTextureFormat() const;
bool shouldAllocateDataOnCPU() const;
HashKey hashKey() const;
const static glm::ivec2 tilePixelStartOffset;
const static glm::ivec2 tilePixelSizeDifference;
private:
void calculateHashKey();
unsigned int getUniqueIdFromTextureFormat(Format textureFormat) const;
HashKey _hashKey;
glm::ivec3 _dimensionsWithPadding;
glm::ivec3 _dimensionsWithoutPadding;
GLenum _glType;
Format _ghoulTextureFormat;
GLenum _glTextureFormat;
size_t _nRasters;
size_t _bytesPerDatum;
size_t _bytesPerPixel;
size_t _bytesPerLine;
size_t _totalNumBytes;
bool _shouldAllocateDataOnCPU;
};
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TILE_TEXTURE_INIT_DATA___H__
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_GLOBEBROWSING___TILE_TEXTURE_INIT_DATA___H__
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILE_TEXTURE_INIT_DATA___H__
#include <ghoul/glm.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/texture.h>
#include <string>
namespace openspace {
namespace globebrowsing {
/**
* All information needed to create a texture used for a Tile.
*/
class TileTextureInitData
{
public:
using HashKey = unsigned long long;
using ShouldAllocateDataOnCPU = ghoul::Boolean;
using Format = ghoul::opengl::Texture::Format;
TileTextureInitData(size_t width, size_t height, GLenum glType, Format textureFormat,
ShouldAllocateDataOnCPU shouldAllocateDataOnCPU = ShouldAllocateDataOnCPU::No);
TileTextureInitData(const TileTextureInitData& original);
~TileTextureInitData() = default;
glm::ivec3 dimensionsWithPadding() const;
glm::ivec3 dimensionsWithoutPadding() const;
size_t nRasters() const;
size_t bytesPerDatum() const;
size_t bytesPerPixel() const;
size_t bytesPerLine() const;
size_t totalNumBytes() const;
GLenum glType() const;
Format ghoulTextureFormat() const;
GLenum glTextureFormat() const;
bool shouldAllocateDataOnCPU() const;
HashKey hashKey() const;
const static glm::ivec2 tilePixelStartOffset;
const static glm::ivec2 tilePixelSizeDifference;
private:
void calculateHashKey();
unsigned int getUniqueIdFromTextureFormat(Format textureFormat) const;
HashKey _hashKey;
glm::ivec3 _dimensionsWithPadding;
glm::ivec3 _dimensionsWithoutPadding;
GLenum _glType;
Format _ghoulTextureFormat;
GLenum _glTextureFormat;
size_t _nRasters;
size_t _bytesPerDatum;
size_t _bytesPerPixel;
size_t _bytesPerLine;
size_t _totalNumBytes;
bool _shouldAllocateDataOnCPU;
};
} // namespace globebrowsing
} // namespace openspace
#endif // __OPENSPACE_MODULE_GLOBEBROWSING___TILE_TEXTURE_INIT_DATA___H__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,57 +1,57 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_VOLUME___RAWVOLUMEWRITER___H__
#define __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__
#include <functional>
#include <string>
#include <modules/volume/rawvolume.h>
namespace openspace {
template <typename VoxelType>
class RawVolumeWriter {
public:
RawVolumeWriter(std::string path, size_t bufferSize = 1024);
void setPath(const std::string& path);
glm::uvec3 dimensions() const;
void setDimensions(const glm::uvec3& dimensions);
void write(const std::function<VoxelType(const glm::uvec3&)>& fn,
const std::function<void(float t)>& onProgress = [](float t) {});
void write(const RawVolume<VoxelType>& volume);
size_t coordsToIndex(const glm::uvec3& coords) const;
glm::ivec3 indexToCoords(size_t linear) const;
private:
glm::ivec3 _dimensions;
std::string _path;
size_t _bufferSize;
};
} // namespace openspace
#include "rawvolumewriter.inl";
#endif // __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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_VOLUME___RAWVOLUMEWRITER___H__
#define __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__
#include <functional>
#include <string>
#include <modules/volume/rawvolume.h>
namespace openspace {
template <typename VoxelType>
class RawVolumeWriter {
public:
RawVolumeWriter(std::string path, size_t bufferSize = 1024);
void setPath(const std::string& path);
glm::uvec3 dimensions() const;
void setDimensions(const glm::uvec3& dimensions);
void write(const std::function<VoxelType(const glm::uvec3&)>& fn,
const std::function<void(float t)>& onProgress = [](float t) {});
void write(const RawVolume<VoxelType>& volume);
size_t coordsToIndex(const glm::uvec3& coords) const;
glm::ivec3 indexToCoords(size_t linear) const;
private:
glm::ivec3 _dimensions;
std::string _path;
size_t _bufferSize;
};
} // namespace openspace
#include "rawvolumewriter.inl"
#endif // __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__