Thursday, March 19, 2009
Plugin Concept in .Net
Here is th VB.NET translation of this excellent Article
http://www.ottoschellekens.nl/PluginConcept.htm
Imports System.Collections.Generic
Imports System.IO
Imports System.Reflection
Public Class PluginHandler
Private Shared _Handler As PluginHandler
Private _haPlugins = New System.Collections.Hashtable
Public Shared Function Create() As PluginHandler
If _Handler Is Nothing Then
_Handler = New PluginHandler()
End If
Return _Handler
End Function
Public Function LoadPlugins() As Int16
Dim PluginsLoaded = 0
'Dim Path = "c:\OceanPlugins"
Dim Path = System.Configuration.ConfigurationManager.AppSettings("RepertoirePlugins")
Dim dir As DirectoryInfo = New DirectoryInfo(Path)
Dim dllFiles() As FileInfo = dir.GetFiles("*.dll")
For Each objInfo As FileInfo In dllFiles
If LoadPlugin(objInfo.FullName) Then
PluginsLoaded += 1
End If
Next
Return PluginsLoaded
End Function
Public Function LoadPlugin(ByVal sFile As String) As Boolean
Dim assPlugin As Assembly = Assembly.LoadFile(sFile)
Dim typPluginTypes() As Type = assPlugin.GetTypes()
Dim bReturn As Boolean = False
For Each typPlugin In typPluginTypes
Dim typInterface As System.Type = typPlugin.GetInterface("Ocean.IOceanPlugin")
If typInterface IsNot Nothing And typPlugin.IsClass Then
Dim objFactory As Object = assPlugin.CreateInstance(typPlugin.FullName)
Dim objPlugin As Ocean.IOceanPlugin = CType(objFactory, Ocean.IOceanPlugin)
_haPlugins.Add(objPlugin.GetShortDescription, objPlugin)
bReturn = True
End If
Next
End Function
Public Function getPlugins() As Hashtable
Return _haPlugins
End Function
End Class
http://www.ottoschellekens.nl/PluginConcept.htm
Imports System.Collections.Generic
Imports System.IO
Imports System.Reflection
Public Class PluginHandler
Private Shared _Handler As PluginHandler
Private _haPlugins = New System.Collections.Hashtable
Public Shared Function Create() As PluginHandler
If _Handler Is Nothing Then
_Handler = New PluginHandler()
End If
Return _Handler
End Function
Public Function LoadPlugins() As Int16
Dim PluginsLoaded = 0
'Dim Path = "c:\OceanPlugins"
Dim Path = System.Configuration.ConfigurationManager.AppSettings("RepertoirePlugins")
Dim dir As DirectoryInfo = New DirectoryInfo(Path)
Dim dllFiles() As FileInfo = dir.GetFiles("*.dll")
For Each objInfo As FileInfo In dllFiles
If LoadPlugin(objInfo.FullName) Then
PluginsLoaded += 1
End If
Next
Return PluginsLoaded
End Function
Public Function LoadPlugin(ByVal sFile As String) As Boolean
Dim assPlugin As Assembly = Assembly.LoadFile(sFile)
Dim typPluginTypes() As Type = assPlugin.GetTypes()
Dim bReturn As Boolean = False
For Each typPlugin In typPluginTypes
Dim typInterface As System.Type = typPlugin.GetInterface("Ocean.IOceanPlugin")
If typInterface IsNot Nothing And typPlugin.IsClass Then
Dim objFactory As Object = assPlugin.CreateInstance(typPlugin.FullName)
Dim objPlugin As Ocean.IOceanPlugin = CType(objFactory, Ocean.IOceanPlugin)
_haPlugins.Add(objPlugin.GetShortDescription, objPlugin)
bReturn = True
End If
Next
End Function
Public Function getPlugins() As Hashtable
Return _haPlugins
End Function
End Class
Tuesday, March 17, 2009
Python Raytracer in 50 Lines of Code
From http://jan.varho.org/blog/programming/python-raytracer-in-50-lines-of-code/comment-page-1/#comment-11
import math
from PIL import Image
def sub(v1, v2): return [x-y for x,y in zip(v1, v2)]
def dot(v1, v2): return sum([x*y for x,y in zip(v1, v2)])
def norm(v): return [x/math.sqrt(dot(v,v)) for x in v]
def trace_sphere(r, s, tmin, color):
sr = sub(s[0], r[0])
dsr = dot(sr, r[1])
d = dsr*dsr - dot(sr,sr) + s[1]
if d < 0: return
d = math.sqrt(d)
t1 = dsr + d
if t1 < 0: return
t2 = dsr - d
if t2 > tmin[0]: return
if t2 < 0:
tmin[0] = t1
else:
tmin[0] = t2
color[:] = [s[2]]
def trace_ray(ray, spheres):
color = [(0, 0, 0)]
tmin = [100000]
for s in spheres:
trace_sphere(ray, s, tmin, color)
return color[0]
red = (255,0,0)
blue = (0,0,255)
spheres = ( ((0,0,100), 100.0, red), ((0,-5,50), 20.0, blue) )
w, h = 200, 200
image = Image.new("RGB", (w, h))
pix = image.load()
for x in range(w):
for y in range(h):
ray = ( (0,0,0), norm(((x-w/2.0)/w, (y-h/2.0)/w, 1)) )
pix[x,y] = trace_ray(ray, spheres)
image.save("out.png")
Simple Ray Tracing Computation
Example of a simple Ray Tracing Computation to compute primary ray and test intersection with a sphere
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtexamp1.htm
http://matthieu-brucher.developpez.com/tutoriels/3D/raytracer/01-introduction/
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtexamp1.htm
http://matthieu-brucher.developpez.com/tutoriels/3D/raytracer/01-introduction/
Sunday, March 15, 2009
jshashtable
shashtable is a JavaScript implementation of a hash table
shashtable is a JavaScript implementation of a hash table
shashtable is a JavaScript implementation of a hash table
Subscribe to:
Posts (Atom)