/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2021 * * * * 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 namespace openspace::volume { template RawVolume::RawVolume(const glm::uvec3& dimensions) : _dimensions(dimensions) , _data(static_cast(dimensions.x) * static_cast(dimensions.y) * static_cast(dimensions.z)) {} template glm::uvec3 RawVolume::dimensions() const { return _dimensions; } template void RawVolume::setDimensions(const glm::uvec3& dimensions) { _dimensions = dimensions; _data.resize(nCells()); } template size_t RawVolume::nCells() const { return static_cast(_dimensions.x) * static_cast(_dimensions.y) * static_cast(_dimensions.z); } template VoxelType RawVolume::get(const glm::uvec3& coordinates) const { return get(coordsToIndex(coordinates)); } template VoxelType RawVolume::get(size_t index) const { return _data[index]; } template void RawVolume::set(const glm::uvec3& coordinates, const VoxelType& value) { return set(coordsToIndex(coordinates), value); } template void RawVolume::set(size_t index, const VoxelType& value) { _data[index] = value; } template void RawVolume::forEachVoxel( const std::function& fn) { for (size_t i = 0; i < nCells(); i++) { const glm::ivec3& coords = indexToCoords(i); fn(coords, _data[i]); } } template size_t RawVolume::coordsToIndex(const glm::uvec3& cartesian) const { return volume::coordsToIndex(cartesian, dimensions()); } template glm::uvec3 RawVolume::indexToCoords(size_t linear) const { return volume::indexToCoords(linear, dimensions()); } template VoxelType* RawVolume::data() { return _data.data(); } template const VoxelType* RawVolume::data() const { return _data.data(); } } // namespace openspace::volume