Skip to content

Commit cca4b2e

Browse files
committed
pr feedback
1 parent af68170 commit cca4b2e

File tree

4 files changed

+86
-74
lines changed

4 files changed

+86
-74
lines changed

frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts

+9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export class ResolutionInfo {
9898
return this.resolutionMap.has(powerOfTwo);
9999
}
100100

101+
hasResolution(resolution: Vector3): boolean {
102+
return this.resolutionMap.has(Math.max(...resolution));
103+
}
104+
101105
getResolutionByIndex(index: number): Vector3 | null | undefined {
102106
const powerOfTwo = this.indexToPowerOf2(index);
103107
return this.getResolutionByPowerOf2(powerOfTwo);
@@ -215,6 +219,11 @@ export class ResolutionInfo {
215219
return bestIndexWithDistance[0];
216220
}
217221

222+
getClosestExistingResolution(resolution: Vector3): Vector3 {
223+
const index = Math.log2(Math.max(...resolution));
224+
return this.getResolutionByIndex(this.getClosestExistingIndex(index)) as Vector3;
225+
}
226+
218227
hasSmallerAndOrHigherIndex(index: number): SmallerOrHigherInfo {
219228
const indices = this.getAllIndices();
220229
const hasSmallOrHigher = {

frontend/javascripts/oxalis/view/action-bar/download_modal_view.tsx

+35-64
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
LayerSelection,
3232
BoundingBoxSelection,
3333
getReadableNameOfVolumeLayer,
34+
MagSlider,
3435
} from "oxalis/view/right-border-tabs/starting_job_modals";
3536
import { getUserBoundingBoxesFromState } from "oxalis/model/accessors/tracing_accessor";
3637
import {
@@ -73,8 +74,6 @@ type ExportLayerInfos = {
7374
layerName: string | null;
7475
tracingId: string | null;
7576
annotationId: string | null;
76-
lowestResolutionIndex: number;
77-
highestResolutionIndex: number;
7877
};
7978

8079
enum ExportFormat {
@@ -84,26 +83,21 @@ enum ExportFormat {
8483

8584
const EXPECTED_DOWNSAMPLING_FILE_SIZE_FACTOR = 1.33;
8685

87-
const exportKey = (layerInfos: ExportLayerInfos, resolutionIndex: number) =>
88-
`${layerInfos.layerName || ""}__${layerInfos.tracingId || ""}__${resolutionIndex}`;
86+
const exportKey = (layerInfos: ExportLayerInfos, mag: Vector3) =>
87+
`${layerInfos.layerName || ""}__${layerInfos.tracingId || ""}__${mag.join("-")}`;
8988

9089
function getExportLayerInfos(
9190
layer: APIDataLayer,
9291
tracing: HybridTracing | null | undefined,
9392
): ExportLayerInfos {
9493
const annotationId = tracing != null ? tracing.annotationId : null;
9594

96-
const highestResolutionIndex = getResolutionInfo(layer.resolutions).getHighestResolutionIndex();
97-
const lowestResolutionIndex = getResolutionInfo(layer.resolutions).getClosestExistingIndex(0);
98-
9995
if (layer.category === "color" || !layer.tracingId) {
10096
return {
10197
displayName: layer.name,
10298
layerName: layer.name,
10399
tracingId: null,
104100
annotationId: null,
105-
lowestResolutionIndex,
106-
highestResolutionIndex,
107101
};
108102
}
109103

@@ -119,8 +113,6 @@ function getExportLayerInfos(
119113
return {
120114
displayName: readableVolumeLayerName,
121115
layerName: layer.fallbackLayerInfo?.name ?? null,
122-
lowestResolutionIndex,
123-
highestResolutionIndex,
124116
tracingId: volumeTracing.tracingId,
125117
annotationId,
126118
};
@@ -169,7 +161,7 @@ function useRunningJobs(): [
169161
(
170162
dataset: APIDataset,
171163
boundingBox: BoundingBoxType,
172-
resolutionIndex: number,
164+
mag: Vector3,
173165
selectedLayerInfos: ExportLayerInfos,
174166
exportFormat: ExportFormat,
175167
) => Promise<void>,
@@ -203,35 +195,29 @@ function useRunningJobs(): [
203195

204196
return [
205197
runningJobs,
206-
async (dataset, boundingBox, resolutionIndex, selectedLayerInfos, exportFormat) => {
198+
async (dataset, boundingBox, mag, selectedLayerInfos, exportFormat) => {
207199
const datasetResolutionInfo = getDatasetResolutionInfo(dataset);
208200
const job = await startExportTiffJob(
209201
dataset.name,
210202
dataset.owningOrganization,
211203
computeArrayFromBoundingBox(boundingBox),
212204
selectedLayerInfos.layerName,
213-
datasetResolutionInfo.getResolutionByIndexOrThrow(resolutionIndex).join("-"),
205+
mag.join("-"),
214206
selectedLayerInfos.annotationId,
215207
selectedLayerInfos.displayName,
216208
exportFormat === ExportFormat.OME_TIFF,
217209
);
218-
setRunningJobs((previous) => [
219-
...previous,
220-
[exportKey(selectedLayerInfos, resolutionIndex), job.id],
221-
]);
210+
setRunningJobs((previous) => [...previous, [exportKey(selectedLayerInfos, mag), job.id]]);
222211
},
223212
];
224213
}
225214

226215
function estimateFileSize(
227216
selectedLayer: APIDataLayer,
228-
resolutionIndex: number,
217+
mag: Vector3,
229218
boundingBox: BoundingBoxType,
230219
exportFormat: ExportFormat,
231220
) {
232-
const mag = getResolutionInfo(selectedLayer.resolutions).getResolutionByIndexOrThrow(
233-
resolutionIndex,
234-
);
235221
const shape = computeShapeFromBoundingBox(boundingBox);
236222
const volume =
237223
Math.ceil(shape[0] / mag[0]) * Math.ceil(shape[1] / mag[1]) * Math.ceil(shape[2] / mag[2]);
@@ -242,9 +228,8 @@ function estimateFileSize(
242228
);
243229
}
244230

245-
function formatSelectedScale(dataset: APIDataset, resolutionIndex: number) {
231+
function formatSelectedScale(dataset: APIDataset, mag: Vector3) {
246232
const scale = dataset.dataSource.scale;
247-
const mag = getDatasetResolutionInfo(dataset).getResolutionByIndexOrThrow(resolutionIndex);
248233
formatScale([scale[0] * mag[0], scale[1] * mag[1], scale[2] * mag[2]]);
249234
}
250235

@@ -343,33 +328,34 @@ function _DownloadModalView({
343328

344329
const selectedLayer = getLayerByName(dataset, selectedLayerName);
345330
const selectedLayerInfos = getExportLayerInfos(selectedLayer, tracing);
331+
const selectedLayerResolutionInfo = getResolutionInfo(selectedLayer.resolutions);
346332

347333
const userBoundingBoxes = [
348334
...rawUserBoundingBoxes,
349335
{
350336
id: -1,
351-
name: "Full dataset",
337+
name: "Full layer",
352338
boundingBox: computeBoundingBoxFromBoundingBoxObject(selectedLayer.boundingBox),
353339
color: [255, 255, 255],
354340
isVisible: true,
355341
} as UserBoundingBox,
356342
];
343+
357344
const [selectedBoundingBoxId, setSelectedBoundingBoxId] = useState(
358345
initialBoundingBoxId ?? userBoundingBoxes[0].id,
359346
);
360-
361-
const datasetResolutionInfo = getDatasetResolutionInfo(dataset);
362-
const { lowestResolutionIndex, highestResolutionIndex } = selectedLayerInfos;
363-
const [rawResolutionIndex, setResolutionIndex] = useState<number>(lowestResolutionIndex);
364-
const resolutionIndex = clamp(lowestResolutionIndex, rawResolutionIndex, highestResolutionIndex);
347+
const [rawMag, setMag] = useState<Vector3>(selectedLayerResolutionInfo.getLowestResolution());
348+
const mag = selectedLayerResolutionInfo.hasResolution(rawMag)
349+
? rawMag
350+
: selectedLayerResolutionInfo.getClosestExistingResolution(rawMag);
365351
const [exportFormat, setExportFormat] = useState<ExportFormat>(ExportFormat.OME_TIFF);
366352

367353
const selectedBoundingBox = userBoundingBoxes.find(
368354
(bbox) => bbox.id === selectedBoundingBoxId,
369355
) as UserBoundingBox;
370356
const { isExportable, alerts: boundingBoxCompatibilityAlerts } = isBoundingBoxExportable(
371357
selectedBoundingBox.boundingBox,
372-
datasetResolutionInfo.getResolutionByIndexOrThrow(resolutionIndex),
358+
mag,
373359
);
374360

375361
const [runningExportJobs, triggerExportJob] = useRunningJobs();
@@ -390,7 +376,7 @@ function _DownloadModalView({
390376
await triggerExportJob(
391377
dataset,
392378
selectedBoundingBox.boundingBox,
393-
resolutionIndex,
379+
mag,
394380
selectedLayerInfos,
395381
exportFormat,
396382
);
@@ -515,6 +501,9 @@ with wk.webknossos_context(
515501
const hasSkeleton = tracing.skeleton != null;
516502

517503
const okText = okTextForTab.get(activeTabKey);
504+
const isCurrentlyRunningExportJob =
505+
activeTabKey === "export" &&
506+
runningExportJobs.some(([key]) => key === exportKey(selectedLayerInfos, mag));
518507

519508
return (
520509
<Modal
@@ -526,24 +515,10 @@ with wk.webknossos_context(
526515
<Button
527516
key="ok"
528517
type="primary"
529-
disabled={
530-
activeTabKey === "export" &&
531-
(!isExportable ||
532-
runningExportJobs.some(
533-
([key]) => key === exportKey(selectedLayerInfos, resolutionIndex),
534-
) || // The export is already running or...
535-
isMergerModeEnabled) // Merger mode is enabled
536-
}
518+
disabled={!isExportable || isCurrentlyRunningExportJob || isMergerModeEnabled}
537519
onClick={handleOk}
520+
loading={isCurrentlyRunningExportJob}
538521
>
539-
{activeTabKey === "export" &&
540-
runningExportJobs.some(
541-
([key]) => key === exportKey(selectedLayerInfos, resolutionIndex),
542-
) && (
543-
<>
544-
<SyncOutlined spin />{" "}
545-
</>
546-
)}
547522
{okText}
548523
</Button>
549524
) : null
@@ -684,7 +659,11 @@ with wk.webknossos_context(
684659
<BoundingBoxSelection
685660
value={selectedBoundingBoxId}
686661
userBoundingBoxes={userBoundingBoxes}
687-
setSelectedBoundingBoxId={setSelectedBoundingBoxId}
662+
setSelectedBoundingBoxId={(boxId: number | null) => {
663+
if (boxId != null) {
664+
setSelectedBoundingBoxId(boxId);
665+
}
666+
}}
688667
style={{ width: "100%" }}
689668
/>
690669
{boundingBoxCompatibilityAlerts}
@@ -698,25 +677,17 @@ with wk.webknossos_context(
698677
</Divider>
699678
<Row>
700679
<Col span={19}>
701-
<Slider
702-
tooltip={{
703-
formatter: () =>
704-
datasetResolutionInfo
705-
.getResolutionByIndexOrThrow(resolutionIndex)
706-
.join("-"),
707-
}}
708-
min={lowestResolutionIndex}
709-
max={highestResolutionIndex}
710-
step={1}
711-
value={resolutionIndex}
712-
onChange={(value) => setResolutionIndex(value)}
680+
<MagSlider
681+
resolutionInfo={selectedLayerResolutionInfo}
682+
value={mag}
683+
onChange={setMag}
713684
/>
714685
</Col>
715686
<Col
716687
span={5}
717688
style={{ display: "flex", justifyContent: "flex-end", alignItems: "center" }}
718689
>
719-
{datasetResolutionInfo.getResolutionByIndexOrThrow(resolutionIndex).join("-")}
690+
{mag.join("-")}
720691
</Col>
721692
</Row>
722693
<Text
@@ -728,12 +699,12 @@ with wk.webknossos_context(
728699
Estimated file size:{" "}
729700
{estimateFileSize(
730701
selectedLayer,
731-
resolutionIndex,
702+
mag,
732703
selectedBoundingBox.boundingBox,
733704
exportFormat,
734705
)}
735706
<br />
736-
Resolution: {formatSelectedScale(dataset, resolutionIndex)}
707+
Resolution: {formatSelectedScale(dataset, mag)}
737708
</Text>
738709

739710
{downloadHint}

frontend/javascripts/oxalis/view/right-border-tabs/bounding_box_tab.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export default function BoundingBoxTab() {
191191
) : null}
192192
{selectedBoundingBoxForExport != null ? (
193193
<DownloadModalView
194-
isOpen={true}
194+
isOpen
195195
onClose={() => setSelectedBoundingBoxForExport(null)}
196196
initialBoundingBoxId={selectedBoundingBoxForExport.id}
197197
initialTab="export"

0 commit comments

Comments
 (0)