Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::core::DataPoints Class Reference

data points data of profile management class More...

#include <DataPoints.h>

Inheritance diagram for kome::core::DataPoints:
Inheritance graph
[legend]
Collaboration diagram for kome::core::DataPoints:
Collaboration graph
[legend]

Classes

union  DataArray
 data array type More...
 

Public Types

enum  ArrayType { DOUBLE, FLOAT }
 the type of array
 

Public Member Functions

 DataPoints (ArrayType type=DOUBLE)
 constructor More...
 
 DataPoints (const DataPoints &pts)
 copy constructor More...
 
virtual ~DataPoints ()
 destructor
 
DataPointsoperator= (const DataPoints &other)
 substitution operator More...
 
void * getXData ()
 gets the pointer of x data array More...
 
void * getYData ()
 gets the pointer of y data array More...
 
- Public Member Functions inherited from kome::core::XYData
 XYData ()
 constructor
 
virtual ~XYData ()
 destructor
 
double getMinX ()
 gets minimum x More...
 
double getMaxX ()
 gets maximum x More...
 
double getMinY ()
 gets minimum y More...
 
double getMaxY ()
 gets maximum y More...
 
void clearPoints ()
 clear all data points
 
void addPoint (const double x, const double y)
 adds point More...
 
void insertPoint (const unsigned int index, const double x, const double y)
 insertts point More...
 
void updatePoint (const unsigned int index, const double x, const double y)
 updates points More...
 
void deletePoint (const unsigned int index)
 delete point More...
 
unsigned int getLength ()
 gets the number of points @return the number of points
 
double getX (const unsigned int index)
 gets x coordinate More...
 
double getY (const unsigned int index)
 gets y coordinate More...
 
void reserve (const unsigned int num)
 reserves enough contiguous memory of array More...
 
unsigned long getVersion ()
 gets the version More...
 
int searchIndex (const double x)
 searches index of specified x value. More...
 
int getNearestIndex (const double x)
 gets nearest index More...
 
void filter (const double absY=0.0, const double relY=0.0)
 executes filter More...
 
void getPoints (std::vector< Point< double > > &points, const bool ySort, const bool desc)
 gets points array More...
 
bool importData (boost::function< int(void *, int) > readFun)
 imports data More...
 
bool exportData (boost::function< int(void *, int) > writeFun)
 exports data More...
 

Protected Member Functions

virtual void onClearPoints ()
 This method is called by clearPoints method. (override method)
 
virtual void onAddPoint (const double x, const double y)
 This method is called by addPoint method. (override method) More...
 
virtual void onInsertPoint (const unsigned int index, const double x, const double y)
 This method is called by insertPoint method. (override method) More...
 
virtual void onDeletePoint (const unsigned int index)
 This method is called by deletePoint method. (override method) More...
 
virtual unsigned int onGetLength ()
 this method is called by getLength method (override method) More...
 
virtual double onGetX (const unsigned int index)
 This method is called by getX method. (override method) More...
 
virtual double onGetY (const unsigned int index)
 This method is called by getY method. (override method) More...
 
virtual void onReserve (const unsigned int num)
 This method is called by reserve method. (override method) More...
 
void changeSize (const unsigned int size)
 change the array of data More...
 
- Protected Member Functions inherited from kome::core::XYData
void updateRange ()
 updates range
 
virtual bool onLoadData (boost::function< int(void *, int) > readFun)
 loads data from file More...
 
virtual bool onSaveData (boost::function< int(void *, int) > writeFun)
 saves data to file More...
 

Protected Attributes

ArrayType m_type
 
DataArray m_xArray
 
DataArray m_yArray
 
unsigned int m_arraySize
 
unsigned int m_length
 
- Protected Attributes inherited from kome::core::XYData
bool m_updated
 
double m_minX
 
double m_maxX
 
double m_minY
 
double m_maxY
 
unsigned long m_version
 

Additional Inherited Members

- Static Protected Attributes inherited from kome::core::XYData
static unsigned long m_currentVersion = 0
 version More...
 

Detailed Description

data points data of profile management class

Definition at line 25 of file DataPoints.h.

Constructor & Destructor Documentation

kome::core::DataPoints::DataPoints ( ArrayType  type = DOUBLE)

constructor

Parameters
[in]typethe type of array

Definition at line 31 of file DataPoints.cpp.

31  : m_type( type ) {
32  // initialize
33  if( type == FLOAT ) {
34  m_xArray.fltarry = NULL;
35  m_yArray.fltarry = NULL;
36  }
37  else{
38  m_xArray.dblarry = NULL;
39  m_yArray.dblarry = NULL;
40  }
41 
42  // clear
43  onClearPoints();
44 }
#define NULL
Definition: CoreMacros.h:18
virtual void onClearPoints()
This method is called by clearPoints method. (override method)
Definition: DataPoints.cpp:141

