-
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
17 changed files
with
329 additions
and
215 deletions.
There are no files selected for viewing
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
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,38 +1,43 @@ | ||
import { test } from "vitest"; | ||
import { computeQrange } from "./qrange"; | ||
import { BeamlineConfig, Beamstop, CircularDevice, Detector } from "../utils/types"; | ||
import { | ||
BeamlineConfig, | ||
Beamstop, | ||
CircularDevice, | ||
Detector, | ||
} from "../utils/types"; | ||
|
||
test("Test getting q from pixel position ", () => { | ||
const detector: Detector = { | ||
resolution: { | ||
height: 1679, | ||
width: 1465, | ||
}, | ||
pixelSize: { | ||
height: 0.172, | ||
width: 0.172 | ||
} | ||
} | ||
const beamstop: Beamstop = { | ||
centre: { x: 738, y: 100 }, | ||
diameter: 4, | ||
clearance: 10 | ||
} | ||
const beamConfig: BeamlineConfig = { | ||
angle: 1.57, | ||
cameraLength: 1.9, | ||
minWavelength: 6.2e-2, | ||
maxWavelength: 0.335, | ||
minCameraLength: 0, | ||
maxCameraLength: 4, | ||
energy: 60, | ||
wavelength: 2e-2 | ||
} | ||
const cameraTube: CircularDevice = { | ||
centre: { x: 738, y: 840 }, | ||
diameter: 310 | ||
} | ||
const detector: Detector = { | ||
resolution: { | ||
height: 1679, | ||
width: 1465, | ||
}, | ||
pixelSize: { | ||
height: 0.172, | ||
width: 0.172, | ||
}, | ||
}; | ||
const beamstop: Beamstop = { | ||
centre: { x: 738, y: 100 }, | ||
diameter: 4, | ||
clearance: 10, | ||
}; | ||
const beamConfig: BeamlineConfig = { | ||
angle: 1.57, | ||
cameraLength: 1.9, | ||
minWavelength: 6.2e-2, | ||
maxWavelength: 0.335, | ||
minCameraLength: 0, | ||
maxCameraLength: 4, | ||
energy: 60, | ||
wavelength: 2e-2, | ||
}; | ||
const cameraTube: CircularDevice = { | ||
centre: { x: 738, y: 840 }, | ||
diameter: 310, | ||
}; | ||
|
||
const result = computeQrange(detector, beamstop, cameraTube, beamConfig) | ||
console.log(result) | ||
const result = computeQrange(detector, beamstop, cameraTube, beamConfig); | ||
console.log(result); | ||
}); |
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,53 +1,114 @@ | ||
import QSpace, { DetectorProperties, DiffractionCrystalEnvironment } from "../calculations/qspace"; | ||
import { BeamlineConfig, Beamstop, CircularDevice, Detector } from "../utils/types"; | ||
import QSpace, { | ||
DetectorProperties, | ||
DiffractionCrystalEnvironment, | ||
} from "../calculations/qspace"; | ||
import { | ||
BeamlineConfig, | ||
Beamstop, | ||
CircularDevice, | ||
Detector, | ||
} from "../utils/types"; | ||
import { Vector3, Vector4 } from "three"; | ||
import { Ray } from "../calculations/ray"; | ||
|
||
export function computeQrange( | ||
detector: Detector, | ||
beamstop: Beamstop, | ||
cameraTube: CircularDevice, | ||
beamProperties: BeamlineConfig, | ||
) { | ||
const initialPosition = new Vector3( | ||
beamstop.clearance ?? | ||
0 * Math.cos(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0), | ||
beamstop.clearance ?? | ||
0 * Math.sin(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0), | ||
); | ||
|
||
export function computeQrange(detector: Detector, beamstop: Beamstop, cameraTube: CircularDevice, beamProperties: BeamlineConfig) { | ||
const initialPosition = new Vector3(beamstop.clearance ?? 0 * Math.cos(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0), | ||
beamstop.clearance ?? 0 * Math.sin(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0)) | ||
const ray = new Ray( | ||
new Vector3( | ||
Math.cos(beamProperties.angle ?? 0), | ||
Math.sin(beamProperties.angle ?? 0), | ||
), | ||
initialPosition, | ||
); | ||
let t1 = ray.getRectangleIntersectionParameterRange( | ||
new Vector3(0, detector.resolution.height), | ||
detector.resolution.width, | ||
detector.resolution.height, | ||
); | ||
|
||
const ray = new Ray(new Vector3(Math.cos(beamProperties.angle ?? 0), Math.sin(beamProperties.angle ?? 0)), initialPosition); | ||
let t1 = ray.getRectangleIntersectionParameterRange(new Vector3(0, detector.resolution.height), detector.resolution.width, detector.resolution.height) | ||
if (t1 != null && cameraTube != null && cameraTube.diameter != 0) { | ||
t1 = t1.intersect( | ||
ray.getCircleIntersectionParameterRange( | ||
(cameraTube.diameter ?? 0) / 2, | ||
new Vector3(cameraTube.centre.x ?? 0, cameraTube.centre.y ?? 0), | ||
), | ||
); | ||
} | ||
console.log(t1); | ||
if ( | ||
t1 === null || | ||
beamProperties.wavelength == null || | ||
beamProperties.cameraLength == null | ||
) { | ||
return null; | ||
} | ||
|
||
if (t1 != null && cameraTube != null && cameraTube.diameter != 0) { | ||
t1 = t1.intersect(ray.getCircleIntersectionParameterRange((cameraTube.diameter ?? 0) / 2, new Vector3(cameraTube.centre.x ?? 0, cameraTube.centre.y ?? 0))); | ||
} | ||
console.log(t1) | ||
if (t1 === null || beamProperties.wavelength == null || beamProperties.cameraLength == null) { | ||
return null | ||
} | ||
const ptMin = ray.getPoint(t1.min); | ||
const ptMax = ray.getPoint(t1.max); | ||
|
||
const ptMin = ray.getPoint(t1.min); | ||
const ptMax = ray.getPoint(t1.max); | ||
const detProps: DetectorProperties = { | ||
...detector, | ||
origin: new Vector3( | ||
beamstop.centre.x ?? 0, | ||
beamstop.centre.y ?? 0, | ||
beamProperties.cameraLength * 1e-3, | ||
), | ||
beamVector: new Vector3(0, 0, 1), | ||
}; | ||
|
||
const detProps: DetectorProperties = { | ||
...detector, | ||
origin: new Vector3(beamstop.centre.x ?? 0, beamstop.centre.y ?? 0, beamProperties.cameraLength * 1e-3), | ||
beamVector: new Vector3(0, 0, 1) | ||
} | ||
const diffCrystEnv: DiffractionCrystalEnvironment = { | ||
wavelength: beamProperties.wavelength * 1e10, | ||
referenceNormal: new Vector3(0, 1, 0), | ||
strokesVector: new Vector4(1, 1, 0, 0), | ||
}; | ||
|
||
const diffCrystEnv: DiffractionCrystalEnvironment = { | ||
wavelength: beamProperties.wavelength * 1e10, | ||
referenceNormal: new Vector3(0, 1, 0), | ||
strokesVector: new Vector4(1, 1, 0, 0) | ||
} | ||
const qspace = new QSpace(detProps, diffCrystEnv, 2 * Math.PI); | ||
|
||
const qspace = new QSpace(detProps, diffCrystEnv, 2 * Math.PI) | ||
// get visible range | ||
const visibleQmin = qspace.qFromPixelPosition( | ||
ptMin.x / detector.pixelSize.width, | ||
ptMin.y / detector.pixelSize.height, | ||
); | ||
const visibleQmax = qspace.qFromPixelPosition( | ||
ptMax.x / detector.pixelSize.width, | ||
ptMax.y / detector.pixelSize.height, | ||
); | ||
|
||
// get visible range | ||
const visibleQmin = qspace.qFromPixelPosition(ptMin.x / detector.pixelSize.width, ptMin.y / detector.pixelSize.height) | ||
const visibleQmax = qspace.qFromPixelPosition(ptMax.x / detector.pixelSize.width, ptMax.y / detector.pixelSize.height) | ||
detProps.origin.z = beamProperties.minCameraLength * 1e3; | ||
qspace.setDiffractionCrystalEnviroment({ | ||
...diffCrystEnv, | ||
wavelength: beamProperties.minCameraLength * 1e10, | ||
}); | ||
const fullQMin = qspace.qFromPixelPosition( | ||
ptMin.x / detector.pixelSize.width, | ||
ptMin.y / detector.pixelSize.height, | ||
); | ||
|
||
detProps.origin.z = beamProperties.minCameraLength * 1e3 | ||
qspace.setDiffractionCrystalEnviroment({ ...diffCrystEnv, wavelength: beamProperties.minCameraLength * 1e10 }) | ||
const fullQMin = qspace.qFromPixelPosition(ptMin.x / detector.pixelSize.width, ptMin.y / detector.pixelSize.height) | ||
detProps.origin.z = beamProperties.maxCameraLength * 1e3; | ||
qspace.setDiffractionCrystalEnviroment({ | ||
...diffCrystEnv, | ||
wavelength: beamProperties.maxCameraLength * 1e10, | ||
}); | ||
const fullQMax = qspace.qFromPixelPosition( | ||
ptMax.x / detector.pixelSize.width, | ||
ptMax.y / detector.pixelSize.height, | ||
); | ||
|
||
detProps.origin.z = beamProperties.maxCameraLength * 1e3 | ||
qspace.setDiffractionCrystalEnviroment({ ...diffCrystEnv, wavelength: beamProperties.maxCameraLength * 1e10 }) | ||
const fullQMax = qspace.qFromPixelPosition(ptMax.x / detector.pixelSize.width, ptMax.y / detector.pixelSize.height) | ||
|
||
return { visibleQmin: visibleQmin, visibleQmax: visibleQmax, fullQMax: fullQMax, fullQMin: fullQMin } | ||
|
||
} | ||
return { | ||
visibleQmin: visibleQmin, | ||
visibleQmax: visibleQmax, | ||
fullQMax: fullQMax, | ||
fullQMin: fullQMin, | ||
}; | ||
} |
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
Oops, something went wrong.