/*! * Write Field data to stream * @param[in] str output stream * @param[in] field field to be written */ void VTKUnstructuredGrid::writeFieldData( std::fstream &str, VTKField &field ){ if( field.usesInterface() ){ flushData( str, field.getCodification(), field.getName() ) ; } else if( field.autoWrite() ) { field.flushData( str ) ; } else{ if(field.getName() == "types" && homogeneousType != VTKElementType::UNDEFINED){ uint8_t type = (uint8_t) homogeneousType ; for( unsigned int i=0; i<nr_cells; ++i) genericIO::flushBINARY(str, type ); } else if(field.getName() == "offsets" && homogeneousType != VTKElementType::UNDEFINED){ uint8_t n = vtk::getNNodeInElement(homogeneousType) ; uint64_t offset(0) ; for( unsigned int i=0; i<nr_cells; ++i){ offset += n ; genericIO::flushBINARY(str, offset ); } } } };
/*! * Converts a Field information to string as requested by VTK format. * @param[in] field_ Field information * @return string in VTK format */ std::string vtk::convertDataArrayToString( const VTKField &field_ ){ std::stringstream os("") ; os << " <DataArray " << "type=\"" << vtk::convertEnumToString( field_.getType() ) << "\" " << "Name=\"" << field_.getName() << "\" " << "NumberOfComponents=\""<< unsigned(field_.getComponents()) << "\" " << "format=\"" << vtk::convertEnumToString(field_.getCodification()) << "\" "; if( field_.getCodification() == VTKFormat::APPENDED ){ os << "offset=\"" << field_.getOffset() << "\" " ; }; os << ">" ; return( os.str() ) ; };
/*! * Read Field data from stream * @param[in] str input stream * @param[in] field field to be read */ void VTKUnstructuredGrid::readFieldData( std::fstream &str, VTKField &field ){ if( field.usesInterface() ){ absorbData( str, field.getCodification(), field.getName() ) ; } else if( field.autoWrite() ){ field.absorbData( str ) ; } else { //dont do nothing } return; }
/*! * Converts a Field information to string as requested by VTK format. * @param[in] field_ Field information * @return string in VTK format */ std::string vtk::convertDataArrayToString( const VTKField &field_ ){ std::stringstream os("") ; unsigned comp = static_cast<unsigned>(field_.getFieldType()) ; if( field_.getFieldType() != VTKFieldType::SCALAR && field_.getFieldType() != VTKFieldType::VECTOR ) comp = 1 ; os << " <DataArray " << "type=\"" << vtk::convertEnumToString( field_.getDataType() ) << "\" " << "Name=\"" << field_.getName() << "\" " << "NumberOfComponents=\""<< comp << "\" " << "format=\"" << vtk::convertEnumToString(field_.getCodification()) << "\" "; if( field_.getCodification() == VTKFormat::APPENDED ){ os << "offset=\"" << field_.getOffset() << "\" " ; }; os << ">" ; return( os.str() ) ; };
/*! * Reads data array from stream and stores in field information * @param[in] str output stream * @param[out] field_ field information */ bool VTK::readDataArray( std::fstream &str, VTKField &field_ ){ std::string line_ ; while( getline(str, line_) ){ if( bitpit::utils::keywordInString( line_, field_.getName() ) ){ if( vtk::convertStringToDataArray( line_, field_ ) ){ if( field_.getCodification() == VTKFormat::ASCII) { field_.setPosition( str.tellg() ) ; }; return true ; }; }; }; return false ; };
/*! * Reads data headers from strean. * All field information available in file are stored. * @param[in] str output stream */ void VTK::readDataHeader( std::fstream &str ){ std::fstream::pos_type pos_ ; VTKLocation location; std::string locationString ; std::string line, loc_; std::stringstream ss; bool read ; VTKField temp ; VTKField** ptemp ; for( int i=0; i<2; i++){ ss.str("") ; if( i== 0) { location = VTKLocation::POINT; locationString = "Point" ; } else if( i== 1) { location = VTKLocation::CELL; locationString = "Cell" ; } temp.setLocation( location ) ; ss << "</" << locationString << "Data>" ; loc_ = ss.str(); read= true ; if( ! getline( str, line) ) read = false ; if( bitpit::utils::keywordInString( line, loc_) ) read=false ; while( read ){ if( vtk::convertStringToDataArray( line, temp ) ) { if( temp.getCodification() == VTKFormat::ASCII) { pos_ = str.tellg() ; } else{ pos_ = 0 ; }; temp.setPosition( pos_ ) ; if( ! getFieldByName( temp.getName(), ptemp )) { data.push_back( new VTKField( temp ) ) ; } else{ (*ptemp)->setOffset( temp.getOffset() ) ; (*ptemp)->setLocation( temp.getLocation() ) ; (*ptemp)->setDataType( temp.getDataType() ) ; (*ptemp)->setFieldType( temp.getFieldType() ) ; (*ptemp)->setCodification( temp.getCodification() ) ; }; }; if( ! getline( str, line) ) read = false ; if( bitpit::utils::keywordInString( line, loc_) ) read=false ; }; }; return ; };