Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sintefneodroid/droid
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Jan 11, 2019
2 parents e03afd4 + 77e32bf commit f061628
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 16 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ environments and ease of integration with existing projects)

## Usage

- Edit your Unity projects "Packages/manifest.json" to include the string
`"net.cnheider.neodroid": "https://github.com/sintefneodroid/droid.git"}`.

Example `manifest.json`
````
{
"dependencies": {
"com.unity.package-manager-ui": "0.0.0-builtin",
...
"net.cnheider.neodroid": "https://github.com/sintefneodroid/droid.git"
}
}
````
You can use `"net.cnheider.neodroid": "https://github.com/sintefneodroid/droid.git#branch"` for a specific branch.

***Or***

- Download the newest Droid.unitypackage from [releases](https://github.com/sintefneodroid/droid/releases) and import into your Unity project.

***Or***
Expand All @@ -93,7 +110,7 @@ environments and ease of integration with existing projects)

## Repository Structure
---
<!-- ├ └ ─ │ -->
<!-- ├ └ ─ │ -->
sintefneodroid/droid # This repository
├── docs
Expand Down
1 change: 1 addition & 0 deletions Runtime/Interfaces/ISimulatorConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Neodroid.Runtime.Messaging.Messages;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.ScriptableObjects;

namespace Neodroid.Runtime.Interfaces {
Expand Down
5 changes: 3 additions & 2 deletions Runtime/Managers/NeodroidManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Neodroid.Runtime.Interfaces;
using Neodroid.Runtime.Messaging;
using Neodroid.Runtime.Messaging.Messages;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.EventRecipients.droid.Neodroid.Utilities.Unsorted;
using Neodroid.Runtime.Utilities.ScriptableObjects;
using UnityEngine;
Expand Down Expand Up @@ -733,7 +734,7 @@ public void React(Reaction[] reactions) {
Debug.Log($"Could not find an environment with the identifier: {reaction.RecipientEnvironment}");
}
#endif
}
}
}
}

Expand Down Expand Up @@ -779,7 +780,7 @@ void SetStepping(bool step) {
}

void SetStepping(Reaction[] reactions) {
if (reactions.Any(reac => reac.Parameters.Step)) {
if (reactions.Any(reaction => reaction.Parameters.Step)) {
this.SetStepping(true);
}
}
Expand Down
1 change: 1 addition & 0 deletions Runtime/Managers/PausableManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.ScriptableObjects;
using UnityEngine;

Expand Down
1 change: 1 addition & 0 deletions Runtime/Prototyping/Observers/Camera/CameraObserver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Neodroid.Runtime.Interfaces;
using Neodroid.Runtime.Managers;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.ScriptableObjects;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Neodroid.Runtime.Interfaces;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.ScriptableObjects;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.NeodroidCamera.Segmentation;
using Neodroid.Runtime.Utilities.ScriptableObjects;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Neodroid.Runtime.Environments;
using Neodroid.Runtime.Interfaces;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.Misc;
using Neodroid.Runtime.Utilities.ScriptableObjects;
using UnityEngine;
Expand Down
File renamed without changes.
89 changes: 89 additions & 0 deletions Runtime/Shaders/Experimental/OpticalFlow.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Excluded/OpticalFlow"
{
Properties
{
_Sensitivity("Sensitivity", Float) = 1
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"


struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};

float4 _CameraMotionVectorsTexture_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _CameraMotionVectorsTexture);
return o;
}

sampler2D _CameraMotionVectorsTexture;

float3 Hue(float H)
{
float R = abs(H * 6 - 3) - 1;
float G = 2 - abs(H * 6 - 2);
float B = 2 - abs(H * 6 - 4);
return saturate(float3(R,G,B));
}

float3 HSVtoRGB(float3 HSV)
{
return float3(((Hue(HSV.x) - 1) * HSV.y + 1) * HSV.z);
}

