-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDataProcessor.cpp
67 lines (49 loc) · 1.53 KB
/
DataProcessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* File: Preprocessor.cpp
* Author: heshan
*
* Created on April 20, 2018, 8:00 PM
*/
#include "DataProcessor.h"
#include <cmath>
#include <iostream>
DataProcessor::DataProcessor() {
out_magnitude = 0.0;
}
DataProcessor::DataProcessor(const DataProcessor& orig) { }
DataProcessor::~DataProcessor() { }
std::vector<double> DataProcessor::process(std::vector<double> vec, int vecType) {
//std::cout<<"processing...\n";
double magnitude = 0.0;
for(std::vector<double>::iterator it = vec.begin(); it != vec.end(); ++it) {
magnitude += std::pow(*it,2);
}
magnitude = std::pow(magnitude,0.5);
if (magnitude != 0) {
for(std::vector<double>::iterator it = vec.begin(); it != vec.end(); ++it) {
*it /= magnitude;
}
}
// if target vector
if (vecType == 1) out_magnitude = magnitude;
return vec;
}
std::vector<double> DataProcessor::postprocess(std::vector<double> vec) {
// std::cout<<"post processing...\n";
for(std::vector<double>::iterator it = vec.begin(); it != vec.end(); ++it) {
*it *= out_magnitude;
}
return vec;
}
double DataProcessor::postProcess(double val) {
// std::cout<<"post processing...\n";
// std::cout<<"\n"<<out_magnitude<<"******"<<"\n";
return val*(out_magnitude);
}
int DataProcessor::printVector(std::vector<double> vec){
for(std::vector<double>::iterator it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it<<", ";
}
std::cout<<std::endl;
return 0;
}