or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-structures.mdfiltering.mdfinite-difference.mdgpu-computing.mdimage-adaptors.mdimage-functions.mdindex.mdio.mdmesh.mdnumpy-integration.mdregistration.mdsegmentation.mdspatial-objects.mdtransforms.md

mesh.mddocs/

0

# Mesh Processing

1

2

3D mesh data structures including traditional and half-edge representations for surface modeling, analysis, and processing. ITK provides comprehensive mesh support with both standard connectivity-based meshes and advanced half-edge data structures for topological operations.

3

4

## Capabilities

5

6

### Traditional Mesh Structure

7

8

Standard mesh representation with point and cell containers for general 3D surface modeling.

9

10

```python { .api }

11

class Mesh[TPixelType, VDimension, TMeshTraits]:

12

"""

13

General mesh container with points and cells.

14

15

Template Parameters:

16

- TPixelType: Type for data associated with points/cells

17

- VDimension: Spatial dimensionality (typically 3)

18

- TMeshTraits: Mesh traits defining containers and types

19

"""

20

def New() -> Mesh[TPixelType, VDimension, TMeshTraits]: ...

21

def SetPoint(self, id: PointIdentifier, point: PointType) -> None: ...

22

def GetPoint(self, id: PointIdentifier) -> PointType: ...

23

def GetPoints(self) -> PointsContainer: ...

24

def SetCell(self, id: CellIdentifier, cell: CellAutoPointer) -> None: ...

25

def GetCell(self, id: CellIdentifier) -> CellType: ...

26

def GetCells(self) -> CellsContainer: ...

27

def GetNumberOfPoints(self) -> PointsContainer.ElementIdentifier: ...

28

def GetNumberOfCells(self) -> CellsContainer.ElementIdentifier: ...

29

def SetPointData(self, id: PointIdentifier, data: TPixelType) -> None: ...

30

def GetPointData(self, id: PointIdentifier) -> TPixelType: ...

31

def SetCellData(self, id: CellIdentifier, data: TPixelType) -> None: ...

32

def GetCellData(self, id: CellIdentifier) -> TPixelType: ...

33

def GetBoundingBox(self) -> BoundingBoxType: ...

34

35

class PointSet[TPixelType, VDimension, TMeshTraits]:

36

"""Collection of points with optional associated data."""

37

def New() -> PointSet[TPixelType, VDimension, TMeshTraits]: ...

38

def SetPoint(self, id: PointIdentifier, point: PointType) -> None: ...

39

def GetPoint(self, id: PointIdentifier) -> PointType: ...

40

def GetPoints(self) -> PointsContainer: ...

41

def GetNumberOfPoints(self) -> PointsContainer.ElementIdentifier: ...

42

def SetPointData(self, id: PointIdentifier, data: TPixelType) -> None: ...

43

def GetPointData(self, id: PointIdentifier) -> TPixelType: ...

44

```

45

46

### Mesh Cells and Primitives

47

48

Individual cell types that compose mesh structures.

49

50

