TODO
my_app::my_appの引数をなんとかする
CODE
# include "stdafx.h"
# include <string>
# include <vector>
# include <boost/format.hpp>
# include <algorithm>
# include <numeric>
# include <functional>
# include <boost/scoped_array.hpp>
# include <memory>
# include <TMath.h>
# include <TApplication.h>
# include <TCanvas.h>
# include <TH1F.h>
# include <TGraph.h>
# include <TMultiGraph.h>
# include <TLatex.h>
# pragma comment(lib, "libCore.lib")
# pragma comment(lib, "libHist.lib")
# pragma comment(lib, "libGpad.lib")
# pragma comment(lib, "libGraf.lib")
using namespace std;
class my_app : public TApplication{
public:
my_app(int* argc, char* argv[]) : TApplication("app name", argc, argv){}
virtual ~my_app(){}
virtual void Run(){
vector<double> x(100);
vector<double> y1(100);
vector<double> y2(100);
for(size_t i = 0; i < x.size(); ++i){
x[i] = 1. * i * 10. / x.size();
y1[i] = TMath::Sin(x[i]);
y2[i] = TMath::Cos(x[i]);
}
//TApplication::MakeBatch();
auto c = new TCanvas("c1 gl", "c gl");
auto mg = new TMultiGraph();
auto gr1 = new TGraph(x.size(), x.data(), y1.data());
gr1->SetLineColor(4);
gr1->SetLineWidth(1);
gr1->SetMarkerColor(4);
gr1->SetMarkerStyle(1);
gr1->SetTitle("sin graph");
auto gr2 = new TGraph(x.size(), x.data(), y2.data());
gr2->SetLineColor(3);
gr2->SetLineWidth(1);
gr2->SetMarkerColor(3);
gr2->SetMarkerStyle(1);
gr2->SetTitle("cos graph");
mg->Add(gr1);
mg->Add(gr2);
//A:軸
//C:なめらかな線
//L:ポリライン
//P:マーカー
mg->Draw("ACP");
auto tex = new TLatex();
tex->SetTextSize(0.04);
const auto mytext = (boost::format("cos(#theta) #leq %1%") % *(max_element(begin(y2), end(y2)))).str();
tex->DrawLatex(1., 1., mytext.c_str());
mg->GetXaxis()->SetTitle("#theta");
mg->GetYaxis()->SetTitle("Y");
mg->GetXaxis()->SetRangeUser(0., 10.);
mg->GetYaxis()->SetRangeUser(-2., 2.);
c->Draw();
//c->SaveAs("test.svg");
c->WaitPrimitive();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
vector<char*> myargv(argc);
vector<unique_ptr<char[]>> mybuff(argc);
for(size_t i = 0; i < argc; ++i){
const wstring o(argv[i]);
mybuff[i] = unique_ptr<char[]>(new char[o.size() * sizeof(wchar_t) + 1]);
wcstombs(mybuff[i].get(), o.c_str(), (o.size() + 1) * sizeof(wchar_t));
myargv[i] = mybuff[i].get();
}
my_app app(&argc, myargv.data());
app.Run();
return 0;
}