evo-data-converters-vtk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evo_data_converters_vtk-0.1.0/LICENSE.md +190 -0
- evo_data_converters_vtk-0.1.0/PKG-INFO +78 -0
- evo_data_converters_vtk-0.1.0/README.md +66 -0
- evo_data_converters_vtk-0.1.0/pyproject.toml +31 -0
- evo_data_converters_vtk-0.1.0/setup.cfg +4 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/__init__.py +10 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/__init__.py +14 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/_utils.py +65 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/exceptions.py +29 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_attributes_to_evo.py +187 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_image_data_to_evo.py +83 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_rectilinear_grid_to_evo.py +70 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_to_evo.py +151 -0
- evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_unstructured_grid_to_evo.py +188 -0
- evo_data_converters_vtk-0.1.0/src/evo_data_converters_vtk.egg-info/PKG-INFO +78 -0
- evo_data_converters_vtk-0.1.0/src/evo_data_converters_vtk.egg-info/SOURCES.txt +17 -0
- evo_data_converters_vtk-0.1.0/src/evo_data_converters_vtk.egg-info/dependency_links.txt +1 -0
- evo_data_converters_vtk-0.1.0/src/evo_data_converters_vtk.egg-info/requires.txt +2 -0
- evo_data_converters_vtk-0.1.0/src/evo_data_converters_vtk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
24
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
25
|
+
|
|
26
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
27
|
+
the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
30
|
+
other entities that control, are controlled by, or are under common
|
|
31
|
+
control with that entity. For the purposes of this definition,
|
|
32
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
33
|
+
direction or management of such entity, whether by contract or
|
|
34
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
35
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
36
|
+
|
|
37
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
38
|
+
exercising permissions granted by this License.
|
|
39
|
+
|
|
40
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
41
|
+
including but not limited to software source code, documentation
|
|
42
|
+
source, and configuration files.
|
|
43
|
+
|
|
44
|
+
"Object" form shall mean any form resulting from mechanical
|
|
45
|
+
transformation or translation of a Source form, including but
|
|
46
|
+
not limited to compiled object code, generated documentation,
|
|
47
|
+
and conversions to other media types.
|
|
48
|
+
|
|
49
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
50
|
+
Object form, made available under the License, as indicated by a
|
|
51
|
+
copyright notice that is included in or attached to the work
|
|
52
|
+
(an example is provided in the Appendix below).
|
|
53
|
+
|
|
54
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
55
|
+
form, that is based on (or derived from) the Work and for which the
|
|
56
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
57
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
+
of this License, Derivative Works shall not include works that remain
|
|
59
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
+
the Work and Derivative Works thereof.
|
|
61
|
+
|
|
62
|
+
"Contribution" shall mean any work of authorship, including
|
|
63
|
+
the original version of the Work and any modifications or additions
|
|
64
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
65
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
66
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
67
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
+
means any form of electronic, verbal, or written communication sent
|
|
69
|
+
to the Licensor or its representatives, including but not limited to
|
|
70
|
+
communication on electronic mailing lists, source code control systems,
|
|
71
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
+
excluding communication that is conspicuously marked or otherwise
|
|
74
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
+
|
|
76
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
+
subsequently incorporated within the Work.
|
|
79
|
+
|
|
80
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
+
Work and such Derivative Works in Source or Object form.
|
|
86
|
+
|
|
87
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
+
(except as stated in this section) patent license to make, have made,
|
|
91
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
+
where such license applies only to those patent claims licensable
|
|
93
|
+
by such Contributor that are necessarily infringed by their
|
|
94
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
95
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
96
|
+
institute patent litigation against any entity (including a
|
|
97
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
98
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
99
|
+
or contributory patent infringement, then any patent licenses
|
|
100
|
+
granted to You under this License for that Work shall terminate
|
|
101
|
+
as of the date such litigation is filed.
|
|
102
|
+
|
|
103
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
104
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
105
|
+
modifications, and in Source or Object form, provided that You
|
|
106
|
+
meet the following conditions:
|
|
107
|
+
|
|
108
|
+
(a) You must give any other recipients of the Work or
|
|
109
|
+
Derivative Works a copy of this License; and
|
|
110
|
+
|
|
111
|
+
(b) You must cause any modified files to carry prominent notices
|
|
112
|
+
stating that You changed the files; and
|
|
113
|
+
|
|
114
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
115
|
+
that You distribute, all copyright, patent, trademark, and
|
|
116
|
+
attribution notices from the Source form of the Work,
|
|
117
|
+
excluding those notices that do not pertain to any part of
|
|
118
|
+
the Derivative Works; and
|
|
119
|
+
|
|
120
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
121
|
+
distribution, then any Derivative Works that You distribute must
|
|
122
|
+
include a readable copy of the attribution notices contained
|
|
123
|
+
within such NOTICE file, excluding those notices that do not
|
|
124
|
+
pertain to any part of the Derivative Works, in at least one
|
|
125
|
+
of the following places: within a NOTICE text file distributed
|
|
126
|
+
as part of the Derivative Works; within the Source form or
|
|
127
|
+
documentation, if provided along with the Derivative Works; or,
|
|
128
|
+
within a display generated by the Derivative Works, if and
|
|
129
|
+
wherever such third-party notices normally appear. The contents
|
|
130
|
+
of the NOTICE file are for informational purposes only and
|
|
131
|
+
do not modify the License. You may add Your own attribution
|
|
132
|
+
notices within Derivative Works that You distribute, alongside
|
|
133
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
134
|
+
that such additional attribution notices cannot be construed
|
|
135
|
+
as modifying the License.
|
|
136
|
+
|
|
137
|
+
You may add Your own copyright statement to Your modifications and
|
|
138
|
+
may provide additional or different license terms and conditions
|
|
139
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
140
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
141
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
142
|
+
the conditions stated in this License.
|
|
143
|
+
|
|
144
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
145
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
146
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
147
|
+
this License, without any additional terms or conditions.
|
|
148
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
149
|
+
the terms of any separate license agreement you may have executed
|
|
150
|
+
with Licensor regarding such Contributions.
|
|
151
|
+
|
|
152
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
153
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
154
|
+
except as required for reasonable and customary use in describing the
|
|
155
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
156
|
+
|
|
157
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
158
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
159
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
160
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
161
|
+
implied, including, without limitation, any warranties or conditions
|
|
162
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
163
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
164
|
+
appropriateness of using or redistributing the Work and assume any
|
|
165
|
+
risks associated with Your exercise of permissions under this License.
|
|
166
|
+
|
|
167
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
168
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
169
|
+
unless required by applicable law (such as deliberate and grossly
|
|
170
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
171
|
+
liable to You for damages, including any direct, indirect, special,
|
|
172
|
+
incidental, or consequential damages of any character arising as a
|
|
173
|
+
result of this License or out of the use or inability to use the
|
|
174
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
175
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
176
|
+
other commercial damages or losses), even if such Contributor
|
|
177
|
+
has been advised of the possibility of such damages.
|
|
178
|
+
|
|
179
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
180
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
181
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
182
|
+
or other liability obligations and/or rights consistent with this
|
|
183
|
+
License. However, in accepting such obligations, You may act only
|
|
184
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
185
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
186
|
+
defend, and hold each Contributor harmless for any liability
|
|
187
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
188
|
+
of your accepting any such warranty or additional liability.
|
|
189
|
+
|
|
190
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evo-data-converters-vtk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python data converters for VTK to Evo geoscience objects
|
|
5
|
+
Author-email: Seequent <support@seequent.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE.md
|
|
9
|
+
Requires-Dist: evo-data-converters-common
|
|
10
|
+
Requires-Dist: vtk
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
<p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://pypi.org/project/evo-data-converters-vtk/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-data-converters-vtk" /></a>
|
|
16
|
+
<a href="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml"><img src="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml/badge.svg" alt="" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
|
|
20
|
+
• <a href="https://community.seequent.com/" target="_blank">Seequent Community</a>
|
|
21
|
+
• <a href="https://seequent.com" target="_blank">Seequent website</a>
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
## Evo
|
|
25
|
+
|
|
26
|
+
Evo is a unified platform for geoscience teams. It enables access, connection, computation, and management of subsurface data. This empowers better decision-making, simplified collaboration, and accelerated innovation. Evo is built on open APIs, allowing developers to build custom integrations and applications. Our open schemas, code examples, and SDK are available for the community to use and extend.
|
|
27
|
+
|
|
28
|
+
Evo is powered by Seequent, a Bentley organisation.
|
|
29
|
+
|
|
30
|
+
## Pre-requisites
|
|
31
|
+
|
|
32
|
+
* Python >= 3.10, <= 3.12
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install evo-data-converters-vtk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# VTK
|
|
41
|
+
|
|
42
|
+
The Visualization Toolkit (VTK) is open source software for manipulating and displaying scientific data
|
|
43
|
+
|
|
44
|
+
Refer here for more information: https://vtk.org/
|
|
45
|
+
|
|
46
|
+
To work with VTK files [the `vtk` Python package](https://pypi.org/project/vtk/) is used, which is a Python wrapper around the underlying `vtk` C++ library.
|
|
47
|
+
|
|
48
|
+
The VTK converter currently supports importing the following objects into geoscience objects:
|
|
49
|
+
- `vtkImageData`/`vtkUniformGrid`/`vtkStructuredPoints`
|
|
50
|
+
- Imported as a `regular-3d-grid` object if there are no blank cells
|
|
51
|
+
- Otherwise, imported as a `regular-masked-3d-grid` object
|
|
52
|
+
- `vtkRectilinearGrid`
|
|
53
|
+
- Imported as a `tensor-3d-grid` object
|
|
54
|
+
- `vtkUnstructuredGrid`
|
|
55
|
+
- Imported as an `unstructured-tet-grid` object if all cells are tetrahedrons
|
|
56
|
+
- Imported as an `unstructured-hex-grid` object if all cells are hexahedrons
|
|
57
|
+
- Otherwise, imported as an `unstructured-grid` object
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Code of conduct
|
|
61
|
+
|
|
62
|
+
We rely on an open, friendly, inclusive environment. To help us ensure this remains possible, please familiarise yourself with our [code of conduct.](https://github.com/SeequentEvo/evo-data-converters/blob/main/CODE_OF_CONDUCT.md)
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
Evo data converters are open source and licensed under the [Apache 2.0 license.](./LICENSE.md)
|
|
66
|
+
|
|
67
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
68
|
+
|
|
69
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
70
|
+
You may obtain a copy of the License at
|
|
71
|
+
|
|
72
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
73
|
+
|
|
74
|
+
Unless required by applicable law or agreed to in writing, software
|
|
75
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
76
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
77
|
+
See the License for the specific language governing permissions and
|
|
78
|
+
limitations under the License.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://pypi.org/project/evo-data-converters-vtk/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-data-converters-vtk" /></a>
|
|
4
|
+
<a href="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml"><img src="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml/badge.svg" alt="" /></a>
|
|
5
|
+
</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
|
|
8
|
+
• <a href="https://community.seequent.com/" target="_blank">Seequent Community</a>
|
|
9
|
+
• <a href="https://seequent.com" target="_blank">Seequent website</a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
## Evo
|
|
13
|
+
|
|
14
|
+
Evo is a unified platform for geoscience teams. It enables access, connection, computation, and management of subsurface data. This empowers better decision-making, simplified collaboration, and accelerated innovation. Evo is built on open APIs, allowing developers to build custom integrations and applications. Our open schemas, code examples, and SDK are available for the community to use and extend.
|
|
15
|
+
|
|
16
|
+
Evo is powered by Seequent, a Bentley organisation.
|
|
17
|
+
|
|
18
|
+
## Pre-requisites
|
|
19
|
+
|
|
20
|
+
* Python >= 3.10, <= 3.12
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install evo-data-converters-vtk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
# VTK
|
|
29
|
+
|
|
30
|
+
The Visualization Toolkit (VTK) is open source software for manipulating and displaying scientific data
|
|
31
|
+
|
|
32
|
+
Refer here for more information: https://vtk.org/
|
|
33
|
+
|
|
34
|
+
To work with VTK files [the `vtk` Python package](https://pypi.org/project/vtk/) is used, which is a Python wrapper around the underlying `vtk` C++ library.
|
|
35
|
+
|
|
36
|
+
The VTK converter currently supports importing the following objects into geoscience objects:
|
|
37
|
+
- `vtkImageData`/`vtkUniformGrid`/`vtkStructuredPoints`
|
|
38
|
+
- Imported as a `regular-3d-grid` object if there are no blank cells
|
|
39
|
+
- Otherwise, imported as a `regular-masked-3d-grid` object
|
|
40
|
+
- `vtkRectilinearGrid`
|
|
41
|
+
- Imported as a `tensor-3d-grid` object
|
|
42
|
+
- `vtkUnstructuredGrid`
|
|
43
|
+
- Imported as an `unstructured-tet-grid` object if all cells are tetrahedrons
|
|
44
|
+
- Imported as an `unstructured-hex-grid` object if all cells are hexahedrons
|
|
45
|
+
- Otherwise, imported as an `unstructured-grid` object
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Code of conduct
|
|
49
|
+
|
|
50
|
+
We rely on an open, friendly, inclusive environment. To help us ensure this remains possible, please familiarise yourself with our [code of conduct.](https://github.com/SeequentEvo/evo-data-converters/blob/main/CODE_OF_CONDUCT.md)
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
Evo data converters are open source and licensed under the [Apache 2.0 license.](./LICENSE.md)
|
|
54
|
+
|
|
55
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
56
|
+
|
|
57
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
58
|
+
You may obtain a copy of the License at
|
|
59
|
+
|
|
60
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
61
|
+
|
|
62
|
+
Unless required by applicable law or agreed to in writing, software
|
|
63
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
64
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
65
|
+
See the License for the specific language governing permissions and
|
|
66
|
+
limitations under the License.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 61.0.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "evo-data-converters-vtk"
|
|
7
|
+
description = "Python data converters for VTK to Evo geoscience objects"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
license-files = ["LICENSE.md"]
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Seequent", email = "support@seequent.com" }
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"evo-data-converters-common",
|
|
17
|
+
"vtk",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = [
|
|
22
|
+
"pytest",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
namespaces = true
|
|
28
|
+
|
|
29
|
+
[tool.ruff]
|
|
30
|
+
src = ["src", "tests"]
|
|
31
|
+
line-length = 120
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from .vtk_to_evo import VTKImportError, convert_vtk
|
|
13
|
+
|
|
14
|
+
__all__ = ["VTKImportError", "convert_vtk"]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import numpy.typing as npt
|
|
14
|
+
import vtk
|
|
15
|
+
from evo_schemas.components import BoundingBox_V1_0_1, Crs_V1_0_1_EpsgCode, Rotation_V1_1_0
|
|
16
|
+
from scipy.spatial.transform import Rotation
|
|
17
|
+
from vtk.util.numpy_support import vtk_to_numpy
|
|
18
|
+
|
|
19
|
+
from evo.data_converters.common.utils import convert_rotation
|
|
20
|
+
|
|
21
|
+
from .exceptions import GhostValueError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_bounding_box(grid: vtk.vtkDataSet) -> BoundingBox_V1_0_1:
|
|
25
|
+
min_x, max_x, min_y, max_y, min_z, max_z = grid.GetBounds()
|
|
26
|
+
return BoundingBox_V1_0_1(min_x=min_x, max_x=max_x, min_y=min_y, max_y=max_y, min_z=min_z, max_z=max_z)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_rotation(vtk_matrix: vtk.vtkMatrix3x3) -> Rotation_V1_1_0:
|
|
30
|
+
matrix = [[vtk_matrix.GetElement(i, j) for j in range(3)] for i in range(3)]
|
|
31
|
+
rot = Rotation.from_matrix(matrix)
|
|
32
|
+
return convert_rotation(rot)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def check_for_ghosts(dataset: vtk.vtkDataSet) -> npt.NDArray[np.bool_] | None:
|
|
36
|
+
# Ghost cells/points, are used for parallel processing, to indicate that cells/points are not in this chunk,
|
|
37
|
+
# but still exist. If any are present, skip this grid as it's not obvious how to handle them.
|
|
38
|
+
#
|
|
39
|
+
# Blank points, mean the cells around that point are not visible, we aren't handling this case for the
|
|
40
|
+
# time being.
|
|
41
|
+
if dataset.HasAnyBlankPoints():
|
|
42
|
+
raise GhostValueError("Grid with blank points are not supported")
|
|
43
|
+
if dataset.HasAnyGhostPoints():
|
|
44
|
+
raise GhostValueError("Grid with ghost points are not supported")
|
|
45
|
+
if dataset.HasAnyGhostCells():
|
|
46
|
+
raise GhostValueError("Grid with ghost cells are not supported")
|
|
47
|
+
|
|
48
|
+
# Blank cell information is stored in the ghost array
|
|
49
|
+
ghost_array = dataset.GetCellGhostArray()
|
|
50
|
+
if ghost_array is not None:
|
|
51
|
+
ghosts = vtk_to_numpy(ghost_array)
|
|
52
|
+
mask: npt.NDArray[np.bool_] = ghosts == 0 # Only include cells that aren't blank
|
|
53
|
+
return mask
|
|
54
|
+
else:
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def common_fields(name: str, epsg_code: int, dataset: vtk.vtkDataSet) -> dict:
|
|
59
|
+
bounding_box = get_bounding_box(dataset)
|
|
60
|
+
return {
|
|
61
|
+
"name": name,
|
|
62
|
+
"coordinate_reference_system": Crs_V1_0_1_EpsgCode(epsg_code=epsg_code),
|
|
63
|
+
"bounding_box": bounding_box,
|
|
64
|
+
"uuid": None,
|
|
65
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class VTKImportError(Exception):
|
|
14
|
+
"""Exception that is raised if there is an error during the reading of a VTK file."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class VTKConversionError(Exception):
|
|
18
|
+
"""Exception that is raised if there is an error during the conversion of a VTK data object."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class GhostValueError(VTKConversionError):
|
|
22
|
+
"""Exception that is raised if ghost cells or points are detected in the VTK data object.
|
|
23
|
+
|
|
24
|
+
This includes if points are blanked out in the VTK data object.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class UnsupportedCellTypeError(VTKConversionError):
|
|
29
|
+
"""Exception that is raised if an unsupported cell type is detected in the VTK unstructured grid."""
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from typing import cast
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
import numpy.typing as npt
|
|
16
|
+
import pyarrow as pa
|
|
17
|
+
import vtk
|
|
18
|
+
from evo_schemas.components import (
|
|
19
|
+
CategoryAttribute_V1_1_0,
|
|
20
|
+
ContinuousAttribute_V1_1_0,
|
|
21
|
+
IntegerAttribute_V1_1_0,
|
|
22
|
+
NanCategorical_V1_0_1,
|
|
23
|
+
NanContinuous_V1_0_1,
|
|
24
|
+
OneOfAttribute_V1_2_0,
|
|
25
|
+
)
|
|
26
|
+
from evo_schemas.elements import FloatArray1_V1_0_1, IntegerArray1_V1_0_1, LookupTable_V1_0_1
|
|
27
|
+
from vtk.util.numpy_support import vtk_to_numpy
|
|
28
|
+
|
|
29
|
+
import evo.logging
|
|
30
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
31
|
+
|
|
32
|
+
logger = evo.logging.getLogger("data_converters")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _is_float_array(array: vtk.vtkAbstractArray) -> bool:
|
|
36
|
+
return array.GetDataType() in [vtk.VTK_DOUBLE, vtk.VTK_FLOAT]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _is_integer_array(array: vtk.vtkAbstractArray) -> bool:
|
|
40
|
+
return array.GetDataType() in [
|
|
41
|
+
vtk.VTK_SIGNED_CHAR,
|
|
42
|
+
vtk.VTK_UNSIGNED_CHAR,
|
|
43
|
+
vtk.VTK_SHORT,
|
|
44
|
+
vtk.VTK_UNSIGNED_SHORT,
|
|
45
|
+
vtk.VTK_INT,
|
|
46
|
+
vtk.VTK_UNSIGNED_INT,
|
|
47
|
+
vtk.VTK_LONG,
|
|
48
|
+
vtk.VTK_UNSIGNED_LONG,
|
|
49
|
+
vtk.VTK_LONG_LONG,
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _is_string_array(array: vtk.vtkAbstractArray) -> bool:
|
|
54
|
+
# mypy doesn't know that GetDataType() and vtk.VTK_STRING are ints
|
|
55
|
+
return cast(bool, array.GetDataType() == vtk.VTK_STRING)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _create_table(
|
|
59
|
+
values: npt.NDArray,
|
|
60
|
+
mask: npt.NDArray[np.bool_] | None,
|
|
61
|
+
grid_is_filtered: bool,
|
|
62
|
+
dtype: npt.DTypeLike,
|
|
63
|
+
) -> pa.Table:
|
|
64
|
+
if grid_is_filtered and mask is not None:
|
|
65
|
+
values = values[mask]
|
|
66
|
+
mask = None # Don't need to filter the values again
|
|
67
|
+
|
|
68
|
+
values = values.astype(dtype)
|
|
69
|
+
array = pa.array(values, mask=~mask if mask is not None else None)
|
|
70
|
+
return pa.table({"values": array})
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _create_continuous_attribute(
|
|
74
|
+
data_client: ObjectDataClient,
|
|
75
|
+
name: str,
|
|
76
|
+
array: vtk.vtkAbstractArray,
|
|
77
|
+
mask: npt.NDArray[np.bool_] | None,
|
|
78
|
+
grid_is_filtered: bool,
|
|
79
|
+
) -> ContinuousAttribute_V1_1_0:
|
|
80
|
+
values = vtk_to_numpy(array)
|
|
81
|
+
# Convert to float64, as Geoscience Objects only support float64 for continuous attributes
|
|
82
|
+
table = _create_table(values, mask, grid_is_filtered, np.float64)
|
|
83
|
+
return ContinuousAttribute_V1_1_0(
|
|
84
|
+
name=name,
|
|
85
|
+
key=name,
|
|
86
|
+
nan_description=NanContinuous_V1_0_1(values=[]),
|
|
87
|
+
values=FloatArray1_V1_0_1(**data_client.save_table(table)),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _create_integer_attribute(
|
|
92
|
+
data_client: ObjectDataClient,
|
|
93
|
+
name: str,
|
|
94
|
+
array: vtk.vtkAbstractArray,
|
|
95
|
+
mask: npt.NDArray[np.bool_] | None,
|
|
96
|
+
grid_is_filtered: bool,
|
|
97
|
+
) -> IntegerAttribute_V1_1_0:
|
|
98
|
+
values = vtk_to_numpy(array)
|
|
99
|
+
# Convert to int32 or int64
|
|
100
|
+
dtype = np.int64 if values.dtype in [np.uint32, np.int64] else np.int32
|
|
101
|
+
table = _create_table(values, mask, grid_is_filtered, dtype)
|
|
102
|
+
return IntegerAttribute_V1_1_0(
|
|
103
|
+
name=name,
|
|
104
|
+
key=name,
|
|
105
|
+
nan_description=NanCategorical_V1_0_1(values=[]),
|
|
106
|
+
values=IntegerArray1_V1_0_1(**data_client.save_table(table)),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
_numpy_dtype_for_pyarrow_type = {
|
|
111
|
+
pa.int32(): np.int32,
|
|
112
|
+
pa.int64(): np.int64,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _create_categorical_attribute(
|
|
117
|
+
data_client: ObjectDataClient,
|
|
118
|
+
name: str,
|
|
119
|
+
array: vtk.vtkStringArray,
|
|
120
|
+
mask: npt.NDArray[np.bool_] | None,
|
|
121
|
+
grid_is_filtered: bool,
|
|
122
|
+
) -> CategoryAttribute_V1_1_0:
|
|
123
|
+
values = [array.GetValue(i) for i in range(array.GetNumberOfValues())]
|
|
124
|
+
arrow_array = pa.array(values, mask=~mask if mask is not None else None)
|
|
125
|
+
|
|
126
|
+
# Encode the array as a dictionary encoded array
|
|
127
|
+
dict_array = arrow_array.dictionary_encode()
|
|
128
|
+
|
|
129
|
+
indices = dict_array.indices
|
|
130
|
+
if grid_is_filtered and mask is not None:
|
|
131
|
+
indices = indices.filter(mask)
|
|
132
|
+
|
|
133
|
+
# Create a lookup table
|
|
134
|
+
indices_dtype = _numpy_dtype_for_pyarrow_type[indices.type]
|
|
135
|
+
lookup_table = pa.table(
|
|
136
|
+
{"key": np.arange(len(dict_array.dictionary), dtype=indices_dtype), "value": dict_array.dictionary}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
values_table = pa.table({"values": indices})
|
|
140
|
+
return CategoryAttribute_V1_1_0(
|
|
141
|
+
name=name,
|
|
142
|
+
key=name,
|
|
143
|
+
nan_description=NanCategorical_V1_0_1(values=[]),
|
|
144
|
+
table=LookupTable_V1_0_1(**data_client.save_table(lookup_table)),
|
|
145
|
+
values=IntegerArray1_V1_0_1(**data_client.save_table(values_table)),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def convert_attributes(
|
|
150
|
+
vtk_data: vtk.vtkDataSetAttributes,
|
|
151
|
+
data_client: ObjectDataClient,
|
|
152
|
+
mask: npt.NDArray[np.bool_] | None = None,
|
|
153
|
+
grid_is_filtered: bool = False,
|
|
154
|
+
) -> OneOfAttribute_V1_2_0:
|
|
155
|
+
"""
|
|
156
|
+
Convert VTK attributes to Geoscience Objects attributes.
|
|
157
|
+
|
|
158
|
+
:param vtk_data: VTK attributes
|
|
159
|
+
:param data_client: Data client used to save the attribute values
|
|
160
|
+
:param mask: Mask to filter the attribute values
|
|
161
|
+
:param grid_is_filtered: True if the attribute values should be filtered by the mask, otherwise the
|
|
162
|
+
attribute values should be set to null where the mask is False.
|
|
163
|
+
"""
|
|
164
|
+
attributes = []
|
|
165
|
+
|
|
166
|
+
for i in range(vtk_data.GetNumberOfArrays()):
|
|
167
|
+
name = vtk_data.GetArrayName(i)
|
|
168
|
+
if name == "vtkGhostType":
|
|
169
|
+
continue # Skip ghost type attribute, we check for ghost cells elsewhere
|
|
170
|
+
array = vtk_data.GetAbstractArray(i)
|
|
171
|
+
if array.GetNumberOfComponents() > 1:
|
|
172
|
+
logger.warning(f"Attribute {name} has more than one component, skipping this attribute")
|
|
173
|
+
continue
|
|
174
|
+
|
|
175
|
+
if _is_float_array(array):
|
|
176
|
+
attribute = _create_continuous_attribute(data_client, name, array, mask, grid_is_filtered)
|
|
177
|
+
elif _is_integer_array(array):
|
|
178
|
+
attribute = _create_integer_attribute(data_client, name, array, mask, grid_is_filtered)
|
|
179
|
+
elif _is_string_array(array):
|
|
180
|
+
attribute = _create_categorical_attribute(data_client, name, array, mask, grid_is_filtered)
|
|
181
|
+
else:
|
|
182
|
+
logger.warning(
|
|
183
|
+
f"Unsupported data type {array.GetDataTypeAsString()} for attribute {name}, skipping this attribute"
|
|
184
|
+
)
|
|
185
|
+
continue
|
|
186
|
+
attributes.append(attribute)
|
|
187
|
+
return attributes
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
import pyarrow as pa
|
|
13
|
+
import vtk
|
|
14
|
+
from evo_schemas.components import BoolAttribute_V1_1_0
|
|
15
|
+
from evo_schemas.elements import BoolArray1_V1_0_1
|
|
16
|
+
from evo_schemas.objects import Regular3DGrid_V1_2_0, RegularMasked3DGrid_V1_2_0
|
|
17
|
+
|
|
18
|
+
import evo.logging
|
|
19
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
20
|
+
|
|
21
|
+
from ._utils import check_for_ghosts, common_fields, get_rotation
|
|
22
|
+
from .vtk_attributes_to_evo import convert_attributes
|
|
23
|
+
|
|
24
|
+
logger = evo.logging.getLogger("data_converters")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def convert_vtk_image_data(
|
|
28
|
+
name: str,
|
|
29
|
+
image_data: vtk.vtkImageData,
|
|
30
|
+
data_client: ObjectDataClient,
|
|
31
|
+
epsg_code: int,
|
|
32
|
+
) -> Regular3DGrid_V1_2_0 | RegularMasked3DGrid_V1_2_0:
|
|
33
|
+
"""Convert a vtkImageData object to a Regular3DGrid or RegularMasked3DGrid object, depending on whether the
|
|
34
|
+
vtkImageData object has any blanked cells.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
# GetDimensions returns the number of points in each dimension, so we need to subtract 1 to get the number of cells
|
|
38
|
+
dimensions = image_data.GetDimensions()
|
|
39
|
+
dimensions = [dim - 1 for dim in dimensions]
|
|
40
|
+
spacing = image_data.GetSpacing()
|
|
41
|
+
|
|
42
|
+
# VTK supports the origin being offset from the corner of the grid, but Geoscience Objects don't.
|
|
43
|
+
# So, get the location of the corner of grid extent, and use that as the origin.
|
|
44
|
+
i1, _, j1, _, k1, _ = image_data.GetExtent()
|
|
45
|
+
origin = [0.0, 0.0, 0.0]
|
|
46
|
+
image_data.TransformIndexToPhysicalPoint(i1, j1, k1, origin)
|
|
47
|
+
|
|
48
|
+
cell_data = image_data.GetCellData()
|
|
49
|
+
vertex_data = image_data.GetPointData()
|
|
50
|
+
|
|
51
|
+
mask = check_for_ghosts(image_data)
|
|
52
|
+
if mask is not None and not mask.all():
|
|
53
|
+
if vertex_data.GetNumberOfArrays() > 0:
|
|
54
|
+
logger.warning("Blank cells are not supported with point data, skipping the point data")
|
|
55
|
+
|
|
56
|
+
cell_attributes = convert_attributes(cell_data, data_client, mask=mask, grid_is_filtered=True)
|
|
57
|
+
mask_attributes = BoolAttribute_V1_1_0(
|
|
58
|
+
name="mask",
|
|
59
|
+
key="mask",
|
|
60
|
+
values=BoolArray1_V1_0_1(**data_client.save_table(pa.table({"mask": mask}))),
|
|
61
|
+
)
|
|
62
|
+
return RegularMasked3DGrid_V1_2_0(
|
|
63
|
+
**common_fields(name, epsg_code, image_data),
|
|
64
|
+
origin=origin,
|
|
65
|
+
size=list(dimensions),
|
|
66
|
+
cell_size=list(spacing),
|
|
67
|
+
rotation=get_rotation(image_data.GetDirectionMatrix()),
|
|
68
|
+
cell_attributes=cell_attributes,
|
|
69
|
+
mask=mask_attributes,
|
|
70
|
+
number_of_active_cells=int(mask.sum()),
|
|
71
|
+
)
|
|
72
|
+
else:
|
|
73
|
+
cell_attributes = convert_attributes(cell_data, data_client)
|
|
74
|
+
vertex_attributes = convert_attributes(vertex_data, data_client)
|
|
75
|
+
return Regular3DGrid_V1_2_0(
|
|
76
|
+
**common_fields(name, epsg_code, image_data),
|
|
77
|
+
origin=origin,
|
|
78
|
+
size=list(dimensions),
|
|
79
|
+
cell_size=list(spacing),
|
|
80
|
+
rotation=get_rotation(image_data.GetDirectionMatrix()),
|
|
81
|
+
cell_attributes=cell_attributes,
|
|
82
|
+
vertex_attributes=vertex_attributes,
|
|
83
|
+
)
|
evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_rectilinear_grid_to_evo.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import vtk
|
|
14
|
+
from evo_schemas.components import Rotation_V1_1_0
|
|
15
|
+
from evo_schemas.objects import Tensor3DGrid_V1_2_0, Tensor3DGrid_V1_2_0_GridCells3D
|
|
16
|
+
from vtk.util.numpy_support import vtk_to_numpy
|
|
17
|
+
|
|
18
|
+
import evo.logging
|
|
19
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
20
|
+
|
|
21
|
+
from ._utils import check_for_ghosts, common_fields
|
|
22
|
+
from .vtk_attributes_to_evo import convert_attributes
|
|
23
|
+
|
|
24
|
+
logger = evo.logging.getLogger("data_converters")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def convert_vtk_rectilinear_grid(
|
|
28
|
+
name: str,
|
|
29
|
+
rectilinear_grid: vtk.vtkRectilinearGrid,
|
|
30
|
+
data_client: ObjectDataClient,
|
|
31
|
+
epsg_code: int,
|
|
32
|
+
) -> Tensor3DGrid_V1_2_0:
|
|
33
|
+
# GetDimensions returns the number of points in each dimension, so we need to subtract 1 to get the number of cells
|
|
34
|
+
dimensions = rectilinear_grid.GetDimensions()
|
|
35
|
+
dimensions = [dim - 1 for dim in dimensions]
|
|
36
|
+
|
|
37
|
+
x_coords = vtk_to_numpy(rectilinear_grid.GetXCoordinates())
|
|
38
|
+
y_coords = vtk_to_numpy(rectilinear_grid.GetYCoordinates())
|
|
39
|
+
z_coords = vtk_to_numpy(rectilinear_grid.GetZCoordinates())
|
|
40
|
+
|
|
41
|
+
origin = [x_coords[0], y_coords[0], z_coords[0]]
|
|
42
|
+
x_spacings = np.diff(x_coords)
|
|
43
|
+
y_spacings = np.diff(y_coords)
|
|
44
|
+
z_spacings = np.diff(z_coords)
|
|
45
|
+
|
|
46
|
+
cell_data = rectilinear_grid.GetCellData()
|
|
47
|
+
vertex_data = rectilinear_grid.GetPointData()
|
|
48
|
+
|
|
49
|
+
mask = check_for_ghosts(rectilinear_grid)
|
|
50
|
+
cell_attributes = convert_attributes(cell_data, data_client, mask)
|
|
51
|
+
if mask is not None and not mask.all():
|
|
52
|
+
if vertex_data.GetNumberOfArrays() > 0:
|
|
53
|
+
logger.warning("Blank cells are not supported with point data, skipping the point data")
|
|
54
|
+
vertex_attributes = []
|
|
55
|
+
else:
|
|
56
|
+
vertex_attributes = convert_attributes(vertex_data, data_client)
|
|
57
|
+
|
|
58
|
+
return Tensor3DGrid_V1_2_0(
|
|
59
|
+
**common_fields(name, epsg_code, rectilinear_grid),
|
|
60
|
+
origin=origin,
|
|
61
|
+
size=list(dimensions),
|
|
62
|
+
grid_cells_3d=Tensor3DGrid_V1_2_0_GridCells3D(
|
|
63
|
+
cell_sizes_x=list(x_spacings),
|
|
64
|
+
cell_sizes_y=list(y_spacings),
|
|
65
|
+
cell_sizes_z=list(z_spacings),
|
|
66
|
+
),
|
|
67
|
+
rotation=Rotation_V1_1_0(dip_azimuth=0.0, dip=0.0, pitch=0.0), # Rectilinear grids don't have rotation
|
|
68
|
+
cell_attributes=cell_attributes,
|
|
69
|
+
vertex_attributes=vertex_attributes,
|
|
70
|
+
)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import TYPE_CHECKING, Callable, Generator, Optional, TypeAlias
|
|
15
|
+
|
|
16
|
+
import vtk
|
|
17
|
+
from evo_schemas.components import BaseSpatialDataProperties_V1_0_1
|
|
18
|
+
from vtk.util.data_model import ImageData, RectilinearGrid, UnstructuredGrid # Override classes from vtk
|
|
19
|
+
|
|
20
|
+
import evo.logging
|
|
21
|
+
from evo.data_converters.common import (
|
|
22
|
+
EvoWorkspaceMetadata,
|
|
23
|
+
create_evo_object_service_and_data_client,
|
|
24
|
+
publish_geoscience_objects,
|
|
25
|
+
)
|
|
26
|
+
from evo.objects.data import ObjectMetadata
|
|
27
|
+
from evo.objects.utils import ObjectDataClient
|
|
28
|
+
|
|
29
|
+
from .exceptions import VTKConversionError, VTKImportError
|
|
30
|
+
from .vtk_image_data_to_evo import convert_vtk_image_data
|
|
31
|
+
from .vtk_rectilinear_grid_to_evo import convert_vtk_rectilinear_grid
|
|
32
|
+
from .vtk_unstructured_grid_to_evo import convert_vtk_unstructured_grid
|
|
33
|
+
|
|
34
|
+
logger = evo.logging.getLogger("data_converters")
|
|
35
|
+
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
from evo.notebooks import ServiceManagerWidget
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _get_leaf_objects(data_object: vtk.vtkDataSet, name: str) -> Generator[tuple[str, vtk.vtkDataObject], None, None]:
|
|
41
|
+
if isinstance(data_object, vtk.vtkMultiBlockDataSet):
|
|
42
|
+
for i in range(data_object.GetNumberOfBlocks()):
|
|
43
|
+
child_name = data_object.GetMetaData(i).Get(vtk.vtkCompositeDataSet.NAME())
|
|
44
|
+
if child_name is None:
|
|
45
|
+
child_name = f"{name}_{i}"
|
|
46
|
+
yield from _get_leaf_objects(data_object.GetBlock(i), child_name)
|
|
47
|
+
else:
|
|
48
|
+
yield name, data_object
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _get_data_objects(filepath: str) -> list[tuple[str, vtk.vtkDataObject]]:
|
|
52
|
+
xml_reader = vtk.vtkXMLGenericDataObjectReader()
|
|
53
|
+
xml_reader.SetFileName(filepath)
|
|
54
|
+
xml_reader.Update()
|
|
55
|
+
data_object = xml_reader.GetOutput()
|
|
56
|
+
if not data_object:
|
|
57
|
+
raise VTKImportError(f"Failed to read data object from {filepath}")
|
|
58
|
+
return list(_get_leaf_objects(data_object, Path(filepath).stem))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
ConverterFunction: TypeAlias = Callable[
|
|
62
|
+
[str, vtk.vtkDataObject, ObjectDataClient, int], BaseSpatialDataProperties_V1_0_1
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
_convert_functions: dict[type[vtk.vtkDataObject], ConverterFunction] = {
|
|
66
|
+
vtk.vtkImageData: convert_vtk_image_data,
|
|
67
|
+
ImageData: convert_vtk_image_data,
|
|
68
|
+
vtk.vtkUniformGrid: convert_vtk_image_data,
|
|
69
|
+
vtk.vtkStructuredPoints: convert_vtk_image_data,
|
|
70
|
+
vtk.vtkRectilinearGrid: convert_vtk_rectilinear_grid,
|
|
71
|
+
RectilinearGrid: convert_vtk_rectilinear_grid,
|
|
72
|
+
vtk.vtkUnstructuredGrid: convert_vtk_unstructured_grid,
|
|
73
|
+
UnstructuredGrid: convert_vtk_unstructured_grid,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def convert_vtk(
|
|
78
|
+
filepath: str,
|
|
79
|
+
epsg_code: int,
|
|
80
|
+
evo_workspace_metadata: Optional[EvoWorkspaceMetadata] = None,
|
|
81
|
+
service_manager_widget: Optional["ServiceManagerWidget"] = None,
|
|
82
|
+
tags: Optional[dict[str, str]] = None,
|
|
83
|
+
upload_path: str = "",
|
|
84
|
+
) -> list[BaseSpatialDataProperties_V1_0_1 | ObjectMetadata]:
|
|
85
|
+
"""Converts an VTK file into Geoscience Objects.
|
|
86
|
+
|
|
87
|
+
:param filepath: Path to the VTK file.
|
|
88
|
+
:param epsg_code: The EPSG code to use when creating a Coordinate Reference System object.
|
|
89
|
+
:param evo_workspace_metadata: (Optional) Evo workspace metadata.
|
|
90
|
+
:param service_manager_widget: (Optional) Service Manager Widget for use in jupyter notebooks.
|
|
91
|
+
:param tags: (Optional) Dict of tags to add to the Geoscience Object(s).
|
|
92
|
+
:param upload_path: (Optional) Path objects will be published under.
|
|
93
|
+
|
|
94
|
+
One of evo_workspace_metadata or service_manager_widget is required.
|
|
95
|
+
|
|
96
|
+
Converted objects will be published if either of the following is true:
|
|
97
|
+
- evo_workspace_metadata.hub_url is present, or
|
|
98
|
+
- service_manager_widget was passed to this function.
|
|
99
|
+
|
|
100
|
+
Caveats:
|
|
101
|
+
- Only supports XML VTK files
|
|
102
|
+
|
|
103
|
+
:return: List of Geoscience Objects, or list of ObjectMetadata if published.
|
|
104
|
+
|
|
105
|
+
:raise MissingConnectionDetailsError: If no connections details could be derived.
|
|
106
|
+
:raise ConflictingConnectionDetailsError: If both evo_workspace_metadata and service_manager_widget present.
|
|
107
|
+
:raise VTKImportError: If the VTK file could not be read.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
publish_objects = True
|
|
111
|
+
geoscience_objects = []
|
|
112
|
+
|
|
113
|
+
object_service_client, data_client = create_evo_object_service_and_data_client(
|
|
114
|
+
evo_workspace_metadata=evo_workspace_metadata, service_manager_widget=service_manager_widget
|
|
115
|
+
)
|
|
116
|
+
if evo_workspace_metadata and not evo_workspace_metadata.hub_url:
|
|
117
|
+
logger.debug("Publishing objects will be skipped due to missing hub_url.")
|
|
118
|
+
publish_objects = False
|
|
119
|
+
|
|
120
|
+
data_objects = _get_data_objects(filepath)
|
|
121
|
+
for name, data_object in data_objects:
|
|
122
|
+
try:
|
|
123
|
+
convert_function = _convert_functions.get(type(data_object))
|
|
124
|
+
if convert_function is None:
|
|
125
|
+
logger.warning(f"{type(data_object).__name__} data object are not supported.")
|
|
126
|
+
continue
|
|
127
|
+
geoscience_object = convert_function(name, data_object, data_client, epsg_code)
|
|
128
|
+
except VTKConversionError as e:
|
|
129
|
+
logger.warning(f"{e}, skipping this grid")
|
|
130
|
+
continue
|
|
131
|
+
|
|
132
|
+
if geoscience_object.tags is None:
|
|
133
|
+
geoscience_object.tags = {}
|
|
134
|
+
geoscience_object.tags["Source"] = f"{os.path.basename(filepath)} (via Evo Data Converters)"
|
|
135
|
+
geoscience_object.tags["Stage"] = "Experimental"
|
|
136
|
+
geoscience_object.tags["InputType"] = "VTK"
|
|
137
|
+
|
|
138
|
+
# Add custom tags
|
|
139
|
+
if tags:
|
|
140
|
+
geoscience_object.tags.update(tags)
|
|
141
|
+
|
|
142
|
+
geoscience_objects.append(geoscience_object)
|
|
143
|
+
|
|
144
|
+
objects_metadata = None
|
|
145
|
+
if publish_objects:
|
|
146
|
+
logger.debug("Publishing Geoscience Objects")
|
|
147
|
+
objects_metadata = publish_geoscience_objects(
|
|
148
|
+
geoscience_objects, object_service_client, data_client, upload_path
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
return objects_metadata if objects_metadata else geoscience_objects
|
evo_data_converters_vtk-0.1.0/src/evo/data_converters/vtk/importer/vtk_unstructured_grid_to_evo.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import pyarrow as pa
|
|
14
|
+
import vtk
|
|
15
|
+
from evo_schemas.components import (
|
|
16
|
+
Hexahedrons_V1_2_0,
|
|
17
|
+
Hexahedrons_V1_2_0_Indices,
|
|
18
|
+
Hexahedrons_V1_2_0_Vertices,
|
|
19
|
+
OneOfAttribute_V1_2_0,
|
|
20
|
+
Tetrahedra_V1_2_0,
|
|
21
|
+
Tetrahedra_V1_2_0_Indices,
|
|
22
|
+
Tetrahedra_V1_2_0_Vertices,
|
|
23
|
+
UnstructuredGridGeometry_V1_2_0,
|
|
24
|
+
UnstructuredGridGeometry_V1_2_0_Cells,
|
|
25
|
+
UnstructuredGridGeometry_V1_2_0_Vertices,
|
|
26
|
+
)
|
|
27
|
+
from evo_schemas.elements import IndexArray1_V1_0_1
|
|
28
|
+
from evo_schemas.objects import (
|
|
29
|
+
UnstructuredGrid_V1_2_0,
|
|
30
|
+
UnstructuredHexGrid_V1_2_0,
|
|
31
|
+
UnstructuredTetGrid_V1_2_0,
|
|
32
|
+
)
|
|
33
|
+
from vtk.util.numpy_support import vtk_to_numpy
|
|
34
|
+
|
|
35
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
36
|
+
|
|
37
|
+
from ._utils import check_for_ghosts, common_fields
|
|
38
|
+
from .exceptions import UnsupportedCellTypeError
|
|
39
|
+
from .vtk_attributes_to_evo import convert_attributes
|
|
40
|
+
|
|
41
|
+
_shape_mapping = {
|
|
42
|
+
vtk.VTK_VERTEX: 0,
|
|
43
|
+
vtk.VTK_LINE: 1,
|
|
44
|
+
vtk.VTK_TRIANGLE: 2,
|
|
45
|
+
vtk.VTK_QUAD: 3,
|
|
46
|
+
vtk.VTK_TETRA: 4,
|
|
47
|
+
vtk.VTK_HEXAHEDRON: 5,
|
|
48
|
+
vtk.VTK_WEDGE: 6,
|
|
49
|
+
vtk.VTK_PYRAMID: 7,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _create_indices_table(unstructured_grid: vtk.vtkUnstructuredGrid, n_vertices: int) -> pa.Table:
|
|
54
|
+
connectivity = vtk_to_numpy(unstructured_grid.GetCells().GetConnectivityArray())
|
|
55
|
+
connectivity = connectivity.astype("uint64")
|
|
56
|
+
offsets = vtk_to_numpy(unstructured_grid.GetCells().GetOffsetsArray())
|
|
57
|
+
offsets = offsets[:-1] # Last offset is the total number of indices
|
|
58
|
+
indices_tables = pa.table({f"n{i}": connectivity[offsets + i] for i in range(n_vertices)})
|
|
59
|
+
return indices_tables
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _create_tetrahedron_grid(
|
|
63
|
+
name: str,
|
|
64
|
+
epsg_code: int,
|
|
65
|
+
unstructured_grid: vtk.vtkUnstructuredGrid,
|
|
66
|
+
data_client: ObjectDataClient,
|
|
67
|
+
vertex_attributes: OneOfAttribute_V1_2_0,
|
|
68
|
+
points_table: pa.Table,
|
|
69
|
+
cell_attributes: OneOfAttribute_V1_2_0,
|
|
70
|
+
) -> UnstructuredTetGrid_V1_2_0:
|
|
71
|
+
indices_tables = _create_indices_table(unstructured_grid, 4)
|
|
72
|
+
return UnstructuredTetGrid_V1_2_0(
|
|
73
|
+
**common_fields(name, epsg_code, unstructured_grid),
|
|
74
|
+
tetrahedra=Tetrahedra_V1_2_0(
|
|
75
|
+
vertices=Tetrahedra_V1_2_0_Vertices(
|
|
76
|
+
attributes=vertex_attributes,
|
|
77
|
+
**data_client.save_table(points_table),
|
|
78
|
+
),
|
|
79
|
+
indices=Tetrahedra_V1_2_0_Indices(
|
|
80
|
+
attributes=cell_attributes,
|
|
81
|
+
**data_client.save_table(indices_tables),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _create_hexahedron_grid(
|
|
88
|
+
name: str,
|
|
89
|
+
epsg_code: int,
|
|
90
|
+
unstructured_grid: vtk.vtkUnstructuredGrid,
|
|
91
|
+
data_client: ObjectDataClient,
|
|
92
|
+
vertex_attributes: OneOfAttribute_V1_2_0,
|
|
93
|
+
points_table: pa.Table,
|
|
94
|
+
cell_attributes: OneOfAttribute_V1_2_0,
|
|
95
|
+
) -> UnstructuredHexGrid_V1_2_0:
|
|
96
|
+
indices_tables = _create_indices_table(unstructured_grid, 8)
|
|
97
|
+
return UnstructuredHexGrid_V1_2_0(
|
|
98
|
+
**common_fields(name, epsg_code, unstructured_grid),
|
|
99
|
+
hexahedrons=Hexahedrons_V1_2_0(
|
|
100
|
+
vertices=Hexahedrons_V1_2_0_Vertices(
|
|
101
|
+
attributes=vertex_attributes,
|
|
102
|
+
**data_client.save_table(points_table),
|
|
103
|
+
),
|
|
104
|
+
indices=Hexahedrons_V1_2_0_Indices(attributes=cell_attributes, **data_client.save_table(indices_tables)),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _create_generic_unstructured_grid(
|
|
110
|
+
name: str,
|
|
111
|
+
epsg_code: int,
|
|
112
|
+
unstructured_grid: vtk.vtkUnstructuredGrid,
|
|
113
|
+
data_client: ObjectDataClient,
|
|
114
|
+
vertex_attributes: OneOfAttribute_V1_2_0,
|
|
115
|
+
points_table: pa.Table,
|
|
116
|
+
cell_attributes: OneOfAttribute_V1_2_0,
|
|
117
|
+
vtk_shapes: np.ndarray,
|
|
118
|
+
) -> UnstructuredGrid_V1_2_0:
|
|
119
|
+
# Convert shape numbering from VTK to Geocience Object convention
|
|
120
|
+
go_shapes = np.zeros(vtk_shapes.shape, dtype="int32")
|
|
121
|
+
for vtk_shape_number, go_shape_number in _shape_mapping.items():
|
|
122
|
+
go_shapes[vtk_shapes == vtk_shape_number] = go_shape_number
|
|
123
|
+
|
|
124
|
+
offsets = vtk_to_numpy(unstructured_grid.GetCells().GetOffsetsArray())
|
|
125
|
+
cell_table = pa.table(
|
|
126
|
+
{
|
|
127
|
+
"shape": go_shapes,
|
|
128
|
+
"offset": offsets[:-1].astype("uint64"),
|
|
129
|
+
"n_vertices": np.diff(offsets).astype("int32"),
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
index_array = vtk_to_numpy(unstructured_grid.GetCells().GetConnectivityArray())
|
|
134
|
+
index_table = pa.table({"index": index_array.astype("uint64")})
|
|
135
|
+
return UnstructuredGrid_V1_2_0(
|
|
136
|
+
**common_fields(name, epsg_code, unstructured_grid),
|
|
137
|
+
geometry=UnstructuredGridGeometry_V1_2_0(
|
|
138
|
+
vertices=UnstructuredGridGeometry_V1_2_0_Vertices(
|
|
139
|
+
attributes=vertex_attributes, **data_client.save_table(points_table)
|
|
140
|
+
),
|
|
141
|
+
cells=UnstructuredGridGeometry_V1_2_0_Cells(
|
|
142
|
+
attributes=cell_attributes, **data_client.save_table(cell_table)
|
|
143
|
+
),
|
|
144
|
+
indices=IndexArray1_V1_0_1(**data_client.save_table(index_table)),
|
|
145
|
+
),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def convert_vtk_unstructured_grid(
|
|
150
|
+
name: str,
|
|
151
|
+
unstructured_grid: vtk.vtkUnstructuredGrid,
|
|
152
|
+
data_client: ObjectDataClient,
|
|
153
|
+
epsg_code: int,
|
|
154
|
+
) -> UnstructuredGrid_V1_2_0 | UnstructuredHexGrid_V1_2_0 | UnstructuredTetGrid_V1_2_0:
|
|
155
|
+
# Unstructured grids don't support blank cells/points, so no mask should be returned here.
|
|
156
|
+
_ = check_for_ghosts(unstructured_grid)
|
|
157
|
+
|
|
158
|
+
vertex_data = unstructured_grid.GetPointData()
|
|
159
|
+
points = vtk_to_numpy(unstructured_grid.GetPoints().GetData())
|
|
160
|
+
points = points.astype("float64")
|
|
161
|
+
points_table = pa.table({"x": points[:, 0], "y": points[:, 1], "z": points[:, 2]})
|
|
162
|
+
vertex_attributes = convert_attributes(vertex_data, data_client)
|
|
163
|
+
|
|
164
|
+
cell_data = unstructured_grid.GetCellData()
|
|
165
|
+
vtk_shapes = vtk_to_numpy(unstructured_grid.GetCellTypesArray())
|
|
166
|
+
cell_attributes = convert_attributes(cell_data, data_client)
|
|
167
|
+
|
|
168
|
+
shape_set = set(np.unique(vtk_shapes))
|
|
169
|
+
if not shape_set.issubset(_shape_mapping.keys()):
|
|
170
|
+
raise UnsupportedCellTypeError("Unsupported cell types found in the unstructured grid")
|
|
171
|
+
|
|
172
|
+
# Check whether the grid contains only hexahedron or tetrahedron cells, if so, create the specific grid type
|
|
173
|
+
if len(shape_set) == 1:
|
|
174
|
+
single_shape = next(iter(shape_set))
|
|
175
|
+
match single_shape:
|
|
176
|
+
case vtk.VTK_TETRA:
|
|
177
|
+
return _create_tetrahedron_grid(
|
|
178
|
+
name, epsg_code, unstructured_grid, data_client, vertex_attributes, points_table, cell_attributes
|
|
179
|
+
)
|
|
180
|
+
case vtk.VTK_HEXAHEDRON:
|
|
181
|
+
return _create_hexahedron_grid(
|
|
182
|
+
name, epsg_code, unstructured_grid, data_client, vertex_attributes, points_table, cell_attributes
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Otherwise, create a generic unstructured grid, which can contain multiple cell types
|
|
186
|
+
return _create_generic_unstructured_grid(
|
|
187
|
+
name, epsg_code, unstructured_grid, data_client, vertex_attributes, points_table, cell_attributes, vtk_shapes
|
|
188
|
+
)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evo-data-converters-vtk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python data converters for VTK to Evo geoscience objects
|
|
5
|
+
Author-email: Seequent <support@seequent.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE.md
|
|
9
|
+
Requires-Dist: evo-data-converters-common
|
|
10
|
+
Requires-Dist: vtk
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
<p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://pypi.org/project/evo-data-converters-vtk/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-data-converters-vtk" /></a>
|
|
16
|
+
<a href="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml"><img src="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml/badge.svg" alt="" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
|
|
20
|
+
• <a href="https://community.seequent.com/" target="_blank">Seequent Community</a>
|
|
21
|
+
• <a href="https://seequent.com" target="_blank">Seequent website</a>
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
## Evo
|
|
25
|
+
|
|
26
|
+
Evo is a unified platform for geoscience teams. It enables access, connection, computation, and management of subsurface data. This empowers better decision-making, simplified collaboration, and accelerated innovation. Evo is built on open APIs, allowing developers to build custom integrations and applications. Our open schemas, code examples, and SDK are available for the community to use and extend.
|
|
27
|
+
|
|
28
|
+
Evo is powered by Seequent, a Bentley organisation.
|
|
29
|
+
|
|
30
|
+
## Pre-requisites
|
|
31
|
+
|
|
32
|
+
* Python >= 3.10, <= 3.12
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install evo-data-converters-vtk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# VTK
|
|
41
|
+
|
|
42
|
+
The Visualization Toolkit (VTK) is open source software for manipulating and displaying scientific data
|
|
43
|
+
|
|
44
|
+
Refer here for more information: https://vtk.org/
|
|
45
|
+
|
|
46
|
+
To work with VTK files [the `vtk` Python package](https://pypi.org/project/vtk/) is used, which is a Python wrapper around the underlying `vtk` C++ library.
|
|
47
|
+
|
|
48
|
+
The VTK converter currently supports importing the following objects into geoscience objects:
|
|
49
|
+
- `vtkImageData`/`vtkUniformGrid`/`vtkStructuredPoints`
|
|
50
|
+
- Imported as a `regular-3d-grid` object if there are no blank cells
|
|
51
|
+
- Otherwise, imported as a `regular-masked-3d-grid` object
|
|
52
|
+
- `vtkRectilinearGrid`
|
|
53
|
+
- Imported as a `tensor-3d-grid` object
|
|
54
|
+
- `vtkUnstructuredGrid`
|
|
55
|
+
- Imported as an `unstructured-tet-grid` object if all cells are tetrahedrons
|
|
56
|
+
- Imported as an `unstructured-hex-grid` object if all cells are hexahedrons
|
|
57
|
+
- Otherwise, imported as an `unstructured-grid` object
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Code of conduct
|
|
61
|
+
|
|
62
|
+
We rely on an open, friendly, inclusive environment. To help us ensure this remains possible, please familiarise yourself with our [code of conduct.](https://github.com/SeequentEvo/evo-data-converters/blob/main/CODE_OF_CONDUCT.md)
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
Evo data converters are open source and licensed under the [Apache 2.0 license.](./LICENSE.md)
|
|
66
|
+
|
|
67
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
68
|
+
|
|
69
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
70
|
+
You may obtain a copy of the License at
|
|
71
|
+
|
|
72
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
73
|
+
|
|
74
|
+
Unless required by applicable law or agreed to in writing, software
|
|
75
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
76
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
77
|
+
See the License for the specific language governing permissions and
|
|
78
|
+
limitations under the License.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE.md
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/evo/data_converters/vtk/__init__.py
|
|
5
|
+
src/evo/data_converters/vtk/importer/__init__.py
|
|
6
|
+
src/evo/data_converters/vtk/importer/_utils.py
|
|
7
|
+
src/evo/data_converters/vtk/importer/exceptions.py
|
|
8
|
+
src/evo/data_converters/vtk/importer/vtk_attributes_to_evo.py
|
|
9
|
+
src/evo/data_converters/vtk/importer/vtk_image_data_to_evo.py
|
|
10
|
+
src/evo/data_converters/vtk/importer/vtk_rectilinear_grid_to_evo.py
|
|
11
|
+
src/evo/data_converters/vtk/importer/vtk_to_evo.py
|
|
12
|
+
src/evo/data_converters/vtk/importer/vtk_unstructured_grid_to_evo.py
|
|
13
|
+
src/evo_data_converters_vtk.egg-info/PKG-INFO
|
|
14
|
+
src/evo_data_converters_vtk.egg-info/SOURCES.txt
|
|
15
|
+
src/evo_data_converters_vtk.egg-info/dependency_links.txt
|
|
16
|
+
src/evo_data_converters_vtk.egg-info/requires.txt
|
|
17
|
+
src/evo_data_converters_vtk.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
evo
|