Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Filter.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "Filter.h"
14 
15 using namespace kome::operation;
16 
17 
18 #include <crtdbg.h>
19 #ifdef _DEBUG
20  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
21  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
22 #endif // _DEBUG
23 
24 
25 
26 // constructor
28  m_fun = NULL;
29  m_settings.clear();
30 
31  setName( "" );
32 }
33 
34 // destructor
36  init();
37 }
38 
39 // initialze
40 void Filter::init() {
41  m_fun = NULL;
42  m_settings.clear();
43 
44  setName( "" );
45 }
46 
47 // set filter function
48 void Filter::setFilterInfo( kome::plugin::PluginCall* func, kome::objects::SettingParameterValues* settings ) {
49  // initialize
50  init();
51  if( func == NULL ) {
52  return;
53  }
54 
55  // set information
56  m_fun = func;
57  if( settings != NULL ) {
58  m_settings = *settings;
59  }
60 
61  // item
62  kome::plugin::PluginFunctionItem item;
63  item.setInfo( func );
64 
65  // set name
66  std::string name = FMT( "Filter [%s", item.getLongName() );
67  std::string paramStr;
68  for( unsigned int i = 0; i < m_settings.getNumberOfParameters(); i++ ) {
69  // add parameter name
70  if( !paramStr.empty() ) {
71  paramStr.append( ", " );
72  }
73 
74  std::string name = m_settings.getParameterName( i );
75  std::string value = m_settings.getParameterValue( i );
76 
77  paramStr.append( FMT( "%s=%s", name.c_str(), value.c_str() ) );
78  }
79 
80  if( paramStr.empty() ) {
81  name.append( "]" );
82  }
83  else {
84  name.append( FMT( "(%s)]", paramStr.c_str() ) );
85  }
86 
87  setName( name.c_str() );
88 }
89 
90 // update data points
92  kome::core::XYData& src,
94 ) {
95  // check the member
96  if( m_fun == NULL ) {
97  LOG_WARN( FMT( "The filter function is not assigned." ) );
98  return;
99  }
100 
101  // check the parameter
102  if( src.getLength() == 0 ) {
103  return;
104  }
105 
106  // parameters
108 
109  kome::plugin::PluginCallTool::setXYData( params, src );
110  kome::plugin::PluginCallTool::setUpdatedXYData( params, dst );
111  kome::plugin::PluginCallTool::setSettingValues( params, m_settings );
112 
113  try {
114  m_fun->invoke( &params );
115  }
116  catch( ... ) {
117  }
118 }
119 
120 // on update (chromatogram)
122  kome::core::XYData& src,
123  kome::core::XYData& dst,
125 ) {
126  getUpdatedData( src, dst );
127 }
128 
129 // on update (spectrum)
131  kome::core::XYData& src,
132  kome::core::XYData& dst,
134 ) {
135  getUpdatedData( src, dst );
136 }
137 
138 // on update (sample)
140  kome::core::XYData& src,
141  kome::core::XYData& dst,
142  kome::objects::Sample& sample
143 ) {
144  getUpdatedData( src, dst );
145 }
146 
147 //---------------------------------------------------------------
148 // MzRangeFilter class
149 //---------------------------------------------------------------
150 // constructor
151 MzRangeFilter::MzRangeFilter( double startMz, double endMz ){
152  m_startMz = startMz;
153  m_endMz = endMz;
154 }
155 
156 // destructor
158 }
159 
160 // on update (chromatogram)
162  kome::core::XYData& src,
163  kome::core::XYData& dst,
165 ) {
166 }
167 
168 // on update (spectrum)
170  kome::core::XYData& src,
171  kome::core::XYData& dst,
173 ) {
174 
175  // check the parameter
176  if( src.getLength() == 0 ) {
177  return;
178  }
179 
180  dst.clearPoints();
181 
182  for( unsigned int i=0; i < src.getLength(); i++ ){
183 
184  if( m_startMz < src.getX(i) && src.getX(i) <= m_endMz ){
185 
186  dst.addPoint( src.getX(i), src.getY(i) );
187  }
188  }
189 
190 }
191 
192 // on update (sample)
194  kome::core::XYData& src,
195  kome::core::XYData& dst,
196  kome::objects::Sample& sample
197 ) {
198 }
abstraction class of two dimention coordinate data
Definition: XYData.h:34
virtual ~MzRangeFilter()
destructor
Definition: Filter.cpp:157
virtual void onUpdate(kome::core::XYData &src, kome::core::XYData &dst, kome::objects::Chromatogram &chrom)
This method is called by update method. (override method)
Definition: Filter.cpp:121
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
Filter()
constructor
Definition: Filter.cpp:27
void clearPoints()
clear all data points
Definition: XYData.cpp:137
MzRangeFilter(double startMz, double endMz)
constructor
Definition: Filter.cpp:151
interfaces of Filter class
void init()
initializes
Definition: Filter.cpp:40
virtual void onUpdate(kome::core::XYData &src, kome::core::XYData &dst, kome::objects::Chromatogram &chrom)
This method is called by update method. (override method)
Definition: Filter.cpp:161
double getY(const unsigned int index)
gets y coordinate
Definition: XYData.cpp:243
void setName(const char *name)
sets name
#define NULL
Definition: CoreMacros.h:18
kome::objects::SettingParameterValues m_settings
Definition: Filter.h:51
const char * getParameterValue(const unsigned int index)
gets parameter value
const char * getParameterName(const unsigned int index)
gets parameter name
kome::plugin::PluginCall * m_fun
Definition: Filter.h:48
unsigned int getNumberOfParameters()
gets the number of parameters
parameters of plug-in function management class
Definition: Parameters.h:28
spectrum information management class
Definition: Spectrum.h:30
void addPoint(const double x, const double y)
adds point
Definition: XYData.cpp:149
virtual ~Filter()
destructor
Definition: Filter.cpp:35
void setFilterInfo(kome::plugin::PluginCall *func, kome::objects::SettingParameterValues *settings)
sets filter information
Definition: Filter.cpp:48
chromatogram information management class
Definition: Chromatogram.h:33
virtual void getUpdatedData(kome::core::XYData &src, kome::core::XYData &dst)
gets updated data points
Definition: Filter.cpp:91
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216