光学処理の公開コントラクトとPSFデータ型を定義

このコミットが含まれているのは:
routersys committed 2026-06-23 08:40:26 +09:00
1 親 5bc82b0a4c
コミット 235d83b6bd
10ファイル変更
+272 -1

検索条件に一致するファイルはありません

+7
ファイルの表示
@@ -0,0 +1,7 @@
namespace WaveOptics.Abstractions;
public enum ApertureShape
{
Circular,
RegularPolygon,
}
+8
ファイルの表示
@@ -0,0 +1,8 @@
namespace WaveOptics.Abstractions;
public interface IPsfGenerator
{
OpticalApiVersion ApiVersion { get; }
OpticalCapabilities Capabilities { get; }
PsfGenerationResult Generate(PsfDescriptor descriptor);
}
+6
ファイルの表示
@@ -0,0 +1,6 @@
namespace WaveOptics.Abstractions;
public readonly record struct OpticalApiVersion(int Major, int Minor)
{
public static OpticalApiVersion Current { get; } = new(1, 0);
}
+13
ファイルの表示
@@ -0,0 +1,13 @@
namespace WaveOptics.Abstractions;
[Flags]
public enum OpticalCapabilities
{
None = 0,
MonochromaticPsf = 1,
CircularAperture = 2,
RegularPolygonAperture = 4,
CentralObstruction = 8,
ZernikeAberration = 16,
DirectConvolution = 32,
}
+96
ファイルの表示
@@ -0,0 +1,96 @@
using System.Numerics;
namespace WaveOptics.Abstractions;
public sealed class PsfDescriptor : IEquatable<PsfDescriptor>
{
public int PupilGridSize { get; }
public int PupilDiameterSamples { get; }
public int KernelSize { get; }
public double WavelengthNanometers { get; }
public double FNumber { get; }
public double SensorPixelPitchMicrometers { get; }
public ApertureShape ApertureShape { get; }
public int BladeCount { get; }
public double BladeRotationDegrees { get; }
public double CentralObstructionRatio { get; }
public WavefrontAberration Aberration { get; }
public PsfDescriptor(
int pupilGridSize,
int pupilDiameterSamples,
int kernelSize,
double wavelengthNanometers,
double fNumber,
double sensorPixelPitchMicrometers,
ApertureShape apertureShape,
int bladeCount,
double bladeRotationDegrees,
double centralObstructionRatio,
WavefrontAberration aberration)
{
ArgumentOutOfRangeException.ThrowIfLessThan(pupilGridSize, 64);
ArgumentOutOfRangeException.ThrowIfGreaterThan(pupilGridSize, 2048);
if (!BitOperations.IsPow2((uint)pupilGridSize))
throw new ArgumentException(nameof(pupilGridSize));
ArgumentOutOfRangeException.ThrowIfLessThan(pupilDiameterSamples, 16);
ArgumentOutOfRangeException.ThrowIfGreaterThan(pupilDiameterSamples, pupilGridSize / 2);
ArgumentOutOfRangeException.ThrowIfLessThan(kernelSize, 3);
ArgumentOutOfRangeException.ThrowIfGreaterThan(kernelSize, 255);
if ((kernelSize & 1) == 0)
throw new ArgumentException(nameof(kernelSize));
ValidateFiniteRange(wavelengthNanometers, 380, 780, nameof(wavelengthNanometers));
ValidateFiniteRange(fNumber, 0.5, 64, nameof(fNumber));
ValidateFiniteRange(sensorPixelPitchMicrometers, 0.25, 100, nameof(sensorPixelPitchMicrometers));
if (!Enum.IsDefined(apertureShape))
throw new ArgumentOutOfRangeException(nameof(apertureShape));
ArgumentOutOfRangeException.ThrowIfLessThan(bladeCount, 3);
ArgumentOutOfRangeException.ThrowIfGreaterThan(bladeCount, 32);
ValidateFiniteRange(bladeRotationDegrees, -360, 360, nameof(bladeRotationDegrees));
ValidateFiniteRange(centralObstructionRatio, 0, 0.95, nameof(centralObstructionRatio));
PupilGridSize = pupilGridSize;
PupilDiameterSamples = pupilDiameterSamples;
KernelSize = kernelSize;
WavelengthNanometers = wavelengthNanometers;
FNumber = fNumber;
SensorPixelPitchMicrometers = sensorPixelPitchMicrometers;
ApertureShape = apertureShape;
BladeCount = bladeCount;
BladeRotationDegrees = bladeRotationDegrees;
CentralObstructionRatio = centralObstructionRatio;
Aberration = aberration;
}
static void ValidateFiniteRange(double value, double minimum, double maximum, string name)
{
ArgumentOutOfRangeException.ThrowIfNotEqual(double.IsFinite(value), true, name);
ArgumentOutOfRangeException.ThrowIfLessThan(value, minimum, name);
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maximum, name);
}
public bool Equals(PsfDescriptor? other)
{
return other is not null
&& PupilGridSize == other.PupilGridSize
&& PupilDiameterSamples == other.PupilDiameterSamples
&& KernelSize == other.KernelSize
&& WavelengthNanometers.Equals(other.WavelengthNanometers)
&& FNumber.Equals(other.FNumber)
&& SensorPixelPitchMicrometers.Equals(other.SensorPixelPitchMicrometers)
&& ApertureShape == other.ApertureShape
&& BladeCount == other.BladeCount
&& BladeRotationDegrees.Equals(other.BladeRotationDegrees)
&& CentralObstructionRatio.Equals(other.CentralObstructionRatio)
&& Aberration.Equals(other.Aberration);
}
public override bool Equals(object? obj) => Equals(obj as PsfDescriptor);
public override int GetHashCode()
{
var first = HashCode.Combine(PupilGridSize, PupilDiameterSamples, KernelSize, WavelengthNanometers, FNumber, SensorPixelPitchMicrometers);
var second = HashCode.Combine(ApertureShape, BladeCount, BladeRotationDegrees, CentralObstructionRatio, Aberration);
return HashCode.Combine(first, second);
}
}
+7
ファイルの表示
@@ -0,0 +1,7 @@
namespace WaveOptics.Abstractions;
public readonly record struct PsfDiagnostics(
int OpenPupilSampleCount,
double FocalPlaneSamplePitchMicrometers,
double UnnormalizedKernelEnergy,
double PeakIntensity);
+3
ファイルの表示
@@ -0,0 +1,3 @@
namespace WaveOptics.Abstractions;
public sealed record PsfGenerationResult(PsfKernel Kernel, PsfDiagnostics Diagnostics);
+63
ファイルの表示
@@ -0,0 +1,63 @@
namespace WaveOptics.Abstractions;
public sealed class PsfKernel
{
readonly double[] values;
public int Size { get; }
public ReadOnlyMemory<double> Values => values;
public double this[int x, int y]
{
get
{
ArgumentOutOfRangeException.ThrowIfNegative(x);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(x, Size);
ArgumentOutOfRangeException.ThrowIfNegative(y);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(y, Size);
return values[y * Size + x];
}
}
public PsfKernel(int size, ReadOnlySpan<double> values)
{
ArgumentOutOfRangeException.ThrowIfLessThan(size, 1);
if ((size & 1) == 0)
throw new ArgumentException(nameof(size));
if (values.Length != size * size)
throw new ArgumentException(nameof(values));
this.values = values.ToArray();
for (var index = 0; index < this.values.Length; index++)
{
var value = this.values[index];
if (!double.IsFinite(value) || value < 0)
throw new ArgumentOutOfRangeException(nameof(values));
}
var sum = this.values.Sum();
if (!double.IsFinite(sum) || sum <= 0)
throw new ArgumentOutOfRangeException(nameof(values));
for (var index = 0; index < this.values.Length; index++)
this.values[index] /= sum;
Size = size;
}
public double Sum()
{
var sum = 0d;
var compensation = 0d;
foreach (var value in values)
{
var corrected = value - compensation;
var next = sum + corrected;
compensation = next - sum - corrected;
sum = next;
}
return sum;
}
public double[] ToArray() => (double[])values.Clone();
}
+4 -1
ファイルの表示
@@ -1,9 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>WaveOptics.Abstractions</AssemblyName>
<RootNamespace>WaveOptics.Abstractions</RootNamespace>
<Version>1.0.0</Version>
</PropertyGroup>
</Project>
+65
ファイルの表示
@@ -0,0 +1,65 @@
namespace WaveOptics.Abstractions;
public readonly struct WavefrontAberration : IEquatable<WavefrontAberration>
{
public double DefocusWaves { get; }
public double AstigmatismVerticalWaves { get; }
public double AstigmatismObliqueWaves { get; }
public double ComaHorizontalWaves { get; }
public double ComaVerticalWaves { get; }
public double TrefoilHorizontalWaves { get; }
public double TrefoilVerticalWaves { get; }
public double SphericalWaves { get; }
public WavefrontAberration(
double defocusWaves = 0,
double astigmatismVerticalWaves = 0,
double astigmatismObliqueWaves = 0,
double comaHorizontalWaves = 0,
double comaVerticalWaves = 0,
double trefoilHorizontalWaves = 0,
double trefoilVerticalWaves = 0,
double sphericalWaves = 0)
{
DefocusWaves = Validate(defocusWaves, nameof(defocusWaves));
AstigmatismVerticalWaves = Validate(astigmatismVerticalWaves, nameof(astigmatismVerticalWaves));
AstigmatismObliqueWaves = Validate(astigmatismObliqueWaves, nameof(astigmatismObliqueWaves));
ComaHorizontalWaves = Validate(comaHorizontalWaves, nameof(comaHorizontalWaves));
ComaVerticalWaves = Validate(comaVerticalWaves, nameof(comaVerticalWaves));
TrefoilHorizontalWaves = Validate(trefoilHorizontalWaves, nameof(trefoilHorizontalWaves));
TrefoilVerticalWaves = Validate(trefoilVerticalWaves, nameof(trefoilVerticalWaves));
SphericalWaves = Validate(sphericalWaves, nameof(sphericalWaves));
}
static double Validate(double value, string name)
{
ArgumentOutOfRangeException.ThrowIfNotEqual(double.IsFinite(value), true, name);
ArgumentOutOfRangeException.ThrowIfLessThan(value, -10, name);
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 10, name);
return value;
}
public bool Equals(WavefrontAberration other)
{
return DefocusWaves.Equals(other.DefocusWaves)
&& AstigmatismVerticalWaves.Equals(other.AstigmatismVerticalWaves)
&& AstigmatismObliqueWaves.Equals(other.AstigmatismObliqueWaves)
&& ComaHorizontalWaves.Equals(other.ComaHorizontalWaves)
&& ComaVerticalWaves.Equals(other.ComaVerticalWaves)
&& TrefoilHorizontalWaves.Equals(other.TrefoilHorizontalWaves)
&& TrefoilVerticalWaves.Equals(other.TrefoilVerticalWaves)
&& SphericalWaves.Equals(other.SphericalWaves);
}
public override bool Equals(object? obj) => obj is WavefrontAberration other && Equals(other);
public override int GetHashCode()
{
var first = HashCode.Combine(DefocusWaves, AstigmatismVerticalWaves, AstigmatismObliqueWaves, ComaHorizontalWaves);
var second = HashCode.Combine(ComaVerticalWaves, TrefoilHorizontalWaves, TrefoilVerticalWaves, SphericalWaves);
return HashCode.Combine(first, second);
}
public static bool operator ==(WavefrontAberration left, WavefrontAberration right) => left.Equals(right);
public static bool operator !=(WavefrontAberration left, WavefrontAberration right) => !left.Equals(right);
}