-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFeature.cpp
More file actions
157 lines (119 loc) · 3.85 KB
/
Feature.cpp
File metadata and controls
157 lines (119 loc) · 3.85 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* File: Feature.cpp
* Author: zoizoi
*
* Created on 23 January 2011, 18:28
*/
#include <limits>
#include "Feature.h"
#include "testVol4D.h"
Feature::Feature(){
}
Feature::Feature(float weight,OVASControl* o,string name) : weight(weight),oc(o) {
scoreData=ArrayTools::allocate2DArray<float>(oc->numSteps,oc->geoSphere->getNumVs());
for(int i=0;i<oc->numSteps;i++){
for(int j=0;j<oc->geoSphere->getNumVs();j++){
scoreData[i][j]=0;
}
}
actors=new vector<vtkSmartPointer<vtkActor> >();
colourB=1;
colourG=0;
colourR=0;
//cout<<"created feature w "<<weight<<endl;
// Feature();
featureName=name;
}
Feature::Feature(const Feature& orig) {
}
Feature::~Feature() {
}
void Feature::readyRenderer(vtkSmartPointer<vtkRenderer> _renderer) {
//cout<<"ready rend w "<<weight<<endl;
renderer = _renderer;
renderWindow = renderer->GetRenderWindow();
camera = renderer->GetActiveCamera();
// std::vector< vtkSmartPointer<vtkActor> >::iterator it;
// for (it = actors.begin(); it != actors.end(); it++) {
// renderer->AddActor((*it));
// }
framebuffer = new FrameBuffer(renderer->GetRenderWindow());
}
void Feature::climbDown() {
// std::vector< vtkSmartPointer<vtkActor> >::iterator it;
// for (it = actors.begin(); it != actors.end(); it++) {
// renderer->RemoveActor((*it));
// }
delete framebuffer;
}
void Feature::scoreFeature(GeoPoint* view) {
float viewRange = 3;
camera->SetPosition(viewRange * view->getx(), viewRange * view->gety(), viewRange * view->getz());
renderWindow->Render();
scoreData[oc->currentStep][oc->currentView]=countColour(framebuffer);
//cout<<"fscore "<<scoreData[oc->currentStep][oc->currentView]<<endl;
}
int Feature::countColour(float r, float g, float b, FrameBuffer* fb) {
fb->grabData();
int count = 0;
int len = fb->getLen();
float* data = fb->getData();
for (int i = 0; i < len; i++) {
int j = i * 4;
if (data[j] == r && data[j + 1] == g && data[j + 2] == b) {
count++;
}
}
fb->delData();
return count;
}
float* Feature::getEvaluatedStepData(int step){
//cout<<"weight this is "<<weight<<endl;
int zc=0;
float* data=new float[oc->geoSphere->getNumVs()];
for(int i=0;i<oc->geoSphere->getNumVs();i++){
float maxValue = log2(300 * 300);
float value=scoreData[step][i];
float contribution;
contribution = weight * (log2(value) / maxValue);
//contribution = weight * value;
if (value == 0){
contribution = 0;
zc++;
}
data[i]=contribution;
//cout<<"contrib "<<value<<" "<<weight<<endl;
}
//cout<<" zc "<<zc<<endl;
return data;
}
void Feature::saveScoreToFile(){
string filename=string("./lastestTempData/")+featureName+string(".scoreData");
cout << "outputing file " << filename << "\n";
ofstream of;
of.open(filename.c_str());
of << oc->numSteps << " " << oc->geoSphere->getNumVs() << endl;
for (int i = 0; i < oc->numSteps; i++) {
for (int j = 0; j < oc->geoSphere->getNumVs(); j++) {
of << scoreData[i][j] << " ";
}
of << endl;
}
of.close();
ifstream infile;
}
void Feature::loadScoreFromFile(){
string filename=string("./lastestTempData/")+featureName+string(".scoreData");
cout << "loading file " << filename << "\n";
ifstream inf;
inf.open(filename.c_str());
int steps,views;
inf >> steps >> views;
cout<<"loading "<<steps<<"steps and "<<views<<" views"<<endl;
for (int i = 0; i < oc->numSteps; i++) {
for (int j = 0; j < oc->geoSphere->getNumVs(); j++) {
inf>>scoreData[i][j] ;
}
}
inf.close();
}