Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: refs #990. Enable point selection in slice view
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen committed Apr 29, 2013
1 parent 21245a6 commit 851a733
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 30 deletions.
23 changes: 22 additions & 1 deletion modules/pvw/apps/midas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MidasApp(paraviewweb_wamp.ServerProtocol):
subgrid = None
sliceMode = None
meshSlice = None
sphere = None
surfaces = []

def initialize(self):
Expand Down Expand Up @@ -174,6 +175,24 @@ def loadData(self):
simple.Render()
return self.srcObj

@exportRpc("showSphere")
def showSphere(self, params):
if self.sphere is not None:
simple.Delete(self.sphere)

maxDim = max(self.bounds[1] - self.bounds[0],
self.bounds[3] - self.bounds[2],
self.bounds[5] - self.bounds[4])

self.sphere = simple.Sphere()
self.sphere.Radius = maxDim / 100.0
self.sphere.Center = params['point']
rep = simple.Show()
rep.Representation = 'Surface'
rep.DiffuseColor = params['color']

simple.SetActiveSource(self.srcObj)

@exportRpc("cameraPreset")
def cameraPreset(self, direction):
global view
Expand Down Expand Up @@ -249,7 +268,8 @@ def setSliceMode(self, sliceMode):
self._sliceSurfaces(sliceNum)
simple.Render()
return {'slice': sliceNum,
'maxSlices': maxSlices}
'maxSlices': maxSlices,
'cameraParallelScale': cameraParallelScale}


@exportRpc("changeSlice")
Expand Down Expand Up @@ -339,6 +359,7 @@ def sliceRender(self, sliceMode):
return {'scalarRange': self.scalarRange,
'bounds': self.bounds,
'extent': self.extent,
'center': self.center,
'sliceInfo': sliceInfo}


