Skip to content

Commit

Permalink
Use other util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Jan 2, 2024
1 parent 6e9220c commit dbcc01b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
21 changes: 10 additions & 11 deletions photon-client/src/components/cameras/CameraCalibrationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ import PvSwitch from "@/components/common/pv-switch.vue";
import PvSelect from "@/components/common/pv-select.vue";
import PvNumberInput from "@/components/common/pv-number-input.vue";
import { WebsocketPipelineType } from "@/types/WebsocketDataTypes";
import { getResolutionString, resolutionsAreEqual } from "@/lib/PhotonUtils";
const settingsValid = ref(true);
const getCalibrationCoeffs = (resolution: Resolution) => {
return useCameraSettingsStore().currentCameraSettings.completeCalibrations.find(
(cal) => cal.resolution.width === resolution.width && cal.resolution.height === resolution.height
return useCameraSettingsStore().currentCameraSettings.completeCalibrations.find((cal) =>
resolutionsAreEqual(cal.resolution, resolution)
);
};
const getUniqueVideoResolutions = (): VideoFormat[] => {
const uniqueResolutions: VideoFormat[] = [];
useCameraSettingsStore().currentCameraSettings.validVideoFormats.forEach((format, index) => {
if (
!uniqueResolutions.some(
(v) => v.resolution.width === format.resolution.width && v.resolution.height === format.resolution.height
)
) {
if (!uniqueResolutions.some((v) => resolutionsAreEqual(v.resolution, format.resolution))) {
format.index = index;
const calib = getCalibrationCoeffs(format.resolution);
Expand Down Expand Up @@ -59,7 +56,7 @@ const getUniqueVideoResolutions = (): VideoFormat[] => {
};
const getUniqueVideoResolutionStrings = (): { name: string; value: number }[] =>
getUniqueVideoResolutions().map<{ name: string; value: number }>((f) => ({
name: `${f.resolution.width} X ${f.resolution.height}`,
name: `${getResolutionString(f.resolution)}`,
// Index won't ever be undefined
value: f.index || 0
}));
Expand Down Expand Up @@ -155,7 +152,7 @@ const openCalibUploadPrompt = () => {
};
const readImportedCalibration = () => {
const files = importCalibrationFromCalibDB.value.files;
if(files.length === 0) return;
if (files.length === 0) return;
files[0].text().then((text) => {
useCameraSettingsStore()
Expand Down Expand Up @@ -238,7 +235,7 @@ const endCalibration = () => {
</thead>
<tbody>
<tr v-for="(value, index) in getUniqueVideoResolutions()" :key="index">
<td>{{ value.resolution.width }} X {{ value.resolution.height }}</td>
<td>{{ getResolutionString(value.resolution) }}</td>
<td>
{{ value.mean !== undefined ? (isNaN(value.mean) ? "NaN" : value.mean.toFixed(2) + "px") : "-" }}
</td>
Expand Down Expand Up @@ -453,7 +450,9 @@ const endCalibration = () => {
<v-card-text>
Camera has been successfully calibrated for
{{
getUniqueVideoResolutionStrings().find(v => v.value === useStateStore().calibrationData.videoFormatIndex)?.name
getUniqueVideoResolutionStrings().find(
(v) => v.value === useStateStore().calibrationData.videoFormatIndex
)?.name
}}!
</v-card-text>
</template>
Expand Down
9 changes: 7 additions & 2 deletions photon-client/src/components/dashboard/tabs/InputTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PvSelect from "@/components/common/pv-select.vue";
import { computed, getCurrentInstance } from "vue";
import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore";
import { useStateStore } from "@/stores/StateStore";
import { getResolutionString } from "@/lib/PhotonUtils";
// Due to something with libcamera or something else IDK much about, the 90° rotations need to be disabled if the libcamera drivers are being used.
const cameraRotations = computed(() =>
Expand All @@ -30,7 +31,7 @@ const getNumberOfSkippedDivisors = () => streamDivisors.length - getFilteredStre
const cameraResolutions = computed(() =>
useCameraSettingsStore().currentCameraSettings.validVideoFormats.map(
(f) => `${f.resolution.width} X ${f.resolution.height} at ${f.fps} FPS, ${f.pixelFormat}`
(f) => `${getResolutionString(f.resolution)} at ${f.fps} FPS, ${f.pixelFormat}`
)
);
const handleResolutionChange = (value: number) => {
Expand All @@ -48,7 +49,11 @@ const streamResolutions = computed(() => {
const streamDivisors = getFilteredStreamDivisors();
const currentResolution = useCameraSettingsStore().currentVideoFormat.resolution;
return streamDivisors.map(
(x) => `${Math.floor(currentResolution.width / x)} X ${Math.floor(currentResolution.height / x)}`
(x) =>
`${getResolutionString({
width: Math.floor(currentResolution.width / x),
height: Math.floor(currentResolution.height / x)
})}`
);
});
const handleStreamResolutionChange = (value: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const openOfflineUpdatePrompt = () => {
};
const handleOfflineUpdate = () => {
const files = offlineUpdate.value.files;
if(files.length === 0) return;
if (files.length === 0) return;
const formData = new FormData();
formData.append("jarData", files[0]);
Expand Down

0 comments on commit dbcc01b

Please sign in to comment.