-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
43 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect, test } from "vitest"; | ||
import { Vector4, Vector3 } from "three"; | ||
import QSpace, { DetectorProperties } from "./qspace"; | ||
|
||
test("Test getting q from pixel position ", () => { | ||
const detProps: DetectorProperties = { | ||
resolution: { | ||
height: 1, | ||
width: 1 | ||
}, | ||
pixelSize: { | ||
height: 1, | ||
width: 1 | ||
}, | ||
origin: new Vector3(0, 0, 0), | ||
beamVector: new Vector3(1, 1, 0), | ||
} | ||
|
||
const diffCrystEnv = { | ||
wavelength: 1, | ||
referenceNormal: new Vector3(1, 1, 1), | ||
strokesVector: new Vector4(1, 0, 1, 0), | ||
} | ||
|
||
const qspace = new QSpace(detProps, diffCrystEnv, 1) | ||
const result = qspace.qFromPixelPosition(1, 1) | ||
expect(result).toBeInstanceOf(Vector3) | ||
console.log(result) | ||
// do better testing when you understand it better | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,56 @@ | ||
import { Vector3, Vector4 } from "three"; | ||
import { Detector } from "../utils/types"; | ||
|
||
export interface DiffractionCrystalEnvironment { | ||
wavelength: number; | ||
referenceNormal: Vector3; | ||
strokesVector: Vector4; | ||
} | ||
|
||
export interface DetectorProperties extends Detector { | ||
origin: Vector3; | ||
beamVector: Vector3; | ||
} | ||
|
||
export default class QSpace { | ||
static QSCALE_DEFAULT = 2 * Math.PI; | ||
private detector: Detector; | ||
private kmod: number; | ||
private ki: Vector3; | ||
private mki: Vector3; | ||
private qScale: number; | ||
private residual: number; | ||
private refrennce: Vector3; | ||
private stroks: Vector4; | ||
detProps: DetectorProperties; | ||
kmod: number; | ||
reference: Vector3; | ||
strokes: Vector4; | ||
qScale: number; | ||
mki: Vector3; | ||
|
||
constructor(detProps: DetectorProperties, diffexp: DiffractionCrystalEnvironment, qScale: number) { | ||
this.detProps = detProps; | ||
detProps.beamVector.normalize() | ||
this.qScale = qScale | ||
this.mki = new Vector3().copy(detProps.beamVector).negate() | ||
this.kmod = this.qScale / diffexp.wavelength; | ||
this.reference = diffexp.referenceNormal; | ||
this.strokes = diffexp.strokesVector; | ||
} | ||
|
||
constructor(detector: Detector, diffexp: DiffractionCrystalEnvironment, scale: number) { | ||
convertToQ(q: Vector3) { | ||
const qLength = q.length(); | ||
if (qLength > 0) { | ||
q.multiplyScalar(this.kmod / qLength); | ||
q.add(this.mki) | ||
} else { | ||
q.add(this.mki); | ||
} | ||
} | ||
|
||
qFromPixelPosition(x: number, y: number) { | ||
const q = new Vector3(); | ||
q.set(-this.detProps.pixelSize.height * (x), -this.detProps.pixelSize.width * (y), 0); | ||
q.add(this.detProps.origin); | ||
this.convertToQ(q); | ||
return q | ||
} | ||
|
||
setDiffractionCrystalEnviroment(diffexp: DiffractionCrystalEnvironment) { | ||
this.kmod = this.qScale / diffexp.wavelength; | ||
this.reference = diffexp.referenceNormal; | ||
this.strokes = diffexp.strokesVector; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters