35 #ifndef OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H 
   36 #define OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H 
   68   template <
template <
typename> 
class SpecT, 
typename PeakType>
 
   69   void raster(SpecT<PeakType>& spectrum)
 
   72     if (spectrum.empty()) 
return;
 
   74     typename SpecT<PeakType>::iterator first = spectrum.begin();
 
   75     typename SpecT<PeakType>::iterator last = spectrum.end();
 
   77     double end_pos = (last-1)->getMZ();
 
   78     double start_pos = first->getMZ();
 
   79     int number_resampled_points = (int)(ceil((end_pos -start_pos) / 
spacing_ + 1));
 
   81     typename std::vector<PeakType> resampled_peak_container;
 
   82     resampled_peak_container.resize(number_resampled_points);
 
   85     typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
 
   86     for (
int i=0; i < number_resampled_points; ++i)
 
   92     raster(spectrum.begin(), spectrum.end(), resampled_peak_container.begin(), resampled_peak_container.end());
 
   94     resampled_peak_container.swap(spectrum);
 
  100   template <
template <
typename> 
class SpecT, 
typename PeakType>
 
  101   void raster_align(SpecT<PeakType>& spectrum, 
double start_pos, 
double end_pos)
 
  104     if (spectrum.empty()) 
return;
 
  105     if (end_pos < start_pos)
 
  107       SpecT<PeakType> empty;
 
  108       empty.swap(spectrum);
 
  112     typename SpecT<PeakType>::iterator first = spectrum.begin();
 
  113     typename SpecT<PeakType>::iterator last = spectrum.end();
 
  116     while (first != spectrum.end() && (first)->getMZ() < start_pos) {++first;}
 
  117     while (last != first && (last-1)->getMZ() > end_pos) {--last;}
 
  119     int number_resampled_points = (int)(ceil((end_pos -start_pos) / 
spacing_ + 1));
 
  121     typename std::vector<PeakType> resampled_peak_container;
 
  122     resampled_peak_container.resize(number_resampled_points);
 
  125     typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
 
  126     for (
int i=0; i < number_resampled_points; ++i)
 
  132     raster(first, last, resampled_peak_container.begin(), resampled_peak_container.end());
 
  134     resampled_peak_container.swap(spectrum);
 
  140   template < 
typename PeakTypeIterator, 
typename ConstPeakTypeIterator>
 
  141   void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
 
  143     PeakTypeIterator resample_start = resample_it;
 
  146     while(raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ())
 
  148       resample_it->setIntensity( resample_it->getIntensity() + raw_it->getIntensity() );
 
  152     while(raw_it != raw_end)
 
  155       while(resample_it != resample_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;} 
 
  156       if (resample_it != resample_start) {resample_it--;}
 
  159       if ((resample_it+1) == resample_end) {
break;}
 
  161       double dist_left =  fabs(raw_it->getMZ() - resample_it->getMZ());
 
  162       double dist_right = fabs(raw_it->getMZ() - (resample_it+1)->getMZ());
 
  165       resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity() * dist_right / (dist_left+dist_right));
 
  166       (resample_it+1)->setIntensity((resample_it+1)->getIntensity() + raw_it->getIntensity() * dist_left / (dist_left+dist_right));
 
  172     while(raw_it != raw_end) 
 
  174       resample_it->setIntensity( resample_it->getIntensity() + raw_it->getIntensity() );
 
  182   template < 
typename PeakTypeIterator>
 
  183   void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator it, PeakTypeIterator resampled_end)
 
  185     PeakTypeIterator raw_start = raw_it;
 
  188     while(it != resampled_end && it->getMZ() < raw_it->getMZ()) {it++;} 
 
  190     while(it != resampled_end)
 
  193       while(raw_it != raw_end && raw_it->getMZ() < it->getMZ() ) {raw_it++;} 
 
  194       if (raw_it != raw_start) {raw_it--;}
 
  197       if ((raw_it+1) == raw_end) {
break;}
 
  200       double m = ((raw_it+1)->getIntensity() - raw_it->getIntensity() ) / ((raw_it+1)->getMZ() - raw_it->getMZ() );
 
  201       it->setIntensity( raw_it->getIntensity() + (it->getMZ() - raw_it->getMZ())*m );
 
void raster(SpecT< PeakType > &spectrum)
Applies the resampling algorithm to an MSSpectrum. 
Definition: LinearResamplerAlign.h:69
Linear Resampling of raw data. 
Definition: LinearResampler.h:61
A 2-dimensional raw data point or peak. 
Definition: Peak2D.h:55
void raster_align(SpecT< PeakType > &spectrum, double start_pos, double end_pos)
Applies the resampling algorithm to an MSSpectrum but it will be aligned between start_pos and end_po...
Definition: LinearResamplerAlign.h:101
Linear Resampling of raw data with alignment. 
Definition: LinearResamplerAlign.h:58
void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
Applies the resampling algorithm to an MSSpectrum. 
Definition: LinearResamplerAlign.h:141
double spacing_
Spacing of the resampled data. 
Definition: LinearResampler.h:162
void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator it, PeakTypeIterator resampled_end)
Applies the resampling algorithm using a linear interpolation. 
Definition: LinearResamplerAlign.h:183