Commit af2ab9cc authored by Julien Finet's avatar Julien Finet Committed by Kitware Robot

Merge topic 'finetjul/vtk-fix-vtkweb-support'

f8b0948f Fix typos in web protocols
c353ed5c Fix viewport.image.push endpoint
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Sebastien Jourdain's avatarSebastien Jourdain <sebastien.jourdain@kitware.com>
Merge-request: !4867
parents f5cb5c3f f8b0948f
......@@ -178,7 +178,6 @@ vtkUnsignedCharArray* vtkWebApplication::StillRender(vtkRenderWindow* view, int
value.Data != nullptr /* FIXME SEB &&
view->HasDirtyRepresentation() == false */)
{
//cout << "Reusing cache" << endl;
bool latest = this->Internals->Encoder->GetLatestOutput(this->Internals->ObjectIdMap->GetGlobalId(view), value.Data);
value.HasImagesBeingProcessed = !latest;
return value.Data;
......@@ -210,7 +209,9 @@ vtkUnsignedCharArray* vtkWebApplication::StillRender(vtkRenderWindow* view, int
//vtkTimerLog::MarkEndEvent("StillRenderToString");
//vtkTimerLog::DumpLogWithIndents(&cout, 0.0);
this->Internals->Encoder->PushAndTakeReference(this->Internals->ObjectIdMap->GetGlobalId(view), image, quality);
this->Internals->Encoder->PushAndTakeReference(
this->Internals->ObjectIdMap->GetGlobalId(view), image, quality,
this->ImageEncoding);
assert(image == nullptr);
if (value.Data == nullptr)
......@@ -228,7 +229,8 @@ vtkUnsignedCharArray* vtkWebApplication::StillRender(vtkRenderWindow* view, int
}
//----------------------------------------------------------------------------
const char* vtkWebApplication::StillRenderToString(vtkRenderWindow* view, vtkMTimeType time, int quality)
const char* vtkWebApplication::StillRenderToString(
vtkRenderWindow* view, vtkMTimeType time, int quality)
{
vtkUnsignedCharArray* array = this->StillRender(view, quality);
if (array && array->GetMTime() != time)
......@@ -240,6 +242,19 @@ const char* vtkWebApplication::StillRenderToString(vtkRenderWindow* view, vtkMTi
return nullptr;
}
//----------------------------------------------------------------------------
vtkUnsignedCharArray* vtkWebApplication::StillRenderToBuffer(
vtkRenderWindow* view, vtkMTimeType time, int quality)
{
vtkUnsignedCharArray* array = this->StillRender(view, quality);
if (array && array->GetMTime() != time)
{
this->LastStillRenderToMTime = array->GetMTime();
return array;
}
return NULL;
}
//----------------------------------------------------------------------------
bool vtkWebApplication::HandleInteractionEvent(
vtkRenderWindow* view, vtkWebInteractionEvent* event)
......
......@@ -83,6 +83,8 @@ public:
vtkUnsignedCharArray* StillRender(vtkRenderWindow* view, int quality = 100);
vtkUnsignedCharArray* InteractiveRender(vtkRenderWindow* view, int quality = 50);
const char* StillRenderToString(vtkRenderWindow* view, vtkMTimeType time = 0, int quality = 100);
vtkUnsignedCharArray* StillRenderToBuffer(
vtkRenderWindow* view, vtkMTimeType time = 0, int quality = 100);
//@}
/**
......
......@@ -143,7 +143,7 @@ class vtkWebViewPort(vtkWebProtocol):
RPC callback to reset camera.
"""
view = self.getView(viewId)
camera = view.GetRenderer().GetActiveCamera()
camera = view.GetRenderers().GetFirstRenderer().GetActiveCamera()
camera.ResetCamera()
try:
# FIXME seb: view.CenterOfRotation = camera.GetFocalPoint()
......@@ -186,10 +186,10 @@ class vtkWebViewPort(vtkWebProtocol):
def updateCamera(self, view_id, focal_point, view_up, position):
view = self.getView(view_id)
camera = view.GetRenderer().GetActiveCamera()
camera = view.GetRenderers().GetFirstRenderer().GetActiveCamera()
camera.SetFocalPoint(focal_point)
camera.SetCameraViewUp(view_up)
camera.SetCameraPosition(position)
camera.SetViewUp(view_up)
camera.SetPosition(position)
self.getApplication().InvalidateCache(view)
self.getApplication().InvokeEvent('UpdateEvent')
......@@ -342,6 +342,8 @@ class vtkWebPublishImageDelivery(vtkWebProtocol):
self.targetFrameRate = self.maxFrameRate
if nextAnimateTime < 0:
if nextAnimateTime < -1.0:
self.targetFrameRate = 1
if self.targetFrameRate > self.minFrameRate:
self.targetFrameRate -= 1.0
reactor.callLater(0.001, lambda: self.animate())
......@@ -366,10 +368,9 @@ class vtkWebPublishImageDelivery(vtkWebProtocol):
sView = self.getView(viewId)
realViewId = str(self.getGlobalId(sView))
if realViewId not in self.viewsInAnimations:
self.viewsInAnimations.append(realViewId)
if len(self.viewsInAnimations) == 1:
self.animate()
self.viewsInAnimations.append(realViewId)
if len(self.viewsInAnimations) == 1:
self.animate()
@exportRpc("viewport.image.animation.stop")
......@@ -382,6 +383,15 @@ class vtkWebPublishImageDelivery(vtkWebProtocol):
@exportRpc("viewport.image.push")
def imagePush(self, options):
sView = self.getView(options["view"])
realViewId = str(self.getGlobalId(sView))
# Make sure an image is pushed
self.getApplication().InvalidateCache(sView)
self.pushRender(realViewId)
# Internal function since the reply[image] is not
# JSON(serializable) it can not be an RPC one
def stillRender(self, options):
"""
RPC Callback to render a view and obtain the rendered image.
......@@ -466,7 +476,7 @@ class vtkWebPublishImageDelivery(vtkWebProtocol):
# There is an observer on this view already
self.trackingViews[realViewId]['observerCount'] += 1
self.publish('viewport.image.push.subscription', self.pushRender(realViewId))
self.pushRender(realViewId)
return { 'success': True, 'viewId': realViewId }
......@@ -515,7 +525,7 @@ class vtkWebPublishImageDelivery(vtkWebProtocol):
# Update image size right now!
if "originalSize" in self.trackingViews[realViewId]:
size = [int(s * ratio) for s in self.trackingViews[realViewId]["originalSize"]]
if 'SetSize' in sView:
if hasattr(sView, 'SetSize'):
sView.SetSize(size)
else:
sView.ViewSize = size
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment