or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analysis-algorithms.mdapplications.mdcolors-visual.mdcore-objects.mdfile-io.mdindex.mdplotting-visualization.mdshape-generation.mdtransformations-geometry.mdui-components.md

core-objects.mddocs/

0

# Core Data Objects

1

2

Primary classes for representing and manipulating 3D data including meshes, point clouds, volumetric data, and 2D images. These objects form the foundation of the vedo library and provide extensive functionality for scientific visualization and analysis.

3

4

## Capabilities

5

6

### Mesh Objects

7

8

The Mesh class handles triangular meshes and polygonal data, providing comprehensive functionality for 3D surface representation, manipulation, and analysis.

9

10

```python { .api }

11

class Mesh(MeshVisual, Points):

12

"""

13

Build an instance of object Mesh derived from vedo.Points.

14

15

Parameters:

16

- inputobj: str, vtkPolyData, vtkActor, or vedo.Mesh

17

Input data to create mesh from. Can be filename, VTK object, or existing mesh.

18

- c: str or tuple, default "gold"

19

Color specification (name, hex, RGB tuple)

20

- alpha: float, default 1

21

Transparency value (0=transparent, 1=opaque)

22

"""

23

def __init__(self, inputobj=None, c="gold", alpha=1): ...

24

```

25

26

Usage example:

27

```python

28

# Create mesh from file

29

mesh = vedo.Mesh("model.stl")

30

31

# Create mesh from vertices and faces

32

vertices = [[0,0,0], [1,0,0], [0,1,0]]

33

faces = [[0,1,2]]

34

mesh = vedo.Mesh([vertices, faces])

35

36

# Apply properties

37

mesh.color('red').alpha(0.8)

38

```

39

40

#### Essential Mesh Methods

41

42

