1 #include <Core/Geometry/Volume.hpp>
3 #include <Core/Utils/Log.hpp>
9 AbstractVolume::AbstractVolume(
const VolumeStorageType& type ) :
10 AbstractGeometry(), m_type( type ) {}
12 bool AbstractVolume::isParametric()
const {
13 return ( m_type == PARAMETRIC );
16 bool AbstractVolume::isDiscrete()
const {
17 return ( m_type == DISCRETE_DENSE ) || ( m_type == DISCRETE_SPARSE );
20 bool AbstractVolume::isDense()
const {
21 return ( m_type == DISCRETE_DENSE );
24 bool AbstractVolume::isSparse()
const {
25 return ( m_type == DISCRETE_SPARSE );
28 void AbstractVolume::displayInfo()
const {
29 using namespace Core::Utils;
39 type =
"DISCRETE (DENSE)";
42 type =
"DISCRETE (SPARSE)";
45 LOG( logINFO ) <<
"======== MESH INFO ========";
46 LOG( logINFO ) <<
" Type : " << type;
49 void AbstractDiscreteVolume::clear() {
50 setBinSize( Vector3::Zero() );
51 setSize( Vector3i::Zero() );
55 Aabb AbstractDiscreteVolume::computeAabb()
const {
56 if ( !isAabbValid() ) {
57 setAabb( Aabb( Vector3::Zero(), m_binSize.cwiseProduct( m_size.cast<Scalar>() ) ) );
62 VolumeGrid::ValueType VolumeGrid::sample(
const IndexType& i ) {
64 std::clamp( i.x(), 0, size().x() - 1 ),
65 std::clamp( i.y(), 0, size().y() - 1 ),
66 std::clamp( i.z(), 0, size().z() - 1 ),
68 return m_data[*linearIndex( idx )];
71 void VolumeGrid::computeGradients() {
72 m_gradient.resize( m_data.size() );
75 #pragma omp parallel for firstprivate( s )
76 for (
int k = 0; k < s.z(); ++k ) {
77 for (
int j = 0; j < s.y(); ++j ) {
78 for (
int i = 0; i < s.x(); ++i ) {
79 Eigen::Matrix<ValueType, 3, 1> s1;
80 Eigen::Matrix<ValueType, 3, 1> s2;
81 s1( 0 ) = sample( { i - 1, j, k } );
82 s2( 0 ) = sample( { i + 1, j, k } );
83 s1( 1 ) = sample( { i, j - 1, k } );
84 s2( 1 ) = sample( { i, j + 1, k } );
85 s1( 2 ) = sample( { i, j, k - 1 } );
86 s2( 2 ) = sample( { i, j, k + 1 } );
87 IndexType idx { i, j, k };
88 Eigen::Matrix<ValueType, 3, 1> gradient = s2 - s1;
89 m_gradient[*linearIndex( idx )] = {
90 gradient[0], gradient[1], gradient[2], sample( { i, j, k } ) };