```python { .api }

51

class CellInterface[TPixelType, TCellTraits]:

52

"""Base interface for all mesh cell types."""

53

def GetType(self) -> CellGeometryEnum: ...

54

def GetDimension(self) -> int: ...

55

def GetNumberOfPoints(self) -> int: ...

56

def GetNumberOfBoundaryFeatures(self, dimension: int) -> int: ...

57

def GetBoundaryFeature(self, dimension: int, feature_id: int) -> CellAutoPointer: ...

58

def SetPointIds(self, point_ids: PointIdIterator) -> None: ...

59

def GetPointIds(self) -> PointIdIterator: ...

60

def GetPointId(self, local_id: int) -> PointIdentifier: ...

61

62

class LineCell[TCellInterface]:

63

"""Line segment cell connecting two points."""

64

def New() -> LineCell[TCellInterface]: ...

65

def GetNumberOfPoints(self) -> int: ... # Always returns 2

66

def GetNumberOfVertices(self) -> int: ... # Always returns 2

67

def GetVertex(self, vertex_id: int) -> VertexAutoPointer: ...

68

69

class TriangleCell[TCellInterface]:

70

"""Triangular cell with three vertices."""

71

def New() -> TriangleCell[TCellInterface]: ...

72

def GetNumberOfPoints(self) -> int: ... # Always returns 3

73

def GetNumberOfVertices(self) -> int: ... # Always returns 3

74

def GetNumberOfEdges(self) -> int: ... # Always returns 3

75

def GetEdge(self, edge_id: int) -> EdgeAutoPointer: ...

76

def GetVertex(self, vertex_id: int) -> VertexAutoPointer: ...

77

78

class QuadrilateralCell[TCellInterface]:

79

"""Quadrilateral cell with four vertices."""

80

def New() -> QuadrilateralCell[TCellInterface]: ...

81

def GetNumberOfPoints(self) -> int: ... # Always returns 4

82

def GetNumberOfVertices(self) -> int: ... # Always returns 4

83

def GetNumberOfEdges(self) -> int: ... # Always returns 4

84

def GetEdge(self, edge_id: int) -> EdgeAutoPointer: ...

85

86

class TetrahedronCell[TCellInterface]:

87

"""Tetrahedral cell with four vertices."""

88

def New() -> TetrahedronCell[TCellInterface]: ...

89

def GetNumberOfPoints(self) -> int: ... # Always returns 4

90

def GetNumberOfVertices(self) -> int: ... # Always returns 4

91

def GetNumberOfEdges(self) -> int: ... # Always returns 6

92

def GetNumberOfFaces(self) -> int: ... # Always returns 4

93

def GetFace(self, face_id: int) -> FaceAutoPointer: ...

94

95

class HexahedronCell[TCellInterface]:

96

"""Hexahedral cell with eight vertices."""

97

def New() -> HexahedronCell[TCellInterface]: ...

98

def GetNumberOfPoints(self) -> int: ... # Always returns 8

99

def GetNumberOfVertices(self) -> int: ... # Always returns 8

100

def GetNumberOfEdges(self) -> int: ... # Always returns 12

101

def GetNumberOfFaces(self) -> int: ... # Always returns 6

102

def GetFace(self, face_id: int) -> FaceAutoPointer: ...

103

```

104

105

### Mesh Traits and Containers

106

107

Configuration classes that define mesh behavior and storage.

108

109

```python { .api }

110

class DefaultStaticMeshTraits[TPixelType, VPointDimension, VMaxTopologicalDimension, TCoordinate, TInterpolationWeight, TCellPixelType]:

111

"""Default mesh traits for static (fixed-size) containers."""

112

# Type definitions

113

PointType = Point[TCoordinate, VPointDimension]

114

CellType = CellInterface[TCellPixelType, CellTraits]

115

PointsContainer = MapContainer[PointIdentifier, PointType]

116

CellsContainer = MapContainer[CellIdentifier, CellAutoPointer]

117

PointDataContainer = MapContainer[PointIdentifier, TPixelType]

118

CellDataContainer = MapContainer[CellIdentifier, TCellPixelType]

119

120

class DefaultDynamicMeshTraits[TPixelType, VPointDimension, VMaxTopologicalDimension, TCoordinate, TInterpolationWeight, TCellPixelType]:

121

"""Default mesh traits for dynamic (resizable) containers."""

122

# Type definitions

123

PointType = Point[TCoordinate, VPointDimension]

124

CellType = CellInterface[TCellPixelType, CellTraits]

125

PointsContainer = VectorContainer[PointIdentifier, PointType]

126

CellsContainer = VectorContainer[CellIdentifier, CellAutoPointer]

127

PointDataContainer = VectorContainer[PointIdentifier, TPixelType]

128

CellDataContainer = VectorContainer[CellIdentifier, TCellPixelType]

129

130

class MapContainer[TElementIdentifier, TElement]:

131

"""Map-based container for sparse data storage."""

132

def New() -> MapContainer[TElementIdentifier, TElement]: ...

133

def Size(self) -> int: ...

134

def Reserve(self, size: int) -> None: ...

135

def Squeeze(self) -> None: ...

136

def Initialize(self) -> None: ...

137

def InsertElement(self, id: TElementIdentifier, element: TElement) -> None: ...

138

def GetElement(self, id: TElementIdentifier) -> TElement: ...

139

def ElementAt(self, id: TElementIdentifier) -> TElement: ...

140

def CreateElementAt(self, id: TElementIdentifier) -> TElement: ...

141

def DeleteElement(self, id: TElementIdentifier) -> None: ...

142

def IndexExists(self, id: TElementIdentifier) -> bool: ...

143

144

class VectorContainer[TElementIdentifier, TElement]:

145

"""Vector-based container for dense data storage."""

146

def New() -> VectorContainer[TElementIdentifier, TElement]: ...

147

def Size(self) -> int: ...

148

def Reserve(self, size: int) -> None: ...

149

def Squeeze(self) -> None: ...

150

def Initialize(self) -> None: ...

151

def InsertElement(self, id: TElementIdentifier, element: TElement) -> None: ...

152

def SetElement(self, id: TElementIdentifier, element: TElement) -> None: ...

153

def GetElement(self, id: TElementIdentifier) -> TElement: ...

154

def CreateElementAt(self, id: TElementIdentifier) -> TElement: ...

155

def DeleteElement(self, id: TElementIdentifier) -> None: ...

156

```

