Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrkioraskari committed Oct 21, 2020
1 parent cca0d7f commit ba93ac8
Show file tree
Hide file tree
Showing 23 changed files with 1,525 additions and 1,295 deletions.
2 changes: 1 addition & 1 deletion IFCtoLBDGeometry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@
</plugin>
</plugins>
</build>
<version>2.12</version>
<version>2.13</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.vecmath.Point3d;

Expand All @@ -20,56 +27,89 @@

public class IFCBoundingBoxes {

private final IfcOpenShellModel renderEngineModel;
private IfcOpenShellModel renderEngineModel=null;

public IFCBoundingBoxes(File ifcFile) throws DeserializeException, IOException, RenderEngineException {
this.renderEngineModel = getRenderEngineModel(ifcFile);

ExecutorService executor = Executors.newCachedThreadPool();
Callable<IfcOpenShellModel> task = new Callable<IfcOpenShellModel>() {
public IfcOpenShellModel call() {
return getRenderEngineModel(ifcFile);
}
};
Future<IfcOpenShellModel> future = executor.submit(task);
try {
// Should be done in 4 minutes
this.renderEngineModel = future.get(4, TimeUnit.MINUTES);
} catch (TimeoutException ex) {
System.out.println("Timeout");
} catch (InterruptedException e) {
} catch (ExecutionException e) {
} finally {
future.cancel(true); // may or may not desire this
}

}

public BoundingBox getBoundingBox(String guid) {
BoundingBox boundingBox = null;

if(renderEngineModel==null)
return null;
IfcOpenShellEntityInstance renderEngineInstance;
renderEngineInstance = renderEngineModel.getInstanceFromGUID(guid);

if (renderEngineInstance == null) {
return null;
}

IfcGeomServerClientEntity geometry = renderEngineInstance.generateGeometry();
if (geometry != null && geometry.getIndices().length > 0) {
boundingBox = new BoundingBox();
double[] tranformationMatrix = new double[16];
Matrix.setIdentityM(tranformationMatrix, 0);
if (renderEngineInstance.getTransformationMatrix() != null) {
tranformationMatrix = renderEngineInstance.getTransformationMatrix();
}
for (int i = 0; i < geometry.getIndices().length; i++) {
Point3d p=processExtends(tranformationMatrix, geometry.getPositions(), geometry.getIndices()[i] * 3);
boundingBox.add(p);
}
try {
IfcGeomServerClientEntity geometry = renderEngineInstance.generateGeometry();
if (geometry != null && geometry.getIndices().length > 0) {
boundingBox = new BoundingBox();
double[] tranformationMatrix = new double[16];
Matrix.setIdentityM(tranformationMatrix, 0);
if (renderEngineInstance.getTransformationMatrix() != null) {
tranformationMatrix = renderEngineInstance.getTransformationMatrix();
}
for (int i = 0; i < geometry.getIndices().length; i++) {
Point3d p=processExtends(tranformationMatrix, geometry.getPositions(), geometry.getIndices()[i] * 3);
boundingBox.add(p);
}
}

} catch (Exception e) {
e.printStackTrace();
}

return boundingBox;
}

private IfcOpenShellModel getRenderEngineModel(File ifcFile) throws RenderEngineException, IOException {
String ifcGeomServerLocation = OperatingSystemCopyOf_IfcGeomServer.getIfcGeomServer();
System.out.println("ifcGeomServerLocation: " + ifcGeomServerLocation);
Path ifcGeomServerLocationPath = Paths.get(ifcGeomServerLocation);
IfcOpenShellEngine ifcOpenShellEngine = new IfcOpenShellEngine(ifcGeomServerLocationPath, false, false);
System.out.println("init");
ifcOpenShellEngine.init();
System.out.println("init done");
FileInputStream ifcFileInputStream = new FileInputStream(ifcFile);

System.out.println("ifcFile: " + ifcFile);
IfcOpenShellModel model = ifcOpenShellEngine.openModel(ifcFileInputStream);
System.out.println("IfcOpenShell opens ifc: " + ifcFile.getAbsolutePath());

model.generateGeneralGeometry();
return model;
private IfcOpenShellModel getRenderEngineModel(File ifcFile) {
try {
String ifcGeomServerLocation = OperatingSystemCopyOf_IfcGeomServer.getIfcGeomServer();
System.out.println("ifcGeomServerLocation: " + ifcGeomServerLocation);
Path ifcGeomServerLocationPath = Paths.get(ifcGeomServerLocation);
IfcOpenShellEngine ifcOpenShellEngine = new IfcOpenShellEngine(ifcGeomServerLocationPath, false, false);
System.out.println("init");
ifcOpenShellEngine.init();
System.out.println("init done");
FileInputStream ifcFileInputStream = new FileInputStream(ifcFile);

System.out.println("ifcFile: " + ifcFile);
IfcOpenShellModel model = ifcOpenShellEngine.openModel(ifcFileInputStream);
System.out.println("IfcOpenShell opens ifc: " + ifcFile.getAbsolutePath());

model.generateGeneralGeometry();
return model;

} catch (Exception e) {
e.printStackTrace();
}



return null;
}

private Point3d processExtends(double[] transformationMatrix, float[] ds, int index) {
Expand All @@ -86,5 +126,16 @@ private Point3d processExtends(double[] transformationMatrix, float[] ds, int in

}

public void close()
{
if(this.renderEngineModel!=null)
{
try {
this.renderEngineModel.close();
} catch (RenderEngineException e) {
// Just do it
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ public void close() throws RenderEngineException {
if (instancesById != null) {
instancesById.clear();
}
//JO 2020
if (instancesByGUID != null) {
instancesByGUID.clear();
}
try {
ifcInputStream.close();
} catch (IOException e) {
LOGGER.error("", e);
}

client.close(); //JO 2020
}

public void generateGeneralGeometry() throws RenderEngineException {
Expand Down
4 changes: 2 additions & 2 deletions IFCtoLBD_OpenAPI/.settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<dependent-module archiveName="IFCtoLBD-2.12.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/IFCtoLBD/IFCtoLBD">
<dependent-module archiveName="IFCtoLBD-2.13.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/IFCtoLBD/IFCtoLBD">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="IFCtoLBDGeometry-2.12.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/IFCtoLBDGeometry/IFCtoLBDGeometry">
<dependent-module archiveName="IFCtoLBDGeometry-2.13.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/IFCtoLBDGeometry/IFCtoLBDGeometry">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="IFCtoRDF-0.5J2-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/IFCtoRDF/IFCtoRDF">
Expand Down
4 changes: 2 additions & 2 deletions IFCtoLBD_OpenAPI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.rwth-aachen.dc.ifctolbd</groupId>
<artifactId>IFCtoLBD_OpenAPI</artifactId>
<version>2.12</version>
<version>2.13</version>
<packaging>war</packaging>
<name>IFCtoLBD OpenAPI Interface</name>

Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>io.github.jyrkioraskari</groupId>
<artifactId>IFCtoLBD</artifactId>
<version>2.12</version>
<version>2.13</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena-libs -->
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IFCtoLBD
Version 2.12
Version 2.13

Contributors: Jyrki Oraskari, Mathias Bonduel, Kris McGlinn, Anna Wagner, Pieter Pauwels, Ville Kukkonen, Simon Steyskaland, and Joel Lehtonen.

Expand Down
4 changes: 2 additions & 2 deletions converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.jyrkioraskari</groupId>
<artifactId>IFCtoLBD</artifactId>
<version>2.12</version>
<version>2.13</version>
<name>IFC to LBD Converter</name>
<licenses>
<license>
Expand Down Expand Up @@ -71,7 +71,7 @@
<dependency>
<groupId>de.rwth-aachen.dc.lbd</groupId>
<artifactId>IFCtoLBDGeometry</artifactId>
<version>2.12</version>
<version>2.13</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
2 changes: 1 addition & 1 deletion converter/src/license/THIRD-PARTY.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
# Please fill the missing licenses for dependencies :
#
#
#Wed Oct 14 18:27:40 CEST 2020
#Wed Oct 21 16:04:22 CEST 2020
gnu.getopt--java-getopt--1.0.13=
Loading

0 comments on commit ba93ac8

Please sign in to comment.