```python { .api }

43

def compute_normals(self, points=True, cells=True, feature_angle=None, consistency=True):

44

"""

45

Compute point and/or cell normals for the mesh.

46

47

Parameters:

48

- points: bool, default True

49

Compute point normals

50

- cells: bool, default True

51

Compute cell normals

52

- feature_angle: float, optional

53

Feature angle for splitting normals at sharp edges

54

- consistency: bool, default True

55

Enforce consistency of normal orientation

56

57

Returns:

58

Mesh object with computed normals

59

"""

60

61

def triangulate(self, verts=True, lines=True):

62

"""

63

Convert mesh to triangular representation.

64

65

Parameters:

66

- verts: bool, default True

67

Triangulate vertex cells

68

- lines: bool, default True

69

Triangulate line cells

70

71

Returns:

72

Triangulated Mesh object

73

"""

74

75

def smooth(self, niter=15, pass_band=0.1, edge_angle=15, feature_angle=60, boundary=False):

76

"""

77

Smooth mesh using Windowed Sinc algorithm.

78

79

Parameters:

80

- niter: int, default 15

81

Number of smoothing iterations

82

- pass_band: float, default 0.1

83

Pass band frequency (0-2)

84

- edge_angle: float, default 15

85

Edge angle threshold for feature detection

86

- feature_angle: float, default 60

87

Feature angle threshold

88

- boundary: bool, default False

89

Smooth boundary points

90

91

Returns:

92

Smoothed Mesh object

93

"""

94

95

def subdivide(self, n=1, method=0, mel=None):

96

"""

97

Increase mesh resolution through subdivision.

98

99

Parameters:

100

- n: int, default 1

101

Number of subdivision levels

102

- method: int, default 0

103

Subdivision method (0=linear, 1=butterfly, 2=loop)

104

- mel: float, optional

105

Maximum edge length for adaptive subdivision

106

107

Returns:

108

Subdivided Mesh object

109

"""

110

111

def decimate(self, fraction=0.5, n=None, preserve_volume=True, regularization=0.0):

112

"""

113

Reduce mesh complexity while preserving shape.

114

115

Parameters:

116

- fraction: float, default 0.5

117

Target reduction fraction (0-1)

118

- n: int, optional

119

Target number of triangles (alternative to fraction)

120

- preserve_volume: bool, default True

121

Preserve mesh volume during decimation

122

- regularization: float, default 0.0

123

Regularization factor

124

125

Returns:

126

Decimated Mesh object

127

"""

128

129

def boolean(self, operation, mesh2, method=0, tol=None):

130

"""

131

Perform boolean operations between meshes.

132

133

Parameters:

134

- operation: str

135

Boolean operation ('plus', 'intersect', 'minus')

136

- mesh2: Mesh

137

Second mesh for operation

138

- method: int, default 0

139

Algorithm method (0=boolean, 1=loop)

140

- tol: float, optional

141

Tolerance for point coincidence

142

143

Returns:

144

Mesh object result of boolean operation

145

"""

146

147

def intersect_with(self, mesh2, tol=1e-06):

148

"""

149

Compute intersection with another mesh.

150

151

Parameters:

152

- mesh2: Mesh

153

Mesh to intersect with

154

- tol: float, default 1e-06

155

Intersection tolerance

156

157

Returns:

158

Mesh object containing intersection lines

159

"""

160

161

def slice(self, origin=(0, 0, 0), normal=(1, 0, 0)):

162

"""

163

Slice mesh with a plane.

164

165

Parameters:

166

- origin: tuple, default (0, 0, 0)

167

Point on the cutting plane

168

- normal: tuple, default (1, 0, 0)

169

Normal vector of the cutting plane

170

171

Returns:

172

Mesh object containing sliced geometry

173

"""

174

175

def cut_with_plane(self, origin=(0, 0, 0), normal=(1, 0, 0)):

176

"""

177

Cut mesh with a plane, keeping one side.

178

179

Parameters:

180

- origin: tuple, default (0, 0, 0)

181

Point on the cutting plane

182

- normal: tuple, default (1, 0, 0)

183

Normal vector of the cutting plane

184

185

Returns:

186

Mesh object with geometry on one side of plane

187

"""

188

189

def fill_holes(self, size=None):

190

"""

191

Fill holes in the mesh surface.

192

193

Parameters:

194

- size: float, optional

195

Maximum hole size to fill (None=fill all)

196

197

Returns:

198

Mesh object with filled holes

199

"""

200

201

def compute_quality(self, metric=6):

202

"""

203

Compute mesh quality metrics for triangles.

204

205

Parameters:

206

- metric: int, default 6

207

Quality metric (0=edge ratio, 6=scaled Jacobian, etc.)

208

209

Returns:

210

Mesh object with quality scalars added

211

"""

212

213

def compute_curvature(self, method=0):

214

"""

215

Compute surface curvature at mesh points.

216

217

Parameters:

218

- method: int, default 0

219

Curvature method (0=Gaussian, 1=mean)

220

221

Returns:

222

Mesh object with curvature scalars

223

"""

224

225

def geodesic(self, start, end):

226

"""

227

Compute geodesic path between two points on surface.

228

229

Parameters:

230

- start: int or tuple

231

Starting point index or coordinates

232

- end: int or tuple

233

Ending point index or coordinates

234

235

Returns:

236

Mesh object containing geodesic path

237

"""

238

239

def volume(self):

240

"""

241

Compute the volume of closed mesh.

242

243

Returns:

244

float: Mesh volume

245

"""

246

247

def area(self):

248

"""

249

Compute the surface area of mesh.

250

251

Returns:

252

float: Total surface area

253

"""

254

255

def is_closed(self):

256

"""

257

Check if mesh is a closed surface.

258

259

Returns:

260

bool: True if mesh is closed

261

"""

262

263

def boundaries(self, return_ids=False, return_cell_ids=False, cell_edge=False):

264

"""

265

Return mesh boundary edges as a new mesh.

266

267

Parameters:

268

- return_ids: bool, default False

269

Return boundary point indices

270

- return_cell_ids: bool, default False

271

Return boundary cell indices

272

- cell_edge: bool, default False

273

Consider cell edges instead of point edges

274

275

Returns:

276

Mesh object containing boundary or indices array

277

"""

278

279

def clean(self, tol=None):

280

"""

281

Clean mesh by merging duplicate points and removing unused points.

282

283

Parameters:

284

- tol: float, optional

285

Tolerance for merging points

286

287

Returns:

288

Cleaned Mesh object

289

"""

290

291

def reverse(self, cells=True, normals=False):

292

"""

293

Reverse mesh orientation by flipping face normals.

294

295

Parameters:

296

- cells: bool, default True

297

Reverse cell orientation

298

- normals: bool, default False

299

Reverse normal vectors

300

301

Returns:

302

Mesh object with reversed orientation

303

"""

304

305

def extrude(self, zshift=1.0, direction=(), rotation=0.0, dr=0.0, cap=True, res=1):

306

"""

307

Extrude mesh along a direction to create a 3D object.

308

309

Parameters:

310

- zshift: float, default 1.0

311

Extrusion distance

312

- direction: tuple, optional

313

Extrusion direction vector

314

- rotation: float, default 0.0

315

Twist rotation angle during extrusion

316

- dr: float, default 0.0

317

Radial expansion/contraction

318

- cap: bool, default True

319

Cap the extruded ends

320

- res: int, default 1

321

Number of intermediate layers

322

323

Returns:

324

Extruded Mesh object

325

"""

326

327

def boolean(self, operation: str, mesh2, method=0, tol=None):

328

"""

329

Perform boolean operations between meshes.

330

331

Parameters:

332

- operation: str

333

Boolean operation ("plus", "minus", "intersect")

334

- mesh2: Mesh

335

Second mesh for the operation

336

- method: int, default 0

337

Boolean algorithm method (0, 1, or 2)

338

- tol: float, optional

339

Tolerance for surface intersection

340

341

Returns:

342

Mesh object with boolean operation result

343

"""

344

345

def subdivide(self, n=1, method=0, mel=None):

346

"""

347

Subdivide mesh faces to increase resolution.

348

349

Parameters:

350

- n: int, default 1

351

Number of subdivision iterations

352

- method: int, default 0

353

Subdivision algorithm (0=linear, 1=butterfly, 2=loop)

354

- mel: float, optional

355

Maximum edge length for adaptive subdivision

356

357

Returns:

358

Subdivided Mesh object

359

"""

360

361

def decimate(self, fraction=0.5, n=None, preserve_volume=True, regularization=0.0):

362

"""

363

Reduce mesh complexity by decimating triangles.

364

365

Parameters:

366

- fraction: float, default 0.5

367

Target reduction fraction (0-1)

368

- n: int, optional

369

Target number of triangles (overrides fraction)

370

- preserve_volume: bool, default True

371

Preserve mesh volume during decimation

372

- regularization: float, default 0.0

373

Regularization strength for edge collapse

374

375

Returns:

376

Decimated Mesh object

377

"""

378

379

def smooth(self, niter=15, pass_band=0.1, edge_angle=15, feature_angle=60, boundary=False):

380

"""

381

Smooth mesh surface using iterative smoothing.

382

383

Parameters:

384

- niter: int, default 15

385

Number of smoothing iterations

386

- pass_band: float, default 0.1

387

Pass band frequency for smoothing

388

- edge_angle: float, default 15

389

Edge angle threshold for feature preservation

390

- feature_angle: float, default 60

391

Feature angle threshold

392

- boundary: bool, default False

393

Smooth boundary edges

394

395

Returns:

396

Smoothed Mesh object

397

"""

398

399

def fill_holes(self, size=None):

400

"""

401

Fill holes in mesh surface.

402

403

Parameters:

404

- size: float, optional

405

Maximum hole size to fill

406

407

Returns:

408

Mesh object with holes filled

409

"""

410

411

def compute_normals(self, points=True, cells=True, feature_angle=None, consistency=True):

412

"""

413

Compute point and/or cell normal vectors.

414

415

Parameters:

416

- points: bool, default True

417

Compute point normals

418

- cells: bool, default True

419

Compute cell normals

420

- feature_angle: float, optional

421

Feature angle for normal computation

422

- consistency: bool, default True

423

Enforce normal consistency

424

425

Returns:

426

Mesh object with computed normals

427

"""

428

429

def triangulate(self, verts=True, lines=True):

430

"""

431

Convert mesh to triangular faces.

432

433

Parameters:

434

- verts: bool, default True

435

Triangulate vertices

436

- lines: bool, default True

437

Triangulate lines

438

439

Returns:

440

Triangulated Mesh object

441

"""

442

443

def compute_quality(self, metric=6):

444

"""

445

Compute mesh quality metrics.

446

447

Parameters:

448

- metric: int, default 6

449

Quality metric (0-7: edge ratio, aspect ratio, radius ratio, etc.)

450

451

Returns:

452

Mesh object with quality scalars

453

"""

454

455

def intersect_with_line(self, p0, p1=None, return_ids=False, tol=0):

456

"""

457

Find intersection points between mesh and a line.

458

459

Parameters:

460

- p0: tuple or array

461

First point of line or line direction

462

- p1: tuple, optional

463

Second point of line

464

- return_ids: bool, default False

465

Return cell IDs of intersected cells

466

- tol: float, default 0

467

Intersection tolerance

468

469

Returns:

470

Array of intersection points or tuple with cell IDs

471

"""

472

473

def intersect_with_plane(self, origin=(0, 0, 0), normal=(1, 0, 0)):

474

"""

475

Intersect mesh with a plane to create a line contour.

476

477

Parameters:

478

- origin: tuple, default (0, 0, 0)

479

Point on the cutting plane

480

- normal: tuple, default (1, 0, 0)

481

Normal vector of the cutting plane

482

483

Returns:

484

Mesh object containing intersection lines

485

"""

486

487

def contains(self, point: tuple, tol=1e-05):

488

"""

489

Check if a point is inside the mesh (for closed meshes).

490

491

Parameters:

492

- point: tuple

493

3D coordinates to test

494

- tol: float, default 1e-05

495

Tolerance for containment test

496

497

Returns:

498

bool: True if point is inside mesh

499

"""

500

501

def geodesic(self, start, end):

502

"""

503

Compute geodesic path between two points on mesh surface.

504

505

Parameters:

506

- start: int or tuple

507

Starting point (vertex index or coordinates)

508

- end: int or tuple

509

Ending point (vertex index or coordinates)

510

511

Returns:

512

Mesh object representing geodesic path

513

"""

514

515

def is_manifold(self):

516

"""

517

Check if mesh is manifold (no non-manifold edges).

518

519

Returns:

520

bool: True if mesh is manifold

521

"""

522

523

def euler_characteristic(self):

524

"""

525

Compute Euler characteristic (V - E + F).

526

527

Returns:

528

int: Euler characteristic value

529

"""

530

531

def genus(self):

532

"""

533

Compute genus of closed mesh surface.

534

535

Returns:

536

int: Genus value (0 for sphere, 1 for torus, etc.)

537

"""

538

```

