|
libGDF
|
00001 // 00002 // This file is part of libGDF. 00003 // 00004 // libGDF is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation, either version 3 of 00007 // the License, or (at your option) any later version. 00008 // 00009 // libGDF is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with libGDF. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // Copyright 2010 Martin Billinger 00018 00019 #include "GDF/SignalHeader.h" 00020 #include <limits> 00021 #include <memory.h> 00022 //#include <iostream> 00023 00024 namespace gdf { 00025 00026 SignalHeader::SignalHeader( ) 00027 { 00028 setDefaultValues( ); 00029 } 00030 00031 //=================================================================================================== 00032 //=================================================================================================== 00033 00034 SignalHeader::~SignalHeader( ) 00035 { 00036 //std::cout << "~SignalHeader( )" << std::endl; 00037 } 00038 00039 //=================================================================================================== 00040 //=================================================================================================== 00041 00042 void SignalHeader::setDefaultValues( ) 00043 { 00044 set_label( " " ); 00045 memset( transducer_type.item, 32, transducer_type.len ); 00046 set_physical_dimension( " " ); 00047 set_physical_dimension_code( 0x0000 ); 00048 set_physmin( 0.0 ); 00049 set_physmax( 0.0 ); 00050 set_digmin( 0.0 ); 00051 set_digmax( 0.0 ); 00052 memset( reserved_1.item, 0, reserved_1.len ); 00053 set_lowpass( std::numeric_limits<float32>::quiet_NaN() ); 00054 set_highpass( std::numeric_limits<float32>::quiet_NaN() ); 00055 set_notch( std::numeric_limits<float32>::quiet_NaN() ); 00056 set_samples_per_record( 0 ); 00057 set_datatype( INVALID_TYPE ); 00058 sensor_pos[0] = 0; 00059 sensor_pos[1] = 0; 00060 sensor_pos[2] = 0; 00061 set_sensor_info( 0 ); 00062 memset( reserved_2.item, 0, reserved_2.len ); 00063 00064 samplerate = 0; 00065 } 00066 00067 //=================================================================================================== 00068 //=================================================================================================== 00069 00070 double SignalHeader::phys_to_raw( const double phy ) const 00071 { 00072 double digmin = get_digmin( ); 00073 double digmax = get_digmax( ); 00074 double physmin = get_physmin( ); 00075 double physmax = get_physmax( ); 00076 return (phy-physmin)*(digmax-digmin)/(physmax-physmin)+digmin; 00077 } 00078 00079 //=================================================================================================== 00080 //=================================================================================================== 00081 00082 double SignalHeader::raw_to_phys( const double raw ) const 00083 { 00084 double digmin = get_digmin( ); 00085 double digmax = get_digmax( ); 00086 double physmin = get_physmin( ); 00087 double physmax = get_physmax( ); 00088 return (raw-digmin)*(physmax-physmin)/(digmax-digmin)+physmin; 00089 } 00090 00091 //=================================================================================================== 00092 //=================================================================================================== 00093 00094 void SignalHeader::copyFrom( const SignalHeader &other ) 00095 { 00096 set_label( other.get_label() ); 00097 memcpy( transducer_type.item, other.transducer_type.item, transducer_type.len ); 00098 set_physical_dimension( other.get_physical_dimension() ); 00099 set_physical_dimension_code( other.get_physical_dimension_code() ); 00100 set_physmin( other.get_physmin() ); 00101 set_physmax( other.get_physmax() ); 00102 set_digmin( other.get_digmin() ); 00103 set_digmax( other.get_digmax() ); 00104 set_lowpass( other.get_lowpass() ); 00105 set_highpass( other.get_highpass() ); 00106 set_notch( other.get_notch() ); 00107 set_samples_per_record( other.get_samples_per_record() ); 00108 set_datatype( other.get_datatype() ); 00109 sensor_pos[0] = other.sensor_pos[0]; 00110 sensor_pos[1] = other.sensor_pos[1]; 00111 sensor_pos[2] = other.sensor_pos[2]; 00112 set_sensor_info( other.get_sensor_info() ); 00113 set_samplerate( other.get_samplerate() ); 00114 } 00115 }