Skip to content

Commit

Permalink
Merge pull request openalea#46 from AurelienBesnier/master
Browse files Browse the repository at this point in the history
updating numpy + vtk functions
  • Loading branch information
pradal authored Oct 3, 2024
2 parents 0d9d52a + 3995cc4 commit 50918da
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ venv.bak/
/site

# mypy
.mypy_cache/
.mypy_cache/

# vscode
.vscode
4 changes: 2 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: openalea.phenomenal
version: "1.9.2"
version: "1.9.3"

source:
path: ..
Expand All @@ -10,12 +10,12 @@ build:
preserve_egg_dir: True
string: phenomenal
script:
- {{PYTHON}} setup.py build_ext -j{{ CPU_COUNT }}
- {{ PYTHON }} -m pip install . -vv

requirements:
host:
- python
- setuptools
- numpy
- scipy
- cython
Expand Down
13 changes: 6 additions & 7 deletions src/openalea/phenomenal/calibration/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def rotation_matrix(angle, direction, point=None):
M[:3, :3] = R
if point is not None:
# rotation not around origin
point = numpy.array(point[:3], dtype=numpy.float64, copy=False)
point = numpy.array(point[:3], dtype=numpy.float64)
M[:3, 3] = point - numpy.dot(R, point)
return M

Expand All @@ -356,7 +356,7 @@ def rotation_from_matrix(matrix):
True
"""
R = numpy.array(matrix, dtype=numpy.float64, copy=False)
R = numpy.array(matrix, dtype=numpy.float64)
R33 = R[:3, :3]
# direction: unit eigenvector of R33 corresponding to eigenvalue of 1
w, W = numpy.linalg.eig(R33.T)
Expand Down Expand Up @@ -491,12 +491,11 @@ def projection_matrix(point, normal, direction=None,
"""
M = numpy.identity(4)
point = numpy.array(point[:3], dtype=numpy.float64, copy=False)
point = numpy.array(point[:3], dtype=numpy.float64)
normal = unit_vector(normal[:3])
if perspective is not None:
# perspective projection
perspective = numpy.array(perspective[:3], dtype=numpy.float64,
copy=False)
perspective = numpy.array(perspective[:3], dtype=numpy.float64)
M[0, 0] = M[1, 1] = M[2, 2] = numpy.dot(perspective-point, normal)
M[:3, :3] -= numpy.outer(perspective, normal)
if pseudo:
Expand All @@ -509,7 +508,7 @@ def projection_matrix(point, normal, direction=None,
M[3, 3] = numpy.dot(perspective, normal)
elif direction is not None:
# parallel projection
direction = numpy.array(direction[:3], dtype=numpy.float64, copy=False)
direction = numpy.array(direction[:3], dtype=numpy.float64)
scale = numpy.dot(direction, normal)
M[:3, :3] -= numpy.outer(direction, normal) / scale
M[:3, 3] = direction * (numpy.dot(point, normal) / scale)
Expand Down Expand Up @@ -552,7 +551,7 @@ def projection_from_matrix(matrix, pseudo=False):
True
"""
M = numpy.array(matrix, dtype=numpy.float64, copy=False)
M = numpy.array(matrix, dtype=numpy.float64)
M33 = M[:3, :3]
w, V = numpy.linalg.eig(M)
i = numpy.where(abs(numpy.real(w) - 1.0) < 1e-8)[0]
Expand Down
2 changes: 1 addition & 1 deletion src/openalea/phenomenal/mesh/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import division, print_function, absolute_import

import vtk
import vtk.util.numpy_support
import vtkmodules.util.numpy_support
import numpy
import math
import skimage.measure
Expand Down
9 changes: 5 additions & 4 deletions src/openalea/phenomenal/mesh/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from __future__ import division, print_function, absolute_import

import vtk
import vtk.util.numpy_support
import vtkmodules.util.numpy_support
import vtkmodules

from .vtk_transformation import (from_vertices_faces_to_vtk_poly_data)
# ==============================================================================
Expand Down Expand Up @@ -47,17 +48,17 @@ def read_ply_to_vertices_faces(filename):

vtk_poly_data = ply_reader.GetOutput()

vertices = vtk.util.numpy_support.vtk_to_numpy(
vertices = vtkmodules.util.numpy_support.vtk_to_numpy(
vtk_poly_data.GetPoints().GetData())

faces = vtk.util.numpy_support.vtk_to_numpy(
faces = vtkmodules.util.numpy_support.vtk_to_numpy(
vtk_poly_data.GetPolys().GetData())

faces = faces.reshape((len(faces) // 4, 4))

colors = vtk_poly_data.GetPointData().GetScalars()
if colors is not None:
colors = vtk.util.numpy_support.vtk_to_numpy(colors)
colors = vtkmodules.util.numpy_support.vtk_to_numpy(colors)

return vertices, faces[:, 1:], colors

Expand Down
10 changes: 5 additions & 5 deletions src/openalea/phenomenal/mesh/vtk_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import division, print_function, absolute_import

import vtk
import vtk.util.numpy_support
import vtkmodules.util.numpy_support
import operator

# ==============================================================================
Expand Down Expand Up @@ -105,10 +105,10 @@ def make_vtk_id_list(it):

def from_vtk_poly_data_to_vertices_faces(vtk_poly_data):

vertices = vtk.util.numpy_support.vtk_to_numpy(
vertices = vtkmodules.util.numpy_support.vtk_to_numpy(
vtk_poly_data.GetPoints().GetData())

faces = vtk.util.numpy_support.vtk_to_numpy(
faces = vtkmodules.util.numpy_support.vtk_to_numpy(
vtk_poly_data.GetPolys().GetData())

faces = faces.reshape((len(faces) // 4, 4))
Expand All @@ -126,12 +126,12 @@ def from_numpy_matrix_to_vtk_image_data(data_matrix):
image_data.SetSpacing(1.0, 1.0, 1.0)

if vtk.VTK_MAJOR_VERSION < 6:
image_data.SetScalarType(vtk.util.numpy_support.get_vtk_array_type(
image_data.SetScalarType(vtkmodules.util.numpy_support.get_vtk_array_type(
data_matrix.dtype))
image_data.SetNumberOfScalarComponents(1)
image_data.AllocateScalars()
else:
image_data.AllocateScalars(vtk.util.numpy_support.get_vtk_array_type(
image_data.AllocateScalars(vtkmodules.util.numpy_support.get_vtk_array_type(
data_matrix.dtype), 1)

lx, ly, lz = image_data.GetDimensions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def stem_detection(stem_segment_voxel, stem_segment_path, voxels_size,
window_length = max(4, len(nodes_length) // 8)
window_length = window_length + 1 if window_length % 2 == 0 else window_length
smooth_distances = scipy.signal.savgol_filter(
numpy.array(distances, dtype=numpy.uint8),
numpy.array(distances, dtype=numpy.uint16),
window_length=window_length,
polyorder=2)

Expand Down
4 changes: 2 additions & 2 deletions src/openalea/phenomenal/tracking/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def insert_gaps(all_sequences, seq_indexes, alignment):
for gi in gap_indexes:

if all_sequences2[si].size == 0:
all_sequences2[si] = np.full((1, vec_len), np.NAN)
all_sequences2[si] = np.full((1, vec_len), np.nan)
else:
all_sequences2[si] = np.insert(all_sequences2[si], gi, np.NAN, 0)
all_sequences2[si] = np.insert(all_sequences2[si], gi, np.nan, 0)

return all_sequences2

Expand Down
2 changes: 1 addition & 1 deletion src/openalea/phenomenal/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

major = 1
minor = 9
post = 2
post = 3

__version__ = ".".join([str(s) for s in (major, minor, post)])
# }}

0 comments on commit 50918da

Please sign in to comment.