Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 package org.srs.srs_knowledge.utils;
00053
00054 import java.io.*;
00055 import java.util.StringTokenizer;
00056 import java.util.ArrayList;
00057 import java.util.Iterator;
00058 import ros.pkg.srs_knowledge.msg.*;
00059 import ros.pkg.geometry_msgs.msg.Pose2D;
00060 import org.srs.srs_knowledge.knowledge_engine.*;
00061
00062 import ros.*;
00063 import ros.communication.*;
00064
00065 import com.hp.hpl.jena.rdf.model.*;
00066 import com.hp.hpl.jena.vocabulary.*;
00067 import com.hp.hpl.jena.util.FileManager;
00068
00069 import com.hp.hpl.jena.rdf.model.Property;
00070 import com.hp.hpl.jena.ontology.OntClass;
00071 import com.hp.hpl.jena.ontology.OntModel;
00072 import com.hp.hpl.jena.rdf.model.Statement;
00073 import com.hp.hpl.jena.ontology.Individual;
00074 import com.hp.hpl.jena.shared.Lock;
00075 import com.hp.hpl.jena.ontology.OntResource;
00076
00077 import tfjava.*;
00078
00079 import javax.vecmath.Quat4d;
00080 import javax.vecmath.Vector3d;
00081 import javax.vecmath.Point3d;
00082 import javax.vecmath.Matrix4d;
00083
00084 import math.geom2d.*;
00085 import math.geom2d.line.LineSegment2D;
00086 import math.geom2d.polygon.Polygon2DUtils;
00087 import math.geom2d.polygon.Polygon2D;
00088 import math.geom2d.polygon.SimplePolygon2D;
00089
00090 import math.geom2d.Point2D;
00091
00092 import ros.pkg.srs_object_database_msgs.srv.GetObjectId;
00093
00094
00095 public class InformationRetrieval
00096 {
00100 public static BoundingBoxDim retrieveBoundingBoxInfo(String objectClassURI) {
00101
00102
00103
00104 BoundingBoxDim d = new BoundingBoxDim();
00105
00106
00107 Iterator<Individual> instances = KnowledgeEngine.ontoDB.getInstancesOfClass(objectClassURI);
00108 if(instances != null) {
00109 if(instances.hasNext()) {
00110 com.hp.hpl.jena.rdf.model.Statement stm;
00111 Individual temp = instances.next();
00112 stm = KnowledgeEngine.ontoDB.getPropertyOf(OntoQueryUtil.GlobalNameSpace, "widthOfObject", temp);
00113 d.w = getFloatOfStatement(stm, -1000);
00114 stm = KnowledgeEngine.ontoDB.getPropertyOf(OntoQueryUtil.GlobalNameSpace, "heightOfObject", temp);
00115 d.h = getFloatOfStatement(stm, -1000);
00116 stm = KnowledgeEngine.ontoDB.getPropertyOf(OntoQueryUtil.GlobalNameSpace, "lengthOfObject", temp);
00117 d.l = getFloatOfStatement(stm, -1000);
00118 if(d.w != -1000 && d.h != -1000 && d.l != -1000) {
00119 return d;
00120 }
00121 }
00122 }
00123
00124
00125
00126 ServiceClient<GetObjectId.Request, GetObjectId.Response, GetObjectId> sc = KnowledgeEngine.nodeHandle.serviceClient("get_models" , new GetObjectId(), false);
00127
00128 GetObjectId.Request rq = new GetObjectId.Request();
00129
00130 rq.type = "item";
00131 String[] subStrs = objectClassURI.trim().split("#");
00132 String objectClass = objectClassURI;
00133 if(subStrs.length == 2) {
00134 objectClass = subStrs[1];
00135 }
00136 rq.item = objectClass;
00137 ArrayList<String> modelDesc = new ArrayList<String>();
00138 ArrayList<String> modelCategory = new ArrayList<String>();
00139 int id = -1000;
00140
00141 try {
00142 GetObjectId.Response res = sc.call(rq);
00143 int[] ids = res.model_ids;
00144 modelDesc = res.model_desc;
00145 modelCategory = res.model_category;
00146 for (int i = 0; i < modelDesc.size(); i++) {
00147 if(modelDesc.get(i).equals(objectClass)) {
00148
00149 id = ids[i];
00150
00151 d.l = res.model_x_size[i];
00152 d.w = res.model_y_size[i];
00153 d.h = res.model_z_size[i];
00154 if(d.l != 0 && d.h != 0 && d.w != 0) {
00155 sc.shutdown();
00156 return d;
00157 }
00158 }
00159 }
00160 }
00161 catch(RosException e) {
00162 System.out.println(e.getMessage());
00163 sc.shutdown();
00164 return new BoundingBoxDim();
00165 }
00166 sc.shutdown();
00167
00168 return new BoundingBoxDim();
00169 }
00170
00171 public static float getFloatOfStatement(com.hp.hpl.jena.rdf.model.Statement stm, float defaultIfInvalid) {
00172 float t = defaultIfInvalid;
00173 try {
00174 t = stm.getFloat();
00175 }
00176 catch(Exception e) {
00177 System.out.println(e.getMessage());
00178 }
00179 return t;
00180 }
00181
00182 private static int getIntOfStatement(Statement stm, int defaultIfInvalid)
00183 {
00184 int t = defaultIfInvalid;
00185 try {
00186 t = stm.getInt();
00187 }
00188 catch(Exception e) {
00189 System.out.println(e.getMessage());
00190 }
00191 return t;
00192 }
00193 }