539

540

### Point Cloud Objects

541

542

The Points class manages point cloud data with extensive algorithms for analysis, fitting, and visualization of discrete 3D point sets.

543

544

```python { .api }

545

class Points(PointsVisual, PointAlgorithms):

546

"""

547

Build an instance of object Points for point cloud data.

548

549

Parameters:

550

- inputobj: array-like, str, or vtkPolyData

551

Point coordinates as Nx3 array, filename, or VTK object

552

- r: float, default 4

553

Point size/radius for visualization

554

- c: str or tuple, default "red"

555

Color specification

556

- alpha: float, default 1

557

Transparency value

558

"""

559

def __init__(self, inputobj=None, r=4, c="red", alpha=1): ...

560

```

561

562

#### Essential Points Methods

563

564

```python { .api }

565

def align_to(self, target, iters=100, rigid=False, invert=False, use_centroids=False):

566

"""

567

Align point cloud to target using iterative closest point (ICP).

568

569

Parameters:

570

- target: Points or array-like

571

Target point set to align to

572

- iters: int, default 100

573

Maximum number of iterations

574

- rigid: bool, default False

575

Use rigid transformation only (no scaling)

576

- invert: bool, default False

577

Invert the transformation

578

- use_centroids: bool, default False

579

Use centroids for initial alignment

580

581

Returns:

582

Aligned Points object

583

"""

584

585

def clean(self):

586

"""

587

Clean point cloud by removing duplicate points.

588

589

Returns:

590

Cleaned Points object

591

"""

592

593

def subsample(self, fraction, absolute=False):

594

"""

595

Subsample points randomly or uniformly.

596

597

Parameters:

598

- fraction: float

599

Fraction of points to keep (0-1) or absolute number if absolute=True

600

- absolute: bool, default False

601

Treat fraction as absolute number of points

602

603

Returns:

604

Subsampled Points object

605

"""

606

607

def remove_outliers(self, radius, neighbors=5):

608

"""

609

Remove outlier points based on local density.

610

611

Parameters:

612

- radius: float

613

Search radius for neighbors

614

- neighbors: int, default 5

615

Minimum number of neighbors required

616

617

Returns:

618

Points object with outliers removed

619

"""

620

621

def compute_normals_with_pca(self, n=20, orientation_point=None, invert=False):

622

"""

623

Compute point normals using Principal Component Analysis.

624

625

Parameters:

626

- n: int, default 20

627

Number of neighbors for PCA analysis

628

- orientation_point: tuple, optional

629

Reference point for normal orientation

630

- invert: bool, default False

631

Invert computed normals

632

633

Returns:

634

Points object with normals computed

635

"""

636

637

def distance_to(self, pcloud, signed=False, invert=False, name="Distance"):

638

"""

639

Compute distance from each point to target point cloud.

640

641

Parameters:

642

- pcloud: Points

643

Target point cloud

644

- signed: bool, default False

645

Compute signed distance

646

- invert: bool, default False

647

Invert distance values

648

- name: str, default "Distance"

649

Name for distance array

650

651

Returns:

652

Distance array for each point

653

"""

654

655

def closest_point(self, pt, n=1, radius=None, return_point_id=False, return_point_coord=True):

656

"""

657

Find closest point(s) to a query point.

658

659

Parameters:

660

- pt: tuple

661

Query point coordinates

662

- n: int, default 1

663

Number of closest points to find

664

- radius: float, optional

665

Search radius limit

666

- return_point_id: bool, default False

667

Return point indices

668

- return_point_coord: bool, default True

669

Return point coordinates

670

671

Returns:

672

Closest point coordinates or indices

673

"""

674

675

def densify(self, target_distance=0.1, nclosest=6, radius=None, niter=1, nmax=None):

676

"""

677

Add points to regions with low point density.

678

679

Parameters:

680

- target_distance: float, default 0.1

681

Target distance between points

682

- nclosest: int, default 6

683

Number of closest points to consider

684

- radius: float, optional

685

Maximum search radius

686

- niter: int, default 1

687

Number of iterations

688

- nmax: int, optional

689

Maximum number of points to add

690

691

Returns:

692

Densified Points object

693

"""

694

695

def smooth_mls_1d(self, f=0.2, radius=None, n=0):

696

"""

697

Smooth 1D point set using Moving Least Squares.

698

699

Parameters:

700

- f: float, default 0.2

701

Smoothing factor

702

- radius: float, optional

703

Smoothing radius

704

- n: int, default 0

705

Polynomial order

706

707

Returns:

708

Smoothed Points object

709

"""

710

711

def smooth_mls_2d(self, f=0.2, radius=None, n=0):

712

"""

713

Smooth 2D point set using Moving Least Squares.

714

715

Parameters:

716

- f: float, default 0.2

717

Smoothing factor

718

- radius: float, optional

719

Smoothing radius

720

- n: int, default 0

721

Polynomial order

722

723

Returns:

724

Smoothed Points object

725

"""

726

727

def generate_mesh(self, radius=None, dims=(25, 25, 25), bounds=(), c="gold", alpha=1):

728

"""

729

Generate mesh surface from point cloud using various algorithms.

730

731

Parameters:

732

- radius: float, optional

733

Sampling radius for mesh generation

734

- dims: tuple, default (25, 25, 25)

735

Grid dimensions for volume-based methods

736

- bounds: tuple, optional

737

Bounding box for mesh generation

738

- c: str, default "gold"

739

Mesh color

740

- alpha: float, default 1

741

Mesh transparency

742

743

Returns:

744

Generated Mesh object

745

"""

746

747

def reconstruct_surface(self, dims=(100, 100, 100), radius=None, sample_size=None, hole_filling=True, bounds=(), pad=0.1):

748

"""

749

Reconstruct surface from point cloud using Poisson reconstruction.

750

751

Parameters:

752

- dims: tuple, default (100, 100, 100)

753

Volume dimensions for reconstruction

754

- radius: float, optional

755

Sampling radius

756

- sample_size: int, optional

757

Number of sample points

758

- hole_filling: bool, default True

759

Fill holes in reconstruction

760

- bounds: tuple, optional

761

Bounding region

762

- pad: float, default 0.1

763

Padding factor

764

765

Returns:

766

Reconstructed Mesh object

767

"""

768

769

def compute_clustering(self, radius):

770

"""

771

Compute point clusters based on proximity.

772

773

Parameters:

774

- radius: float

775

Clustering radius

776

777

Returns:

778

Points object with cluster IDs as scalars

779

"""

780

781

def project_on_plane(self, plane="z", point=None, direction=None):

782

"""

783

Project points onto a plane.

784

785

Parameters:

786

- plane: str or array, default "z"

787

Plane specification ("x", "y", "z" or normal vector)

788

- point: tuple, optional

789

Point on the plane

790

- direction: tuple, optional

791

Projection direction

792

793

Returns:

794

Projected Points object

795

"""

796

797

def cut_with_plane(self, origin=(0, 0, 0), normal=(1, 0, 0), invert=False):

798

"""

799

Cut point cloud with a plane.

800

801

Parameters:

802

- origin: tuple, default (0, 0, 0)

803

Point on cutting plane

804

- normal: tuple, default (1, 0, 0)

805

Plane normal vector

806

- invert: bool, default False

807

Keep points on opposite side

808

809

Returns:

810

Cut Points object

811

"""

812

813

def cut_with_box(self, bounds, invert=False):

814

"""

815

Cut point cloud with a bounding box.

816

817

Parameters:

818

- bounds: tuple or list

819

Bounding box coordinates [xmin, xmax, ymin, ymax, zmin, zmax]

820

- invert: bool, default False

821

Keep points outside box

822

823

Returns:

824

Cut Points object

825

"""

826

827

def cut_with_sphere(self, center=(0, 0, 0), r=1.0, invert=False):

828

"""

829

Cut point cloud with a sphere.

830

831

Parameters:

832

- center: tuple, default (0, 0, 0)

833

Sphere center coordinates

834

- r: float, default 1.0

835

Sphere radius

836

- invert: bool, default False

837

Keep points outside sphere

838

839

Returns:

840

Cut Points object

841

"""

842

843

def generate_delaunay2d(self, mode="xy", boundaries=(), alpha=0, tol=None, transform=None):

844

"""

845

Generate 2D Delaunay triangulation from point cloud.

846

847

Parameters:

848

- mode: str, default "xy"

849

Projection plane ("xy", "xz", "yz")

850

- boundaries: tuple, optional

851

Boundary constraints

852

- alpha: float, default 0

853

Alpha value for alpha-shape filtering

854

- tol: float, optional

855

Tolerance for point merging

856

- transform: array, optional

857

Transformation matrix

858

859

Returns:

860

Mesh object with Delaunay triangulation

861

"""

862

863

def generate_delaunay3d(self, radius=0, tol=None):

864

"""

865

Generate 3D Delaunay tetrahedralization from point cloud.

866

867

Parameters:

868

- radius: float, default 0

869

Alpha radius for alpha-shape filtering

870

- tol: float, optional

871

Tolerance for duplicate point removal

872

873

Returns:

874

TetMesh object with Delaunay tetrahedralization

875

"""

876

877

def hausdorff_distance(self, points):

878

"""

879

Compute Hausdorff distance to another point set.

880

881

Parameters:

882

- points: Points or array-like

883

Target point set

884

885

Returns:

886

float: Hausdorff distance

887

"""

888

```