157

158

### QuadEdge Mesh Structure

159

160

Half-edge data structure for advanced topological operations and mesh processing.

161

162

```python { .api }

163

class QuadEdgeMesh[TPixel, VDimension, TTraits]:

164

"""

165

Half-edge mesh representation for advanced topological operations.

166

167

Template Parameters:

168

- TPixel: Type for data associated with vertices/faces

169

- VDimension: Spatial dimensionality

170

- TTraits: QuadEdge mesh traits

171

"""

172

def New() -> QuadEdgeMesh[TPixel, VDimension, TTraits]: ...

173

def AddFace(self, points: list[PointIdentifier]) -> QEType: ...

174

def AddFaceTriangle(self, point_id0: PointIdentifier, point_id1: PointIdentifier, point_id2: PointIdentifier) -> QEType: ...

175

def DeleteFace(self, face: QEType) -> None: ...

176

def FindEdge(self, point1: PointIdentifier, point2: PointIdentifier) -> QEType: ...

177

def GetEdge(self) -> QEType: ...

178

def GetPoint(self, id: PointIdentifier) -> PointType: ...

179

def SetPoint(self, id: PointIdentifier, point: PointType) -> None: ...

180

def GetNumberOfFaces(self) -> CellIdentifier: ...

181

def GetNumberOfEdges(self) -> CellIdentifier: ...

182

def ComputeNumberOfPoints(self) -> PointIdentifier: ...

183

def Squeeze(self) -> None: ...

184

185

class QuadEdge:

186

"""Basic half-edge structure for topological navigation."""

187

def GetSym(self) -> QuadEdge: ...

188

def GetOnext(self) -> QuadEdge: ...

189

def GetLnext(self) -> QuadEdge: ...

190

def GetRnext(self) -> QuadEdge: ...

191

def GetDnext(self) -> QuadEdge: ...

192

def GetOprev(self) -> QuadEdge: ...

193

def GetLprev(self) -> QuadEdge: ...

194

def GetRprev(self) -> QuadEdge: ...

195

def GetDprev(self) -> QuadEdge: ...

196

def GetInvOnext(self) -> QuadEdge: ...

197

def GetInvLnext(self) -> QuadEdge: ...

198

def GetInvRnext(self) -> QuadEdge: ...

199

def GetInvDnext(self) -> QuadEdge: ...

200

def IsOriginSet(self) -> bool: ...

201

def IsDestinationSet(self) -> bool: ...

202

def IsLeftSet(self) -> bool: ...

203

def IsRightSet(self) -> bool: ...

204

205

class GeometricalQuadEdge[TVRef, TFRef, TPrimalData, TDualData]:

206

"""Geometric half-edge with spatial and data information."""

207

def New() -> GeometricalQuadEdge[TVRef, TFRef, TPrimalData, TDualData]: ...

208

def GetOrigin(self) -> TVRef: ...

209

def GetDestination(self) -> TVRef: ...

210

def GetLeft(self) -> TFRef: ...

211

def GetRight(self) -> TFRef: ...

212

def SetOrigin(self, origin: TVRef) -> None: ...

213

def SetDestination(self, destination: TVRef) -> None: ...

214

def SetLeft(self, left: TFRef) -> None: ...

215

def SetRight(self, right: TFRef) -> None: ...

216

def GetPrimalData(self) -> TPrimalData: ...

217

def SetPrimalData(self, data: TPrimalData) -> None: ...

218

def GetDualData(self) -> TDualData: ...

219

def SetDualData(self, data: TDualData) -> None: ...

220

```

