コレは何?/What is this?
CuiPlot(キュイプロット)はC++用のクラス。その名の通りCUI上で、Linuxのフレームバッファにグラフを描きます。
X Windowは要りません!
しかもヘッダファイルをインクルードするだけで使用可能!
こんなときに役立ちます。
- グラフ描きたいんだけど、この端末、Xwindow動かねーんだよな。。
- X Windowなしで、C++で計算中にオンラインで波形を描画したい。
- GnuPlot、煩わしい。
(車輪の再発明は承知の上! ロスアラモス国立研究所の中の人が作った GIFPlot がすげぇ。)
CuiPlot(sound is kyu/i/pu/ro/tto in Japanese) is a class of C++ language.
CuiPlot draws the 2-axes plot of numerical data on a framebuffer of Linux.
X Window systems are NOT required!
You have only to include the header files!
CuiPlot is very useful to following situations:
- I wanna plot the numerical data....but this computer cannot operate on X Window systems....
- I wanna draw the graph in C++, online, without X Window systems....
- I can't use GnuPlot owing to some reasons.
画面/Screenshot
CuiPlotを使えば、フレームバッファさえあれば、X Windowなしでこんなグラフを手軽に描けます。
You can plot the numerical data without using X Window systems, as shown in the following figure.

ダウンロード/Download
クラスのソース&使い方の一例は以下からダウンロードできます。
You can download the source code of the class, and examples for demonstrations.
- CuiPlot-REV.160513.zip NEW! (Latest Version!)
- CuiPlot-REV.140809.zip
gcc(g++) で動作確認済みです。フレームバッファさえあれば十分です。
入っているファイルの説明は以下の通り。
Compile, link, and operations of the class have been confirmed on Linux gcc(g++) and the frame buffer.
The explanations of the files included in zip are as follows:
CuiPlot.cc CuiPlotクラスの実体ファイル/actual implementation CuiPlot.hh CuiPlotクラスのヘッダ/header FrameGraphics.cc フレームバッファグラフィックスクラスの実体ファイル/actual implementation for frame buffers FrameGraphics.hh フレームバッファグラフィックスクラスのヘッダ/header of frame buffers Makefile メイクファイル/make file makefile.depend 依存関係ファイル/dependencies ReadMe.txt 私を読んで/Read Me file test.cc 使い方の一例/examples
色深度は 16bit もしくは 32bit のみ対応!その他の色深度には対応していません!
Available color depths are only 16bit/32bit colors !
デモ/demonstration
以下のように、ディレクトリ直下でメイクして test を起動するだけ。
Please "make" and launch the executable file "test" as follows:
make
./test
すると上の図のような3相電流波形が表示されます。(ひょっとしたら root 権限がないとダメな場合があるかも)
After that, you can see the 3-phase current waveform shown in the above screenshot.
("root permission" might be required...?)
使い方の一例/Example
以下に使い方の一例を書いときます。
1 : // CuiPlot テストプログラム 2 : #include <stdio.h> 3 : #include <stdlib.h> 4 : #include <math.h> 5 : #include "FrameGraphics.hh" // インクルードするだけでおk! 6 : #include "CuiPlot.hh" // インクルードするだけでおk! 7 : 8 : using namespace ARCS; 9 : 10 : int main(void){ 11 : printf("CuiPlot TEST CODE\n"); 12 : 13 : // グラフ描画準備 14 : FrameGraphics* FG; 15 : CuiPlot* Plot1; 16 : FG = new FrameGraphics("/dev/fb0"); // フレームバッファグラフィックス生成 17 : Plot1 = new CuiPlot(*FG,50,50,1000,200);// CuiPlot生成 左上を(50px,50px),幅1000px,高さ200px に設定 18 : 19 : // 基本軸と凡例の描画 20 : Plot1->DrawAxis(); 21 : Plot1->DrawLegend(); 22 : 23 : // 正弦波を一括プロットする例 24 : const unsigned int N = 1000; // プロット点 25 : double t[N] = {0}, y[N] = {0}; 26 : double tmin = -1, tmax = 1; 27 : for(unsigned int i=0;i<N;i++){ 28 : // 最初に正弦波データを作っておいてから、 29 : t[i] = (tmax-tmin)/N*i + tmin; // 時間軸データ 30 : y[i] = cos(2.0*M_PI*1.0*t[i]); // 縦軸データ 31 : } 32 : // プロットする 33 : Plot1->PlotData(t,y,N,FrameGraphics::WHITE); 34 : 35 : delete Plot1; // CuiPlotの消去 36 : delete FG; // フレームバッファグラフィックスの消去 37 : 38 : return EXIT_SUCCESS; 39 : } 40 :
上記の例では、以下の様なグラフが表示されます。 2D-graph appears as following figure:

