1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
31
#include "../common/WAssert.h"
32
#include "../common/math/linearAlgebra/WLinearAlgebra.h"
33
#include "WDataSetSingle.h"
34
#include "WDataSetSphericalHarmonics.h"
36
// prototype instance as singleton
37
boost::shared_ptr< WPrototyped > WDataSetSphericalHarmonics::m_prototype = boost::shared_ptr< WPrototyped >();
39
WDataSetSphericalHarmonics::WDataSetSphericalHarmonics( boost::shared_ptr< WValueSetBase > newValueSet,
40
boost::shared_ptr< WGrid > newGrid ) :
41
WDataSetSingle( newValueSet, newGrid ), m_valueSet( newValueSet )
43
m_gridRegular3D = boost::shared_dynamic_cast< WGridRegular3D >( newGrid );
44
WAssert( newValueSet, "No value set given." );
45
WAssert( newGrid, "No grid given." );
48
WDataSetSphericalHarmonics::WDataSetSphericalHarmonics()
53
WDataSetSphericalHarmonics::~WDataSetSphericalHarmonics()
57
WDataSetSingle::SPtr WDataSetSphericalHarmonics::clone( boost::shared_ptr< WValueSetBase > newValueSet ) const
59
return WDataSetSingle::SPtr( new WDataSetSphericalHarmonics( newValueSet, getGrid() ) );
62
WDataSetSingle::SPtr WDataSetSphericalHarmonics::clone( boost::shared_ptr< WGrid > newGrid ) const
64
return WDataSetSingle::SPtr( new WDataSetSphericalHarmonics( getValueSet(), newGrid ) );
67
WDataSetSingle::SPtr WDataSetSphericalHarmonics::clone() const
69
return WDataSetSingle::SPtr( new WDataSetSphericalHarmonics( getValueSet(), getGrid() ) );
72
boost::shared_ptr< WPrototyped > WDataSetSphericalHarmonics::getPrototype()
76
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetSphericalHarmonics() );
82
WSymmetricSphericalHarmonic WDataSetSphericalHarmonics::interpolate( const WPosition& pos, bool* success ) const
84
*success = m_gridRegular3D->encloses( pos );
87
size_t cellId = m_gridRegular3D->getCellId( pos, &isInside );
92
return WSymmetricSphericalHarmonic();
95
// ids of vertices for interpolation
96
WGridRegular3D::CellVertexArray vertexIds = m_gridRegular3D->getCellVertexIds( cellId );
98
WPosition localPos = pos - m_gridRegular3D->getPosition( vertexIds[0] );
100
double lambdaX = localPos[0] / m_gridRegular3D->getOffsetX();
101
double lambdaY = localPos[1] / m_gridRegular3D->getOffsetY();
102
double lambdaZ = localPos[2] / m_gridRegular3D->getOffsetZ();
103
WValue< double > h( 8 );
113
h[0] = ( 1 - lambdaX ) * ( 1 - lambdaY ) * ( 1 - lambdaZ );
114
h[1] = ( lambdaX ) * ( 1 - lambdaY ) * ( 1 - lambdaZ );
115
h[2] = ( 1 - lambdaX ) * ( lambdaY ) * ( 1 - lambdaZ );
116
h[3] = ( lambdaX ) * ( lambdaY ) * ( 1 - lambdaZ );
117
h[4] = ( 1 - lambdaX ) * ( 1 - lambdaY ) * ( lambdaZ );
118
h[5] = ( lambdaX ) * ( 1 - lambdaY ) * ( lambdaZ );
119
h[6] = ( 1 - lambdaX ) * ( lambdaY ) * ( lambdaZ );
120
h[7] = ( lambdaX ) * ( lambdaY ) * ( lambdaZ );
123
WValue<double> interpolatedCoefficients( m_valueSet->dimension() );
124
for( size_t i = 0; i < 8; ++i )
126
interpolatedCoefficients += h[i] * m_valueSet->getWValueDouble( vertexIds[i] );
131
return WSymmetricSphericalHarmonic( interpolatedCoefficients );
134
WSymmetricSphericalHarmonic WDataSetSphericalHarmonics::getSphericalHarmonicAt( size_t index ) const
136
if( index < m_valueSet->size() ) return WSymmetricSphericalHarmonic( m_valueSet->getWValueDouble( index ) );
137
return WSymmetricSphericalHarmonic();
140
const std::string WDataSetSphericalHarmonics::getName() const
142
return "WDataSetSphericalHarmonics";
145
const std::string WDataSetSphericalHarmonics::getDescription() const
147
return "Contains factors for spherical harmonics.";
150
bool WDataSetSphericalHarmonics::isTexture() const