1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
|
"""Provide sources for generating images."""
from __future__ import annotations
from typing import TYPE_CHECKING
from typing import ClassVar
from pyvista.core import _vtk_core as _vtk
from pyvista.core.utilities.misc import no_new_attr
from .helpers import wrap
if TYPE_CHECKING: # pragma: no cover
from typing import Sequence
@no_new_attr
class ImageEllipsoidSource(_vtk.vtkImageEllipsoidSource):
"""Create a binary image of an ellipsoid class.
.. versionadded:: 0.44.0
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
center : sequence[float]
The center of the ellipsoid.
radius : tuple
The radius of the ellipsoid.
Examples
--------
Create an image of an ellipsoid.
>>> import pyvista as pv
>>> source = pv.ImageEllipsoidSource(
... whole_extent=(0, 20, 0, 20, 0, 0),
... center=(10, 10, 0),
... radius=(3, 4, 5),
... )
>>> source.output.plot(cpos="xy")
"""
def __init__(self, whole_extent=None, center=None, radius=None) -> None:
super().__init__()
if whole_extent is not None:
self.whole_extent = whole_extent
if center is not None:
self.center = center
if radius is not None:
self.radius = radius
@property
def whole_extent(self) -> Sequence[int]:
"""Get extent of the whole output image.
Returns
-------
sequence[int]
The extent of the whole output image.
"""
return self.GetWholeExtent()
@whole_extent.setter
def whole_extent(self, whole_extent: Sequence[int]) -> None:
"""Set extent of the whole output image.
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
"""
self.SetWholeExtent(whole_extent)
@property
def center(self) -> Sequence[float]:
"""Get the center of the ellipsoid.
Returns
-------
sequence[float]
The center of the ellipsoid.
"""
return self.GetCenter()
@center.setter
def center(self, center: Sequence[float]) -> None:
"""Set the center of the ellipsoid.
Parameters
----------
center : sequence[float]
The center of the ellipsoid.
"""
self.SetCenter(center)
@property
def radius(self) -> Sequence[float]:
"""Get the radius of the ellipsoid.
Returns
-------
sequence[float]
The radius of the ellipsoid.
"""
return self.GetRadius()
@radius.setter
def radius(self, radius: Sequence[float]) -> None:
"""Set the radius of the ellipsoid.
Parameters
----------
radius : sequence[float]
The radius of the ellipsoid.
"""
self.SetRadius(radius)
@property
def output(self):
"""Get the output image as a ImageData.
Returns
-------
pyvista.ImageData
The output image.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class ImageMandelbrotSource(_vtk.vtkImageMandelbrotSource):
"""Create an image of the Mandelbrot set.
.. versionadded:: 0.44.0
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
maxiter : int
The maximum number of iterations.
Examples
--------
Create an image of the Mandelbrot set.
>>> import pyvista as pv
>>> source = pv.ImageMandelbrotSource(
... whole_extent=(0, 200, 0, 200, 0, 0),
... maxiter=100,
... )
>>> source.output.plot(cpos="xy")
"""
def __init__(self, whole_extent=None, maxiter=None) -> None:
super().__init__()
if whole_extent is not None:
self.whole_extent = whole_extent
if maxiter is not None:
self.maxiter = maxiter
@property
def whole_extent(self) -> Sequence[int]:
"""Get extent of the whole output image.
Returns
-------
sequence[int]
The extent of the whole output image.
"""
return self.GetWholeExtent()
@whole_extent.setter
def whole_extent(self, whole_extent: Sequence[int]) -> None:
"""Set extent of the whole output image.
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
"""
self.SetWholeExtent(whole_extent)
@property
def maxiter(self) -> int:
"""Get the maximum number of iterations.
Returns
-------
int
The maximum number of iterations.
"""
return self.GetMaximumNumberOfIterations()
@maxiter.setter
def maxiter(self, maxiter: int) -> None:
"""Set the maximum number of iterations.
Parameters
----------
maxiter : int
The maximum number of iterations.
"""
self.SetMaximumNumberOfIterations(maxiter)
@property
def output(self):
"""Get the output image as a ImageData.
Returns
-------
pyvista.ImageData
The output image.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class ImageNoiseSource(_vtk.vtkImageNoiseSource):
"""Create an image filled with uniform noise.
.. versionadded:: 0.44.0
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
minimum : float
The minimum value for the generated noise.
maximum : float
The maximum value for the generated noise.
seed : int, optional
Seed the random number generator with a value.
Examples
--------
Create an image of noise.
>>> import pyvista as pv
>>> source = pv.ImageNoiseSource(
... whole_extent=(0, 200, 0, 200, 0, 0),
... minimum=0,
... maximum=255,
... seed=0,
... )
>>> source.output.plot(cpos="xy")
"""
_new_attr_exceptions: ClassVar[list[str]] = ['_whole_extent', 'whole_extent']
def __init__(
self,
whole_extent=(0, 255, 0, 255, 0, 0),
minimum=0.0,
maximum=1.0,
seed=None,
) -> None:
super().__init__()
if whole_extent is not None:
self.whole_extent = whole_extent
if minimum is not None:
self.minimum = minimum
if maximum is not None:
self.maximum = maximum
if seed is not None:
self.seed(seed)
@property
def whole_extent(self) -> Sequence[int]:
"""Get extent of the whole output image.
Returns
-------
sequence[int]
The extent of the whole output image.
"""
return self._whole_extent
@whole_extent.setter
def whole_extent(self, whole_extent: Sequence[int]) -> None:
"""Set extent of the whole output image.
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
"""
self._whole_extent = whole_extent
self.SetWholeExtent(whole_extent)
@property
def minimum(self) -> float:
"""Get the minimum value for the generated noise.
Returns
-------
float
The minimum value for the generated noise.
"""
return self.GetMinimum()
@minimum.setter
def minimum(self, minimum: float) -> None:
"""Set the minimum value for the generated noise.
Parameters
----------
minimum : float
The minimum value for the generated noise.
"""
self.SetMinimum(minimum)
@property
def maximum(self) -> float:
"""Get the maximum value for the generated noise.
Returns
-------
float
The maximum value for the generated noise.
"""
return self.GetMaximum()
@maximum.setter
def maximum(self, maximum: float) -> None:
"""Set the maximum value for the generated noise.
Parameters
----------
maximum : float
The maximum value for the generated noise.
"""
self.SetMaximum(maximum)
def seed(self, value: int) -> None:
"""Seed the random number generator with a value.
Parameters
----------
value : int
The seed value for the random number generator to use.
"""
_vtk.vtkMath().RandomSeed(value)
@property
def output(self):
"""Get the output image as a ImageData.
Returns
-------
pyvista.ImageData
The output image.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class ImageSinusoidSource(_vtk.vtkImageSinusoidSource):
"""Create an image of a sinusoid.
.. versionadded:: 0.44.0
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
direction : tuple
The direction vector which determines the sinusoidal orientation.
period : float
The period of the sinusoid in pixel.
phase : tuple
The phase of the sinusoid in pixel.
amplitude : float
The magnitude of the sinusoid.
Examples
--------
Create an image of a sinusoid.
>>> import pyvista as pv
>>> source = pv.ImageSinusoidSource(
... whole_extent=(0, 200, 0, 200, 0, 0),
... period=20.0,
... phase=0.0,
... amplitude=255,
... direction=(1.0, 0.0, 0.0),
... )
>>> source.output.plot(cpos="xy")
"""
_new_attr_exceptions: ClassVar[list[str]] = ['_whole_extent', 'whole_extent']
def __init__(
self,
whole_extent=None,
direction=None,
period=None,
phase=None,
amplitude=None,
) -> None:
super().__init__()
if whole_extent is not None:
self.whole_extent = whole_extent
if direction is not None:
self.direction = direction
if period is not None:
self.period = period
if phase is not None:
self.phase = phase
if amplitude is not None:
self.amplitude = amplitude
@property
def whole_extent(self) -> Sequence[int]:
"""Get extent of the whole output image.
Returns
-------
sequence[int]
The extent of the whole output image.
"""
return self._whole_extent
@whole_extent.setter
def whole_extent(self, whole_extent: Sequence[int]) -> None:
"""Set extent of the whole output image.
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
"""
self._whole_extent = whole_extent
self.SetWholeExtent(
whole_extent[0],
whole_extent[1],
whole_extent[2],
whole_extent[3],
whole_extent[4],
whole_extent[5],
)
@property
def direction(self) -> Sequence[float]:
"""Get the direction of the sinusoid.
Returns
-------
sequence[float]
The direction of the sinusoid.
"""
return self.GetDirection()
@direction.setter
def direction(self, direction: Sequence[float]) -> None:
"""Set the direction of the sinusoid.
Parameters
----------
direction : sequence[float]
The direction of the sinusoid.
"""
self.SetDirection(direction)
@property
def period(self) -> float:
"""Get the period of the sinusoid.
Returns
-------
float
The period of the sinusoid in pixel.
"""
return self.GetPeriod()
@period.setter
def period(self, period: float) -> None:
"""Set the period of the sinusoid.
Parameters
----------
period : float
The period of the sinusoid in pixel.
"""
self.SetPeriod(period)
@property
def phase(self) -> Sequence[float]:
"""Get the phase of the sinusoid.
Returns
-------
sequence[float]
The phase of the sinusoid in pixel.
"""
return self.GetPhase()
@phase.setter
def phase(self, phase: Sequence[float]) -> None:
"""Set the phase of the sinusoid.
Parameters
----------
phase : sequence[float]
The phase of the sinusoid in pixel.
"""
self.SetPhase(phase)
@property
def amplitude(self) -> float:
"""Get the magnitude of the sinusoid.
Returns
-------
float
The magnitude of the sinusoid.
"""
return self.GetAmplitude()
@amplitude.setter
def amplitude(self, amplitude: float) -> None:
"""Set the magnitude of the sinusoid.
Parameters
----------
amplitude : float
The magnitude of the sinusoid.
"""
self.SetAmplitude(amplitude)
@property
def output(self):
"""Get the output image as a ImageData.
Returns
-------
pyvista.ImageData
The output image.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class ImageGaussianSource(_vtk.vtkImageGaussianSource):
"""Create a binary image with Gaussian pixel values.
.. versionadded:: 0.44.0
Parameters
----------
center : sequence[float]
The center of the gaussian.
whole_extent : sequence[int]
The extent of the whole output image.
maximum : float
The maximum value of the gaussian.
std : sequence[float]
The standard deviation of the gaussian.
Examples
--------
Create an image of Gaussian pixel values.
>>> import pyvista as pv
>>> source = pv.ImageGaussianSource(
... center=(100, 100, 0),
... whole_extent=(0, 200, 0, 200, 0, 0),
... maximum=255,
... std=100.0,
... )
>>> source.output.plot(cpos="xy")
"""
_new_attr_exceptions: ClassVar[list[str]] = ['_whole_extent', 'whole_extent']
def __init__(self, center=None, whole_extent=None, maximum=None, std=None) -> None:
super().__init__()
if center is not None:
self.center = center
if whole_extent is not None:
self.whole_extent = whole_extent
if maximum is not None:
self.maximum = maximum
if std is not None:
self.std = std
@property
def center(self) -> Sequence[float]:
"""Get the center of the gaussian.
Returns
-------
sequence[float]
The center of the gaussian.
"""
return self.GetCenter()
@center.setter
def center(self, center: Sequence[float]) -> None:
"""Set the center of the gaussian.
Parameters
----------
center : sequence[float]
The center of the gaussian.
"""
self.SetCenter(center)
@property
def whole_extent(self) -> Sequence[int]:
"""Get extent of the whole output image.
Returns
-------
sequence[int]
The extent of the whole output image.
"""
return self._whole_extent
@whole_extent.setter
def whole_extent(self, whole_extent: Sequence[int]) -> None:
"""Set extent of the whole output image.
Parameters
----------
whole_extent : sequence[int]
The extent of the whole output image.
"""
self._whole_extent = whole_extent
self.SetWholeExtent(
whole_extent[0],
whole_extent[1],
whole_extent[2],
whole_extent[3],
whole_extent[4],
whole_extent[5],
)
@property
def maximum(self) -> float:
"""Get the maximum value of the gaussian.
Returns
-------
float
The maximum value of the gaussian.
"""
return self.GetMaximum()
@maximum.setter
def maximum(self, maximum: float) -> None:
"""Set the maximum value of the gaussian.
Parameters
----------
maximum : float
The maximum value of the gaussian.
"""
self.SetMaximum(maximum)
@property
def std(self) -> float:
"""Get the standard deviation of the gaussian.
Returns
-------
float
The standard deviation of the gaussian.
"""
return self.GetStandardDeviation()
@std.setter
def std(self, std: float) -> None:
"""Set the standard deviation of the gaussian.
Parameters
----------
std : float
The standard deviation of the gaussian.
"""
self.SetStandardDeviation(std)
@property
def output(self):
"""Get the output image as a ImageData.
Returns
-------
pyvista.ImageData
The output image.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class ImageGridSource(_vtk.vtkImageGridSource):
"""Create an image of a grid.
.. versionadded:: 0.44.0
Parameters
----------
origin : sequence[float]
The origin of the grid.
extent : sequence[int]
The extent of the whole output image, Default: (0,255,0,255,0,0).
spacing : tuple
The pixel spacing.
Examples
--------
Create an image of a grid.
>>> import pyvista as pv
>>> source = pv.ImageGridSource(
... extent=(0, 20, 0, 20, 0, 0),
... spacing=(1, 1, 1),
... )
>>> source.output.plot(cpos="xy")
"""
def __init__(self, origin=None, extent=None, spacing=None) -> None:
super().__init__()
if origin is not None:
self.origin = origin
if extent is not None:
self.extent = extent
if spacing is not None:
self.spacing = spacing
@property
def origin(self) -> Sequence[float]:
"""Get the origin of the data.
Returns
-------
sequence[float]
The origin of the grid.
"""
return self.GetGridOrigin()
@origin.setter
def origin(self, origin: Sequence[float]) -> None:
"""Set the origin of the data.
Parameters
----------
origin : sequence[float]
The origin of the grid.
"""
self.SetGridOrigin(origin)
@property
def extent(self) -> Sequence[int]:
"""Get extent of the whole output image.
Returns
-------
sequence[int]
The extent of the whole output image.
"""
return self.GetDataExtent()
@extent.setter
def extent(self, extent: Sequence[int]) -> None:
"""Set extent of the whole output image.
Parameters
----------
extent : sequence[int]
The extent of the whole output image.
"""
self.SetDataExtent(extent)
@property
def spacing(self) -> Sequence[float]:
"""Get the spacing of the grid.
Returns
-------
sequence[float]
The pixel spacing.
"""
return self.GetDataSpacing()
@spacing.setter
def spacing(self, spacing: Sequence[float]) -> None:
"""Set the spacing of the grid.
Parameters
----------
spacing : sequence[float]
The pixel spacing.
"""
self.SetDataSpacing(spacing)
@property
def output(self):
"""Get the output image as a ImageData.
Returns
-------
pyvista.ImageData
The output image.
"""
self.Update()
return wrap(self.GetOutput())
|