Permalink
Browse files

added files (copy from OpenNI)

  • Loading branch information...
1 parent 70d8e3a commit 7bcac3080ce9e71daf4f1bdfaccafd26681baddc @elliotwoods committed Nov 5, 2011
@@ -0,0 +1,99 @@
+#region usings
+using System;
+using System.ComponentModel.Composition;
+using System.Drawing;
+using System.Threading;
+
+using VVVV.PluginInterfaces.V1;
+using VVVV.PluginInterfaces.V2;
+using VVVV.Utils.VMath;
+using VVVV.Core.Logging;
+
+using ThreadState = System.Threading.ThreadState;
+using System.Collections.Generic;
+
+using OpenNI;
+using Emgu.CV;
+using Emgu.CV.Structure;
+
+using VVVV.Nodes.EmguCV;
+
+#endregion usings
+
+namespace VVVV.Nodes.OpenNI
+{
+
+ class OpenNIContext {
+ public Context context;
+ public bool running = false;
+ }
+
+ #region PluginInfo
+ [PluginInfo(Name = "Context", Category = "OpenNI", Help = "OpenNI context loader", Tags = "")]
+ #endregion PluginInfo
+ public class OpenNIContextNode : IPluginEvaluate, IDisposable
+ {
+ #region fields & pins
+ [Input("Filename", StringType=StringType.Filename)]
+ ISpread<string> FPinInFilename;
+
+ [Input("Open", IsBang = true, IsSingle = true)]
+ ISpread<bool> FPinInOpen;
+
+ [Output("Context")]
+ ISpread<OpenNIContext> FPinOutContext;
+
+ [Output("Status")]
+ ISpread<String> FPinOutStatus;
+
+ [Import]
+ ILogger FLogger;
+
+ string FConfig;
+ Context FContext;
+ OpenNIContext FOutput = new OpenNIContext();
+
+ #endregion fields & pins
+
+ [ImportingConstructor]
+ public OpenNIContextNode(IPluginHost host)
+ {
+
+ }
+
+ public void Dispose()
+ {
+
+ }
+
+ //called when data for any output pin is requested
+ public void Evaluate(int SpreadMax)
+ {
+ if (FPinInOpen[0] && FPinInFilename[0] != "")
+ {
+ FConfig = FPinInFilename[0];
+
+ try
+ {
+ FContext = new Context();
+ FContext.RunXmlScriptFromFileEx(FPinInFilename[0]);
+ FContext.GlobalMirror = false;
+
+ FOutput.context = FContext;
+ FOutput.running = true;
+ FPinOutStatus[0] = "OK";
+ }
+ catch (StatusException e)
+ {
+ FLogger.Log(LogType.Error, e.Message);
+ FOutput.running = false;
+ FPinOutStatus[0] = e.Message;
+ }
+ }
+
+ FPinOutContext[0] = FOutput;
+
+ }
+
+ }
+}
View
@@ -0,0 +1,189 @@
+#region usings
+using System;
+using System.ComponentModel.Composition;
+using System.Drawing;
+using System.Threading;
+
+using VVVV.PluginInterfaces.V1;
+using VVVV.PluginInterfaces.V2;
+using VVVV.Utils.VMath;
+using VVVV.Core.Logging;
+
+using ThreadState = System.Threading.ThreadState;
+using System.Collections.Generic;
+
+using OpenNI;
+using System.Runtime.InteropServices;
+
+using Emgu.Util;
+using Emgu.CV;
+using Emgu.CV.Structure;
+
+using VVVV.Nodes.EmguCV;
+
+#endregion usings
+
+namespace VVVV.Nodes.OpenNI
+{
+ #region PluginInfo
+ [PluginInfo(Name = "Images", Category = "OpenNI", Help = "OpenNI Image generator", Tags = "")]
+ #endregion PluginInfo
+ public class OpenNIImageNode : IPluginEvaluate, IDisposable
+ {
+ [DllImport("msvcrt.dll", EntryPoint = "memcpy")]
+ public unsafe static extern void CopyMemory(IntPtr pDest, IntPtr pSrc, int length);
+
+ #region fields & pins
+ [Input("Context")]
+ ISpread<OpenNIContext> FPinInContext;
+
+ [Output("RGB")]
+ ISpread<ImageRGB> FPinOutRGB;
+
+ [Output("Depth")]
+ ISpread<ImageL16> FPinOutDepth;
+
+ [Output("World")]
+ ISpread<ImageRGB32F> FPinOutWorld;
+
+
+ [Output("Status")]
+ ISpread<String> FPinOutStatus;
+
+ [Import]
+ ILogger FLogger;
+
+ string FConfig;
+ OpenNIContext FContext;
+ bool FRunning = false;
+
+ ImageGenerator FImageGenerator;
+ DepthGenerator FDepthGenerator;
+
+ ImageRGB FImageRGB;
+ ImageL16 FImageDepth;
+ ImageRGB32F FImageWorld;
+
+ Image<Bgr, byte> FImageRGBBuffer;
+ Image<Gray, ushort> FImageDepthBuffer;
+ Image<Rgb, float> FImageWorldBuffer;
+
+
+ Thread FThread;
+ #endregion fields & pins
+
+ [ImportingConstructor]
+ public OpenNIImageNode(IPluginHost host)
+ {
+
+ }
+
+ public void Dispose()
+ {
+
+ }
+
+ //called when data for any output pin is requested
+ public void Evaluate(int SpreadMax)
+ {
+ if (FPinInContext[0] != FContext)
+ {
+ FContext = FPinInContext[0];
+ }
+
+ if (FContext == null)
+ {
+ FRunning = false;
+ return;
+ }
+
+ if (FContext.running && !FRunning && FContext.context != null)
+ {
+ try
+ {
+ FImageGenerator = FContext.context.FindExistingNode(global::OpenNI.NodeType.Image) as ImageGenerator;
+ FDepthGenerator = FContext.context.FindExistingNode(global::OpenNI.NodeType.Depth) as DepthGenerator;
+ FDepthGenerator.AlternativeViewpointCapability.SetViewpoint(FImageGenerator);
+
+ FImageRGB = new ImageRGB();
+ FImageDepth = new ImageL16();
+ FImageWorld = new ImageRGB32F();
+
+ Size size = new Size(640, 480);
+ FImageRGBBuffer = new Image<Bgr, byte>(size);
+ FImageDepthBuffer = new Image<Gray,ushort>(size);
+ FImageWorldBuffer = new Image<Rgb, float>(size);
+
+ FPinOutRGB[0] = FImageRGB;
+ FPinOutDepth[0] = FImageDepth;
+ FPinOutWorld[0] = FImageWorld;
+
+ FThread = new Thread(fnThread);
+ FRunning = true;
+ FThread.Start();
+ FPinOutStatus[0] = "OK";
+ }
+ catch (StatusException e)
+ {
+ FRunning = false;
+ FPinOutStatus[0] = e.Message;
+ }
+ }
+
+
+ }
+
+ private unsafe void fnThread()
+ {
+ while (FRunning)
+ {
+ this.FContext.context.WaitOneUpdateAll(this.FDepthGenerator);
+
+ byte* rgbs = (byte*)FImageGenerator.ImageMapPtr.ToPointer();
+ byte* rgbd = (byte*)FImageRGBBuffer.MIplImage.imageData.ToPointer();
+
+ for (int i=0; i<640*480; i++) {
+ rgbd[2] = rgbs[0];
+ rgbd[1] = rgbs[1];
+ rgbd[0] = rgbs[2];
+ rgbs += 3;
+ rgbd += 3;
+ }
+ //CopyMemory(FImageRGBBuffer.MIplImage.imageData, FImageGenerator.ImageMapPtr, 640 * 480 * 3);
+ CopyMemory(FImageDepthBuffer.MIplImage.imageData, FDepthGenerator.DepthMapPtr, 640 * 480 * 2);
+
+ fillWorld();
+ FImageRGB.SetImage(FImageRGBBuffer);
+ FImageDepth.SetImage(FImageDepthBuffer);
+ FImageWorld.SetImage(FImageWorldBuffer);
+ }
+ }
+
+ private unsafe void fillWorld()
+ {
+ float* DataXYZ = (float*)FImageWorldBuffer.MIplImage.imageData;
+ ushort* DataDepth = (ushort*)FImageDepthBuffer.MIplImage.imageData;
+
+ //calculate world positions and move pointer
+ for (int iY = 0; iY < 480; iY++)
+ for (int iX = 0; iX < 640; iX++, DataXYZ += 3, DataDepth++)
+ DepthToWorld(iX, iY, DataDepth[0], DataXYZ);
+ }
+
+ const float fx_d = 1.0f / 5.9421434211923247e+02f;
+ const float fy_d = 1.0f / 5.9104053696870778e+02f;
+ const float cx_d = 3.3930780975300314e+02f;
+ const float cy_d = 2.4273913761751615e+02f;
+
+ private unsafe void DepthToWorld(int x, int y, int depthValue, float* data)
+ {
+ //adapted from http://graphics.stanford.edu/~mdfisher/Kinect.html
+
+ //presume we're in mm units
+ data[2] = (float)depthValue / 1000.0f;
+ data[0] = ((float)x - cx_d) * fx_d * data[2];
+ data[1] = -((float)y - cy_d) * fy_d * data[2];
+ }
+
+ }
+}
View
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("VVVV.Nodes.ImageCache")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("VVVV.Nodes.ImageCache")]
+[assembly: AssemblyCopyright("Copyright © 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("19cf950b-0917-4d38-8424-00557c2617d2")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
@@ -0,0 +1,67 @@
+<!DOCTYPE PATCH SYSTEM "http://vvvv.org/versions/vvvv45beta26.dtd" >
+ <PATCH nodename="C:\kimchiandchips\VVVV.Research\VVVV.Nodes.OpenNI\Samples\0. Context.v4p" filename="C:\kimchiandchips\VVVV.Research\VVVV.Nodes.OpenNI\Samples\0. Context.v4p" systemname="0. Context">
+ <BOUNDS height="4410" left="6840" top="5310" type="Window" width="9030">
+ </BOUNDS>
+ <NODE componentmode="InABox" id="3" nodename="IOBox (String)" systemname="IOBox (String)">
+ <BOUNDS height="100" left="6270" top="2625" type="Node" width="100">
+ </BOUNDS>
+ <BOUNDS height="240" left="6270" top="2625" type="Box" width="795">
+ </BOUNDS>
+ <PIN pinname="Input String" visible="1">
+ </PIN>
+ <PIN encoded="0" pinname="Descriptive Name" slicecount="1" values="Status">
+ </PIN>
+ </NODE>
+ <NODE componentmode="InABox" id="4" nodename="IOBox (Value Advanced)" systemname="IOBox (Value Advanced)">
+ <BOUNDS height="100" left="6285" top="570" type="Node" width="100">
+ </BOUNDS>
+ <BOUNDS height="480" left="6285" top="570" type="Box" width="480">
+ </BOUNDS>
+ <PIN pinname="Value Type" slicecount="1" values="Boolean">
+ </PIN>
+ <PIN pinname="Behavior" slicecount="1" values="Bang">
+ </PIN>
+ <PIN pinname="Y Output Value" visible="1">
+ </PIN>
+ <PIN pinname="X Input Value" slicecount="1" values="0">
+ </PIN>
+ <PIN pinname="Y Input Value" slicecount="1" values="0">
+ </PIN>
+ <PIN encoded="0" pinname="Descriptive Name" slicecount="1" values="Open">
+ </PIN>
+ </NODE>
+ <NODE systemname="Context (OpenNI)" filename="..\..\Prerequisites\VVVV.Nodes.OpenNI.dll" nodename="Context (OpenNI)" componentmode="Hidden" id="5">
+ <BOUNDS type="Node" left="1980" top="1635" width="4350" height="270">
+ </BOUNDS>
+ <PIN pinname="Filename">
+ </PIN>
+ <PIN pinname="Open" visible="1">
+ </PIN>
+ <PIN pinname="Status" visible="1">
+ </PIN>
+ </NODE>
+ <NODE nodename="IOBox (String)" componentmode="InABox" id="6" systemname="IOBox (String)">
+ <BOUNDS type="Node" left="1980" top="570" width="0" height="0">
+ </BOUNDS>
+ <BOUNDS type="Box" left="1980" top="570" width="1860" height="240">
+ </BOUNDS>
+ <PIN pinname="Input String" slicecount="1" values="SamplesConfig.xml" encoded="0">
+ </PIN>
+ <PIN pinname="Default" slicecount="1" values="||" encoded="0">
+ </PIN>
+ <PIN pinname="File Mask" slicecount="1" values="|All Files (*.*)||*.*|" encoded="0">
+ </PIN>
+ <PIN pinname="Maximum Characters" slicecount="1" values="-1">
+ </PIN>
+ <PIN pinname="String Type" slicecount="1" values="Filename">
+ </PIN>
+ <PIN pinname="Descriptive Name" slicecount="1" values="Filename" encoded="0">
+ </PIN>
+ </NODE>
+ <LINK srcnodeid="6" srcpinname="Output String" dstnodeid="5" dstpinname="Filename">
+ </LINK>
+ <LINK srcnodeid="4" srcpinname="Y Output Value" dstnodeid="5" dstpinname="Open">
+ </LINK>
+ <LINK srcnodeid="5" srcpinname="Status" dstnodeid="3" dstpinname="Input String">
+ </LINK>
+ </PATCH>
Oops, something went wrong.

0 comments on commit 7bcac30

Please sign in to comment.