use of org.vcell.imagej.helper.VCellHelper.BasicStackDimensions in project vcell by virtualcell.
the class VCellPlugin_Minimal method run.
// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
// public void showAndZoom(String displayName,Object thingToDisplay,double zoomFactor) throws Exception{
// final ImageDisplayService ids = getContext().getService(ImageDisplayService.class);
// final DisplayService ds = getContext().getService(DisplayService.class);
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// // TODO Auto-generated method stub
// uiService.show(displayName,thingToDisplay);
// //Find display and set zoom, resize window
// List<ImageDisplay> knownImageDisplays = ids.getImageDisplays();
// boolean bvisible = false;
// while (!bvisible) {
// for (ImageDisplay imageDisplay : knownImageDisplays) {
// if (imageDisplay.getName().equals(displayName)) {
// if (imageDisplay.isVisible(imageDisplay.getActiveView())) {
// bvisible = true;
// break;
// }
// }
// }
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// // int vw = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportWidth();
// // int vh = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportHeight();
// // System.out.println(" -----byname="+ij.display().getDisplay(displayName));
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// try {
// ids.getActiveImageDisplay().getCanvas().setZoom(zoomFactor);
// if(ds.getDisplay(displayName) != null && uiService.getDisplayViewer(ds.getDisplay(displayName)) instanceof JFrame) {
// double vw = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.X))*zoomFactor;
// double vh = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.Y))*zoomFactor;
// ((JFrame)uiService.getDisplayViewer(ds.getDisplay(displayName)).getWindow()).setSize(new Dimension((int)vw+50, (int)vh+150));
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
//
// // ij.ui().getDisplayViewer(ij.display().getDisplay(displayName)).getPanel().redoLayout();
// // List<Display<?>> displays = ij.display().getDisplays();
// // for (Display<?> display : displays) {
// // System.out.println(display+" -----byname="+ij.display().getDisplay(displayName));
// // }
//
// }
// }).start();
//
// }
@Override
public void run() {
try {
if (vcellSelection != null && vcellSelection.exception != null) {
if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
}
return;
}
if (vcellSelection == null || vcellSelection.theCacheKey == null) {
return;
}
// Create ImageJ datasets and display separate hyperstack for each variable
for (int varIndex = 0; varIndex < vcellSelection.varName.length; varIndex++) {
int[] time = vcellSelection.timePointIndexes;
displayProgressBar(true, "loading Image...", "VCell Model Loader", (varIndex + 1) * 100 / vcellSelection.varName.length, uiService);
final IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, vcellSelection.varName[varIndex], VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
double[] data = new double[bsd.getTotalSize() * tpd.ijData.length];
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize, tpd.ijData.length);
for (int i = 0; i < tpd.ijData.length; i++) {
System.arraycopy(tpd.ijData[i].getDoubleData(), 0, data, i * bsd.getTotalSize(), bsd.getTotalSize());
// calc minmax only for pixel values that are in domain of this variable
for (int j = 0; j < tpd.ijData[i].getDoubleData().length; j++) {
if (tpd.ijData[i].getDoubleData()[j] != tpd.ijData[i].notInDomainValue) {
min = Math.min(min, tpd.ijData[i].getDoubleData()[j]);
max = Math.max(max, tpd.ijData[i].getDoubleData()[j]);
}
}
}
ImgPlus<DoubleType> imgPlus = new ImgPlus<DoubleType>(testimg);
imgPlus.setChannelMinimum(0, min);
imgPlus.setChannelMaximum(0, max);
imgPlus.setAxis(new DefaultLinearAxis(Axes.Z), 2);
imgPlus.setAxis(new DefaultLinearAxis(Axes.TIME), 3);
uiService.show(vcellSelection.varName[varIndex], imgPlus);
DefaultImageDisplay createDisplayQuietly = (DefaultImageDisplay) displayService.getDisplay(vcellSelection.varName[varIndex]);
while (displayService.getActiveDisplay() == null) {
Thread.sleep(100);
}
WindowManager.getActiveWindow().setSize(400, 400);
IJ.run("Scale to Fit", "");
// refresh the sliders
WindowManager.getActiveWindow().setSize(400, 400);
// final ZoomService zoomService = getContext().getService(ZoomService.class);
// zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
// eventService.publish(new PanZoomEvent(createDisplayQuietly.getCanvas()));
// IJ.run("Set... ", "zoom=300 x="+(bsd.xsize/2)+" y="+(bsd.ysize/2));
// IJ.run("Set... ", "zoom=300");
// IJ.run("In");
// IJ.run("In");
// IJ.run("In");
// RunService runService = getContext().getService(RunService.class);
// runService.run("In", (Map)null);
// final Iterator<PluginInfo<Op>> iterator = opService.getPlugins().iterator();
// while(iterator.hasNext()) {
// System.out.println(iterator.next());
// }
// opService.run("In", "");
// final ZoomService zoomService = getContext().getService(ZoomService.class);
// zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
// createDisplayQuietly.update();
// final Display<?> createDisplayQuietly = getContext().getService(DisplayService.class).createDisplayQuietly(testimg);
final DefaultDatasetView defaultDatasetView = (DefaultDatasetView) ((DefaultImageDisplay) createDisplayQuietly).getActiveView();
// defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(2), 2);
// defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(3), 3);
// defaultDatasetView.update();
System.out.println(min + " " + max);
// displayService.setActiveDisplay(createDisplayQuietly);
// IJ.setMinAndMax(min, max);
// defaultDatasetView.getData().setChannelMinimum(0, min);
// defaultDatasetView.getData().setChannelMaximum(0, max);
// defaultDatasetView.setChannelRanges(min,max);
// IJ.getImage().updateAndDraw();
// while(displayService.getActiveDisplay() == null) {
// Thread.sleep(100);
// }
// IJ.setMinAndMax(min, max);
// WindowManager.getCurrentImage().setDisplayRange(min, max)
// WindowManager.getCurrentImage().setDisplayRange(min,max);
// ImageStack.create(varIndex, varIndex, varIndex, varIndex)
// ImagePlus ip = new ImagePlus();
// uiService.showUI();
// EventService es = null;
// getContext().getService(EventService.class).publish(new DisplayUpdatedEvent(createDisplayQuietly,DisplayUpdatedEvent.DisplayUpdateLevel.UPDATE));
// uiService.get
// uiService.show(createDisplayQuietly);
// getContext().getService(DisplayService.class).
// showAndZoom(vcellSelection.varName[varIndex],createDisplayQuietly, 3);
}
} catch (Exception e) {
displayProgressBar(false, "Error", "VCell Model Loader", 100, uiService);
uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
} finally {
displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
}
}
use of org.vcell.imagej.helper.VCellHelper.BasicStackDimensions in project vcell by virtualcell.
the class VCellPlugin method run.
// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
// public void showAndZoom(String displayName,Object thingToDisplay,double zoomFactor) throws Exception{
// final ImageDisplayService ids = getContext().getService(ImageDisplayService.class);
// final DisplayService ds = getContext().getService(DisplayService.class);
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// // TODO Auto-generated method stub
// uiService.show(displayName,thingToDisplay);
// //Find display and set zoom, resize window
// List<ImageDisplay> knownImageDisplays = ids.getImageDisplays();
// boolean bvisible = false;
// while (!bvisible) {
// for (ImageDisplay imageDisplay : knownImageDisplays) {
// if (imageDisplay.getName().equals(displayName)) {
// if (imageDisplay.isVisible(imageDisplay.getActiveView())) {
// bvisible = true;
// break;
// }
// }
// }
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// // int vw = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportWidth();
// // int vh = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportHeight();
// // System.out.println(" -----byname="+ij.display().getDisplay(displayName));
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// try {
// ids.getActiveImageDisplay().getCanvas().setZoom(zoomFactor);
// if(ds.getDisplay(displayName) != null && uiService.getDisplayViewer(ds.getDisplay(displayName)) instanceof JFrame) {
// double vw = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.X))*zoomFactor;
// double vh = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.Y))*zoomFactor;
// ((JFrame)uiService.getDisplayViewer(ds.getDisplay(displayName)).getWindow()).setSize(new Dimension((int)vw+50, (int)vh+150));
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
//
// // ij.ui().getDisplayViewer(ij.display().getDisplay(displayName)).getPanel().redoLayout();
// // List<Display<?>> displays = ij.display().getDisplays();
// // for (Display<?> display : displays) {
// // System.out.println(display+" -----byname="+ij.display().getDisplay(displayName));
// // }
//
// }
// }).start();
//
// }
@Override
public void run() {
try {
if (vcellSelection != null && vcellSelection.exception != null) {
if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
}
return;
}
if (vcellSelection == null || vcellSelection.theCacheKey == null) {
return;
}
// Create ImageJ datasets and display separate hyperstack for each variable
for (int varIndex = 0; varIndex < vcellSelection.varName.length; varIndex++) {
int[] time = vcellSelection.timePointIndexes;
displayProgressBar(true, "loading Image...", "VCell Model Loader", (varIndex + 1) * 100 / vcellSelection.varName.length, uiService);
final IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, vcellSelection.varName[varIndex], VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
double[] data = new double[bsd.getTotalSize() * tpd.ijData.length];
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize, tpd.ijData.length);
for (int i = 0; i < tpd.ijData.length; i++) {
System.arraycopy(tpd.ijData[i].getDoubleData(), 0, data, i * bsd.getTotalSize(), bsd.getTotalSize());
// calc minmax only for pixel values that are in domain of this variable
for (int j = 0; j < tpd.ijData[i].getDoubleData().length; j++) {
if (tpd.ijData[i].getDoubleData()[j] != tpd.ijData[i].notInDomainValue) {
min = Math.min(min, tpd.ijData[i].getDoubleData()[j]);
max = Math.max(max, tpd.ijData[i].getDoubleData()[j]);
}
}
}
ImgPlus<DoubleType> imgPlus = new ImgPlus<DoubleType>(testimg);
imgPlus.setChannelMinimum(0, min);
imgPlus.setChannelMaximum(0, max);
imgPlus.setAxis(new DefaultLinearAxis(Axes.Z), 2);
imgPlus.setAxis(new DefaultLinearAxis(Axes.TIME), 3);
uiService.show(vcellSelection.varName[varIndex], imgPlus);
DefaultImageDisplay createDisplayQuietly = (DefaultImageDisplay) displayService.getDisplay(vcellSelection.varName[varIndex]);
while (displayService.getActiveDisplay() == null) {
Thread.sleep(100);
}
WindowManager.getActiveWindow().setSize(400, 400);
IJ.run("Scale to Fit", "");
// refresh the sliders
WindowManager.getActiveWindow().setSize(400, 400);
// final ZoomService zoomService = getContext().getService(ZoomService.class);
// zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
// eventService.publish(new PanZoomEvent(createDisplayQuietly.getCanvas()));
// IJ.run("Set... ", "zoom=300 x="+(bsd.xsize/2)+" y="+(bsd.ysize/2));
// IJ.run("Set... ", "zoom=300");
// IJ.run("In");
// IJ.run("In");
// IJ.run("In");
// RunService runService = getContext().getService(RunService.class);
// runService.run("In", (Map)null);
// final Iterator<PluginInfo<Op>> iterator = opService.getPlugins().iterator();
// while(iterator.hasNext()) {
// System.out.println(iterator.next());
// }
// opService.run("In", "");
// final ZoomService zoomService = getContext().getService(ZoomService.class);
// zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
// createDisplayQuietly.update();
// final Display<?> createDisplayQuietly = getContext().getService(DisplayService.class).createDisplayQuietly(testimg);
final DefaultDatasetView defaultDatasetView = (DefaultDatasetView) ((DefaultImageDisplay) createDisplayQuietly).getActiveView();
// defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(2), 2);
// defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(3), 3);
// defaultDatasetView.update();
System.out.println(min + " " + max);
// displayService.setActiveDisplay(createDisplayQuietly);
// IJ.setMinAndMax(min, max);
// defaultDatasetView.getData().setChannelMinimum(0, min);
// defaultDatasetView.getData().setChannelMaximum(0, max);
// defaultDatasetView.setChannelRanges(min,max);
// IJ.getImage().updateAndDraw();
// while(displayService.getActiveDisplay() == null) {
// Thread.sleep(100);
// }
// IJ.setMinAndMax(min, max);
// WindowManager.getCurrentImage().setDisplayRange(min, max)
// WindowManager.getCurrentImage().setDisplayRange(min,max);
// ImageStack.create(varIndex, varIndex, varIndex, varIndex)
// ImagePlus ip = new ImagePlus();
// uiService.showUI();
// EventService es = null;
// getContext().getService(EventService.class).publish(new DisplayUpdatedEvent(createDisplayQuietly,DisplayUpdatedEvent.DisplayUpdateLevel.UPDATE));
// uiService.get
// uiService.show(createDisplayQuietly);
// getContext().getService(DisplayService.class).
// showAndZoom(vcellSelection.varName[varIndex],createDisplayQuietly, 3);
}
} catch (Exception e) {
displayProgressBar(false, "Error", "VCell Model Loader", 100, uiService);
uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
} finally {
displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
}
}
use of org.vcell.imagej.helper.VCellHelper.BasicStackDimensions in project vcell by virtualcell.
the class ModelLoad method run.
@Override
public void run() {
displayProgressBar(true, "Checking listening ports...", "Checking for VCell Client");
startJProgressThread0(null, "Check");
try {
// Find the port that a separately running VCell client is listening on
//
System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
// uiService.getDisplayViewer(textDisplay).dispose();
displayProgressBar(false, null, null);
} catch (Exception e) {
// e.printStackTrace();
displayProgressBar(false, null, null);
// uiService.getDisplayViewer(textDisplay).dispose();
uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
return;
}
displayProgressBar(true, "Searching...", "Searching VCell Models");
startJProgressThread0("Check", "Search");
String theCacheKey = null;
VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm, vCellUser, vCellModel, application, simulation, null, null);
try {
ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
if (vcmsr.size() == 0) {
throw new Exception("No Results for search found");
}
theCacheKey = vcmsr.get(0).getCacheKey();
System.out.println("theCacheKey=" + theCacheKey);
displayProgressBar(false, null, null);
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
uiService.showDialog("VCellHelper.ModelType.bm,vCellUser,vCellModel,application,simulation,null,null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
displayProgressBar(false, null, null);
}
displayProgressBar(true, "Loading Data...", "Loading Data");
startJProgressThread0("Search", "getTimePointData");
try {
String var = variable;
int[] time = new int[] { timePoint };
IJDataList tpd = vcellHelper.getTimePointData(theCacheKey, var, VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
double[] data = tpd.ijData[0].getDoubleData();
BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
System.out.println(bsd.xsize + " " + bsd.ysize);
ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize);
uiService.show(testimg);
displayProgressBar(false, null, null);
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
displayProgressBar(false, null, null);
}
startJProgressThread0("getTimePointData", null);
}
use of org.vcell.imagej.helper.VCellHelper.BasicStackDimensions in project vcell by virtualcell.
the class TestJettyService method exerciseService.
public static void exerciseService() {
try {
// HttpClient httpClient = new HttpClient();
// HostConfiguration hostConfiguration = new HostConfiguration();
// hostConfiguration.setHost("localhost",8080);
// HttpMethod method = new GetMethod("/list?type=biom");
// int var = httpClient.executeMethod(hostConfiguration, method);
// System.out.println("result="+var);
//
// method = new GetMethod("/");
// var = httpClient.executeMethod(hostConfiguration, method);
// System.out.println("result="+var);
// search for port that vcell is providing IJ related services on
int lastVCellApiPort = VCellHelper.findVCellApiServerPort();
// get rest api
System.out.println(VCellHelper.getApiInfo() + "\n");
URL[] testUrls = new URL[] { new URL("http://localhost:" + lastVCellApiPort + "/" + "getinfo" + "?" + "open=true" + "&" + "type" + "=" + "quick") // new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=true"+"&"+"type"+"="+"bm"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=true"+"&"+"type"+"="+"mm"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=false"+"&"+"type"+"="+"quick"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=false"+"&"+"type"+"="+"bm"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=false"+"&"+"type"+"="+"mm")
};
for (int i = 0; i < testUrls.length; i++) {
System.out.println("----------Test " + i + ": " + testUrls[i].toString());
// System.out.println(VCellHelper.getRawContent(testUrls[i]));
Document doc = VCellHelper.getDocument(testUrls[i]);
printDocument(doc, System.out);
Node simNode = doc.getElementsByTagName("simInfo").item(0);
String cachekey = simNode.getAttributes().getNamedItem("cacheKey").getNodeValue();
URL varInfoUrl = new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + "cachekey" + "=" + cachekey);
System.out.println(" --varInfo=" + varInfoUrl.toString());
System.out.println(VCellHelper.getRawContent(varInfoUrl));
doc = VCellHelper.getDocument(varInfoUrl);
ArrayList<Double> times = new ArrayList<>();
Node timeNode = doc.getElementsByTagName("times").item(0);
StringTokenizer st = new StringTokenizer(timeNode.getTextContent(), ",");
while (st.hasMoreTokens()) {
StringTokenizer timepointT = new StringTokenizer(st.nextToken(), "='");
timepointT.nextToken();
times.add(Double.parseDouble(timepointT.nextToken()));
}
String varName = null;
NodeList varNodes = doc.getElementsByTagName("ijVarInfo");
for (int j = 0; j < varNodes.getLength(); j++) {
if (varNodes.item(j).getAttributes().getNamedItem("variableType").getNodeValue().equals("Volume")) {
varName = varNodes.item(j).getAttributes().getNamedItem("name").getNodeValue();
break;
}
}
URL dataUrl = new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + "cachekey" + "=" + cachekey + "&" + "varname" + "=" + varName + "&" + "timepoint" + "=" + times.get(times.size() / 2) + "&" + "jobid=0");
System.out.println(" --data=" + dataUrl.toString());
doc = VCellHelper.getDocument(dataUrl);
BasicStackDimensions basicStackDimensions = VCellHelper.getVCStackDims(doc);
double[] data = VCellHelper.getData(doc);
System.out.println(basicStackDimensions.getTotalSize());
System.out.println(data.length);
}
if (true) {
return;
}
int cachekey = 4;
// get rest api
System.out.println(VCellHelper.getApiInfo());
// System.out.println(VCellHelper.getRawContent(new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=true"+"&"+"type"+"="+"bm")));//generate cachekeys user can reference to get data
// get variable names
System.out.println(VCellHelper.getRawContent(new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + /*+"open=true"+"&"*/
"cachekey" + "=" + cachekey)));
// get data
Document doc = VCellHelper.getDocument(new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + "cachekey" + "=" + cachekey + "&" + "varname" + "=" + "C_cyt" + "&" + "timepoint" + "=5.55394648006857" + "&" + "jobid=0"));
BasicStackDimensions basicStackDimensions = VCellHelper.getVCStackDims(doc);
double[] data = VCellHelper.getData(doc);
System.out.println(basicStackDimensions.getTotalSize());
System.out.println(data.length);
long[] dims = new long[basicStackDimensions.numDimensions()];
basicStackDimensions.dimensions(dims);
ArrayImg<DoubleType, DoubleArray> img = ArrayImgs.doubles(data, dims);
// ArrayImg<DoubleType, DoubleArray> img = (ArrayImg<DoubleType, DoubleArray>)new ArrayImgFactory< DoubleType >().create( basicStackDimensions, new DoubleType() );
// ArrayCursor<DoubleType> cursor = img.cursor();
// while(cursor.hasNext()) {
// cursor.next().set
// }
// Img< UnsignedByteType > img = new ArrayImgFactory< UnsignedByteType >().create( new long[] { 400, 320 }, new UnsignedByteType() );
ImageJFunctions.show(img);
DialogUtils.showInfoDialog(JOptionPane.getRootFrame(), "blah");
// JAXBContext jaxbContext = JAXBContext.newInstance(IJData.class);
// Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
// IJData ijData = (IJData) jaxbUnmarshaller.unmarshal(new URL("http://localhost:8080/"+ApiEnum.getdata.name()+"?"/*+"open=true"+"&"*/+IJGetDataParams.cachekey.name()+"=0"));
// System.out.println(ijData);
// URLConnection con = url.openConnection();
// InputStream in = con.getInputStream();
// String encoding = con.getContentEncoding();
// encoding = encoding == null ? "UTF-8" : encoding;
// String body = IOUtils.toString(in, encoding);
// System.out.println(body);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.vcell.imagej.helper.VCellHelper.BasicStackDimensions in project vcell by virtualcell.
the class ModelSearch method run.
// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
@Override
public void run() {
try {
if (vcellSelection != null && vcellSelection.exception != null) {
if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
}
return;
}
if (vcellSelection == null || vcellSelection.theCacheKey == null) {
return;
}
String var = vcellSelection.varName;
int[] time = new int[] { vcellSelection.timePointIndex };
displayProgressBar(true, "loading Image...", "VCell Model Loader", 50, uiService);
IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, var, VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
displayProgressBar(true, "displaying Image...", "VCell Model Loader", 100, uiService);
double[] data = tpd.ijData[0].getDoubleData();
BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
System.out.println(bsd.xsize + " " + bsd.ysize);
ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize);
uiService.show(testimg);
} catch (Exception e) {
displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
} finally {
displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
}
}
Aggregations