Search in sources :

Example 6 with SBounds

use of org.bimserver.interfaces.objects.SBounds in project BIMserver by opensourceBIM.

the class Draw2DAABB method createImage.

private void createImage() {
    Graphics graphics = image.getGraphics();
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
            List<SProjectSmall> allRelatedProjects = client.getServiceInterface().getAllRelatedProjects(13500417L);
            Bounds totalBounds = new Bounds();
            Bounds screenBounds = new Bounds(0, 0, 0, width, height, 1000);
            for (SProjectSmall projectSmall : allRelatedProjects) {
                if (projectSmall.getLastRevisionId() != -1 && projectSmall.getNrSubProjects() == 0) {
                    SProject project = client.getServiceInterface().getProjectByPoid(projectSmall.getOid());
                    SBounds bounds = client.getServiceInterface().getModelBounds(project.getLastRevisionId());
                    if (bounds != null) {
                        totalBounds.integrate(new Bounds(bounds));
                    }
                }
            }
            System.out.println("Model bounds: " + totalBounds);
            System.out.println("Screen bounds: " + screenBounds);
            for (SProjectSmall projectSmall : allRelatedProjects) {
                if (projectSmall.getLastRevisionId() != -1 && projectSmall.getNrSubProjects() == 0) {
                    SProject project = client.getServiceInterface().getProjectByPoid(projectSmall.getOid());
                    SBounds bounds = client.getServiceInterface().getModelBounds(project.getLastRevisionId());
                    if (bounds != null) {
                        Bounds subModelBounds = new Bounds(bounds);
                        Bounds subModelScreenBounds = subModelBounds.scale(totalBounds, screenBounds);
                    }
                }
            }
        }
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Graphics(java.awt.Graphics) SBounds(org.bimserver.interfaces.objects.SBounds) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) Bounds(org.bimserver.database.queries.Bounds) SBounds(org.bimserver.interfaces.objects.SBounds) SProjectSmall(org.bimserver.interfaces.objects.SProjectSmall) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) BimServerClient(org.bimserver.client.BimServerClient) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 7 with SBounds

use of org.bimserver.interfaces.objects.SBounds in project BIMserver by opensourceBIM.

the class ServiceImpl method getTotalUntransformedBounds.