Here is the call graph for this function:

kome::core::DataPoints::DataPoints ( const DataPoints pts)

copy constructor

Parameters
[in]ptscopy source

Definition at line 47 of file DataPoints.cpp.

47  : kome::core::XYData( dps ) {
48  // initialize
49  m_type = dps.m_type;
50  m_length = dps.m_length;
51  m_arraySize = dps.m_arraySize;
52 
53  // create array
54  if( m_arraySize == 0 ) { // empty array
55  if( m_type == FLOAT ) { // float
56  m_xArray.fltarry = NULL;
57  m_yArray.fltarry = NULL;
58  }
59  else { // double
60  m_xArray.dblarry = NULL;
61  m_yArray.dblarry = NULL;
62  }
63  }
64  else {
65  if( m_type == FLOAT ) { // float
66  m_xArray.fltarry = new float[ m_arraySize ];
67  memcpy( m_xArray.fltarry, dps.m_xArray.fltarry, sizeof( float ) * m_arraySize );
68 
69  m_yArray.fltarry = new float[ m_arraySize ];
70  memcpy( m_yArray.fltarry, dps.m_yArray.fltarry, sizeof( float ) * m_arraySize );
71  }
72  else { // double
73  m_xArray.dblarry = new double[ m_arraySize ];
74  memcpy( m_xArray.dblarry, dps.m_xArray.dblarry, sizeof( double ) * m_arraySize );
75 
76  m_yArray.dblarry = new double[ m_arraySize ];
77  memcpy( m_yArray.dblarry, dps.m_yArray.dblarry, sizeof( double ) * m_arraySize );
78  }
79  }
80 }
abstraction class of two dimention coordinate data
Definition: XYData.h:34
unsigned int m_length
Definition: DataPoints.h:89
unsigned int m_arraySize
Definition: DataPoints.h:86
#define NULL
Definition: CoreMacros.h:18

Member Function Documentation

void kome::core::DataPoints::changeSize ( const unsigned int  size)
protected

change the array of data

Parameters
[in]sizenew size

Definition at line 279 of file DataPoints.cpp.

279  {
280  // check size
281  if( m_arraySize == size ) {
282  return;
283  }
284  if( size == 0 ) {
285  onClearPoints();
286  return;
287  }
288 
289  // the number of points to be copied
290  unsigned copyNum = MIN( size, m_length );
291 
292  // create new array and copy data
293  if( m_type == FLOAT ) { // float
294  // create array
295  float* xArray = new float[ size ];
296  float* yArray = new float[ size ];
297 
298  // copy
299  if( copyNum > 0 ) {
300  unsigned int copySize = copyNum * sizeof( float );
301  memcpy( xArray, m_xArray.fltarry, copySize );
302  memcpy( yArray, m_yArray.fltarry, copySize );
303  }
304 
305  // delete
306  if( m_xArray.fltarry != NULL ) {
307  delete[] m_xArray.fltarry;
308  }
309  m_xArray.fltarry = xArray;
310 
311  if( m_yArray.fltarry != NULL ) {
312  delete[] m_yArray.fltarry;
313  }
314  m_yArray.fltarry = yArray;
315  }
316  else { // double
317  // create array
318  double* xArray = new double[ size ];
319  double* yArray = new double[ size ];
320 
321  // copy
322  if( copyNum > 0 ) {
323  unsigned int copySize = copyNum * sizeof( double );
324  memcpy( xArray, m_xArray.dblarry, copySize );
325  memcpy( yArray, m_yArray.dblarry, copySize );
326  }
327 
328  // delete
329  if( m_xArray.dblarry != NULL ) {
330  delete[] m_xArray.dblarry;
331  }
332  m_xArray.dblarry = xArray;
333 
334  if( m_yArray.dblarry != NULL ) {
335  delete[] m_yArray.dblarry;
336  }
337  m_yArray.dblarry = yArray;
338  }
339 
340  // array size
341  m_arraySize = size;
342 }
unsigned int m_length
Definition: DataPoints.h:89
unsigned int m_arraySize
Definition: DataPoints.h:86
#define MIN(x, y)
Definition: CoreMacros.h:30
#define NULL
Definition: CoreMacros.h:18
virtual void onClearPoints()
This method is called by clearPoints method. (override method)
Definition: DataPoints.cpp:141

Here is the call graph for this function:

