Search in sources :

Example 6 with DoubleArray

use of net.imglib2.img.basictypeaccess.array.DoubleArray 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();
    }
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) URL(java.net.URL) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) DoubleType(net.imglib2.type.numeric.real.DoubleType) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)6 DoubleArray (net.imglib2.img.basictypeaccess.array.DoubleArray)5 BasicStackDimensions (org.vcell.imagej.helper.VCellHelper.BasicStackDimensions)5 IJDataList (org.vcell.imagej.helper.VCellHelper.IJDataList)4 ImgPlus (net.imagej.ImgPlus)2 DefaultLinearAxis (net.imagej.axis.DefaultLinearAxis)2 DefaultDatasetView (net.imagej.display.DefaultDatasetView)2 DefaultImageDisplay (net.imagej.display.DefaultImageDisplay)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)1 VCellHelper (org.vcell.imagej.helper.VCellHelper)1 VCellModelSearchResults (org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1