Skip to content

Commit

Permalink
removed octree attribute in AdjacencyMap
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezsieira committed Jun 13, 2016
1 parent d4c1673 commit fd80698
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 47 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>format</goal>
</goals>
</execution>
</executions>
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/es/usc/citius/lab/joctomap/octree/JOctree.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
* @author adrian.gonzalez
*/
public class JOctree extends NativeObject{

private String path;

/**
* Initializes the JOctree with a pointer to the native OcTree object of
Expand Down Expand Up @@ -424,14 +422,5 @@ public JOctreeNode search(float x, float y, float z){
* @return octree with the given resolution
*/
public static native JOctree create(float res);

/**
* Retrieves the path from which the octree was loaded.
*
* @return
*/
public String getPath() {
return path;
}

}
21 changes: 2 additions & 19 deletions src/main/java/es/usc/citius/lab/joctomap/util/AdjacencyMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* This class implements a builder for calculating the adjacency map of an Octomap.
Expand All @@ -49,7 +46,6 @@
public class AdjacencyMap implements Serializable{

private Map<JOctreeKey, List<JOctreeKey>> adjacencies;
private JOctree octree;
//contains the information of size and center of each leaf in the octree
private Map<JOctreeKey, Pair<Float, Point3D>> nodesInfo;
private double EPSILON = 1e-3;
Expand All @@ -63,7 +59,6 @@ public class AdjacencyMap implements Serializable{
*/
private AdjacencyMap(JOctree octree){
this.adjacencies = new HashMap<JOctreeKey, List<JOctreeKey>>();
this.octree = octree;
this.nodesInfo = new HashMap<JOctreeKey, Pair<Float, Point3D>>();
//create cache
Cache cacheOfKeys = new Cache();
Expand Down Expand Up @@ -116,10 +111,8 @@ private AdjacencyMap(){
public static AdjacencyMap create(JOctree octree){
//initialize structures
AdjacencyMap map = new AdjacencyMap();
//assign octree
map.octree = octree;
//fill with JNI method
map.initializeJNI();
map.initializeJNI(octree);
//retrieve result
return map;
}
Expand All @@ -139,7 +132,7 @@ public static AdjacencyMap createJava(JOctree octree){
* This fills the structures of the adjacency map using full-native
* implementation method for efficiency.
*/
private native void initializeJNI();
private native void initializeJNI(JOctree octree);

/**
* Retrieves the adjacencies for a current key.
Expand All @@ -159,10 +152,6 @@ public Map<JOctreeKey, Pair<Float, Point3D>> getNodesInfo() {
return nodesInfo;
}

public JOctree getOctree() {
return octree;
}

/**
* Retrieves the information of a node stored after exploring the adjacencies.
*
Expand Down Expand Up @@ -194,8 +183,6 @@ public boolean write(String filename){
//open output stream
try{
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(outputFile));
//write name of octree
outputStream.writeUTF(this.octree.getPath());
//write adjacencies & nodesInfo
outputStream.writeInt(adjacencies.size());
for(Map.Entry<JOctreeKey, List<JOctreeKey>> current : adjacencies.entrySet()){
Expand Down Expand Up @@ -239,10 +226,6 @@ public static AdjacencyMap read(String filename){
//open input stream (will be closed after this statement)
try{
DataInputStream inputStream = new DataInputStream(new FileInputStream(inputFile));
//read name of the octree
String octreePath = inputStream.readUTF();
//load octree
map.octree = JOctree.read(octreePath);
//read map instance
int sizeMap = inputStream.readInt();
map.adjacencies = new HashMap<JOctreeKey, List<JOctreeKey>>(sizeMap);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/joctomap-natives/include/adjacencymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ extern "C" {
/*
* Class: es_usc_citius_lab_joctomap_util_AdjacencyMap
* Method: initializeJNI
* Signature: ()V
* Signature: (Les/usc/citius/lab/joctomap/octree/JOctree;)V
*/
JNIEXPORT void JNICALL Java_es_usc_citius_lab_joctomap_util_AdjacencyMap_initializeJNI
(JNIEnv *, jobject);
(JNIEnv *, jobject, jobject);

#ifdef __cplusplus
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/joctomap-natives/src/adjacencymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
using namespace octomap;

JNIEXPORT void JNICALL Java_es_usc_citius_lab_joctomap_util_AdjacencyMap_initializeJNI
(JNIEnv *env, jobject jadjacencymap){
(JNIEnv *env, jobject jadjacencymap, jobject joctree){
//error margin
float EPSILON = 0.001f;
//retrieve fields from adjacencymap
jclass cls_jadjacencymap = env->FindClass(CLS_JADJACENCYMAP);
jfieldID field_joctomap = env->GetFieldID(cls_jadjacencymap, FIELD_ADJACENCYMAP_OCTREE, CLS_JOCTREE);
jfieldID field_nodes_info = env->GetFieldID(cls_jadjacencymap, FIELD_ADJACENCYMAP_NODESINFO, CLS_MAP);
jfieldID field_adjacencies = env->GetFieldID(cls_jadjacencymap, FIELD_ADJACENCYMAP_ADJACENCIES, CLS_MAP);
//retrieve objects from fields
jobject joctree = env->GetObjectField(jadjacencymap, field_joctomap);
jobject jnodes_info = env->GetObjectField(jadjacencymap, field_nodes_info);
jobject jadjacencies = env->GetObjectField(jadjacencymap, field_adjacencies);
//retrieve HashMap, JOctreeKey, Pair, Point3D class
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/joctomap-natives/src/joctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,6 @@ JNIEXPORT jboolean JNICALL Java_es_usc_citius_lab_joctomap_octree_JOctree_write
const char *nativeFilename = env->GetStringUTFChars(filename, &iscopy);
//write octree in filename
bool value = octree->write(nativeFilename);
//set path to which the octree was read
jfieldID pathField = env->GetFieldID(env->GetObjectClass(obj), FIELD_PATH, CLS_STRING);
env->SetObjectField(obj, pathField, filename);
//release memory of native char*
env->ReleaseStringUTFChars(filename, nativeFilename);
//return obtained value
Expand Down Expand Up @@ -660,9 +657,6 @@ JNIEXPORT jobject JNICALL Java_es_usc_citius_lab_joctomap_octree_JOctree_read
stream.close();
//create joctree object
jobject jtree = env->NewObject(cls, constructor, ot);
//set path from which the octree was read
jfieldID pathField = env->GetFieldID(cls, FIELD_PATH, CLS_STRING);
env->SetObjectField(jtree, pathField, filename);
return jtree;
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/es/usc/citius/lab/joctomap/JOctreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void test02_readFileOt() throws IOException {
octree = JOctree.read(inputPath);
assertTrue("Octree direction of memory not assigned",
octree.getPointer() != 0);
assertTrue("Octree input path not assigned", octree.getPath().equals(inputPath));
}

/**
Expand All @@ -117,8 +116,7 @@ public void test03_writeFileOtTest() throws IOException {
octree.write(fileWrite.getAbsolutePath());
// compare by content both files
assertTrue("Input and output files with the same content",
FileUtils.contentEquals(fileRead, fileWrite));
assertTrue("File path not set properly after write", octree.getPath().equals(fileWrite.getAbsolutePath()));
FileUtils.contentEquals(fileRead, fileWrite));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public AdjacencyMapTest() throws URISyntaxException{
@Test
public void test01_calculateAdjacencyMap(){

assertEquals("Nodes info size do not match with number of leaves.", adjacencyMap.getOctree().size(), adjacencyMap.getNodesInfo().size());
assertEquals("Adjacencies info size do not match with number of leaves.", adjacencyMap.getOctree().size(), adjacencyMap.getAdjacencies().size());
assertEquals("Nodes info size do not match with number of leaves.", octree.size(), adjacencyMap.getNodesInfo().size());
assertEquals("Adjacencies info size do not match with number of leaves.", octree.size(), adjacencyMap.getAdjacencies().size());
//iterate over the entries of the adjacency map
for(Map.Entry<JOctreeKey, List<JOctreeKey>> entry : adjacencyMap.getAdjacencies().entrySet()){
//center of first cell
Expand Down

0 comments on commit fd80698

Please sign in to comment.