221

222

### QuadEdge Euler Operations

223

224

Topological operations for mesh modification and construction.

225

226

```python { .api }

227

class QuadEdgeMeshEulerOperatorJoinVertexFunction[TMesh, TQEType]:

228

"""Join two vertices by removing the edge between them."""

229

def New() -> QuadEdgeMeshEulerOperatorJoinVertexFunction[TMesh, TQEType]: ...

230

def Evaluate(self, e: TQEType) -> PointIdentifier: ...

231

232

class QuadEdgeMeshEulerOperatorSplitEdgeFunction[TMesh, TQEType]:

233

"""Split an edge by inserting a new vertex."""

234

def New() -> QuadEdgeMeshEulerOperatorSplitEdgeFunction[TMesh, TQEType]: ...

235

def Evaluate(self, e: TQEType, point: PointType) -> PointIdentifier: ...

236

237

class QuadEdgeMeshEulerOperatorFlipEdgeFunction[TMesh, TQEType]:

238

"""Flip an edge in a triangular mesh."""

239

def New() -> QuadEdgeMeshEulerOperatorFlipEdgeFunction[TMesh, TQEType]: ...

240

def Evaluate(self, e: TQEType) -> TQEType: ...

241

242

class QuadEdgeMeshEulerOperatorSplitFaceFunction[TMesh, TQEType]:

243

"""Split a face by inserting a new edge."""

244

def New() -> QuadEdgeMeshEulerOperatorSplitFaceFunction[TMesh, TQEType]: ...

245

def Evaluate(self, e: TQEType, f: TQEType) -> TQEType: ...

246

247

class QuadEdgeMeshEulerOperatorJoinFaceFunction[TMesh, TQEType]:

248

"""Join two faces by removing the edge between them."""

249

def New() -> QuadEdgeMeshEulerOperatorJoinFaceFunction[TMesh, TQEType]: ...

250

def Evaluate(self, e: TQEType) -> FaceRefType: ...

251

```

252

253

### Specialized QuadEdge Components

254

255

Specialized components for QuadEdge mesh structure.

256

257

```python { .api }

258

class QuadEdgeMeshPoint[TCoordRep, VPointDimension, TPointData]:

259

"""Point class specialized for QuadEdge meshes."""

260

def New() -> QuadEdgeMeshPoint[TCoordRep, VPointDimension, TPointData]: ...

261

def GetEdge(self) -> QEType: ...

262

def SetEdge(self, edge: QEType) -> None: ...

263

def GetValence(self) -> int: ...

264

def IsInternal(self) -> bool: ...

265

266

class QuadEdgeMeshLineCell[TCellInterface]:

267

"""Line cell specialized for QuadEdge meshes."""

268

def New() -> QuadEdgeMeshLineCell[TCellInterface]: ...

269

def GetQEGeom(self) -> QEType: ...

270

def SetQEGeom(self, geom: QEType) -> None: ...

271

272

class QuadEdgeMeshPolygonCell[TCellInterface]:

273

"""Polygon cell specialized for QuadEdge meshes."""

274

def New() -> QuadEdgeMeshPolygonCell[TCellInterface]: ...

275

def GetQEGeom(self) -> QEType: ...

276

def SetQEGeom(self, geom: QEType) -> None: ...

277

def GetNumberOfPoints(self) -> int: ...

278

279

class QuadEdgeMeshBoundaryEdgesMeshFunction[TMesh]:

280

"""Function to detect boundary edges in QuadEdge mesh."""

281

def New() -> QuadEdgeMeshBoundaryEdgesMeshFunction[TMesh]: ...

282

def Evaluate(self, edge: QEType) -> OutputType: ...

283

def GetBoundaryEdges(self) -> list[QEType]: ...

284

```

285