Expand Down
13 changes: 13 additions & 0 deletions modules/pvw/controllers/ParaviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ public function volumeAction()
* @param jsImports (Optional) List of javascript files to import. These should contain handler
* functions for imported operations. Separated by ;
* @param meshes (Optional) List of item id's corresponding to surface meshes to visualize in the scene
* @param operations (Optional) List of operations separated by ; to allow
*/
public function sliceAction()
{
$jsImports = $this->_getParam('jsImports');
$operations = $this->_getParam('operations');
if(isset($jsImports))
{
$this->view->jsImports = explode(';', $jsImports);
Expand All @@ -226,6 +228,16 @@ public function sliceAction()
{
$this->view->jsImports = array();
}
if(isset($operations))
{
$operations = explode(';', $operations);
}
else
{
$operations = array();
}


$itemId = $this->_getParam('itemId');
if(!isset($itemId))
{
Expand Down Expand Up @@ -257,6 +269,7 @@ public function sliceAction()
$this->view->json['pvw']['item'] = $item;
$this->view->json['pvw']['meshIds'] = $meshes;
$this->view->json['pvw']['viewMode'] = 'slice';
$this->view->json['pvw']['operations'] = $operations;
$this->view->item = $item;
}

Expand Down
67 changes: 38 additions & 29 deletions modules/pvw/public/js/paraview/paraview.slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ midas.pvw.sliceRenderStarted = function (resp) {
midas.pvw.extent = resp.extent;
midas.pvw.slice = resp.sliceInfo.slice;
midas.pvw.maxSlices = resp.sliceInfo.maxSlices;
midas.pvw.cameraParallelScale = resp.sliceInfo.cameraParallelScale;
midas.pvw.scalarRange = resp.scalarRange;
midas.pvw.center = resp.center;

pv.viewport.render();

Expand All @@ -62,6 +64,7 @@ midas.pvw.sliceRenderStarted = function (resp) {
midas.pvw.updateSliceInfo(midas.pvw.slice);
midas.pvw.populateInfo();
midas.pvw.updateWindowInfo([midas.pvw.scalarRange[0], midas.pvw.scalarRange[1]]);
midas.pvw.enableActions(json.pvw.operations);

$('a.switchToVolumeView').attr('href', json.global.webroot + '/pvw/paraview/volume' + window.location.search);
}
Expand All @@ -75,10 +78,7 @@ midas.pvw.setupSliders = function () {
max: midas.pvw.maxSlices,
value: midas.pvw.slice,
slide: function(event, ui) {
if(midas.pvw.acquireUpdateLock()) {
// TODO degrade quality for intermediate updates
midas.pvw.changeSlice(ui.value);
}
midas.pvw.changeSlice(ui.value, true);
midas.pvw.updateSliceInfo(ui.value);
},
change: function(event, ui) {
Expand Down Expand Up @@ -132,16 +132,28 @@ midas.pvw.changeWindow = function (values) {
};

/** Change the slice and run appropriate slice filter on any meshes in the scene */
midas.pvw.changeSlice = function (slice) {
midas.pvw.changeSlice = function (slice, degradeQuality) {
slice = parseInt(slice);
midas.pvw.currentSlice = slice;

pv.connection.session.call('pv:changeSlice', slice)
.then(function (resp) {
pv.viewport.render();
midas.pvw.releaseUpdateLock();
})
.otherwise(midas.pvw.rpcFailure)
if(midas.pvw.acquireUpdateLock()) {
pv.connection.session.call('pv:changeSlice', slice)
.then(function (resp) {
if(degradeQuality) {
pv.viewport.render(null, {quality: 50});
}
else {
pv.viewport.render();
}
midas.pvw.releaseUpdateLock();
})
.otherwise(midas.pvw.rpcFailure)
}
else if(!degradeQuality) {
// If this is a non-interactive fetch, we should poll the lock until it unlocks and then
// fetch a full-res frame. This will happens after sliding stops.
window.setTimeout(midas.pvw.changeSlice, 20, slice);
}
};

/**
Expand All @@ -158,11 +170,11 @@ midas.pvw.pointSelectMode = function () {
midas.createNotice('Click on the image to select a point', 3500);

// Bind click action on the render window
var el = $(midas.pvw.renderers.current.view);
var el = $('#renderercontainer .mouse-listener');
el.unbind('click').click(function (e) {
var x, y, z;
var pscale = midas.pvw.cameraParallelScale;
var focus = midas.pvw.cameraFocalPoint;
var focus = midas.pvw.center;

if(midas.pvw.sliceMode == 'XY Plane') {
var top = focus[1] - pscale;
Expand All @@ -171,29 +183,32 @@ midas.pvw.pointSelectMode = function () {
var right = focus[0] + pscale;
x = (e.offsetX / $(this).width()) * (right - left) + left;
y = (e.offsetY / $(this).height()) * (bottom - top) + top;
z = midas.pvw.currentSlice + midas.pvw.bounds[4] - midas.pvw.extent[4];
var a = (midas.pvw.slice + midas.pvw.extent[4]) / (midas.pvw.extent[5] - midas.pvw.extent[4]);
z = a * (midas.pvw.bounds[5] - midas.pvw.bounds[4]) + midas.pvw.bounds[4];
}
else if(midas.pvw.sliceMode == 'XZ Plane') {
var top = focus[2] + pscale;
var bottom = focus[2] - pscale;
var left = focus[0] + pscale;
var right = focus[0] - pscale;
x = (e.offsetX / $(this).width()) * (right - left) + left;
y = midas.pvw.currentSlice + midas.pvw.bounds[2] - midas.pvw.extent[2];
var a = (midas.pvw.slice + midas.pvw.extent[2]) / (midas.pvw.extent[3] - midas.pvw.extent[2]);
y = a * (midas.pvw.bounds[3] - midas.pvw.bounds[2]) + midas.pvw.bounds[2];
z = (e.offsetY / $(this).height()) * (bottom - top) + top;
}
else if(midas.pvw.sliceMode == 'YZ Plane') {
var top = focus[2] + pscale;
var bottom = focus[2] - pscale;
var left = focus[0] - pscale;
var right = focus[0] + pscale;
x = midas.pvw.currentSlice + midas.pvw.bounds[0] - midas.pvw.extent[0];
var a = (midas.pvw.slice + midas.pvw.extent[0]) / (midas.pvw.extent[1] - midas.pvw.extent[0]);
x = a * (midas.pvw.bounds[1] - midas.pvw.bounds[0]) + midas.pvw.bounds[2];
y = (e.offsetX / $(this).width()) * (right - left) + left;
z = (e.offsetY / $(this).height()) * (bottom - top) + top;
}

var html = 'You have selected the point:<p><b>('
+x.toFixed(1)+', '+y.toFixed(1)+', '+z.toFixed(1)+')</b></p>'
+x.toFixed(2)+', '+y.toFixed(2)+', '+z.toFixed(2)+')</b></p>'
+'Click OK to proceed or Cancel to re-select a point';
html += '<br/><br/><div style="float: right;"><button id="pointSelectOk">OK</button>';
html += '<button style="margin-left: 15px" id="pointSelectCancel">Cancel</button></div>';
Expand All @@ -213,15 +228,11 @@ midas.pvw.pointSelectMode = function () {

var params = {
point: [x, y, z],
color: [1.0, 0.0, 0.0],
radius: midas.pvw.maxDim / 100.0, //make the sphere some small fraction of the image size
objectToDelete: midas.pvw.glyph ? midas.pvw.glyph : false,
input: midas.pvw.input
color: [1.0, 0.0, 0.0]
};
paraview.callPluginMethod('midasslice', 'ShowSphere', params, function (view, retVal) {
midas.pvw.glyph = retVal.glyph;
midas.pvw.forceRefreshView();
});
pv.connection.session.call('pv:showSphere', params)
.then(pv.viewport.render)
.otherwise(midas.pvw.rpcFailure);
});
};

Expand Down Expand Up @@ -304,16 +315,14 @@ midas.pvw.sliceModeChanged = function (resp) {
pv.viewport.render();
midas.pvw.slice = resp.slice;
midas.pvw.maxSlices = resp.maxSlices;
midas.pvw.cameraParallelScale = resp.cameraParallelScale;
midas.pvw.updateSliceInfo(resp.slice);
$('#sliceSlider').slider('destroy').slider({
min: 0,
max: midas.pvw.maxSlices,
value: resp.slice,
slide: function(event, ui) {
if(midas.pvw.acquireUpdateLock()) {
// TODO degrade quality for intermediate updates
midas.pvw.changeSlice(ui.value);
}
midas.pvw.changeSlice(ui.value, true);
midas.pvw.updateSliceInfo(ui.value);
},
change: function(event, ui) {
Expand Down

0 comments on commit 851a733

Please sign in to comment.