-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Isosurface generation (now inluding frontend) (#3495)
* Isosurface: route and actor setup * isosurface wip * removed debug print (#3313) * add size parameter * Restructure isosurface actor interface (#3313) * isosurfaces roughly working * support for v oxel dimensions, #3313 * loading and parsing mappings, #3313 * parsing mappings, generics, #3313 * use raw float arrays as protocol for isosurfaces, #3313 * expose voxel dimensions as parameter, proper scale, #3313 * wip, #3313 * working on mappings, #3313 * request via actor, #3313 * mapping cache WIP, #3313 * mapping cache working, #3313 * cubeSize is now vector, not scalar, #3313 * Refactoring, #3313 * support voxelDimensions in data requests, #3313 * Fix data requests with nnon-trivial voxelDimension, #3313 * fixing isosurfaces with nnew voxelDimensions data requests, #3313 * isosurface refactoring, #3313 * skip locations where the segment id is not present, #3313 * PR feedback, #3313 * move mappingservice out of holder * Isosurface frontend (#3493) * button in frontend * startup parameters * add mapping to isosurface request, #3313 * loading and parsing mappings, #3313 * build faster * use raw float array as isosurface protocol, #3313 * expose voxel dimensions as parameter, proper scale, #3313 * smooth shading, #3313 * improve lighting for isosurface * improve lighting and clean up code * fix merge conflicts * refactor isosurface front-end code and enable lookups according to bucket structure * adapt code to cubeSize vector * clean up * clean up * use mapped voxels if mapping is active; hide setting in non-view-mode * update changelog
- Loading branch information
1 parent
03d6b43
commit 0638d53
Showing
38 changed files
with
1,113 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
106 changes: 106 additions & 0 deletions
106
app/assets/javascripts/oxalis/model/sagas/isosurface_saga.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import type { APIDataset } from "admin/api_flow_types"; | ||
import { ControlModeEnum, type Vector3 } from "oxalis/constants"; | ||
import { FlycamActions } from "oxalis/model/actions/flycam_actions"; | ||
import { type Saga, _takeEvery, select, take } from "oxalis/model/sagas/effect-generators"; | ||
import { computeIsosurface } from "admin/admin_rest_api"; | ||
import { getFlooredPosition } from "oxalis/model/accessors/flycam_accessor"; | ||
import { map3 } from "libs/utils"; | ||
import DataLayer from "oxalis/model/data_layer"; | ||
import Model from "oxalis/model"; | ||
import getSceneController from "oxalis/controller/scene_controller_provider"; | ||
|
||
class ThreeDMap<T> { | ||
map: Map<number, ?Map<number, ?Map<number, T>>>; | ||
|
||
constructor() { | ||
this.map = new Map(); | ||
} | ||
|
||
get(vec: Vector3): ?T { | ||
const [x, y, z] = vec; | ||
if (this.map[x] == null) { | ||
return null; | ||
} | ||
if (this.map[x][y] == null) { | ||
return null; | ||
} | ||
if (this.map[x][y][z] == null) { | ||
return null; | ||
} | ||
return this.map[x][y][z]; | ||
} | ||
|
||
set(vec: Vector3, value: T): void { | ||
const [x, y, z] = vec; | ||
if (this.map[x] == null) { | ||
this.map[x] = new Map(); | ||
} | ||
if (this.map[x][y] == null) { | ||
this.map[x][y] = new Map(); | ||
} | ||
this.map[x][y][z] = value; | ||
} | ||
} | ||
const isosurfacesMap: Map<number, ThreeDMap<boolean>> = new Map(); | ||
const cubeSize = [256, 256, 256]; | ||
|
||
function* ensureSuitableIsosurface(): Saga<void> { | ||
const renderIsosurfaces = yield* select(state => state.datasetConfiguration.renderIsosurfaces); | ||
const isControlModeSupported = yield* select( | ||
state => state.temporaryConfiguration.controlMode === ControlModeEnum.VIEW, | ||
); | ||
if (!renderIsosurfaces || !isControlModeSupported) { | ||
return; | ||
} | ||
const dataset = yield* select(state => state.dataset); | ||
const layer = Model.getSegmentationLayer(); | ||
const position = yield* select(state => getFlooredPosition(state.flycam)); | ||
const zoomStep = 1; | ||
const segmentId = layer.cube.getMappedDataValue(position, zoomStep); | ||
|
||
if (segmentId === 0 || segmentId == null) { | ||
return; | ||
} | ||
|
||
if (isosurfacesMap.get(segmentId) == null) { | ||
isosurfacesMap.set(segmentId, new ThreeDMap()); | ||
} | ||
const threeDMap = isosurfacesMap.get(segmentId); | ||
|
||
const zoomedCubeSize = map3(el => el * 2 ** zoomStep, cubeSize); | ||
const currentCube = map3((el, idx) => Math.floor(el / zoomedCubeSize[idx]), position); | ||
const cubedPostion = map3((el, idx) => el * zoomedCubeSize[idx], currentCube); | ||
if (threeDMap.get(currentCube)) { | ||
return; | ||
} | ||
|
||
threeDMap.set(currentCube, true); | ||
loadIsosurface(dataset, layer, segmentId, cubedPostion, zoomStep); | ||
} | ||
|
||
async function loadIsosurface( | ||
dataset: APIDataset, | ||
layer: DataLayer, | ||
segmentId: number, | ||
position: Vector3, | ||
zoomStep: number, | ||
) { | ||
const voxelDimensions = [2, 2, 2]; | ||
|
||
const responseBuffer = await computeIsosurface( | ||
dataset, | ||
layer, | ||
position, | ||
zoomStep, | ||
segmentId, | ||
voxelDimensions, | ||
cubeSize, | ||
); | ||
const vertices = new Float32Array(responseBuffer); | ||
getSceneController().addIsosurface(vertices, segmentId); | ||
} | ||
|
||
export default function* isosurfaceSaga(): Saga<void> { | ||
yield* take("WK_READY"); | ||
yield _takeEvery(FlycamActions, ensureSuitableIsosurface); | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.