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;
206 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
221 std::unique_ptr< base::VolumeGrid< SegmentHUVolumeType, SegmentNormalsVolumeType > > myGrid;
225 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
281 template<
typename UnaryVector3uiToHUVFunction >
282 void loadData(
const UnaryVector3uiToHUVFunction& data );
316 (
unsigned int geometryType
325 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
329 const float maxSideLengthF = std::pow
330 ( maxSegmentBytesize / static_cast< float >(
sizeof(
typename SegmentHUVolumeType::Voxel ) ), 1.f / 3 );
340 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
343 , std::size_t maxSegmentBytesize )
345 , maxSegmentBytesize( maxSegmentBytesize )
346 , maxSegmentSize( computeMaxSegmentSize( nativeResolution, maxSegmentBytesize ) )
347 , partitioningX( nativeResolution.x(), maxSegmentSize.x() )
348 , partitioningY( nativeResolution.y(), maxSegmentSize.y() )
349 , partitioningZ( nativeResolution.z(), maxSegmentSize.z() )
357 NormalsComponent::setGrid( *myGrid );
368 HUComponent ::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
369 NormalsComponent::initializeSegment( myGrid->segmentAt( segmentCoord ), segmentSize );
374 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
377 HUComponent ::releaseGeometryFeatures();
378 NormalsComponent::releaseGeometryFeatures();
382 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
383 template<
typename UnaryVector3uiToHUVFunction >
385 (
const UnaryVector3uiToHUVFunction& data )
387 releaseGeometryFeatures();
390 const bool outOfNativeBounds
391 = coord.x() >= nativeResolution.x()
392 || coord.y() >= nativeResolution.y()
393 || coord.z() >= nativeResolution.z();
394 const base::HUV huv = outOfNativeBounds ? -1024 : data( coord );
395 myGrid->template setVoxel< typename base::VolumeGrid< SegmentHUVolumeType, SegmentNormalsVolumeType >::HUVSelector >( coord, huv );
397 NormalsComponent::computeNormals();
401 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
405 loadData< std::function< base::HUV( const base::math::Vector3ui& ) > >( data );
409 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
417 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
419 (
unsigned int geometryType,
const Spacing& spacing,
const Dimensions& dimensions )
const
444 segmentCoord.x() + 1 == myGrid->segmentCounts.x()
445 || segmentCoord.y() + 1 == myGrid->segmentCounts.y()
446 || segmentCoord.z() + 1 == myGrid->segmentCounts.z();
450 .cast< float >().cwiseProduct( spacing.millimeters ) );
456 HUComponent ::attachTexture( *geom, segment );
457 NormalsComponent::attachTexture( *geom, segment );
464 : ( regularSegmentDimensions - dimensions ) / 2 ) )
474 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
476 (
unsigned int geometryType,
const Spacing& spacing )
const
480 return createNode( geometryType, spacing,
Dimensions( dimensions ) );
484 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
486 (
unsigned int geometryType,
const Dimensions& dimensions )
const
490 = mmDimensions.cast<
float >().cwiseQuotient( ( resolution.cast<
int >() -
base::math::Vector3i( 1, 1, 1 ) ).cast<
float >() );
491 return createNode( geometryType,
Spacing( spacing ), dimensions );
495 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
507 #endif // VOLUMEGRIDHELPER_H_6014714286
base::VolumeGrid< SegmentHUVolumeType, SegmentNormalsVolumeType > & grid() const
References the underlying grid.
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
const details::VolumeGridHelper::Partionining partitioningX
Describes the partitioning along the x-axis.
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.
std::size_t totalSize() const
Computes the effective total resolution.
Matrix4f scaling4f(float x, float y, float z)
Creates scaling matrix for homogeneous coordinates.
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.
Defines type-parameters-independent VolumeGridHelper base interface.
std::size_t partitionsCount() const
Tells the total partitions number.
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Represents a single volumetric data partition.
const details::VolumeGridHelper::Partionining partitioningZ
Describes the partitioning along the z-axis.
NormalsComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_NORMALS.
SegmentHUVolumeType & huVolume()
References the HU volume data of this partition.
virtual void releaseGeometryFeatures() override
Releases all previously acquired textures. Invoke this method when the volume data changes...
Defines a Geometry minimal boundary box.
HUComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_HU_VOLUME.
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...
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...
#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.
base::math::Vector3f millimeters
Holds the spacing between two succeeding voxel centers in millimeters.
virtual base::math::Vector3ui gridResolution() const override
Tells the effective grid resolution.
const base::math::Vector3ui maxSegmentSize
The maximum effective resolution of a single grid segment.
const std::size_t maxSegmentBytesize
Maximum memory size of a single segment volume.
const base::math::Vector3ui resolution
Holds the effective resolution, i.e. the resolution covered by the grid.
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.
Defines the helpers::VolumeGridHelper component that maintains HU volume data.
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 the helpers::VolumeGridHelper component that computes and maintains normal maps...
Defines Carna::base::VolumeSegment.
Computes the partitioning of volumetric data and the corresponding normal map. Also creates scene nod...
signed short HUV
Represents values in .
const base::math::Vector3ui nativeResolution
Holds the original resolution of the loaded data.
const details::VolumeGridHelper::Partionining partitioningY
Describes the partitioning along the y-axis.
Defines Carna::base::BoundingBox.
void loadData(const UnaryVector3uiToHUVFunction &data)
Alters the volume data.
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.
Eigen::Matrix< signed int, 3, 1 > Vector3i
Defines vector.
void setBoundingVolume(BoundingVolume *boundingVolume)
Sets boundingVolume as the minimum boundary volume of this node. Supply nullptr for boundingVolume to...
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...
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.