Search in sources :

Example 1 with Buffer

use of org.bimserver.models.geometry.Buffer in project BIMserver by opensourceBIM.

the class TestChangeGeometryError method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        bimServerClient.checkinSync(newProject.getOid(), "test", deserializer.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, true, true);
        List<IfcWall> walls = model.getAllWithSubTypes(Ifc2x3tc1Package.eINSTANCE.getIfcWall());
        IfcWall firstWall = walls.get(0);
        Buffer buffer = GeometryFactory.eINSTANCE.createBuffer();
        buffer.setData(new byte[10]);
        firstWall.getGeometry().getData().setVertices(buffer);
        model.commit("Tried to change geometry, which should not be possible");
        fail("This have thrown an error");
    } catch (Throwable e) {
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        e.printStackTrace();
        assertEquals("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (GeometryData) is from the \"geometry\" package", e.getMessage());
    }
}
Also used : Buffer(org.bimserver.models.geometry.Buffer) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 2 with Buffer

use of org.bimserver.models.geometry.Buffer in project BIMserver by opensourceBIM.

the class OfflineGeometryGenerator method createBuffer.

private Buffer createBuffer(ByteBuffer data) {
    Buffer buffer = GeometryFactory.eINSTANCE.createBuffer();
    buffer.setData(data.array());
    return buffer;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(org.bimserver.models.geometry.Buffer) DoubleBuffer(java.nio.DoubleBuffer)

Example 3 with Buffer

use of org.bimserver.models.geometry.Buffer in project BIMserver by opensourceBIM.

the class GeometryGenerator method createBuffer.

private Buffer createBuffer(IfcModelInterface model, DatabaseSession databaseSession, ByteBuffer data, boolean store, int pid, int rid) throws ObjectAlreadyExistsException, IfcModelInterfaceException, BimserverDatabaseException {
    Buffer buffer = null;
    if (store) {
        buffer = model.createAndAdd(GeometryPackage.eINSTANCE.getBuffer(), databaseSession.newOid(GeometryPackage.eINSTANCE.getBuffer()));
        databaseSession.store(buffer, pid, rid);
    } else {
        buffer = GeometryFactory.eINSTANCE.createBuffer();
    }
    buffer.setData(data.array());
    return buffer;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(org.bimserver.models.geometry.Buffer) DoubleBuffer(java.nio.DoubleBuffer)

Example 4 with Buffer

use of org.bimserver.models.geometry.Buffer in project BIMserver by opensourceBIM.

the class StreamingCheckinDatabaseAction method generateQuantizedVertices.

private void generateQuantizedVertices(DatabaseSession databaseSession, Revision revision, float[] quantizationMatrix, float multiplierToMm) {
    PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    Query query = new Query(packageMetaData);
    QueryPart queryPart = query.createQueryPart();
    queryPart.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
    Include geometryDataInclude = queryPart.createInclude();
    try {
        geometryDataInclude.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
        geometryDataInclude.addFieldDirect("vertices");
        QueryObjectProvider objectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(revision.getOid()), packageMetaData);
        HashMapVirtualObject next = objectProvider.next();
        while (next != null) {
            HashMapVirtualObject verticesBuffer = (HashMapVirtualObject) next.get("vertices");
            ByteBuffer verticesData = ByteBuffer.wrap((byte[]) verticesBuffer.get("data"));
            verticesData.order(ByteOrder.LITTLE_ENDIAN);
            FloatBuffer vertices = verticesData.asFloatBuffer();
            ByteBuffer verticesQuantized = quantizeVertices(vertices.array(), quantizationMatrix, multiplierToMm);
            Buffer buffer = getDatabaseSession().create(Buffer.class);
            buffer.setData(verticesQuantized.array());
            next.setReference(GeometryPackage.eINSTANCE.getGeometryData_VerticesQuantized(), buffer.getOid(), -1);
            next.saveOverwrite();
            next = objectProvider.next();
            System.out.println("Generating quantized vertices");
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) Buffer(org.bimserver.models.geometry.Buffer) OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) Include(org.bimserver.database.queries.om.Include) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Aggregations

Buffer (org.bimserver.models.geometry.Buffer)4 ByteBuffer (java.nio.ByteBuffer)3 FloatBuffer (java.nio.FloatBuffer)3 DoubleBuffer (java.nio.DoubleBuffer)2 IntBuffer (java.nio.IntBuffer)2 IOException (java.io.IOException)1 URL (java.net.URL)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)1 OldQuery (org.bimserver.database.OldQuery)1 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)1 Include (org.bimserver.database.queries.om.Include)1 Query (org.bimserver.database.queries.om.Query)1 QueryPart (org.bimserver.database.queries.om.QueryPart)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 PackageMetaData (org.bimserver.emf.PackageMetaData)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1 SProject (org.bimserver.interfaces.objects.SProject)1 IfcWall (org.bimserver.models.ifc2x3tc1.IfcWall)1 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)1