12#ifndef VOLUMEGRIDHELPERDETAILS_H_6014714286
13#define VOLUMEGRIDHELPERDETAILS_H_6014714286
15#include <Carna/Carna.h>
58template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
80template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
100template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
123template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
144template<
typename TextureFactory >
152 <
typename TextureFactory::SegmentIntensityVolume
153 ,
typename TextureFactory::SegmentNormalsVolume >*
178 <
typename TextureFactory::SegmentIntensityVolume
179 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const;
185 <
typename TextureFactory::SegmentIntensityVolume
186 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const;
191template<
typename TextureFactory >
194 releaseGeometryFeatures();
198template<
typename TextureFactory >
201 for(
auto itr = textures.begin(); itr != textures.end(); ++itr )
210template<
typename TextureFactory >
215 <
typename TextureFactory::SegmentIntensityVolume
216 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const
223template<
typename TextureFactory >
226 <
typename TextureFactory::SegmentIntensityVolume
227 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const
229 auto textureItr = textures.find( &segment );
230 if( textureItr == textures.end() )
235 textures[ &segment ] = &texture;
242 return *textureItr->second;
259template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
313template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
315 : role( DEFAULT_ROLE_INTENSITIES )
320template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
327template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
334template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
340 ::attachTexture( geometry, role, segment );
344template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
349 SegmentIntensityVolumeType*
const intensities =
new SegmentIntensityVolumeType( size );
398template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
400 :
public TextureManager< NormalsTextureFactory< SegmentIntensityVolumeType, SegmentNormalsVolumeType > >
466template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
468 : role( DEFAULT_ROLE_NORMALS )
473template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
480template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
487template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
498 const Vector3ui resolution = gridResolution();
503 for(
unsigned int dim0 = 0; dim0 < 3; ++dim0 )
505 for(
signed int sign = -1; sign <= +1; sign += 2 )
509 Vector3f normal( 0, 0, 0 );
510 normal( dim0 ) = sign;
514 const unsigned int dim1 = ( dim0 + 1 ) % 3;
515 const unsigned int dim2 = ( dim0 + 2 ) % 3;
518 coord( dim0 ) = sign < 0 ? 0 : resolution( dim0 ) - 1;
520 for( coord( dim1 ) = 0; coord( dim1 ) < resolution( dim1 ); ++coord( dim1 ) )
521 for( coord( dim2 ) = 0; coord( dim2 ) < resolution( dim2 ); ++coord( dim2 ) )
523 grid->template setVoxel< NormalSelector >( coord, normal );
530 const Vector3ui coordLowerBound = Vector3ui( 1, 1, 1 );
531 const Vector3ui coordUpperBound = ( resolution.cast<
int >() - Vector3i( 1, 1, 1 ) ).cast< unsigned int >();
537 [
this, &coord](
unsigned int dx,
unsigned int dy,
unsigned int dz )
539 return grid->template getVoxel< IntensitySelector >( Vector3ui( coord.x() + dx, coord.y() + dy, coord.z() + dz ) );
546 Vector3f normal = -gradient;
547 if( normal.squaredNorm() > 1e-12 )
553 normal = Vector3f( 0, 0, 0 );
555 grid->template setVoxel< NormalSelector >( coord, normal );
562 ,
"VolumeGridHelper finished normals computation in "
563 + base::text::lexical_cast< std::string >( seconds )
568template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
576template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
582 ::attachTexture( geometry, role, segment );
586template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
591 SegmentNormalsVolumeType*
const normals =
new SegmentNormalsVolumeType( size );
607template<
typename SegmentIntensityVolumeType >
647template<
typename SegmentIntensityVolumeType >
653template<
typename SegmentIntensityVolumeType >
659template<
typename SegmentIntensityVolumeType >
666template<
typename SegmentIntensityVolumeType >
674template<
typename SegmentIntensityVolumeType >
Defines Carna::base::BufferedNormalMap3D.
Defines Carna::base::BufferedVectorFieldTexture.
#define CARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Defines Carna::base::Geometry.
Defines Carna::base::Log.
Defines Carna::base::Stopwatch.
Defines Carna::base::VolumeGrid.
Defines Carna::base::VolumeSegment.
Represents an association.
static BufferedVectorFieldTexture< BufferedVectorFieldType > & create(const BufferedVectorFieldType &field)
Instantiates. Invoke release when it isn't needed any longer.
void release()
Denotes that this object is no longer required and may be deleted as soon as it is valid to delete it...
Defines scene graph leafs. Instances of this class represent visible geometry that can be rendered....
void putFeature(unsigned int role, GeometryFeature &feature)
Adds the feature to this geometry node using role in . The concept of geometry features and roles is ...
@ verbose
Indicates statistics and suchlike.
Represents 3D OpenGL texture object whose lifetime is managed by instances of this class.
static Log & instance()
Returns the only instance from class InstanceType.
Implements stopwatch using the robust wallclock time from OMP that most compilers support.
double result() const
Tells result in seconds from current time measurement.
Represents a single volumetric data partition.
Computes the partitioning of volumetric data and the corresponding normal map. Also creates scene nod...
Defines the helpers::VolumeGridHelper component that maintains intensity volume data.
static const unsigned int DEFAULT_ROLE_INTENSITIES
Holds the default role to use for attaching textures to base::Geometry nodes.
void setIntensitiesRole(unsigned int role)
Sets the role to use for attaching textures to base::Geometry nodes.
unsigned int intensitiesRole() const
Tels the role used for attaching textures to base::Geometry nodes.
void attachTexture(base::Geometry &geometry, const base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment) const
Attaches the texture that represents the base::VolumeSegment::intensities of segment to geometry usin...
IntensityComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_INTENSITIES.
void initializeSegment(base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment, const base::math::Vector3ui &size) const
Initializes intensity volume of segment.
Defines the NormalsComponent base class that is independent of type arguments.
virtual ~NormalsComponentBase()
Deletes.
virtual base::math::Vector3ui gridResolution() const =0
Tells the effective grid resolution.
Defines the helpers::VolumeGridHelper component that computes and maintains normal maps.
void attachTexture(base::Geometry &geometry, const base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment) const
Attaches the texture that represents the base::VolumeSegmentNormalsComponent::normals of segment to g...
void setNormalsRole(unsigned int role)
Sets the role to use for attaching textures to base::Geometry nodes.
void computeNormals()
Computes the normal map on the previously set grid.
unsigned int normalsRole() const
Tels the role used for attaching textures to base::Geometry nodes.
NormalsComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_NORMALS.
void setGrid(base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &grid)
Sets the grid that computeNormals operates on.
static const unsigned int DEFAULT_ROLE_NORMALS
Holds the default role to use for attaching textures to base::Geometry nodes.
void initializeSegment(base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment, const base::math::Vector3ui &size) const
Initializes normal map of segment.
Provides mapping base::VolumeSegment to base::ManagedTexture3D objects in a caching manner....
void attachTexture(base::Geometry &geometry, unsigned int role, const base::VolumeSegment< typename TextureFactory::SegmentIntensityVolume, typename TextureFactory::SegmentNormalsVolume > &segment) const
Attaches the texture that TextureFactory creates from segment to geometry using role.
void releaseGeometryFeatures()
Releases all textures.
virtual ~TextureManager()
Releases all textures and deletes.
#define CARNA_FOR_VECTOR3UI_EX(vecName, vecLimit, vecStart)
Loops vecName over all where is vecLimit and is vecStart.
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
base::math::Vector3f computeFastGradient3f(Sampler func)
Computes fast approximation of the gradient at the origin of the scalar field func.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Eigen::Matrix< signed int, 3, 1 > Vector3i
Defines vector.
unsigned int round_ui(ScalarType x)
Rounds x to the closest . Either the data type of must be unsigned or .
#define NON_COPYABLE
Features class it is placed in as non-copyable.
References the intensity volume of a given partition.
Creates textures that represents base::VolumeSegment::intensities in video memory.
static base::ManagedTexture3D & createTexture(const base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment)
Creates texture that represents the base::VolumeSegment::intensities of segment in video memory.
SegmentNormalsVolumeType SegmentNormalsVolume
Reflects the type to use for storing the normal map of a single partition.
SegmentIntensityVolumeType SegmentIntensityVolume
Reflects the type to use for storing the intensity volume of a single partition.
Creates textures that represents base::VolumeSegmentNormalsComponent::normals in video memory.
SegmentNormalsVolumeType SegmentNormalsVolume
Reflects the type to use for storing the normal map of a single partition.
static base::ManagedTexture3D & createTexture(const base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment)
Creates texture that represents the base::VolumeSegmentNormalsComponent::normals of segment in video ...
SegmentIntensityVolumeType SegmentIntensityVolume
Reflects the type to use for storing the intensity volume of a single partition.
Computes the partitioning that VolumeGridHelper uses along one dimension.
std::size_t partitionsCount() const
Tells the total partitions number.
Partionining(std::size_t nativeSize, std::size_t regularPartitionSize)
Computes the partitioning.
std::size_t tailSize
Holds the resolution of the last partition that may also be 0.
std::size_t regularPartitionsCount
Holds the number of regular partitions, i.e. such of the size held by regularPartitionSize.
std::size_t totalSize() const
Computes the effective total resolution.
std::size_t regularPartitionSize
Holds the always odd, effective resolution of a single regular partition.
Defines Carna::base::text.