889

890

### Point Creation and Merging

891

892

Functions for creating individual points and combining multiple point sets or meshes.

893

894

```python { .api }

895

def Point(pos=(0, 0, 0), r=12, c="red", alpha=1.0):

896

"""

897

Create a single point marker.

898

899

Parameters:

900

- pos: tuple, default (0, 0, 0)

901

3D position coordinates

902

- r: float, default 12

903

Point size/radius

904

- c: str or tuple, default "red"

905

Color specification

906

- alpha: float, default 1.0

907

Transparency value

908

909

Returns:

910

Points object representing single point

911

"""

912

913

def merge(*meshs, flag=False):

914

"""

915

Build a new Mesh or Points formed by the fusion of inputs.

916

917

Parameters:

918

- *meshs: variable arguments of Mesh or Points objects

919

Objects to merge together

920

- flag: bool, default False

921

If True, keeps track of original identities

922

923

Returns:

924

Union[Mesh, Points, None]: Merged object

925

"""

926

```

927

928

### Volumetric Data Objects

929

930

The Volume class handles 3D scalar and vector field data for volumetric visualization and analysis.

931

932

```python { .api }

933

class Volume(VolumeAlgorithms, VolumeVisual):

934

"""

935

Class to describe datasets defined on voxels (3D equivalent of 2D pixels).

936

937

Parameters:

938

- inputobj: str, numpy array, or vtkImageData

939

Volume data source - filename, 3D array, or VTK image data

940

- c: str, default "RdYlBu_r"

941

Colormap name for volume rendering

942

- alpha: tuple, default (0.0, 0.0, 0.2, 0.4, 0.8, 1.0)

943

Opacity transfer function values

944

"""

945

def __init__(

946

self,

947

inputobj=None,

948

c="RdYlBu_r",

949

alpha=(0.0, 0.0, 0.2, 0.4, 0.8, 1.0)

950

): ...

951

```

