12 #ifndef VOLUMEGRIDHELPERDETAILS_H_6014714286 13 #define VOLUMEGRIDHELPERDETAILS_H_6014714286 15 #include <Carna/Carna.h> 58 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
80 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
100 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
123 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
144 template<
typename TextureFactory >
152 <
typename TextureFactory::SegmentIntensityVolume
153 ,
typename TextureFactory::SegmentNormalsVolume >*
166 void releaseGeometryFeatures();
178 <
typename TextureFactory::SegmentIntensityVolume
179 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const;
185 <
typename TextureFactory::SegmentIntensityVolume
186 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const;
191 template<
typename TextureFactory >
194 releaseGeometryFeatures();
198 template<
typename TextureFactory >
201 for(
auto itr = textures.begin(); itr != textures.end(); ++itr )
210 template<
typename TextureFactory >
215 <
typename TextureFactory::SegmentIntensityVolume
216 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const 223 template<
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;
259 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
271 const static unsigned int DEFAULT_ROLE_INTENSITIES = 0;
284 void setIntensitiesRole(
unsigned int role );
290 unsigned int intensitiesRole()
const;
306 void initializeSegment
313 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
315 : role( DEFAULT_ROLE_INTENSITIES )
320 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
327 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
334 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
344 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
349 SegmentIntensityVolumeType*
const intensities =
new SegmentIntensityVolumeType( size );
398 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
400 :
public TextureManager< NormalsTextureFactory< SegmentIntensityVolumeType, SegmentNormalsVolumeType > >
413 const static unsigned int DEFAULT_ROLE_NORMALS = 1;
426 void setNormalsRole(
unsigned int role );
432 unsigned int normalsRole()
const;
437 void computeNormals();
466 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
468 : role( DEFAULT_ROLE_NORMALS )
473 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
480 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
487 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
503 for(
unsigned int dim0 = 0; dim0 < 3; ++dim0 )
505 for(
signed int sign = -1; sign <= +1; sign += 2 )
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 );
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 ) );
547 if( normal.squaredNorm() > 1e-12 )
555 grid->template setVoxel< NormalSelector >( coord, normal );
562 ,
"VolumeGridHelper finished normals computation in " 563 + base::text::lexical_cast< std::string >( seconds )
568 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
576 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
586 template<
typename SegmentIntensityVolumeType,
typename SegmentNormalsVolumeType >
591 SegmentNormalsVolumeType*
const normals =
new SegmentNormalsVolumeType( size );
607 template<
typename SegmentIntensityVolumeType >
647 template<
typename SegmentIntensityVolumeType >
653 template<
typename SegmentIntensityVolumeType >
659 template<
typename SegmentIntensityVolumeType >
666 template<
typename SegmentIntensityVolumeType >
674 template<
typename SegmentIntensityVolumeType >
702 Partionining( std::size_t nativeSize, std::size_t regularPartitionSize )
703 : regularPartitionSize( regularPartitionSize )
704 , regularPartitionsCount( nativeSize / regularPartitionSize )
705 , tailSize( base::math::
makeEven( nativeSize % regularPartitionSize, +1 ) )
707 CARNA_ASSERT_EX( regularPartitionSize % 2 == 1,
"Effective regular partition size must be odd!" );
731 return tailSize + regularPartitionsCount * regularPartitionSize;
739 return regularPartitionsCount + ( tailSize > 0 ? 1 : 0 );
753 #endif // VOLUMEGRIDHELPERDETAILS_H_6014714286 base::math::Vector3f computeFastGradient3f(Sampler func)
Computes fast approximation of the gradient at the origin of the scalar field func.
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 .
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 ...
ScalarType makeEven(ScalarType x, int s)
Returns if is even and if is odd, where . The data type of must be integral. ...
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...
Defines Carna::base::BufferedVectorFieldTexture.
SegmentIntensityVolumeType SegmentIntensityVolume
Reflects the type to use for storing the intensity volume of a single partition.
Defines scene graph leafs. Instances of this class represent visible geometry that can be rendered...
Defines Carna::base::BufferedNormalMap3D.
void setNormals(Association< SegmentNormalsVolumeType > *volume)
Sets the normal map of this partition.
Indicates statistics and suchlike.
Defines Carna::base::text.
Provides mapping base::VolumeSegment to base::ManagedTexture3D objects in a caching manner...
void initializeSegment(base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment, const base::math::Vector3ui &size) const
Initializes normal map of segment.
#define CARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
double result() const
Tells result in seconds from current time measurement.
Implements stopwatch using the robust wallclock time from OMP that most compilers support...
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...
Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
Defines vector.
Represents a single volumetric data partition.
static BufferedVectorFieldTexture< BufferedVectorFieldType > & create(const BufferedVectorFieldType &field)
Instantiates. Invoke release when it isn't needed any longer.
static base::ManagedTexture3D & createTexture(const base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment)
Creates texture that represents the base::VolumeSegmentNormalsComponent::normals of segment in video ...
Creates textures that represents base::VolumeSegmentNormalsComponent::normals in video memory...
Defines the helpers::VolumeGridHelper component that maintains intensity volume data.
SegmentNormalsVolumeType SegmentNormalsVolume
Reflects the type to use for storing the normal map of a single partition.
SegmentNormalsVolumeType SegmentNormalsVolume
Reflects the type to use for storing the normal map of a single partition.
Represents 3D OpenGL texture object whose lifetime is managed by instances of this class...
Defines Carna::base::Log.
References the intensity volume of a given partition.
Eigen::Matrix< float, 3, 1 > Vector3f
Defines vector.
SegmentNormalsVolumeType & normals()
References the normal map of this partition.
Defines the NormalsComponent base class that is independent of type arguments.
Defines Carna::base::VolumeGrid.
static Log & instance()
Returns the only instance from class InstanceType.
void setIntensitiesRole(unsigned int role)
Sets the role to use for attaching textures to base::Geometry nodes.
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.
#define CARNA_FOR_VECTOR3UI_EX(vecName, vecLimit, vecStart)
Loops vecName over all where is vecLimit and is vecStart.
static base::ManagedTexture3D & createTexture(const base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment)
Creates texture that represents the base::VolumeSegment::intensities of segment in video memory...
SegmentIntensityVolumeType SegmentIntensityVolume
Reflects the type to use for storing the intensity volume of a single partition.
void computeNormals()
Computes the normal map on the previously set grid.
NormalsComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_NORMALS.
void release()
Denotes that this object is no longer required and may be deleted as soon as it is valid to delete it...
std::size_t tailSize
Holds the resolution of the last partition that may also be 0.
void initializeSegment(base::VolumeSegment< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &segment, const base::math::Vector3ui &size) const
Initializes intensity volume of segment.
unsigned int normalsRole() const
Tels the role used for attaching textures to base::Geometry nodes.
Defines the helpers::VolumeGridHelper component that computes and maintains normal maps...
Defines Carna::base::VolumeSegment.
Defines Carna::base::Stopwatch.
SegmentIntensityVolumeType & intensities()
References the intensity volume data of this partition.
void setGrid(base::VolumeGrid< SegmentIntensityVolumeType, SegmentNormalsVolumeType > &grid)
Sets the grid that computeNormals operates on.
virtual ~TextureManager()
Releases all textures and deletes.
Computes the partitioning of volumetric data and the corresponding normal map. Also creates scene nod...
Represents a composition, i.e. a strong reference. This basically is a std::unique_ptr that supports ...
std::size_t regularPartitionsCount
Holds the number of regular partitions, i.e. such of the size held by regularPartitionSize.
void record(Severity severity, const std::string &entry) const
Instructs current writer to write entry with severity.
std::size_t totalSize() const
Computes the effective total resolution.
IntensityComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_INTENSITIES.
void setIntensities(Association< SegmentIntensityVolumeType > *intensities)
Sets the intensity volume data of this partition.
Computes the partitioning that VolumeGridHelper uses along one dimension.
virtual base::math::Vector3ui gridResolution() const =0
Tells the effective grid resolution.
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Partionining(std::size_t nativeSize, std::size_t regularPartitionSize)
Computes the partitioning.
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 releaseGeometryFeatures()
Releases all textures.
unsigned int intensitiesRole() const
Tels the role used for attaching textures to base::Geometry nodes.
Creates textures that represents base::VolumeSegment::intensities in video memory.
void setNormalsRole(unsigned int role)
Sets the role to use for attaching textures to base::Geometry nodes.
Eigen::Matrix< signed int, 3, 1 > Vector3i
Defines vector.