OpenWalnut  1.5.0dev
WReaderVTK.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 <fstream>
26 #include <iosfwd>
27 #include <memory>
28 #include <stdint.h>
29 #include <string>
30 #include <vector>
31 
32 
33 #include "WReaderVTK.h"
34 #include "core/common/WAssert.h"
35 #include "core/common/WIOTools.h"
36 #include "core/common/WLimits.h"
37 #include "core/common/WLogger.h"
38 #include "core/common/WStringUtils.h"
39 #include "core/dataHandler/WDataSet.h"
40 #include "core/dataHandler/WDataSetDTI.h"
41 #include "core/dataHandler/WDataSetRawHARDI.h"
42 #include "core/dataHandler/WDataSetScalar.h"
43 #include "core/dataHandler/WDataSetVector.h"
44 #include "core/dataHandler/WGridRegular3D.h"
45 #include "core/dataHandler/exceptions/WDHIOFailure.h"
46 #include "core/dataHandler/exceptions/WDHNoSuchFile.h"
47 #include "core/dataHandler/exceptions/WDHParseError.h"
48 
49 WReaderVTK::WReaderVTK( std::string fname )
50  : WReader( fname )
51 {
52 }
53 
55 {
56 }
57 
58 std::shared_ptr< WDataSet > WReaderVTK::read()
59 {
60  std::shared_ptr< WDataSet > ds;
61 
62  m_ifs = std::shared_ptr< std::ifstream >( new std::ifstream() );
63  m_ifs->open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
64  if( !m_ifs || m_ifs->bad() )
65  {
66  throw WDHIOFailure( std::string( "internal error while opening" ) );
67  }
68 
69  if( !readHeader() )
70  {
71  return ds;
72  }
73 
74  // constructs the grid
75  std::shared_ptr< WGridRegular3D > grid;
76 
77  switch( m_domainType )
78  {
79  case STRUCTURED_POINTS:
80  grid = readStructuredPoints();
81  break;
82  case RECTILINEAR_GRID:
83  grid = readRectilinearGrid();
84  break;
85  default:
86  break;
87  }
88 
89  if( !grid )
90  {
91  wlog::error( "WReaderVTK" ) << "Invalid grid!";
92  return ds;
93  }
94 
95  std::shared_ptr< WValueSetBase > values = readData( grid );
96  if( !values )
97  {
98  wlog::error( "WReaderVTK" ) << "Invalid values!";
99  return ds;
100  }
101 
102  m_ifs->close();
103 
104  switch( m_attributeType )
105  {
106  case SCALARS:
107  ds = std::shared_ptr< WDataSet >( new WDataSetScalar( values, grid ) );
108  break;
109  case VECTORS:
110  ds = std::shared_ptr< WDataSet >( new WDataSetVector( values, grid ) );
111  break;
112  case TENSORS:
113  ds = std::shared_ptr< WDataSet >( new WDataSetDTI( values, grid ) );
114  break;
115  case ARRAYS:
116  if( values->dimension() > 6 )
117  {
118  std::shared_ptr< std::vector< WVector3d > > grads = readGradients();
119  ds = std::shared_ptr< WDataSet >( new WDataSetRawHARDI( values, grid, grads ) );
120  }
121  else
122  {
123  ds = std::shared_ptr< WDataSet >( new WDataSetDTI( values, grid ) );
124  }
125  break;
126 
127  default:
128  break;
129  }
130 
131  return ds;
132 }
133 
134 std::shared_ptr< std::vector< WVector3d > > WReaderVTK::readGradients()
135 {
136  typedef std::vector< WVector3d > GradVec;
137 
138  std::string gradientFileName = m_fname;
139  std::string suffix = getSuffix( m_fname );
140 
141  WAssert( suffix == ".vtk", "Input file is not a vtk file." );
142 
143  WAssert( gradientFileName.length() > 4, "" );
144  gradientFileName.resize( gradientFileName.length() - 4 );
145  gradientFileName += ".bvec";
146 
147  // check if the file exists
148  std::ifstream i( gradientFileName.c_str() );
149  if( i.bad() || !i.is_open() )
150  {
151  if( i.is_open() )
152  {
153  i.close();
154  }
155  }
156  else
157  {
158  // the file should contain the x-coordinates in line 0, y-coordinates in line 1,
159  // z-coordinates in line 2
160  std::vector< double > values;
161  while( !i.eof() )
162  {
163  double d;
164  i >> d;
165  values.push_back( d );
166  }
167  i.close();
168 
169  if( values.size() % 3 != 0 )
170  {
171  values.resize( values.size() / 3 );
172  }
173 
174  std::shared_ptr< GradVec > newGradients( new GradVec( values.size() / 3 ) );
175 
176  for( std::size_t j = 0; j < values.size() / 3; ++j )
177  {
178  ( *newGradients )[ j ] = WVector3d( values[ 3 * j + 0 ], values[ 3 * j + 1 ], values[ 3 * j + 2 ] );
179  }
180 
181  return newGradients;
182  }
183  return std::shared_ptr< GradVec >();
184 }
185 
187 {
188  for( int i = 0; i < 4; ++i ) // strip first four lines
189  {
190  m_header.push_back( getLine( "reading first 4 lines (aka header)" ) );
191  }
192 
193  // check if the header may be valid
194  if( ( m_header.at( 0 ) != "# vtk DataFile Version 3.0" )
195  && ( m_header.at( 0 ) != "# vtk DataFile Version 2.0" ) )
196  {
197  wlog::error( "WReaderVTK" ) << "Unsupported format version string in VTK file: "
198  << m_fname
199  << ", "
200  << m_header.at( 0 );
201  return false;
202  }
203  if( m_header.at( 1 ).size() > 256 )
204  {
205  wlog::warn( "WReaderVTK" ) << "Invalid header size of VTK file: "
206  << m_fname
207  << ", max. 256 but got: "
208  << m_header.at( 1 ).size();
209  }
210  namespace su = string_utils;
211  if( ( su::toUpper( su::trim( m_header.at( 2 ) ) ) != "BINARY" )
212  &&( su::toUpper( su::trim( m_header.at( 2 ) ) ) != "ASCII" ) )
213  {
214  wlog::error( "WReaderVTK" ) << "VTK files in '" << m_header.at( 2 ) << "' format are not yet supported. Must be BINARY or ASCII";
215  return false;
216  }
217 
218  m_isASCII = ( su::toUpper( su::trim( m_header.at( 2 ) ) ) == "ASCII" );
219 
220  if( su::tokenize( m_header.at( 3 ) ).size() == 2 )
221  {
222  if( su::toUpper( su::tokenize( m_header.at( 3 ) )[1] ) == "STRUCTURED_POINTS" )
223  {
225  }
226  else if( su::toUpper( su::tokenize( m_header.at( 3 ) )[1] ) == "RECTILINEAR_GRID" )
227  {
229  }
230  else
231  {
232  wlog::error( "WReaderVTK" ) << "Cannot read this VTK DATASET type: " << su::tokenize( m_header.back() )[1];
233  return false;
234  }
235  }
236  else
237  {
238  wlog::error( "WReaderVTK" ) << "Cannot read this VTK DATASET type: " << su::tokenize( m_header.back() )[1];
239  return false;
240  }
241 
242  return true;
243 }
244 
245 std::shared_ptr< WGridRegular3D > WReaderVTK::readStructuredPoints()
246 {
247  std::string line = getLine( "reading DIMENSIONS" );
248  std::vector< std::string > dimensions_line = string_utils::tokenize( line );
249  if( ( dimensions_line.size() != 4 ) && string_utils::toLower( dimensions_line.at( 0 ) ) != "dimensions" )
250  {
251  throw WDHParseError( std::string( "invalid DIMENSIONS token: " + line + ", expected DIMENSIONS." ) );
252  }
253 
254  size_t dimensions[ 3 ];
255  dimensions[ 0 ] = getLexicalCast< size_t >( dimensions_line.at( 1 ), "" );
256  dimensions[ 1 ] = getLexicalCast< size_t >( dimensions_line.at( 2 ), "" );
257  dimensions[ 2 ] = getLexicalCast< size_t >( dimensions_line.at( 3 ), "" );
258 
259  line = getLine( "reading ORIGIN" );
260  std::vector< std::string > origin_line = string_utils::tokenize( line );
261  if( ( origin_line.size() != 4 ) && string_utils::toLower( origin_line.at( 0 ) ) != "origin" )
262  {
263  throw WDHParseError( std::string( "invalid ORIGIN token: " + line + ", expected ORIGIN." ) );
264  }
265 
266  double origin[ 3 ];
267  origin[ 0 ] = getLexicalCast< float >( origin_line.at( 1 ), "" );
268  origin[ 1 ] = getLexicalCast< float >( origin_line.at( 2 ), "" );
269  origin[ 2 ] = getLexicalCast< float >( origin_line.at( 3 ), "" );
270 
271  line = getLine( "reading SPACING" );
272  std::vector< std::string > spacings_line = string_utils::tokenize( line );
273  if( ( spacings_line.size() != 4 ) && string_utils::toLower( spacings_line.at( 0 ) ) != "spacing" )
274  {
275  throw WDHParseError( std::string( "invalid DIMENSIONS token: " + line + ", expected DIMENSIONS." ) );
276  }
277 
278  double spacings[ 3 ];
279  spacings[ 0 ] = getLexicalCast< float >( spacings_line.at( 1 ), "" );
280  spacings[ 1 ] = getLexicalCast< float >( spacings_line.at( 2 ), "" );
281  spacings[ 2 ] = getLexicalCast< float >( spacings_line.at( 3 ), "" );
282 
283  WGridTransformOrtho transform( spacings[ 0 ], spacings[ 1 ], spacings[ 2 ] );
284  transform.translate( origin );
285 
286  return std::shared_ptr< WGridRegular3D >( new WGridRegular3D( dimensions[ 0 ], dimensions[ 1 ], dimensions[ 2 ], transform ) );
287 }
288 
289 std::shared_ptr< WGridRegular3D > WReaderVTK::readRectilinearGrid()
290 {
291  std::string line = getLine( "reading DIMENSIONS" );
292  std::vector< std::string > dimensions_line = string_utils::tokenize( line );
293  if( ( dimensions_line.size() != 4 ) && string_utils::toLower( dimensions_line.at( 0 ) ) != "dimensions" )
294  {
295  throw WDHParseError( std::string( "invalid DIMENSIONS token: " + line + ", expected DIMENSIONS." ) );
296  }
297 
298  size_t dimensions[ 3 ];
299  dimensions[ 0 ] = getLexicalCast< size_t >( dimensions_line.at( 1 ), "" );
300  dimensions[ 1 ] = getLexicalCast< size_t >( dimensions_line.at( 2 ), "" );
301  dimensions[ 2 ] = getLexicalCast< size_t >( dimensions_line.at( 3 ), "" );
302 
303  std::vector< float > xcoords;
304  readCoords( "X_COORDINATES", dimensions[ 0 ], xcoords );
305  std::vector< float > ycoords;
306  readCoords( "Y_COORDINATES", dimensions[ 1 ], ycoords );
307  std::vector< float > zcoords;
308  readCoords( "Z_COORDINATES", dimensions[ 2 ], zcoords );
309 
310  wlog::warn( "WReaderVTK" ) << "Assuming evenly spaced rectilinear grid! This may not adhere to the domain data in the file!";
311 
312  WGridTransformOrtho transform( xcoords.at( 1 ) - xcoords.at( 0 ), ycoords.at( 1 ) - ycoords.at( 0 ), zcoords.at( 1 ) - zcoords.at( 0 ) ); // NOLINT this is not #<algorithm>'s transform!
313  return std::shared_ptr< WGridRegular3D >( new WGridRegular3D( dimensions[ 0 ], dimensions[ 1 ], dimensions[ 2 ], transform ) );
314 }
315 
316 void WReaderVTK::readCoords( std::string const& name, std::size_t dim, std::vector< float >& coords )
317 {
318  std::string line = getLine( std::string( "reading " ) + name );
319  std::vector< std::string > l = string_utils::tokenize( line );
320  if( ( l.size() != 3 ) && string_utils::toLower( l.at( 0 ) ) != name )
321  {
322  throw WDHParseError( std::string( "invalid " ) + name + " token: " + line + ", expected " + name + "!" );
323  }
324 
325  readValuesFromFile( coords, dim );
326 }
327 
328 void WReaderVTK::readValuesFromFile( std::vector< float >& values, std::size_t numValues ) // NOLINT non-const ref
329 {
330  values.clear();
331 
332  if( this->m_isASCII )
333  {
334  wlog::debug( "WReaderVTK" ) << "Reading ASCII";
335 
336  std::string line = getLine( "Data" );
337  std::vector< std::string > tokens = string_utils::tokenize( line );
338 
339  size_t point = 0;
340  while( point < numValues )
341  {
342  for( size_t token = 0; token < tokens.size(); ++token )
343  {
344  values.push_back( getLexicalCast< float >( tokens.at( token ), "invalid data point" ) );
345  ++point;
346  if( point > numValues )
347  {
348  throw WDHException( std::string( "Too many points in file" ) );
349  }
350  }
351  if( point < numValues )
352  {
353  line = getLine( "Data Loop" );
354  tokens = string_utils::tokenize( line );
355  }
356  }
357  }
358  else
359  {
360  wlog::debug( "WReaderVTK" ) << "Reading BINARY";
361  m_ifs->read( reinterpret_cast<char*>( &values[ 0 ] ), values.size() * sizeof( values[ 0 ] ) );
362 
363  // TODO(hlawitschka): do endianess stuff!!! switchByteOrderOfArray( data, data->size() );
364  }
365 }
366 
367 // we currently do not handle the name flag but should set the name of the data set somewhere
368 std::shared_ptr< WValueSetBase > WReaderVTK::readScalars( size_t nbPoints, const std::string& /*name*/ )
369 {
370  std::size_t pos = m_ifs->tellg();
371 
372  std::string line = getLine( "LookupTableOrData" );
373  std::vector< std::string > tokens = string_utils::tokenize( line );
374  if( string_utils::toUpper( tokens.at( 0 ) ) == "LOOKUP_TABLE" )
375  {
376  pos = m_ifs->tellg(); // remember where we are for binary files
377  }
378 
379  m_ifs->seekg( pos, std::ios::beg );
380 
381  std::shared_ptr< std::vector< float > > data( new std::vector< float >() );
382 
383  readValuesFromFile( *data, nbPoints );
384 
385  return std::shared_ptr< WValueSetBase >( new WValueSet< float >( 0, 1, data, W_DT_FLOAT ) );
386 }
387 
388 std::shared_ptr< WValueSetBase > WReaderVTK::readVectors( size_t nbPoints, const std::string& /*name*/ )
389 {
390  int pos = m_ifs->tellg(); // remember where we are for binary files
391 
392  // some files even have a lookup-table tag for vector-valued data
393  std::string line = getLine( "LookupTableOrData" );
394  std::vector< std::string > tokens = string_utils::tokenize( line );
395  if( string_utils::toUpper( tokens.at( 0 ) ) == "LOOKUP_TABLE" )
396  {
397  line = getLine( "Data" );
398  tokens = string_utils::tokenize( line );
399  pos = m_ifs->tellg(); // remember where we are for binary files
400  }
401 
402  m_ifs->seekg( pos, std::ios::beg );
403 
404  // We assume that all VTK fields store 3-dimensional vectors.
405  // There are other fields around, but there is no official VTK documentation dealing
406  // with 2D vectors and no unique interpretation of the data
407  const size_t dimension = 3;
408  std::shared_ptr< std::vector< float > > data( new std::vector< float >( nbPoints * dimension ) );
409 
410  readValuesFromFile( *data, nbPoints * dimension );
411 
412  return std::shared_ptr< WValueSetBase >( new WValueSet< float >( 1, 3, data, W_DT_FLOAT ) );
413 
414  // line = getLine( "also eat the remaining newline after lines declaration" );
415  // WAssert( std::string( "" ) == line, "Found characters in file where nothing was expected." );
416 }
417 
418 std::shared_ptr< WValueSetBase > WReaderVTK::readTensors( size_t nbPoints, const std::string& /*name*/ )
419 {
420  int pos = m_ifs->tellg(); // remember where we are for binary files
421 
422  // some files even have a lookup-table tag for vector-valued data
423  std::string line = getLine( "LookupTableOrData" );
424  std::vector< std::string > tokens = string_utils::tokenize( line );
425  if( string_utils::toUpper( tokens.at( 0 ) ) == "LOOKUP_TABLE" )
426  {
427  pos = m_ifs->tellg(); // remember where we are for binary files
428  }
429 
430  m_ifs->seekg( pos, std::ios::beg );
431 
432  std::size_t dimension = 9;
433  if( m_attributeType == ARRAYS )
434  {
435  dimension = 6;
436  }
437 
438  std::shared_ptr< std::vector< float > > data( new std::vector< float >( nbPoints * dimension ) );
439 
440  readValuesFromFile( *data, nbPoints * dimension );
441 
442  if( dimension == 9 )
443  {
444  std::size_t idx = 0;
445  for( std::size_t k = 0; k < data->size(); ++k )
446  {
447  std::size_t m = k % 9;
448  if( m != 3 && m != 6 && m != 7 )
449  {
450  ( *data )[ idx ] = ( *data )[ k ];
451  ++idx;
452  }
453  }
454  data->resize( nbPoints * 6 );
455  }
456 
457  return std::shared_ptr< WValueSetBase >( new WValueSet< float >( 1, 6, data, W_DT_FLOAT ) );
458 
459  // line = getLine( "also eat the remaining newline after lines declaration" );
460  // WAssert( std::string( "" ) == line, "Found characters in file where nothing was expected." );
461 }
462 
463 std::shared_ptr< WValueSetBase > WReaderVTK::readHARDI( std::size_t nbPoints, std::size_t nbGradients, const std::string& /*name*/ )
464 {
465  int pos = m_ifs->tellg(); // remember where we are for binary files
466 
467  // some files even have a lookup-table tag for vector-valued data
468  std::string line = getLine( "LookupTableOrData" );
469  std::vector< std::string > tokens = string_utils::tokenize( line );
470  if( string_utils::toUpper( tokens.at( 0 ) ) == "LOOKUP_TABLE" )
471  {
472  line = getLine( "Data" );
473  tokens = string_utils::tokenize( line );
474  pos = m_ifs->tellg(); // remember where we are for binary files
475  }
476 
477  m_ifs->seekg( pos, std::ios::beg );
478 
479  // We assume that all VTK fields store 3-dimensional vectors.
480  // There are other fields around, but there is no official VTK documentation dealing
481  // with 2D vectors and no unique interpretation of the data
482  std::shared_ptr< std::vector< float > > data( new std::vector< float >( nbPoints * nbGradients ) );
483 
484  readValuesFromFile( *data, nbPoints * nbGradients );
485 
486  return std::shared_ptr< WValueSetBase >( new WValueSet< float >( 1, nbGradients, data, W_DT_FLOAT ) );
487 
488  // line = getLine( "also eat the remaining newline after lines declaration" );
489  // WAssert( std::string( "" ) == line, "Found characters in file where nothing was expected." );
490 }
491 
492 
493 std::shared_ptr< WValueSetBase > WReaderVTK::readData( std::shared_ptr< WGridRegular3D > const& /* grid */ )
494 {
495  std::string line = getLine( "POINT_DATA declaration" );
496 
497  std::vector< std::string > tokens = string_utils::tokenize( line );
498  if( tokens.size() != 2 || string_utils::toUpper( tokens.at( 0 ) ) != "POINT_DATA" )
499  {
500  throw WDHException( std::string( "Invalid SCALARS tag" ) );
501  }
502 
503  size_t nbPoints = getLexicalCast< size_t >( tokens.at( 1 ), "parsing number of points" );
504 
505  line = getLine( "SCALARS declaration" );
506  tokens = string_utils::tokenize( line );
507 
508  std::string name = "Default";
509  if( tokens.size() >= 2 )
510  {
511  name = tokens.at( 1 );
512  }
513  if( tokens.size() == 3 && string_utils::toUpper( tokens.at( 0 ) ) == "SCALARS" )
514  {
516  return readScalars( nbPoints, name );
517  }
518  else if( tokens.size() == 3 && string_utils::toUpper( tokens.at( 0 ) ) == "VECTORS" )
519  {
521  return readVectors( nbPoints, name );
522  }
523  else if( tokens.size() == 3 && string_utils::toUpper( tokens.at( 0 ) ) == "TENSORS" )
524  {
526  return readTensors( nbPoints, name );
527  }
528  else if( tokens.size() == 4 && string_utils::toUpper( tokens.at( 0 ) ) == "ARRAYS" && tokens.at( 2 ) == "6" )
529  {
531  return readTensors( nbPoints, name );
532  }
533  else if( tokens.size() == 4 && string_utils::toUpper( tokens.at( 0 ) ) == "ARRAYS" && getLexicalCast< std::size_t >( tokens.at( 2 ), "" ) > 6 )
534  {
536  std::size_t k = getLexicalCast< std::size_t >( tokens.at( 2 ), "" );
537  return readHARDI( nbPoints, k, name );
538  }
539  else
540  {
541  throw WDHException( std::string( "Invalid SCALARS or VECTORS tag" ) );
542  }
543 }
544 
545 std::string WReaderVTK::getLine( const std::string& desc )
546 {
547  std::string line;
548  try
549  {
550  // we use '\n' as line termination under every platform so our files (which are most likely to be generated on Unix systems)
551  // can be read from all platforms not having those line termination symbols like e.g. windows ('\r\n').
552  std::getline( *m_ifs, line, '\n' );
553  }
554  catch( const std::ios_base::failure &e )
555  {
556  throw WDHIOFailure( std::string( "IO error while " + desc + " of VTK fiber file: " + m_fname + ", " + e.what() ) );
557  }
558  if( !m_ifs->good() )
559  {
560  throw WDHParseError( std::string( "Unexpected end of VTK fiber file: " + m_fname ) );
561  }
562  return line;
563 }
General purpose exception and therefore base class for all DataHandler related exceptions.
Definition: WDHException.h:40
Use this for IO error handling.
Definition: WDHIOFailure.h:38
Use this for IO error handling.
Definition: WDHParseError.h:38
Represents a Diffusion-Tensor-Image dataset.
Definition: WDataSetDTI.h:40
This data set type contains raw HARDI and its gradients.
This data set type contains scalars as values.
This data set type contains vectors as values.
A grid that has parallelepiped cells which all have the same proportion.
Implements an orthogonal grid transformation.
void translate(VecType const &vec)
Translate by a vector.
std::shared_ptr< WValueSetBase > readVectors(size_t nbVectors, const std::string &name)
Read VTK SCALARS field.
Definition: WReaderVTK.cpp:388
@ VECTORS
vector data
Definition: WReaderVTK.h:187
@ TENSORS
tensor data
Definition: WReaderVTK.h:190
@ SCALARS
scalar data
Definition: WReaderVTK.h:184
@ ARRAYS
array data
Definition: WReaderVTK.h:193
std::shared_ptr< std::ifstream > m_ifs
Pointer to the input file stream reader.
Definition: WReaderVTK.h:164
WReaderVTK(std::string fname)
Constructs and makes a new VTK reader for separate thread start.
Definition: WReaderVTK.cpp:49
void readCoords(std::string const &name, std::size_t dim, std::vector< float > &coords)
Read the coordinates of the dataset's domain.
Definition: WReaderVTK.cpp:316
std::shared_ptr< WGridRegular3D > readStructuredPoints()
Read VTK Domain specification and create a matching grid.
Definition: WReaderVTK.cpp:245
bool readHeader()
Read VTK header from file.
Definition: WReaderVTK.cpp:186
std::shared_ptr< WValueSetBase > readTensors(size_t nbTensors, const std::string &name)
Read VTK TENSORS field.
Definition: WReaderVTK.cpp:418
@ RECTILINEAR_GRID
rectilinear grid
Definition: WReaderVTK.h:174
@ STRUCTURED_POINTS
structured points
Definition: WReaderVTK.h:171
std::shared_ptr< WGridRegular3D > readRectilinearGrid()
Read VTK Domain specification and create a matching grid.
Definition: WReaderVTK.cpp:289
void readValuesFromFile(std::vector< float > &values, std::size_t numValues)
Read values from the file.
Definition: WReaderVTK.cpp:328
AttributeType m_attributeType
The type of the attributes first read from the file.
Definition: WReaderVTK.h:263
bool m_isASCII
internal flag whether we read ascii or binary
Definition: WReaderVTK.h:257
std::shared_ptr< WValueSetBase > readHARDI(std::size_t nbPoints, std::size_t nbGradients, const std::string &)
Read HARDI data from the file.
Definition: WReaderVTK.cpp:463
std::shared_ptr< std::vector< WVector3d > > readGradients()
Read gradients from a gradients file which has the same basename as the data file and ends in ....
Definition: WReaderVTK.cpp:134
std::shared_ptr< WValueSetBase > readScalars(size_t nbScalars, const std::string &name)
Read VTK SCALARS field.
Definition: WReaderVTK.cpp:368
DomainType m_domainType
The type of domain specified in the file.
Definition: WReaderVTK.h:260
virtual std::shared_ptr< WDataSet > read()
Reads the data file and creates a dataset out of it.
Definition: WReaderVTK.cpp:58
virtual ~WReaderVTK()
Destroys this instance and closes the file.
Definition: WReaderVTK.cpp:54
std::shared_ptr< WValueSetBase > readData(std::shared_ptr< WGridRegular3D > const &grid)
Read domain information for structured points.
Definition: WReaderVTK.cpp:493
std::string getLine(const std::string &desc)
Reads the next line from current position in stream of the fiber VTK file.
Definition: WReaderVTK.cpp:545
std::vector< std::string > m_header
VTK header of the read file.
Definition: WReaderVTK.h:162
Read some data from a given file.
Definition: WReader.h:40
std::string m_fname
Absolute path of the file to read from.
Definition: WReader.h:68
Base Class for all value set types.
Definition: WValueSet.h:47
Some utilities for string manipulation and output operations.
Definition: WStringUtils.h:59
std::string toLower(const std::string &source)
Transforms all characters in the given string into lower case characters.
std::string toUpper(const std::string &source)
Transforms all characters in the given string into upper case characters.
std::vector< std::string > tokenize(const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
Splits the given string into a vector of strings (so called tokens).
WStreamedLogger debug(const std::string &source)
Logging a debug message.
Definition: WLogger.h:331
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Definition: WLogger.h:309
WStreamedLogger error(const std::string &source)
Logging an error message.
Definition: WLogger.h:298