Skip to content

Commit

Permalink
Configurable PixImage functions throw proper exceptions
Browse files Browse the repository at this point in the history
See: #42
  • Loading branch information
hyazinthh committed Oct 19, 2022
1 parent a70e602 commit 6b03bbf
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,10 +1584,15 @@ public override PixImage RemappedPixImage(
ImageInterpolation ip = ImageInterpolation.Cubic
) => Remapped(xMap, xMap, ip);

public PixImage<T> Remapped(
Matrix<float> xMap, Matrix<float> yMap,
ImageInterpolation ip = ImageInterpolation.Cubic
) => new PixImage<T>(Format, s_remappedFun(Volume, xMap, yMap, ip));
public PixImage<T> Remapped(Matrix<float> xMap, Matrix<float> yMap, ImageInterpolation ip = ImageInterpolation.Cubic)
{
if (s_remappedFun == null)
{
throw new NotSupportedException($"No remapping function has been installed via PixImage<{(typeof(T).Name)}>.SetRemappedFun");
}

return new PixImage<T>(Format, s_remappedFun(Volume, xMap, yMap, ip));
}

private static Func<Volume<T>, Matrix<float>, Matrix<float>, ImageInterpolation, Volume<T>> s_remappedFun = null;

Expand Down Expand Up @@ -1618,10 +1623,15 @@ public override PixImage RotatedPixImage(
ImageInterpolation ip = ImageInterpolation.Cubic
) => Rotated(angleInRadiansCCW, resize, ip);

public PixImage<T> Rotated(
double angleInRadiansCCW, bool resize = true,
ImageInterpolation ip = ImageInterpolation.Cubic
) => new PixImage<T>(Format, s_rotatedFun(Volume, angleInRadiansCCW, resize, ip));
public PixImage<T> Rotated(double angleInRadiansCCW, bool resize = true, ImageInterpolation ip = ImageInterpolation.Cubic)
{
if (s_rotatedFun == null)
{
throw new NotSupportedException($"No rotating function has been installed via PixImage<{(typeof(T).Name)}>.SetRotatedFun");
}

return new PixImage<T>(Format, s_rotatedFun(Volume, angleInRadiansCCW, resize, ip));
}

private static Func<Volume<T>, double, bool, ImageInterpolation, Volume<T>> s_rotatedFun = null;

Expand All @@ -1640,6 +1650,11 @@ public PixImage<T> Scaled(
V2d scaleFactor,
ImageInterpolation ip = ImageInterpolation.Cubic)
{
if (s_scaledFun == null)
{
throw new NotSupportedException($"No scaling function has been installed via PixImage<{(typeof(T).Name)}>.SetScaledFun");
}

if (!(scaleFactor.X > 0.0 && scaleFactor.Y > 0.0)) throw new ArgumentOutOfRangeException(nameof(scaleFactor));

// SuperSample is only available for scale factors < 1; fall back to Cubic
Expand Down

0 comments on commit 6b03bbf

Please sign in to comment.