952

953

#### Essential Volume Methods

954

955

```python { .api }

956

def slice_plane(self, origin, normal, autocrop=False, border=0.5, mode="linear"):

957

"""

958

Slice volume with a plane to create a 2D mesh.

959

960

Parameters:

961

- origin: tuple

962

Point on the cutting plane

963

- normal: tuple

964

Normal vector of the cutting plane

965

- autocrop: bool, default False

966

Automatically crop to volume bounds

967

- border: float, default 0.5

968

Border padding factor

969

- mode: str, default "linear"

970

Interpolation mode ("linear", "cubic", "nearest")

971

972

Returns:

973

Mesh object representing the slice

974

"""

975

976

def xslice(self, i):

977

"""

978

Extract a slice at x-index i.

979

980

Parameters:

981

- i: int

982

X-axis slice index

983

984

Returns:

985

Mesh object representing YZ slice

986

"""

987

988

def yslice(self, j):

989

"""

990

Extract a slice at y-index j.

991

992

Parameters:

993

- j: int

994

Y-axis slice index

995

996

Returns:

997

Mesh object representing XZ slice

998

"""

999

1000

def zslice(self, k):

1001

"""

1002

Extract a slice at z-index k.

1003

1004

Parameters:

1005

- k: int

1006

Z-axis slice index

1007

1008

Returns:

1009

Mesh object representing XY slice

1010

"""

1011

1012

def threshold(self, above=None, below=None, replace=None, replace_value=None):

1013

"""

1014

Apply threshold filtering to volume data.

1015

1016

Parameters:

1017

- above: float, optional

1018

Keep values above this threshold

1019

- below: float, optional

1020

Keep values below this threshold

1021

- replace: str, optional

1022

Replace values ("above", "below")

1023

- replace_value: float, optional

1024

Replacement value

1025

1026

Returns:

1027

Thresholded Volume object

1028

"""

1029

1030

def crop(self, left=None, right=None, back=None, front=None, bottom=None, top=None, VOI=()):

1031

"""

1032

Crop volume to specified bounds.

1033

1034

Parameters:

1035

- left: int, optional

1036

Left boundary (x-min)

1037

- right: int, optional

1038

Right boundary (x-max)

1039

- back: int, optional

1040

Back boundary (y-min)

1041

- front: int, optional

1042

Front boundary (y-max)

1043

- bottom: int, optional

1044

Bottom boundary (z-min)

1045

- top: int, optional

1046

Top boundary (z-max)

1047

- VOI: tuple, optional

1048

Volume of interest bounds [x0,x1,y0,y1,z0,z1]

1049

1050

Returns:

1051

Cropped Volume object

1052

"""

1053

1054

def resize(self, newdims):

1055

"""

1056

Resize volume to new dimensions.

1057

1058

Parameters:

1059

- newdims: tuple

1060

New dimensions (nx, ny, nz)

1061

1062

Returns:

1063

Resized Volume object

1064

"""

1065

1066

def smooth_gaussian(self, sigma=(2, 2, 2), radius=None):

1067

"""

1068

Apply Gaussian smoothing filter.

1069

1070

Parameters:

1071

- sigma: tuple, default (2, 2, 2)

1072

Standard deviation for each axis

1073

- radius: tuple, optional

1074

Kernel radius for each axis

1075

1076

Returns:

1077

Smoothed Volume object

1078

"""

1079

1080

def smooth_median(self, neighbours=(2, 2, 2)):

1081

"""

1082

Apply median smoothing filter.

1083

1084

Parameters:

1085

- neighbours: tuple, default (2, 2, 2)

1086

Neighborhood size for each axis

1087

1088

Returns:

1089

Smoothed Volume object

1090

"""

1091

1092

def resample(self, new_spacing, interpolation=1):

1093

"""

1094

Resample volume to new voxel spacing.

1095

1096

Parameters:

1097

- new_spacing: tuple

1098

New voxel spacing (dx, dy, dz)

1099

- interpolation: int, default 1

1100

Interpolation method (0=nearest, 1=linear, 3=cubic)

1101

1102

Returns:

1103

Resampled Volume object

1104

"""

1105

1106

def pad(self, voxels=10, value=0):

1107

"""

1108

Pad volume with additional voxels.

1109

1110

Parameters:

1111

- voxels: int or tuple, default 10

1112

Number of voxels to add on each side

1113

- value: float, default 0

1114

Padding value

1115

1116

Returns:

1117

Padded Volume object

1118

"""

1119

1120

def mirror(self, axis="x"):

1121

"""

1122

Mirror volume along specified axis.

1123

1124

Parameters:

1125

- axis: str, default "x"

1126

Axis to mirror along ("x", "y", "z")

1127

1128

Returns:

1129

Mirrored Volume object

1130

"""

1131

1132

def operation(self, operation, volume2=None):

1133

"""

1134

Apply mathematical operations between volumes.

1135

1136

Parameters:

1137

- operation: str

1138

Operation type ("+", "-", "*", "/", "max", "min")

1139

- volume2: Volume, optional

1140

Second volume for binary operations

1141

1142

Returns:

1143

Volume object with operation result

1144

"""

1145

1146

def euclidean_distance(self, anisotropy=False, max_distance=None):

1147

"""

1148

Compute Euclidean distance transform.

1149

1150

Parameters:

1151

- anisotropy: bool, default False

1152

Consider voxel spacing for anisotropic distances

1153

- max_distance: float, optional

1154

Maximum distance to compute

1155

1156

Returns:

1157

Volume object with distance values

1158

"""

1159

1160

def topoints(self):

1161

"""

1162

Convert volume to point cloud representation.

1163

1164

Returns:

1165

Points object with coordinates and scalar values

1166

"""

1167

1168

def tonumpy(self):

1169

"""

1170

Convert volume data to numpy array.

1171

1172

Returns:

1173

numpy.ndarray: Volume data array

1174

"""

1175

```