@Override
public SBounds getTotalUntransformedBounds(Set<Long> roids) throws ServerException, UserException {
    // TODO duplicate code with getTotalBounds
    try (DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY)) {
        double[] totalMin = new double[] { Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE };
        double[] totalMax = new double[] { -Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE };
        for (Long roid : roids) {
            Revision revision = session.get(roid, OldQuery.getDefault());
            Bounds bounds = revision.getBoundsUntransformedMm();
            if (bounds.getMin().getX() == Double.MAX_VALUE || bounds.getMin().getY() == Double.MAX_VALUE || bounds.getMin().getZ() == Double.MAX_VALUE || bounds.getMax().getX() == -Double.MAX_VALUE || bounds.getMax().getY() == -Double.MAX_VALUE || bounds.getMax().getZ() == -Double.MAX_VALUE) {
                // Probably no objects or weird error, let's skip this one
                continue;
            }
            Vector3f min = bounds.getMin();
            Vector3f max = bounds.getMax();
            if (min.getX() < totalMin[0]) {
                totalMin[0] = min.getX();
            }
            if (min.getY() < totalMin[1]) {
                totalMin[1] = min.getY();
            }
            if (min.getZ() < totalMin[2]) {
                totalMin[2] = min.getZ();
            }
            if (max.getX() > totalMax[0]) {
                totalMax[0] = max.getX();
            }
            if (max.getY() > totalMax[1]) {
                totalMax[1] = max.getY();
            }
            if (max.getZ() > totalMax[2]) {
                totalMax[2] = max.getZ();
            }
        }
        SBounds sBounds = new SBounds();
        SVector3f sMin = new SVector3f();
        SVector3f sMax = new SVector3f();
        sBounds.setMin(sMin);
        sBounds.setMax(sMax);
        sMin.setX(totalMin[0]);
        sMin.setY(totalMin[1]);
        sMin.setZ(totalMin[2]);
        sMax.setX(totalMax[0]);
        sMax.setY(totalMax[1]);
        sMax.setZ(totalMax[2]);
        return sBounds;
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : SBounds(org.bimserver.interfaces.objects.SBounds) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SRevision(org.bimserver.interfaces.objects.SRevision) Revision(org.bimserver.models.store.Revision) CheckinRevision(org.bimserver.models.store.CheckinRevision) SExtendedDataAddedToRevision(org.bimserver.interfaces.objects.SExtendedDataAddedToRevision) DatabaseSession(org.bimserver.database.DatabaseSession) Bounds(org.bimserver.models.geometry.Bounds) SBounds(org.bimserver.interfaces.objects.SBounds) SVector3f(org.bimserver.interfaces.objects.SVector3f) Vector3f(org.bimserver.models.geometry.Vector3f) SVector3f(org.bimserver.interfaces.objects.SVector3f) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 8 with SBounds

use of org.bimserver.interfaces.objects.SBounds in project BIMserver by opensourceBIM.

the class ServiceImpl method listBoundingBoxes.

public List<SBounds> listBoundingBoxes(Set<Long> roids) throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY)) {
        List<SBounds> results = new ArrayList<>();
        Set<Region> regions = new HashSet<>();
        for (long roid : roids) {
            Revision revision = session.get(roid, OldQuery.getDefault());
            for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
                Bounds bounds = concreteRevision.getBounds();
                if (bounds.getMin().getX() == Double.MAX_VALUE || bounds.getMin().getY() == Double.MAX_VALUE || bounds.getMin().getZ() == Double.MAX_VALUE || bounds.getMax().getX() == -Double.MAX_VALUE || bounds.getMax().getY() == -Double.MAX_VALUE || bounds.getMax().getZ() == -Double.MAX_VALUE) {
                    // Probably no objects or weird error, let's skip this one
                    continue;
                }
                scaleBounds(bounds, concreteRevision.getMultiplierToMm());
                boolean integrated = false;
                for (Region region : regions) {
                    if (region.canAccept(bounds)) {
                        region.integrate(bounds);
                        integrated = true;
                        break;
                    }
                }
                if (!integrated) {
                    Region region = new Region(bounds);
                    regions.add(region);
                }
            }
        }
        for (Region region : regions) {
            results.add(region.toSBounds());
        }
        return results;
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) Bounds(org.bimserver.models.geometry.Bounds) SBounds(org.bimserver.interfaces.objects.SBounds) ArrayList(java.util.ArrayList) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) SBounds(org.bimserver.interfaces.objects.SBounds) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SRevision(org.bimserver.interfaces.objects.SRevision) Revision(org.bimserver.models.store.Revision) CheckinRevision(org.bimserver.models.store.CheckinRevision) SExtendedDataAddedToRevision(org.bimserver.interfaces.objects.SExtendedDataAddedToRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with SBounds

use of org.bimserver.interfaces.objects.SBounds in project BIMserver by opensourceBIM.

the class ServiceImpl method getModelBounds.

@Override
public SBounds getModelBounds(Long roid) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        Revision revision = session.get(roid, OldQuery.getDefault());
        ConcreteRevision lastConcreteRevision = revision.getLastConcreteRevision();
        Bounds bounds = lastConcreteRevision.getBounds();
        Vector3f min = bounds.getMin();
        Vector3f max = bounds.getMax();
        if (lastConcreteRevision.getMultiplierToMm() != 1f) {
            min.setX(min.getX() * lastConcreteRevision.getMultiplierToMm());
            min.setY(min.getY() * lastConcreteRevision.getMultiplierToMm());
            min.setZ(min.getZ() * lastConcreteRevision.getMultiplierToMm());
            max.setX(max.getX() * lastConcreteRevision.getMultiplierToMm());
            max.setY(max.getY() * lastConcreteRevision.getMultiplierToMm());
            max.setZ(max.getZ() * lastConcreteRevision.getMultiplierToMm());
        }
        return getBimServer().getSConverter().convertToSObject(bounds);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SRevision(org.bimserver.interfaces.objects.SRevision) Revision(org.bimserver.models.store.Revision) CheckinRevision(org.bimserver.models.store.CheckinRevision) SExtendedDataAddedToRevision(org.bimserver.interfaces.objects.SExtendedDataAddedToRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) DatabaseSession(org.bimserver.database.DatabaseSession) Bounds(org.bimserver.models.geometry.Bounds) SBounds(org.bimserver.interfaces.objects.SBounds) SVector3f(org.bimserver.interfaces.objects.SVector3f) Vector3f(org.bimserver.models.geometry.Vector3f) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 10 with SBounds

use of org.bimserver.interfaces.objects.SBounds in project BIMserver by opensourceBIM.

the class ServiceImpl method getTotalBounds.

@Override
public SBounds getTotalBounds(Set<Long> roids) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
    try {
        double[] totalMin = new double[] { Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE };
        double[] totalMax = new double[] { -Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE };
        for (Long roid : roids) {
            Revision revision = session.get(roid, OldQuery.getDefault());
            Bounds bounds = revision.getBoundsMm();
            if (bounds.getMin().getX() == Double.MAX_VALUE || bounds.getMin().getY() == Double.MAX_VALUE || bounds.getMin().getZ() == Double.MAX_VALUE || bounds.getMax().getX() == -Double.MAX_VALUE || bounds.getMax().getY() == -Double.MAX_VALUE || bounds.getMax().getZ() == -Double.MAX_VALUE) {
                // Probably no objects or weird error, let's skip this one
                continue;
            }
            Vector3f min = bounds.getMin();
            Vector3f max = bounds.getMax();
            // }
            if (min.getX() < totalMin[0]) {
                totalMin[0] = min.getX();
            }
            if (min.getY() < totalMin[1]) {
                totalMin[1] = min.getY();
            }
            if (min.getZ() < totalMin[2]) {
                totalMin[2] = min.getZ();
            }
            if (max.getX() > totalMax[0]) {
                totalMax[0] = max.getX();
            }
            if (max.getY() > totalMax[1]) {
                totalMax[1] = max.getY();
            }
            if (max.getZ() > totalMax[2]) {
                totalMax[2] = max.getZ();
            }
        }
        SBounds sBounds = new SBounds();
        SVector3f sMin = new SVector3f();
        SVector3f sMax = new SVector3f();
        sBounds.setMin(sMin);
        sBounds.setMax(sMax);
        sMin.setX(totalMin[0]);
        sMin.setY(totalMin[1]);
        sMin.setZ(totalMin[2]);
        sMax.setX(totalMax[0]);
        sMax.setY(totalMax[1]);
        sMax.setZ(totalMax[2]);
        return sBounds;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SBounds(org.bimserver.interfaces.objects.SBounds) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SRevision(org.bimserver.interfaces.objects.SRevision) Revision(org.bimserver.models.store.Revision) CheckinRevision(org.bimserver.models.store.CheckinRevision) SExtendedDataAddedToRevision(org.bimserver.interfaces.objects.SExtendedDataAddedToRevision) DatabaseSession(org.bimserver.database.DatabaseSession) Bounds(org.bimserver.models.geometry.Bounds) SBounds(org.bimserver.interfaces.objects.SBounds) SVector3f(org.bimserver.interfaces.objects.SVector3f) Vector3f(org.bimserver.models.geometry.Vector3f) SVector3f(org.bimserver.interfaces.objects.SVector3f) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Aggregations

SBounds (org.bimserver.interfaces.objects.SBounds)11 SVector3f (org.bimserver.interfaces.objects.SVector3f)8 IOException (java.io.IOException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 MalformedURLException (java.net.MalformedURLException)7 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)7 MessagingException (javax.mail.MessagingException)7 AddressException (javax.mail.internet.AddressException)7 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)7 DatabaseSession (org.bimserver.database.DatabaseSession)7 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)7 Bounds (org.bimserver.models.geometry.Bounds)7 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)7 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)7 SerializerException (org.bimserver.plugins.serializers.SerializerException)7 PluginException (org.bimserver.shared.exceptions.PluginException)7 ServerException (org.bimserver.shared.exceptions.ServerException)7 ServiceException (org.bimserver.shared.exceptions.ServiceException)7 UserException (org.bimserver.shared.exceptions.UserException)7 BcfException (org.opensourcebim.bcf.BcfException)7