• 検索結果がありません。

untitled

N/A
N/A
Protected

Academic year: 2021

シェア "untitled"

Copied!
16
0
0

読み込み中.... (全文を見る)

全文

(1)

1

計算機実験2

VTKを使った描画方法 ∼

高田雅美

takata@奈良女子大学情報科学科

G401での描画方法

„

gnuplot

„

扱えるデータ

„ プロットデータ „ 格子データ „

2次元プロット

„

3次元プロット((x, y, 値), 色なし)

„

Version3.8以上の場合

„ カラーマッピング

(2)

3

G401での描画方法

„

vtk

„

扱いやすいデータ

„ 格子データ „ プロットデータを扱うのは困難 „

カラーマッピング

„

ボリュームレンダリング

CMakeLists.txt

PROJECT (ProjectName) INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake) IF (USE_VTK_FILE) INCLUDE(${USE_VTK_FILE}) ENDIF (USE_VTK_FILE) ADD_EXECUTABLE(ObjectName ProgramFile) TARGET_LINK_LIBRARIES(ObjectName Libraries) プロジェクト名(適当) 実行ファイル使用するVTKのライブラリ プログラムファイル

(3)

5

使用するライブラリの確認

„

リファレンス

URL

„

http://www.vtk.org/doc/release/4.2/html/

„

Alphabetical Listで関数を確認

CVS logs(CVSweb): ・.cxx(/Graphics/vtk???.cxx) ・.h(/Graphics/vtk???.h) vtkGraphics を使う

Vtkのデータセット型

vtkDataSet

vtkImageData

vtkPointSet

vtkStructuredPoints

vtkRectilinear

vtkPolyData

(4)

7

データセット型 (1)

„

vtkStructuredPoints

„ 3次元格子 „ x,y,z軸に平行 „ 格子間隔が一定 „

vtkRectilinear

„ 3次元格子 „ x,y,z軸に平行 „ 格子間隔がふぞろい

データセット型 (2)

„

vtkStructuredGrid

„ 幾何形状の格子 „

vtkPolyData

„ 多面体データ „ 格子の位置関係はなし

(5)

9

データセット属性

„

格子点上(PointData)

or

„

セル上(CellData)

„

属性

„ スカラ値 „ SvalarData „ ベクタ値 „ VectorData „ デンソル値 „ TensorData „ フィールドデータ „ FieldData „ 複数存在 PointData CellData

3次元グラフ作成

class vtkPolyData; class vtkPoints; class vtkIdList; void AddLineToPolyData(vtkPolyData *pdata,char *fname){ double x,y,z; int newflg=0; char buffer[1000]; vtkIdList *pntids=vtkIdList::New(); vtkPoints *pnts=pdata->GetPoints(); if(pnts==NULL){ pnts=vtkPoints::New(); pdata->Allocate(); newflg=1; } FILE *fp=fopen(fname,"r"); while( fgets(buffer, BUFFER_SIZE, fp) ){ sscanf(buffer," %f %f %f", &x,&y,&z); pntids->InsertNextId(pnts->InsertNextPoint(x,y,z)); } fclose(fp); pdata->SetPoints(pnts); pdata->InsertNextCell (VTK_POLY_LINE,pntids); pntids->Delete(); if(newflg==1) pnts->Delete(); } x1 y1 z1 x2 y2 z2 : xn yn zn 入力ファイル

(6)

11

VTK のデータファイル

# vtkDataFile Version 1.0 ・・・(1) Volume example ・・・(2) ASCII ・・・(3) DATASET STRUCTURED_POINTS ・・・(4) DIMENSIONS 3 4 6 ・・・(5) ORIGIN 0 0 0 ・・・(6) SPACING 1 1 1 ・・・(7) POINT_DATA 72 ・・・(8)

SCALARS volume_scalars unsigned_char 1 ・・・(9) LOOKUP_TABLE default ・・・(10) 0 0 0 0 0 0 0 0 0 0 0 50 ・・・(11) 0 5 10 15 20 25 25 20 15 10 5 0 0 10 20 30 40 50 50 40 30 20 10 50 0 10 20 30 40 50 50 40 30 20 10 50 0 5 10 15 20 25 25 20 15 10 5 0 0 0 0 0 0 0 0 0 0 0 0 50 (1) ファイルバージョン (2) タイトルコメント (3) ファイルフォーマット ASCII or BINARY (4) データセットの種類 (5) 配列の大きさ (X, Y, Z) (6) 原点の位置 (X, Y, Z) (7) データ間の距離 (X, Y, Z) (8) 総データ数 (9) スカラ値のデータ名,データ型,要素数 (10) LookUpTableがデフォルトであることを示す (11) ASCIIコードで書かれたデータ „

詳しくは

http://www.vtk.org/pdf/file-formats.pdf

描画に最低限必要なもの

vtkRenderer *ren = vtkRenderer::New();

vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren);

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); Iren->SetRenderwindow(renWin); : : ren->AddActor(???); // ren->AddVolume(???); renWin->SetSize(600, 600); renWin->Render(); iren->Initialize(); renWin->Render(); iren->Start(); 表示する物体を登録 表示画面のサイズを決定 表示画面を維持 これが無い場合は,プログラム終了と同時に VTK表示画面も閉じられる

(7)

13

色の付け方

„

Actorの色づけ

vtkMapper*->ScalarVisibilityOff();

vtkActor*->GetProperty()

->SetColor(red, green, blue);

„

背景の色づけ

vtkRenderer*

->SetBackground(red, green, blue)

VTKで描画した画像の保存

vtkWindowToImageFilter *w2i=vtkWindowToImageFilter::New(); vtkJPEGWriter *writer=vtkJPEGWriter::New(); (JPEG形式で保存. 他形式保存の場合は,*JPEG*の部分を置き換え.) w2i->SetInput(vtkRenderWindow*); writer->SetInput(w2i->GetOutput()); writer->SetFileName(char *); vtkRenderWindow*->Render(); w2i->Update(); writer->Write();

(8)

15

可視化手法

„

スカラ値の可視化

„ カラーマッピング(Color mapping) „ 等高線(2D Contour) „ 等値面(3D Contour) „ 切り取り(Cutting) „ 平面,格子 „

ベクタ値の可視化

„ 矢印による表記 „ 流れの軌跡を表示 „

ボリュームレンダリング

カラーマッピング

„

Lookup Tableの利用

„ スカラ値と色を対応付け „ 使い方 „ 使う色のテーブルを作成 „ スカラ値の範囲(Max, Min) を指定 あるスカラ値Siの場合 ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − − = Min Max Min S lut color i i

(9)

17

Pipeline: カラーマッピング

