OpenWalnut  1.5.0dev
WDataSetDTIToScalar_I.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2015 OpenWalnut Community, Nemtics, BSV@Uni-Leipzig
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 <vector>
27 
28 #include "WDataSetDTIToScalar_I.h"
29 #include "core/common/WFlag.h"
30 #include "core/common/WLogger.h"
31 #include "core/common/WProgress.h"
32 #include "core/dataHandler/WDataSetDTI.h"
33 #include "core/dataHandler/WDataSetScalar.h"
34 #include "core/dataHandler/WDataSetVector.h"
35 
37 {
38 }
39 
42 {
43  wlog::debug( "WDataSetDTIToScalar_I" ) << "Start computation";
44  typedef double ValueType;
45  typedef WValueSet< ValueType > ValueSetType;
46  std::shared_ptr< WGrid > grid( evals->getGrid() );
47  std::shared_ptr< std::vector< ValueType > > data( new std::vector< ValueType >( grid->size() ) );
48 
49  std::shared_ptr< WValueSet< float > > t = std::dynamic_pointer_cast< WValueSet< float > >( tensors->getValueSet() );
50  WAssert( t, "Error: Only tensor data sets with doubles are allowed currently." );
51 
52  for( unsigned int i = 0; i < grid->size() && !shutdown; ++i )
53  {
54  WTensorSym< 2, 3, float > tensor( t->getWValue( i ) );
55  WVector3d ev = evals->getVectorAt( i );
56  (*data)[i] = tensorToScalar( ev, tensor );
57  ++*progress;
58  }
59 
60  if( shutdown )
61  {
62  return WDataSetScalar::SPtr( new WDataSetScalar() ); // incase we had to abort due to shutdown, empty result
63  }
64 
65  wlog::debug( "WDataSetDTIToScalar_I" ) << "Computation done.";
66  std::shared_ptr< ValueSetType > vals( new ValueSetType( 0, 1, data ) );
67  return WDataSetScalar::SPtr( new WDataSetScalar( vals, grid ) );
68 }
virtual ~WDataSetDTIToScalar_I()
Destructor.
virtual WDataSetScalar::SPtr operator()(WProgress::SPtr progress, WBoolFlag const &shutdown, WDataSetDTI::SPtr tensors, WDataSetVector::SPtr evals)
This runs the given strategy on the given dataset.
virtual double tensorToScalar(const WVector3d &evals, const WTensorSym< 2, 3, float > &tensor)=0
Actual scalar computation.
This data set type contains scalars as values.
std::shared_ptr< WDataSetScalar > SPtr
shared_ptr abbreviation
std::shared_ptr< WDataSetVector > SPtr
shared_ptr abbreviation
std::shared_ptr< WDataSet > SPtr
Shared pointer abbreviation to a instance of this class.
Definition: WDataSet.h:55
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:48
Implements a symmetric tensor that has the same number of components in every direction.
Definition: WTensorSym.h:73
Base Class for all value set types.
Definition: WValueSet.h:47
WStreamedLogger debug(const std::string &source)
Logging a debug message.
Definition: WLogger.h:331