Permalink
Browse files

Nearest neighbour node.

  • Loading branch information...
1 parent a0b1ff4 commit 1024e01ff1f7e8f18b99eb38dada9236098d44da @mrvux committed Dec 29, 2011
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using VVVV.PluginInterfaces.V2;
+
+namespace VVVV.Nodes
+{
+ public abstract class BaseNearestNeighbourNode<T> : IPluginEvaluate
+ {
+ [Input("Reference")]
+ ISpread<T> FInReference;
+
+ [Input("Input")]
+ ISpread<T> FInput;
+
+ [Output("Nearest Index")]
+ ISpread<int> FOutput;
+
+ public void Evaluate(int SpreadMax)
+ {
+ if (SpreadMax > 1)
+ {
+ this.FOutput.SliceCount = this.FInput.SliceCount;
+
+ for (int i = 0; i < this.FInput.SliceCount; i++)
+ {
+ double dblmin = double.MaxValue;
+ int minidx = -1;
+
+ double dist;
+
+ T input = this.FInput[i];
+
+ for (int j = 0; j < this.FInReference.SliceCount; j++)
+ {
+
+ T refobj = this.FInReference[j];
+
+ dist = this.Distance(input, refobj);
+ if (dist < dblmin)
+ {
+ minidx = j;
+ dblmin = dist;
+ }
+ }
+ this.FOutput[i] = minidx;
+ }
+ }
+ else
+ {
+ this.FOutput.SliceCount = 0;
+ }
+ }
+
+ protected abstract double Distance(T t1, T t2);
+ }
+}
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{5AD3E291-9FDB-4893-8C98-EC1478789783}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>VVVV.Nodes</RootNamespace>
+ <AssemblyName>NearestNeighbour</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>2.0</OldToolsVersion>
+ <UpgradeBackupLocation />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.ComponentModel.Composition.Codeplex">
+ <HintPath>..\..\..\..\..\..\lib\core\System.ComponentModel.Composition.Codeplex.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="BaseNearestNeighbourNode.cs" />
+ <Compile Include="NearestNeighbourNodes.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\..\core\Hosting\Hosting.csproj">
+ <Project>{F9A754A6-EEA5-4761-9446-C2AAF9CF8B31}</Project>
+ <Name>Hosting</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\..\core\PluginInterfaces\PluginInterfaces.csproj">
+ <Project>{837C740A-485C-424C-8C38-086ED3DC73CB}</Project>
+ <Name>PluginInterfaces</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\..\core\Utils3rdParty\Utils3rdParty.csproj">
+ <Project>{87863121-C124-4585-B3BB-7706F03ECC64}</Project>
+ <Name>Utils3rdParty</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\..\core\Utils\Utils.csproj">
+ <Project>{C3773330-81FA-4253-823E-1BDE1529AA99}</Project>
+ <Name>Utils</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NearestNeighbour", "NearestNeighbour.csproj", "{5AD3E291-9FDB-4893-8C98-EC1478789783}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5AD3E291-9FDB-4893-8C98-EC1478789783}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5AD3E291-9FDB-4893-8C98-EC1478789783}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5AD3E291-9FDB-4893-8C98-EC1478789783}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5AD3E291-9FDB-4893-8C98-EC1478789783}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using VVVV.PluginInterfaces.V2;
+using VVVV.Utils.VMath;
+
+namespace VVVV.Nodes
+{
+ [PluginInfo(Name="NearestNeighbour", Category="Value", Author="vux")]
+ public class NearestNeighbourValueNode : BaseNearestNeighbourNode<double>
+ {
+ protected override double Distance(double t1, double t2)
+ {
+ return Math.Abs(t1 - t2);
+ }
+ }
+
+ [PluginInfo(Name = "NearestNeighbour", Category = "2d", Author = "vux")]
+ public class NearestNeighbour2dNode : BaseNearestNeighbourNode<Vector2D>
+ {
+ protected override double Distance(Vector2D t1, Vector2D t2)
+ {
+ Vector2D diff = t1 - t2;
+ return diff.Length;
+ }
+ }
+
+ [PluginInfo(Name = "NearestNeighbour", Category = "3d", Author = "vux")]
+ public class NearestNeighbour3dNode : BaseNearestNeighbourNode<Vector3D>
+ {
+ protected override double Distance(Vector3D t1, Vector3D t2)
+ {
+ Vector3D diff = t1 - t2;
+ return diff.Length;
+ }
+ }
+
+ [PluginInfo(Name = "NearestNeighbour", Category = "4d", Author = "vux")]
+ public class NearestNeighbour4dNode : BaseNearestNeighbourNode<Vector4D>
+ {
+ protected override double Distance(Vector4D t1, Vector4D t2)
+ {
+ Vector4D diff = t1 - t2;
+ return diff.Length;
+ }
+ }
+
+
+}
@@ -0,0 +1,35 @@
+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("NearestNeighbour")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("NearestNeighbour")]
+[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("6551bdf6-c58c-4e0e-b307-687033270987")]
+
+// 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 Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 1024e01

Please sign in to comment.