286

### Voronoi Diagrams

287

288

2D Voronoi diagram generation and representation.

289

290

```python { .api }

291

class VoronoiDiagram2D[TCoordinate]:

292

"""2D Voronoi diagram representation."""

293

def New() -> VoronoiDiagram2D[TCoordinate]: ...

294

def GetNumberOfSeeds(self) -> int: ...

295

def GetSeed(self, seed_id: int) -> PointType: ...

296

def GetNumberOfVertices(self) -> int: ...

297

def GetVertex(self, vertex_id: int) -> PointType: ...

298

def GetNumberOfNeighbors(self, seed_id: int) -> int: ...

299

def GetNeighbor(self, seed_id: int, neighbor_id: int) -> int: ...

300

def GetSeedsIDAroundEdge(self, edge: EdgeInfo) -> tuple[int, int]: ...

301

302

class VoronoiDiagram2DGenerator[TCoordinate]:

303

"""Generate 2D Voronoi diagrams from point sets."""

304

def New() -> VoronoiDiagram2DGenerator[TCoordinate]: ...

305

def SetSeeds(self, num_seeds: int, seeds: list[PointType]) -> None: ...

306

def AddOneSeed(self, seed: PointType) -> None: ...

307

def SetBoundary(self, boundary: PointType) -> None: ...

308

def GetBoundary(self) -> PointType: ...

309

def SetRandomSeeds(self, num_seeds: int) -> None: ...

310

def Update(self) -> None: ...

311

def UpdateAgain(self) -> None: ...

312

def GetOutput(self) -> VoronoiDiagram2D[TCoordinate]: ...

313

```

314

315

## Usage Examples

316

317

### Creating and Manipulating Traditional Meshes

318

319

```python

320

import itk

321

import numpy as np

322

323

# Create a 3D mesh with float pixel type

324

MeshType = itk.Mesh[itk.F, 3]

325

mesh = MeshType.New()

326

327

# Get point and cell containers

328

points = mesh.GetPoints()

329

cells = mesh.GetCells()

330

331

# Add vertices for a tetrahedron

332

points.InsertElement(0, itk.Point[itk.F, 3]([0.0, 0.0, 0.0]))

333

points.InsertElement(1, itk.Point[itk.F, 3]([1.0, 0.0, 0.0]))

334

points.InsertElement(2, itk.Point[itk.F, 3]([0.5, 1.0, 0.0]))

335

points.InsertElement(3, itk.Point[itk.F, 3]([0.5, 0.5, 1.0]))

336

337

# Create triangular faces

338

TriangleType = itk.TriangleCell[MeshType.CellType]

339

340

# Face 1 (bottom triangle)

341

triangle1 = TriangleType.New()

342

triangle1.SetPointId(0, 0)

343

triangle1.SetPointId(1, 1)

344

triangle1.SetPointId(2, 2)

345

cells.InsertElement(0, triangle1)

346

347

# Face 2 (side triangle)

348

triangle2 = TriangleType.New()

349

triangle2.SetPointId(0, 0)

350

triangle2.SetPointId(1, 1)

351

triangle2.SetPointId(2, 3)

352

cells.InsertElement(1, triangle2)

353

354

# Face 3 (side triangle)

355

triangle3 = TriangleType.New()

356

triangle3.SetPointId(0, 1)

357

triangle3.SetPointId(1, 2)

358

triangle3.SetPointId(2, 3)

359

cells.InsertElement(2, triangle3)

360

361

# Face 4 (side triangle)

362

triangle4 = TriangleType.New()

363

triangle4.SetPointId(0, 0)

364

triangle4.SetPointId(1, 2)

365

triangle4.SetPointId(2, 3)

366

cells.InsertElement(3, triangle4)

367

368

# Add point data (e.g., scalar values)

369

point_data = mesh.GetPointData()

370

point_data.InsertElement(0, 1.0)

371

point_data.InsertElement(1, 2.0)

372

point_data.InsertElement(2, 3.0)

373

point_data.InsertElement(3, 4.0)

374

375

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

376

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

377

378

# Access and print point coordinates

379

for i in range(mesh.GetNumberOfPoints()):

380

point = mesh.GetPoint(i)

381

data = mesh.GetPointData(i)

382

print(f"Point {i}: {point}, Data: {data}")

383

```

384

385

### Working with QuadEdge Meshes

386

387

```python

388

import itk

389

390

# Create QuadEdge mesh

391

QEMeshType = itk.QuadEdgeMesh[itk.F, 3]

392

qe_mesh = QEMeshType.New()

393

394

# Add points

395

qe_mesh.SetPoint(0, itk.Point[itk.F, 3]([0.0, 0.0, 0.0]))

396

qe_mesh.SetPoint(1, itk.Point[itk.F, 3]([1.0, 0.0, 0.0]))

397

qe_mesh.SetPoint(2, itk.Point[itk.F, 3]([0.5, 1.0, 0.0]))

398

qe_mesh.SetPoint(3, itk.Point[itk.F, 3]([1.5, 1.0, 0.0]))

399

400

# Add triangular faces

401

face1 = qe_mesh.AddFaceTriangle(0, 1, 2)

402

face2 = qe_mesh.AddFaceTriangle(1, 3, 2)

403

404

print(f"Number of points: {qe_mesh.ComputeNumberOfPoints()}")

405

print(f"Number of faces: {qe_mesh.GetNumberOfFaces()}")

406

print(f"Number of edges: {qe_mesh.GetNumberOfEdges()}")

407

408

# Navigate the mesh topology using QuadEdge operations

409

if face1:

410

# Get the edge and navigate around it

411

edge = face1

412

print(f"Starting edge origin: {edge.GetOrigin()}")

413

print(f"Starting edge destination: {edge.GetDestination()}")

414

415

# Navigate to next edge in face

416

next_edge = edge.GetLnext()

417

print(f"Next edge origin: {next_edge.GetOrigin()}")

418

print(f"Next edge destination: {next_edge.GetDestination()}")

419

420

# Find edge between two specific points

421

edge_between = qe_mesh.FindEdge(1, 2)

422

if edge_between:

423

print("Found edge between points 1 and 2")

424

print(f"Edge origin: {edge_between.GetOrigin()}")

425

print(f"Edge destination: {edge_between.GetDestination()}")

426

```

427

428

### Euler Operations on QuadEdge Meshes

429

430

```python

431

import itk

432

433

# Create a QuadEdge mesh

434

QEMeshType = itk.QuadEdgeMesh[itk.F, 3]

435

mesh = QEMeshType.New()

436

437

# Add points for a square

438

mesh.SetPoint(0, itk.Point[itk.F, 3]([0.0, 0.0, 0.0]))

439

mesh.SetPoint(1, itk.Point[itk.F, 3]([1.0, 0.0, 0.0]))

440

mesh.SetPoint(2, itk.Point[itk.F, 3]([1.0, 1.0, 0.0]))

441

mesh.SetPoint(3, itk.Point[itk.F, 3]([0.0, 1.0, 0.0]))

442

443

# Add two triangular faces to form a square

444

face1 = mesh.AddFaceTriangle(0, 1, 2)

445

face2 = mesh.AddFaceTriangle(0, 2, 3)

446

447

print(f"Initial: {mesh.GetNumberOfFaces()} faces, {mesh.GetNumberOfEdges()} edges")

448

449

# Split an edge by adding a new vertex

450

SplitEdgeType = itk.QuadEdgeMeshEulerOperatorSplitEdgeFunction[QEMeshType, QEMeshType.QEType]

451

split_edge = SplitEdgeType.New()

452

split_edge.SetInput(mesh)

453

454

# Find edge to split (between points 1 and 2)

455

edge_to_split = mesh.FindEdge(1, 2)

456

if edge_to_split:

457

# Add new point at edge midpoint

458

new_point = itk.Point[itk.F, 3]([1.0, 0.5, 0.0])

459

new_point_id = split_edge.Evaluate(edge_to_split, new_point)

460

print(f"Added new point with ID: {new_point_id}")

461

print(f"After split: {mesh.GetNumberOfFaces()} faces, {mesh.GetNumberOfEdges()} edges")

462

463

# Flip an edge

464

FlipEdgeType = itk.QuadEdgeMeshEulerOperatorFlipEdgeFunction[QEMeshType, QEMeshType.QEType]

465

flip_edge = FlipEdgeType.New()

466

flip_edge.SetInput(mesh)

467

468

# Find diagonal edge to flip

469

diagonal_edge = mesh.FindEdge(0, 2)

470

if diagonal_edge:

471

flipped_edge = flip_edge.Evaluate(diagonal_edge)

472

if flipped_edge:

473

print("Successfully flipped edge")

474

print(f"After flip: {mesh.GetNumberOfFaces()} faces, {mesh.GetNumberOfEdges()} edges")

475

```

