close
include目錄設定
C:\VTK 5.6\VTK\Views;C:\VTK 5.6\VTK\Charts;C:\VTK 5.6\VTK\Widgets;C:\VTK 5.6\VTK\Rendering;C:\VTK 5.6\VTK\IO;C:\VTK 5.6\VTK\Imaging;C:\VTK 5.6\VTK\Graphics;C:\VTK 5.6\VTK\Geovis;C:\VTK 5.6\VTK\GenericFiltering;C:\VTK 5.6\VTK\Filtering;C:\VTK 5.6\VTK\Common;C:\VTK 5.6\release\x86
加入下列函式庫
vtkCharts.lib
vtkViews.lib
vtkWidgets.lib
vtkHybrid.lib
vtkRendering.lib
vtkGraphics.lib
vtkImaging.lib
vtkIO.lib
vtkFiltering.lib
vtkCommon.lib
vtksys.lib
=================================================================
1: // LinePlotEx.cpp : 定義主控台應用程式的進入點。
2: //
3:
4: #include "stdafx.h"
5: #include <vtkVersion.h>
6: #include <vtkRenderer.h>
7: #include <vtkRenderWindowInteractor.h>
8: #include <vtkRenderWindow.h>
9: #include <vtkSmartPointer.h>
10: #include <vtkChartXY.h>
11: #include <vtkTable.h>
12: #include <vtkPlot.h>
13: #include <vtkFloatArray.h>
14: #include <vtkContextView.h>
15: #include <vtkContextScene.h>
16: #include <vtkPen.h>
17:
18: int _tmain(int argc, _TCHAR* argv[])
19: {
20: // Create a table with some points in it
21: vtkSmartPointer<vtkTable> table =
22: vtkSmartPointer<vtkTable>::New();
23:
24: vtkSmartPointer<vtkFloatArray> arrX =
25: vtkSmartPointer<vtkFloatArray>::New();
26: arrX->SetName("X Axis");
27: table->AddColumn(arrX);
28:
29: vtkSmartPointer<vtkFloatArray> arrC =
30: vtkSmartPointer<vtkFloatArray>::New();
31: arrC->SetName("Square");
32: table->AddColumn(arrC);
33:
34: vtkSmartPointer<vtkFloatArray> arrS =
35: vtkSmartPointer<vtkFloatArray>::New();
36: arrS->SetName("Sine");
37: table->AddColumn(arrS);
38:
39: vtkSmartPointer<vtkFloatArray> arrY =
40: vtkSmartPointer<vtkFloatArray>::New();
41: arrY->SetName("Random");
42: table->AddColumn(arrY);
43:
44: // Fill in the table with some example values
45: int numPoints = 200;
46: float inc = 20.0 / (numPoints-1);
47: table->SetNumberOfRows(numPoints);
48: for (int i = 0; i < numPoints; ++i)
49: {
50: table->SetValue(i, 0, i * inc);
51: table->SetValue(i, 1, sin(i * inc)>0);
52: table->SetValue(i, 2, sin(i * inc));
53: table->SetValue(i, 3, sin(i * inc)+rand()%10/100.0);
54: }
55:
56: // Set up the view
57: vtkSmartPointer<vtkContextView> view =
58: vtkSmartPointer<vtkContextView>::New();
59: view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
60:
61: // Add multiple line plots, setting the colors etc
62: vtkSmartPointer<vtkChartXY> chart =
63: vtkSmartPointer<vtkChartXY>::New();
64: view->GetScene()->AddItem(chart);
65: vtkPlot *line = chart->AddPlot(vtkChart::LINE);
66: #if VTK_MAJOR_VERSION <= 5
67: line->SetInput(table, 0, 1);
68: #else
69: line->SetInputData(table, 0, 1);
70: #endif
71: line->SetColor(0, 255, 0, 255);
72: line->SetWidth(1.0);
73:
74:
75: //----------------------------------------------------
76: line = chart->AddPlot(vtkChart::LINE);
77: #if VTK_MAJOR_VERSION <= 5
78: line->SetInput(table, 0, 2);
79: #else
80: line->SetInputData(table, 0, 2);
81: #endif
82: line->SetColor(255, 0, 0, 255);
83: line->SetWidth(5.0);
84: //----------------------------------------------------
85: vtkPlot *points = chart->AddPlot(vtkChart::POINTS);
86: #if VTK_MAJOR_VERSION <= 5
87: points->SetInput(table, 0, 3);
88: #else
89: points->SetInputData(table, 0, 3);
90: #endif
91: points->SetColor(0, 0, 255);
92: points->SetWidth(10.0);
93: line = chart->AddPlot(vtkChart::LINE);
94: #if VTK_MAJOR_VERSION <= 5
95: line->SetInput(table, 0, 3);
96: #else
97: line->SetInputData(table, 0, 3);
98: #endif
99: line->SetColor(255, 120, 0, 255);
100: line->SetWidth(2.0);
101:
102:
103:
104:
105: // For dotted line, the line type can be from 2 to 5 for different dash/dot
106: // patterns (see enum in vtkPen containing DASH_LINE, value 2):
107: #ifndef WIN32
108: line->GetPen()->SetLineType(vtkPen::DASH_LINE);
109: #endif
110: // (ifdef-ed out on Windows because DASH_LINE does not work on Windows
111: // machines with built-in Intel HD graphics card...)
112:
113: //view->GetRenderWindow()->SetMultiSamples(0);
114:
115: // Start interactor
116: view->GetInteractor()->Initialize();
117: view->GetInteractor()->Start();
118: return 0;
119: }
120:
輸出結果:
參考來源:
VTK/Examples/Cxx/Plotting/LinePlot
全站熱搜
留言列表