or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-processing.mddata-structures.mdexamples.mdfile-io.mdgeometric-primitives.mdindex.mdplotting.md

data-structures.mddocs/

0

# Data Structures and Mesh Types

1

2

PyVista provides comprehensive data structure classes that wrap VTK objects with Pythonic interfaces for representing different types of 3D spatial data.

3

4

## Capabilities

5

6

### Polygonal Data (PolyData)

7

8

Represents surfaces, lines, and vertices. The most common mesh type for surface visualization and CAD data.

9

10

```python { .api }

11

class PolyData:

12

"""

13

Polygonal data consisting of vertices, lines, polygons, and triangle strips.

14

15

Attributes:

16

points: np.ndarray - 3D coordinates of vertices

17

faces: np.ndarray - Connectivity information for polygons

18

lines: np.ndarray - Connectivity for line segments

19

verts: np.ndarray - Connectivity for vertices

20

n_points: int - Number of points

21

n_cells: int - Number of cells

22

n_faces: int - Number of faces

23

bounds: tuple - Spatial extent (xmin, xmax, ymin, ymax, zmin, zmax)

24

"""

25

26

def __init__(self, var_inp=None, deep=False, **kwargs): ...

27

28

# Array access

29

def __getitem__(self, key: str) -> np.ndarray: ...

30

def __setitem__(self, key: str, value: ArrayLike): ...

31

32

# Basic operations

33

def copy(self, deep=True) -> 'PolyData': ...

34

def clean(self, **kwargs) -> 'PolyData': ...

35

def extract_surface(self, **kwargs) -> 'PolyData': ...

36

def triangulate(self, **kwargs) -> 'PolyData': ...

37

```

38

39

### Unstructured Grid

40

41

Represents meshes with arbitrary cell types including tetrahedra, hexahedra, prisms, and pyramids.

42

43

```python { .api }

44

class UnstructuredGrid:

45

"""

46

Unstructured grid with arbitrary cell types and connectivity.

47

48

Attributes:

49

points: np.ndarray - 3D coordinates of vertices

50

cells: CellArray - Cell connectivity information

51

celltypes: np.ndarray - VTK cell type for each cell

52

n_points: int - Number of points

53

n_cells: int - Number of cells

54

bounds: tuple - Spatial extent

55

"""

56

57

def __init__(self, var_inp=None, deep=False, **kwargs): ...

58

59

# Array access

60

def __getitem__(self, key: str) -> np.ndarray: ...

61

def __setitem__(self, key: str, value: ArrayLike): ...

62

63

# Grid operations

64

def extract_cells(self, ind: ArrayLike) -> 'UnstructuredGrid': ...

65

def remove_cells(self, ind: ArrayLike) -> 'UnstructuredGrid': ...

66

def explode(self, factor=0.1) -> 'UnstructuredGrid': ...

67

```

68

69

### Structured Grid

70

71

Represents curvilinear grids with regular topology but irregular geometry.

72

73

```python { .api }

74

class StructuredGrid:

75

"""

76

Structured grid with regular topology and arbitrary point coordinates.

77

78

Attributes:

79

points: np.ndarray - 3D coordinates arranged in grid structure

80

dimensions: tuple - Grid dimensions (ni, nj, nk)

81

n_points: int - Number of points

82

n_cells: int - Number of cells

83

bounds: tuple - Spatial extent

84

"""

85

86

def __init__(self, var_inp=None, deep=False, **kwargs): ...

87

88

# Array access

89

def __getitem__(self, key: str) -> np.ndarray: ...

90

def __setitem__(self, key: str, value: ArrayLike): ...

91

92

# Grid operations

93

def extract_subset(self, voi: tuple) -> 'StructuredGrid': ...

94

def hide_cells(self, ind: ArrayLike, inplace=False) -> 'StructuredGrid': ...

95

```

96

97

### Image Data (Uniform Grid)

98

99

Represents uniform rectilinear grids with regular spacing, commonly used for voxel data and medical imaging.

100

101

```python { .api }

102

class ImageData:

103

"""

104

Uniform rectilinear grid with regular spacing in all directions.

105

106

Attributes:

107

dimensions: tuple - Grid dimensions (ni, nj, nk)

108

spacing: tuple - Uniform spacing in each direction

109

origin: tuple - Origin point coordinates

110

n_points: int - Number of points

111

n_cells: int - Number of cells

112

bounds: tuple - Spatial extent

113

"""

114

115

def __init__(self, dimensions=None, spacing=None, origin=None, **kwargs): ...

116

117

# Array access

118

def __getitem__(self, key: str) -> np.ndarray: ...

119

def __setitem__(self, key: str, value: ArrayLike): ...

120

121

# Image operations

122

def to_tetrahedra(self) -> UnstructuredGrid: ...

123

def gaussian_smooth(self, radius_factor=1.5, **kwargs) -> 'ImageData': ...

124

def median_smooth(self, kernel_size=(3, 3, 3)) -> 'ImageData': ...

125

```

126

127

### Rectilinear Grid

128

129

Represents non-uniform rectilinear grids with variable spacing along coordinate axes.

130

131

