12 #ifndef VOLUMEGRIDHELPERDETAILS_H_6014714286
13 #define VOLUMEGRIDHELPERDETAILS_H_6014714286
15 #include <Carna/Carna.h>
58 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
80 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
100 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
123 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
144 template<
typename TextureFactory >
152 <
typename TextureFactory::SegmentHUVolume
153 ,
typename TextureFactory::SegmentNormalsVolume >*
178 <
typename TextureFactory::SegmentHUVolume
179 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const;
185 <
typename TextureFactory::SegmentHUVolume
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::SegmentHUVolume
216 ,
typename TextureFactory::SegmentNormalsVolume >& segment )
const
223 template<
typename TextureFactory >
226 <
typename TextureFactory::SegmentHUVolume
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 SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
313 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
315 : role( DEFAULT_ROLE_HU_VOLUME )
320 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
327 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
334 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
340 ::attachTexture( geometry, role, segment );
344 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
349 SegmentHUVolumeType*
const huVolume =
new SegmentHUVolumeType( size );
398 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
400 :
public TextureManager< NormalsTextureFactory< SegmentHUVolumeType, SegmentNormalsVolumeType > >
466 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
468 : role( DEFAULT_ROLE_NORMALS )
473 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
480 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
487 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
498 const Vector3ui resolution = gridResolution();
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 >();
536 const base::HUV huv_0yz = grid->template getVoxel< HUVSelector >(
Vector3ui( coord.x() - 1, coord.y(), coord.z() ) );
537 const base::HUV huv_1yz = grid->template getVoxel< HUVSelector >(
Vector3ui( coord.x() + 1, coord.y(), coord.z() ) );
538 const base::HUV huv_x0z = grid->template getVoxel< HUVSelector >(
Vector3ui( coord.x(), coord.y() - 1, coord.z() ) );
539 const base::HUV huv_x1z = grid->template getVoxel< HUVSelector >(
Vector3ui( coord.x(), coord.y() + 1, coord.z() ) );
540 const base::HUV huv_xy0 = grid->template getVoxel< HUVSelector >(
Vector3ui( coord.x(), coord.y(), coord.z() - 1 ) );
541 const base::HUV huv_xy1 = grid->template getVoxel< HUVSelector >(
Vector3ui( coord.x(), coord.y(), coord.z() + 1 ) );
547 Vector3f normal =
Vector3f( huv_0yz - huv_1yz, huv_x0z - huv_x1z, huv_xy0 - huv_xy1 ) / 2;
548 if( !base::math::isEqual< float >( normal.squaredNorm(), 0 ) )
556 grid->template setVoxel< NormalSelector >( coord, normal );
563 ,
"VolumeGridHelper finished normals computation in "
564 + base::text::lexical_cast< std::string >( seconds )
569 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
577 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
583 ::attachTexture( geometry, role, segment );
587 template<
typename SegmentHUVolumeType,
typename SegmentNormalsVolumeType >
592 SegmentNormalsVolumeType*
const normals =
new SegmentNormalsVolumeType( size );
608 template<
typename SegmentHUVolumeType >
648 template<
typename SegmentHUVolumeType >
654 template<
typename SegmentHUVolumeType >
660 template<
typename SegmentHUVolumeType >
667 template<
typename SegmentHUVolumeType >
675 template<
typename SegmentHUVolumeType >
704 : regularPartitionSize( regularPartitionSize )
708 CARNA_ASSERT_EX( regularPartitionSize % 2 == 1,
"Effective regular partition size must be odd!" );
740 return regularPartitionsCount + ( tailSize > 0 ? 1 : 0 );
754 #endif // VOLUMEGRIDHELPERDETAILS_H_6014714286
unsigned int huVolumeRole() const
Tels the role used for attaching textures to base::Geometry nodes.
void setGrid(base::VolumeGrid< SegmentHUVolumeType, SegmentNormalsVolumeType > &grid)
Sets the grid that computeNormals operates on.
unsigned int round_ui(ScalarType x)
Rounds x to the closest . Either the data type of must be unsigned or .
static base::ManagedTexture3D & createTexture(const base::VolumeSegment< SegmentHUVolumeType, SegmentNormalsVolumeType > &segment)
Creates texture that represents the base::VolumeSegment::huVolume of segment in video memory...
void attachTexture(base::Geometry &geometry, unsigned int role, const base::VolumeSegment< typename TextureFactory::SegmentHUVolume, typename TextureFactory::SegmentNormalsVolume > &segment) const
Attaches the texture that TextureFactory creates from segment to geometry using role.
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. ...
SegmentNormalsVolumeType SegmentNormalsVolume
Reflects the type to use for storing the normal map of a single partition.
double result() const
Tells result in seconds from current time measurement.
Defines Carna::base::BufferedVectorFieldTexture.
std::size_t totalSize() const
Computes the effective total resolution.
static const unsigned int DEFAULT_ROLE_NORMALS
Holds the default role to use for attaching textures to base::Geometry nodes.
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< SegmentHUVolumeType, SegmentNormalsVolumeType > &segment, const base::math::Vector3ui &size) const
Initializes HU volume 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...
std::size_t partitionsCount() const
Tells the total partitions number.
Implements stopwatch using the robust wallclock time from OMP that most compilers support...
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.
Creates textures that represents base::VolumeSegmentNormalsComponent::normals in video memory...
void attachTexture(base::Geometry &geometry, const base::VolumeSegment< SegmentHUVolumeType, SegmentNormalsVolumeType > &segment) const
Attaches the texture that represents the base::VolumeSegment::huVolume of segment to geometry using t...
void computeNormals()
Computes the normal map on the previously set grid.
void record(Severity severity, const std::string &entry) const
Instructs current writer to write entry with severity.
Represents 3D OpenGL texture object whose lifetime is managed by instances of this class...
Defines Carna::base::Log.
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.
HUComponent()
Sets the role to use for attaching textures to base::Geometry nodes to DEFAULT_ROLE_HU_VOLUME.
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.
SegmentHUVolumeType SegmentHUVolume
Reflects the type to use for storing the HU volume of a single partition.
static const unsigned int DEFAULT_ROLE_HU_VOLUME
Holds the default role to use for attaching textures to base::Geometry nodes.
References the normal map of a given partition.
Defines Carna::base::VolumeGrid.
static Log & instance()
Returns the only instance from class InstanceType.
static base::ManagedTexture3D & createTexture(const base::VolumeSegment< SegmentHUVolumeType, SegmentNormalsVolumeType > &segment)
Creates texture that represents the base::VolumeSegmentNormalsComponent::normals of segment in video ...
SegmentHUVolumeType SegmentHUVolume
Reflects the type to use for storing the HU volume of a single partition.
Creates textures that represents base::VolumeSegment::huVolume in video memory.
#define CARNA_FOR_VECTOR3UI_EX(vecName, vecLimit, vecStart)
Loops vecName over all where is vecLimit and is vecStart.
void setHUVolumeRole(unsigned int role)
Sets the role to use for attaching textures to base::Geometry nodes.
unsigned int normalsRole() const
Tels the role used for attaching textures to base::Geometry nodes.
Defines the helpers::VolumeGridHelper component that maintains HU volume data.
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.
Defines the helpers::VolumeGridHelper component that computes and maintains normal maps...
Defines Carna::base::VolumeSegment.
Defines Carna::base::Stopwatch.
void initializeSegment(base::VolumeSegment< SegmentHUVolumeType, SegmentNormalsVolumeType > &segment, const base::math::Vector3ui &size) const
Initializes normal map of segment.
void attachTexture(base::Geometry &geometry, const base::VolumeSegment< SegmentHUVolumeType, SegmentNormalsVolumeType > &segment) const
Attaches the texture that represents the base::VolumeSegmentNormalsComponent::normals of segment to g...
virtual ~TextureManager()
Releases all textures and deletes.
Computes the partitioning of volumetric data and the corresponding normal map. Also creates scene nod...
signed short HUV
Represents values in .
Represents a composition, i.e. a strong reference. This basically is a std::unique_ptr that supports ...
void setNormalsRole(unsigned int role)
Sets the role to use for attaching textures to base::Geometry nodes.
std::size_t regularPartitionsCount
Holds the number of regular partitions, i.e. such of the size held by regularPartitionSize.
SegmentNormalsVolumeType SegmentNormalsVolume
Reflects the type to use for storing the normal map of a single partition.
Computes the partitioning that VolumeGridHelper uses along one dimension.
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Partionining(std::size_t nativeSize, std::size_t regularPartitionSize)
Computes the partitioning.
void setHUVolume(Association< SegmentHUVolumeType > *huVolume)
Sets the HU volume data of this partition.
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.
Eigen::Matrix< signed int, 3, 1 > Vector3i
Defines vector.