The Flutter Shutter Density Estimator
 All Files Functions Macros Pages
demo_flutter_density.cpp
Go to the documentation of this file.
1 /*demo_flutter_density.cpp*/
2 /*
3 * Copyright 2014 IPOL Image Processing On Line http://www.ipol.im/
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
37 #include <stdlib.h>
38 #include <iostream>
39 #include <fstream>
40 #include <vector>
41 #include <math.h>
42 #include "routines.h"
43 using namespace std;
44 #ifndef M_PI
45 
48 #define M_PI 3.14159265358979323846
49 #endif
50 
51 
62 int main(int argc, char **argv)
63 {
64 //Check arguments : IN OUT;
65  if (argc < 3)
66  {
67  std::cerr << " ******************************************* " << std::endl
68  << " ********** Flutter shutter density estimator ****** " << std::endl
69  << " EX: ./flutter_estimator snapshot.txt output_rho.txt 0 " << std::endl
70  << " ***************************************************** " << std::endl
71  << " ************* Yohann Tendero, 2014 **************** " << std::endl
72  << " ***************************************************** " << std::endl;
73  return 1;
74  }
75 
76 
86 
91  char* flutter_code_file=argv[1]; // file_name containing the flutter code
92  char* output_rho_file=argv[2];
93  vector<double> code; // to store the flutter code
94  double num_plot_points=1001; // number of points for the plot
95  vector<double> output_rho; // to store the estimated density
96  vector<double> output_wprime; // to store the estimated w'
97  double epsilon=2/num_plot_points; // precision for numerical
98  //differentiation estimation
99 
104 
105  code=fileToVector(flutter_code_file);
106 
111  double probability_of_velocity; // to store $\rho(velocity)$
112 
114  for(double velocity=-1; velocity<=1;
115  velocity=velocity+2/num_plot_points)
116  {
117  probability_of_velocity=-velocity*w_prime_estimator(M_PI*velocity,
118  code, epsilon); // this is Thm 2 eq (26)
119  if(probability_of_velocity>=0)//remove negative values
120  output_rho.push_back(probability_of_velocity);
121  else output_rho.push_back(0); // this implements the variant given
122  // by eq (27).
123  }
124  // renormalization so \int \rho(v) dv =1
125  double sum=0;
126  for(unsigned k=0; k<output_rho.size(); k++)
127  sum=sum+output_rho[k];
128  sum=sum*2/num_plot_points; // Length of the interval/ Number of points.
129 
130  for(unsigned k=0; k<output_rho.size(); k++)
131  output_rho[k]=output_rho[k]/sum;
132  if(atof(argv[3])==1)
133  {
134  for(unsigned k=0; k<output_rho.size(); k++)
135  output_rho[k]=log(output_rho[k]+1); //for log scaling the output_rho
136  }
142  double w_prime_velocity; // to store $w'(velocity)$
143 
144  for(double velocity=0; velocity<=1; velocity=velocity+2/num_plot_points)
145  {
146  w_prime_velocity=w_prime_estimator(M_PI*velocity, code, epsilon);
147  output_wprime.push_back(w_prime_velocity);
148 
149  }
150 
152  ofstream file_output_rho(output_rho_file, ios::out | ios::trunc);
153  // opening the file (erase if previous exists)
154  if (file_output_rho)
155  {
156  int k=0;
157  for(double velocity=-1; velocity<=1;
158  velocity=velocity+2/num_plot_points)
159  {
160  file_output_rho << velocity <<" " << output_rho[k] << endl;
161  k++;
162  }
163 
164  file_output_rho.close();
165  }
166  else
167  cerr << "Unable to open file !" << endl;
168 
169 
171  ofstream file_output_wprime("wprime.txt", ios::out | ios::trunc);
172  // opening the file (erase if previous exists)
173  if ("wprime.txt")
174  {
175  int k=0;
176  for(double velocity=0; velocity<=1; velocity=velocity+2/num_plot_points)
177  {
178  file_output_wprime << velocity <<" " << output_wprime[k] << endl;
179  k++;
180  }
181 
182  file_output_wprime.close();
183  }
184  else
185  cerr << "Unable to open file !" << endl;
186 
187 
188 
189  return 0;
190 }
191 
192 
193 
194 
195 
int main(int argc, char **argv)
main function call
std::vector< double > fileToVector(const char *name)
Given the file name oof a text file containing a flutter code store the values in a vector of doubles...
Definition: routines.cpp:74
#define M_PI
double w_prime_estimator(double xi, std::vector< double > code, double epsilon)
Definition: routines.cpp:162