代码语言:xml复制
<Window x:Class="FirstSolver.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vtksharp="clr-namespace:FirstSolver;assembly=vtkSharp"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="16"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="ClearType"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="Microsoft YaHei Light"
Name="RootWindow" Title="vtk圆柱体演示" WindowState="Maximized" WindowStartupLocation="CenterScreen" Loaded="RootWindow_Loaded">
<materialDesign:DialogHost Identifier="RootDialog" DialogTheme="Inherit">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<WindowsFormsHost Grid.Row="1">
<vtksharp:RenderWindowControl x:Name="vtkFormControl1"/>
</WindowsFormsHost>
</Grid>
</materialDesign:DialogHost>
</Window>
代码语言:csharp复制using System.Windows;
namespace FirstSolver
{
public partial class MainWindow : Window
{
/// <summary>
/// 对话框宿主标识符
/// </summary>
public const string DialogHostIdentifier = "RootDialog";
public MainWindow()
{
InitializeComponent();
}
// 主窗体加载事件处理器
private void RootWindow_Loaded(object sender, RoutedEventArgs e)
{
// 柱体
vtkCylinderSource cylinderSource = vtkCylinderSource.New();
cylinderSource.SetHeight(3.0);
cylinderSource.SetRadius(1.0);
// 映射器
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(cylinderSource.GetOutputPort());
// 演员
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
// WinForm控件
vtkFormControl1.Renderer.AddActor(actor); // 增加演员
vtkFormControl1.Renderer.SetBackground(0.1, 0.2, 0.4);
vtkFormControl1.RenderWindow.Render(); // 渲染
vtkFormControl1.Renderer.ResetCamera(); // 重置相机
}
}
}