use of org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D 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.IfcAxis2Placement3D in project BIMserver by opensourceBIM.
the class AddFurniture method main.
public static void main(String[] args) {
try {
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
Deserializer deserializer = deserializerPlugin.createDeserializer(null);
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));
deserializer = deserializerPlugin.createDeserializer(null);
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
IfcModelInterface furnishingModel = DeserializerUtils.readFromFile(deserializer, Paths.get("test.ifc"));
model.fixOids(new IncrementingOidProvider());
long oid = model.getHighestOid();
IncrementingOidProvider oidProvider = new IncrementingOidProvider(oid + 1);
IfcFurnishingElement picknick = (IfcFurnishingElement) furnishingModel.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), model);
IfcProductDefinitionShape representation = (IfcProductDefinitionShape) picknick.getRepresentation();
IfcRepresentation surfaceModel = null;
IfcRepresentation boundingBox = null;
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
if (ifcShapeRepresentation.getRepresentationType().equals("SurfaceModel")) {
surfaceModel = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
} else if (ifcShapeRepresentation.getRepresentationType().equals("BoundingBox")) {
boundingBox = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
}
}
IfcOwnerHistory ownerHistory = null;
List<IfcOwnerHistory> all = model.getAll(IfcOwnerHistory.class);
if (all.size() > 0) {
ownerHistory = all.get(0);
}
for (IfcBuildingStorey ifcBuildingStorey : model.getAll(IfcBuildingStorey.class)) {
for (IfcRelDecomposes ifcRelDecomposes : ifcBuildingStorey.getIsDecomposedBy()) {
for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) {
if (ifcObjectDefinition instanceof IfcSpace) {
IfcSpace ifcSpace = (IfcSpace) ifcObjectDefinition;
// IfcProductDefinitionShape slabRepr = (IfcProductDefinitionShape) ifcSpace.getRepresentation();
// IfcBoundingBox box = null;
// for (IfcRepresentation representation2 : slabRepr.getRepresentations()) {
// IfcShapeRepresentation shapeRepresentation = (IfcShapeRepresentation)representation2;
// if (shapeRepresentation.getRepresentationType().equals("BoundingBox")) {
// for (IfcRepresentationItem i2 : shapeRepresentation.getItems()) {
// box = (IfcBoundingBox)i2;
// }
// }
// }
IfcFurnishingElement newFurnishing = model.create(IfcFurnishingElement.class, oidProvider);
IfcRelContainedInSpatialStructure containedInSpatialStructure2 = model.create(IfcRelContainedInSpatialStructure.class, oidProvider);
containedInSpatialStructure2.setRelatingStructure(ifcBuildingStorey);
containedInSpatialStructure2.getRelatedElements().add(newFurnishing);
newFurnishing.setName("Generated");
newFurnishing.setGlobalId("TEST");
newFurnishing.setOwnerHistory(ownerHistory);
IfcProductDefinitionShape definitionShape = model.create(IfcProductDefinitionShape.class, oidProvider);
newFurnishing.setRepresentation(definitionShape);
definitionShape.getRepresentations().add(boundingBox);
definitionShape.getRepresentations().add(surfaceModel);
IfcLocalPlacement localPlacement = model.create(IfcLocalPlacement.class, oidProvider);
localPlacement.setPlacementRelTo(ifcSpace.getObjectPlacement());
IfcAxis2Placement3D axis2Placement3D = model.create(IfcAxis2Placement3D.class, oidProvider);
localPlacement.setRelativePlacement(axis2Placement3D);
IfcCartesianPoint pos = model.create(IfcCartesianPoint.class, oidProvider);
pos.getCoordinates().add(-3d);
pos.getCoordinates().add(+0.5d);
pos.getCoordinates().add(0d);
axis2Placement3D.setLocation(pos);
newFurnishing.setObjectPlacement(localPlacement);
}
}
}
}
model.resetExpressIds();
SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
Serializer serializer = serializerPlugin.createSerializer(null);
serializer.init(model, null, true);
SerializerUtils.writeToFile(serializer, Paths.get("withfurn.ifc"));
} catch (PluginException e) {
e.printStackTrace();
} catch (DeserializeException e) {
e.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
} catch (SerializerException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D in project BIMserver by opensourceBIM.
the class TestBigModelEmf method createFurnishing.
private void createFurnishing(RichIfcModel richIfcModel, IfcRepresentationContext representationContext, int number, IfcSpace ifcSpace, IfcLocalPlacement spacePlacement) throws IfcModelInterfaceException {
IfcFurnishingElement furnishing = richIfcModel.create(IfcFurnishingElement.class);
furnishing.setName("Furnishing " + number);
IfcLocalPlacement furnishingPlacement = richIfcModel.create(IfcLocalPlacement.class);
furnishingPlacement.setPlacementRelTo(spacePlacement);
IfcAxis2Placement3D furnitureAxisPlacement = richIfcModel.create(IfcAxis2Placement3D.class);
furnitureAxisPlacement.setLocation(richIfcModel.createIfcCartesianPoint(500, 500, 2));
furnishingPlacement.setRelativePlacement(furnitureAxisPlacement);
furnishing.setObjectPlacement(furnishingPlacement);
furnishing.setRepresentation(richIfcModel.createRectangularExtrusionProductRepresentation(4000, 4000, 1200));
richIfcModel.addContains(ifcSpace, furnishing);
}
use of org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D in project BIMserver by opensourceBIM.
the class IfcTools2D method getArea.
private Area getArea(double multiplierMillimeters, double[] productMatrix, IfcRepresentationItem ifcRepresentationItem) {
if (ifcRepresentationItem instanceof IfcExtrudedAreaSolid) {
IfcExtrudedAreaSolid ifcExtrudedAreaSolid = (IfcExtrudedAreaSolid) ifcRepresentationItem;
IfcAxis2Placement3D position = ifcExtrudedAreaSolid.getPosition();
// 1 0 0 0 <- 3de argument
// 0 1 0 0 <- cross product van 2 en 3 (levert ortogonale vector op)
// 0 0 1 0 <- 2st argument
// 5 0 0 1 <- 1st argument
double[] matrix = placement3DToMatrix(position);
if (productMatrix != null) {
double[] rhs = matrix;
matrix = Matrix.identity();
Matrix.multiplyMM(matrix, 0, productMatrix, 0, rhs, 0);
}
IfcDirection extrudedDirection = ifcExtrudedAreaSolid.getExtrudedDirection();
// TODO do something with this
IfcProfileDef ifcProfileDef = ifcExtrudedAreaSolid.getSweptArea();
if (ifcProfileDef instanceof IfcArbitraryProfileDefWithVoids) {
IfcArbitraryProfileDefWithVoids ifcArbitraryProfileDefWithVoids = (IfcArbitraryProfileDefWithVoids) ifcProfileDef;
IfcCurve outerCurve = ifcArbitraryProfileDefWithVoids.getOuterCurve();
Path2D outerPath = null;
if (outerCurve instanceof IfcPolyline) {
outerPath = curveToPath(matrix, outerCurve, multiplierMillimeters);
} else {
storeUnimplemented(outerCurve);
}
if (outerPath != null) {
Area area = new Area(outerPath);
for (IfcCurve innerCurve : ifcArbitraryProfileDefWithVoids.getInnerCurves()) {
Path2D.Float innerPath = curveToPath(matrix, innerCurve, multiplierMillimeters);
if (innerPath != null) {
area.subtract(new Area(innerPath));
}
}
return area;
}
} else if (ifcProfileDef instanceof IfcArbitraryClosedProfileDef) {
IfcArbitraryClosedProfileDef ifcArbitraryClosedProfileDef = (IfcArbitraryClosedProfileDef) ifcProfileDef;
Path2D.Float path2d = new Path2D.Float();
IfcCurve outerCurve = ifcArbitraryClosedProfileDef.getOuterCurve();
boolean first = true;
if (outerCurve instanceof IfcPolyline) {
IfcPolyline ifcPolyline = (IfcPolyline) outerCurve;
double[] res = new double[4];
int i = 0;
for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
EList<Double> coords = cartesianPoint.getCoordinates();
Matrix.multiplyMV(res, 0, matrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
if (first) {
path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
first = false;
} else {
if (i > 1) {
}
path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
}
i++;
}
path2d.closePath();
return new Area(path2d);
} else if (outerCurve instanceof IfcCompositeCurve) {
IfcCompositeCurve ifcCompositeCurve = (IfcCompositeCurve) outerCurve;
for (IfcCompositeCurveSegment ifcCompositeCurveSegment : ifcCompositeCurve.getSegments()) {
IfcCurve curve = ifcCompositeCurveSegment.getParentCurve();
if (curve instanceof IfcPolyline) {
IfcPolyline ifcPolyline = (IfcPolyline) curve;
double[] res = new double[4];
for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
EList<Double> coords = cartesianPoint.getCoordinates();
Matrix.multiplyMV(res, 0, matrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
if (first) {
path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
first = false;
} else {
path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
}
}
} else if (curve instanceof IfcTrimmedCurve) {
storeUnimplemented(curve);
} else {
storeUnimplemented(curve);
}
}
try {
path2d.closePath();
return new Area(path2d);
} catch (Exception e) {
//
}
}
} else if (ifcProfileDef instanceof IfcRectangleProfileDef) {
IfcRectangleProfileDef ifcRectangleProfileDef = (IfcRectangleProfileDef) ifcProfileDef;
double[] min = new double[] { ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(0) - ifcRectangleProfileDef.getXDim() / 2, ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(1) - ifcRectangleProfileDef.getYDim() / 2, 0, 1 };
double[] max = new double[] { ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(0) + ifcRectangleProfileDef.getXDim() / 2, ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(1) + ifcRectangleProfileDef.getYDim() / 2, 0, 1 };
Cube cube = new Cube(min, max);
cube.transform(matrix);
double[] transformedMin = cube.getMin();
double[] transformedMax = cube.getMax();
Path2D.Float path2d = new Path2D.Float();
path2d.moveTo(transformedMin[0] * multiplierMillimeters, transformedMin[1] * multiplierMillimeters);
path2d.lineTo(transformedMax[0] * multiplierMillimeters, transformedMin[1] * multiplierMillimeters);
path2d.lineTo(transformedMax[0] * multiplierMillimeters, transformedMax[1] * multiplierMillimeters);
path2d.lineTo(transformedMin[0] * multiplierMillimeters, transformedMax[1] * multiplierMillimeters);
path2d.lineTo(transformedMin[0] * multiplierMillimeters, transformedMin[1] * multiplierMillimeters);
path2d.closePath();
return new Area(path2d);
} else {
storeUnimplemented(ifcProfileDef);
}
} else if (ifcRepresentationItem instanceof IfcPolyline) {
IfcPolyline ifcPolyline = (IfcPolyline) ifcRepresentationItem;
double[] res = new double[4];
Path2D.Float path2d = new Path2D.Float();
boolean first = true;
for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
EList<Double> coords = cartesianPoint.getCoordinates();
Matrix.multiplyMV(res, 0, productMatrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
if (first) {
path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
first = false;
} else {
path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
}
}
path2d.closePath();
return new Area(path2d);
} else {
storeUnimplemented(ifcRepresentationItem);
}
return null;
}
use of org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D 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 };
}
Aggregations