diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs index a0203b6c..7cddd338 100644 --- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs +++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs @@ -48,7 +48,7 @@ public record JsonRedirectionData { public List Targets => script.scene.targets.ConvertAll(t => new TransformData(t)); public TransformData PhysicalTarget => script.scene.physicalTarget ? new(script.scene.physicalTarget) : null; public TransformData VirtualTarget => script.scene.virtualTarget ? new(script.scene.virtualTarget) : null; - public string StrategyDirection => script.scene.forwardTarget != null ? script.scene.forwardTarget.ToString() : null; + public string StrategyDirection => script.scene.forwardTarget != null ? Convert.ToString(script.scene.forwardTarget.ToString()) : null; public JsonRedirectionData(Interaction script) => this.script = script; } @@ -74,8 +74,8 @@ protected void WriteRecords(Queue records) { } private sealed class Unsubscriber : IDisposable { - private HashSet> _observers; - private IObserver _observer; + private readonly HashSet> _observers; + private readonly IObserver _observer; public Unsubscriber(HashSet> observers, IObserver observer) { _observers = observers; diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs index 14f6c358..0cb817e3 100644 --- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs +++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs @@ -22,27 +22,26 @@ public class Kohli2010RedirectedTouching : BodyRedirectionTechnique { public void ComputeDisplacement(Scene scene) { var x = Array.ConvertAll(scene.referenceParent.GetComponentsInChildren(), t => t.position); var y = Array.ConvertAll(scene.interpolatedParent.GetComponentsInChildren(), t => t.position); - if (add_boundaries) { - var bounds = new Bounds(x[0], Vector3.zero); - foreach (var v in x.Concat(y)) { - bounds.Encapsulate(v); - } - bounds.extents *= 2f; - Vector3[] ends = { bounds.min, bounds.max }; - var supplementary_fixed = new List(8); - foreach (var a in ends) - foreach (var b in ends) - foreach (var c in ends) - supplementary_fixed.Add(new Vector3(a.x, b.y, c.z)); - x = x.Concat(supplementary_fixed).ToArray(); - y = y.Concat(supplementary_fixed).ToArray(); - } displace = ThinPlateSpline.SabooSmoothedDisplacementField( x, y, scene.parameters.SmoothingParameter, scene.parameters.Rescale ); + if (add_boundaries) { + var bounds = new Bounds(x[0], Vector3.zero); + foreach (var v in x.Concat(y)) { + bounds.Encapsulate(v); + } + var sqrRadius = 3 * bounds.extents.sqrMagnitude; + + static float f(float x) => x > 0 ? Mathf.Exp(-1 / x) : 0; + static float g(float x) => f(x) / (f(x) + f(1 - x)); + float transitionLayerWidth = 0.5F; + float smoothTransition(float x) => 1 - g((x - sqrRadius) / (transitionLayerWidth * sqrRadius)); + var old_displace = displace; + displace = (pos) => old_displace(pos) * smoothTransition((pos - bounds.center).sqrMagnitude); + } } public override void Redirect(Scene scene) { diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs index 867664f3..c161d935 100644 --- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs +++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs @@ -19,8 +19,8 @@ struct WorldRedirectionData { [SerializeField] float[] maxSums; public void AddTo(float overTime, float rotational, float curvature, float time) { - if (this.maxSums is null || this.maxSums.Length != 3) { - this.maxSums = new float[3]; + if (maxSums?.Length != 3) { + maxSums = new float[3]; } this.overTime += Mathf.Abs(overTime); this.rotational += Mathf.Abs(rotational); @@ -108,9 +108,6 @@ private void StartSendingMessages() { Thread thread = new(() => SendMessage(client, json)); thread.Start(); redirectionData.Reset(); - // redirectionData.overTime = 0f; - // redirectionData.rotational = 0f; - // redirectionData.curvature = 0f; } }