15#ifndef VOLUMEGRIDHELPER_H_6014714286
16#define VOLUMEGRIDHELPER_H_6014714286
60 const static std::size_t DEFAULT_MAX_SEGMENT_BYTESIZE = 2 * 300 * 300 * 300;
153 template<
typename LoadIntensitiesFunction >
154 void loadIntensities(
const LoadIntensitiesFunction& intensityData );
168template<
typename LoadIntensitiesFunction >
175 return intensityData( loc );
217template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
221 ,
public details::VolumeGridHelper::
NormalsComponent< SegmentIntensityVolumeType, SegmentNormalsVolumeType >
227 typedef details::VolumeGridHelper:: NormalsComponent< SegmentIntensityVolumeType, SegmentNormalsVolumeType >
NormalsComponent;
232 std::unique_ptr< base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > > myGrid;
236 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
324 (
unsigned int geometryType
326 ,
const Extent& extent )
const;
335template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
339 const float maxSideLengthF = std::pow
340 ( maxSegmentBytesize /
static_cast< float >(
sizeof(
typename SegmentIntensityVolumeType::Voxel ) ), 1.f / 3 );
350template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
353 , std::size_t maxSegmentBytesize )
355 , maxSegmentBytesize( maxSegmentBytesize )
356 , maxSegmentSize( computeMaxSegmentSize( nativeResolution, maxSegmentBytesize ) )
357 , partitioningX( nativeResolution.x(), maxSegmentSize.x() )
358 , partitioningY( nativeResolution.y(), maxSegmentSize.y() )
359 , partitioningZ( nativeResolution.z(), maxSegmentSize.z() )
360 , resolution( partitioningX.totalSize(), partitioningY.totalSize(), partitioningZ.totalSize() )
378 IntensityComponent::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
379 NormalsComponent ::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
384template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
387 IntensityComponent::releaseGeometryFeatures();
388 NormalsComponent ::releaseGeometryFeatures();
392template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
396 releaseGeometryFeatures();
399 const bool outOfNativeBounds
400 = coord.x() >= nativeResolution.x()
401 || coord.y() >= nativeResolution.y()
402 || coord.z() >= nativeResolution.z();
403 const float intensity = outOfNativeBounds ? 0 : data( coord );
404 myGrid->template setVoxel< typename base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType >::IntensitySelector >( coord, intensity );
406 NormalsComponent::computeNormals();
410template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
418template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
420 (
unsigned int geometryType,
const Spacing& spacing,
const Extent& extent )
const
460 const bool isTailX = segmentCoord.x() + 1 == myGrid->segmentCounts.x();
461 const bool isTailY = segmentCoord.y() + 1 == myGrid->segmentCounts.y();
462 const bool isTailZ = segmentCoord.z() + 1 == myGrid->segmentCounts.z();
465 ( isTailX ? ( volumeSize.x() - 1 ) * spacing.units.x() : regularSegmentExtent.x()
466 , isTailY ? ( volumeSize.y() - 1 ) * spacing.units.y() : regularSegmentExtent.y()
467 , isTailZ ? ( volumeSize.z() - 1 ) * spacing.units.z() : regularSegmentExtent.z() );
473 IntensityComponent::attachTexture( *geom, segment );
474 NormalsComponent ::attachTexture( *geom, segment );
479 ( segmentCoord.x() * regularSegmentExtent.x() - ( isTailX ? ( regularSegmentExtent.x() - segmentExtent.x() ) / 2 : 0 )
480 , segmentCoord.y() * regularSegmentExtent.y() - ( isTailY ? ( regularSegmentExtent.y() - segmentExtent.y() ) / 2 : 0 )
481 , segmentCoord.z() * regularSegmentExtent.z() - ( isTailZ ? ( regularSegmentExtent.z() - segmentExtent.z() ) / 2 : 0 ) )
482 * base::math::scaling4f( segmentExtent );
488 ,
"VolumeGridHelper computed "
489 + base::text::lexical_cast< std::string >( 8 *
sizeof(
typename SegmentIntensityVolumeType::Voxel ) )
490 +
"bit grid data using "
491 + base::text::lexical_cast< std::string >( myGrid->segmentCounts.x() ) +
"×"
492 + base::text::lexical_cast< std::string >( myGrid->segmentCounts.y() ) +
"×"
493 + base::text::lexical_cast< std::string >( myGrid->segmentCounts.z() ) +
" segments" );
498template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
500 (
unsigned int geometryType,
const Spacing& spacing )
const
504 ).cast< float >().cwiseProduct( spacing.
units );
505 return createNode( geometryType, spacing,
Extent( extent ) );
509template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
511 (
unsigned int geometryType,
const Extent& extent )
const
516 return createNode( geometryType,
Spacing( spacing ), extent );
520template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
Defines LibCarna::base::BoundingBox.
Defines LibCarna::base::Geometry.
Contains forward-declarations.
Defines LibCarna::base::Node.
Defines LibCarna::helpers::details::VolumeGridHelper.
Defines LibCarna::base::VolumeGrid.
Defines LibCarna::base::VolumeSegment.
Represents an association.
Defines a Geometry minimal boundary box.
Defines scene graph leafs. Instances of this class represent visible geometry that can be rendered....
void setBoundingVolume(BoundingVolume *boundingVolume)
Sets boundingVolume as the minimum boundary volume of this node. Supply nullptr for boundingVolume to...
@ debug
Indicates messages that might be of interest when searching bugs.
Defines the inner node of a scene graph. Implements a spatial scene element that is allowed to have c...
void attachChild(Spatial *child)
Attaches child to this node in and takes it's possession.
static Log & instance()
Returns the only instance from class InstanceType.
void setMovable(bool movable)
Sets whether this spatial may be displaced w.r.t. it's parent through user interaction....
math::Matrix4f localTransform
Defines the location, rotation and scale of this spatial in relation to it's parent....
Defines type-parameters-independent VolumeGridHelper base interface.
VolumeGridHelperBase(const base::math::Vector3ui &nativeResolution)
Instantiates.
static const std::size_t DEFAULT_MAX_SEGMENT_BYTESIZE
Default maximum memory size of a single segment volume, 50 megabytes approximately....
const base::math::Vector3ui nativeResolution
Holds the original resolution of the loaded data.
virtual ~VolumeGridHelperBase()
Does nothing.
virtual void releaseGeometryFeatures()=0
Releases all previously acquired textures. Invoke this method when the volume data changes.
virtual base::Node * createNode(unsigned int geometryType, const Spacing &spacing) const =0
Creates renderable representation of the underlying grid, that can be put anywhere in the scene graph...
virtual base::Node * createNode(unsigned int geometryType, const Extent &extent) const =0
Creates renderable representation of the underlying grid, that can be put anywhere in the scene graph...
virtual void loadIntensities(const std::function< float(const base::math::Vector3ui &) > &intensityData)=0
Updates the data of the volume grid.
void loadIntensities(const LoadIntensitiesFunction &intensityData)
Computes the partitioning of volumetric data and the corresponding normal map. Also creates scene nod...
const std::size_t maxSegmentBytesize
Maximum memory size of a single segment volume.
const details::VolumeGridHelper::Partionining partitioningX
Describes the partitioning along the x-axis.
const details::VolumeGridHelper::Partionining partitioningZ
Describes the partitioning along the z-axis.
virtual base::Node * createNode(unsigned int geometryType, const Spacing &spacing) const override
Creates renderable representation of the underlying grid, that can be put anywhere in the scene graph...
VolumeGridHelper(const base::math::Vector3ui &nativeResolution, std::size_t maxSegmentBytesize=DEFAULT_MAX_SEGMENT_BYTESIZE)
Creates a new base::VolumeGrid object. Initializes the segments of the grid so that the totally cover...
virtual void loadIntensities(const std::function< float(const base::math::Vector3ui &) > &intensityData) override
Updates the data of the volume grid.
const base::math::Vector3ui resolution
Holds the effective resolution, i.e. the resolution covered by the grid.
virtual void releaseGeometryFeatures() override
Releases all previously acquired textures. Invoke this method when the volume data changes,...
const base::math::Vector3ui maxSegmentSize
The maximum effective resolution of a single grid segment.
base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > & grid() const
References the underlying grid.
const details::VolumeGridHelper::Partionining partitioningY
Describes the partitioning along the y-axis.
Defines the helpers::VolumeGridHelper component that maintains intensity volume data.
Defines the helpers::VolumeGridHelper component that computes and maintains normal maps.
void setGrid(base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &grid)
Sets the grid that computeNormals operates on.
Defines LibCarna::base::math namespace and LIBCARNA_FOR_VECTOR3UI.
#define LIBCARNA_FOR_VECTOR3UI(vecName, vecLimit)
Loops vecName over all where is vecLimit.
Eigen::Matrix< signed int, 3, 1 > Vector3i
Defines vector.
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
ScalarType makeEven(ScalarType x, int s)
Returns if is even and if is odd, where . The data type of must be integral.
unsigned int round_ui(ScalarType x)
Rounds x to the closest . Either the data type of must be unsigned or .
Matrix4f translation4f(float x, float y, float z)
Returns matrix that translates homogeneous coordinates.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
#define NON_COPYABLE
Marks the class that it is placed in as non-copyable.
Specifies the extent of the whole dataset.
Extent(const base::math::Vector3f &units)
Instantiates.
base::math::Vector3f units
Holds the extent of the whole dataset in units.
Specifies the spacing between two succeeding voxel centers.
Spacing(const base::math::Vector3f &units)
Instantiates.
base::math::Vector3f units
Holds the spacing between two succeeding voxel centers.
Computes the partitioning that VolumeGridHelper uses along one dimension.
std::size_t partitionsCount() const
Tells the total partitions number.
std::size_t tailSize
Holds the resolution of the last partition that may also be 0.
std::size_t regularPartitionSize
Holds the always odd, effective resolution of a single regular partition.