From 321b9640cafa57535fc48ef6a587e9e13d69145b Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Thu, 18 Mar 2021 10:11:11 +0100
Subject: [PATCH] chore: fix swc support

now expects all units in microns
---
 package.json                  |  2 +-
 src/messaging/nmvSwc/index.ts | 38 ++++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/package.json b/package.json
index 9e45f6196..bd788abf8 100644
--- a/package.json
+++ b/package.json
@@ -80,7 +80,7 @@
     "@ngrx/effects": "^9.1.1",
     "@ngrx/store": "^9.1.1",
     "@types/node": "12.12.39",
-    "export-nehuba": "0.0.6",
+    "export-nehuba": "0.0.7",
     "hbp-connectivity-component": "^0.3.18",
     "zone.js": "^0.10.2"
   }
diff --git a/src/messaging/nmvSwc/index.ts b/src/messaging/nmvSwc/index.ts
index 367fa2ca5..c34afc44a 100644
--- a/src/messaging/nmvSwc/index.ts
+++ b/src/messaging/nmvSwc/index.ts
@@ -1,6 +1,6 @@
 import { Observable, Subject } from "rxjs"
 import { getUuid } from "src/util/fn"
-import { IMessagingActions, IMessagingActionTmpl, TVec4 } from "../types"
+import { IMessagingActions, IMessagingActionTmpl, TVec4, TMat4 } from "../types"
 import { INmvTransform } from "./type"
 
 export const TYPE = 'bas.datasource'
@@ -15,11 +15,11 @@ const waitFor = (condition: (...arg: any[]) => boolean) => new Promise((rs, rj)
 })
 
 const NM_IDS = {
-  AMBA_V3: 'hbp:Allen_Mouse_CCF_v3(nm)',
-  WAXHOLM_V1_01: 'hbp:WHS_SD_Rat_v1.01(nm)',
-  BIG_BRAIN: 'hbp:BigBrain_r2015(nm)',
-  COLIN: 'hbp:Colin27_r2008(nm)',
-  MNI152_2009C_ASYM: 'hbp:ICBM_Asym_r2009c(nm)',
+  AMBA_V3: 'hbp:Allen_Mouse_CCF_v3(um)',
+  WAXHOLM_V1_01: 'hbp:WHS_SD_Rat_v1.01(um)',
+  BIG_BRAIN: 'hbp:BigBrain_r2015(um)',
+  COLIN: 'hbp:Colin27_r2008(um)',
+  MNI152_2009C_ASYM: 'hbp:ICBM_Asym_r2009c(um)',
 }
 
 const IAV_IDS = {
@@ -92,6 +92,25 @@ export const processJsonLd = (json: { [key: string]: any }): Observable<IMessagi
       new Blob([ encoder.encode(output) ], { type: 'application/octet-stream' })
     )
     const uuid = getUuid()
+
+    // NG internal treats skeleton as mm 
+    const scaleUmToMm = 1e-3
+    // NG translation works on nm scale
+    const scaleUmToNm = 1e3
+    const { mat3, vec3 } = (window as any).export_nehuba
+    const modA = mat3.fromValues(
+      scaleUmToMm, 0, 0,
+      0, scaleUmToMm, 0,
+      0, 0, scaleUmToMm
+    )
+    mat3.mul(modA, modA, [...A[0], ...A[1], ...A[2]])
+    const modb = vec3.scale(vec3.create(), b, scaleUmToNm)
+    const transform = [
+      [...modA.slice(0, 3), modb[0]] as TVec4,
+      [...modA.slice(3, 6), modb[1]] as TVec4,
+      [...modA.slice(6), modb[2]] as TVec4,
+      [0, 0, 0, 1],
+    ] as TMat4
     const payload: IMessagingActionTmpl['loadResource'] = {
       '@id': uuid,
       "@type" : 'swc',
@@ -100,12 +119,7 @@ export const processJsonLd = (json: { [key: string]: any }): Observable<IMessagi
       },
       url: tmpUrl,
       resourceParam: {
-        transform: [
-          [...A[0], b[0]] as TVec4,
-          [...A[1], b[1]] as TVec4,
-          [...A[2], b[2]] as TVec4,
-          [0, 0, 0, 1],
-        ]
+        transform
       }
     }
     subject.next({
-- 
GitLab