From 9b819e017af4d0fe7b79a135e1d8b9be5ab577a9 Mon Sep 17 00:00:00 2001 From: Simon Wollwage Date: Wed, 17 Mar 2010 20:13:37 +0100 Subject: [PATCH] - Imported PluginSystem --- Hyperion.Core/Hyperion.Core.csproj | 17 +++ .../PluginSystem/AcceleratorPlugin.cs | 38 +++++++ Hyperion.Core/PluginSystem/AreaLightPlugin.cs | 38 +++++++ Hyperion.Core/PluginSystem/CameraPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/FilmPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/FilterPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/LightPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/MaterialPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/Plugin.cs | 96 ++++++++++++++++ Hyperion.Core/PluginSystem/PluginManager.cs | 103 ++++++++++++++++++ Hyperion.Core/PluginSystem/RendererPlugin.cs | 38 +++++++ Hyperion.Core/PluginSystem/SamplerPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/ShapePlugin.cs | 37 +++++++ .../PluginSystem/SurfaceIntegratorPlugin.cs | 37 +++++++ Hyperion.Core/PluginSystem/TexturePlugin.cs | 47 ++++++++ .../PluginSystem/VolumeIntegratorPlugin.cs | 37 +++++++ Hyperion.Core/RenderOptions.cs | 13 ++- Hyperion.Core/Tools/TextureParameterSet.cs | 85 +++++++++++++++ 18 files changed, 806 insertions(+), 2 deletions(-) create mode 100644 Hyperion.Core/PluginSystem/AcceleratorPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/AreaLightPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/CameraPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/FilmPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/FilterPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/LightPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/MaterialPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/Plugin.cs create mode 100644 Hyperion.Core/PluginSystem/PluginManager.cs create mode 100644 Hyperion.Core/PluginSystem/RendererPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/SamplerPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/ShapePlugin.cs create mode 100644 Hyperion.Core/PluginSystem/SurfaceIntegratorPlugin.cs create mode 100644 Hyperion.Core/PluginSystem/TexturePlugin.cs create mode 100644 Hyperion.Core/PluginSystem/VolumeIntegratorPlugin.cs create mode 100644 Hyperion.Core/Tools/TextureParameterSet.cs diff --git a/Hyperion.Core/Hyperion.Core.csproj b/Hyperion.Core/Hyperion.Core.csproj index 6f6c3b5..2962854 100644 --- a/Hyperion.Core/Hyperion.Core.csproj +++ b/Hyperion.Core/Hyperion.Core.csproj @@ -135,6 +135,22 @@ + + + + + + + + + + + + + + + + @@ -144,6 +160,7 @@ + \ No newline at end of file diff --git a/Hyperion.Core/PluginSystem/AcceleratorPlugin.cs b/Hyperion.Core/PluginSystem/AcceleratorPlugin.cs new file mode 100644 index 0000000..72e74bf --- /dev/null +++ b/Hyperion.Core/PluginSystem/AcceleratorPlugin.cs @@ -0,0 +1,38 @@ + +using System; +using System.Collections.Generic; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of cameras. + /// + public class AcceleratorPlugin : Plugin + { + /// + /// + /// + public delegate IPrimitive CreateAcceleratorDelegate (List primitives, ParameterSet paramSet); + + /// + /// + /// + public CreateAcceleratorDelegate CreateAccelerator; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public AcceleratorPlugin (string name) : base("Accelerators", name) + { + MethodInfo methodInfo = GetMethod ("CreateAccelerator"); + CreateAccelerator = Delegate.CreateDelegate (typeof(CreateAcceleratorDelegate), methodInfo) as CreateAcceleratorDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/AreaLightPlugin.cs b/Hyperion.Core/PluginSystem/AreaLightPlugin.cs new file mode 100644 index 0000000..48671f4 --- /dev/null +++ b/Hyperion.Core/PluginSystem/AreaLightPlugin.cs @@ -0,0 +1,38 @@ + +using System; +using System.Collections.Generic; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of cameras. + /// + public class AreaLightPlugin : Plugin + { + /// + /// + /// + public delegate ILight CreateAreaLightDelegate (Transform objectToWorld, ParameterSet parameters, IShape shape); + + /// + /// + /// + public CreateAreaLightDelegate CreateAreaLight; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public AreaLightPlugin (string name) : base("Lights", name) + { + MethodInfo methodInfo = GetMethod ("CreateAreaLight"); + CreateAreaLight = Delegate.CreateDelegate (typeof(CreateAreaLightDelegate), methodInfo) as CreateAreaLightDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/CameraPlugin.cs b/Hyperion.Core/PluginSystem/CameraPlugin.cs new file mode 100644 index 0000000..ad8b1cf --- /dev/null +++ b/Hyperion.Core/PluginSystem/CameraPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of cameras. + /// + public class CameraPlugin : Plugin + { + /// + /// + /// + public delegate ICamera CreateCameraDelegate (ParameterSet paramSet, Transform worldToCamera, IFilm film); + + /// + /// + /// + public CreateCameraDelegate CreateCamera; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public CameraPlugin (string name) : base("Cameras", name) + { + MethodInfo methodInfo = GetMethod ("CreateCamera"); + CreateCamera = Delegate.CreateDelegate (typeof(CreateCameraDelegate), methodInfo) as CreateCameraDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/FilmPlugin.cs b/Hyperion.Core/PluginSystem/FilmPlugin.cs new file mode 100644 index 0000000..636f518 --- /dev/null +++ b/Hyperion.Core/PluginSystem/FilmPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of films. + /// + public class FilmPlugin : Plugin + { + /// + /// + /// + public delegate IFilm CreateFilmDelegate (ParameterSet paramSet, IFilter filter); + + /// + /// + /// + public CreateFilmDelegate CreateFilm; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public FilmPlugin (string name) : base("Films", name) + { + MethodInfo methodInfo = GetMethod ("CreateFilm"); + CreateFilm = Delegate.CreateDelegate (typeof(CreateFilmDelegate), methodInfo) as CreateFilmDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/FilterPlugin.cs b/Hyperion.Core/PluginSystem/FilterPlugin.cs new file mode 100644 index 0000000..7b1949f --- /dev/null +++ b/Hyperion.Core/PluginSystem/FilterPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of films. + /// + public class FilterPlugin : Plugin + { + /// + /// + /// + public delegate IFilter CreateFilterDelegate (ParameterSet paramSet); + + /// + /// + /// + public CreateFilterDelegate CreateFilter; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public FilterPlugin (string name) : base("Filters", name) + { + MethodInfo methodInfo = GetMethod ("CreateFilter"); + CreateFilter = Delegate.CreateDelegate (typeof(CreateFilterDelegate), methodInfo) as CreateFilterDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/LightPlugin.cs b/Hyperion.Core/PluginSystem/LightPlugin.cs new file mode 100644 index 0000000..30e1d42 --- /dev/null +++ b/Hyperion.Core/PluginSystem/LightPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of cameras. + /// + public class LightPlugin : Plugin + { + /// + /// + /// + public delegate ILight CreateLightDelegate (Transform lightToWorld, ParameterSet paramSet); + + /// + /// + /// + public CreateLightDelegate CreateLight; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public LightPlugin (string name) : base("Lights", name) + { + MethodInfo methodInfo = GetMethod ("CreateLight"); + CreateLight = Delegate.CreateDelegate (typeof(CreateLightDelegate), methodInfo) as CreateLightDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/MaterialPlugin.cs b/Hyperion.Core/PluginSystem/MaterialPlugin.cs new file mode 100644 index 0000000..6852d84 --- /dev/null +++ b/Hyperion.Core/PluginSystem/MaterialPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of cameras. + /// + public class MaterialPlugin : Plugin + { + /// + /// + /// + public delegate IMaterial CreateMaterialDelegate (Transform objectToWorld, TextureParameterSet parameters); + + /// + /// + /// + public CreateMaterialDelegate CreateMaterial; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public MaterialPlugin (string name) : base("Materials", name) + { + MethodInfo methodInfo = GetMethod ("CreateMaterial"); + CreateMaterial = Delegate.CreateDelegate (typeof(CreateMaterialDelegate), methodInfo) as CreateMaterialDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/Plugin.cs b/Hyperion.Core/PluginSystem/Plugin.cs new file mode 100644 index 0000000..6f626ab --- /dev/null +++ b/Hyperion.Core/PluginSystem/Plugin.cs @@ -0,0 +1,96 @@ + +using System; +using System.IO; +using System.Reflection; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// This is the basic Plugin class. So far, a plugin holds track + /// of it's name and a library handle. To use a plugin, the pluginclass + /// has to inherit from Plugin and provide a Creation Method. Afterwards it + /// can be used like this: + /// + /// + /// ICamera cam = PluginManager.CreateCamera ("PerspectiveCamera"); + /// + /// + /// Therefore your class must contain this (again, the camera as an example): + /// + /// + /// public class CameraPlugin : Plugin + /// { + /// delegate ICamera CreateCameraDelegate (); + /// public CreateCameraDelegate CreateCamera; + /// } + /// + /// + public class Plugin + { + /// + /// The plugin's name + /// + private string _name; + + /// + /// The plugin's assembly + /// + private Assembly _assembly; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public Plugin (string category, string name) + { + _name = name; + + string currentDirectory = Directory.GetCurrentDirectory (); + string[] files = Directory.GetFiles (currentDirectory); + string assemblyPath = string.Empty; + + foreach (string file in files) + { + if (file.Contains (category + "." + name + ".dll")) + { + assemblyPath = file; + break; + } + } + + _assembly = Assembly.LoadFile (assemblyPath); + } + + /// + /// Retrieves a pointer to a method in the plugin's assembly + /// + /// + /// The method's name + /// + /// + /// The method info + /// + public MethodInfo GetMethod (string methodName) + { + Type[] types = null; + try + { + types = _assembly.GetTypes (); + } + catch (ReflectionTypeLoadException e) + { + types = e.Types; + } + + foreach (Type type in types) + { + if (type.Name == _name) + return type.GetMethod (methodName); + } + + return null; + } + } +} diff --git a/Hyperion.Core/PluginSystem/PluginManager.cs b/Hyperion.Core/PluginSystem/PluginManager.cs new file mode 100644 index 0000000..383e501 --- /dev/null +++ b/Hyperion.Core/PluginSystem/PluginManager.cs @@ -0,0 +1,103 @@ + +using System.Collections.Generic; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Geometry; +using Hyperion.Core.Tools; + +namespace Hyperion.Core.PluginSystem +{ + public static class PluginManager + { + public static ICamera CreateCamera (string name, ParameterSet paramSet, Transform worldToCamera, IFilm film) + { + CameraPlugin plugin = new CameraPlugin (name); + return plugin.CreateCamera (paramSet, worldToCamera, film); + } + + public static IFilm CreateFilm (string name, ParameterSet paramSet, IFilter filter) + { + FilmPlugin plugin = new FilmPlugin (name + "Film"); + return plugin.CreateFilm (paramSet, filter); + } + + public static ISurfaceIntegrator CreateSurfaceIntegrator (string name, ParameterSet paramSet) + { + SurfaceIntegratorPlugin plugin = new SurfaceIntegratorPlugin (name); + return plugin.CreateSurfaceIntegrator (paramSet); + } + + public static IVolumeIntegrator CreateVolumeIntegrator (string name, ParameterSet paramSet) + { + VolumeIntegratorPlugin plugin = new VolumeIntegratorPlugin (name); + return plugin.CreateVolumeIntegrator (paramSet); + } + + public static ITexture CreateDoubleTexture (string name, Transform textureToWorld, TextureParameterSet parameters) + { + TexturePlugin plugin = new TexturePlugin (name); + return plugin.CreateDoubleTexture (textureToWorld, parameters); + } + + public static ITexture CreateSpectrumTexture (string name, Transform textureToWorld, TextureParameterSet parameters) + { + TexturePlugin plugin = new TexturePlugin (name); + return plugin.CreateSpectrumTexture (textureToWorld, parameters); + } + + public static IPrimitive CreateAccelerator (string name, List primitives, ParameterSet parameters) + { + AcceleratorPlugin plugin = new AcceleratorPlugin (name); + return plugin.CreateAccelerator (primitives, parameters); + } + + public static IRenderer CreateRenderer (string name, ISampler sampler, ICamera camera, ISurfaceIntegrator surfaceIntegrator, IVolumeIntegrator volumeIntegrator) + { + RendererPlugin plugin = new RendererPlugin (name); + return plugin.CreateRenderer (sampler, camera, surfaceIntegrator, volumeIntegrator); + } + + public static IShape CreateShape (string name, Transform objectToWorld, bool reverseOrientation, ParameterSet parameters) + { + ShapePlugin plugin = new ShapePlugin (name); + return plugin.CreateShape (objectToWorld, reverseOrientation, parameters); + } + + public static AreaLight CreateAreaLight (string name, Transform objectToWorld, ParameterSet parameters, IShape shape) + { + if (name == "AreaLight") + { + Spectrum L = parameters.FindOneSpectrum ("L", new Spectrum (1.0)); + int numberOfSamples = parameters.FindOneInt ("nsamples", 1); + //return new AreaLight (objectToWorld, L, numberOfSamples, shape); + return null; + } + AreaLightPlugin plugin = new AreaLightPlugin (name); + return plugin.CreateAreaLight (objectToWorld, parameters, shape) as AreaLight; + } + + public static IMaterial CreateMaterial (string name, Transform objectToWorld, TextureParameterSet parameters) + { + MaterialPlugin plugin = new MaterialPlugin (name); + return plugin.CreateMaterial (objectToWorld, parameters); + } + + public static IFilter CreateFilter (string name, ParameterSet parameters) + { + FilterPlugin plugin = new FilterPlugin (name); + IFilter filter = plugin.CreateFilter (parameters); + return filter; + } + + public static ISampler CreateSampler (string name, ParameterSet parameters, IFilm film) + { + SamplerPlugin plugin = new SamplerPlugin (name); + return plugin.CreateSampler (parameters, film); + } + + public static ILight CreateLight (string name, Transform lightToWorld, ParameterSet parameters) + { + LightPlugin plugin = new LightPlugin (name); + return plugin.CreateLight (lightToWorld, parameters); + } + } +} diff --git a/Hyperion.Core/PluginSystem/RendererPlugin.cs b/Hyperion.Core/PluginSystem/RendererPlugin.cs new file mode 100644 index 0000000..cc2cd4f --- /dev/null +++ b/Hyperion.Core/PluginSystem/RendererPlugin.cs @@ -0,0 +1,38 @@ + +using System; +using System.Collections.Generic; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of renderers + /// + public class RendererPlugin : Plugin + { + /// + /// + /// + public delegate IRenderer CreateRendererDelegate (ISampler sampler, ICamera camera, ISurfaceIntegrator surfaceIntegrator, IVolumeIntegrator volumeIntegrator); + + /// + /// + /// + public CreateRendererDelegate CreateRenderer; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public RendererPlugin (string name) : base("Renderers", name) + { + MethodInfo methodInfo = GetMethod ("CreateRenderer"); + CreateRenderer = Delegate.CreateDelegate (typeof(CreateRendererDelegate), methodInfo) as CreateRendererDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/SamplerPlugin.cs b/Hyperion.Core/PluginSystem/SamplerPlugin.cs new file mode 100644 index 0000000..2c76010 --- /dev/null +++ b/Hyperion.Core/PluginSystem/SamplerPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of films. + /// + public class SamplerPlugin : Plugin + { + /// + /// + /// + public delegate ISampler CreateSamplerDelegate (ParameterSet paramSet, IFilm film); + + /// + /// + /// + public CreateSamplerDelegate CreateSampler; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public SamplerPlugin (string name) : base("Samplers", name) + { + MethodInfo methodInfo = GetMethod ("CreateSampler"); + CreateSampler = Delegate.CreateDelegate (typeof(CreateSamplerDelegate), methodInfo) as CreateSamplerDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/ShapePlugin.cs b/Hyperion.Core/PluginSystem/ShapePlugin.cs new file mode 100644 index 0000000..795be4e --- /dev/null +++ b/Hyperion.Core/PluginSystem/ShapePlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of cameras. + /// + public class ShapePlugin : Plugin + { + /// + /// + /// + public delegate IShape CreateShapeDelegate (Transform objectToWorld, bool reverse, ParameterSet paramSet); + + /// + /// + /// + public CreateShapeDelegate CreateShape; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public ShapePlugin (string name) : base("Shapes", name) + { + MethodInfo methodInfo = GetMethod ("CreateShape"); + CreateShape = Delegate.CreateDelegate (typeof(CreateShapeDelegate), methodInfo) as CreateShapeDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/SurfaceIntegratorPlugin.cs b/Hyperion.Core/PluginSystem/SurfaceIntegratorPlugin.cs new file mode 100644 index 0000000..f35b6d5 --- /dev/null +++ b/Hyperion.Core/PluginSystem/SurfaceIntegratorPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of surface integrators. + /// + public class SurfaceIntegratorPlugin : Plugin + { + /// + /// + /// + public delegate ISurfaceIntegrator CreateSurfaceIntegratorDelegate (ParameterSet paramSet); + + /// + /// + /// + public CreateSurfaceIntegratorDelegate CreateSurfaceIntegrator; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public SurfaceIntegratorPlugin (string name) : base("Integrators", name) + { + MethodInfo methodInfo = GetMethod ("CreateSurfaceIntegrator"); + CreateSurfaceIntegrator = Delegate.CreateDelegate (typeof(CreateSurfaceIntegratorDelegate), methodInfo) as CreateSurfaceIntegratorDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/TexturePlugin.cs b/Hyperion.Core/PluginSystem/TexturePlugin.cs new file mode 100644 index 0000000..01fe596 --- /dev/null +++ b/Hyperion.Core/PluginSystem/TexturePlugin.cs @@ -0,0 +1,47 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of textures. + /// + public class TexturePlugin : Plugin + { + /// + /// + /// + public delegate ITexture CreateDoubleTextureDelegate (Transform worldToTexture, TextureParameterSet paramSet); + /// + /// + /// + public delegate ITexture CreateSpectrumTextureDelegate (Transform worldToTexture, TextureParameterSet paramSet); + + /// + /// + /// + public CreateDoubleTextureDelegate CreateDoubleTexture; + + /// + /// + /// + public CreateSpectrumTextureDelegate CreateSpectrumTexture; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public TexturePlugin (string name) : base("Textures", name) + { + MethodInfo methodInfo = GetMethod ("CreateTexture"); + CreateDoubleTexture = Delegate.CreateDelegate (typeof(CreateDoubleTextureDelegate), methodInfo) as CreateDoubleTextureDelegate; + CreateSpectrumTexture = Delegate.CreateDelegate (typeof(CreateSpectrumTextureDelegate), methodInfo) as CreateSpectrumTextureDelegate; + } + } +} diff --git a/Hyperion.Core/PluginSystem/VolumeIntegratorPlugin.cs b/Hyperion.Core/PluginSystem/VolumeIntegratorPlugin.cs new file mode 100644 index 0000000..271ccd4 --- /dev/null +++ b/Hyperion.Core/PluginSystem/VolumeIntegratorPlugin.cs @@ -0,0 +1,37 @@ + +using System; +using System.Reflection; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Tools; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.PluginSystem +{ + /// + /// Plugin for all kinds of volume integrators. + /// + public class VolumeIntegratorPlugin : Plugin + { + /// + /// + /// + public delegate IVolumeIntegrator CreateVolumeIntegratorDelegate (ParameterSet paramSet); + + /// + /// + /// + public CreateVolumeIntegratorDelegate CreateVolumeIntegrator; + + /// + /// Initialize the plugin and it's name + /// + /// + /// The plugin's name + /// + public VolumeIntegratorPlugin (string name) : base("Integrators", name) + { + MethodInfo methodInfo = GetMethod ("CreateVolumeIntegrator"); + CreateVolumeIntegrator = Delegate.CreateDelegate (typeof(CreateVolumeIntegratorDelegate), methodInfo) as CreateVolumeIntegratorDelegate; + } + } +} diff --git a/Hyperion.Core/RenderOptions.cs b/Hyperion.Core/RenderOptions.cs index 19e7058..9d1de56 100644 --- a/Hyperion.Core/RenderOptions.cs +++ b/Hyperion.Core/RenderOptions.cs @@ -3,6 +3,7 @@ using Hyperion.Core.Tools; using Hyperion.Core.Geometry; using Hyperion.Core.Interfaces; +using Hyperion.Core.PluginSystem; namespace Hyperion.Core { @@ -43,12 +44,20 @@ public RenderOptions () public Scene CreateScene () { - return null; + IPrimitive accelerator = PluginManager.CreateAccelerator (AcceleratorName, Primitives, AcceleratorParameters); + return new Scene (accelerator, Lights, null); } public IRenderer CreateRenderer () { - return null; + IFilter filter = PluginManager.CreateFilter (FilterName, FilterParameters); + IFilm film = PluginManager.CreateFilm (FilmName, FilmParameters, filter); + ICamera camera = PluginManager.CreateCamera (CameraName, CameraParameters, WorldToCamera, film); + ISurfaceIntegrator surfaceIntegrator = PluginManager.CreateSurfaceIntegrator (SurfaceIntegratorName, SurfaceIntegratorParameters); + IVolumeIntegrator volumeIntegrator = PluginManager.CreateVolumeIntegrator (VolumeIntegratorName, VolumeIntegratorParameters); + ISampler sampler = PluginManager.CreateSampler (SamplerName, SamplerParameters, film); + + return PluginManager.CreateRenderer ("Sampler", sampler, camera, surfaceIntegrator, volumeIntegrator); } } } diff --git a/Hyperion.Core/Tools/TextureParameterSet.cs b/Hyperion.Core/Tools/TextureParameterSet.cs new file mode 100644 index 0000000..7065f44 --- /dev/null +++ b/Hyperion.Core/Tools/TextureParameterSet.cs @@ -0,0 +1,85 @@ + +using System; +using System.Collections.Generic; +using Hyperion.Core.Interfaces; +using Hyperion.Core.Geometry; + +namespace Hyperion.Core.Tools +{ + public sealed class ConstantTexture : ITexture + { + /// + /// + /// + private T _value; + + /// + /// + /// + public ConstantTexture (T val) + { + _value = val; + } + + /// + /// + /// + /// + /// A + /// + /// + /// A + /// + public T Evaluate (DifferentialGeometry geom) + { + return _value; + } + } + + public sealed class TextureParameterSet + { + private ParameterSet GeometryParameters; + private ParameterSet MaterialParameters; + private Dictionary> DoubleTextures; + private Dictionary> SpectrumTextures; + + public TextureParameterSet (ParameterSet geometryParameters, ParameterSet materialParameters, + Dictionary> ft, Dictionary> st) + { + this.GeometryParameters = geometryParameters; + this.MaterialParameters = materialParameters; + this.DoubleTextures = ft; + this.SpectrumTextures = st; + } + + public ITexture GetSpectrumTexture (string name, Spectrum def) + { + string n = GeometryParameters.FindTexture (name); + if (n == "" || n == string.Empty || n == null) + n = MaterialParameters.FindTexture (name); + if (n == "" && n != string.Empty && n != null) + { + if (SpectrumTextures.ContainsKey (n)) + return SpectrumTextures[n]; + } + + Spectrum val = GeometryParameters.FindOneSpectrum (name, MaterialParameters.FindOneSpectrum (name, def)); + return new ConstantTexture (val); + } + + public ITexture GetDoubleTexture (string name, double def) + { + string n = GeometryParameters.FindTexture (name); + if (n == "" || n == string.Empty || n == null) + n = MaterialParameters.FindTexture (name); + if (n == "" && n != string.Empty && n != null) + { + if (DoubleTextures.ContainsKey (n)) + return DoubleTextures[n]; + } + + double val = GeometryParameters.FindOneDouble (name, MaterialParameters.FindOneDouble (name, def)); + return new ConstantTexture (val); + } + } +}