Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
geektortoise committed Nov 7, 2019
2 parents 380eea7 + c56d4da commit 991a336
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 61 deletions.
76 changes: 44 additions & 32 deletions src/main/java/be/cytomine/client/Cytomine.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,50 @@ public User getUser(String publicKey) throws CytomineException {
return user.fetch(null);
}

public String getImageServersOfAbstractImage(Long abstractImageID) {

String subUrl = "/api/abstractimage/"+abstractImageID+"/imageservers.json";

HttpClient client = null;
client = new HttpClient(publicKey, privateKey, getHost());


try {
client.authorize("GET", subUrl, "", "application/json,*/*");
client.connect(getHost() + subUrl);
int code = client.get();

String response = client.getResponseData();
client.disconnect();
JSONObject json = createJSONResponse(code, response);
analyzeCode(code, json);

JSONArray servers = (JSONArray) json.get("imageServersURLs");

return (String) servers.get(0);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CytomineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

public Collection<ImageServer> getAbstractImageServers(AbstractImage abstractImage) throws CytomineException {
Collection<ImageServer> imageServers = new Collection<>(ImageServer.class,0,0);
imageServers.addFilter("abstractimage", "" + abstractImage.getId());
return imageServers.fetch();
}
public Collection<ImageServer> getImageInstanceServers(ImageInstance image) throws CytomineException {
AbstractImage abstractImage = new AbstractImage();
abstractImage.set("id", image.get("baseImage"));
return getAbstractImageServers(abstractImage);
}

public User getKeys(String publicKey) throws CytomineException {
User user = new User();
user.addFilter("publicKeyFilter", publicKey);
Expand Down Expand Up @@ -763,38 +807,6 @@ public String getSimplified(String wkt, Long min, Long max) throws CytomineExcep
}


public String getImageServersOfAbstractImage(Long abstractImageID) {

String subUrl = "/api/abstractimage/"+abstractImageID+"/imageservers.json";

HttpClient client = null;
client = new HttpClient(publicKey, privateKey, getHost());


try {
client.authorize("GET", subUrl, "", "application/json,*/*");
client.connect(getHost() + subUrl);
int code = client.get();

String response = client.getResponseData();
client.disconnect();
JSONObject json = createJSONResponse(code, response);
analyzeCode(code, json);

JSONArray servers = (JSONArray) json.get("imageServersURLs");

return (String) servers.get(0);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CytomineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}



Expand Down
10 changes: 5 additions & 5 deletions src/main/java/be/cytomine/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void connect(String url, String username, String password) throws IOExcep
isAuthByPrivateKey = false;
log.info("Connection to " + url + " with login=" + username + " and pass=" + password);
URL = new URL(url);
targetHost = new HttpHost(URL.getHost(), URL.getPort());
targetHost = new HttpHost(URL.getHost(), URL.getPort(), URL.getProtocol());
client = HttpClientBuilder.create().build();
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
Expand Down Expand Up @@ -144,7 +144,7 @@ public int get() throws IOException {
public int get(String url, String dest) throws IOException {
log.debug("get:" + url);
URL URL = new URL(url);
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort());
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort(), URL.getProtocol());
log.debug("targetHost:" + targetHost);
DefaultHttpClient client = new DefaultHttpClient();
log.debug("client:" + client);
Expand Down Expand Up @@ -303,7 +303,7 @@ public int download(String dest) throws IOException {
public BufferedImage readBufferedImageFromURL(String url) throws IOException {
log.debug("readBufferedImageFromURL:" + url);
URL URL = new URL(url);
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort());
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort(), URL.getProtocol());
log.debug("targetHost:" + targetHost);
DefaultHttpClient client = new DefaultHttpClient();

Expand Down Expand Up @@ -339,7 +339,7 @@ public BufferedImage readBufferedImageFromURL(String url) throws IOException {
public static BufferedImage readBufferedImageFromPOST(String url, String post) throws IOException{
log.debug("readBufferedImageFromURL:" + url);
URL URL = new URL(url);
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort());
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort(), URL.getProtocol());
log.debug("targetHost:" + targetHost);
DefaultHttpClient client = new DefaultHttpClient();

Expand Down Expand Up @@ -372,7 +372,7 @@ public static BufferedImage readBufferedImageFromPOST(String url, String post) t
public static BufferedImage readBufferedImageFromRETRIEVAL(String url, String publicKey, String privateKey, String host) throws IOException {
log.debug("readBufferedImageFromURL:" + url);
URL URL = new URL(url);
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort());
HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort(), URL.getProtocol());
log.debug("targetHost:" + targetHost);
DefaultHttpClient client = new DefaultHttpClient();
log.debug("client:" + client);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/be/cytomine/client/models/ImageServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package be.cytomine.client.models;

/*
* Copyright (c) 2009-2019. Authors: see NOTICE file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

public class ImageServer extends Model<ImageServer> {
}
43 changes: 19 additions & 24 deletions src/main/java/be/cytomine/client/sample/SoftwareExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,10 @@ public static void addSoftwareTissueSegmentBuilder(Cytomine cytomine) throws Exc
"--cytomine_host $host " +
"--cytomine_public_key $publicKey " +
"--cytomine_private_key $privateKey " +
"--cytomine_base_path /api/ " +
"--cytomine_id_software $cytomine_id_software " +
"--cytomine_working_path algo/segmentation_model_builder/ " +
"--cytomine_id_project $cytomine_id_project " +
"--cytomine_annotation_projects $cytomine_annotation_projects " +
"-z $cytomine_zoom_level " +
"--cytomine_zoom_level $cytomine_zoom_level " +
"--cytomine_predict_terms $cytomine_predict_terms " +
"--cytomine_excluded_terms $cytomine_excluded_terms " +
"--pyxit_target_width $pyxit_target_width " +
Expand All @@ -302,7 +300,7 @@ public static void addSoftwareTissueSegmentBuilder(Cytomine cytomine) throws Exc
"--forest_min_samples_split $forest_min_samples_split " +
"--pyxit_n_subwindows $pyxit_n_subwindows " +
"--cytomine_reviewed $cytomine_reviewed " +
"--verbose True");
"--log_level INFO");


// set by server
Expand All @@ -313,20 +311,19 @@ public static void addSoftwareTissueSegmentBuilder(Cytomine cytomine) throws Exc
cytomine.addSoftwareParameter("cytomine_annotation_projects", "ListDomain", software.getId(), "", true, 600, "/api/ontology/$currentOntology$/project.json", "name", "name");
cytomine.addSoftwareParameter("cytomine_zoom_level", "Number", software.getId(), "0", true, 700);
cytomine.addSoftwareParameter("cytomine_predict_terms", "ListDomain", software.getId(), "", true, 800, "/api/project/$currentProject$/term.json", "name", "name");
cytomine.addSoftwareParameter("cytomine_excluded_terms", "ListDomain", software.getId(), "", true, 900, "/api/project/$currentProject$/term.json", "name", "name");
cytomine.addSoftwareParameter("cytomine_excluded_terms", "ListDomain", software.getId(), "", false, 900, "/api/project/$currentProject$/term.json", "name", "name");
cytomine.addSoftwareParameter("cytomine_reviewed", "Boolean", software.getId(), "false", true, 925);
cytomine.addSoftwareParameter("pyxit_n_subwindows", "Number", software.getId(), "100", true, 950);
cytomine.addSoftwareParameter("pyxit_target_width", "Number", software.getId(), "24", true, 1000);
cytomine.addSoftwareParameter("pyxit_target_height", "Number", software.getId(), "24", true, 1100);
cytomine.addSoftwareParameter("pyxit_colorspace", "Number", software.getId(), "2", true, 1200);
cytomine.addSoftwareParameter("pyxit_n_jobs", "Number", software.getId(), "10", true, 1300);
cytomine.addSoftwareParameter("pyxit_transpose", "Boolean", software.getId(), "false", false, 1500);
cytomine.addSoftwareParameter("pyxit_fixed_size", "Boolean", software.getId(), "true", false, 1600);
cytomine.addSoftwareParameter("pyxit_fixed_size", "Boolean", software.getId(), "false", false, 1600);
cytomine.addSoftwareParameter("pyxit_interpolation", "Number", software.getId(), "1", false, 1700);
cytomine.addSoftwareParameter("forest_n_estimators", "Number", software.getId(), "10", true, 1800);
cytomine.addSoftwareParameter("forest_max_features", "Number", software.getId(), "28", true, 1900);
cytomine.addSoftwareParameter("forest_min_samples_split", "Number", software.getId(), "1", true, 2000);

cytomine.addSoftwareParameter("forest_min_samples_split", "Number", software.getId(), "2", true, 2000);

} catch (CytomineException e) {
log.error(e);
Expand All @@ -342,33 +339,33 @@ public static void addSoftwareTissueSegmentPrediction(Cytomine cytomine) throws
"--cytomine_host $host " +
"--cytomine_public_key $publicKey " +
"--cytomine_private_key $privateKey " +
"--cytomine_base_path /api/ " +
"--cytomine_id_software $cytomine_id_software " +
"--cytomine_working_path algo/segmentation_prediction/ " +
"--cytomine_id_project $cytomine_id_project " +
"-z $cytomine_zoom_level " +
"-t $cytomine_tile_size " +
"--pyxit_load_from $pyxit_load_from " +

"--model_id_job $model_id_job " +
"--cytomine_zoom_level $cytomine_zoom_level " +
"--cytomine_tile_size $cytomine_tile_size " +
"--cytomine_tile_min_stddev $cytomine_tile_min_stddev " +
"--cytomine_tile_max_mean $cytomine_tile_max_mean " +
"--startx $cytomine_startx " +
"--starty $cytomine_starty " +
"--endx $cytomine_endx " +
"--endy $cytomine_endy " +
"-j $cytomine_nb_jobs " +
"--cytomine_startx $cytomine_startx " +
"--cytomine_starty $cytomine_starty " +
"--cytomine_endx $cytomine_endx " +
"--cytomine_endy $cytomine_endy " +
"--cytomine_nb_jobs $cytomine_nb_jobs " +
"--cytomine_predict_term $cytomine_predict_term " +
"--cytomine_roi_term $cytomine_roi_term " +
"--cytomine_reviewed_roi $cytomine_reviewed_roi " +
"--pyxit_target_width $pyxit_target_width " +
"--pyxit_target_height $pyxit_target_height " +
"--pyxit_colorspace $pyxit_colorspace " +
"--pyxit_nb_jobs $pyxit_nb_jobs " +
"--pyxit_save_to $pyxit_load_from " +
"--cytomine_predict_step $cytomine_predict_step " +

"--cytomine_union $cytomine_union " +
"--cytomine_postproc $cytomine_postproc " +

"--cytomine_min_size $cytomine_min_size " +
"--cytomine_max_size $cytomine_max_size " +
"--cytomine_union_min_length $cytomine_union_min_length " +
"--cytomine_union_bufferoverlap $cytomine_union_bufferoverlap " +
"--cytomine_union_area $cytomine_union_area " +
Expand All @@ -378,12 +375,11 @@ public static void addSoftwareTissueSegmentPrediction(Cytomine cytomine) throws
"--cytomine_union_nb_zones_width $cytomine_union_nb_zones_width " +
"--cytomine_union_nb_zones_height $cytomine_union_nb_zones_height " +

"--cytomine_mask_internal_holes $cytomine_mask_internal_holes " +
"--cytomine_count $cytomine_count " +

"--cytomine_max_size $cytomine_max_size " +
"--pyxit_post_classification $pyxit_post_classification " +
"--pyxit_post_classification_save_to $pyxit_post_classification_save_to ");
"--pyxit_post_classification_save_to $pyxit_post_classification_save_to " +
"--log_level INFO");



Expand All @@ -396,7 +392,7 @@ public static void addSoftwareTissueSegmentPrediction(Cytomine cytomine) throws
cytomine.addSoftwareParameter("cytomine_zoom_level", "Number", software.getId(), "2", true, 900);
cytomine.addSoftwareParameter("cytomine_predict_term", "Domain", software.getId(), "", true, 925, "/api/project/$currentProject$/term.json", "name", "name");
cytomine.addSoftwareParameter("cytomine_roi_term", "Domain", software.getId(), "", true, 950, "/api/project/$currentProject$/term.json", "name", "name");
cytomine.addSoftwareParameter("cytomine_reviewed_roi", "Boolean", software.getId(), "true", true, 975);
cytomine.addSoftwareParameter("cytomine_reviewed_roi", "Boolean", software.getId(), "false", true, 975);
cytomine.addSoftwareParameter("cytomine_tile_size", "Number", software.getId(), "512", true, 1000);
cytomine.addSoftwareParameter("cytomine_tile_min_stddev", "Number", software.getId(), "5", true, 1100);
cytomine.addSoftwareParameter("cytomine_tile_max_mean", "Number", software.getId(), "250", true, 1200);
Expand All @@ -417,7 +413,6 @@ public static void addSoftwareTissueSegmentPrediction(Cytomine cytomine) throws
cytomine.addSoftwareParameter("cytomine_union_max_point", "Number", software.getId(), "1000", true, 3500);
cytomine.addSoftwareParameter("cytomine_union_nb_zones_width", "Number", software.getId(), "5", true, 3600);
cytomine.addSoftwareParameter("cytomine_union_nb_zones_height", "Number", software.getId(), "5", true, 3700);
cytomine.addSoftwareParameter("cytomine_mask_internal_holes", "Boolean", software.getId(), "true", true, 3800);
cytomine.addSoftwareParameter("cytomine_count", "Boolean", software.getId(), "false", true, 3900);
cytomine.addSoftwareParameter("cytomine_startx", "Number", software.getId(), "0", true, 3925);
cytomine.addSoftwareParameter("cytomine_starty", "Number", software.getId(), "0", true, 3950);
Expand Down

0 comments on commit 991a336

Please sign in to comment.