Skip to content

Commit

Permalink
Merge branch 'master' into pynormals
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksnape committed Jul 31, 2018
2 parents df5bd68 + 2a0169a commit 51844a5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 163 deletions.
53 changes: 0 additions & 53 deletions menpo/transform/piecewiseaffine/base.py
Expand Up @@ -2,7 +2,6 @@
from copy import deepcopy
from menpo.base import Copyable
from menpo.transform.base import Alignment, Invertible, Transform
from .fastpwa import CLookupPWA
# TODO View is broken for PWA (TriangleContainmentError)


Expand Down Expand Up @@ -398,55 +397,3 @@ def index_alpha_beta(self, points):
self._iab = PythonPWA.index_alpha_beta(self, points)
self._applied_points = points
return self._iab


class CythonPWA(AbstractPWA):
r"""
A piecewise affine transformation.
The apply method in this case involves dotting the triangle vectors with
the values of alpha and beta found. The calculation of alpha and beta is
done in C, and a hash map is used to cache lookup values.
Parameters
----------
source : :class:`menpo.shape.PointCloud` or :class:`menpo.shape.TriMesh`
The source points. If a TriMesh is provided, the triangulation on
the TriMesh is used. If a :class:`menpo.shape.PointCloud`
is provided, a Delaunay triangulation of the source is performed
automatically.
target : :class:`PointCloud`
The target points. Note that the trilist is entirely decided by
the source.
Raises
------
ValueError
Source and target must both be 2D.
TriangleContainmentError
All points to apply must be contained in a source triangle. Check
`error.points_outside_source_domain` to handle this case.
"""
def __init__(self, source, target):
super(CythonPWA, self).__init__(source, target)
# make sure the source and target satisfy the c requirements
source_c = np.require(self.source.points, dtype=np.float64,
requirements=['C'])
trilist_c = np.require(self.trilist, dtype=np.uint32,
requirements=['C'])
# build the cython wrapped C object and store it locally
self._fastpwa = CLookupPWA(source_c, trilist_c)

def copy(self):
new = Copyable.copy(self)
new._fastpwa = deepcopy(self._fastpwa)
return new

def index_alpha_beta(self, points):
points_c = np.require(points, dtype=np.float64, requirements=['C'])
index, alpha, beta = self._fastpwa.index_alpha_beta(points_c)
if np.any(index < 0):
raise TriangleContainmentError(index < 0)
else:
return index, alpha, beta
89 changes: 0 additions & 89 deletions menpo/transform/piecewiseaffine/fastpwa.pyx

This file was deleted.

23 changes: 5 additions & 18 deletions menpo/transform/test/test_pwa.py
@@ -1,7 +1,6 @@
import menpo
from numpy.testing import assert_equal
from menpo.transform.piecewiseaffine.base import (CythonPWA, CachedPWA,
PythonPWA)
from menpo.transform.piecewiseaffine.base import CachedPWA, PythonPWA

b = menpo.io.import_builtin_asset('breakingbad.jpg').as_masked()
b = b.crop_to_landmarks_proportion(0.1)
Expand All @@ -13,27 +12,15 @@


def test_cached_pwa_same_as_python_pwa():
cached_pwa = CythonPWA(src, tgt)
cached_pwa = CachedPWA(src, tgt)
python_pwa = PythonPWA(src, tgt)
assert_equal(python_pwa.apply(points), cached_pwa.apply(points))


def test_cython_pwa_batch_same():
cached_pwa = CythonPWA(src, tgt)
assert_equal(cached_pwa.apply(points),
cached_pwa.apply(points, batch_size=10))


def test_python_pwa_batch_same():
cached_pwa = PythonPWA(src, tgt)
assert_equal(cached_pwa.apply(points),
cached_pwa.apply(points, batch_size=10))


def test_cython_pwa_same_as_python_pwa():
python = PythonPWA(src, tgt)
cython = CythonPWA(src, tgt)
assert_equal(python.apply(points), cython.apply(points))
python_pwa = PythonPWA(src, tgt)
assert_equal(python_pwa.apply(points),
python_pwa.apply(points, batch_size=10))


def test_cached_pwa_same_twice():
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Expand Up @@ -82,9 +82,6 @@ def build_extension_from_pyx(pyx_path, extra_sources_paths=None):

cython_modules = [
build_extension_from_pyx('menpo/external/skimage/_warps_cy.pyx'),
build_extension_from_pyx(
'menpo/transform/piecewiseaffine/fastpwa.pyx',
extra_sources_paths=['menpo/transform/piecewiseaffine/fastpwa/pwa.cpp']),
build_extension_from_pyx(
'menpo/feature/windowiterator.pyx',
extra_sources_paths=['menpo/feature/cpp/ImageWindowIterator.cpp',
Expand Down

0 comments on commit 51844a5

Please sign in to comment.