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();
}
}
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);
}
}
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);
}
}
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();
}
}
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();
}
}
Aggregations