Sim-LIT  2.0
 All Classes Namespaces Files Functions Variables Typedefs
main.cpp
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <string>
10 #include <vector>
11 #include <cstring>
12 #include <cstdio>
13 #include <algorithm>
14 #include <fstream>
15 #include <sstream>
16 #include "header.h"
17 
18 /*-----------------------------------------------*/
19 /*-----------VARIABLES DEL SISTEMA---------------*/
20 /* Estas variables son las que hacen que el software funcione por defecto*/
21 string src="lena.jpg";
22 string folder="";
23 string folder_result="images/";
24 bool show_data=false;
25 bool export_files=false;
26 int wblock=1, hblock=1, package_size=27;
27 vector<ForwardProcessing *> fp;
28 vector<int> fp_narguments;
29 vector<string> fp_name;
30 vector<vector<int> > fp_arguments;
31 Packetizer* pktz=NULL;
32 Rebuilder* rbd=NULL;
33 Channel* chnl=NULL;
34 vector<Metric *> metrics;
35 ofstream file;
36 /*------------------------------------------------*/
37 double npkgo, npkgf, nepkgo, nepkgf;
38 
39 #include "functions.h"
40 
41 using namespace std;
42 
43  int main(int argc, char const *argv[])
44  {
45  readArguments(argc,argv);
46  if(export_files){
47  file.open("files/results.txt",ios::app);
48  file << src << "\t";
49  }
50  if(show_data)
51  cout << "Arguments readed\n";
52  Images img(src,wblock,hblock,show_data);
53  vector<DataType *> list = img.toList();
54  int nwblock=(int)(img.getWidth()/img.getWidthBlock());
55  int nhblock=(int)(img.getHeight()/img.getHeightBlock());
56  for (int i = 0; i < fp.size(); i=i+1)
57  {
58  int narg = fp_narguments[i];
59  vector<int> args = fp_arguments[i];
60  fp[i]->make(&list,nwblock,nhblock,args,narg,show_data);
61  }
62  //if((wblock*hblock)*img.getType()>package_size){
63  // cout << "The Package Size is minor than the block sizes\n";
64  // return 0;
65  //}
66  vector<Package> pkgs = pktz->imgToPackageList(list,package_size,show_data);
67  npkgo = pkgs.size();
68  nepkgo = pktz->getSizeElements();
69  vector<Package> rcved = chnl->simulate(pkgs);
70  npkgf = rcved.size();
71 
72  if(rcved.size()==0){
73  cout << "Not exists packages received, end \n";
74  return 0;
75  }
76  vector<DataType *> pkgs_rcved = pktz->packageListToImg(rcved,show_data);
77  nepkgf = pktz->getSizeElements();
78 
79  if(export_files){
80  file << "\% Pkg-Lost: " << 100-((npkgf*100)/npkgo) << "\t";
81  file << "\% Block-Lost: " << 100-((nepkgf*100)/nepkgo) << "\t";
82  }
83 
84  if(export_files){
85  Images aux(pkgs_rcved,img.getType(),img.getWidth(),img.getHeight(),img.getWidthBlock(),img.getHeightBlock(),show_data);
86  string path = folder_result+"image_received_mixed.bmp";
87  aux.save(path.c_str());
88  }
89  for (int i = fp.size()-1; i>=0; i=i-1)
90  {
91  fp[i]->unmake(&pkgs_rcved,show_data);
92  }
93  Images received(pkgs_rcved,img.getType(),img.getWidth(),img.getHeight(),img.getWidthBlock(),img.getHeightBlock(),show_data);
94  if(export_files){
95  string path = folder_result+"image_received_unmixed.bmp";
96  received.save(path.c_str());
97  }
98  rbd->hidden(&received,show_data);
99  if(export_files){
100  string path = folder_result+"image_received_rebuilded.bmp";
101  received.save(path.c_str());
102  }
103  for (int i = 0; i < metrics.size(); i=i+1)
104  {
105  double met = metrics.at(i)->calculate(img,received,show_data);
106  if(export_files){
107  file << metrics.at(i)->getName() << ": " << met << "\t";
108  }
109  }
110  if(export_files){
111  file << "\n";
112  }
113  return 0;
114  }
115 
Clase que representa una Imagen.
Definition: Images.h:22
Clase que define la estructuras que debe tener el paquetizador.
Definition: Packetizer.h:16
Clase Abstracta que indica la forma que debe tener todo método de Ocultamiento de errores en Imágenes...
Definition: Rebuilder.h:15
Clase Abstracta que representa el Simulador de pérdida de paquetes.
Definition: Channel.h:16