3#include <Core/Geometry/AbstractGeometry.hpp>
4#include <Core/RaCore.hpp>
7#define RA_REQUIRE_OPTIONAL
8#include <Core/Utils/StdOptional.hpp>
10#undef RA_REQUIRE_OPTIONAL
43 DISCRETE_DENSE = 1 << 2,
44 DISCRETE_SPARSE = 1 << 3
71 virtual Utils::optional<ValueType>
getValue( Eigen::Ref<const Vector3> p )
const = 0;
76 bool isParametric()
const;
78 bool isDiscrete()
const;
82 bool isSparse()
const;
86 void displayInfo()
const;
102 using IndexType = Vector3i;
106 AbstractVolume( type ), m_size( IndexType::Zero() ), m_binSize { 1_ra, 1_ra, 1_ra } {}
114 void clear()
override;
117 Aabb computeAabb()
const override;
120 const Vector3i&
size()
const {
return m_size; }
122 void setSize( Eigen::Ref<const Vector3i> size ) {
122 void setSize( Eigen::Ref<const Vector3i> size ) {
…}
128 const Vector3&
binSize()
const {
return m_binSize; }
132 CORE_ASSERT( binSize != Vector3::Zero(),
"Volume bin size can't be zero." );
138 inline Utils::optional<ValueType>
getBinValue( Eigen::Ref<const IndexType> p )
const {
139 if (
auto res = linearIndex( p ) )
return getBinValue( *res );
138 inline Utils::optional<ValueType>
getBinValue( Eigen::Ref<const IndexType> p )
const {
…}
147 inline Utils::optional<ValueType>
getValue( Eigen::Ref<const Vector3> p )
const override final {
148 return getBinValue( ( p.cwiseQuotient( m_binSize ) ).cast<
typename IndexType::Scalar>() );
147 inline Utils::optional<ValueType>
getValue( Eigen::Ref<const Vector3> p )
const override final {
…}
155 inline bool addToBin(
const ValueType& value, Eigen::Ref<const IndexType> p ) {
156 if (
auto res = linearIndex( p ) ) {
157 addToBin( value, *res );
155 inline bool addToBin(
const ValueType& value, Eigen::Ref<const IndexType> p ) {
…}
166 inline Utils::optional<typename IndexType::Scalar>
168 using Integer =
typename IndexType::Scalar;
169 if ( ( p.array() >= m_size.array() ).any() )
return {};
170 return p.dot( IndexType( Integer( 1 ), m_size( 0 ), m_size( 0 ) * m_size( 1 ) ) );
173 virtual Utils::optional<ValueType>
getBinValue(
typename IndexType::Scalar idx )
const = 0;
175 virtual void addToBin(
const ValueType& value,
typename IndexType::Scalar idx ) = 0;
189 using ValueType = AbstractDiscreteVolume::ValueType;
190 using IndexType = AbstractDiscreteVolume::IndexType;
193 using GradientType = Eigen::Matrix<ValueType, 4, 1>;
199 inline VolumeGrid(
const ValueType& defaultValue = ValueType( 0. ) ) :
205 using AbstractDiscreteVolume::addToBin;
206 using AbstractDiscreteVolume::getBinValue;
215 for (
auto& v : m_data ) {
221 bool hasGradients()
const {
return m_data.size() == m_gradient.size(); }
224 void computeGradients();
234 inline Utils::optional<ValueType>
getBinValue(
typename IndexType::Scalar idx )
const override {
235 return m_data[size_t( idx )];
234 inline Utils::optional<ValueType>
getBinValue(
typename IndexType::Scalar idx )
const override {
…}
240 inline void addToBin(
const ValueType& value,
typename IndexType::Scalar idx )
override {
241 m_data[size_t( idx )] += value;
240 inline void addToBin(
const ValueType& value,
typename IndexType::Scalar idx )
override {
…}
246 m_data.resize(
size_t( size().prod() ), m_defaultValue );
251 ValueType sample(
const IndexType& i );
253 ValueType m_defaultValue;
255 GradientContainer m_gradient;
266 using ValueType = AbstractDiscreteVolume::ValueType;
267 using IndexType = AbstractDiscreteVolume::IndexType;
272 inline SampleType(
int idx,
const ValueType& v ) : index( idx ), value( v ) {}
282 using AbstractDiscreteVolume::addToBin;
283 using AbstractDiscreteVolume::getBinValue;
293 inline Utils::optional<ValueType>
getBinValue(
typename IndexType::Scalar idx )
const override {
294 auto res = findBin( idx );
295 if ( res !=
std::end( m_data ) )
return res->value;
293 inline Utils::optional<ValueType>
getBinValue(
typename IndexType::Scalar idx )
const override {
…}
305 inline void addToBin(
const ValueType& value,
typename IndexType::Scalar idx )
override {
306 auto res = findBin( idx );
310 m_data.emplace_back( idx, value );
305 inline void addToBin(
const ValueType& value,
typename IndexType::Scalar idx )
override {
…}
316 inline Container::iterator findBin(
typename IndexType::Scalar idx ) {
319 [&idx](
const SampleType& s ) {
return s.index == idx; } );
321 inline Container::const_iterator findBin(
typename IndexType::Scalar idx )
const {
324 [&idx](
const SampleType& s ) {
return s.index == idx; } );
Utils::optional< typename IndexType::Scalar > linearIndex(Eigen::Ref< const IndexType > p) const
Convert the 3D position into a linear index on the bin set.
Utils::optional< ValueType > getValue(Eigen::Ref< const Vector3 > p) const override final
Utils::optional< ValueType > getBinValue(Eigen::Ref< const IndexType > p) const
Get the value of the given bin.
void setBinSize(Eigen::Ref< const Vector3 > binSize)
Set the bin size.
const Vector3i & size() const
return the size (number of bins ni each dimension) of the volume
virtual void updateStorage()=0
Method called when size as been updated.
const Vector3 & binSize() const
return the bin size
void setSize(Eigen::Ref< const Vector3i > size)
virtual void addToBin(const ValueType &value, typename IndexType::Scalar idx)=0
Add a value to the bin.
virtual Utils::optional< ValueType > getBinValue(typename IndexType::Scalar idx) const =0
Get the bin value.
bool addToBin(const ValueType &value, Eigen::Ref< const IndexType > p)
Scalar ValueType
Type of value encoded in the volume.
virtual Utils::optional< ValueType > getValue(Eigen::Ref< const Vector3 > p) const =0
VolumeStorageType m_type
The type of geometry for the object.
void setType(const VolumeStorageType &type)
Set the type of geometry.
VolumeStorageType getType() const
Return the type of geometry.
VolumeStorageType
The type of geometry.
Discrete volume data storing values in a regular grid.
const GradientContainer & gradient() const
Direct access to the managed gradients.
const Container & data() const
Direct access to the managed data.
bool hasGradients() const
Test if gradients are defined.
GradientContainer & gradient()
Direct access, with modification allowed to the managed gradients.
void addToAllBins(const ValueType &value)
Add a value to all bins.
void updateStorage() override
Container & data()
Direct access, with modification allowed to the managed data.
void addToBin(const ValueType &value, typename IndexType::Scalar idx) override
Utils::optional< ValueType > getBinValue(typename IndexType::Scalar idx) const override
Utils::optional< ValueType > getBinValue(typename IndexType::Scalar idx) const override
void updateStorage() override
Method called when size as been updated.
void addToBin(const ValueType &value, typename IndexType::Scalar idx) override
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet