Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Volume.cpp
1#include <Core/Geometry/Volume.hpp>
2#include <Core/Utils/Log.hpp>
3#include <memory>
4#include <ostream>
5#include <string>
6
7namespace Ra {
8namespace Core {
9namespace Geometry {
10
11AbstractVolume::AbstractVolume( const VolumeStorageType& type ) :
12 AbstractGeometry(), m_type( type ) {}
13
14bool AbstractVolume::isParametric() const {
15 return ( m_type == PARAMETRIC );
16}
17
18bool AbstractVolume::isDiscrete() const {
19 return ( m_type == DISCRETE_DENSE ) || ( m_type == DISCRETE_SPARSE );
20}
21
22bool AbstractVolume::isDense() const {
23 return ( m_type == DISCRETE_DENSE );
24}
25
26bool AbstractVolume::isSparse() const {
27 return ( m_type == DISCRETE_SPARSE );
28}
29
30void AbstractVolume::displayInfo() const {
31 using namespace Core::Utils; // log
32 std::string type;
33 switch ( m_type ) {
34 case UNKNOWN:
35 type = "UNKNOWN";
36 break;
37 case PARAMETRIC:
38 type = "PARAMETRIC";
39 break;
40 case DISCRETE_DENSE:
41 type = "DISCRETE (DENSE)";
42 break;
43 case DISCRETE_SPARSE:
44 type = "DISCRETE (SPARSE)";
45 break;
46 }
47 LOG( logINFO ) << "======== MESH INFO ========";
48 LOG( logINFO ) << " Type : " << type;
49}
50
51void AbstractDiscreteVolume::clear() {
52 setBinSize( Vector3::Zero() );
53 setSize( Vector3i::Zero() );
54 invalidateAabb();
55}
56
57Aabb AbstractDiscreteVolume::computeAabb() const {
58 if ( !isAabbValid() ) {
59 setAabb( Aabb( Vector3::Zero(), m_binSize.cwiseProduct( m_size.cast<Scalar>() ) ) );
60 }
61 return getAabb();
62}
63
64VolumeGrid::ValueType VolumeGrid::sample( const IndexType& i ) {
65 IndexType idx {
66 std::clamp( i.x(), 0, size().x() - 1 ),
67 std::clamp( i.y(), 0, size().y() - 1 ),
68 std::clamp( i.z(), 0, size().z() - 1 ),
69 };
70 return m_data[*linearIndex( idx )];
71}
72
73void VolumeGrid::computeGradients() {
74 m_gradient.resize( m_data.size() );
75 auto s = size();
76
77#pragma omp parallel for firstprivate( s )
78 for ( int k = 0; k < s.z(); ++k ) {
79 for ( int j = 0; j < s.y(); ++j ) {
80 for ( int i = 0; i < s.x(); ++i ) {
81 Eigen::Matrix<ValueType, 3, 1> s1;
82 Eigen::Matrix<ValueType, 3, 1> s2;
83 s1( 0 ) = sample( { i - 1, j, k } );
84 s2( 0 ) = sample( { i + 1, j, k } );
85 s1( 1 ) = sample( { i, j - 1, k } );
86 s2( 1 ) = sample( { i, j + 1, k } );
87 s1( 2 ) = sample( { i, j, k - 1 } );
88 s2( 2 ) = sample( { i, j, k + 1 } );
89 IndexType idx { i, j, k };
90 Eigen::Matrix<ValueType, 3, 1> gradient = s2 - s1;
91 m_gradient[*linearIndex( idx )] = {
92 gradient[0], gradient[1], gradient[2], sample( { i, j, k } ) };
93 }
94 }
95 }
96}
97
98} // namespace Geometry
99} // namespace Core
100} // 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:4