Search in sources :

Example 6 with GeometryInfo

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;
}
Also used : SGeometryInfo(org.bimserver.interfaces.objects.SGeometryInfo) Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) SGeometryInfo(org.bimserver.interfaces.objects.SGeometryInfo) UserException(org.bimserver.shared.exceptions.UserException) OldQuery(org.bimserver.database.OldQuery)

Example 7 with GeometryInfo

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());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Vector3f(org.bimserver.models.geometry.Vector3f) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 8 with GeometryInfo

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);
}
Also used : Path(java.nio.file.Path) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) SProject(org.bimserver.interfaces.objects.SProject) BimServerClient(org.bimserver.client.BimServerClient) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) CheckinProgressHandler(org.bimserver.plugins.services.CheckinProgressHandler) Test(org.junit.Test)

Example 9 with GeometryInfo

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);
}
Also used : Path(java.nio.file.Path) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) ClientIfcModel(org.bimserver.client.ClientIfcModel) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) GeometryTargetImpl(org.bimserver.client.GeometryTargetImpl) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) PackageMetaData(org.bimserver.emf.PackageMetaData) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) GeometryData(org.bimserver.models.geometry.GeometryData) SProject(org.bimserver.interfaces.objects.SProject) GeometryLoader(org.bimserver.client.GeometryLoader) BimServerClient(org.bimserver.client.BimServerClient) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with GeometryInfo

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();
                }
            }
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) ArrayList(java.util.ArrayList) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) Plugin(org.bimserver.plugins.Plugin)

Aggregations

GeometryInfo (org.bimserver.models.geometry.GeometryInfo)15 GeometryData (org.bimserver.models.geometry.GeometryData)8 IdEObject (org.bimserver.emf.IdEObject)6 IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 SProject (org.bimserver.interfaces.objects.SProject)4 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)4 EClass (org.eclipse.emf.ecore.EClass)4 ByteBuffer (java.nio.ByteBuffer)3 BimServerClient (org.bimserver.client.BimServerClient)3 ClientIfcModel (org.bimserver.client.ClientIfcModel)3 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)3 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)3 Vector3f (org.bimserver.models.geometry.Vector3f)3 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 Test (org.junit.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 DoubleBuffer (java.nio.DoubleBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 IntBuffer (java.nio.IntBuffer)2