use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class GetGeometryInfoDatabaseAction method execute.
@Override
public SGeometryInfo execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
Project project = revision.getProject();
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
IdEObject ifcProduct = getDatabaseSession().get(oid, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid()));
if (ifcProduct == null) {
throw new UserException("Object with oid " + oid + " not found");
}
EStructuralFeature geometryFeature = packageMetaData.getEClass("IfcProduct").getEStructuralFeature("geometry");
GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature);
SGeometryInfo convertToSObject = bimServer.getSConverter().convertToSObject(geometry);
return convertToSObject;
}
use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class TestGeometry method test.
@Test
public void test() {
try {
// Create a new BimServerClient with authentication
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Get the low level interface
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
// Create a new project
SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Look for a deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
// Checkin file
long start = System.nanoTime();
bimServerClient.checkinSync(project.getOid(), "test", deserializer.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
// bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, Paths.get("D:\\Dropbox\\Shared\\IFC files\\ArenA 2014\\3D IFC\\arena.ifc"));
long end = System.nanoTime();
System.out.println(((end - start) / 1000000) + " ms");
// Refresh project
project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
int nrTriangles = 0;
// Load model without lazy loading (complete model at once)
IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, true, true);
Assert.assertNotNull(model.getModelMetaData().getMinBounds());
Assert.assertNotNull(model.getModelMetaData().getMaxBounds());
for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
GeometryInfo geometryInfo = ifcProduct.getGeometry();
if (geometryInfo != null) {
Vector3f minBounds = geometryInfo.getBounds().getMin();
Vector3f maxBounds = geometryInfo.getBounds().getMax();
Assert.assertNotNull(minBounds);
Assert.assertNotNull(maxBounds);
nrTriangles += geometryInfo.getPrimitiveCount();
}
}
Assert.assertEquals(45260, nrTriangles);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class TestGetGeometry2 method test.
@Test
public void test() throws Exception {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, new CheckinProgressHandler() {
@Override
public void progress(String title, int progress) {
System.out.println(title + ": " + progress);
}
});
ClientIfcModel model = client.getModel(project, actionState.getRoid(), false, false, true);
for (IfcProduct product : model.getAllWithSubTypes(IfcProduct.class)) {
GeometryInfo geometry = product.getGeometry();
if (geometry != null) {
System.out.println(product.getGeometry().getData().getNrVertices());
System.out.println(product.getGeometry().getData().getVertices().getData().length);
}
}
}
}
Thread.sleep(1000);
}
use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class TestGetGeometry method test.
@Test
public void test() throws Exception {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
SLongCheckinActionState actionState = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> System.out.println(title + ": " + progress));
PackageMetaData packageMetaData = client.getMetaDataManager().getPackageMetaData("ifc2x3tc1");
GeometryTargetImpl geometryTargetImpl = new GeometryTargetImpl(packageMetaData);
GeometryLoader geometryLoader = new GeometryLoader(client, packageMetaData, geometryTargetImpl);
Set<Long> oids = new HashSet<>();
// Only to gather oids
ClientIfcModel model = client.getModel(project, actionState.getRoid(), true, false, false);
for (IfcWall ifcWall : model.getAllWithSubTypes(IfcWall.class)) {
oids.add(ifcWall.getOid());
}
geometryLoader.loadProducts(actionState.getRoid(), oids);
System.out.println(geometryTargetImpl);
Set<Long> geometryDataOids = new HashSet<>();
for (GeometryInfo geometryInfo : geometryTargetImpl.getAllGeometryInfo()) {
GeometryData geometryData = geometryInfo.getData();
System.out.println(geometryInfo.getPrimitiveCount());
System.out.println(geometryData.getNrIndices());
geometryDataOids.add(geometryData.getOid());
}
geometryTargetImpl = new GeometryTargetImpl(packageMetaData);
geometryLoader = new GeometryLoader(client, packageMetaData, geometryTargetImpl);
geometryLoader.loadGeometryData(actionState.getRoid(), geometryDataOids);
System.out.println(geometryTargetImpl);
}
}
Thread.sleep(1000);
}
use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class AbstractDownloadDatabaseAction method checkGeometry.
protected void checkGeometry(PluginConfiguration serializerPluginConfiguration, PluginManager pluginManager, IfcModelInterface model, Project project, ConcreteRevision concreteRevision, Revision revision) throws BimserverDatabaseException, GeometryGeneratingException {
Set<String> needsGeometry = null;
Plugin plugin = pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (plugin instanceof SerializerPlugin) {
needsGeometry = ((SerializerPlugin) plugin).getRequiredGeometryFields();
}
if (needsGeometry != null) {
if (!revision.isHasGeometry()) {
// setProgress("Generating geometry...", -1);
// TODO When generating geometry for a partial model download (by types for example), this will fail (for example walls have no openings)
// new GeometryGenerator(bimServer).generateGeometry(authorization.getUoid(), pluginManager, getDatabaseSession(), model, project.getId(), concreteRevision.getId(), false, null);
} else {
EClass productClass = model.getPackageMetaData().getEClass("IfcProduct");
List<IdEObject> allWithSubTypes = new ArrayList<>(model.getAllWithSubTypes(productClass));
for (IdEObject ifcProduct : allWithSubTypes) {
ifcProduct.forceLoad();
GeometryInfo geometryInfo = (GeometryInfo) ifcProduct.eGet(productClass.getEStructuralFeature("geometry"));
if (geometryInfo != null) {
geometryInfo.forceLoad();
geometryInfo.getData().forceLoad();
if (needsGeometry.contains("colorsQuantized")) {
geometryInfo.getData().getColorsQuantized().forceLoad();
}
if (needsGeometry.contains("indices")) {
geometryInfo.getData().getIndices().forceLoad();
}
if (needsGeometry.contains("normals")) {
geometryInfo.getData().getNormals().forceLoad();
}
if (needsGeometry.contains("normalsQuantized")) {
geometryInfo.getData().getNormalsQuantized().forceLoad();
}
if (needsGeometry.contains("vertices")) {
geometryInfo.getData().getVertices().forceLoad();
}
if (needsGeometry.contains("verticesQuantized")) {
geometryInfo.getData().getVerticesQuantized().forceLoad();
}
geometryInfo.getData().getColor().forceLoad();
geometryInfo.getTransformation();
geometryInfo.getBounds().forceLoad();
geometryInfo.getBounds().getMin().forceLoad();
geometryInfo.getBounds().getMax().forceLoad();
}
}
}
}
}
Aggregations