vtkDataSetReader vtkImageDataGeometryFilter vtkWarpScalar vtkPolyDataMapper vtkLookupTable ReleaseDataFlagOn(); SetNormal(0,0,1); UseNormalOn(); ReleaseDataFlagOn(); SetVisibilityOn(); SetLookupTable(vtkLookupTable*) SetScalarRange(vtkWarpScalar*->GetOutput()->GetScalarRange(); SetNumberOfColors(int); SetHueRange(double, double); SetSaturationRange(double, double); SetValueRange(double, double); Build(); vtkWarpScalar* ->Update(); Actor

LookupTable

„

SetNumberOfColors(int);

„ Int数分に色分け „

SetHueRange(double, double);

„ 色相(0.6∼0.0: 青→緑→赤) „

SetSaturationRange(double,

double);

„ 彩度(1以下の正数:値が高い=色味無) „

SetValueRange(double, double);

„ 明度(1以下の正数:値が高い=明るい)

(10)

19

Pipeline:等高線(2D Contour)

vtkDataSetReader vtkImageDataGeometryFilter vtkWarpScalar vtkPolyDataMapper ReleaseDataFlagOn(); SetNormal(0,0,1); UseNormalOn(); ReleaseDataFlagOn(); Actor1 vtkContourFilter vtkPolyDataMapper Actor2 SetValue(int, double);

Pipeline:等値面(3D Contour)

vtkStructuredGridReader vtkStructuredGridOutlineFilter vtkPolyDataMapper SetValue(int, double); Actor1 vtkContourFilter ScalarVisibilityOn(); vtkPolyDataMapper ScalarVisibilityOn(); Actor2

(11)

21

vtkContourFilter

„ 入力データセット:vtkDataSet „ 出力データセット:vtkPolyData „ 関数 „ GenerateValues(int, double[2]) „ 等値線を等間隔に線を引く „ int: 本数 „ double[2]: 値の範囲(vtkWarpScale*->GetOutput()->GetScalarRange()); „ SetValue(int, double) „ 一本の等値線を引く „ int: 線の番号 double: 等値線の値 „ GetNumberOfContours() „ 等値線の数を求める

Pipeline: 平面での切り取り

vtkStructuredGridReader vtkStructuredGridOutlineFilter vtkPolyDataMapper SetCutFunction(vtkPlane*) Actor1 vtkCutter vtkPolyDataMapper Actor2 vtkPlane SetOrigin(x, y, z)

(12)

23

Pipeline: 格子での切り取り

vtkStructuredGridReader vtkStructuredGridOutlineFilter vtkPolyDataMapper SetExtent(double, double, double, double, double, double) Actor1 vtkStructuredGridGeometryFilter vtkPolyDataMapper Actor2 外枠用

Pipeline:

Glyphing を用いたベクトル描画

vtkStructured GridReader vtkStructured GridOutlineFilter vtkPolyDataMapper Actor1 vtkMaskPoints vtkPolyDataMapper vtkGlyph3D SetOnRatio(50); RandomModeOn(); Update(); Vtk???Source Setsource(vtk???Source*->GetOutput()); scalingOn(); SetScaleModeToScaleByScalar(); SetColorModeToColorByScalar(); SetScaleFactor(2); SetRange(vtkMaskPoints*->GetOutput() ->GetScalarRange()) ScalarVisibilityOn(); SetScalarRange(vtkMaskPoints* ->GetOutput()->GetScalarRange());

(13)

25

vtkMaskPoints

„

表示する格子を選択するマスク

„

最初のint点目から選択

„ SetOffset(int) „

int点に1つ選択する

„ SetOnRatio(int) „

ランダム選択

„ RandomModeOn(), RandomModeOff() „

選択する点の最大数を決定

„ SetMaximumNumberOfPoints(int)

vtkGlyph3D

„ グリフの形状を指定 SetSource(vtkPolyData*) „ グリフの大きさを比例させる<させない> ScalingOn() <ScalingOff()> „ スカラ値でスケーリング SetScaleModeToScaleByScalar „ ベクタ値でスケーリング SetScaleModeToScaleByVector „ 色とスカラ値を対応 SetColorModeToColorByScalar „ 色とベクタ値を対応 SetColorModeToColorByVector „ スケーリングを全体にfloat倍する SetScaleFactor(float) „ スカラ値の範囲 SetRange(float[2])

(14)

27

グリフの形状

矢印 vtkArrowSource 円錐 vtkConeSource 球vtkSphereSource

Pipeline: 流線の描画

vtkStructured GridReader vtkStructured GridOutlineFilter vtkPolyDataMapper Actor1 vtkExtractGrid vtkPolyDataMapper Actor2 SetVOI(int, int, int, int, int, int); SetSamplerate

(int, int, int); IncludeBoundaryOn(); vtkStreamLine vtkPolyDataMapper Actor3 GetProperty() vtkRungeKutta4 SetSource (vtkExtractGrid*); SetIntegrator (vtkRungeKutta4*); SetStepLength(float);

(15)

29

Pipeline:ボリュームレンダリング

vtkStructured PointsReader vtkOutlineFilter vtkPolyDataMapper Actor1 vtkVolumeRayCastMapper vtkVolume Actor2 外枠用 AddVolume(vtkVolume*) vtkPiecewiseFunction vtkTransferFunction vtkVolumeProperty SetProperty(vtkVolumeProperty*) vtkVolumeRayCastCompositeFunction SetVolumeRayCastFunction (vtkVolumeRayCastCompositeFunction*) AddPoint(int, double) AddRGBPoint

(double, double, double , double) SetColor(vtkTransforFunction*) SetScalarOpacity(vtkPiecewiseFunction*) ShadeOn() SetInterpolationTypeToLinear()

伝達関数

„

vtkPiecewiseFunction

„ 透明度の伝達関数

„ AddPoint(double vlaue, trans)

„ double value: データの値 „ double trans: 透明度

„

vtkColorTransferFunction

„ 色と値を対応させる

„ AddRGBPoint(double value, red, green, blue) „ HSVで色づけしたい場合

(16)

31

vtkImageShiftScale

„ 入力元:vtkStructuredPointsReader* „ 出力先:vtkRayCastMapper* „ 符号なしの整数のみ取り扱い可能 „ SetShift(負の最小値の絶対値 or 0) „ 値をシフトする(全ての値を正にする) „ SetScale(Scale/ 最大値−最小値) „ スケールをかえる(広い範囲に値を分散させる) „ SetOutputScalarTypeToUnsignedChar() „ データ型を変換

参考資料

„ 公式サイト „ http://www.vtk.org „ 尺八郎の3Dで始めるプログラミング „ http://donguri.sakura.ne.jp/~shock8/3d/vtk_index.html „ 書籍 „ http://www.kitware.com/products/vtktextbook.html „ The Visualization ToolKit –An Object-oriented approach to

3D Graphics – „ VTK User’s Guide

参照

関連したドキュメント

SCHUR TYPE FUNCTIONS ASSOCIATED WITH POLYNOMIAL SEQUENCES 0\mathrm{F} UINOMIAL TYPE AND EIGENVALUES 0\mathrm{F} CENTRAL ELEMENTS 0\mathrm{F} UNIVERSAL ENVELOPING ALGEURAS

Further using the Hamiltonian formalism for P II –P IV , it is shown that these special polynomials, which are defined by second order bilinear differential-difference equations,

They proved that if Y is a (real or complex) rearrangement-invariant nonatomic function space on [0, 1] isometric to L p [0, 1] for some 1 ≤ p < ∞ then the isometric isomorphism

By con- structing a single cone P in the product space C[0, 1] × C[0, 1] and applying fixed point theorem in cones, we establish the existence of positive solutions for a system

If the interval [0, 1] can be mapped continuously onto the square [0, 1] 2 , then after partitioning [0, 1] into 2 n+m congruent subintervals and [0, 1] 2 into 2 n+m congruent

Dive [D] proved a converse of Newton’s theorem: if Ω contains 0, and is strongly star-shaped with respect to 0, and for all t > 1 and sufficiently close to 1, the uniform

Every 0–1 distribution on a standard Borel space (that is, a nonsingular borelogical space) is concentrated at a single point. Therefore, existence of a 0–1 distri- bution that does

Taking care of all above mentioned dates we want to create a discrete model of the evolution in time of the forest.. We denote by x 0 1 , x 0 2 and x 0 3 the initial number of