void * kome::core::DataPoints::getXData ( )

gets the pointer of x data array

Returns
x data array

Definition at line 125 of file DataPoints.cpp.

125  {
126  if( m_type == FLOAT ) {
127  return m_xArray.fltarry;
128  }
129  return m_xArray.dblarry;
130 }
void * kome::core::DataPoints::getYData ( )

gets the pointer of y data array

Returns
y data array

Definition at line 133 of file DataPoints.cpp.

133  {
134  if( m_type == FLOAT ) {
135  return m_yArray.fltarry;
136  }
137  return m_yArray.dblarry;
138 }
void kome::core::DataPoints::onAddPoint ( const double  x,
const double  y 
)
protectedvirtual

This method is called by addPoint method. (override method)

Parameters
[in]xx coordinate of point to be added
[in]yy coordinate of point to be added

Implements kome::core::XYData.

Definition at line 170 of file DataPoints.cpp.

170  {
171  // check array size
172  if( m_length >= m_arraySize ) {
173  changeSize( MAX( FIRST_ARRAY_SIZE, m_arraySize * 2 ) );
174  }
175 
176  // store data
177  if( m_type == FLOAT ) { // float
178  m_xArray.fltarry[ m_length ] = (float)x;
179  m_yArray.fltarry[ m_length ] = (float)y;
180  }
181  else { // double
182  m_xArray.dblarry[ m_length ] = x;
183  m_yArray.dblarry[ m_length ] = y;
184  }
185 
186  // update length
187  m_length++;
188 }
unsigned int m_length
Definition: DataPoints.h:89
void changeSize(const unsigned int size)
change the array of data
Definition: DataPoints.cpp:279
unsigned int m_arraySize
Definition: DataPoints.h:86
#define MAX(x, y)
Definition: CoreMacros.h:27

Here is the call graph for this function:

void kome::core::DataPoints::onDeletePoint ( const unsigned int  index)
protectedvirtual

This method is called by deletePoint method. (override method)

Parameters
[in]indexpoint index

Implements kome::core::XYData.

Definition at line 227 of file DataPoints.cpp.

227  {
228  // length
229  m_length--;
230 
231  // delete
232  if( m_type == FLOAT ) { // float
233  for( unsigned int i = index; i < m_length; i++ ) {
234  m_xArray.fltarry[ i ] = m_xArray.fltarry[ i + 1 ];
235  m_yArray.fltarry[ i ] = m_yArray.fltarry[ i + 1 ];
236  }
237  }
238  else { // double
239  for( unsigned int i = index; i < m_length; i++ ) {
240  m_xArray.dblarry[ i ] = m_xArray.dblarry[ i + 1 ];
241  m_yArray.dblarry[ i ] = m_yArray.dblarry[ i + 1 ];
242  }
243  }
244 }
unsigned int m_length
Definition: DataPoints.h:89
unsigned int kome::core::DataPoints::onGetLength ( )
protectedvirtual

this method is called by getLength method (override method)

Returns
the number of points

Implements kome::core::XYData.

Definition at line 247 of file DataPoints.cpp.

247  {
248  return m_length;
249 }
unsigned int m_length
Definition: DataPoints.h:89
double kome::core::DataPoints::onGetX ( const unsigned int  index)
protectedvirtual

This method is called by getX method. (override method)

Parameters
[in]indexthe index of point
Returns
x coordinate

Implements kome::core::XYData.

Definition at line 252 of file DataPoints.cpp.

252  {
253  if( m_type == FLOAT ) {
254  return (double)m_xArray.fltarry[ index ];
255  }
256  return m_xArray.dblarry[ index ];
257 }
double kome::core::DataPoints::onGetY ( const unsigned int  index)
protectedvirtual

This method is called by getY method. (override method)

Parameters
[in]indexthe index of point
Returns
y coordiante

Implements kome::core::XYData.

Definition at line 260 of file DataPoints.cpp.

260  {
261  if( m_type == FLOAT ) {
262  return (double)m_yArray.fltarry[ index ];
263  }
264  return m_yArray.dblarry[ index ];
265 }
void kome::core::DataPoints::onInsertPoint ( const unsigned int  index,
const double  x,
const double  y 
)
protectedvirtual

This method is called by insertPoint method. (override method)

Parameters
[in]indexinsert position
[in]xx coordinate of point
[in]yy coordinate of point

Implements kome::core::XYData.

Definition at line 191 of file DataPoints.cpp.

