Radium Engine  1.5.20
Loading...
Searching...
No Matches
Volume.cpp
1#include <Core/Geometry/Volume.hpp>
2
3#include <Core/Utils/Log.hpp>
4
5namespace Ra {
6namespace Core {
7namespace Geometry {
8
9AbstractVolume::AbstractVolume( const VolumeStorageType& type ) :
10 AbstractGeometry(), m_type( type ) {}
11
12bool AbstractVolume::isParametric() const {
13 return ( m_type == PARAMETRIC );
14}
15
16bool AbstractVolume::isDiscrete() const {
17 return ( m_type == DISCRETE_DENSE ) || ( m_type == DISCRETE_SPARSE );
18}
19
20bool AbstractVolume::isDense() const {
21 return ( m_type == DISCRETE_DENSE );
22}
23
24bool AbstractVolume::isSparse() const {
25 return ( m_type == DISCRETE_SPARSE );
26}
27
28void AbstractVolume::displayInfo() const {
29 using namespace Core::Utils; // log
30 std::string type;
31 switch ( m_type ) {
32 case UNKNOWN:
33 type = "UNKNOWN";
34 break;
35 case PARAMETRIC:
36 type = "PARAMETRIC";
37 break;
38 case DISCRETE_DENSE:
39 type = "DISCRETE (DENSE)";
40 break;
41 case DISCRETE_SPARSE:
42 type = "DISCRETE (SPARSE)";
43 break;
44 }
45 LOG( logINFO ) << "======== MESH INFO ========";
46 LOG( logINFO ) << " Type : " << type;
47}
48
49void AbstractDiscreteVolume::clear() {
50 setBinSize( Vector3::Zero() );
51 setSize( Vector3i::Zero() );
52 invalidateAabb();
53}
54
55Aabb AbstractDiscreteVolume::computeAabb() const {
56 if ( !isAabbValid() ) {
57 setAabb( Aabb( Vector3::Zero(), m_binSize.cwiseProduct( m_size.cast<Scalar>() ) ) );
58 }
59 return getAabb();
60}
61
62VolumeGrid::ValueType VolumeGrid::sample( const IndexType& i ) {
63 IndexType idx {
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 ),
67 };
68 return m_data[*linearIndex( idx )];
69}
70
71void VolumeGrid::computeGradients() {
72 m_gradient.resize( m_data.size() );
73 auto s = size();
74
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 } ) };
91 }
92 }
93 }
94}
95
96} // namespace Geometry
97} // namespace Core
98} // namespace Ra
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3