1 #include "renderer_detail_normal_mrf.h"
2 #include "renderer_detail_normal_mrf_helpers.h"
23 void NormalMRF::CalculateNormals(
31 assert( m_coarseness == 0 );
37 #pragma omp parallel for
38 for (
int ii = 0; ii < static_cast< int >( m_dimension[ 1 ] ); ++ii ) {
41 ( 0.5 - 0.5 * m_dimension[ 0 ] ) * spreadX -
42 ( ii + 0.5 - 0.5 * m_dimension[ 1 ] ) * spreadY -
46 unsigned int const offset = ii * m_dimension[ 0 ];
47 for (
int jj = 0; jj < static_cast< int >( m_dimension[ 0 ] ); ++jj ) {
51 double const reciprocalDepth = m_states[ offset + jj ].first;
52 if ( reciprocalDepth > 0 ) {
54 double const depth = 1 / reciprocalDepth;
57 Vector< double, 3 > horizontalDifference = gradient[ 0 ] * ray + ( gradient[ 0 ] + depth ) * spreadX;
58 Vector< double, 3 > verticalDifference = gradient[ 1 ] * ray - ( gradient[ 1 ] + depth ) * spreadY;
60 normal =
Cross( horizontalDifference, -verticalDifference );
61 normal /= normal.Norm();
63 normals[ offset + jj ] = normal;
71 void NormalMRF::SmoothHorizontal(
bool const odd,
bool const decreasing ) {
73 unsigned int const size = ( 1u << m_coarseness );
76 int jjEnd = ( ( m_dimension[ 0 ] - 1 ) & ~( size - 1 ) );
80 std::swap( jjBegin, jjEnd );
85 #pragma omp parallel for
86 for (
int ii = ( odd ? size : 0 ); ii < static_cast< int >( m_dimension[ 1 ] ); ii += size * 2 ) {
88 for (
int jj = jjBegin; jj != jjEnd; jj += jjDelta ) {
90 assert( ( jj >= 0 ) && ( jj < m_dimension[ 0 ] ) );
101 Square( size ) * m_observationPrecision,
111 void NormalMRF::SmoothVertical(
bool const odd,
bool const decreasing ) {
113 unsigned int const size = ( 1u << m_coarseness );
116 int jjEnd = ( ( m_dimension[ 1 ] - 1 ) & ~( size - 1 ) );
120 std::swap( jjBegin, jjEnd );
125 #pragma omp parallel for
126 for (
int ii = ( odd ? size : 0 ); ii < static_cast< int >( m_dimension[ 0 ] ); ii += size * 2 ) {
128 for (
int jj = jjBegin; jj != jjEnd; jj += jjDelta ) {
130 assert( ( jj >= 0 ) && ( jj < m_dimension[ 1 ] ) );
141 Square( size ) * m_observationPrecision,
151 void NormalMRF::SmoothCardinalCheckerboard(
bool const odd ) {
153 unsigned int const size = ( 1u << m_coarseness );
155 #pragma omp parallel for
156 for (
int ii = 0; ii < static_cast< int >( m_dimension[ 1 ] ); ii += size ) {
158 for (
int jj = ( ( ( ii & size ) != 0 ) == odd ) ? 0 : size; jj < static_cast< int >( m_dimension[ 0 ] ); jj += size * 2 ) {
170 Square( size ) * m_observationPrecision,
180 void NormalMRF::SmoothDiagonalCheckerboard(
bool const odd ) {
182 unsigned int const size = ( 1u << m_coarseness );
183 double const scale = size * std::sqrt( 2 );
185 #pragma omp parallel for
186 for (
int ii = odd ? size : 0; ii < static_cast< int >( m_dimension[ 1 ] ); ii += size * 2 ) {
188 for (
int jj = odd ? size : 0; jj < static_cast< int >( m_dimension[ 0 ] ); jj += size * 2 ) {
200 Square( scale ) * m_observationPrecision,
210 void NormalMRF::InitializeStates() {
212 unsigned int const size = ( 1u << m_coarseness );
216 #pragma omp parallel for
217 for (
int ii = 0; ii < static_cast< int >( m_dimension[ 1 ] ); ii += size ) {
219 unsigned int const offset = ii * m_dimension[ 0 ];
220 for (
int jj = 0; jj < static_cast< int >( m_dimension[ 0 ] ); jj += size ) {
222 double const reciprocalDepth = 1 / m_depths[ offset + jj ];
224 m_states[ offset + jj ].first = reciprocalDepth;
225 m_states[ offset + jj ].second = gradient0;