Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
BaselineSubtract.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "BaselineSubtract.h"
14 
15 
16 using namespace kome::operation;
17 
18 
19 #include <crtdbg.h>
20 #ifdef _DEBUG
21  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
22  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
23 #endif // _DEBUG
24 
25 
26 
27 // constructor
29  m_fun = NULL;
30  m_settings.clear();
31 
32  setName( "" );
33 }
34 
35 // destructor
37  init();
38 }
39 
40 // initialze
42  m_fun = NULL;
43  m_settings.clear();
44 
45  setName( "" );
46 }
47 
48 // set baseline function
49 void BaselineSubtract::setBaselineInfo( kome::plugin::PluginCall* func, kome::objects::SettingParameterValues* settings ) {
50  // initialize
51  init();
52  if( func == NULL ) {
53  return;
54  }
55 
56  // set information
57  m_fun = func;
58  if( settings != NULL ) {
59  m_settings = *settings;
60  }
61 
62  // function item
63  kome::plugin::PluginFunctionItem item;
64  item.setInfo( m_fun );
65 
66  // set name
67  std::string name = FMT( "Baseline Subtract[%s", item.getLongName() );
68  std::string paramStr;
69  for( unsigned int i = 0; i < m_settings.getNumberOfParameters(); i++ ) {
70  // add parameter name
71  if( !paramStr.empty() ) {
72  paramStr.append( ", " );
73  }
74 
75  std::string name = m_settings.getParameterName( i );
76  std::string value = m_settings.getParameterValue( i );
77 
78  paramStr.append( FMT( "%s=%s", name.c_str(), value.c_str() ) );
79  }
80 
81  if( paramStr.empty() ) {
82  name.append( "]" );
83  }
84  else {
85  name.append( FMT( "(%s)]", paramStr.c_str() ) );
86  }
87 
88  setName( name.c_str() );
89 }
90 
91 // subtract baseline
93  kome::core::XYData& src,
94  kome::core::XYData& dst,
95  kome::core::XYData& baseline
96 ) {
97 
98  // linear interporeration
99  unsigned int len = src.getLength();
100  double* xArray = ( len == 0 ? NULL : new double[ len ] );
101  for( unsigned int i = 0; i < src.getLength(); i++ ) {
102  xArray[ i ] = src.getX( i );
103  }
104 
105  kome::core::DataPoints baseline2;
106  kome::numeric::Interpolation::linear( baseline, baseline2, xArray, src.getLength() );
107 
108  // delete array
109  if( xArray != NULL ) {
110  delete[] xArray;
111  xArray = NULL;
112  }
113 
114  // subtract
115  dst.reserve( len );
116  for( unsigned int i = 0; i < len; i++ ) {
117  double x = src.getX( i );
118  double y = src.getY( i ) - baseline2.getY( i );
119  y = MAX( y, 0.0 );
120 
121  dst.addPoint( x, y );
122  }
123 }
124 
125 // update data points
127  kome::core::XYData& src,
128  kome::core::XYData& dst
129 ) {
130  // check the member
131  if( m_fun == NULL ) {
132  LOG_WARN( FMT( "The baseline function is not assigned." ) );
133  return;
134  }
135 
136  // check the parameter
137  if( src.getLength() == 0 ) {
138  return;
139  }
140 
141  // baseline points
142  kome::core::DataPoints baseline;
143 
144  // parameters
146 
147  kome::plugin::PluginCallTool::setXYData( params, src );
148  kome::plugin::PluginCallTool::setBaseline( params, baseline );
149  kome::plugin::PluginCallTool::setSettingValues( params, m_settings );
150 
151  m_fun->invoke( &params );
152 
153  // subtract baseline
154  subtractBaseline( src, dst, baseline );
155 
156 }
157 
158 // on update (chromatogram)
160  kome::core::XYData& src,
161  kome::core::XYData& dst,
163 ) {
164  getUpdatedData( src, dst );
165 }
166 
167 // on update (spectrum)
169  kome::core::XYData& src,
170  kome::core::XYData& dst,
172 ) {
173  getUpdatedData( src, dst );
174 }
175 
176 // on update (sample)
178  kome::core::XYData& src,
179  kome::core::XYData& dst,
180  kome::objects::Sample& sample
181 ) {
182  getUpdatedData( src, dst );
183 }
abstraction class of two dimention coordinate data
Definition: XYData.h:34
data points data of profile management class
Definition: DataPoints.h:25
double getX(const unsigned int index)
gets x coordinate
Definition: XYData.cpp:224
sample information management class
Definition: Sample.h:34
setting parameter values management class
virtual ~BaselineSubtract()
destructor
virtual void getUpdatedData(kome::core::XYData &src, kome::core::XYData &dst)
gets updated data points
double getY(const unsigned int index)
gets y coordinate
Definition: XYData.cpp:243
void setName(const char *name)
sets name
interfaces of BaselineSubtract class
kome::objects::SettingParameterValues m_settings
virtual void onUpdate(kome::core::XYData &src, kome::core::XYData &dst, kome::objects::Chromatogram &chrom)
This method is called by update method. (override method)
#define NULL
Definition: CoreMacros.h:18
const char * getParameterValue(const unsigned int index)
gets parameter value
#define MAX(x, y)
Definition: CoreMacros.h:27
const char * getParameterName(const unsigned int index)
gets parameter name
void reserve(const unsigned int num)
reserves enough contiguous memory of array
Definition: XYData.cpp:262
unsigned int getNumberOfParameters()
gets the number of parameters
parameters of plug-in function management class
Definition: Parameters.h:28
void subtractBaseline(kome::core::XYData &src, kome::core::XYData &dst, kome::core::XYData &baseline)
subtracts baseline
spectrum information management class
Definition: Spectrum.h:30
kome::plugin::PluginCall * m_fun
void setBaselineInfo(kome::plugin::PluginCall *func, kome::objects::SettingParameterValues *settings)
sets baseline information
void addPoint(const double x, const double y)
adds point
Definition: XYData.cpp:149
chromatogram information management class
Definition: Chromatogram.h:33
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216