12 #ifndef BUFFEREDNORMALMAP3D_H_6014714286
13 #define BUFFEREDNORMALMAP3D_H_6014714286
25 #include <type_traits>
58 template<
typename BufferedVectorComponentType,
typename BufferType >
63 ( std::is_integral< BufferedVectorComponentType >::value
64 ,
"Only integral buffer vector component types allowed." );
96 ( new BufferType( 4 * sizeof( BufferedVectorComponentType ) * size.x() * size.y() * size.z() ) ) )
111 const float range =
static_cast< float >(
static_cast< signed long >( std::numeric_limits< BufferedVectorComponentType >::max() )
112 - static_cast< signed long >( std::numeric_limits< BufferedVectorComponentType >::min() ) );
113 const signed long x = encodedVectorComponent;
114 const float fraction = ( x -
static_cast< signed long >( std::numeric_limits< BufferedVectorComponentType >::min() ) ) / range;
115 return ( fraction - 0.5f ) * 2;
130 ( std::abs( actualVectorComponent ) <= 1
131 ,
"Unnormalized vector! Component: " + text::lexical_cast< std::string >( actualVectorComponent ) );
133 const signed long range =
static_cast< signed long >( std::numeric_limits< BufferedVectorComponentType >::max() )
134 - static_cast< signed long >( std::numeric_limits< BufferedVectorComponentType >::min() );
135 const signed long result =
static_cast< signed long >( ( ( actualVectorComponent + 1 ) * range ) / 2 )
136 + static_cast< signed long >( std::numeric_limits< BufferedVectorComponentType >::min() );
137 return static_cast< BufferedVectorComponentType
>( result );
145 return ( *
this )( location.x(), location.y(), location.z() );
153 ,
unsigned int z )
const
156 const std::size_t index = 4 * ( x +
size.x() * y +
size.y() *
size.x() * z );
168 this->
setVoxel( location.x(), location.y(), location.z(), normal );
176 const std::size_t index = 4 * ( x +
size.x() * y +
size.y() *
size.x() * z );
203 const std::unique_ptr< Association< BufferType > >
myBuffer;
210 ( myBuffer.get() && myBuffer->get()
211 ,
"No volume data buffer supplied!" );
214 ( myBuffer->get()->size() >=
size.x() *
size.y() *
size.z()
215 ,
"Supplied volume data buffer is of size "
216 << myBuffer->get()->size()
217 <<
" bytes but must be at least "
218 << 4 *
sizeof( BufferedVectorComponentType ) *
size.x() *
size.y() *
size.z()
230 #endif // BUFFEREDNORMALMAP3D_H_6014714286
static BufferedVectorComponentType encodeComponent(float actualVectorComponent)
Returns the buffered vector component corresponding to actualVectorComponent.
static float decodeComponent(BufferedVectorComponentType encodedVectorComponent)
Returns the actual normal vector component corresponding to encodedVectorComponent.
Defines Carna::base::text.
#define CARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
void setVoxel(unsigned int x, unsigned int y, unsigned int z, const math::Vector3f &normal)
Implements NormalMap3D generically for a particular VoxelType.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
BufferedNormalMap3D(const math::Vector3ui &size, Association< BufferType > *buffer)
Instantiates.
math::Vector3ui size
Holds the resolution.
Defines Carna::base::NormalMap3D.
BufferType Buffer
Holds the used buffer type.
void setVoxel(const math::Vector3ui &location, const math::Vector3f &normal)
Encodes normal and stores it at location.
BufferedNormalMap3D(const math::Vector3ui &size)
BufferType & buffer()
References the underlying buffer.
BufferedVectorComponentType BufferedVectorComponent
Holds the type used to store the components of the normal vectors.
Defines interface to mapping.
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
Represents a composition, i.e. a strong reference. This basically is a std::unique_ptr that supports ...
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
const std::unique_ptr< Association< BufferType > > myBuffer
Holds the buffer.
const BufferType & buffer() const
References the underlying buffer.
Defines Carna::base::Composition.
math::Vector3f operator()(const math::Vector3ui &location) const
Decodes and tells the vector stored at location.