Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kinect2 Pipet Nodes - Depth & Pipet #355

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VVVV.PluginInterfaces.V2;
using BulletSharp;
using VVVV.Utils.VMath;
using VVVV.Bullet.Core;

namespace VVVV.Bullet.Nodes.Bodies.Interactions.Rigid
{
[PluginInfo(Name = "SetCustom", Category = "Bullet", Version = "Rigid", Author = "vux",
Help = "Updates rigid body custom string", AutoEvaluate = true)]
public class BulletSetCustomNode : IPluginEvaluate
{
[Input("Bodies", Order = 0)]
protected ISpread<RigidBody> FInput;



[Input("Custom String")]
protected ISpread<string> FString;

[Input("Set")]
protected IDiffSpread<bool> FSet;


public void Evaluate(int SpreadMax)
{
for (int i = 0; i < SpreadMax; i++)
{
RigidBody rb = this.FInput[i];


if (rb != null && FSet.IsChanged && FSet[i])
{

BodyCustomData bd = (BodyCustomData)rb.UserObject;
bd.Custom = FString[i];


}
}
}
}
}
1 change: 1 addition & 0 deletions Nodes/VVVV.DX11.Nodes.Bullet/VVVV.Nodes.Bullet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Compile Include="Nodes\Bodies\Interactions\BulletDestroyBodyNode.cs" />
<Compile Include="Nodes\Bodies\Interactions\Rigid\AbstractBodyForceNode.cs" />
<Compile Include="Nodes\Bodies\Interactions\Rigid\BulletActivateBodyNode.cs" />
<Compile Include="Nodes\Bodies\Interactions\Rigid\BulletSetCustomNode.cs" />
<Compile Include="Nodes\Bodies\Interactions\Rigid\BulletSetPoseRigidBodyNode.cs" />
<Compile Include="Nodes\Bodies\Interactions\Rigid\BulletSetVelocityNode.cs" />
<Compile Include="Nodes\Bodies\Interactions\Rigid\BulletApplyForceNode.cs" />
Expand Down
165 changes: 165 additions & 0 deletions Nodes/VVVV.DX11.Nodes.kinect2/KinectDepthPipetNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VVVV.PluginInterfaces.V2;
using SlimDX;
using VVVV.MSKinect.Lib;
using VVVV.PluginInterfaces.V1;
using Microsoft.Kinect;


namespace VVVV.MSKinect.Nodes
{
[PluginInfo(Name = "Depth Pipet",
Category = "Kinect2",
Version = "Microsoft",
Author = "vux",
Tags = "DX11",
Help = "pipet IR image")]
public class KinectDepthPipetNode : IPluginEvaluate, IPluginConnections
{
[Input("Kinect Runtime")]
protected Pin<KinectRuntime> FInRuntime;

[Input("Update RayTable")]
public ISpread<bool> FUpdateRayTable;

[Input("Pixel")]
public ISpread<Vector2> FInPixelPos;

[Output("Value")]
protected ISpread<double> FOutValue;

[Output("RayTable")]
protected ISpread<Vector2> FRayTable;



private bool FInvalidateConnect = false;

private KinectRuntime runtime;

private bool FInvalidate = false;

private Body[] lastframe = new Body[6];
private object m_lock = new object();
private PointF[] dataRayTable;






public void Evaluate(int SpreadMax)
{
if (this.FUpdateRayTable[0] && runtime != null)
{
this.dataRayTable = this.runtime.Runtime.CoordinateMapper.GetDepthFrameToCameraSpaceTable();
}


if (this.FInvalidateConnect)
{
if (runtime != null)
{

this.runtime.DepthFrameReady -= DepthFrameReady;
}

if (this.FInRuntime.IsConnected)
{
//Cache runtime node
this.runtime = this.FInRuntime[0];

if (runtime != null)
{
this.FInRuntime[0].DepthFrameReady += DepthFrameReady;
}


}

this.FInvalidateConnect = false;
}

if (this.FInvalidate)
{
if (this.lastframe != null)
{




}
this.FInvalidate = false;
}
}


private unsafe void DepthFrameReady(object sender, DepthFrameArrivedEventArgs e)
{
if (e.FrameReference != null)
{
using (var frame = e.FrameReference.AcquireFrame())
{
if (frame != null)
{
using (var buffer = frame.LockImageBuffer())
{
short* data = (short*)buffer.UnderlyingBuffer;
FOutValue.SliceCount = 0;
FRayTable.SliceCount = 0;

int pixelX = 10;
int pixelY = 10;

foreach (var item in FInPixelPos)
{
pixelX = (int)item.X;
pixelY = (int)item.Y;

pixelX = pixelX < 0 ? 0 : pixelX;
pixelY = pixelY < 0 ? 0 : pixelY;

pixelX = pixelX > 511 ? 511 : pixelX;
pixelY = pixelY > 423 ? 423 : pixelY;

double pixel = data[pixelY * 512 + pixelX];
FOutValue.Add(pixel);

if (dataRayTable != null)
{
PointF mypoint = dataRayTable[pixelY * 512 + pixelX];

FRayTable.Add(new Vector2(mypoint.X,mypoint.Y));
}

}

}
}
}
}
}




public void ConnectPin(IPluginIO pin)
{
if (pin == this.FInRuntime.PluginIO)
{
this.FInvalidateConnect = true;
}
}

public void DisconnectPin(IPluginIO pin)
{
if (pin == this.FInRuntime.PluginIO)
{
this.FInvalidateConnect = true;
}
}
}
}
138 changes: 138 additions & 0 deletions Nodes/VVVV.DX11.Nodes.kinect2/KinectIRPipetNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VVVV.PluginInterfaces.V2;
using SlimDX;
using VVVV.MSKinect.Lib;
using VVVV.PluginInterfaces.V1;
using Microsoft.Kinect;


