Carna Version 3.3.3
Loading...
Searching...
No Matches
BufferedHUVolume.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2015 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 */
11
12#ifndef BUFFEREDHUVOLUME_H_6014714286
13#define BUFFEREDHUVOLUME_H_6014714286
14
19#include <Carna/base/HUVolume.h>
22#include <vector>
23#include <memory>
24
25namespace Carna
26{
27
28namespace base
29{
30
31
32
33// ----------------------------------------------------------------------------------
34// BufferedHUVolume
35// ----------------------------------------------------------------------------------
36
48template< typename VoxelType, typename BufferType >
50{
51
52public:
53
58
62 typedef VoxelType Voxel;
63
73 : HUVolume( size )
74 , myBuffer( buffer )
75 {
76 initializeBuffer();
77 }
78
82 : HUVolume( size )
83 , myBuffer( new Composition< BufferType >( new BufferType( size.x() * size.y() * size.z() ) ) )
84 {
85 initializeBuffer();
86 }
87
91 static HUV bufferValueToHUV( VoxelType bufferValue )
92 {
93 return HUV::abs( ( bufferValue >> ( sizeof( VoxelType ) * 8 - 12 ) ) - 1024 );
94 }
95
99 static VoxelType HUVToBufferValue( HUV huValue )
100 {
101 return ( static_cast< VoxelType >( huValue + 1024 ) << ( sizeof( VoxelType ) * 8 - 12 ) );
102 }
103
107 HUV operator()( unsigned int x
108 , unsigned int y
109 , unsigned int z ) const
110 {
111 const std::size_t index = x + size.x() * y + size.y() * size.x() * z;
112 return bufferValueToHUV( myBuffer->get()->at( index ) );
113 }
114
119 {
120 return ( *this )( at.x(), at.y(), at.z() );
121 }
122
126 void setVoxel( unsigned int x, unsigned int y, unsigned int z, HUV huv )
127 {
128 CARNA_ASSERT( x < size.x() && y < size.y() && z < size.z() );
129 const std::size_t index = x + size.x() * y + size.y() * size.x() * z;
130 myBuffer->get()->at( index ) = HUVToBufferValue( huv );
131 }
132
137 {
138 this->setVoxel( at.x(), at.y(), at.z(), huv );
139 }
140
145 {
146 return **myBuffer;
147 }
148
152 const BufferType& buffer() const
153 {
154 return **myBuffer;
155 }
156
157protected:
158
168 const std::unique_ptr< Association< BufferType > > myBuffer;
169
170private:
171
172 void initializeBuffer()
173 {
175 ( myBuffer.get() && myBuffer->get()
176 , "No volume data buffer supplied!" );
177
179 ( myBuffer->get()->size() >= size.x() * size.y() * size.z()
180 , "Supplied volume data buffer is of size "
181 << myBuffer->get()->size()
182 << " bytes but must be at least "
183 << size.x() * size.y() * size.z()
184 << " bytes!" );
185 }
186
187}; // BufferedHUVolume
188
189
190
191} // namespace Carna :: base
192
193} // namespace Carna
194
195#endif // BUFFEREDHUVOLUME_H_6014714286
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
#define CARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Defines Carna::base::Composition.
Defines Carna::base::HUVolume.
Represents an association.
Definition Association.h:45
AssociatedObjectType * get() const
Returns raw pointer to the referenced object.
Definition Association.h:61
Implements HUVolume generically for a particular VoxelType.
HUV operator()(unsigned int x, unsigned int y, unsigned int z) const
Returns HUV of specified voxel.
void setVoxel(const math::Vector3ui &at, HUV huv)
Sets the HUV of a voxel.
HUV operator()(const math::Vector3ui &at) const
Returns HUV of specified voxel.
const std::unique_ptr< Association< BufferType > > myBuffer
Holds the underlying buffer.
BufferedHUVolume(const math::Vector3ui &size, Association< BufferType > *buffer)
Instantiates with , where is size.
BufferType Buffer
Holds the used buffer type.
static HUV bufferValueToHUV(VoxelType bufferValue)
Returns the HU value corresponding to bufferValue.
VoxelType Voxel
Holds the type used to store the value of a single voxel.
void setVoxel(unsigned int x, unsigned int y, unsigned int z, HUV huv)
Sets the HUV of a voxel.
BufferedHUVolume(const math::Vector3ui &size)
static VoxelType HUVToBufferValue(HUV huValue)
Returns the buffer value corresponding to huValue.
const BufferType & buffer() const
References the underlying buffer.
BufferType & buffer()
References the underlying buffer.
Represents a composition, i.e. a strong reference. This basically is a std::unique_ptr that supports ...
Definition Composition.h:53
Defines interface to volumetric data.
Definition HUVolume.h:47
math::Vector3ui size
Holds the resolution.
Definition HUVolume.h:66
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Definition math.h:199
Represents values in .
Definition HUV.h:35
static HUV abs(T value)
Wraps an absolute HU value.
Definition HUV.h:134