1176

1177

### 2D Image Objects

1178

1179

The Image class provides functionality for 2D image data visualization and manipulation.

1180

1181

```python { .api }

1182

class Image(ImageVisual):

1183

"""

1184

Class for 2D image data handling and visualization.

1185

1186

Parameters:

1187

- obj: str, numpy array, or PIL Image

1188

Image data source - filename, array, or image object

1189

- channels: int, default 3

1190

Number of color channels (1=grayscale, 3=RGB, 4=RGBA)

1191

"""

1192

def __init__(self, obj=None, channels=3): ...

1193

```

1194

1195

### Grid Objects

1196

1197

Specialized grid classes for structured and unstructured data visualization.

1198

1199

```python { .api }

1200

class UnstructuredGrid(PointAlgorithms, MeshVisual):

1201

"""Support for UnstructuredGrid objects with mixed cell types."""

1202

def __init__(self, inputobj=None, c="gold", alpha=1): ...

1203

1204

class TetMesh(UnstructuredGrid):

1205

"""Tetrahedral mesh support for 3D finite element data."""

1206

def __init__(self, inputobj, c="gold", alpha=1): ...

1207

1208

class RectilinearGrid(PointAlgorithms, MeshVisual):

1209

"""Rectilinear grid data structure for structured datasets."""

1210

def __init__(self, inputobj=None, c="gold", alpha=1): ...

1211

1212

class StructuredGrid(PointAlgorithms, MeshVisual):

1213

"""Structured grid data structure with regular connectivity."""

1214

def __init__(self, inputobj=None, c="gold", alpha=1): ...

1215

```

