File: test_parametric_geometry.py

package info (click to toggle)
python-pyvista 0.46.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176,968 kB
  • sloc: python: 94,346; sh: 216; makefile: 70
file content (200 lines) | stat: -rw-r--r-- 5,120 bytes parent folder | download
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
from __future__ import annotations

import numpy as np
import pytest
import vtk

import pyvista as pv


def test_spline():
    theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
    z = np.linspace(-2, 2, 100)
    r = z**2 + 1
    x = r * np.sin(theta)
    y = r * np.cos(theta)

    points = np.column_stack((x, y, z))
    spline = pv.Spline(points, 1000)
    assert spline.n_points == 1000


def test_kochanek_spline():
    theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
    z = np.linspace(-2, 2, 100)
    r = z**2 + 1
    x = r * np.sin(theta)
    y = r * np.cos(theta)

    tension = np.random.default_rng().random(3)
    bias = np.random.default_rng().random(3)
    continuity = np.random.default_rng().random(3)

    n_points = 1000
    points = np.column_stack((x, y, z))
    kochanek_spline = pv.KochanekSpline(
        points, tension=tension, bias=bias, continuity=continuity, n_points=n_points
    )
    assert kochanek_spline.n_points == n_points

    # test default
    kochanek_spline = pv.KochanekSpline(points)
    assert kochanek_spline.n_points == points.shape[0]

    # test invalid
    with pytest.raises(ValueError, match='tension'):
        kochanek_spline = pv.KochanekSpline(
            points, tension=[-2, 0, 0], bias=bias, continuity=continuity, n_points=n_points
        )
    with pytest.raises(ValueError, match='bias'):
        kochanek_spline = pv.KochanekSpline(
            points, tension=tension, bias=[-2, 0, 0], continuity=continuity, n_points=n_points
        )
    with pytest.raises(ValueError, match='continuity'):
        kochanek_spline = pv.KochanekSpline(
            points, tension=tension, bias=bias, continuity=[-2, 0, 0], n_points=n_points
        )


def test_parametric_bohemian_dome():
    geom = pv.ParametricBohemianDome(direction=[0, 0, 1], a=0.5, b=1.5, c=1.0)
    assert geom.n_points


def test_parametric_bour():
    geom = pv.ParametricBour()
    assert geom.n_points


def test_parametric_boy():
    geom = pv.ParametricBoy()
    assert geom.n_points


def test_parametric_catalan_minimal():
    geom = pv.ParametricCatalanMinimal()
    assert geom.n_points


def test_parametric_conic_spiral():
    geom = pv.ParametricConicSpiral()
    assert geom.n_points


def test_parametric_cross_cap():
    geom = pv.ParametricCrossCap()
    assert geom.n_points


def test_parametric_dini():
    geom = pv.ParametricDini()
    assert geom.n_points


def test_parametric_ellipsoid():
    geom = pv.ParametricEllipsoid()
    assert geom.n_points


def test_parametric_enneper():
    geom = pv.ParametricEnneper()
    assert geom.n_points


def test_parametric_figure8_klein():
    geom = pv.ParametricFigure8Klein()
    assert geom.n_points


def test_parametric_henneberg():
    geom = pv.ParametricHenneberg()
    assert geom.n_points


def test_parametric_klein():
    geom = pv.ParametricKlein()
    assert geom.n_points


def test_parametric_kuen():
    geom = pv.ParametricKuen()
    assert geom.n_points


def test_parametric_mobius():
    geom = pv.ParametricMobius()
    assert geom.n_points


def test_parametric_plucker_conoid():
    geom = pv.ParametricPluckerConoid()
    assert geom.n_points


def test_parametric_pseudosphere():
    geom = pv.ParametricPseudosphere()
    assert geom.n_points


def test_parametric_random_hills():
    geom = pv.ParametricRandomHills()
    assert geom.n_points
    geom = pv.ParametricRandomHills(
        number_of_hills=30,
        hill_x_variance=30,
        hill_y_variance=2.5,
        hill_amplitude=2.5,
        random_seed=1,
        x_variance_scale_factor=13,
        y_variance_scale_factor=13,
        amplitude_scale_factor=13,
    )
    assert geom.n_points


def test_parametric_roman():
    geom = pv.ParametricRoman()
    assert geom.n_points


def test_parametric_super_ellipsoid():
    geom = pv.ParametricSuperEllipsoid()
    assert geom.n_points


def test_parametric_super_toroid():
    geom = pv.ParametricSuperToroid()
    assert geom.n_points


def test_parametric_torus():
    geom = pv.ParametricTorus()
    assert geom.n_points


def test_direction():
    geom1 = pv.ParametricEllipsoid(300, 100, 10, direction=[1, 0, 0])
    geom2 = pv.ParametricEllipsoid(300, 100, 10, direction=[0, 1, 0])
    geom3 = pv.ParametricEllipsoid(300, 100, 10, direction=[0, -1, 0])
    assert geom1.n_points
    assert geom2.n_points
    assert geom3.n_points
    points1 = geom1.points
    points2 = geom2.points
    points3 = geom3.points

    assert np.allclose(points1[:, 0], points2[:, 1])
    assert np.allclose(points1[:, 1], -points2[:, 0])
    assert np.allclose(points1[:, 2], points2[:, 2])

    assert np.allclose(points1[:, 0], -points3[:, 1])
    assert np.allclose(points1[:, 1], points3[:, 0])
    assert np.allclose(points1[:, 2], points3[:, 2])


def test_surface_from_para():
    parametric_function = vtk.vtkParametricBour()
    geom = pv.surface_from_para(parametric_function, texture_coordinates=False)
    assert geom.active_texture_coordinates is None
    geom = pv.surface_from_para(parametric_function, texture_coordinates=True)
    assert geom.active_texture_coordinates is not None