在已编译的ROOT(CERN)应用程序中将TCanvas绘制到屏幕上 [英] Painting a TCanvas to the screen in a compiled ROOT (CERN) application

查看:448
本文介绍了在已编译的ROOT(CERN)应用程序中将TCanvas绘制到屏幕上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在屏幕上绘画的规则是什么?

What are the rules for painting to the screen?

我的最终目标是将TCanvas放在一个类中并从那里进行绘画,但是现在我认为也许看看一个不太复杂的示例可能会有帮助.下面是一些在我的计算机上编译并绘制到屏幕上的代码.

My end goal is to put the TCanvas into a class and paint from there, but for now I think that maybe looking at a less complicated example might help. Below is some code that compiles and paints to the screen, on my computer.

# include <TApplication.h>
# include <TCanvas.h>
# include <TH1D.h>
# include <thread>
# include <chrono>

//TCanvas canvas ("fCanvas", "fCanvas", 600, 400);

int main ( int argc, char* argv[] )
{
    TApplication app ("app",&argc,argv);

    TCanvas canvas ("fCanvas", "fCanvas", 600, 400);
    //TCanvas* canvas = new TCanvas("fCanvas", "fCanvas", 600, 400);

    TH1D h ("h","h",10,0,10);
    h.Fill(1);
    h.Fill(2);
    h.Fill(2);
    h.Fill(2);
    h.Fill(3);
    h.Fill(3);
    h.Draw();

    canvas.Update();
    canvas.Draw();

    std::this_thread::sleep_for( std::chrono::seconds(3) );

    return 0;
}

您可能会注意到一些注释掉的行.如果我使用这些canvas定义中的任何一个,并在后来称为UpdateDraw方法上使用适当的成员访问运算符,则在屏幕上打印空白TCanvas窗口后,应用程序将崩溃.如果将apph更改为指针,它也会崩溃.

You may notice some commented-out lines. If I use either of those definitions of canvas, using the appropriate member access operators on the later-called Update and Draw methods, the application crashes after printing a blank TCanvas-window to the screen. It also crashes if I change app and h to pointers.

如果我尝试使用任何种类的ROOT对象实例化一个类,它将使应用程序崩溃.

If I try to instantiate a class using any sort of ROOT object at all, it crashes the application.

现在,我正在使用MSVC ++的cl.exe进行编译,并与link.exe链接.我正在使用64位Windows 7 EnterpriseN.我正在尝试移植我在Unix中构建的应用程序,对于main开头的简单new TApplication("name",0,0);来说,它可以正常运行.

Right now, I'm compiling with MSVC++'s cl.exe and linking with link.exe. I'm working on a 64-bit Windows 7 Enterprise N. I'm trying to port an application that I built in Unix, for which a simple new TApplication("name",0,0); at the start of main made everything work.

因此,我要重申一下:在这个OS以及其他操作系统中,如何将直方图显示在屏幕上?我怀疑我是否能够理解为什么",但是最好为其他阅读此内容的人写些有关的内容.否则,只需逐步说明如何使用这些对象绘画即可.

So, to reiterate: how can I get my histograms onto the screen in this OS, and maybe others? I doubt that I'll be able to understand the "why", but it might be nice to write something about that for others reading this who can. Otherwise, just a step-by-step description of how to use these objects to paint would be wonderful.

非常感谢您对此提供的帮助;如果值得证明,我将提供更多信息/示例.

Many thanks for any help on this; I'll gladly provide more information / examples if that should prove useful.

更新:如果我使用类似的东西进行编译,则在我的特殊情况下可以使用

Update: it works in my particular case if I compile with something like

cl -nologo -DWIN32 -W3 -D_WINDOWS -Z7 -MDd -GR -EHsc main.cxx -I %ROOTSYS%\include -FIw32pragma.h /link -debug -LIBPATH:%ROOTSYS%\lib libCore.lib libRIO.lib libHist.lib libGpad.lib

不确定为什么.

请参见

See https://root.cern.ch/phpBB3/viewtopic.php?f=3&t=3402&p=85329&hilit=Vector+stl+of+TH1F*+Objects#p85329 .

推荐答案

我通常使用如下所示的TApplication来使TCanvas es真正显示为屏幕上的窗口.

I usually use TApplications like below to have TCanvases really appear as window on the screen.

#include "TApplication.h"
// other stuff

int main(int argc, char** argv) {
  TApplication theApp("App",&argc, argv);
  // your code
  // here you can Draw() things
  theApp.Run();
  return 0;
}

然后该程序仅在Run()处停止,我以^C结束该过程.

The program then just stops at Run() and I end the process with ^C.

这篇关于在已编译的ROOT(CERN)应用程序中将TCanvas绘制到屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