Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sigma to UI #712

Merged
merged 3 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,73 @@ import { Object3D } from 'three';
import { Editor } from '../../../../js/Editor';
import { useSmartWatchEditorState } from '../../../../util/hooks/signals';
import { PropertiesCategory } from './PropertiesCategory';
import { Beam, isBeam } from '../../../../util/Beam';
import { NumberPropertyField, PropertyField, Vector2PropertyField } from '../fields/PropertyField';
import { Beam, isBeam, SigmaType, SIGMA_TYPE } from '../../../../util/Beam';
import {
NumberPropertyField,
PropertyField,
SelectPropertyField,
Vector2PropertyField
} from '../fields/PropertyField';
import { PARTICLE_TYPES } from '../../../../util/particles';
import { IParticleType, ParticleSelect } from '../../../Select/ParticlesSelect';
import { Divider } from '@mui/material';

function BeamSigmaField(props: { beam: Beam }) {
const configuration = {
[SIGMA_TYPE.Gaussian]: {
X: {
text: 'sigma in X'
},
Y: {
text: 'sigma in Y'
}
},
[SIGMA_TYPE['Flat square']]: {
X: {
text: 'half-side in X'
},
Y: {
text: 'half-side in Y'
}
},
[SIGMA_TYPE['Flat circular']]: {
Y: {
text: 'radius'
}
}
};

const selectedConfiguration = configuration[props.beam.sigma.type];

return (
<>
<SelectPropertyField
label='Beam shape'
value={props.beam.sigma.type}
onChange={value =>
(props.beam.sigma = { ...props.beam.sigma, type: value as SigmaType })
}
options={Object.keys(SIGMA_TYPE)}
/>
{'X' in selectedConfiguration && (
<NumberPropertyField
label={selectedConfiguration.X.text}
value={props.beam.sigma.x}
onChange={value => (props.beam.sigma = { ...props.beam.sigma, x: value })}
min={0}
unit='cm'
/>
)}
<NumberPropertyField
label={selectedConfiguration.Y.text}
value={props.beam.sigma.y}
onChange={value => (props.beam.sigma = { ...props.beam.sigma, y: value })}
min={0}
unit='cm'
/>
</>
);
}

export function BeamConfiguration(props: { editor: Editor; object: Object3D }) {
const { object, editor } = props;
Expand Down Expand Up @@ -35,6 +98,7 @@ export function BeamConfiguration(props: { editor: Editor; object: Object3D }) {
watchedObject.energySpread = v;
}}
/>
<PropertyField children={<Divider />} />
<Vector2PropertyField
label='Divergence XY'
value={watchedObject.divergence}
Expand All @@ -52,14 +116,11 @@ export function BeamConfiguration(props: { editor: Editor; object: Object3D }) {
watchedObject.divergence.distanceToFocal = v;
}}
/>
{console.log(watchedObject.beamSigma)}
<Vector2PropertyField
label='Beam sigma'
value={watchedObject.beamSigma}
onChange={v => {
watchedObject.beamSigma = v;
}}
/>
<PropertyField children={<Divider />} />

<BeamSigmaField beam={watchedObject} />

<PropertyField children={<Divider />} />
<NumberPropertyField
label='Number of primary particles'
precision={0}
Expand Down
26 changes: 19 additions & 7 deletions src/ThreeEditor/util/Beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { Editor } from '../js/Editor';
import { Particle, PARTICLE_TYPES } from './particles';
import { SimulationObject3D } from './SimulationBase/SimulationMesh';

export const SIGMA_TYPE = {
'Gaussian': 'Gaussian',
'Flat square': 'Flat square',
'Flat circular': 'Flat circular'
} as const;
export type SigmaType = keyof typeof SIGMA_TYPE;

export interface BeamJSON {
position: THREE.Vector3Tuple;
direction: THREE.Vector3Tuple;
Expand All @@ -24,7 +31,8 @@ export interface BeamJSON {
z: number;
a: number;
};
beamSigma: {
sigma: {
type: SigmaType;
x: number;
y: number;
};
Expand All @@ -47,7 +55,8 @@ const _default = {
a: 1,
z: 1
},
beamSigma: {
sigma: {
type: SIGMA_TYPE.Gaussian,
x: 0,
y: 0
},
Expand Down Expand Up @@ -85,7 +94,8 @@ export class Beam extends SimulationObject3D {
distanceToFocal: number;
};

beamSigma: {
sigma: {
type: SigmaType
x: number;
y: number;
};
Expand Down Expand Up @@ -120,7 +130,8 @@ export class Beam extends SimulationObject3D {
'energySpread',
'divergence',
'particleData',
'numberOfParticles'
'numberOfParticles',
'sigma'
];
if (informChange.includes(prop)) {
this.debouncedDispatchChanged();
Expand Down Expand Up @@ -151,7 +162,7 @@ export class Beam extends SimulationObject3D {

this.divergence = { ..._default.divergence };

this.beamSigma = { ..._default.beamSigma };
this.sigma = { ..._default.sigma };

this.particleData = _default.particle;

Expand Down Expand Up @@ -243,6 +254,7 @@ export class Beam extends SimulationObject3D {
this.energySpread = _default.energySpread;
this.divergence = { ..._default.divergence };
this.particleData = _default.particle;
this.sigma = { ..._default.sigma };
this.material.color.setHex(0xffff00); // yellow
}

Expand All @@ -252,7 +264,7 @@ export class Beam extends SimulationObject3D {
direction: this.direction.toArray(),
energy: this.energy,
energySpread: this.energySpread,
beamSigma: this.beamSigma,
sigma: this.sigma,
divergence: this.divergence,
particle: this.particleData,
colorHex: this.material.color.getHex(),
Expand All @@ -272,7 +284,7 @@ export class Beam extends SimulationObject3D {
this.particleData = loadedData.particle;
this.material.color.setHex(loadedData.colorHex);
this.numberOfParticles = loadedData.numberOfParticles;
this.beamSigma = loadedData.beamSigma;
this.sigma = loadedData.sigma;
return this;
}

Expand Down