use of org.bimserver.models.ifc2x3tc1.IfcObjectPlacement in project BIMserver by opensourceBIM.
the class IfcTools2D method placementToMatrix.
public static double[] placementToMatrix(IfcObjectPlacement objectPlacement) {
double[] matrix = Matrix.identity();
if (objectPlacement instanceof IfcLocalPlacement) {
IfcLocalPlacement ifcLocalPlacement = (IfcLocalPlacement) objectPlacement;
IfcAxis2Placement relativePlacement = ifcLocalPlacement.getRelativePlacement();
if (relativePlacement instanceof IfcAxis2Placement3D) {
IfcAxis2Placement3D ifcAxis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
matrix = placement3DToMatrix(ifcAxis2Placement3D);
}
IfcObjectPlacement relativeTo = ifcLocalPlacement.getPlacementRelTo();
if (relativeTo != null) {
double[] baseMatrix = placementToMatrix(relativeTo);
double[] rhs = matrix;
matrix = Matrix.identity();
Matrix.multiplyMM(matrix, 0, baseMatrix, 0, rhs, 0);
}
}
return matrix;
}
use of org.bimserver.models.ifc2x3tc1.IfcObjectPlacement in project BIMserver by opensourceBIM.
the class IfcTools2D method get2D.
public Area get2D(IfcProduct ifcProduct, double multiplierMillimeters) {
IfcObjectPlacement objectPlacement = ifcProduct.getObjectPlacement();
double[] productMatrix = placementToMatrix(objectPlacement);
// Matrix.dump(productMatrix);
IfcProductRepresentation representation = ifcProduct.getRepresentation();
if (representation == null) {
return null;
}
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
if ("Curve2D".equals(ifcRepresentation.getRepresentationType())) {
// Skip
} else {
if (ifcRepresentation instanceof IfcShapeRepresentation) {
IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
for (IfcRepresentationItem ifcRepresentationItem : ifcShapeRepresentation.getItems()) {
Area area = getArea(multiplierMillimeters, productMatrix, ifcRepresentationItem);
if (area != null && area.getPathIterator(null).isDone()) {
return area;
}
}
}
}
}
// Fall back to 3D geometry projected from the top
GeometryInfo geometry = ifcProduct.getGeometry();
if (geometry != null) {
GeometryData geometryData = geometry.getData();
if (geometryData != null) {
int[] indices = GeometryUtils.toIntegerArray(geometryData.getIndices());
float[] vertices = GeometryUtils.toFloatArray(geometryData.getVertices());
float[] matrix = GeometryUtils.toFloatArray(GeometryUtils.toDoubleArray(geometry.getTransformation()));
Area area = new Area();
for (int i = 0; i < indices.length; i += 3) {
int index1 = indices[i + 0];
int index2 = indices[i + 1];
int index3 = indices[i + 2];
float[] a = new float[] { vertices[index1 * 3], vertices[index1 * 3 + 1], vertices[index1 * 3 + 2] };
float[] b = new float[] { vertices[index2 * 3], vertices[index2 * 3 + 1], vertices[index2 * 3 + 2] };
float[] c = new float[] { vertices[index3 * 3], vertices[index3 * 3 + 1], vertices[index3 * 3 + 2] };
float[][] points = new float[][] { a, b, c };
// if (similar(a[2], b[2], c[2])) {
boolean first = true;
Path2D.Float path = new Path2D.Float();
for (int j = 0; j < 3; j++) {
float[] point = points[j];
float[] res = new float[4];
Matrix.multiplyMV(res, 0, matrix, 0, new float[] { point[0], point[1], point[2], 1 }, 0);
// * multiplierMillimeters
float x = (float) (res[0]);
// * multiplierMillimeters
float y = (float) (res[1]);
if (first) {
path.moveTo(x, y);
first = false;
} else {
path.lineTo(x, y);
}
}
path.closePath();
area.add(new Area(path));
// }
}
return area;
}
} else {
LOGGER.info("No geometry generated for " + ifcProduct);
}
return null;
}
use of org.bimserver.models.ifc2x3tc1.IfcObjectPlacement in project BIMserver by opensourceBIM.
the class IfcUtils method getAbsolutePosition.
/**
* Not finished, does not take into account the directions
*
* @param ifcObjectPlacement
* @return
* @throws PlacementNotImplementedException
*/
public static double[] getAbsolutePosition(IfcObjectPlacement ifcObjectPlacement) throws PlacementNotImplementedException {
if (ifcObjectPlacement instanceof IfcGridPlacement) {
throw new PlacementNotImplementedException("IfcGridPlacement has not been implemented");
} else if (ifcObjectPlacement instanceof IfcLocalPlacement) {
IfcLocalPlacement ifcLocalPlacement = (IfcLocalPlacement) ifcObjectPlacement;
IfcAxis2Placement relativePlacement = ifcLocalPlacement.getRelativePlacement();
if (relativePlacement instanceof IfcAxis2Placement2D) {
throw new PlacementNotImplementedException("IfcAxis2Placement2D has not been implemented");
} else if (relativePlacement instanceof IfcAxis2Placement3D) {
IfcAxis2Placement3D ifcAxis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
IfcObjectPlacement placementRelativeTo = ifcLocalPlacement.getPlacementRelTo();
if (placementRelativeTo == null) {
IfcCartesianPoint ifcCartesianPoint = ifcAxis2Placement3D.getLocation();
return new double[] { ifcCartesianPoint.getCoordinates().get(0), ifcCartesianPoint.getCoordinates().get(1), ifcCartesianPoint.getCoordinates().get(2) };
} else {
double[] relative = getAbsolutePosition(placementRelativeTo);
IfcCartesianPoint ifcCartesianPoint = ifcAxis2Placement3D.getLocation();
return new double[] { relative[0] + ifcCartesianPoint.getCoordinates().get(0), relative[1] + ifcCartesianPoint.getCoordinates().get(1), relative[2] + ifcCartesianPoint.getCoordinates().get(2) };
}
}
}
return new double[] { 0d, 0d, 0d };
}
use of org.bimserver.models.ifc2x3tc1.IfcObjectPlacement in project BIMserver by opensourceBIM.
the class TestMoveObject 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");
// Get the appropriate deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
// Checkin the file
bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
// Refresh project info
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
for (IfcFurnishingElement ifcFurnishingElement : model.getAllWithSubTypes(IfcFurnishingElement.class)) {
IfcObjectPlacement objectPlacement = ifcFurnishingElement.getObjectPlacement();
if (objectPlacement != null && objectPlacement instanceof IfcLocalPlacement) {
IfcLocalPlacement localPlacement = (IfcLocalPlacement) objectPlacement;
IfcAxis2Placement relativePlacement = localPlacement.getRelativePlacement();
if (relativePlacement != null) {
if (relativePlacement instanceof IfcAxis2Placement3D) {
IfcAxis2Placement3D axis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
IfcCartesianPoint location = axis2Placement3D.getLocation();
double newValue = location.getCoordinates().get(2) + 50;
System.out.println("Changing z value of " + ifcFurnishingElement.getName() + " from " + location.getCoordinates().get(2) + " to " + newValue);
location.getCoordinates().set(2, newValue);
}
}
}
}
long newRoid = model.commit("Moved all furniture 50 meters up");
SSerializerPluginConfiguration ifcSerializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
bimServerClient.download(newRoid, ifcSerializer.getOid(), Paths.get("movedf.ifc"));
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof AssertionError) {
throw (AssertionError) e;
}
fail(e.getMessage());
}
}
Aggregations