Skip to content

Commit

Permalink
sample positioning slider
Browse files Browse the repository at this point in the history
fix setting source position
  • Loading branch information
WYVERN2742 committed Oct 16, 2024
1 parent 35fd318 commit 3fe880f
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 10 deletions.
57 changes: 57 additions & 0 deletions flake.lock

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

63 changes: 63 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
description = "Python environment using micromamba";

inputs = {
utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
utils,
...
}:
utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
webct = pkgs.buildFHSUserEnv {
name = "webct";
targetPkgs = pkgs: with pkgs; [
micromamba
just
fish
vscode

# gvxr
libGL
libGLU
xorg.libX11

# open3d (mesh decimation)
libudev-zero

# frontend
nodejs_22
];
# runScript=''
extraBuildCommands = ''
# link micromamba to 'conda' in .mamba
# ln -s ${pkgs.micromamba}/bin/micromamba conda
'';
# https://nixos.org/manual/nixpkgs/unstable/
profile = ''
export PATH=${pkgs.vscode.fhs}/bin:".":$PATH
export MAMBA_ROOT_PREFIX=./.mamba
eval "$(micromamba shell hook --shell=posix)"
if [ ! -d $MAMBA_ROOT_PREFIX ]; then
micromamba create -f environment.yml -y
fi
micromamba activate webct
'';
};
in {
devShells.default = pkgs.mkShell {
buildInputs = [
webct
];
shellHook = ''webct'';
};
});
}
63 changes: 63 additions & 0 deletions webct/blueprints/capture/static/js/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ let DetectorPosXElement: SlInput;
let DetectorPosYElement: SlInput;
let DetectorPosZElement: SlInput;

let SamplePosElement: SlRange;
let SampleSDDElement: HTMLParagraphElement;
let SampleSODElement: HTMLParagraphElement;
let SampleODDElement: HTMLParagraphElement;
let SampleRotateXElement: SlInput;
let SampleRotateYElement: SlInput;
let SampleRotateZElement: SlInput;
Expand Down Expand Up @@ -64,6 +68,11 @@ export function setupCapture(): boolean {
const detector_posy_element = document.getElementById("inputDetectorPosY");
const detector_posz_element = document.getElementById("inputDetectorPosZ");

const sample_position_element = document.getElementById("rangeSamplePosition");
const sample_position_sdd = document.getElementById("textSDD")
const sample_position_sod = document.getElementById("textSOD")
const sample_position_odd = document.getElementById("textODD")

const sample_rotatex_element = document.getElementById("inputSampleRotateX");
const sample_rotatey_element = document.getElementById("inputSampleRotateY");
const sample_rotatez_element = document.getElementById("inputSampleRotateZ");
Expand All @@ -78,6 +87,10 @@ export function setupCapture(): boolean {
beam_posx_element == null ||
beam_posy_element == null ||
beam_posz_element == null ||
sample_position_element == null ||
sample_position_sdd == null ||
sample_position_sod == null ||
sample_position_odd == null ||
sample_rotatex_element == null ||
sample_rotatey_element == null ||
sample_rotatez_element == null ||
Expand All @@ -99,9 +112,14 @@ export function setupCapture(): boolean {
console.log(detector_posy_element);
console.log(detector_posz_element);

console.log(sample_position_element);
console.log(sample_position_sdd);
console.log(sample_position_sod);
console.log(sample_position_odd);
console.log(sample_rotatex_element);
console.log(sample_rotatey_element);
console.log(sample_rotatez_element);

console.log(sample_rotate_clock_45_element);
console.log(sample_rotate_counter_clock_45_element);
console.log(range_nyquist);
Expand All @@ -123,6 +141,10 @@ export function setupCapture(): boolean {
DetectorPosYElement = detector_posy_element as SlInput;
DetectorPosZElement = detector_posz_element as SlInput;

SamplePosElement = sample_position_element as SlRange;
SampleSDDElement = sample_position_sdd as HTMLParagraphElement;
SampleSODElement = sample_position_sod as HTMLParagraphElement;
SampleODDElement = sample_position_odd as HTMLParagraphElement;
SampleRotateXElement = sample_rotatex_element as SlInput;
SampleRotateYElement = sample_rotatey_element as SlInput;
SampleRotateZElement = sample_rotatez_element as SlInput;
Expand All @@ -142,6 +164,28 @@ export function setupCapture(): boolean {
});
});

SamplePosElement.addEventListener("sl-change", () => {
let [sod, odd, sdd] = updateSamplePositionBar();

BeamPosYElement.value = (sod * -1).toFixed(2)
DetectorPosYElement.value = odd.toFixed(2)
});

BeamPosYElement.addEventListener("sl-change", () => {
let sod = parseFloat(BeamPosYElement.value) * -1
let odd = parseFloat(DetectorPosYElement.value)
let sdd = sod + odd
SamplePosElement.value = (sod / sdd) * 100
updateSamplePositionBar();
});
DetectorPosYElement.addEventListener("sl-change", () => {
let sod = parseFloat(BeamPosYElement.value) * -1
let odd = parseFloat(DetectorPosYElement.value)
let sdd = sod + odd
SamplePosElement.value = (sod / sdd) * 100
updateSamplePositionBar();
});

NyquistRange = range_nyquist as SlRange;
NyquistRange.addEventListener("sl-change", () => {
TotalProjectionsElement.value = Math.floor((Math.PI / 2.0 * (parseInt(PaneWidthElement.value) / (parseFloat(PanePixelSizeElement.value) / 1000))) * (NyquistRange.value as number / 100)) + "";
Expand Down Expand Up @@ -191,6 +235,20 @@ export function validateCapture(): boolean {
// =================== Display and UI =================== //
// ====================================================== //

function updateSamplePositionBar():[number, number, number] {
// Assuming sample position only moves in the Y-coordinate, not taking into account axis offsets.
let sod = parseFloat(BeamPosYElement.value) * -1
let odd = parseFloat(DetectorPosYElement.value)
let sdd = sod + odd

sod = sdd * (SamplePosElement.value / 100)
odd = sdd - sod
SampleODDElement.textContent = odd.toFixed(2) + "mm"
SampleSODElement.textContent = sod.toFixed(2) + "mm"
SampleSDDElement.textContent = sdd.toFixed(2) + "mm"
return [sod, odd, sdd]
}

function SetOverlaySize(width: number, height: number): void {
for (let index = 0; index < PreviewOverlays.length; index++) {
const overlay = PreviewOverlays[index];
Expand Down Expand Up @@ -405,4 +463,9 @@ export function setCaptureParams(properties:CaptureProperties) {
SampleRotateYElement.value = properties.sampleRotation[1] + "";
SampleRotateZElement.value = properties.sampleRotation[2] + "";

let pct = ((properties.beamPosition[1] * -1) / ((properties.beamPosition[1]* -1) + properties.detectorPosition[1])) * 100
console.log(properties);
console.log(pct);
SamplePosElement.value = pct
updateSamplePositionBar();
}
32 changes: 32 additions & 0 deletions webct/blueprints/capture/static/scss/capture.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,35 @@ sl-range.linked {
sl-range::part(tooltip) {
z-index: var(--sl-z-index-tooltip);
}

#rangeSamplePosition {
margin: 0;
}

#gridSDD {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
margin: 0;
}

#gridSDD > p {
text-align: center;
margin: 0;
}

#gridSOD {
display: grid;
grid-template-columns: 1fr max-content 1fr;
margin: 0;
}

#gridSOD > p {
text-align: center;
margin: 0;
margin-bottom: 1rem;
}

#textSDD, #textSOD, #textODD {
color: var(--sl-color-neutral-500);
font-size: var(--sl-font-size-x-small);
}
12 changes: 12 additions & 0 deletions webct/blueprints/capture/templates/tab.capture.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@

<div class="group">
<div>
<div id="gridSDD">
<p style="text-align: left;">Source</p>
<p id="textSDD">500mm</p>
<p style="text-align: right;">Detector</p>
</div>
<sl-range id="rangeSamplePosition" max="100" min="0" step="0.1" tooltip="none"></sl-range>
<div id="gridSOD">
<p id="textSOD">400mm</p>
<p>Sample</p>
<p id="textODD">100mm</p>
</div>

<p>Beam source to sample</p>
<sl-input advanced type="number" max="1000" step="0.1" min="-1000" id="inputBeamPosX" label=""><span slot="prefix">X</span>0<span slot="suffix">mm</span></sl-input>
<sl-input type="number" max="1000" step="0.1" min="-1000" id="inputBeamPosY"><span slot="prefix">Y</span>0<span slot="suffix">mm</span></sl-input>
Expand Down
19 changes: 9 additions & 10 deletions webct/components/sim/simulators/GVXRSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, sid:str, pid:int):
self._initRenderer()