1216

1217

### Point Cloud Analysis Functions

1218

1219

Advanced analysis functions for fitting geometric primitives to point data.

1220

1221

```python { .api }

1222

def fit_line(points):

1223

"""

1224

Fit a line through points using linear regression.

1225

1226

Parameters:

1227

- points: array-like or Points object

1228

Input point coordinates

1229

1230

Returns:

1231

Line object representing fitted line

1232

"""

1233

1234

def fit_circle(points):

1235

"""

1236

Fit a circle through 2D or 3D points.

1237

1238

Parameters:

1239

- points: array-like or Points object

1240

Input point coordinates

1241

1242

Returns:

1243

tuple: (center, radius, normal) of fitted circle

1244

"""

1245

1246

def fit_plane(points, signed=False):

1247

"""

1248

Fit a plane through 3D points.

1249

1250

Parameters:

1251

- points: array-like or Points object

1252

Input point coordinates

1253

- signed: bool, default False

1254

Whether to return signed distance

1255

1256

Returns:

1257

Plane object representing fitted plane

1258

"""

1259

1260

def fit_sphere(coords):

1261

"""

1262

Fit a sphere through 3D points.

1263

1264

Parameters:

1265

- coords: array-like or Points object

1266

Input point coordinates

1267

1268

Returns:

1269

Sphere object representing fitted sphere

1270

"""

1271

1272

def pca_ellipse(points, pvalue=0.673, res=60):

1273

"""

1274

Create PCA ellipse from point distribution.

1275

1276

Parameters:

1277

- points: array-like or Points object

1278

Input point coordinates

1279

- pvalue: float, default 0.673

1280

Confidence level for ellipse size

1281

- res: int, default 60

1282

Resolution of ellipse boundary

1283

1284

Returns:

1285

Circle object representing PCA ellipse, or None

1286

"""

1287

1288

def pca_ellipsoid(points, pvalue=0.673, res=24):

1289

"""

1290

Create PCA ellipsoid from 3D point distribution.

1291

1292

Parameters:

1293

- points: array-like or Points object

1294

Input point coordinates

1295

- pvalue: float, default 0.673

1296

Confidence level for ellipsoid size

1297

- res: int, default 24

1298

Resolution of ellipsoid surface

1299

1300

Returns:

1301

Ellipsoid object representing PCA ellipsoid, or None

1302

"""

1303

```