```python { .api }

132

class RectilinearGrid:

133

"""

134

Rectilinear grid with variable spacing along each coordinate axis.

135

136

Attributes:

137

x: np.ndarray - X-coordinate values

138

y: np.ndarray - Y-coordinate values

139

z: np.ndarray - Z-coordinate values

140

dimensions: tuple - Grid dimensions

141

n_points: int - Number of points

142

n_cells: int - Number of cells

143

bounds: tuple - Spatial extent

144

"""

145

146

def __init__(self, x=None, y=None, z=None, **kwargs): ...

147

148

# Array access

149

def __getitem__(self, key: str) -> np.ndarray: ...

150

def __setitem__(self, key: str, value: ArrayLike): ...

151

```

152

153

### Composite Datasets

154

155

#### MultiBlock Dataset

156

157

Container for multiple datasets of potentially different types.

158

159

```python { .api }

160

class MultiBlock:

161

"""

162

Composite dataset containing multiple datasets.

163

164

Attributes:

165

n_blocks: int - Number of blocks

166

bounds: tuple - Combined spatial extent

167

"""

168

169

def __init__(self, *args, **kwargs): ...

170

171

# Block access

172

def __getitem__(self, index: int): ...

173

def __setitem__(self, index: int, data): ...

174

def append(self, dataset, name=None): ...

175

176

# Operations

177

def combine(self) -> PolyData: ...

178

def extract_geometry(self) -> PolyData: ...

179

```

180

181

#### Partitioned Dataset

182

183

Represents partitioned datasets for parallel processing.

184

185

```python { .api }

186

class PartitionedDataSet:

187

"""

188

Partitioned dataset for parallel processing workflows.

189

190

Attributes:

191

n_partitions: int - Number of partitions

192

bounds: tuple - Combined spatial extent

193

"""

194

195

def __init__(self, *args, **kwargs): ...

196

197

# Partition access

198

def __getitem__(self, index: int): ...

199

def __setitem__(self, index: int, data): ...

200

```

201

202

### Point Clouds

203

204

#### PointGrid

205

206

Specialized dataset for point cloud data.

207

208

```python { .api }

209

class PointGrid:

210

"""

211

Point cloud dataset for scattered 3D points.

212

213

Attributes:

214

points: np.ndarray - 3D point coordinates

215

n_points: int - Number of points

216

bounds: tuple - Spatial extent

217

"""

218

219

def __init__(self, points=None, **kwargs): ...

220

221

# Array access

222

def __getitem__(self, key: str) -> np.ndarray: ...

223

def __setitem__(self, key: str, value: ArrayLike): ...

224

```

225

226

### Specialized Objects

227

228

#### Table

229

230

Represents tabular data compatible with VTK pipeline.

231

232

```python { .api }

233

class Table:

234

"""

235

Tabular data structure for storing columnar data.

236

237

Attributes:

238

n_rows: int - Number of rows

239

n_columns: int - Number of columns

240

"""

241

242

def __init__(self, var_inp=None, **kwargs): ...

243

244

# Data access

245

def __getitem__(self, key: str) -> np.ndarray: ...

246

def __setitem__(self, key: str, value: ArrayLike): ...

247

```

248

249

#### Cell and CellArray

250

251

Low-level cell representation and connectivity.

252

253

```python { .api }

254

class Cell:

255

"""Individual cell representation with connectivity and type information."""

256

257

def __init__(self, cell_type, point_ids): ...

258

259

class CellArray:

260

"""

261

Array storing cell connectivity information.

262

263

Attributes:

264

n_cells: int - Number of cells

265

"""

266

267

def __init__(self, cells=None, **kwargs): ...

268

269

class CellType:

270

"""Enumeration of VTK cell types."""

271

272

# Common cell types

273

VERTEX: int = 1

274

LINE: int = 3

275

TRIANGLE: int = 5

276

QUAD: int = 9

277

TETRA: int = 10

278

HEXAHEDRON: int = 12

279

WEDGE: int = 13

280

PYRAMID: int = 14

281

```

282

283

## Usage Examples

284

285

### Creating and manipulating PolyData

286

287

```python

288

import pyvista as pv

289

import numpy as np

290

291

# Create from points and faces

292

points = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])

293

faces = np.array([4, 0, 1, 2, 3]) # 4 points in face, then point indices

294

mesh = pv.PolyData(points, faces)

295

296

# Add scalar data

297

mesh['elevation'] = mesh.points[:, 2]

298

299

# Access properties

300

print(f"Number of points: {mesh.n_points}")

301

print(f"Number of cells: {mesh.n_cells}")

302

print(f"Bounds: {mesh.bounds}")

303

```

304

305

### Working with ImageData

306

307

```python

308

import pyvista as pv

309

import numpy as np

310

311

# Create 3D grid

312

grid = pv.ImageData(dimensions=(50, 50, 50), spacing=(0.1, 0.1, 0.1))

313

314

# Add volumetric data

315

x, y, z = np.meshgrid(np.linspace(-2, 2, 50),

316

np.linspace(-2, 2, 50),

317

np.linspace(-2, 2, 50), indexing='ij')

318

grid['values'] = np.exp(-(x**2 + y**2 + z**2))

319

320

# Extract isosurface

321

contour = grid.contour(isosurfaces=5)

322

```