FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

clear calibration file, use parent folder name for desktop import by BryonLewis · Pull Request #1716 · Kitware/dive · GitHub

/ dive Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (5) .vue  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
Expand Up @@ -11,10 +11,11 @@ export default defineComponent({
...importMultiCamContextProp,
},
setup(props) {
const { calibrationFile, open } = props.ctx;
const { calibrationFile, open, clearCalibration } = props.ctx;
return {
calibrationFile,
open,
clearCalibration,
};
},
});
Expand All @@ -28,13 +29,22 @@ export default defineComponent({
<v-text-field
label="Calibration File"
placeholder="Not selected"
disabled
readonly
outlined
dense
hide-details
:value="calibrationFile"
class="mr-3"
/>
<v-btn
v-if="calibrationFile"
icon
class="mr-2"
aria-label="Clear calibration file"
@click="clearCalibration"
>
<v-icon>mdi-close</v-icon>
</v-btn>
<v-btn
color="primary"
@click="open('calibration', 'calibration')"
Expand Down
This file contains hidden or 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
Expand Up @@ -10,9 +10,11 @@ import {
isVideoFileName,
organizeSubfolderCameras,
orderSubfolderCameraNames,
parentFolderLabelFromAbsolutePaths,
preferLeftSubfolderFirst,
pickDefaultMulticamCamera,
sortSubfolderCameraNames,
subfolderVideoDisplayLabel,
} from './multicamSubfolderLayout';

describe('isValidCameraName', () => {
Expand Down Expand Up @@ -46,6 +48,27 @@ describe('applyParentPathToAssignments', () => {
});
});

describe('parentFolderLabelFromAbsolutePaths', () => {
it('returns the shared parent folder name for sibling camera paths', () => {
expect(parentFolderLabelFromAbsolutePaths([
'/data/my_scene/left',
'/data/my_scene/right',
])).toBe('my_scene');
});

it('handles Windows-style paths', () => {
expect(parentFolderLabelFromAbsolutePaths([
'C:\\datasets\\stereo\\left',
'C:\\datasets\\stereo\\right',
])).toBe('stereo');
});

it('returns empty when no paths are provided', () => {
expect(parentFolderLabelFromAbsolutePaths([])).toBe('');
expect(parentFolderLabelFromAbsolutePaths(['', ' '])).toBe('');
});
});

describe('pickDefaultMulticamCamera', () => {
it('prefers center or middle by name', () => {
expect(pickDefaultMulticamCamera(['STAR', 'CENTER', 'PORT'])).toBe('CENTER');
Expand Down Expand Up @@ -131,6 +154,23 @@ describe('isVideoFileName', () => {
});
});

describe('subfolderVideoDisplayLabel', () => {
const mk = (name: string) => ({ name } as File);

it('uses the video file name when only the stem is known on web', () => {
expect(subfolderVideoDisplayLabel('left', 'left', [mk('left.mp4')])).toBe('left.mp4');
expect(subfolderVideoDisplayLabel('right', 'right', [mk('right.mov')])).toBe('right.mov');
});

it('uses the path basename when it includes a video extension', () => {
expect(subfolderVideoDisplayLabel('/data/stereo/left.mp4', 'left', [])).toBe('left.mp4');
});

it('falls back to folder name when no video file is available', () => {
expect(subfolderVideoDisplayLabel('left', 'left', [])).toBe('left');
});
});

describe('groupRootLevelVideoFiles', () => {
const mk = (path: string) => ({ webkitRelativePath: path, name: path.split('/').pop() } as File);

Expand Down
This file contains hidden or 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
Expand Up @@ -220,6 +220,21 @@ export function commonPathPrefix(paths: string[]): string {
return prefix.join('/');
}

/** Last path segment of the common parent directory across absolute filesystem paths. */
export function parentFolderLabelFromAbsolutePaths(paths: string[]): string {
const normalized = paths.map((p) => p.trim()).filter(Boolean);
if (!normalized.length) {
return '';
}
const withForwardSlashes = normalized.map((p) => p.replace(/\\/g, '/'));
const parentPath = commonPathPrefix(withForwardSlashes);
if (!parentPath) {
return '';
}
const segments = parentPath.split('/').filter(Boolean);
return segments[segments.length - 1] || parentPath;
}

function stripPathPrefix(path: string, prefix: string): string {
if (!prefix) {
return path;
Expand Down Expand Up @@ -273,6 +288,23 @@ export function isVideoFileName(fileName: string): boolean {
return fileVideoTypes.includes(ext);
}

/** Display label for a video camera in parent-folder import (includes file extension when known). */
export function subfolderVideoDisplayLabel(
sourcePath: string,
folderName: string,
files: Pick<File, 'name'>[] = [],
): string {
const videoFile = files.find((file) => isVideoFileName(file.name));
if (videoFile) {
return videoFile.name;
}
const fromPath = sourcePath.split(/[/\\]/).pop() || '';
if (fromPath && isVideoFileName(fromPath)) {
return fromPath;
}
return fromPath || folderName;
}

/**
* Group video files that sit directly in the selected parent folder (one camera per file).
* Camera keys are the file stem (basename without extension).
Expand Down
This file contains hidden or 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
Expand Up @@ -20,7 +20,9 @@ import {
groupParentFolderByCamera,
isValidCameraName,
organizeSubfolderCameras,
parentFolderLabelFromAbsolutePaths,
pickDefaultMulticamCamera,
subfolderVideoDisplayLabel,
} from 'dive-common/components/ImportMultiCamDialog/multicamSubfolderLayout';
import { findStereoCalibrationInFileList } from 'dive-common/stereoParentFolder';
import { ImageSequenceType, VideoType } from 'dive-common/constants';
Expand Down Expand Up @@ -350,7 +352,11 @@ export function useImportMultiCamDialog(
Vue.set(
subfolderOriginalNames.value,
cameraName,
subfolderSourceDisplayLabel(sourcePath, organized.assignments[i].folderName),
subfolderSourceDisplayLabel(
sourcePath,
organized.assignments[i].folderName,
files,
),
);
Vue.set(folderList.value, cameraName, { sourcePath, trackFile: '' });
// eslint-disable-next-line no-await-in-loop -- import each camera media sequentially
Expand Down Expand Up @@ -422,7 +428,7 @@ export function useImportMultiCamDialog(
props.unregisterSubfolderCamera(oldSourcePath);
}
const displayName = props.dataType === VideoType
? (resolvedPath.split(/[/\\]/).pop() || cameraKey)
? subfolderSourceDisplayLabel(resolvedPath, cameraKey, files)
: ((displayRoot || sourcePath).split(/[/\\]/).pop() || cameraKey);
Vue.set(subfolderOriginalNames.value, cameraKey, displayName);
folderList.value[cameraKey].sourcePath = resolvedPath;
Expand Down Expand Up @@ -477,6 +483,7 @@ export function useImportMultiCamDialog(
folder,
await importRequest(() => props.importMedia(sourcePath)),
);
syncSuggestedDatasetNameFromCameraPaths();
} else if (importType.value === 'subfolders') {
const sourcePath = ret.root || path;
await importRequest(() => updateSubfolderCameraSource(
Expand Down Expand Up @@ -567,12 +574,30 @@ export function useImportMultiCamDialog(
(val: string) => (val || '').trim().length > 0 || 'Dataset name is required',
];

function syncSuggestedDatasetNameFromCameraPaths() {
if (!listParentFolderCameras || importType.value !== 'multi') {
return;
}
const paths = Object.values(folderList.value)
.map((entry) => entry.sourcePath)
.filter((path) => path);
const label = parentFolderLabelFromAbsolutePaths(paths);
if (label && !datasetName.value.trim()) {
datasetName.value = label;
}
}

function clearCalibration() {
calibrationFile.value = '';
}

function subfolderSourceDisplayLabel(
sourcePath: string,
folderName: string,
files: File[] = [],
): string {
if (props.dataType === VideoType) {
return sourcePath.split(/[/\\]/).pop() || folderName;
return subfolderVideoDisplayLabel(sourcePath, folderName, files);
}
return folderName;
}
Expand Down Expand Up @@ -636,5 +661,6 @@ export function useImportMultiCamDialog(
deleteSet,
onRenameCamera,
openAnnotationFile,
clearCalibration,
};
}
13 changes: 13 additions & 0 deletions client/platform/desktop/backend/native/multiCam.spec.ts
This file contains hidden or 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
Expand Up @@ -87,6 +87,19 @@ type FailingKeyword= Record<string, {
}>;

describe('native.multiCamImport', () => {
it('uses datasetName when provided for folder imports', async () => {
const output = await beginMultiCamImport({
datasetName: 'my_stereo_scene',
defaultDisplay: 'left',
sourceList: {
left: { sourcePath: '/home/user/data/stereoLeftRightImages/left', trackFile: '' },
right: { sourcePath: '/home/user/data/stereoLeftRightImages/right', trackFile: '' },
},
type: 'image-sequence',
});
expect(output.jsonMeta.name).toBe('my_stereo_scene');
});

if (multiCamSetup.folderTests) {
const folderTests = (multiCamSetup.folderTests as FolderTest);
Object.entries(folderTests).forEach(([key, val]) => {
Expand Down
This file contains hidden or 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
Expand Up @@ -101,7 +101,9 @@ async function beginMultiCamImport(args: MultiCamImportArgs): Promise<DesktopMed
originalImageFiles: [],
transcodedVideoFile: '',
transcodedImageFiles: [],
name: 'Multi-camera data',
name: (isFolderArgs(args) && args.datasetName?.trim())
? args.datasetName.trim()
: 'Multi-camera data',
multiCam: {
cameras,
calibration: args.calibrationFile,
Expand Down
Loading

Back | FazBrowse Home | New Git URL