Skip to content

Commit

Permalink
feat(camera): ignore camera state during deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jspanchu committed Feb 27, 2024
1 parent 4b9ec9e commit 27c80e1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
5 changes: 3 additions & 2 deletions examples/vtk/cone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from trame.app import get_server
from trame.ui.html import DivLayout
from trame.widgets import vtklocal, html
from trame.widgets import html
from trame_vtklocal.widgets import vtklocal
from trame.decorators import TrameApp, change

from vtkmodules.vtkFiltersSources import vtkConeSource
Expand Down Expand Up @@ -41,7 +42,7 @@ def create_vtk_pipeline():
actor.SetMapper(mapper)

renderer.AddActor(actor)
renderer.SetBackground(1, 0, 0)
renderer.SetBackground(0.1, 0.2, 0.4)
renderer.ResetCamera()

return renderWindow, cone
Expand Down
18 changes: 11 additions & 7 deletions trame_vtklocal/module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,30 @@ def active_ids(self):

@export_rpc("vtklocal.get.state")
def get_state(self, obj_id):
print("get_state", obj_id)
print(f"get_state {obj_id}")
state = self.vtk_object_manager.GetState(obj_id)
# print(state)
return state

@export_rpc("vtklocal.get.hash")
def get_hash(self, hash):
# print("get_hash", hash)
print("get_hash", hash)
return self.addAttachment(memoryview(self.vtk_object_manager.GetBlob(hash)))

@export_rpc("vtklocal.get.status")
def get_status(self, obj_id):
print("get_status", obj_id)
ids = self.vtk_object_manager.GetAllDependencies(obj_id)
hashes = self.vtk_object_manager.GetBlobHashes(ids)
return dict(
ids=[map_id_mtime(self.vtk_object_manager, v) for v in ids],
hashes=hashes,
mtime=self.vtk_object_manager.GetLatestMTimeFromObjects(),
)
renderWindow = self.vtk_object_manager.GetObjectAtId(obj_id)
ids_mtime = [map_id_mtime(self.vtk_object_manager, v) for v in ids]
ignore_ids = []
if renderWindow:
renderers = renderWindow.GetRenderers()
for renderer in renderers:
activeCamera = renderer.GetActiveCamera()
ignore_ids.append(self.vtk_object_manager.GetId(activeCamera))
return dict(ids=ids_mtime, hashes=hashes, ignore_ids=ignore_ids)


# -----------------------------------------------------------------------------
Expand Down
36 changes: 18 additions & 18 deletions trame_vtklocal/module/serve/wasm/vtkObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,23 @@ var tempDouble;
var tempI64;