上記は最初に正弦波のデータを作っておいてから一括してプロットしてますが、下記のような逐次プロットも可能です。
1 : // 正弦波を逐次プロットする例 2 : double tt, yy; 3 : for(unsigned int i=0;i<N;i++){ 4 : tt = (tmax-tmin)/N*i + tmin; 5 : yy = cos(2.0*M_PI*1.0*tt); 6 : Plot1->PlotData(tt,yy,FrameGraphics::RED); 7 : } 8 : Plot1->EndPlot();
SetXgridNum関数、SetYgridNum関数を使えばグリッドの分割数も自由に設定できます。
You can change number of division of the grids by using functions SetXgridNum and SetYgridNum.
1 : Plot1->SetXgridNum(20); // 横軸分割数を20に変更

色も自由に変えられます。自然な感じ。(注意!:各種設定変更後は DrawAxis() と DrawLegend() を実行しないと反映されません!)
The following code changes the colors of axes, grids, back screen, and fore text.
(Please execute DrawAxis() and DrawLegend() after changing the settings!)
1 : Plot1->SetAxisColor(FrameGraphics::BLACK); // 軸の色 2 : Plot1->SetGridColor(FrameGraphics::GRAY75); // グリッドの色 3 : Plot1->SetBackColor(FrameGraphics::WHITE); // 背景色 4 : Plot1->SetTextColor(FrameGraphics::BLACK); // 文字色

関数一覧/List of Functions
用意してある関数の一覧は以下の通り。
Available Functions are as follows:
void SetAxisColor(FrameGraphics::FGcolors color); // 主軸の色設定 void SetGridColor(FrameGraphics::FGcolors color); // グリッドの色設定 void SetBackColor(FrameGraphics::FGcolors color); // 背景色の設定 void SetTextColor(FrameGraphics::FGcolors color); // 文字色の設定 void SetXrange(double xmin, double xmax); // X軸範囲の設定 void SetYrange(double ymin, double ymax); // Y軸範囲の設定 void SetXgridNum(unsigned int N); // X軸グリッド分割数の設定 void SetYgridNum(unsigned int N); // Y軸グリッド分割数の設定 void SetXLabel(std::string str); // X軸ラベルの設定 void SetYLabel(std::string str); // Y軸ラベルの設定 void SetXform(std::string format); // X軸書式の設定 void SetYform(std::string format); // Y軸書式の設定 void DrawAxis(); // 軸の描画 void DrawLegend(); // 凡例の描画 void PlotData(double* x, double* y, unsigned int N, FrameGraphics::FGcolors color); // 1つの変数値を一括プロットする関数 void PlotData(double x, double y, FrameGraphics::FGcolors color); // 1つの変数値を逐次プロットする関数 void SetVariables(const unsigned int var_num, const std::string* var_names, const FrameGraphics::FGcolors* var_colors); // プロットする変数の設定 void PlotVariables(volatile double x, volatile double* var_values); // 複数の変数値を逐次プロットする関数 void EndPlot(); // 逐次プロット終了 void ClearPlots(); // プロットの消去 void SetVisible(bool flag); // グラフ描画の有効/無効設定
SetXform関数、SetYform関数の引数"format"はprintfの書式指定子と同じです。
例:"%1.5f"とか"%1.2e"などなど。有効数字の設定、指数表示の設定に使用します。
色の定義/Definition of Colors
FGcolorsの色の定義は以下の通り。(FrameGraphicsクラスの定義に依存します)
RED, // 赤
GREEN, // 緑
BLUE, // 青
CYAN, // 水(シアン)
MAGENTA,// 紫(マゼンタ)
YELLOW, // 黄(イエロー)
ORANGE, // 橙
WHITE, // 白
GRAY75, // 灰 輝度75%
GRAY50, // 灰 輝度50%
GRAY25, // 灰 輝度25%
BLACK // 黒
応用例/Applications
ARCS5.1-SF に使用しています。

Raspberry Pi2 でも動作を確認!
ライセンス/Licenses
Copyright (C) 2011-2014 Yuki YOKOKURA
This program is free software;
you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details <http://www.gnu.org/licenses/>.
Besides, you can negotiate about other options of licenses instead of GPL.
If you would like to get other licenses, please contact us
研究室の横の倉庫 - Side Warehouse of Laboratory
Copyright(C), Side Warehouse, All rights reserved.