12#ifndef VOLUMEGRIDHELPER_H_6014714286
13#define VOLUMEGRIDHELPER_H_6014714286
16#include <Carna/Carna.h>
59 const static std::size_t DEFAULT_MAX_SEGMENT_BYTESIZE = 2 * 300 * 300 * 300;
164 template<
typename LoadIntensitiesFunction >
165 void loadIntensities(
const LoadIntensitiesFunction& intensityData );
176 template<
typename LoadHUDataFunction >
177 void loadHUData(
const LoadHUDataFunction& huData );
182template<
typename LoadIntensitiesFunction >
189 return intensityData( loc );
196template<
typename LoadHUDataFunction >
203 return huData( loc );
253template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
257 ,
public details::VolumeGridHelper::
NormalsComponent< SegmentIntensityVolumeType, SegmentNormalsVolumeType >
263 typedef details::VolumeGridHelper:: NormalsComponent< SegmentIntensityVolumeType, SegmentNormalsVolumeType >
NormalsComponent;
268 std::unique_ptr< base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > > myGrid;
272 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
360 (
unsigned int geometryType
369template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
373 const float maxSideLengthF = std::pow
374 ( maxSegmentBytesize /
static_cast< float >(
sizeof(
typename SegmentIntensityVolumeType::Voxel ) ), 1.f / 3 );
384template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
387 , std::size_t maxSegmentBytesize )
389 , maxSegmentBytesize( maxSegmentBytesize )
390 , maxSegmentSize( computeMaxSegmentSize( nativeResolution, maxSegmentBytesize ) )
391 , partitioningX( nativeResolution.x(), maxSegmentSize.x() )
392 , partitioningY( nativeResolution.y(), maxSegmentSize.y() )
393 , partitioningZ( nativeResolution.z(), maxSegmentSize.z() )
394 , resolution( partitioningX.totalSize(), partitioningY.totalSize(), partitioningZ.totalSize() )
412 IntensityComponent::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
413 NormalsComponent ::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
418template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
421 IntensityComponent::releaseGeometryFeatures();
422 NormalsComponent ::releaseGeometryFeatures();
426template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
430 releaseGeometryFeatures();
433 const bool outOfNativeBounds
434 = coord.x() >= nativeResolution.x()
435 || coord.y() >= nativeResolution.y()
436 || coord.z() >= nativeResolution.z();
437 const float intensity = outOfNativeBounds ? 0 : data( coord );
438 myGrid->template setVoxel< typename base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType >::IntensitySelector >( coord, intensity );
440 NormalsComponent::computeNormals();
444template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
452template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
454 (
unsigned int geometryType,
const Spacing& spacing,
const Dimensions& dimensions )
const
495 const bool isTailX = segmentCoord.x() + 1 == myGrid->segmentCounts.x();
496 const bool isTailY = segmentCoord.y() + 1 == myGrid->segmentCounts.y();
497 const bool isTailZ = segmentCoord.z() + 1 == myGrid->segmentCounts.z();
500 ( isTailX ? ( volumeSize.x() - 1 ) * spacing.millimeters.x() : regularSegmentDimensions.x()
501 , isTailY ? ( volumeSize.y() - 1 ) * spacing.millimeters.y() : regularSegmentDimensions.y()
502 , isTailZ ? ( volumeSize.z() - 1 ) * spacing.millimeters.z() : regularSegmentDimensions.z() );
508 IntensityComponent::attachTexture( *geom, segment );
509 NormalsComponent ::attachTexture( *geom, segment );
514 ( segmentCoord.x() * regularSegmentDimensions.x() - ( isTailX ? ( regularSegmentDimensions.x() - segmentDimensions.x() ) / 2 : 0 )
515 , segmentCoord.y() * regularSegmentDimensions.y() - ( isTailY ? ( regularSegmentDimensions.y() - segmentDimensions.y() ) / 2 : 0 )
516 , segmentCoord.z() * regularSegmentDimensions.z() - ( isTailZ ? ( regularSegmentDimensions.z() - segmentDimensions.z() ) / 2 : 0 ) )
517 * base::math::scaling4f( segmentDimensions );
523 ,
"VolumeGridHelper computed "
524 + base::text::lexical_cast< std::string >( 8 *
sizeof(
typename SegmentIntensityVolumeType::Voxel ) )
525 +
"bit grid data using "
526 + base::text::lexical_cast< std::string >( myGrid->segmentCounts.x() ) +
"×"
527 + base::text::lexical_cast< std::string >( myGrid->segmentCounts.y() ) +
"×"
528 + base::text::lexical_cast< std::string >( myGrid->segmentCounts.z() ) +
" segments" );
533template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
535 (
unsigned int geometryType,
const Spacing& spacing )
const
539 return createNode( geometryType, spacing,
Dimensions( dimensions ) );
543template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
545 (
unsigned int geometryType,
const Dimensions& dimensions )
const
549 = mmDimensions.cast<
float >().cwiseQuotient( ( nativeResolution.cast<
int >() -
base::math::Vector3i( 1, 1, 1 ) ).cast<
float >() );
550 return createNode( geometryType,
Spacing( spacing ), dimensions );
554template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
Defines Carna::base::BoundingBox.
Defines Carna::base::Geometry.
Defines Carna::base::Node.
Defines Carna::helpers::details::VolumeGridHelper.
Defines Carna::base::VolumeGrid.
Defines Carna::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.
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 Dimensions &dimensions) const =0
Creates renderable representation of the underlying grid, that can be put anywhere in the scene graph...
static const std::size_t DEFAULT_MAX_SEGMENT_BYTESIZE
Default maximum memory size of a single segment volume, 50 megabytes approximately....
void loadHUData(const std::function< base::HUV(const base::math::Vector3ui &) > &huData)
Updates the data of the volume grid.
virtual ~VolumeGridHelperBase()
Does nothing.
virtual void loadIntensities(const std::function< float(const base::math::Vector3ui &) > &intensityData)=0
Updates the data of the volume grid.
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...
const base::math::Vector3ui nativeResolution
Holds the original resolution of the loaded data.
Computes the partitioning of volumetric data and the corresponding normal map. Also creates scene nod...
const base::math::Vector3ui resolution
Holds the effective resolution, i.e. the resolution covered by the grid.
virtual void loadIntensities(const std::function< float(const base::math::Vector3ui &) > &intensityData) override
Updates the data of the volume grid.
const base::math::Vector3ui maxSegmentSize
The maximum effective resolution of a single grid segment.
VolumeGridHelper(const base::math::Vector3ui &nativeResolution, std::size_t maxSegmentBytesize=DEFAULT_MAX_SEGMENT_BYTESIZE)
Creates new base::VolumeGrid object. Initializes its' segments s.t. the totally covered resolution is...
virtual void releaseGeometryFeatures() override
Releases all previously acquired textures. Invoke this method when the volume data changes,...
const details::VolumeGridHelper::Partionining partitioningZ
Describes the partitioning along the z-axis.
base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > & grid() const
References the underlying grid.
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...
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 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 Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
#define CARNA_FOR_VECTOR3UI(vecName, vecLimit)
Loops vecName over all where is vecLimit.
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Eigen::Matrix< signed int, 3, 1 > Vector3i
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.
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Specifies the dimensions of the whole dataset in millimeters.
base::math::Vector3f millimeters
Holds the dimensions of the whole dataset in millimeters.
Dimensions(const base::math::Vector3f &millimeters)
Instantiates.
Specifies the spacing between two succeeding voxel centers in millimeters.
base::math::Vector3f millimeters
Holds the spacing between two succeeding voxel centers in millimeters.
Spacing(const base::math::Vector3f &millimeters)
Instantiates.
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.