/*! * Calculates the compnents of a field * @param[in] field field * @return size of the field */ uint8_t VTKUnstructuredGrid::calcFieldComponents( const VTKField &field ){ uint8_t comp ; std::string name( field.getName() ) ; if( name == "Points" ){ comp = static_cast<int>(VTKFieldType::VECTOR) ; } else if( name == "offsets" ){ comp = 1 ; } else if( name == "types" ){ comp = 1 ; } else if( name == "connectivity" ){ if( m_homogeneousType != VTKElementType::UNDEFINED){ comp = vtk::getNNodeInElement( m_homogeneousType ) ; } else { comp = 1; } } else{ VTKFieldType fieldType( field.getFieldType() ) ; assert( fieldType != VTKFieldType::UNDEFINED) ; comp = static_cast<uint8_t>(fieldType) ; } return comp ; };
/*! * Converts a parallel field information to string as requested by VTK format. * @param[in] field_ Field information * @return string in VTK format */ std::string vtk::convertPDataArrayToString( 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 << " <PDataArray " << "type=\"" << vtk::convertEnumToString(field_.getDataType()) << "\" " << "Name=\"" << field_.getName() << "\" " << "NumberOfComponents=\""<< comp << "\" " << ">" ; return( os.str() ) ; };
/*! * 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() ) ; };
/*! * Calculates the compnents of a field * @param[in] field field * @return size of the field */ uint8_t VTKRectilinearGrid::calcFieldComponents( const VTKField &field ){ uint8_t comp ; std::string name( field.getName() ) ; if( name == "x_Coord" || name == "y_Cooord" || name == "z_Coord" ){ comp = 1 ; } else{ VTKFieldType fieldType( field.getFieldType() ) ; assert( fieldType != VTKFieldType::UNDEFINED) ; comp = static_cast<uint8_t>(fieldType) ; } return comp ; };
/*! * Calculates the number of entries of a field * @param[in] field field * @return size of the field */ uint64_t VTKUnstructuredGrid::calcFieldEntries( const VTKField &field ){ uint64_t entries(0) ; std::string name( field.getName() ) ; if( name == "Points" ){ entries = m_points *static_cast<int>(VTKFieldType::VECTOR) ; } else if( name == "offsets" ){ entries = m_cells ; } else if( name == "types" ){ entries = m_cells ; } else if( name == "connectivity"){ entries = m_connectivity ; } else{ VTKLocation location( field.getLocation() ) ; assert( location != VTKLocation::UNDEFINED) ; if( location == VTKLocation::CELL ){ entries = m_cells ; } else if( location == VTKLocation::POINT ){ entries = m_points ; } VTKFieldType fieldType( field.getFieldType() ) ; assert( fieldType != VTKFieldType::UNDEFINED) ; entries *= static_cast<uint64_t>(fieldType) ; } return entries ; };
/*! * Calculates the number of entries of a field * @param[in] field field * @return size of the field */ uint64_t VTKRectilinearGrid::calcFieldEntries( const VTKField &field ){ uint64_t entries(0) ; std::string name( field.getName() ) ; if( name == "x_Coord" ){ entries = m_localIndex[0][1] -m_localIndex[0][0] +1 ; } else if( name == "y_Coord" ){ entries = m_localIndex[1][1] -m_localIndex[1][0] +1 ; } else if( name == "z_Coord" ){ entries = m_localIndex[2][1] -m_localIndex[2][0] +1 ; } else{ VTKLocation location( field.getLocation() ) ; assert( location != VTKLocation::UNDEFINED) ; if( location == VTKLocation::CELL ){ entries = m_cells ; } else if( location == VTKLocation::POINT ){ entries = m_points ; } VTKFieldType fieldType( field.getFieldType() ) ; assert( fieldType != VTKFieldType::UNDEFINED) ; entries *= static_cast<uint64_t>(fieldType) ; } return entries ; };
/*! * 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 ; };