LibCarna Version 3.4.0
Loading...
Searching...
No Matches
BufferedIntensityVolume.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef BUFFEREDINTENSITYVOLUME_H_6014714286
16#define BUFFEREDINTENSITYVOLUME_H_6014714286
17
26#include <vector>
27#include <memory>
28
29namespace LibCarna
30{
31
32namespace base
33{
34
35
36
37// ----------------------------------------------------------------------------------
38// BufferedIntensityVolume
39// ----------------------------------------------------------------------------------
40
49template< typename VoxelType, typename BufferType >
51{
52
53public:
54
59
63 typedef VoxelType Voxel;
64
79
84 , myBuffer( new Composition< BufferType >( new BufferType( size.x() * size.y() * size.z() ) ) )
85 {
86 initializeBuffer();
87 }
88
92 static float bufferValueToIntensity( VoxelType bufferValue )
93 {
94 return bufferValue / static_cast< float >( ( 1 << ( 8 * sizeof( VoxelType ) ) ) - 1 );
95 }
96
100 static VoxelType intensityToBufferValue( float intensity )
101 {
102 LIBCARNA_ASSERT_EX( 0 <= intensity && intensity <= 1, "Intensity out of range: " << intensity ); // TODO: check how much this slows down?
103 const auto valueMax = ( 1 << ( 8 * sizeof( VoxelType ) ) ) - 1;
104 float value = intensity * valueMax + 0.5f;
105 if( value > valueMax ) value = valueMax;
106 return static_cast< VoxelType >( value );
107 }
108
112 float operator()( unsigned int x
113 , unsigned int y
114 , unsigned int z ) const
115 {
116 const std::size_t index = x + size.x() * y + size.y() * size.x() * z;
117 return bufferValueToIntensity( myBuffer->get()->at( index ) );
118 }
119
122 float operator()( const math::Vector3ui& at ) const
123 {
124 return ( *this )( at.x(), at.y(), at.z() );
125 }
126
130 void setVoxel( unsigned int x, unsigned int y, unsigned int z, float intensity )
131 {
132 LIBCARNA_ASSERT( x < size.x() && y < size.y() && z < size.z() );
133 const std::size_t index = x + size.x() * y + size.y() * size.x() * z;
134 myBuffer->get()->at( index ) = intensityToBufferValue( intensity );
135 }
136
139 void setVoxel( const math::Vector3ui& at, float intensity )
140 {
141 this->setVoxel( at.x(), at.y(), at.z(), intensity );
142 }
143
148 {
149 return **myBuffer;
150 }
151
155 const BufferType& buffer() const
156 {
157 return **myBuffer;
158 }
159
160protected:
161
171 const std::unique_ptr< Association< BufferType > > myBuffer;
172
173private:
174
175 void initializeBuffer()
176 {
178 ( myBuffer.get() && myBuffer->get()
179 , "No volume data buffer supplied!" );
180
182 ( myBuffer->get()->size() >= size.x() * size.y() * size.z()
183 , "Supplied volume data buffer is of size "
184 << myBuffer->get()->size()
185 << " bytes but must be at least "
186 << size.x() * size.y() * size.z()
187 << " bytes!" );
188 }
189
190}; // BufferedIntensityVolume
191
192
193
194} // namespace LibCarna :: base
195
196} // namespace LibCarna
197
198#endif // BUFFEREDINTENSITYVOLUME_H_6014714286
Defines LibCarna::base::Composition.
Defines LibCarna::base::IntensityVolume.
Defines LibCarna::base::LibCarnaException and LibCarna::base::AssertionFailure.
#define LIBCARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
#define LIBCARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Represents an association.
AssociatedObjectType * get() const
Returns raw pointer to the referenced object.
Implements IntensityVolume generically for a particular VoxelType.
void setVoxel(const math::Vector3ui &at, float intensity)
BufferType & buffer()
References the underlying buffer.
VoxelType Voxel
Holds the type used to store the value of a single voxel.
static float bufferValueToIntensity(VoxelType bufferValue)
Returns the intensity value corresponding to bufferValue.
BufferedIntensityVolume(const math::Vector3ui &size, Association< BufferType > *buffer)
Instantiates with , where is size.
float operator()(const math::Vector3ui &at) const
BufferType Buffer
Holds the used buffer type.
void setVoxel(unsigned int x, unsigned int y, unsigned int z, float intensity)
Sets the intensity value of a voxel.
const std::unique_ptr< Association< BufferType > > myBuffer
Holds the underlying buffer.
float operator()(unsigned int x, unsigned int y, unsigned int z) const
Returns intensity of specified voxel.
static VoxelType intensityToBufferValue(float intensity)
Returns the buffer value corresponding to an intensity.
const BufferType & buffer() const
References the underlying buffer.
BufferedIntensityVolume(const math::Vector3ui &size)
Represents a composition, i.e. a strong reference. This basically is a std::unique_ptr that supports ...
Defines interface to volume data.
math::Vector3ui size
Holds the resolution.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Definition math.hpp:203