1304

1305

## Usage Examples

1306

1307

```python

1308

import vedo

1309

import numpy as np

1310

1311

# Create and analyze point cloud

1312

points_data = np.random.rand(100, 3) * 10

1313

points = vedo.Points(points_data, c='blue', r=6)

1314

1315

# Clean and process point cloud

1316

points = points.clean().remove_outliers(radius=1.0, neighbors=5)

1317

points = points.smooth_mls_2d(f=0.3).densify(target_distance=0.2)

1318

1319

# Fit geometric primitives

1320

fitted_plane = vedo.fit_plane(points)

1321

fitted_sphere = vedo.fit_sphere(points)

1322

pca_ellipsoid = vedo.pca_ellipsoid(points)

1323

1324

# Create and process mesh

1325

vertices = [[0,0,0], [1,0,0], [0,1,0], [0,0,1]]

1326

faces = [[0,1,2], [0,1,3], [0,2,3], [1,2,3]]

1327

mesh = vedo.Mesh([vertices, faces], c='yellow')

1328

1329

# Apply mesh processing operations

1330

mesh = mesh.triangulate().compute_normals().smooth(niter=10)

1331

mesh = mesh.subdivide(n=2).fill_holes()

1332

1333

# Mesh analysis and operations

1334

print(f"Mesh volume: {mesh.volume():.3f}")

1335

print(f"Mesh area: {mesh.area():.3f}")

1336

print(f"Is closed: {mesh.is_closed()}")

1337

1338

# Boolean operations between meshes

1339

sphere1 = vedo.Sphere(r=1.0).pos(0, 0, 0)

1340

sphere2 = vedo.Sphere(r=0.8).pos(0.5, 0, 0)

1341

union = sphere1.boolean("plus", sphere2)

1342

intersection = sphere1.boolean("intersect", sphere2)

1343

difference = sphere1.boolean("minus", sphere2)

1344

1345

# Volume processing example

1346

volume_data = np.random.rand(50, 50, 50)

1347

volume = vedo.Volume(volume_data)

1348

1349

# Process volume

1350

volume = volume.smooth_gaussian(sigma=(1, 1, 1))

1351

volume = volume.threshold(above=0.3, below=0.8)

1352

volume = volume.crop(left=10, right=40, bottom=10, top=40)

1353

1354

# Extract volume slices

1355

x_slice = volume.xslice(25)

1356

y_slice = volume.yslice(25)

1357

z_slice = volume.zslice(25)

1358

1359

# Convert volume to points and mesh

1360

volume_points = volume.topoints()

1361

volume_mesh = volume_points.generate_mesh(radius=0.5)

1362

1363

# Load and combine objects

1364

mesh1 = vedo.load("model1.stl")

1365

mesh2 = vedo.load("model2.obj")

1366

combined = vedo.merge(mesh1, mesh2, flag=True)

1367

1368

# Visualize all objects

1369

vedo.show(points, fitted_plane, union, intersection, x_slice,

1370

title="Advanced Data Processing", axes=True)

1371

```