476

477

### Voronoi Diagram Generation

478

479

```python

480

import itk

481

import numpy as np

482

483

# Create Voronoi diagram generator

484

VoronoiType = itk.VoronoiDiagram2DGenerator[itk.D]

485

voronoi_generator = VoronoiType.New()

486

487

# Set boundary (defines the region)

488

boundary = itk.Point[itk.D, 2]([10.0, 10.0])

489

voronoi_generator.SetBoundary(boundary)

490

491

# Add seed points

492

seeds = [

493

itk.Point[itk.D, 2]([2.0, 2.0]),

494

itk.Point[itk.D, 2]([8.0, 2.0]),

495

itk.Point[itk.D, 2]([5.0, 8.0]),

496

itk.Point[itk.D, 2]([2.0, 8.0]),

497

itk.Point[itk.D, 2]([8.0, 8.0])

498

]

499

500

for seed in seeds:

501

voronoi_generator.AddOneSeed(seed)

502

503

# Generate the Voronoi diagram

504

voronoi_generator.Update()

505

voronoi_diagram = voronoi_generator.GetOutput()

506

507

print(f"Number of seeds: {voronoi_diagram.GetNumberOfSeeds()}")

508

print(f"Number of vertices: {voronoi_diagram.GetNumberOfVertices()}")

509

510

# Print seed information

511

for i in range(voronoi_diagram.GetNumberOfSeeds()):

512

seed = voronoi_diagram.GetSeed(i)

513

num_neighbors = voronoi_diagram.GetNumberOfNeighbors(i)

514

print(f"Seed {i}: {seed}, Neighbors: {num_neighbors}")

515

516

# Print neighbor information

517

for j in range(num_neighbors):

518

neighbor_id = voronoi_diagram.GetNeighbor(i, j)

519

print(f" Neighbor {j}: Seed {neighbor_id}")

520

521

# Print Voronoi vertices

522

for i in range(voronoi_diagram.GetNumberOfVertices()):

523

vertex = voronoi_diagram.GetVertex(i)

524

print(f"Voronoi vertex {i}: {vertex}")

525

```

526

527

### Mesh I/O and Conversion

528

529

```python

530

import itk

531

532

# Create a simple mesh

533

MeshType = itk.Mesh[itk.F, 3]

534

mesh = MeshType.New()

535

536

# Add some geometry (triangle)

537

points = mesh.GetPoints()

538

points.InsertElement(0, itk.Point[itk.F, 3]([0.0, 0.0, 0.0]))

539

points.InsertElement(1, itk.Point[itk.F, 3]([1.0, 0.0, 0.0]))

540

points.InsertElement(2, itk.Point[itk.F, 3]([0.5, 1.0, 0.0]))

541

542

cells = mesh.GetCells()

543

TriangleType = itk.TriangleCell[MeshType.CellType]

544

triangle = TriangleType.New()

545

triangle.SetPointId(0, 0)

546

triangle.SetPointId(1, 1)

547

triangle.SetPointId(2, 2)

548

cells.InsertElement(0, triangle)

549

550

# Write mesh to file (if mesh I/O is available)

551

try:

552

writer = itk.MeshFileWriter[MeshType].New()

553

writer.SetFileName("output_mesh.vtk")

554

writer.SetInput(mesh)

555

writer.Update()

556

print("Mesh written to output_mesh.vtk")

557

except:

558

print("Mesh I/O not available in this ITK build")

559

560

# Convert between different mesh representations

561

# Traditional mesh to QuadEdge mesh conversion would require

562

# custom conversion functions or filters

563

print("Mesh conversion requires specialized filters or manual implementation")

564

```