WDataSetSingle.cpp 5.4 KB
Newer Older
wiebel's avatar
wiebel committed
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
wiebel's avatar
wiebel committed
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
wiebel's avatar
wiebel committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
25
#include <string>
26
#include <vector>
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
27

28 29 30
#include "../common/WAssert.h"
#include "../common/WException.h"
#include "../common/WPrototyped.h"
31
#include "WDataTexture3D.h"
32
#include "WDataTexture3D_2.h"
wiebel's avatar
wiebel committed
33
#include "WGrid.h"
34
#include "WGridRegular3D.h"
35
#include "WValueSet.h"
wiebel's avatar
wiebel committed
36

37 38
#include "WDataSetSingle.h"

39 40 41
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetSingle::m_prototype = boost::shared_ptr< WPrototyped >();

42 43
WDataSetSingle::WDataSetSingle( boost::shared_ptr< WValueSetBase > newValueSet,
                                boost::shared_ptr< WGrid > newGrid )
44 45
    : WDataSet(),
    m_texture()
wiebel's avatar
wiebel committed
46
{
47 48 49 50
    WAssert( newValueSet, "Need a value set for new data set." );
    WAssert( newGrid, "Need a grid for new data set." );
    WAssert( newValueSet->size() == newGrid->size(),
             "Number of grid position unequal number of values in value set." );
wiebel's avatar
wiebel committed
51 52 53

    m_valueSet = newValueSet;
    m_grid = newGrid;
54
    m_texture3D = boost::shared_ptr< WDataTexture3D >( new WDataTexture3D( m_valueSet, m_grid ) );
55

56 57
    m_infoProperties->addProperty( m_grid->getInformationProperties() );

58 59 60 61 62 63
    // technically this should be placed into the WDataSetScalar, WDataSetVector and so on
    boost::shared_ptr< WGridRegular3D > regGrid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
    if ( regGrid )
    {
        m_texture = osg::ref_ptr< WDataTexture3D_2 >( new WDataTexture3D_2( m_valueSet, regGrid ) );
    }
wiebel's avatar
wiebel committed
64 65
}

66 67 68
WDataSetSingle::WDataSetSingle()
    : WDataSet(),
    m_grid(),
69
    m_valueSet(),
70 71
    m_texture3D(),
    m_texture()
72 73 74 75
{
    // default constructor used by the prototype mechanism
}

wiebel's avatar
wiebel committed
76 77 78 79
WDataSetSingle::~WDataSetSingle()
{
}

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
WDataSetSingle::SPtr WDataSetSingle::clone( boost::shared_ptr< WValueSetBase > newValueSet ) const
{
    return WDataSetSingle::SPtr( new WDataSetSingle( newValueSet, getGrid() ) );
}

WDataSetSingle::SPtr WDataSetSingle::clone( boost::shared_ptr< WGrid > newGrid ) const
{
    return WDataSetSingle::SPtr( new WDataSetSingle( getValueSet(), newGrid ) );
}

WDataSetSingle::SPtr WDataSetSingle::clone() const
{
    return WDataSetSingle::SPtr( new WDataSetSingle( getValueSet(), getGrid() ) );
}

95
boost::shared_ptr< WValueSetBase > WDataSetSingle::getValueSet() const
wiebel's avatar
wiebel committed
96 97 98 99
{
    return m_valueSet;
}

100
boost::shared_ptr< WGrid > WDataSetSingle::getGrid() const
wiebel's avatar
wiebel committed
101 102 103
{
    return m_grid;
}
104 105 106

bool WDataSetSingle::isTexture() const
{
107
    // TODO(all): this is not sophisticated. This should depend on type of data (vectors? scalars? tensors?)
108
    return m_texture;
109 110 111 112 113 114 115
}

boost::shared_ptr< WDataTexture3D > WDataSetSingle::getTexture()
{
    return m_texture3D;
}

116
osg::ref_ptr< WDataTexture3D_2 > WDataSetSingle::getTexture2() const
117 118 119 120
{
    return m_texture;
}

121
const std::string WDataSetSingle::getName() const
122 123 124 125
{
    return "WDataSetSingle";
}

126
const std::string WDataSetSingle::getDescription() const
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
{
    // TODO(all): write this
    return "Please write me.";
}

boost::shared_ptr< WPrototyped > WDataSetSingle::getPrototype()
{
    if ( !m_prototype )
    {
        m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetSingle() );
    }

    return m_prototype;
}

142
double WDataSetSingle::getValueAt( size_t id ) const
143 144 145 146 147
{
    switch( getValueSet()->getDataType() )
    {
        case W_DT_UNSIGNED_CHAR:
        {
148
            return static_cast< double >( boost::shared_dynamic_cast< WValueSet< uint8_t > >( getValueSet() )->getScalar( id ) );
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        }
        case W_DT_INT16:
        {
            return static_cast< double >( boost::shared_dynamic_cast< WValueSet< int16_t > >( getValueSet() )->getScalar( id ) );
        }
        case W_DT_SIGNED_INT:
        {
            return static_cast< double >( boost::shared_dynamic_cast< WValueSet< int32_t > >( getValueSet() )->getScalar( id ) );
        }
        case W_DT_FLOAT:
        {
            return static_cast< double >( boost::shared_dynamic_cast< WValueSet< float > >( getValueSet() )->getScalar( id ) );
        }
        case W_DT_DOUBLE:
        {
            return static_cast< double >( boost::shared_dynamic_cast< WValueSet< double > >( getValueSet() )->getScalar( id ) );
        }
        default:
167
            WAssert( false, "Unknow data type in dataset." );
168 169
    }

170
    return 0.0; // should not be reached. Just there to quiet compiler.
171
}
172 173 174 175 176

boost::shared_ptr< WDataSet > WDataSetSingle::clone( boost::shared_ptr< WValueSetBase > vs, boost::shared_ptr< WGrid > grid ) const
{
    return boost::shared_ptr< WDataSet >( new WDataSetSingle( vs, grid ) );
}