float _Sensitivity;
float3 MotionVectorsToOpticalFlow(float2 motion)
{
// Currently is based on HSV encoding from:
// "Optical Flow in a Smart Sensor Based on Hybrid Analog-Digital Architecture" by P. Guzman et al
// http://www.mdpi.com/1424-8220/10/4/2975

// Analogous to http://docs.opencv.org/trunk/d7/d8b/tutorial_py_lucas_kanade.html
// but might need to swap or rotate axis!

// @TODO: support other HSV encodings (using lookup texture)
// https://www.microsoft.com/en-us/research/wp-content/uploads/2007/10/ofdatabase_iccv_07.pdf
// https://people.csail.mit.edu/celiu/SIFTflow/
// some MATLAB code: https://github.com/suhangpro/epicflow/blob/master/utils/flow-code-matlab/computeColor.m

float angle = atan2(-motion.y, -motion.x);
float hue = angle / (UNITY_PI * 2.0) + 0.5; // convert motion angle to Hue
float value = length(motion) * _Sensitivity; // convert motion strength to Value
return HSVtoRGB(float3(hue, 1, value)); // HSV -> RGB
}

fixed4 frag (v2f i) : SV_Target
{
float2 motion = tex2D(_CameraMotionVectorsTexture, i.uv).rg;
float3 rgb = MotionVectorsToOpticalFlow(motion);
return float4(rgb, 1);
}
ENDCG
}
}
}
9 changes: 9 additions & 0 deletions Runtime/Shaders/Experimental/OpticalFlow.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Utilities/Enums/FrameFinishes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Neodroid.Runtime.Utilities.ScriptableObjects {
namespace Neodroid.Runtime.Utilities.Enums {
/// <summary>
/// Determines where in the monobehaviour cycle a frame/step is finished
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Utilities/Enums/SimulationType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Neodroid.Runtime.Utilities.ScriptableObjects
namespace Neodroid.Runtime.Utilities.Enums
{
/// <summary>
/// Determines the discrete timesteps of the simulation environment.
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Utilities/Misc/Perlin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Neodroid.Runtime.Prototyping.Configurables.Experimental {
namespace Neodroid.Runtime.Utilities.Misc {

public class Perlin
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Neodroid.Runtime.Interfaces;
using Neodroid.Runtime.Messaging.Messages;
using Neodroid.Runtime.Utilities.Enums;
using Neodroid.Runtime.Utilities.Misc.SearchableEnum;
using UnityEngine;

Expand Down
12 changes: 6 additions & 6 deletions Runtime/Utilities/Structs/DoubleVector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace Neodroid.Runtime.Utilities.Structs {
[Serializable]
public struct DoubleVector3 {
[SerializeField] public double _X;
[SerializeField] public double _Y;
[SerializeField] public double _Z;
[SerializeField] double _X;
[SerializeField] double _Y;
[SerializeField] double _Z;

public DoubleVector3(Vector3 vec3) {
this._X = vec3.x;
Expand All @@ -27,10 +27,10 @@ public DoubleVector3(double x, double y, double z) {
this._Z = z;
}

public Double X { get { return this._X; } set { this._X = value; } }
public Double x { get { return this._X; } set { this._X = value; } }

public Double Y { get { return this._Y; } set { this._Y = value; } }
public Double y { get { return this._Y; } set { this._Y = value; } }

public Double Z { get { return this._Z; } set { this._Z = value; } }
public Double z { get { return this._Z; } set { this._Z = value; } }
}
}
9 changes: 5 additions & 4 deletions Samples/MultiArmedBandit/MultiArmedBanditMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public Single[] WinLikelihoods {
/// </summary>
protected override void Setup() {
var mvs = this.MotionValueSpace;
mvs._Min_Value = 0;
mvs._Max_Value = this._Indicators.Length - 1;
mvs._Min_Value = -1;
mvs._Max_Value = 1;
mvs._Decimal_Granularity = 0;
this.MotionValueSpace = mvs;
if (this._Win_Likelihoods == null || this._Win_Likelihoods.Length == 0) {
this._Win_Likelihoods = new Single[this._Indicators.Length];
Expand Down Expand Up @@ -133,7 +134,7 @@ protected override void InnerApplyMotion(IMotorMotion motion) {
indicator.color = this._inactive_color;
}

var index = (int)motion.Strength;
var index = (int)motion.Strength+1;

#if NEODROID_DEBUG
if (this.Debugging) {
Expand All @@ -143,7 +144,7 @@ protected override void InnerApplyMotion(IMotorMotion motion) {

this._last_index = index;

var random_value = Random.Range(0f, 1f);
var random_value = Random.Range(-1f, 1f);
if (random_value <= this._Win_Likelihoods[this._last_index]) {
this._Indicators[this._last_index].color = this._win_color;
this._won = true;
Expand Down

0 comments on commit f061628

Please sign in to comment.