def _initRenderer(self):
gvxr.createWindow(-1, 0, "OPENGL")
gvxr.createWindow(-1, 0, "EGL")
gvxr.setWindowSize(1800, 600)

gvxr.removePolygonMeshesFromSceneGraph()
Expand Down Expand Up @@ -89,12 +89,7 @@ def beam(self) -> Beam:
def beam(self, value: Beam) -> None:
if value.params.projection == PROJECTION.POINT:
gvxr.usePointSource()
if value.params.spotSize != 0:
gvxr.setFocalSpot(*self.capture.beam_position, value.params.spotSize, "mm", 3)
else:
# workaround to disable focalspot
if self.capture is not None:
gvxr.setSourcePosition(*self.capture.beam_position, "mm")
# Focal spot is setup in capture, as it changes beam position.
elif value.params.projection == PROJECTION.PARALLEL:
gvxr.useParallelBeam()
else:
Expand Down Expand Up @@ -204,10 +199,14 @@ def capture(self) -> CaptureParameters:

@capture.setter
def capture(self, value: CaptureParameters) -> None:
print(value)
gvxr.setDetectorPosition(*value.detector_position, "mm")
if self.beam.params.spotSize == 0.0:
# if using a spot size, the focal point is handled in beam settings
gvxr.setSourcePosition(*value.beam_position, "mm")
gvxr.setSourcePosition(*value.beam_position, "mm")

if self.beam.params.spotSize != 0:
# todo: change to square source
gvxr.setFocalSpot(*self.capture.beam_position, self.beam.params.spotSize, "mm", 3)

# Changing detector/source position will effect if the source is in
# parallel or point mode. We re-set the beam value to fix this.
self.beam = self._beam
Expand Down

0 comments on commit 3fe880f

Please sign in to comment.