namespace VVVV.MSKinect.Nodes
{
[PluginInfo(Name = "IR Pipet",
Category = "Kinect2",
Version = "Microsoft",
Author = "u7angel",
Tags = "DX11",
Help = "pipet IR image")]
public class KinectRawIRNode : IPluginEvaluate, IPluginConnections
{
[Input("Kinect Runtime")]
protected Pin<KinectRuntime> FInRuntime;

[Input("Pixel")]
public ISpread<Vector2> FInPixelPos;


[Output("Value")]
protected ISpread<double> FOutValue;


private bool FInvalidateConnect = false;

private KinectRuntime runtime;

private bool FInvalidate = false;

private Body[] lastframe = new Body[6];
private object m_lock = new object();


public void Evaluate(int SpreadMax)
{
if (this.FInvalidateConnect)
{
if (runtime != null)
{
this.runtime.IRFrameReady -= IRFrameReady;
}

if (this.FInRuntime.IsConnected)
{
//Cache runtime node
this.runtime = this.FInRuntime[0];

if (runtime != null)
{

this.FInRuntime[0].IRFrameReady += IRFrameReady;
}

}

this.FInvalidateConnect = false;
}

if (this.FInvalidate)
{
if (this.lastframe != null)
{




}
this.FInvalidate = false;
}
}


private unsafe void IRFrameReady(object sender, InfraredFrameArrivedEventArgs e)
{
if (e.FrameReference != null)
{
using (var frame = e.FrameReference.AcquireFrame())
{
if (frame != null)
{
using (var buffer = frame.LockImageBuffer())
{
short* data = (short*)buffer.UnderlyingBuffer;
FOutValue.SliceCount = 0;

int pixelX = 10;
int pixelY = 10;

foreach (var item in FInPixelPos)
{
pixelX = (int)item.X;
pixelY = (int)item.Y;

pixelX = pixelX < 0 ? 0 : pixelX;
pixelY = pixelY < 0 ? 0 : pixelY;

pixelX = pixelX > 511 ? 511 : pixelX;
pixelY = pixelY > 423 ? 423 : pixelY;

double pixel = data[pixelY * 512 + pixelX];
FOutValue.Add(pixel);
}

}
}
}
}
}




public void ConnectPin(IPluginIO pin)
{
if (pin == this.FInRuntime.PluginIO)
{
this.FInvalidateConnect = true;
}
}

public void DisconnectPin(IPluginIO pin)
{
if (pin == this.FInRuntime.PluginIO)
{
this.FInvalidateConnect = true;
}
}
}
}
2 changes: 2 additions & 0 deletions Nodes/VVVV.DX11.Nodes.kinect2/VVVV.DX11.Nodes.kinect2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
<Compile Include="KinectBaseTextureNode.cs" />
<Compile Include="KinectBodyIndexRawTextureNode.cs" />
<Compile Include="KinectCameraIntrinsics.cs" />
<Compile Include="KinectDepthPipetNode.cs" />
<Compile Include="KinectDepthTextureNodeRaw.cs" />
<Compile Include="KinectIRPipetNode.cs" />
<Compile Include="KinectPreposeGestureStatusNode.cs" />
<Compile Include="KinectPreposeGestureNode.cs" />
<Compile Include="KinectHdFaceBufferNode.cs" />
Expand Down
2 changes: 1 addition & 1 deletion girlpower