OpenWalnut  1.5.0dev
WDataSetSingle.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
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.
14 //
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.
19 //
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/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "../common/WAssert.h"
30 #include "../common/WException.h"
31 #include "../common/WPrototyped.h"
32 #include "WDataSetSingle.h"
33 #include "WDataTexture3D.h"
34 #include "WGrid.h"
35 #include "WGridRegular3D.h"
36 #include "WValueSet.h"
37 
38 // prototype instance as singleton
39 std::shared_ptr< WPrototyped > WDataSetSingle::m_prototype = std::shared_ptr< WPrototyped >();
40 
41 WDataSetSingle::WDataSetSingle( std::shared_ptr< WValueSetBase > newValueSet,
42  std::shared_ptr< WGrid > newGrid )
43  : WDataSet(),
44  m_texture()
45 {
46  WAssert( newValueSet, "Need a value set for new data set." );
47  WAssert( newGrid, "Need a grid for new data set." );
48  WAssert( newValueSet->size() == newGrid->size(),
49  "Number of grid position unequal number of values in value set." );
50 
51  m_valueSet = newValueSet;
52  m_grid = newGrid;
53 
54  m_infoProperties->addProperty( m_grid->getInformationProperties() );
55 
56  // technically this should be placed into the WDataSetScalar, WDataSetVector and so on
57  std::shared_ptr< WGridRegular3D > regGrid = std::dynamic_pointer_cast< WGridRegular3D >( m_grid );
58  if( regGrid && ( m_valueSet->dimension() < 5 ) && ( m_valueSet->dimension() != 0 ) )
59  {
60  m_texture = osg::ref_ptr< WDataTexture3D >( new WDataTexture3D( m_valueSet, regGrid ) );
61  }
62 }
63 
65  : WDataSet(),
66  m_grid(),
67  m_valueSet(),
68  m_texture()
69 {
70  // default constructor used by the prototype mechanism
71 }
72 
74 {
75 }
76 
77 WDataSetSingle::SPtr WDataSetSingle::clone( std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid ) const
78 {
79  return WDataSetSingle::SPtr( new WDataSetSingle( newValueSet, newGrid ) );
80 }
81 
82 WDataSetSingle::SPtr WDataSetSingle::clone( std::shared_ptr< WValueSetBase > newValueSet ) const
83 {
84  return WDataSetSingle::SPtr( new WDataSetSingle( newValueSet, getGrid() ) );
85 }
86 
87 WDataSetSingle::SPtr WDataSetSingle::clone( std::shared_ptr< WGrid > newGrid ) const
88 {
89  return WDataSetSingle::SPtr( new WDataSetSingle( getValueSet(), newGrid ) );
90 }
91 
93 {
95 }
96 
97 std::shared_ptr< WValueSetBase > WDataSetSingle::getValueSet() const
98 {
99  return m_valueSet;
100 }
101 
102 std::shared_ptr< WGrid > WDataSetSingle::getGrid() const
103 {
104  return m_grid;
105 }
106 
108 {
109  // TODO(all): this is not sophisticated. This should depend on type of data (vectors? scalars? tensors?)
110  return m_texture;
111 }
112 
113 osg::ref_ptr< WDataTexture3D > WDataSetSingle::getTexture() const
114 {
115  return m_texture;
116 }
117 
118 const std::string WDataSetSingle::getName() const
119 {
120  return "WDataSetSingle";
121 }
122 
123 const std::string WDataSetSingle::getDescription() const
124 {
125  return "A single dataset containing a number of WValues on a structured"
126  "grid. Single, in this case, means not time-dependent and not one type of"
127  "data for several subjects.";
128 }
129 
130 std::shared_ptr< WPrototyped > WDataSetSingle::getPrototype()
131 {
132  if( !m_prototype )
133  {
134  m_prototype = std::shared_ptr< WPrototyped >( new WDataSetSingle() );
135  }
136 
137  return m_prototype;
138 }
139 
140 double WDataSetSingle::getValueAt( size_t id ) const
141 {
142  return getSingleRawValue( id );
143 }
144 
145 double WDataSetSingle::getSingleRawValue( size_t id ) const
146 {
147  switch( getValueSet()->getDataType() )
148  {
149  case W_DT_UNSIGNED_CHAR:
150  {
151  return static_cast< double >( std::dynamic_pointer_cast< WValueSet< uint8_t > >( getValueSet() )->getScalar( id ) );
152  }
153  case W_DT_UINT16:
154  {
155  return static_cast< double >( std::dynamic_pointer_cast< WValueSet< uint16_t > >( getValueSet() )->getScalar( id ) );
156  }
157  case W_DT_INT16:
158  {
159  return static_cast< double >( std::dynamic_pointer_cast< WValueSet< int16_t > >( getValueSet() )->getScalar( id ) );
160  }
161  case W_DT_SIGNED_INT:
162  {
163  return static_cast< double >( std::dynamic_pointer_cast< WValueSet< int32_t > >( getValueSet() )->getScalar( id ) );
164  }
165  case W_DT_FLOAT:
166  {
167  return static_cast< double >( std::dynamic_pointer_cast< WValueSet< float > >( getValueSet() )->getScalar( id ) );
168  }
169  case W_DT_DOUBLE:
170  {
171  return static_cast< double >( std::dynamic_pointer_cast< WValueSet< double > >( getValueSet() )->getScalar( id ) );
172  }
173  default:
174  WAssert( false, "Unknow data type in dataset." );
175  }
176 
177  return 0.0; // should not be reached. Just there to quiet compiler.
178 }
std::shared_ptr< WValueSetBase > getValueSet() const
WDataSetSingle()
Construct an empty and unusable instance.
virtual const std::string getDescription() const
Gets the description for this prototype.
virtual const std::string getName() const
Gets the name of this prototype.
virtual bool isTexture() const
Determines whether this dataset can be used as a texture.
virtual WDataSetSingle::SPtr clone() const
Creates a copy (clone) of this instance.
OW_API_DEPRECATED T getValueAt(size_t id)
Get the scalar value stored at id-th position of the array of the value set.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
std::shared_ptr< WGrid > m_grid
Stores the reference of the WGrid of this DataSetSingle instance.
osg::ref_ptr< WDataTexture3D > m_texture
The 3D texture representing this dataset.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
virtual osg::ref_ptr< WDataTexture3D > getTexture() const
Returns the texture representation of the dataset.
std::shared_ptr< WGrid > getGrid() const
double getSingleRawValue(size_t id) const
Get the raw scalar value stored at id-th position of the raw array of the value set.
std::shared_ptr< WValueSetBase > m_valueSet
Stores the reference of the WValueSet of this DataSetSingle instance.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
virtual ~WDataSetSingle()
Destroys this DataSet instance.
Base class for all data set types.
Definition: WDataSet.h:50
std::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WDataSet.h:181
This class allows simple creation of WGETexture3D by using a specified grid and value-set.