var ASM_CONSTS = {
1580188: () => {
1580220: () => {
if (typeof (AudioContext) !== "undefined") {
return true;
} else if (typeof (webkitAudioContext) !== "undefined") {
return true;
}
return false;
},
1580335: () => {
1580367: () => {
if ((typeof (navigator.mediaDevices) !== "undefined") && (typeof (navigator.mediaDevices.getUserMedia) !== "undefined")) {
return true;
} else if (typeof (navigator.webkitGetUserMedia) !== "undefined") {
return true;
}
return false;
},
1580569: $0 => {
1580601: $0 => {
if (typeof (Module["SDL2"]) === "undefined") {
Module["SDL2"] = {};
}
Expand All @@ -418,11 +418,11 @@ var ASM_CONSTS = {
}
return SDL2.audioContext === undefined ? -1 : 0;
},
1581062: () => {
1581094: () => {
var SDL2 = Module["SDL2"];
return SDL2.audioContext.sampleRate;
},
1581130: ($0, $1, $2, $3) => {
1581162: ($0, $1, $2, $3) => {
var SDL2 = Module["SDL2"];
var have_microphone = function(stream) {
if (SDL2.capture.silenceTimer !== undefined) {
Expand Down Expand Up @@ -463,7 +463,7 @@ var ASM_CONSTS = {
}, have_microphone, no_microphone);
}
},
1582782: ($0, $1, $2, $3) => {
1582814: ($0, $1, $2, $3) => {
var SDL2 = Module["SDL2"];
SDL2.audio.scriptProcessorNode = SDL2.audioContext["createScriptProcessor"]($1, 0, $0);
SDL2.audio.scriptProcessorNode["onaudioprocess"] = function(e) {
Expand All @@ -475,7 +475,7 @@ var ASM_CONSTS = {
};
SDL2.audio.scriptProcessorNode["connect"](SDL2.audioContext["destination"]);
},
1583192: ($0, $1) => {
1583224: ($0, $1) => {
var SDL2 = Module["SDL2"];
var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels;
for (var c = 0; c < numChannels; ++c) {
Expand All @@ -494,7 +494,7 @@ var ASM_CONSTS = {
}
}
},
1583797: ($0, $1) => {
1583829: ($0, $1) => {
var SDL2 = Module["SDL2"];
var numChannels = SDL2.audio.currentOutputBuffer["numberOfChannels"];
for (var c = 0; c < numChannels; ++c) {
Expand All @@ -507,7 +507,7 @@ var ASM_CONSTS = {
}
}
},
1584277: $0 => {
1584309: $0 => {
var SDL2 = Module["SDL2"];
if ($0) {
if (SDL2.capture.silenceTimer !== undefined) {
Expand Down Expand Up @@ -545,7 +545,7 @@ var ASM_CONSTS = {
SDL2.audioContext = undefined;
}
},
1585449: ($0, $1, $2) => {
1585481: ($0, $1, $2) => {
var w = $0;
var h = $1;
var pixels = $2;
Expand Down Expand Up @@ -616,7 +616,7 @@ var ASM_CONSTS = {
}
SDL2.ctx.putImageData(SDL2.image, 0, 0);
},
1586918: ($0, $1, $2, $3, $4) => {
1586950: ($0, $1, $2, $3, $4) => {
var w = $0;
var h = $1;
var hot_x = $2;
Expand Down Expand Up @@ -653,18 +653,18 @@ var ASM_CONSTS = {
stringToUTF8(url, urlBuf, url.length + 1);
return urlBuf;
},
1587907: $0 => {
1587939: $0 => {
if (Module["canvas"]) {
Module["canvas"].style["cursor"] = UTF8ToString($0);
}
},
1587990: () => {
1588022: () => {
if (Module["canvas"]) {
Module["canvas"].style["cursor"] = "none";
}
},
1588059: () => window.innerWidth,
1588089: () => window.innerHeight
1588091: () => window.innerWidth,
1588121: () => window.innerHeight
};

/** @constructor */ function ExitStatus(status) {
Expand Down Expand Up @@ -10375,7 +10375,7 @@ var wasmImports = {
/** @export */ $h: __embind_register_bool,
/** @export */ _h: __embind_register_emval,
/** @export */ rb: __embind_register_float,
/** @export */ x: __embind_register_function,
/** @export */ v: __embind_register_function,
/** @export */ u: __embind_register_integer,
/** @export */ g: __embind_register_memory_view,
/** @export */ qb: __embind_register_std_string,
Expand Down Expand Up @@ -10800,7 +10800,7 @@ var wasmImports = {
/** @export */ Ob: _glGenVertexArrays,
/** @export */ fa: _glGenerateMipmap,
/** @export */ ea: _glGetAttribLocation,
/** @export */ w: _glGetBooleanv,
/** @export */ x: _glGetBooleanv,
/** @export */ i: _glGetError,
/** @export */ da: _glGetFloatv,
/** @export */ r: _glGetFramebufferAttachmentParameteriv,
Expand Down Expand Up @@ -10847,7 +10847,7 @@ var wasmImports = {
/** @export */ Q: invoke_i,
/** @export */ c: invoke_ii,
/** @export */ e: invoke_iii,
/** @export */ v: invoke_iiii,
/** @export */ w: invoke_iiii,
/** @export */ za: invoke_iiiii,
/** @export */ A: invoke_v,
/** @export */ d: invoke_vi,
Expand Down
Binary file modified trame_vtklocal/module/serve/wasm/vtkObjectManager.wasm
Binary file not shown.
23 changes: 16 additions & 7 deletions vue-components/src/components/VtkLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ export default {
stateMTimes[vtkId] = JSON.parse(serverState).MTime;
console.log(`vtkLocal::state(${vtkId})`);
objectManager.registerState(serverState);
}
else {
} else {
throw new Error(`Server returned empty state for ${vtkId}`);
}
return serverState;
}
async function fetchHash(hash) {
const session = client.getConnection().getSession();
const blob = await session.call("vtklocal.get.hash", [hash]);
console.log(`vtkLocal::hash(${hash})`)
console.log(`vtkLocal::hash(${hash})`);
const array = new Uint8Array(await blob.arrayBuffer());
objectManager.registerBlob(hash, array);
hashesAvailable.add(hash);
Expand All @@ -71,19 +70,29 @@ export default {
console.log("ids", serverStatus.ids);
serverStatus.ids.forEach(([vtkId, mtime]) => {
if (!stateMTimes[vtkId] || stateMTimes[vtkId] < mtime) {
console.log("fetch", vtkId)
console.log("fetch", vtkId);
pendingRequests.push(fetchState(vtkId));
} else {
console.log("skip", vtkId)
console.log("skip", vtkId);
}
});
serverStatus.ignore_ids.forEach((vtkId) => {
objectManager.unRegisterState(vtkId);
});
serverStatus.hashes.forEach((hash) => {
if (!hashesAvailable.has(hash)) {
pendingRequests.push(fetchHash(hash));
}
});
await Promise.all(pendingRequests);
console.log("vtkLocal::update(end)");
// Shows memory, feel free to remove.
console.log(
`vtkLocal::update(end) blobs: ${
objectManager.getTotalBlobMemoryUsage() / 1024
}kB, objects: ${
objectManager.getTotalVTKDataObjectMemoryUsage() / 1024
}kB`
);
objectManager.update(startEventLoop);
resize();
emit("updated");
Expand All @@ -94,7 +103,7 @@ export default {
objectManager = await createModule(unref(canvas));
console.log("objectManager", objectManager);
resizeObserver.observe(unref(container));
update(/*startEventLoop=*/true);
update(/*startEventLoop=*/ true);
setTimeout(() => {
canvasWidth.value = 300;
canvasHeight.value = 300;
Expand Down

0 comments on commit 27c80e1

Please sign in to comment.