Blue Brain BioExplorer
SharedDataVolume.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  * Responsible Author: Daniel Nachbaur <daniel.nachbaur@epfl.ch>
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 3.0 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
26 
27 namespace core
28 {
35 class SharedDataVolume : public virtual Volume
36 {
37 public:
42  PLATFORM_API virtual void setVoxels(const void* voxels) = 0;
43 
48  PLATFORM_API void mapData(const std::string& filename);
49 
54  PLATFORM_API void mapData(const uint8_ts& buffer);
55 
60  PLATFORM_API void mapData(uint8_ts&& buffer);
61 
67  const uint8_ts& getMemoryBuffer() const { return _memoryBuffer; }
68 
69 protected:
76  SharedDataVolume(const Vector3ui& dimensions, const Vector3f& spacing, const DataType type)
77  : Volume(dimensions, spacing, type)
78  {
79  }
80 
86 
87 protected:
88  uint8_ts _memoryBuffer; // The buffer containing the mapped data
89 
90 private:
91  void* _memoryMapPtr{nullptr}; // The pointer to the mapped memory
92  int _cacheFileDescriptor{-1}; // The file descriptor of the mapped file
93  size_t _size{0}; // The size of the mapped data
94 };
95 } // namespace core
#define PLATFORM_API
Definition: Api.h:37
~SharedDataVolume()
Destructs the SharedDataVolume object. Unmaps the data from memory and closes the mapped file.
virtual PLATFORM_API void setVoxels(const void *voxels)=0
Sets the voxels of the volume.
const uint8_ts & getMemoryBuffer() const
Get the Memory Buffer object.
SharedDataVolume(const Vector3ui &dimensions, const Vector3f &spacing, const DataType type)
Constructs a new SharedDataVolume object.
PLATFORM_API void mapData(const std::string &filename)
Convenience function to map data from file.
A base class for volumes.
Definition: Volume.h:34
glm::vec3 Vector3f
Definition: MathTypes.h:137
glm::vec< 3, uint32_t > Vector3ui
Definition: MathTypes.h:134
DataType
Definition: Types.h:344
std::vector< uint8_t > uint8_ts
Definition: Types.h:49