Github'da bir medyan filtresi kütüphanesi var. Ben bunu alıp kendi uygulamamda kullanmak istedim. Kütüphane bu. Keil'e çektim kodu aynı şekilde. Ama konu başlığından da anlayacağınız üzere "no default constructor exists for class hatası" alıyorum. C++'a aşina olmadığım için hatanın sebebini anlayamadım.
Header dosyası:
Source dosyası:
main kodda myMedian. ile ulaşabiliyorum nesnenin fonksiyonlarına. Fakat source dosyasında bu hatayı alıyorum. Eğer source dosyasındaki medianFilter myMedian'ı yorum yaparsam da bu sefer main kodda myMedian undefined olarak gözüküyor. Nasıl çözebilirim?
Header dosyası:
Kod:
#ifndef __MEDIANFILTER_H_
#define __MEDIANFILTER_H_
#include "M031Series.h"
#include <stdlib.h>
#include <stdbool.h>
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
class MedianFilter {
public:
MedianFilter(int size, int seed);
~MedianFilter();
int in(const int & value);
int out();
private:
uint8_t medFilterWin; // number of samples in sliding median filter window - usually odd #
uint8_t medDataPointer; // mid point of window
int * data; // array pointer for data sorted by age in ring buffer
uint8_t * sizeMap; // array pointer for locations data in sorted by size
uint8_t * locationMap; // array pointer for data locations in history map
uint8_t oldestDataPoint; // oldest data point location in ring buffer
int32_t totalSum;
};
extern MedianFilter myMedian;
#endif
Source dosyası:
Kod:
#include "medianFilter.h"
MedianFilter myMedian;
MedianFilter::MedianFilter(int size, int seed)
{
medFilterWin = constrain(size,3,255);
medDataPointer = size >> 1;
data = (int*)calloc (size, sizeof(int));
sizeMap = (uint8_t*)calloc(size, sizeof(uint8_t));
locationMap = (uint8_t*)calloc(size, sizeof(uint8_t));
oldestDataPoint = medDataPointer;
totalSum = size * seed;
for(uint8_t i = 0; i < medFilterWin; i++) // initialize the arrays
{
sizeMap[i] = i; // start map with straight run
locationMap[i] = i; // start map with straight run
data[i] = seed; // populate with seed value
}
}
MedianFilter::~MedianFilter()
{
// Free up the used memory when the object is destroyed
free(data);
free(sizeMap);
free(locationMap);
}
int MedianFilter::in(const int & value)
{
// sort sizeMap
// small vaues on the left (-)
// larger values on the right (+)
bool dataMoved = false;
const uint8_t rightEdge = medFilterWin - 1; // adjusted for zero indexed array
totalSum += value - data[oldestDataPoint]; // add new value and remove oldest value
data[oldestDataPoint] = value; // store new data in location of oldest data in ring buffer
// SORT LEFT (-) <======(n) (+)
if(locationMap[oldestDataPoint] > 0) // don't check left neighbours if at the extreme left
{
for(uint8_t i = locationMap[oldestDataPoint]; i > 0; i--) //index through left adjacent data
{
uint8_t n = i - 1; // neighbour location
if(data[oldestDataPoint] < data[sizeMap[n]]) // find insertion point, move old data into position
{
sizeMap[i] = sizeMap[n]; // move existing data right so the new data can go left
locationMap[sizeMap[n]]++;
sizeMap[n] = oldestDataPoint; // assign new data to neighbor position
locationMap[oldestDataPoint]--;
dataMoved = true;
}
else
{
break; // stop checking once a smaller value is found on the left
}
}
}
// SORT RIGHT (-) (n)======> (+)
if(!dataMoved && locationMap[oldestDataPoint] < rightEdge) // don't check right if at right border, or the data has already moved
{
for(int i = locationMap[oldestDataPoint]; i < rightEdge; i++) //index through left adjacent data
{
int n = i + 1; // neighbour location
if(data[oldestDataPoint] > data[sizeMap[n]]) // find insertion point, move old data into position
{
sizeMap[i] = sizeMap[n]; // move existing data left so the new data can go right
locationMap[sizeMap[n]]--;
sizeMap[n] = oldestDataPoint; // assign new data to neighbor position
locationMap[oldestDataPoint]++;
}
else
{
break; // stop checking once a smaller value is found on the right
}
}
}
oldestDataPoint++; // increment and wrap
if(oldestDataPoint == medFilterWin) oldestDataPoint = 0;
return data[sizeMap[medDataPointer]];
}
int MedianFilter::out() // return the value of the median data sample
{
return data[sizeMap[medDataPointer]];
}
main kodda myMedian. ile ulaşabiliyorum nesnenin fonksiyonlarına. Fakat source dosyasında bu hatayı alıyorum. Eğer source dosyasındaki medianFilter myMedian'ı yorum yaparsam da bu sefer main kodda myMedian undefined olarak gözüküyor. Nasıl çözebilirim?