Skip to content

Commit b86ba6a

Browse files
committed
[WIP] Caching pivot in Transforms when makes sense
1 parent 2c55d60 commit b86ba6a

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

gempy/core/data/geo_model.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def solutions(self, value):
157157

158158
# TODO: These meshes are in the order of the scalar field
159159
world_coord_vertices = self.input_transform.apply_inverse(dc_mesh.vertices)
160+
world_coord_vertices = self.grid.transform.apply_inverse_with_cached_pivot(world_coord_vertices)
160161

161162
element.vertices = world_coord_vertices
162163
element.edges = (dc_mesh.edges if dc_mesh is not None else None)
@@ -176,11 +177,8 @@ def surface_points_copy(self):
176177
@property
177178
def surface_points_copy_transformed(self) -> SurfacePointsTable:
178179
og_sp = self.surface_points_copy
179-
og_sp.xyz_view = self.grid.transform.apply_with_pivot(
180-
points=og_sp.xyz,
181-
pivot=self.grid.corner_min
182-
)
183-
180+
181+
og_sp.xyz_view = self.grid.transform.apply_with_cached_pivot(og_sp.xyz)
184182
og_sp.xyz_view = self.input_transform.apply(og_sp.xyz)
185183
return og_sp
186184

@@ -205,13 +203,9 @@ def orientations_copy_transformed(self) -> OrientationsTable:
205203
og_or = self.orientations_copy
206204
total_transform: Transform = self.input_transform + self.grid.transform
207205

208-
og_or.xyz_view = self.grid.transform.apply_with_pivot(
209-
points=og_or.xyz,
210-
pivot=self.grid.corner_min
211-
)
212-
206+
og_or.xyz_view = self.grid.transform.apply_with_cached_pivot(og_or.xyz)
213207
og_or.xyz_view = self.input_transform.apply(og_or.xyz)
214-
# og_or.xyz_view = total_transform.apply(og_or.xyz)
208+
215209
og_or.grads_view = total_transform.transform_gradient(og_or.grads)
216210
return og_or
217211

@@ -244,7 +238,7 @@ def extent(self) -> np.ndarray:
244238
def interpolation_input_copy(self):
245239
warnings.warn("This property is deprecated. Use directly "
246240
"`interpolation_input_from_structural_frame` instead.", DeprecationWarning)
247-
241+
248242
if self.structural_frame.is_dirty is False:
249243
return self._interpolationInput
250244

gempy/core/data/grid_modules/grid_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ def _calculate_rotated_box_val(v1, v2):
127127
])
128128

129129
inverted_rotation_matrix = np.linalg.inv(rotation_matrix)
130-
transform = Transform.from_matrix(inverted_rotation_matrix)
131-
132130
# Calculate the extents in the new coordinate system
133131
extent_x = np.linalg.norm(v1)
134132
extent_y = np.linalg.norm(v2)
135133

136134
# We transform the origin point1 to the new coordinates
137-
# [[ 5.47925650e+06 5.70152895e+06 -2.39200000e+02]]
138135
origin_ = [x1, y1, zmin]
139136

140137
xmin, ymin, zmin = origin_
141138
xmax, ymax, zmax = xmin + extent_x, ymin + extent_y, zmin + zmax - zmin
142139

143140
extent = np.array([xmin, xmax, ymin, ymax, zmin, zmax], dtype='float64')
144141

142+
143+
transform = Transform.from_matrix(inverted_rotation_matrix)
144+
transform.cached_pivot = origin_
145145
grid = cls(extent=extent, resolution=resolution, transform=transform)
146146

147147
if plot:

test/test_modules/.benchmarks/test_transformed_space.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_plot_transformed_data_including_grid_transform():
4747
distance_point3=1000,
4848
zmin=model.extent[4],
4949
zmax=model.extent[5],
50-
resolution=np.array([50, 50, 50]),
50+
resolution=np.array([20, 20, 20]),
5151
plot=True
5252
)
5353

@@ -60,12 +60,25 @@ def test_plot_transformed_data_including_grid_transform():
6060
if PLOT:
6161
gpv = require_gempy_viewer()
6262

63+
6364
gpv.plot_3d(
6465
model,
6566
image=False,
6667
transformed_data=True,
6768
show_boundaries=True,
68-
show_lith=True,
69+
show_lith=False,
70+
kwargs_plot_data={
71+
'arrow_size': .01
72+
}
73+
)
74+
75+
76+
gpv.plot_3d(
77+
model,
78+
image=False,
79+
transformed_data=False,
80+
show_boundaries=True,
81+
show_lith=False,
6982
kwargs_plot_data={
7083
'arrow_size': .01
7184
}

0 commit comments

Comments
 (0)