use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class AbstractGeometrySerializer method calculateExtents.
private void calculateExtents(String id, IfcProduct ifcObject) throws RenderEngineException, SerializerException {
if (!geometryExtents.containsKey(id)) {
geometryExtents.put(id, new Extends());
}
Extends extents = geometryExtents.get(id);
GeometryInfo geometryInfo = ifcObject.getGeometry();
if (geometryInfo != null) {
extents.integrate(geometryInfo);
sceneExtends.addToMinExtents(extents.min);
sceneExtends.addToMaxExtents(extents.max);
}
}
use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class GetVolumes method start.
private void start() {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
try (BimServerClient bimServerClient = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = bimServerClient.getServiceInterface().getProjectsByName("K06K09").get(0);
ClientIfcModel model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false, true);
for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
if (ifcProduct.eClass().getName().equals("IfcStair")) {
GeometryInfo geometryInfo = ifcProduct.getGeometry();
if (geometryInfo != null) {
System.out.println(ifcProduct.getName() + ": " + geometryInfo.getVolume());
}
}
}
}
} catch (BimServerClientException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
use of org.bimserver.models.geometry.GeometryInfo in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer method generateSceneAndBody.
private void generateSceneAndBody() throws SerializerException {
int totalBodyByteLength = 0;
int totalIndicesByteLength = 0;
int totalVerticesByteLength = 0;
int totalNormalsByteLength = 0;
int totalColorsByteLength = 0;
int maxIndexValues = 16389;
for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
GeometryInfo geometryInfo = ifcProduct.getGeometry();
if (!ifcProduct.eClass().getName().equals("IfcOpeningElement") && geometryInfo != null && geometryInfo.getData().getVertices().length > 0) {
GeometryData data = geometryInfo.getData();
int nrIndicesBytes = data.getIndices().length;
totalIndicesByteLength += nrIndicesBytes / 2;
if (nrIndicesBytes > 4 * maxIndexValues) {
int nrIndices = nrIndicesBytes / 4;
totalVerticesByteLength += nrIndices * 3 * 4;
totalNormalsByteLength += nrIndices * 3 * 4;
if (data.getMaterials() != null) {
totalColorsByteLength += nrIndices * 4 * 4;
}
} else {
totalVerticesByteLength += data.getVertices().length;
totalNormalsByteLength += data.getNormals().length;
if (data.getMaterials() != null) {
totalColorsByteLength += data.getMaterials().length;
}
}
}
}
totalBodyByteLength = totalIndicesByteLength + totalVerticesByteLength + totalNormalsByteLength + totalColorsByteLength;
body = ByteBuffer.allocate(totalBodyByteLength + materialColorFragmentShaderBytes.length + materialColorVertexShaderBytes.length + vertexColorFragmentShaderBytes.length + vertexColorVertexShaderBytes.length);
body.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer newIndicesBuffer = ByteBuffer.allocate(totalIndicesByteLength);
newIndicesBuffer.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer newVerticesBuffer = ByteBuffer.allocate(totalVerticesByteLength);
newVerticesBuffer.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer newNormalsBuffer = ByteBuffer.allocate(totalNormalsByteLength);
newNormalsBuffer.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer newColorsBuffer = ByteBuffer.allocate(totalColorsByteLength);
newColorsBuffer.order(ByteOrder.LITTLE_ENDIAN);
String indicesBufferView = createBufferView(totalIndicesByteLength, 0, ELEMENT_ARRAY_BUFFER);
String verticesBufferView = createBufferView(totalVerticesByteLength, totalIndicesByteLength, ARRAY_BUFFER);
String normalsBufferView = createBufferView(totalNormalsByteLength, totalIndicesByteLength + totalVerticesByteLength, ARRAY_BUFFER);
String colorsBufferView = null;
scenesNode.set("defaultScene", createDefaultScene());
createModelNode();
for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
GeometryInfo geometryInfo = ifcProduct.getGeometry();
if (!ifcProduct.eClass().getName().equals("IfcOpeningElement") && geometryInfo != null) {
ByteBuffer matrixByteBuffer = ByteBuffer.wrap(ifcProduct.getGeometry().getTransformation());
matrixByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
DoubleBuffer doubleBuffer = matrixByteBuffer.asDoubleBuffer();
float[] matrix = new float[16];
for (int i = 0; i < doubleBuffer.capacity(); i++) {
matrix[i] = (float) doubleBuffer.get();
}
updateExtends(geometryInfo, matrix);
}
}
float[] offsets = getOffsets();
// This will "normalize" the model by moving it's axis-aligned bounding box center to the 0-point. This will always be the wrong position, but at least the building will be close to the 0-point
modelTranslation.add(-offsets[0]);
modelTranslation.add(-offsets[1]);
modelTranslation.add(-offsets[2]);
for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
GeometryInfo geometryInfo = ifcProduct.getGeometry();
if (!ifcProduct.eClass().getName().equals("IfcOpeningElement") && geometryInfo != null && geometryInfo.getData().getVertices().length > 0) {
int startPositionIndices = newIndicesBuffer.position();
int startPositionVertices = newVerticesBuffer.position();
int startPositionNormals = newNormalsBuffer.position();
int startPositionColors = newColorsBuffer.position();
GeometryData data = geometryInfo.getData();
ByteBuffer indicesBuffer = ByteBuffer.wrap(data.getIndices());
indicesBuffer.order(ByteOrder.LITTLE_ENDIAN);
IntBuffer indicesIntBuffer = indicesBuffer.asIntBuffer();
ByteBuffer verticesBuffer = ByteBuffer.wrap(data.getVertices());
verticesBuffer.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer verticesFloatBuffer = verticesBuffer.asFloatBuffer();
ByteBuffer normalsBuffer = ByteBuffer.wrap(data.getNormals());
normalsBuffer.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer normalsFloatBuffer = normalsBuffer.asFloatBuffer();
FloatBuffer materialsFloatBuffer = null;
if (data.getMaterials() != null) {
ByteBuffer materialsBuffer = ByteBuffer.wrap(data.getMaterials());
materialsBuffer.order(ByteOrder.LITTLE_ENDIAN);
materialsFloatBuffer = materialsBuffer.asFloatBuffer();
}
if (data.getIndices().length > 4 * maxIndexValues) {
int totalNrIndices = indicesIntBuffer.capacity();
int nrParts = (totalNrIndices + maxIndexValues - 1) / maxIndexValues;
ArrayNode primitivesNode = OBJECT_MAPPER.createArrayNode();
for (int part = 0; part < nrParts; part++) {
startPositionIndices = newIndicesBuffer.position();
startPositionVertices = newVerticesBuffer.position();
startPositionNormals = newNormalsBuffer.position();
startPositionColors = newColorsBuffer.position();
short indexCounter = 0;
int upto = Math.min((part + 1) * maxIndexValues, totalNrIndices);
for (int i = part * maxIndexValues; i < upto; i++) {
newIndicesBuffer.putShort(indexCounter++);
}
int nrVertices = upto - part * maxIndexValues;
for (int i = part * maxIndexValues; i < upto; i += 3) {
int oldIndex1 = indicesIntBuffer.get(i);
int oldIndex2 = indicesIntBuffer.get(i + 1);
int oldIndex3 = indicesIntBuffer.get(i + 2);
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex1 * 3));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex1 * 3 + 1));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex1 * 3 + 2));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex2 * 3));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex2 * 3 + 1));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex2 * 3 + 2));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex3 * 3));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex3 * 3 + 1));
newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex3 * 3 + 2));
}
for (int i = part * maxIndexValues; i < upto; i += 3) {
int oldIndex1 = indicesIntBuffer.get(i);
int oldIndex2 = indicesIntBuffer.get(i + 1);
int oldIndex3 = indicesIntBuffer.get(i + 2);
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex1 * 3));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex1 * 3 + 1));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex1 * 3 + 2));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex2 * 3));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex2 * 3 + 1));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex2 * 3 + 2));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex3 * 3));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex3 * 3 + 1));
newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex3 * 3 + 2));
}
if (materialsFloatBuffer != null) {
for (int i = part * maxIndexValues; i < upto; i += 3) {
int oldIndex1 = indicesIntBuffer.get(i);
int oldIndex2 = indicesIntBuffer.get(i + 1);
int oldIndex3 = indicesIntBuffer.get(i + 2);
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4 + 1));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4 + 2));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4 + 3));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4 + 1));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4 + 2));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4 + 3));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4 + 1));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4 + 2));
newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4 + 3));
}
}
ObjectNode primitiveNode = OBJECT_MAPPER.createObjectNode();
String indicesAccessor = addIndicesAccessor(ifcProduct, indicesBufferView, startPositionIndices, nrVertices / 3);
String verticesAccessor = addVerticesAccessor(ifcProduct, verticesBufferView, startPositionVertices, nrVertices);
String normalsAccessor = addNormalsAccessor(ifcProduct, normalsBufferView, startPositionNormals, nrVertices);
String colorAccessor = null;
if (data.getMaterials() != null) {
if (colorsBufferView == null) {
colorsBufferView = createBufferView(totalColorsByteLength, totalIndicesByteLength + totalVerticesByteLength + totalNormalsByteLength, ARRAY_BUFFER);
}
colorAccessor = addColorsAccessor(ifcProduct, colorsBufferView, startPositionColors, nrVertices * 4 / 3);
}
primitivesNode.add(primitiveNode);
primitiveNode.put("indices", indicesAccessor);
primitiveNode.put("mode", TRIANGLES);
ObjectNode attributesNode = OBJECT_MAPPER.createObjectNode();
primitiveNode.set("attributes", attributesNode);
attributesNode.put("NORMAL", normalsAccessor);
attributesNode.put("POSITION", verticesAccessor);
if (colorAccessor != null) {
attributesNode.put("COLOR", colorAccessor);
primitiveNode.put("material", VERTEX_COLOR_MATERIAL);
} else {
primitiveNode.put("material", createOrGetMaterial(ifcProduct.eClass().getName(), IfcColors.getDefaultColor(ifcProduct.eClass().getName())));
}
}
String meshName = addMesh(ifcProduct, primitivesNode);
String nodeName = addNode(meshName, ifcProduct);
translationChildrenNode.add(nodeName);
} else {
for (int i = 0; i < indicesIntBuffer.capacity(); i++) {
int index = indicesIntBuffer.get(i);
if (index > Short.MAX_VALUE) {
throw new SerializerException("Index too large to store as short " + index);
}
newIndicesBuffer.putShort((short) (index));
}
newVerticesBuffer.put(data.getVertices());
newNormalsBuffer.put(data.getNormals());
if (data.getMaterials() != null) {
newColorsBuffer.put(data.getMaterials());
}
int totalNrIndices = indicesIntBuffer.capacity();
ArrayNode primitivesNode = OBJECT_MAPPER.createArrayNode();
ObjectNode primitiveNode = OBJECT_MAPPER.createObjectNode();
String indicesAccessor = addIndicesAccessor(ifcProduct, indicesBufferView, startPositionIndices, totalNrIndices);
String verticesAccessor = addVerticesAccessor(ifcProduct, verticesBufferView, startPositionVertices, data.getVertices().length / 4);
String normalsAccessor = addNormalsAccessor(ifcProduct, normalsBufferView, startPositionNormals, data.getNormals().length / 4);
String colorAccessor = null;
if (data.getMaterials() != null) {
if (colorsBufferView == null) {
colorsBufferView = createBufferView(totalColorsByteLength, totalIndicesByteLength + totalVerticesByteLength + totalNormalsByteLength, ARRAY_BUFFER);
}
colorAccessor = addColorsAccessor(ifcProduct, colorsBufferView, startPositionColors, data.getVertices().length / 4);
}
primitivesNode.add(primitiveNode);
primitiveNode.put("indices", indicesAccessor);
primitiveNode.put("mode", TRIANGLES);
ObjectNode attributesNode = OBJECT_MAPPER.createObjectNode();
primitiveNode.set("attributes", attributesNode);
attributesNode.put("NORMAL", normalsAccessor);
attributesNode.put("POSITION", verticesAccessor);
if (colorAccessor != null) {
attributesNode.put("COLOR", colorAccessor);
primitiveNode.put("material", VERTEX_COLOR_MATERIAL);
} else {
primitiveNode.put("material", createOrGetMaterial(ifcProduct.eClass().getName(), IfcColors.getDefaultColor(ifcProduct.eClass().getName())));
}
String meshName = addMesh(ifcProduct, primitivesNode);
String nodeName = addNode(meshName, ifcProduct);
translationChildrenNode.add(nodeName);
}
}
}
if (newIndicesBuffer.position() != newIndicesBuffer.capacity()) {
throw new SerializerException("Not all space used");
}
if (newVerticesBuffer.position() != newVerticesBuffer.capacity()) {
throw new SerializerException("Not all space used");
}
if (newNormalsBuffer.position() != newNormalsBuffer.capacity()) {
throw new SerializerException("Not all space used");
}
if (newColorsBuffer.position() != newColorsBuffer.capacity()) {
throw new SerializerException("Not all space used");
}
newIndicesBuffer.position(0);
newVerticesBuffer.position(0);
newNormalsBuffer.position(0);
newColorsBuffer.position(0);
body.put(newIndicesBuffer);
body.put(newVerticesBuffer);
body.put(newNormalsBuffer);
body.put(newColorsBuffer);
String vertexColorFragmentShaderBufferViewName = createBufferView(vertexColorFragmentShaderBytes.length, body.position());
body.put(vertexColorFragmentShaderBytes);
String vertexColorVertexShaderBufferViewName = createBufferView(vertexColorVertexShaderBytes.length, body.position());
body.put(vertexColorVertexShaderBytes);
String materialColorFragmentShaderBufferViewName = createBufferView(materialColorFragmentShaderBytes.length, body.position());
body.put(materialColorFragmentShaderBytes);
String materialColorVertexShaderBufferViewName = createBufferView(materialColorVertexShaderBytes.length, body.position());
body.put(materialColorVertexShaderBytes);
gltfNode.set("animations", createAnimations());
gltfNode.set("asset", createAsset());
gltfNode.set("programs", createPrograms());
gltfNode.put("scene", "defaultScene");
gltfNode.set("skins", createSkins());
gltfNode.set("techniques", createTechniques());
createVertexColorShaders(vertexColorFragmentShaderBufferViewName, vertexColorVertexShaderBufferViewName);
createMaterialColorShaders(materialColorFragmentShaderBufferViewName, materialColorVertexShaderBufferViewName);
addBuffer("binary_glTF", "arraybuffer", body.capacity());
ArrayNode extensions = OBJECT_MAPPER.createArrayNode();
extensions.add("KHR_binary_glTF");
gltfNode.set("extensionsUsed", extensions);
}
use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.
the class OfflineGeometryGenerator method generateGeometry.
private GenerateGeometryResult generateGeometry(IfcProduct ifcProduct) {
GenerateGeometryResult generateGeometryResult = new GenerateGeometryResult();
if (ifcProduct.getRepresentation() != null && ifcProduct.getRepresentation().getRepresentations().size() != 0) {
try {
RenderEngineInstance renderEngineInstance = renderEngineModel.getInstanceFromExpressId(ifcProduct.getExpressId());
RenderEngineGeometry geometry = renderEngineInstance.generateGeometry();
boolean translate = true;
if (geometry != null && geometry.getNrIndices() > 0) {
GeometryInfo geometryInfo = null;
geometryInfo = GeometryFactory.eINSTANCE.createGeometryInfo();
Bounds bounds = GeometryFactory.eINSTANCE.createBounds();
bounds.setMin(createVector3f(model.getPackageMetaData(), model, Double.POSITIVE_INFINITY));
bounds.setMax(createVector3f(model.getPackageMetaData(), model, -Double.POSITIVE_INFINITY));
geometryInfo.setBounds(bounds);
try {
ObjectNode additionalData = renderEngineInstance.getAdditionalData();
if (additionalData != null) {
geometryInfo.setAdditionalData(additionalData.toString());
if (additionalData.has("TOTAL_SURFACE_AREA")) {
geometryInfo.setArea(additionalData.get("TOTAL_SURFACE_AREA").asDouble());
}
if (additionalData.has("TOTAL_SHAPE_VOLUME")) {
geometryInfo.setVolume(additionalData.get("TOTAL_SHAPE_VOLUME").asDouble());
}
}
// EStructuralFeature guidFeature = ifcProduct.eClass().getEStructuralFeature("GlobalId");
// String guid = (String) ifcProduct.eGet(guidFeature);
// System.out.println(guid + ": " + "Area: " + area + ", Volume: " + volume);
} catch (UnsupportedOperationException e) {
}
GeometryData geometryData = null;
geometryData = GeometryFactory.eINSTANCE.createGeometryData();
geometryData.setIndices(createBuffer(geometry.getIndices()));
geometryData.setVertices(createBuffer(geometry.getVertices()));
geometryData.setColorsQuantized(createBuffer(geometry.getMaterialIndices()));
geometryData.setNormals(createBuffer(geometry.getNormals()));
geometryInfo.setPrimitiveCount(geometry.getNrIndices() / 3);
// if (geometry.getMaterialIndices() != null && geometry.getMaterialIndices().length > 0) {
// boolean hasMaterial = false;
// float[] vertex_colors = new float[geometry.getVertices().length / 3 * 4];
// for (int i = 0; i < geometry.getMaterialIndices().length; ++i) {
// int c = geometry.getMaterialIndices()[i];
// for (int j = 0; j < 3; ++j) {
// int k = geometry.getIndices()[i * 3 + j];
// if (c > -1) {
// hasMaterial = true;
// for (int l = 0; l < 4; ++l) {
// vertex_colors[4 * k + l] = geometry.getMaterials()[4 * c + l];
// }
// }
// }
// }
// if (hasMaterial) {
// geometryData.setColorsQuantized(vertex_colors));
// }
// }
double[] tranformationMatrix = new double[16];
Matrix.setIdentityM(tranformationMatrix, 0);
if (translate && renderEngineInstance.getTransformationMatrix() != null) {
tranformationMatrix = renderEngineInstance.getTransformationMatrix();
}
ByteBuffer indices = geometry.getIndices().order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < geometry.getNrIndices(); i++) {
processExtends(geometryInfo, tranformationMatrix, geometry.getVertices(), indices.getInt(i * 3), generateGeometryResult);
}
geometryInfo.setData(geometryData);
// long length = (geometryData.getIndices() != null ? geometryData.getIndices().length : 0) +
// (geometryData.getVertices() != null ? geometryData.getVertices().length : 0) +
// (geometryData.getNormals() != null ? geometryData.getNormals().length : 0) +
// (geometryData.getMaterials() != null ? geometryData.getMaterials().length : 0) +
// (geometryData.getMaterialIndices() != null ? geometryData.getMaterialIndices().length : 0);
setTransformationMatrix(geometryInfo, tranformationMatrix);
int hash = hash(geometryData);
if (hashes.containsKey(hash)) {
geometryInfo.setData(hashes.get(hash));
} else {
hashes.put(hash, geometryData);
}
ifcProduct.setGeometry(geometryInfo);
}
} catch (EntityNotFoundException e) {
e.printStackTrace();
// As soon as we find a representation that is not Curve2D, then we should show a "INFO" message in the log to indicate there could be something wrong
boolean ignoreNotFound = true;
// }
if (!ignoreNotFound) {
LOGGER.info("Entity not found " + ifcProduct.eClass().getName() + " " + ifcProduct.getExpressId() + "/" + ifcProduct.getOid());
}
} catch (BimserverDatabaseException | RenderEngineException e) {
LOGGER.error("", e);
} catch (IfcModelInterfaceException e) {
LOGGER.error("", e);
}
}
return generateGeometryResult;
}
use of org.bimserver.models.geometry.GeometryInfo 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().getData());
float[] vertices = GeometryUtils.toFloatArray(geometryData.getVertices().getData());
double[] matrix = 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 double[] { point[0], point[1], point[2], 1 }, 0);
float x = (float) (res[0] * multiplierMillimeters);
float y = (float) (res[1] * multiplierMillimeters);
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;
}
Aggregations