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;
86 virtual void releaseGeometryFeatures() = 0;
136 virtual base::Node* createNode(
unsigned int geometryType,
const Spacing& spacing )
const = 0;
153 virtual base::Node* createNode(
unsigned int geometryType,
const Dimensions& dimensions )
const = 0;
160 virtual void loadIntensities(
const std::function<
float(
const base::math::Vector3ui& ) >& intensityData ) = 0;
164 template<
typename LoadIntensitiesFunction >
165 void loadIntensities(
const LoadIntensitiesFunction& intensityData );
176 template<
typename LoadHUDataFunction >
177 void loadHUData(
const LoadHUDataFunction& huData );
182 template<
typename LoadIntensitiesFunction >
185 loadIntensities(
static_cast< const std::function< float( const base::math::Vector3ui& ) >&
> 189 return intensityData( loc );
196 template<
typename LoadHUDataFunction >
199 loadHUData(
static_cast< const std::function< base::HUV( const base::math::Vector3ui& ) >&
> 203 return huData( loc );
253 template<
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
330 virtual void loadIntensities(
const std::function<
float(
const base::math::Vector3ui& ) >& intensityData )
override;
342 virtual void releaseGeometryFeatures()
override;
349 virtual base::Node* createNode(
unsigned int geometryType,
const Spacing& spacing )
const override;
351 virtual base::Node* createNode(
unsigned int geometryType,
const Dimensions& dimensions )
const override;
360 (
unsigned int geometryType
369 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
373 const float maxSideLengthF = std::pow
374 ( maxSegmentBytesize / static_cast< float >(
sizeof(
typename SegmentIntensityVolumeType::Voxel ) ), 1.f / 3 );
384 template<
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() )
401 NormalsComponent::setGrid( *myGrid );
412 IntensityComponent::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
413 NormalsComponent ::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
418 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
421 IntensityComponent::releaseGeometryFeatures();
422 NormalsComponent ::releaseGeometryFeatures();
426 template<
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();
444 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
452 template<
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 );
510 geom->setMovable(
false );
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 ) )
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" );
533 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
535 (
unsigned int geometryType,
const Spacing& spacing )
const 539 return createNode( geometryType, spacing,
Dimensions( dimensions ) );
543 template<
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 );
554 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
566 #endif // VOLUMEGRIDHELPER_H_6014714286 Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
std::size_t partitionsCount() const
Tells the total partitions number.
unsigned int round_ui(ScalarType x)
Rounds x to the closest . Either the data type of must be unsigned or .
ScalarType makeEven(ScalarType x, int s)
Returns if is even and if is odd, where . The data type of must be integral. ...
Defines Carna::helpers::details::VolumeGridHelper.
Matrix4f scaling4f(float x, float y, float z)
Creates scaling matrix for homogeneous coordinates.
const std::size_t maxSegmentBytesize
Maximum memory size of a single segment volume.
Defines scene graph leafs. Instances of this class represent visible geometry that can be rendered...
void attachChild(Spatial *child)
Attaches child to this node in and takes it's possession.
Defines Carna::base::Node.
Indicates messages that might be of interest when searching bugs.
Defines type-parameters-independent VolumeGridHelper base interface.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Represents a single volumetric data partition.
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...
Defines the helpers::VolumeGridHelper component that maintains intensity volume data.
virtual void releaseGeometryFeatures() override
Releases all previously acquired textures. Invoke this method when the volume data changes...
Defines a Geometry minimal boundary box.
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
Matrix4f translation4f(float x, float y, float z)
Returns matrix that translates homogeneous coordinates.
Defines the inner node of a scene graph. Implements a spatial scene element that is allowed to have c...
const details::VolumeGridHelper::Partionining partitioningX
Describes the partitioning along the x-axis.
#define CARNA_FOR_VECTOR3UI(vecName, vecLimit)
Loops vecName over all where is vecLimit.
base::math::Vector3f millimeters
Holds the dimensions of the whole dataset in millimeters.
Defines Carna::base::VolumeGrid.
static Log & instance()
Returns the only instance from class InstanceType.
base::math::Vector3f millimeters
Holds the spacing between two succeeding voxel centers in millimeters.
const details::VolumeGridHelper::Partionining partitioningZ
Describes the partitioning along the z-axis.
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...
void setMovable(bool movable)
Sets whether this spatial may be displaced w.r.t. it's parent through user interaction. Usually this will be false when this spatial represents a component of it's parent, like the shaft of an arrow.
virtual void loadIntensities(const std::function< float(const base::math::Vector3ui &) > &intensityData) override
Updates the data of the volume grid.
Specifies the spacing between two succeeding voxel centers in millimeters.
std::size_t tailSize
Holds the resolution of the last partition that may also be 0.
Defines Carna::base::VolumeSegment.
const base::math::Vector3ui maxSegmentSize
The maximum effective resolution of a single grid segment.
SegmentIntensityVolumeType & intensities()
References the intensity volume data of this partition.
const details::VolumeGridHelper::Partionining partitioningY
Describes the partitioning along the y-axis.
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.
const base::math::Vector3ui nativeResolution
Holds the original resolution of the loaded data.
void record(Severity severity, const std::string &entry) const
Instructs current writer to write entry with severity.
base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > & grid() const
References the underlying grid.
virtual void loadIntensities(const std::function< float(const base::math::Vector3ui &) > &intensityData)=0
Updates the data of the volume grid.
std::size_t totalSize() const
Computes the effective total resolution.
Defines Carna::base::BoundingBox.
Specifies the dimensions of the whole dataset in millimeters.
Computes the partitioning that VolumeGridHelper uses along one dimension.
#define NON_COPYABLE
Features class it is placed in as non-copyable.
std::size_t regularPartitionSize
Holds the always odd, effective resolution of a single regular partition.
Defines Carna::base::Geometry.
Represents a particular partitioning of volumetric data.
void loadHUData(const std::function< base::HUV(const base::math::Vector3ui &) > &huData)
Updates the data of the volume grid.
Eigen::Matrix< signed int, 3, 1 > Vector3i
Defines vector.
math::Matrix4f localTransform
Defines the location, rotation and scale of this spatial in relation to it's parent. If this spatial has no parent, the value has no meaning.