generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
_posts/2023-06-22-show-hdf5-data-using-vtkUnstructuredGrid.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: vtkUnstructuredGrid 显示 HDF5 数据 | ||
date: 2023-06-22 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 | ||
categories: [VTK] | ||
tags: [VTK] # TAG names should always be lowercase | ||
|
||
# 以下默认false | ||
math: true | ||
mermaid: true | ||
# pin: true | ||
--- | ||
|
||
# vtkUnstructuredGrid 显示 HDF5 数据 | ||
|
||
## Reference | ||
|
||
* [VTK examples](https://github.com/Kitware/vtk-examples/blob/c1c8af1e70708e65d6fa4bf69fab814f03c99dc2/src/Cxx/GeometricObjects/Hexahedron.cxx) | ||
|
||
## 添加 field (dataset) 数据 | ||
|
||
### 第一步,创建VTK的`field`数据 | ||
|
||
```C++ | ||
vtkSmartPointer<vtkDoubleArray> fieldDataArray = vtkSmartPointer<vtkDoubleArray>::New(); | ||
fieldDataArray->SetNumberOfComponents(1); // assuming scalar data | ||
|
||
// Assuming "dataset" is your std::map<std::string, std::vector<double>> | ||
for (const auto& pair : dataset) { | ||
const std::string& fieldName = pair.first; | ||
const std::vector<double>& fieldValues = pair.second; | ||
|
||
fieldDataArray->SetName(fieldName.c_str()); | ||
for (double value : fieldValues) { | ||
fieldDataArray->InsertNextValue(value); | ||
} | ||
|
||
// Assuming "grid" is your vtkUnstructuredGrid object | ||
grid->GetPointData()->AddArray(fieldDataArray); | ||
} | ||
``` | ||
* 根据`dataset`的属性`field`是`scalar`数据还是`tensor`数据,设置`SetNumberOfComponents`的参数; | ||
* 根据`dataset`的属性`field`是`scalar`数据还是`tensor`数据,选择`InsertNectValue`或者`InsertNextTuple`; | ||
* 根据`dataset`的属性`location type`属性是`vetex`还是`element`,`grid`选取`GetPointData`或者`GetCellData`; | ||
### 第二步,添加VTK `field`数据到`mapper` | ||
```C++ | ||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); | ||
mapper->SetInputData(grid); | ||
mapper->SetScalarModeToUsePointData(); // or SetScalarModeToUseCellData() | ||
mapper->SelectColorArray("fieldName"); // replace "fieldName" with the name of the field you want to use for coloring | ||
vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New(); | ||
lut->SetRange(minValue, maxValue); // set range according to your data | ||
mapper->SetLookupTable(lut); | ||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); | ||
actor->SetMapper(mapper); | ||
vtkSmartPointer<vtkScalarBarActor> scalarBar = vtkSmartPointer<vtkScalarBarActor>::New(); | ||
scalarBar->SetLookupTable(mapper->GetLookupTable()); | ||
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); | ||
renderer->AddActor(actor); | ||
renderer->AddActor2D(scalarBar); | ||
``` | ||
|
||
* 根据`dataset`的属性`location type`属性是`vetex`还是`element`,`mapper`调用`SetScalarModeToUsePointData`或者`SetScalarModeToUseCellData`; | ||
|
||
## 颜色转换的另一种方式 | ||
|
||
使用`vtkColorTranslationFunction`转换: | ||
|
||
```C++ | ||
// Create a vtkColorTransferFunction to map scalar values to colors | ||
vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New(); | ||
colorTransferFunction->AddRGBPoint(minScalarValue, r, g, b); // Add as many points as needed | ||
|
||
// Set the color transfer function for the mapper | ||
mapper->SetLookupTable(colorTransferFunction); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: VTK 官方examples记录,及优秀VTK blog列表 | ||
date: 2023-05-24 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 | ||
categories: [VTK] | ||
tags: [VTK] # TAG names should always be lowercase | ||
|
||
# 以下默认false | ||
math: true | ||
mermaid: true | ||
# pin: true | ||
--- | ||
|
||
# VTK 官方examples记录,及优秀VTK blog列表 | ||
|
||
## 概览列表 | ||
|
||
关于CXX的示例说明,在官方examples代码的相关README里面有简单介绍,路径:src/Cxx.md | ||
|
||
* github `HDF5` & `TDR`代码 [JosefWeinbub](https://github.com/JosefWeinbub?tab=stars) | ||
* C++示例代码列表 [Cxx](https://examples.vtk.org/site/Cxx/) | ||
* 演示`vtkUnstructureGrid`及mesh显示(`EdgeVisibilityOn`) [UGrid](https://examples.vtk.org/site/Cxx/UnstructuredGrid/UGrid/) | ||
|
||
## Color a mesh by dotting a vector from the origin to each point with a specified vector | ||
* [SimpleElevationFilter](https://examples.vtk.org/site/Cxx/Meshes/SimpleElevationFilter/) | ||
|
||
## Vector field -- 显示矢量场箭头 | ||
* [VectorField](https://examples.vtk.org/site/Cxx/Visualization/VectorField/) | ||
* [VectorFieldNonZeroExtraction](https://examples.vtk.org/site/Cxx/Filtering/VectorFieldNonZeroExtraction/) | ||
|
||
## VTK blog | ||
* [VTK入门范例2](https://www.michaelapp.com/posts/2019/2019-03-20-VTK%E5%85%A5%E9%97%A8%E8%8C%83%E4%BE%8B2/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: VTK 笔记 | ||
date: 2023-07-09 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 | ||
categories: [VTK] | ||
tags: [VTK] # TAG names should always be lowercase | ||
|
||
# 以下默认false | ||
math: true | ||
mermaid: true | ||
# pin: true | ||
--- | ||
|
||
# VTK 笔记 | ||
|
||
## vtkUnstructuredGrid 添加数据 | ||
|
||
* SetScalar、Vector = AddArray + SetActiveScalar\Vector 类似问题,看源码,不同的filter会取不同的activeAttribute,具体设置哪个active还是取决于filter | ||
* setActive 不是2选一的关系 |