00001 #include "gnuplotanim.h"
00002 #include "iostream"
00003
00004 #define _PREFIX_FILE png
00005
00006 using std::cout;
00007 using std::endl;
00008 GnuPlotAnim * GnuPlotAnim::plotSingleton;
00009
00010 GnuPlotAnim::GnuPlotAnim(string strPrefix,string strSufIn,string termOptions)
00011 {
00012
00013 char aux[100];
00014 m_iScreen = 0;
00015 m_sufIn = strSufIn;
00016 m_prefix = strPrefix;
00017
00018
00019 if (m_sufIn == "eps")
00020 {
00021 m_terminal = "postscript eps " + termOptions;
00022 m_terminal = "anim.eps";
00023 }
00024 else if (m_sufIn == "png")
00025 {
00026 m_terminal = "png " + termOptions;
00027 m_out = "anim.mng";
00028 }
00029 else if (m_sufIn == "pdf")
00030 m_terminal = "pdf " + termOptions;
00031 else if (m_sufIn == "jpg" || m_sufIn == "jpeg")
00032 {
00033 m_terminal = "jpeg " + termOptions;
00034 m_out = "anim.mpg";
00035 m_sufIn = "jpeg";
00036 }
00037
00038 sprintf(aux,"rm %s/*.%s ",m_dir.c_str(),m_sufIn.c_str());
00039 runSystemCommand(aux);
00040
00041 fprintf(m_file,"set term %s;\n set output \"%s/%s%06ld.%s\";\n",m_terminal.c_str(),m_dir.c_str(),m_prefix.c_str(),m_iScreen++,m_sufIn.c_str());
00042 m_iDelay = 20;
00043 }
00044
00045 void GnuPlotAnim::setGnuPlotAnim(string strPrefix,string strSufIn,string termOptions)
00046 {
00047
00048 char aux[100];
00049 m_iScreen = 0;
00050 m_sufIn = strSufIn;
00051 m_prefix = strPrefix;
00052
00053
00054 if (m_sufIn == "eps")
00055 {
00056 m_terminal = "postscript eps " + termOptions;
00057 m_out = "anim.eps";
00058 }
00059 else if (m_sufIn == "png")
00060 {
00061 m_terminal = "png small " + termOptions;
00062 m_out = "anim.mng";
00063 }
00064 else if (m_sufIn == "jpg" || m_sufIn == "jpeg")
00065 {
00066 m_terminal = "jpeg " + termOptions;
00067 m_out = "anim.mpg";
00068 m_sufIn = "jpg";
00069 }
00070 else
00071 {
00072 cout << "Invalid Format\nQuitting..." << endl;
00073 exit(0);
00074 }
00075 sprintf(aux,"rm %s/*.%s ",m_dir.c_str(),m_sufIn.c_str());
00076 runSystemCommand(aux);
00077
00078 fprintf(m_file,"set term %s;\n set output \"%s/%s%06ld.%s\";\n",m_terminal.c_str(),m_dir.c_str(),m_prefix.c_str(),m_iScreen++,m_sufIn.c_str());
00079 m_iDelay = 20;
00080 }
00081
00082
00083
00084
00085 void GnuPlotAnim::NextScene()
00086 {
00087 if (m_bPlot || m_bPlot3D)
00088 {
00089 m_bPlot = false;
00090 m_bPlot3D = false;
00091 fprintf(m_file,";\n");
00092 fprintf(m_file,"set output \"%s/%s%06ld.%s\";\n",m_dir.c_str(),m_prefix.c_str(),m_iScreen++,m_sufIn.c_str());
00093 }
00094
00095 else
00096 {
00097 fprintf(m_file,"set output \"%s/%s%06ld.%s\";\n",m_dir.c_str(),m_prefix.c_str(),m_iScreen++,m_sufIn.c_str());
00098
00099 }
00100 }
00101 void GnuPlotAnim::Draw()
00102 {
00103 char str_aux[200];
00104
00105 cout << "Gerando Animacao ... "<< endl;
00106
00107 GnuPlot::Draw();
00108
00109
00110
00111 if (m_sufIn == "png")
00112 {
00113 sprintf(str_aux,"convert -delay %d %s/*.%s %s/%s",m_iDelay,m_dir.c_str(),m_sufIn.c_str(),m_dir.c_str(),m_out.c_str());
00114 runSystemCommand(str_aux);
00115 }
00116 else if (m_sufIn == "jpeg")
00117 {
00118 sprintf(str_aux,"convert -delay %d %s/*.%s %s/%s",m_iDelay,m_dir.c_str(),m_sufIn.c_str(),m_dir.c_str(),m_out.c_str());
00119 runSystemCommand(str_aux);
00120 }
00121 else if (m_sufIn == "eps")
00122 {
00123 sprintf(str_aux,"epsmerge -o %s/%s %s/*.eps",m_dir.c_str(),m_out.c_str(),m_dir.c_str());
00124 runSystemCommand(str_aux);
00125 }
00126
00127
00128
00129 cout << "done ! " << endl;
00130
00131
00132 }
00133
00134
00135 GnuPlotAnim::~GnuPlotAnim()
00136 {
00137 }
00138
00139
00140 GnuPlotAnim& GnuPlotAnim::getGnuPlotAnim()
00141 {
00142 if (plotSingleton == NULL)
00143 {
00144 plotSingleton = new GnuPlotAnim("SCREEN","png","size 860,640");
00145 }
00146 return *plotSingleton;
00147 }