191  {
192  // check array size
193  if( m_length >= m_arraySize ) {
194  changeSize( MAX( FIRST_ARRAY_SIZE, m_arraySize * 2 ) );
195  }
196 
197  // insert
198  int idx = (int)MIN( index, m_length );
199  if( m_type == FLOAT ) { // float
200  // move
201  for( int i = (int)m_length - 1; i >= idx; i-- ) {
202  m_xArray.fltarry[ i + 1 ] = m_xArray.fltarry[ i ];
203  m_yArray.fltarry[ i + 1 ] = m_yArray.fltarry[ i ];
204  }
205 
206  // insert
207  m_xArray.fltarry[ idx ] = (float)x;
208  m_yArray.fltarry[ idx ] = (float)y;
209  }
210  else { // double
211  // move
212  for( int i = (int)m_length - 1; i >= idx; i-- ) {
213  m_xArray.dblarry[ i + 1 ] = m_xArray.dblarry[ i ];
214  m_yArray.dblarry[ i + 1 ] = m_yArray.dblarry[ i ];
215  }
216 
217  // insert
218  m_xArray.dblarry[ idx ] = x;
219  m_yArray.dblarry[ idx ] = y;
220  }
221 
222  // update length
223  m_length++;
224 }
unsigned int m_length
Definition: DataPoints.h:89
void changeSize(const unsigned int size)
change the array of data
Definition: DataPoints.cpp:279
unsigned int m_arraySize
Definition: DataPoints.h:86
#define MIN(x, y)
Definition: CoreMacros.h:30
#define MAX(x, y)
Definition: CoreMacros.h:27

Here is the call graph for this function:

void kome::core::DataPoints::onReserve ( const unsigned int  num)
protectedvirtual

This method is called by reserve method. (override method)

Parameters
[in]numof points to be reserved

Implements kome::core::XYData.

Definition at line 268 of file DataPoints.cpp.

268  {
269  // necessary size
270  unsigned size = m_length + num;
271 
272  // change size
273  if( size > m_arraySize ) {
274  changeSize( size );
275  }
276 }
unsigned int m_length
Definition: DataPoints.h:89
void changeSize(const unsigned int size)
change the array of data
Definition: DataPoints.cpp:279
unsigned int m_arraySize
Definition: DataPoints.h:86

Here is the call graph for this function:

DataPoints & kome::core::DataPoints::operator= ( const DataPoints other)

substitution operator

Parameters
[in]othersource data points
Returns
substituted data points

Definition at line 88 of file DataPoints.cpp.

88  {
89  // initialize
90  m_type = other.m_type;
91  m_length = other.m_length;
92  m_arraySize = other.m_arraySize;
93 
94  // create array
95  if( m_arraySize == 0 ) { // empty array
96  if( m_type == FLOAT ) { // float
97  m_xArray.fltarry = NULL;
98  m_yArray.fltarry = NULL;
99  }
100  else { // double
101  m_xArray.dblarry = NULL;
102  m_yArray.dblarry = NULL;
103  }
104  }
105  else {
106  if( m_type == FLOAT ) { // float
107  m_xArray.fltarry = new float[ m_arraySize ];
108  memcpy( m_xArray.fltarry, other.m_xArray.fltarry, sizeof( float ) * m_arraySize );
109 
110  m_yArray.fltarry = new float[ m_arraySize ];
111  memcpy( m_yArray.fltarry, other.m_yArray.fltarry, sizeof( float ) * m_arraySize );
112  }
113  else { // double
114  m_xArray.dblarry = new double[ m_arraySize ];
115  memcpy( m_xArray.dblarry, other.m_xArray.dblarry, sizeof( double ) * m_arraySize );
116 
117  m_yArray.dblarry = new double[ m_arraySize ];
118  memcpy( m_yArray.dblarry, other.m_yArray.dblarry, sizeof( double ) * m_arraySize );
119  }
120  }
121  return *this;
122 }
unsigned int m_length
Definition: DataPoints.h:89
unsigned int m_arraySize
Definition: DataPoints.h:86
#define NULL
Definition: CoreMacros.h:18

Member Data Documentation

unsigned int kome::core::DataPoints::m_arraySize
protected

the size of array

Definition at line 86 of file DataPoints.h.

unsigned int kome::core::DataPoints::m_length
protected

the number of data points

Definition at line 89 of file DataPoints.h.

ArrayType kome::core::DataPoints::m_type
protected

type of array

Definition at line 77 of file DataPoints.h.

DataArray kome::core::DataPoints::m_xArray
protected

the array of x data

Definition at line 80 of file DataPoints.h.

DataArray kome::core::DataPoints::m_yArray
protected

the array of y data

Definition at line 83 of file DataPoints.h.


The documentation for this class was generated from the following files: