diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/actions/ImportBIMDataAction.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/actions/ImportBIMDataAction.java index bf47538..e249b2b 100644 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/actions/ImportBIMDataAction.java +++ b/src/org/openstreetmap/josm/plugins/indoorhelper/io/actions/ImportBIMDataAction.java @@ -16,7 +16,7 @@ */ public class ImportBIMDataAction extends JosmAction { - private ImportEventListener importListener; + private final ImportEventListener importListener; public ImportBIMDataAction(ImportEventListener listener) { super(tr("Import BIM File"), "dialogs/bim_small", null, null, false); diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/controller/ImportDataController.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/controller/ImportDataController.java index 5b8853b..50ec3b2 100644 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/controller/ImportDataController.java +++ b/src/org/openstreetmap/josm/plugins/indoorhelper/io/controller/ImportDataController.java @@ -1,10 +1,6 @@ // License: AGPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.indoorhelper.io.controller; -import org.openstreetmap.josm.plugins.indoorhelper.io.actions.ImportBIMDataAction; -import org.openstreetmap.josm.plugins.indoorhelper.io.model.ImportDataModel; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.BIMtoOSMParser; -import org.openstreetmap.josm.plugins.indoorhelper.io.renderer.ImportDataRenderer; import org.openstreetmap.josm.actions.JosmAction; import org.openstreetmap.josm.data.Preferences; import org.openstreetmap.josm.data.osm.DataSet; @@ -13,6 +9,8 @@ import org.openstreetmap.josm.gui.MapFrame; import org.openstreetmap.josm.gui.widgets.JMultilineLabel; import org.openstreetmap.josm.gui.widgets.UrlLabel; +import org.openstreetmap.josm.plugins.indoorhelper.io.actions.ImportBIMDataAction; +import org.openstreetmap.josm.plugins.indoorhelper.io.renderer.ImportDataRenderer; import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.tools.GBC; import org.openstreetmap.josm.tools.ImageProvider; @@ -37,11 +35,10 @@ import static org.openstreetmap.josm.tools.I18n.tr; /** - * Import data controller class handles communication between {@link ImportDataModel} and import views. + * Import data controller handles import actions */ public class ImportDataController implements ImportEventListener { - private final ImportDataModel model; private String importedFilepath; private final String pluginDir = Preferences.main().getPluginsDirectory().toString(); @@ -52,7 +49,6 @@ public class ImportDataController implements ImportEventListener { private final String[] BIMResources = {"IFC2X3_TC1.exp", "IFC4.exp"}; public ImportDataController() { - model = new ImportDataModel(); JosmAction importBIMAction = new ImportBIMDataAction(this); MainMenu.add(MainApplication.getMenu().fileMenu, importBIMAction, false, 21); @@ -66,6 +62,7 @@ public ImportDataController() { } // export resource files used by BuildingSMARTLibrary from jar to file system + // TODO should be done by BIMtoOSM lib try { exportBIMResource(); } catch (Exception e) { @@ -89,14 +86,15 @@ private void importBIMData(String filepath) { initProgressProcess(); progressFrame.setVisible(true); new Thread(() -> { - new BIMtoOSMParser(this, pluginDir + "/indoorhelper/").parse(importedFilepath); + // TODO replace bei BIMtoOSM lib + //new BIMtoOSMParser(this, pluginDir + "/indoorhelper/").parse(importedFilepath); progressFrame.setVisible(false); }).start(); } @Override + // TODO replace DataSet class by data set class form BIMtoOSM public void onDataParsed(DataSet ds) { - model.setImportData(ds); String layerName = String.format("BIMObject%2d", MainApplication.getLayerManager().getLayers().size()); if (importedFilepath != null) { String[] parts = importedFilepath.split(File.separator.equals("\\") ? "\\\\" : "/"); diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/model/BIMtoOSMCatalog.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/model/BIMtoOSMCatalog.java deleted file mode 100644 index 6a5d472..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/model/BIMtoOSMCatalog.java +++ /dev/null @@ -1,114 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.model; - -import java.util.ArrayList; -import java.util.List; - -/** - * Class holding information of BIM to OSM translation schema - */ -public class BIMtoOSMCatalog { - /** - * Returns all BIM tags representing a wall - * - * @return List of {@link BIMObject}s representing a wall - */ - public static List getWallTags() { - ArrayList wallTags = new ArrayList<>(); - wallTags.add(BIMObject.IfcWall.toString()); - wallTags.add(BIMObject.IfcWallStandardCase.toString()); - wallTags.add(BIMObject.IfcWallElementedCase.toString()); - return wallTags; - } - - /** - * Returns all BIM tags representing an area - * - * @return List of {@link BIMObject}s representing an area - */ - public static List getAreaTags() { - ArrayList areaTags = new ArrayList<>(); - areaTags.add(BIMObject.IfcSlab.toString()); - areaTags.add(BIMObject.IfcSlabStandardCase.toString()); - areaTags.add(BIMObject.IfcSlabElementedCase.toString()); - return areaTags; - } - - /** - * Returns all BIM tags representing a column - * - * @return List of {@link BIMObject}s representing a column - */ - public static List getColumnTags() { - ArrayList colTags = new ArrayList<>(); - colTags.add(BIMObject.IfcColumn.toString()); - return colTags; - } - - /** - * Returns all BIM tags representing a door - * - * @return List of {@link BIMObject}s representing a door - */ - public static List getDoorTags() { - ArrayList doorTags = new ArrayList<>(); - doorTags.add(BIMObject.IfcDoor.toString()); - doorTags.add(BIMObject.IfcDoorStandardCase.toString()); - return doorTags; - } - - /** - * Returns all BIM tags representing a window - * - * @return List of {@link BIMObject}s representing a window - */ - public static List getWindowTags() { - ArrayList stairTags = new ArrayList<>(); - stairTags.add(BIMObject.IfcWindow.toString()); - return stairTags; - } - - /** - * Returns all BIM tags representing a stair - * - * @return List of {@link BIMObject}s representing a stair - */ - public static List getStairTags() { - ArrayList stairTags = new ArrayList<>(); - stairTags.add(BIMObject.IfcStair.toString()); - return stairTags; - } - - /** - * Returns all BIM tags representing a RelVoidsElement - * - * @return List of {@link BIMObject}s representing a RelVoidsElement - */ - public static List getRelVoidsElementTags() { - ArrayList relVoidsTags = new ArrayList<>(); - relVoidsTags.add(BIMObject.IfcRelVoidsElement.toString()); - return relVoidsTags; - } - - /** - * Get IfcSite tag - * - * @return List of IfcSite tags - */ - public static List getIFCSITETags() { - ArrayList ifcSiteTags = new ArrayList<>(); - ifcSiteTags.add(BIMObject.IfcSite.toString()); - return ifcSiteTags; - } - - /** - * Relevant BIM objects - * - * @author rebsc - */ - public enum BIMObject { - IfcSlab, IfcSlabStandardCase, IfcSlabElementedCase, IfcSlabType, IfcWall, IfcWallStandardCase, - IfcWallElementedCase, IfcWallType, IfcColumn, IfcColumnType, IfcDoor, IfcDoorStandardCase, IfcStair, - IfcRelVoidsElement, IfcWindow, IfcSite - } -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/model/ImportDataModel.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/model/ImportDataModel.java deleted file mode 100644 index e6d13a6..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/model/ImportDataModel.java +++ /dev/null @@ -1,22 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.model; - -import org.openstreetmap.josm.data.osm.DataSet; - -/** - * Class holding imported data - */ -public class ImportDataModel { - - private DataSet ds; - - public void setImportData(DataSet data) { - ds = data; - } - - public DataSet getData() { - return ds; - } - - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/optimizer/InputOptimizer.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/optimizer/InputOptimizer.java deleted file mode 100644 index fe83b70..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/optimizer/InputOptimizer.java +++ /dev/null @@ -1,73 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.optimizer; - -import org.openstreetmap.josm.tools.Logging; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.Scanner; - -/** - * Class providing methods to optimize IFC files before loading them - */ -public class InputOptimizer { - - /** - * Optimizes an ifc file following the given config parameters - * - * @param ifcFilepath to file to optimize - * @return optimized file as {@link File} - * @throws IOException - */ - public static File optimizeIfcFile(Configuration config, String ifcFilepath) throws IOException { - // TODO Maybe find a better way than creating a temporary file... - File tempFile = File.createTempFile(getFileName(ifcFilepath) + "_optimized", ".ifc"); - tempFile.deleteOnExit(); - - if (config.REMOVE_BLOCK_COMMENTS) { - StringBuilder optimizedInput = new StringBuilder(""); - try { - File file = new File(ifcFilepath); - Scanner reader = new Scanner(file, StandardCharsets.UTF_8.name()); - while (reader.hasNextLine()) { - optimizedInput.append(reader.nextLine().replaceAll("/\\*.*?\\*/", "")).append("\n"); - } - reader.close(); - } catch (FileNotFoundException e) { - Logging.error(e.getMessage()); - } - - try (FileWriter writer = new FileWriter(tempFile)) { - writer.write(String.valueOf(optimizedInput)); - } - } - return tempFile; - } - - /** - * Extracts the filename of path - * - * @param filepath to get name for - * @return file name without suffix or default string if no valid file name - */ - private static String getFileName(String filepath) { - try { - String[] parts = filepath.split(File.separator.equals("\\") ? "\\\\" : "/"); - return parts[parts.length - 1].split("\\.")[0]; - } catch (NullPointerException e) { - return "indoorhelper_ifc_optimized"; - } - } - - /** - * Configuration class for file optimization tasks - */ - public static class Configuration { - public final boolean REMOVE_BLOCK_COMMENTS; - - public Configuration(boolean removeBlockCommands) { - REMOVE_BLOCK_COMMENTS = removeBlockCommands; - } - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/optimizer/OutputOptimizer.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/optimizer/OutputOptimizer.java deleted file mode 100644 index 994e52e..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/optimizer/OutputOptimizer.java +++ /dev/null @@ -1,148 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.optimizer; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.ParserGeoMath; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ParserUtility; -import org.openstreetmap.josm.data.osm.DataSet; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.tools.Logging; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Class providing methods to optimize OSM data files to avoid unnecessary nodes/ways in data set - */ -public class OutputOptimizer { - - /** - * Method optimizes the osm data following the set configurations - * - * @param config describes the optimization - * @param ds to optimize - */ - public static void optimize(Configuration config, DataSet ds) { - if (config.MERGE_CLOSE_NODES) { - int preCount = ds.getNodes().size() + ds.getWays().size(); - - // for each level merge possible nodes - ArrayList levels = ParserUtility.getLevelList(ds); - for (Integer level : levels) { - ArrayList merges = findMerges(ds, config.MERGE_DISTANCE, level); - mergeData(merges, ds); - } - - Logging.info(String.format("%s-OutputOptimizerReport: OSM primitives reduced by factor %.2f", - OutputOptimizer.class.getName(), - 1.0 - ((double) (ds.getNodes().size() + ds.getWays().size()) / preCount))); - } - } - - /** - * Method merges nodes in data set following the mergeLayout. - * - * @param mergeLayout holding information about merge targets and candidates - * @param ds data set to merge data in - */ - private static void mergeData(ArrayList mergeLayout, DataSet ds) { - Collections.reverse(mergeLayout); - - for (Merge target : mergeLayout) { - Node dsTarget = (Node) ds.getPrimitiveById(target.target.getPrimitiveId()); - - for (Node candidate : target.mergeCandidates) { - Node dsCandidate = (Node) ds.getPrimitiveById(candidate.getPrimitiveId()); - if (dsCandidate == null) { - //TODO Improve the merge to avoid this case! - Logging.info(String.format("%s-OutputOptimizerReport: Merge candidate is NULL, this should not happen!", - OutputOptimizer.class.getName())); - continue; - } - // replace nodes in parent ways - dsCandidate.getParentWays().forEach(way -> { - while (way.containsNode(dsCandidate)) { - way.addNode(way.getNodes().indexOf(dsCandidate), dsTarget); - way.removeNode(dsCandidate); - } - }); - // remove primitive - ds.removePrimitive(dsCandidate); - } - } - - Collections.reverse(mergeLayout); - } - - /** - * This method creates a {@link Merge} object for each node in dataset on defined level. - * The {@link Merge} object holds the node as target and a list of other nodes (tagged with the same level tag) - * as merge candidates. Whether a node is a merge candidate or not will be determined by the distance between - * target and node which needs to be smaller than the mergeDistance. - * If a target has no merge candidates it will not be included in the returned list. - * - * @param ds data set to find merges in - * @param mergeDistance distance between nodes so that the nodes can be merged - * @param level only object with this level tag will be considered - * @return Set of merges - */ - private static ArrayList findMerges(DataSet ds, double mergeDistance, int level) { - //TODO find merges by using clustering algorithm - - ArrayList merges = new ArrayList<>(); - ArrayList nodes = new ArrayList<>(ds.getNodes()); - - for (int i = 0; i < nodes.size(); ++i) { - Node targetNode = nodes.get(i); - // skip if node is part of another or none level - Number targetLevel = ParserUtility.getLevelTag(targetNode); - if (targetLevel == null || (int) targetLevel != level) continue; - Merge merge = new Merge(targetNode); - - for (int j = i + 1; j < nodes.size(); ++j) { - Node mergeCandidate = nodes.get(j); - // skip if node is part of another or none level - Number candidateLevel = ParserUtility.getLevelTag(mergeCandidate); - if (candidateLevel == null || (int) candidateLevel != level) continue; - // skip (for now) if node is part of the same way - if (ParserUtility.nodesPartOfSameWay(targetNode, mergeCandidate)) continue; - - // check distance between target and merge candidate - double distance = ParserGeoMath.getDistance( - targetNode.lat(), targetNode.lon(), mergeCandidate.lat(), mergeCandidate.lon()); - if (distance < mergeDistance) { - merge.mergeCandidates.add(mergeCandidate); - } - } - - if (!merge.mergeCandidates.isEmpty()) { - merges.add(merge); - } - } - - return merges; - } - - private static class Merge { - public final Node target; - public final List mergeCandidates; // merge to target - - public Merge(Node root) { - target = root; - mergeCandidates = new ArrayList<>(); - } - } - - /** - * Configuration class for output optimization tasks - */ - public static class Configuration { - public final boolean MERGE_CLOSE_NODES; - public final double MERGE_DISTANCE; - - public Configuration(boolean mergeCloseNodes, double mergeDistance) { - MERGE_CLOSE_NODES = mergeCloseNodes; - MERGE_DISTANCE = mergeDistance; - } - } -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/BIMtoOSMParser.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/BIMtoOSMParser.java deleted file mode 100644 index 7bed345..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/BIMtoOSMParser.java +++ /dev/null @@ -1,684 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.*; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentationCatalog.*; -import org.openstreetmap.josm.plugins.indoorhelper.io.controller.ImportEventListener; -import org.openstreetmap.josm.plugins.indoorhelper.io.model.BIMtoOSMCatalog; -import org.openstreetmap.josm.plugins.indoorhelper.io.optimizer.InputOptimizer; -import org.openstreetmap.josm.plugins.indoorhelper.io.optimizer.OutputOptimizer; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.BIMDataCollection; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.BIMObject3D; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.*; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ifc.BIMtoOSMUtility; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ifc.IfcGeometryExtractor; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ifc.IfcObjectIdentifier; -import org.openstreetmap.josm.plugins.indoorhelper.model.TagCatalog; -import nl.tue.buildingsmart.express.population.EntityInstance; -import nl.tue.buildingsmart.express.population.ModelPopulation; -import org.openstreetmap.josm.data.Preferences; -import org.openstreetmap.josm.data.coor.LatLon; -import org.openstreetmap.josm.data.osm.DataSet; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.data.osm.Tag; -import org.openstreetmap.josm.data.osm.Way; -import org.openstreetmap.josm.gui.MainApplication; -import org.openstreetmap.josm.tools.Logging; -import org.openstreetmap.josm.tools.Pair; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Scanner; - -import static org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ParserUtility.prepareDoubleString; -import static org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ParserUtility.stringVectorToVector3D; -import static org.openstreetmap.josm.tools.I18n.tr; - -/** - * Parser for BIM data. Extracts major BIM elements and transforms coordinates into OSM convenient format - */ -public class BIMtoOSMParser { - - private static final String FLAG_IFC2X3_TC1 = "FILE_SCHEMA(('IFC2X3_TC1'))"; - private static final String FLAG_IFC2X3 = "FILE_SCHEMA(('IFC2X3'))"; - private static final String FLAG_IFC4 = "FILE_SCHEMA(('IFC4'))"; - private static final String IFC2X3_TC1_SCHEMA = "IFC2X3_TC1.exp"; - private static final String IFC4_SCHEMA = "IFC4.exp"; - private final String resourcePathDir; - private String ifcSchemaFilePath; - - private final ImportEventListener importListener; - private FileInputStream inputFs = null; - - private ModelPopulation ifcModel; - private final TagCatalog tagCatalog; - private IfcUnitCatalog.LengthUnit lengthUnit; - - private static final int DEFAULT_LEVEL = 999; - - // configuration parameters - private BIMtoOSMUtility.GeometrySolution solutionType; - private boolean optimizeInputFile; - private InputOptimizer.Configuration optimizeInputConfig; - private boolean optimizeOutput; - private OutputOptimizer.Configuration optimizeOutputConfig; - - /** - * Constructor - * - * @param listener for import events - * @param pluginDirectory of indoorHelper plugin - */ - public BIMtoOSMParser(ImportEventListener listener, String pluginDirectory) { - if (listener == null) { - throw new IllegalArgumentException("invalid argument value of listener: null"); - } - importListener = listener; - - if (pluginDirectory == null) { - resourcePathDir = Preferences.main().getPluginsDirectory().toString() + "/indoorhelper/resources"; - } else { - resourcePathDir = pluginDirectory + "/resources/"; - } - - ifcSchemaFilePath = resourcePathDir + IFC2X3_TC1_SCHEMA; - tagCatalog = new TagCatalog(); - lengthUnit = IfcUnitCatalog.LengthUnit.M; - applyDefaultConfiguration(); - } - - /** - * Applies default configuration to parser - */ - private void applyDefaultConfiguration() { - configure(BIMtoOSMUtility.GeometrySolution.BOUNDING_BOX, - new InputOptimizer.Configuration(true), - // default: merge overlapping nodes only (distance < 0.01) - new OutputOptimizer.Configuration(true, 0.01)); - } - - /** - * Sets configuration values of parser - * - * @param solution type of parsed data. {@link BIMtoOSMUtility.GeometrySolution} represents - * precision of parsed data - * @param optimizeInputConfig not null if IFC file should be pre-optimized, else null - * @param optimizeOutputConfig not null if OSM output should be optimized, else null - * @return true if config set successfully, else false - */ - public boolean configure(BIMtoOSMUtility.GeometrySolution solution, - InputOptimizer.Configuration optimizeInputConfig, - OutputOptimizer.Configuration optimizeOutputConfig) { - if (solution == null) { - Logging.info(BIMtoOSMParser.class.getName() - + ": Failed to set parser configuration. Solution equals null!"); - return false; - } - if (optimizeInputConfig == null) { - Logging.info(BIMtoOSMParser.class.getName() - + ": Failed to set parser configuration. optimizeInputConfig equals null!"); - return false; - } - if (optimizeOutputConfig == null) { - Logging.info(BIMtoOSMParser.class.getName() - + ": Failed to set parser configuration. optimizeOutputConfig equals null!"); - return false; - } - - solutionType = solution; - Logging.info(String.format("%s-ConfigurationReport: solution set to %s", - BIMtoOSMParser.class.getName(), solutionType.name())); - - optimizeInputFile = optimizeInputConfig.REMOVE_BLOCK_COMMENTS; - this.optimizeInputConfig = optimizeInputConfig; - Logging.info(String.format("%s-ConfigurationReport: optimizeInputFile %s; RemoveBlockCommands %s", - BIMtoOSMParser.class.getName(), - optimizeInputConfig.REMOVE_BLOCK_COMMENTS ? "enabled" : "disabled", - optimizeInputConfig.REMOVE_BLOCK_COMMENTS ? "enabled" : "disabled")); - - optimizeOutput = optimizeOutputConfig.MERGE_CLOSE_NODES; - this.optimizeOutputConfig = optimizeOutputConfig; - Logging.info(String.format("%s-ConfigurationReport: optimizeOutput %s; MergeCloseNodes %s; " + - "MergeDistance set to %.2f m", - BIMtoOSMParser.class.getName(), - optimizeOutputConfig.MERGE_CLOSE_NODES ? "enabled" : "disabled", - optimizeOutputConfig.MERGE_CLOSE_NODES ? "enabled" : "disabled", - optimizeOutputConfig.MERGE_CLOSE_NODES ? optimizeOutputConfig.MERGE_DISTANCE : -999)); - - return true; - } - - /** - * Method parses data from ifc file into OSM data - * - * @param filepath of ifc file - */ - public boolean parse(String filepath) { - if (!loadFile(filepath)) return false; - - // get osm relevant data - BIMDataCollection rawFilteredData = BIMtoOSMUtility.extractMajorBIMData(ifcModel); - - if (!checkForIFCSITE(rawFilteredData)) { - showParsingErrorView(filepath, "Could not import IFC file.\nIFC " + - "file does not contain IFCSITE element.", true); - return false; - } - - // transform osm relevant data into BIMObject3D - ArrayList preparedData = (ArrayList) transformToBIMData(rawFilteredData); - - // transform building coordinates to WCS - setUnits(); - LatLon llBuildingOrigin = getLatLonBuildingOrigin(rawFilteredData.getIfcSite()); - transformToGeodetic(llBuildingOrigin, preparedData); - - // pack parsed data into osm format - DataSet packedOSMData = packIntoOSMData(preparedData); - if (optimizeOutput) { - importListener.onProcessStatusChanged("optimizing data"); - OutputOptimizer.optimize(optimizeOutputConfig, packedOSMData); - } - - if (preparedData.size() != rawFilteredData.getSize()) { - showParsingErrorView(filepath, "Caution!\nImported data might include errors!", false); - } - - // trigger rendering - importListener.onDataParsed(packedOSMData); - - Logging.info(this.getClass().getName() + ": " + filepath + " parsed successfully"); - return true; - } - - /** - * Load file into ifcModel - * - * @param filepath of IFC file - * @return true if loading successful, else false - */ - private boolean loadFile(String filepath) { - try { - // pre-optimize and load IFC file - File file; - if (optimizeInputFile) { - file = InputOptimizer.optimizeIfcFile(optimizeInputConfig, filepath); - } else { - file = new File(filepath); - } - - inputFs = new FileInputStream(file); - - // find used IFC schema - String usedIfcSchema = chooseSchemaFile(file); - if (usedIfcSchema.isEmpty()) { - showLoadingErrorView(filepath, "Could not load IFC file.\nIFC schema is not supported."); - return false; - } - if (usedIfcSchema.equals(FLAG_IFC4)) { - ifcSchemaFilePath = resourcePathDir + IFC4_SCHEMA; - } - - // load IFC file data into model - ifcModel = new ModelPopulation(inputFs); - ifcModel.setSchemaFile(Paths.get(ifcSchemaFilePath)); - ifcModel.load(); - - // if loading throws ParseException check if ifcModel is empty to recognize something went wrong - if (ifcModel.getInstances() == null) { - showLoadingErrorView(filepath, "Could not load IFC file."); - return false; - } - } catch (IOException e) { - Logging.error(e.getMessage()); - return false; - } finally { - if (inputFs != null) { - try { - inputFs.close(); - } catch (IOException ignored) { - // do nothing - } - } - } - Logging.info(this.getClass().getName() + ": " + filepath + " loaded successfully"); - return true; - } - - /** - * Read the FILE_SCHEMA flag from ifc file and return used schema - * - * @param ifcFile (if necessary) optimized IFC file - * @return Used ifc file schema as string - */ - private String chooseSchemaFile(File ifcFile) { - String schema = ""; - try { - Scanner reader = new Scanner(ifcFile, StandardCharsets.UTF_8.name()); - while (reader.hasNextLine()) { - String data = reader.nextLine(); - data = data.replaceAll("\\s+", ""); - - // schema must be defined before this flag - if (data.contains("DATA;")) break; - // check if IFC2X3 - if (data.contains(FLAG_IFC2X3_TC1) || data.contains(FLAG_IFC2X3)) { - schema = FLAG_IFC2X3_TC1; - break; - } - // check if IFC4 - else if (data.contains(FLAG_IFC4)) { - schema = FLAG_IFC4; - break; - } - } - reader.close(); - } catch (FileNotFoundException e) { - Logging.error(e.getMessage()); - } - - return schema; - } - - /** - * Checks if IfcSite element exists in data - * - * @param data to check - * @return true if exists, else false - */ - private boolean checkForIFCSITE(BIMDataCollection data) { - try { - data.getIfcSite().getAttributeValueBNasEntityInstance("ObjectPlacement").getId(); - return true; - } catch (NullPointerException e) { - return false; - } - } - - /** - * Extracts the BIM object geometry and transform data to {@link BIMObject3D} - * - * @param rawBIMData to transform - * @return transformed data for rendering - */ - private List transformToBIMData(BIMDataCollection rawBIMData) { - List transformedData = new ArrayList<>(); - List slabs = BIMtoOSMUtility.transformBIMObjects(ifcModel, solutionType, BIMtoOSMCatalog.BIMObject.IfcSlab, rawBIMData.getAreaObjects()); - List walls = BIMtoOSMUtility.transformBIMObjects(ifcModel, solutionType, BIMtoOSMCatalog.BIMObject.IfcWall, rawBIMData.getWallObjects()); - List columns = BIMtoOSMUtility.transformBIMObjects(ifcModel, solutionType, BIMtoOSMCatalog.BIMObject.IfcColumn, rawBIMData.getColumnObjects()); -// List doors = BIMtoOSMUtility.transformBIMObjects(ifcModel, solutionType, BIMtoOSMCatalog.BIMObject.IfcDoor, rawBIMData.getDoorObjects()); -// List windows = BIMtoOSMUtility.transformBIMObjects(ifcModel, solutionType, BIMtoOSMCatalog.BIMObject.IfcWindow, rawBIMData.getWindowObjects()); - List stairs = BIMtoOSMUtility.transformBIMObjects(ifcModel, solutionType, BIMtoOSMCatalog.BIMObject.IfcStair, rawBIMData.getStairObjects()); - transformedData.addAll(slabs); - transformedData.addAll(walls); - transformedData.addAll(columns); -// transformedData.addAll(doors); -// transformedData.addAll(windows); - transformedData.addAll(stairs); - return transformedData; - } - - /** - * Method packs prepared BIM data into OSM ways and nodes - * - * @param preparedBIMData to transform to OSM data - * @return packed data as {@link DataSet} - */ - private DataSet packIntoOSMData(ArrayList preparedBIMData) { - ArrayList ways = new ArrayList<>(); - ArrayList nodes = new ArrayList<>(); - ArrayList> levelIdentifier = extractAndIdentifyLevels(); - - for (BIMObject3D object : preparedBIMData) { - int level = getLevelTag(object, levelIdentifier); - - ArrayList tmpNodes = new ArrayList<>(); - for (LatLon point : object.getGeodeticGeometryCoordinates()) { - Node n = new Node(point); - tmpNodes.add(n); - } - - if (tmpNodes.size() < 2) continue; - - if (tmpNodes.get(0).lat() == tmpNodes.get(tmpNodes.size() - 1).lat() && tmpNodes.get(0).lon() == tmpNodes.get(tmpNodes.size() - 1).lon()) { - tmpNodes.remove(tmpNodes.size() - 1); - nodes.addAll(tmpNodes); - tmpNodes.add(tmpNodes.get(0)); - } else { - nodes.addAll(tmpNodes); - } - Way w = new Way(); - w.setNodes(tmpNodes); - getObjectTags(object).forEach(w::put); - if (level != DEFAULT_LEVEL) w.put(new Tag("level", Integer.toString(level))); - ways.add(w); - } - - DataSet ds = new DataSet(); - nodes.forEach(ds::addPrimitive); - ways.forEach(ds::addPrimitive); - return ds; - } - - /** - * Method gets level tag of PreparedBIMObject3D - * - * @param object to get level tag for - * @param levelIdentifierList with identified levels - * @return level - */ - private int getLevelTag(BIMObject3D object, ArrayList> levelIdentifierList) { - int level = DEFAULT_LEVEL; - - // get all IfcRelContainedInSpatialStructure elements - List relContainedInSpatialStructureElements = ifcModel.getInstancesOfType("IfcRelContainedInSpatialStructure"); - - for (EntityInstance entity : relContainedInSpatialStructureElements) { - // for each element get contained entities - ArrayList containedElements = entity.getAttributeValueBNasEntityInstanceList("RelatedElements"); - - // check if object is part of contained entities - for (EntityInstance element : containedElements) { - - if (element.getId() == object.getId()) { - // if part of contained elements get Elevation entity from object - EntityInstance relatingStructure = entity.getAttributeValueBNasEntityInstance("RelatingStructure"); - - String relatingStructureType = IfcObjectIdentifier.getSpatialStructureElementType(ifcModel, relatingStructure); - // get type of relatingStructure - if (!relatingStructureType.equals(IfcSpatialStructureElementTypes.IfcBuildingStorey.name())) - return 0; - // if of type IfcBuildingStorey - double storeyElevation = prepareDoubleString((String) relatingStructure.getAttributeValueBN("Elevation")); - - // get assigned level tag to Elevation entity - for (Pair identifier : levelIdentifierList) { - if (identifier.a == storeyElevation) { - level = identifier.b; - break; - } - } - } - - } - } - return level; - } - - /** - * Method extracts and identifies level tags from IfcRelContainedInSpatialStructure elements - * - * @return List with pairs of level Elevation entity (Double) and assigned level tag (Integer) - */ - private ArrayList> extractAndIdentifyLevels() { - // get all IfcRelContainedInSpatialStructure elements - List relContainedInSpatialStructureElements = ifcModel.getInstancesOfType("IfcRelContainedInSpatialStructure"); - - ArrayList> levelIdentifier = new ArrayList<>(); - ArrayList levelList = new ArrayList<>(); - - // run thru IfcRelContainedInSpatialStructure and get the buildingStorey elements. Those elements include an Elevation entity - for (EntityInstance entity : relContainedInSpatialStructureElements) { - EntityInstance buildingStorey = entity.getAttributeValueBNasEntityInstance("RelatingStructure"); - double storeyElevation = prepareDoubleString((String) buildingStorey.getAttributeValueBN("Elevation")); - levelList.add(storeyElevation); - } - - // Sort the Elevation entity ascending - Collections.sort(levelList); - - int level0Index = -1; - double level0 = 999.0; - for (Double level : levelList) { - double d = Math.abs(0.0 - level); - if (d < level0) { - level0Index = levelList.indexOf(level); - level0 = d; - } - } - - for (Double level : levelList) { - int index = levelList.indexOf(level) - level0Index; - levelIdentifier.add(new Pair<>(level, index)); - } - - return levelIdentifier; - } - - /** - * Method sets geodetic shape coordinates of PreparedBIMObject3D - * - * @param llBuildingOrigin building origin latlon - * @param preparedBIMData data to set the geodetic shapes - */ - private void transformToGeodetic(LatLon llBuildingOrigin, ArrayList preparedBIMData) { - if (llBuildingOrigin != null) { - - // get building rotation matrix - Vector3D projectNorth = getProjectNorth(); - Vector3D trueNorth = getTrueNorth(); - Matrix3D rotationMatrix = null; - if (projectNorth != null && trueNorth != null) { - double rotationAngle = trueNorth.angleBetween(projectNorth); - rotationMatrix = ParserMath.getRotationMatrixZ(rotationAngle); - } - - if (rotationMatrix == null) return; - - for (BIMObject3D object : preparedBIMData) { - ArrayList transformedCoordinates = new ArrayList<>(); - for (Vector3D point : object.getCartesianGeometryCoordinates()) { - // rotate point - rotationMatrix.transform(point); - // transform point - LatLon llPoint = ParserGeoMath.cartesianToGeodetic(point, new Vector3D(0.0, 0.0, 0.0), llBuildingOrigin, lengthUnit); - transformedCoordinates.add(llPoint); - } - object.setGeodeticGeometryCoordinates(transformedCoordinates); - } - } - } - - /** - * Method calculates the latlon coordinates of building origin corner - * - * @param ifcSite IfcSite entity - * @return latlon coordinates of building corner - */ - @SuppressWarnings("unchecked") - private LatLon getLatLonBuildingOrigin(EntityInstance ifcSite) { - Vector3D ifcSiteOffset = null; - if (ifcSite.getAttributeValueBNasEntityInstance("Representation") != null) { - // get the offset between IfcSite geodetic coordinates and building origin coordinate - // handle IfcSite offset if IfcBoundingBox representation - List repObjectIdentities = BIMtoOSMUtility.getIfcRepresentations(ifcSite); - if (repObjectIdentities == null) return null; - - IfcRepresentation boxRepresentation = - BIMtoOSMUtility.getIfcRepresentation(repObjectIdentities, RepresentationIdentifier.Box); - if (boxRepresentation != null) { - // get offset - EntityInstance bb = boxRepresentation.getEntity(); - EntityInstance bbItem = bb.getAttributeValueBNasEntityInstanceList("Items").get(0); - EntityInstance cartesianCorner = bbItem.getAttributeValueBNasEntityInstance("Corner"); - ifcSiteOffset = IfcGeometryExtractor.ifcCoordinatesToVector3D(cartesianCorner); - } - } - - // get RefLatitude and RefLongitude of IfcSite - List refLat; - List refLon; - try { - refLat = (List) ifcSite.getAttributeValueBN("RefLatitude"); - refLon = (List) ifcSite.getAttributeValueBN("RefLongitude"); - } catch (NullPointerException e) { - return null; - } - - if (refLat == null || refLon == null) return null; - - // transform angle measurement to latlon - double lat = ParserGeoMath.degreeMinutesSecondsToLatLon( - prepareDoubleString(refLat.get(0)), - prepareDoubleString(refLat.get(1)), - prepareDoubleString(refLat.get(2))); - double lon = ParserGeoMath.degreeMinutesSecondsToLatLon( - prepareDoubleString(refLon.get(0)), - prepareDoubleString(refLon.get(1)), - prepareDoubleString(refLon.get(2))); - - // if offset, calculate building origin without offset - if (ifcSiteOffset != null && ifcSiteOffset.getX() != 0.0 && ifcSiteOffset.getY() != 0.0) { - return ParserGeoMath.cartesianToGeodetic(new Vector3D(0.0, 0.0, 0.0), ifcSiteOffset, new LatLon(lat, lon), lengthUnit); - } - - return new LatLon(lat, lon); - } - - /** - * Get project north of building - * - * @return project north as {@link Vector3D} - */ - @SuppressWarnings("unchecked") - private Vector3D getProjectNorth() { - List projectNorthDirectionRatios; - try { - EntityInstance ifcProject = ifcModel.getInstancesOfType("IfcProject").get(0); - EntityInstance geometricContext = ifcProject.getAttributeValueBNasEntityInstanceList("RepresentationContexts").get(0); - EntityInstance worldCoordinates = geometricContext.getAttributeValueBNasEntityInstance("WorldCoordinateSystem"); - EntityInstance projectNorth = worldCoordinates.getAttributeValueBNasEntityInstance("RefDirection"); - projectNorthDirectionRatios = (List) projectNorth.getAttributeValueBN("DirectionRatios"); - } catch (NullPointerException e) { - return null; - } - return stringVectorToVector3D(projectNorthDirectionRatios); - } - - /** - * get true north vector of building - * - * @return true north as {@link Vector3D} - */ - @SuppressWarnings("unchecked") - private Vector3D getTrueNorth() { - List trueNorthDirectionRatios; - try { - EntityInstance ifcProject = ifcModel.getInstancesOfType("IfcProject").get(0); - EntityInstance geometricContext = ifcProject.getAttributeValueBNasEntityInstanceList("RepresentationContexts").get(0); - EntityInstance trueNorth = geometricContext.getAttributeValueBNasEntityInstance("TrueNorth"); - trueNorthDirectionRatios = (List) trueNorth.getAttributeValueBN("DirectionRatios"); - } catch (NullPointerException e) { - return null; - } - return stringVectorToVector3D(trueNorthDirectionRatios); - } - - /** - * Method sets length unit of file - */ - private void setUnits() { - ArrayList units = - ifcModel.getInstancesOfType("IfcUnitAssignment").get(0).getAttributeValueBNasEntityInstanceList("Units"); - for (EntityInstance unit : units) { - try { - String unitType = (String) unit.getAttributeValueBN("UnitType"); - String unitLabel = (String) unit.getAttributeValueBN("Name"); - if (unitType.equals(".LENGTHUNIT.")) { - if (unitLabel.equals(".METRE.")) { - try { - String unitPrefix = (String) unit.getAttributeValueBN("Prefix"); - if (unitPrefix.equals(".CENTI.")) lengthUnit = IfcUnitCatalog.LengthUnit.CM; - if (unitPrefix.equals(".MILLI.")) lengthUnit = IfcUnitCatalog.LengthUnit.MM; - break; - // TODO handle more prefixes - } catch (NullPointerException e) { - // do nothing - } - break; - } - } - } catch (NullPointerException e) { - // do nothing - } - } - } - - /** - * Method get OSM tags describing BIM object - * - * @param object to get OSM tags for - * @return OSM Tags as array - */ - private ArrayList getObjectTags(BIMObject3D object) { - if (object.getType().name().contains("Slab")) { - return (ArrayList) tagCatalog.getTags(TagCatalog.IndoorObject.ROOM); - } - if (object.getType().name().contains("Wall")) { - return (ArrayList) tagCatalog.getTags(TagCatalog.IndoorObject.CONCRETE_WALL); - } - if (object.getType().name().contains("Column")) { - return (ArrayList) tagCatalog.getTags(TagCatalog.IndoorObject.CONCRETE_WALL); - } - if (object.getType().name().contains("Door")) { - return (ArrayList) tagCatalog.getTags(TagCatalog.IndoorObject.DOOR_PRIVATE); - } - if (object.getType().name().contains("Window")) { - return (ArrayList) tagCatalog.getTags(TagCatalog.IndoorObject.GLASS_WALL); - } - if (object.getType().name().contains("Stair")) { - return (ArrayList) tagCatalog.getTags(TagCatalog.IndoorObject.STEPS); - } - return new ArrayList<>(); - } - - /** - * Shows error dialog is file loading failed - * - * @param filepath of ifc file - * @param msg Error message - */ - private void showLoadingErrorView(String filepath, String msg) { - showErrorView(tr(msg)); - Logging.info(this.getClass().getName() + ": " + filepath + " loading failed"); - } - - /** - * Shows error dialog is file loading failed - * - * @param filepath of ifc file - * @param msg Error message - * @param logInfo log info to console - */ - private void showParsingErrorView(String filepath, String msg, boolean logInfo) { - showErrorView(tr(msg)); - if (logInfo) { - Logging.info(this.getClass().getName() + ": " + filepath + " parsing failed"); - } - } - - /** - * Shows error dialog - * - * @param msg Error message - */ - private void showErrorView(String msg) { - Logging.error(msg.replaceAll("\n", " ")); - if (!GraphicsEnvironment.isHeadless()) { - SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(MainApplication.getMainFrame(), - msg, - tr("Error"), - JOptionPane.ERROR_MESSAGE)); - } - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/BIMDataCollection.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/BIMDataCollection.java deleted file mode 100644 index b9f0965..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/BIMDataCollection.java +++ /dev/null @@ -1,90 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.data; - -import nl.tue.buildingsmart.express.population.EntityInstance; - -import java.util.List; - -/** - * Data structure holding specific BIM data elements. - */ -public class BIMDataCollection { - private EntityInstance ifcSite; // root of data set - private List areaObjects; - private List wallObjects; - private List columnObjects; - private List doorObjects; - private List stairObjects; - private List windowObjects; - private List relVoidsElements; // IfcRelVoidsElement - - public EntityInstance getIfcSite() { - return ifcSite; - } - - public void setIfcSite(EntityInstance ifcSite) { - this.ifcSite = ifcSite; - } - - public List getAreaObjects() { - return areaObjects; - } - - public void setAreaObjects(List areaObjects) { - this.areaObjects = areaObjects; - } - - public List getWallObjects() { - return wallObjects; - } - - public void setWallObjects(List wallObjects) { - this.wallObjects = wallObjects; - } - - public List getColumnObjects() { - return columnObjects; - } - - public void setColumnObjects(List columnObjects) { - this.columnObjects = columnObjects; - } - - public List getDoorObjects() { - return doorObjects; - } - - public void setDoorObjects(List doorObjects) { - this.doorObjects = doorObjects; - } - - public List getStairObjects() { - return stairObjects; - } - - public void setStairObjects(List stairObjects) { - this.stairObjects = stairObjects; - } - - public List getWindowObjects() { - return windowObjects; - } - - public void setWindowObjects(List windowObjects) { - this.windowObjects = windowObjects; - } - - public List getRelVoidsElements() { - return relVoidsElements; - } - - public void setRelVoidsElements(List relVoidsElements) { - this.relVoidsElements = relVoidsElements; - } - - public int getSize() { - return (areaObjects.size() + wallObjects.size() + - columnObjects.size() + doorObjects.size() + stairObjects.size()); - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/BIMObject3D.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/BIMObject3D.java deleted file mode 100644 index 91ca30b..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/BIMObject3D.java +++ /dev/null @@ -1,137 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.data; - -import org.openstreetmap.josm.plugins.indoorhelper.io.model.BIMtoOSMCatalog; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.Matrix3D; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.Vector3D; -import nl.tue.buildingsmart.express.population.EntityInstance; -import org.openstreetmap.josm.data.coor.LatLon; - -import java.util.ArrayList; -import java.util.List; - -/** - * Class holding OSM relevant data of 3D BIM object - */ -public class BIMObject3D { - - // object identity - private int id; - private BIMtoOSMCatalog.BIMObject type; - private EntityInstance rootEntity; - private EntityInstance placementEntity; - private EntityInstance representationEntity; - - // object representation data - private List cartesianGeometryCoordinates; - private List geodeticGeometryCoordinates; - - // transformation matrices - private Vector3D translation; - private Matrix3D rotation; - - public BIMObject3D(int id) { - this.id = id; - cartesianGeometryCoordinates = new ArrayList<>(); - geodeticGeometryCoordinates = new ArrayList<>(); - translation = new Vector3D(); - rotation = new Matrix3D(); - rotation.setIdentity(); - } - - public BIMObject3D( - int id, - BIMtoOSMCatalog.BIMObject type, - Vector3D cartesianOrigin, - List shapeCoordinates) { - this.id = id; - this.type = type; - cartesianGeometryCoordinates = shapeCoordinates; - geodeticGeometryCoordinates = new ArrayList<>(); - translation = cartesianOrigin; - rotation = new Matrix3D(); - rotation.setIdentity(); - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public BIMtoOSMCatalog.BIMObject getType() { - return type; - } - - public void setType(BIMtoOSMCatalog.BIMObject type) { - this.type = type; - } - - public EntityInstance getRootEntity() { - return rootEntity; - } - - public void setRootEntity(EntityInstance rootEntity) { - this.rootEntity = rootEntity; - } - - public EntityInstance getPlacementEntity() { - return placementEntity; - } - - public void setPlacementEntity(EntityInstance placementEntity) { - this.placementEntity = placementEntity; - } - - public EntityInstance getRepresentationEntity() { - return representationEntity; - } - - public void setRepresentationEntity(EntityInstance representationEntity) { - this.representationEntity = representationEntity; - } - - public Vector3D getCartesianPlacement() { - // TODO implement - throw new UnsupportedOperationException(); - } - - public List getCartesianGeometryCoordinates() { - return cartesianGeometryCoordinates; - } - - public void setCartesianGeometryCoordinates(List cartesianGeometryCoordinates) { - this.cartesianGeometryCoordinates = cartesianGeometryCoordinates; - } - - public LatLon getGeodeticPlacement() { - // TODO implement - throw new UnsupportedOperationException(); - } - - public List getGeodeticGeometryCoordinates() { - return geodeticGeometryCoordinates; - } - - public void setGeodeticGeometryCoordinates(List geodeticGeometryCoordinates) { - this.geodeticGeometryCoordinates = geodeticGeometryCoordinates; - } - - public Vector3D getTranslation() { - return translation; - } - - public void setTranslation(Vector3D translation) { - this.translation = translation; - } - - public Matrix3D getRotation() { - return rotation; - } - - public void setRotation(Matrix3D rotation) { - this.rotation = rotation; - } -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcRepresentation.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcRepresentation.java deleted file mode 100644 index 151fc99..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcRepresentation.java +++ /dev/null @@ -1,74 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentationCatalog.*; -import nl.tue.buildingsmart.express.population.EntityInstance; - -/** - * Class holding identifier and types of IfcRepresentation - */ -public class IfcRepresentation { - // IFC attributes - private RepresentationIdentifier identifier; - private RepresentationType type; - - // local attributes - private EntityInstance entity; - private EntityInstance rootEntity; - - public IfcRepresentation() { - // default - } - - public IfcRepresentation(RepresentationIdentifier identifier, RepresentationType type, EntityInstance representationObject, EntityInstance rootEntity) { - this.identifier = identifier; - this.type = type; - this.entity = representationObject; - this.rootEntity = rootEntity; - } - - public RepresentationIdentifier getIdentifier() { - return identifier; - } - - public String getIdentifierString() { - return identifier.name(); - } - - public RepresentationType getType() { - return type; - } - - public String getTypeString() { - return type.name(); - } - - public void setIdentifier(RepresentationIdentifier identifier) { - this.identifier = identifier; - } - - public void setType(RepresentationType type) { - this.type = type; - } - - public boolean isFilled() { - return this.identifier != null && this.type != null; - } - - public EntityInstance getEntity() { - return entity; - } - - public void setEntity(EntityInstance entity) { - this.entity = entity; - } - - public EntityInstance getRootEntity() { - return rootEntity; - } - - public void setRootEntity(EntityInstance rootEntity) { - this.rootEntity = rootEntity; - } - -} \ No newline at end of file diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcRepresentationCatalog.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcRepresentationCatalog.java deleted file mode 100644 index 59a8b47..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcRepresentationCatalog.java +++ /dev/null @@ -1,154 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc; - -/** - * Class classify ifc object types. - * Notice: Enum elements are not defined uppercase to use them as strings - */ -public class IfcRepresentationCatalog { - - /** - * RepresentationIdentifier of IfcShapeRepresentations - */ - public enum RepresentationIdentifier { - Annotation, Axis, Box, Body, Clearance, CoG, FootPrint, Lighting, Profile, Reference, Surface - } - - /** - * RepresentationType of IfcShapeRepresentations - */ - public enum RepresentationType { - AdvancedBrep, AdvancedSweptSolid, Annotation2D, Brep, CSG, Clipping, SurfaceModel, Point, PointCloud, Curve, Curve2D, - Curve3D, Surface, Surface2D, Surface3D, FillArea, Text, AdvancedSurface, GeometricSet, GeometricCurveSet, - Tessellation, SolidModel, SweptSolid, BoundingBox, SectionedSpine, LightSoure, - MappedRepresentation - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationType AdvancedBrep - */ - public enum AdvancedBrepRepresentationTypeItems { - IfcAdvancedBrep, IfcFacetedBrep - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationTypes AdvancedSweptSolid - */ - public enum AdvancedSweptSolidRepresentationTypeItems { - IfcSweptDiskSolid, IfcSweptDiskSolidPolygonal - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationType Brep - */ - public enum BrepRepresentationTypeItems { - IfcFacetedBrep - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationType CSG - */ - public enum CSGRepresentationTypeItems { - IfcCsgSolid, IfcBooleanResult, IfcPrimitive3D - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationTypes Clipping - */ - public enum ClippingRepresentationTypeItems { - IfcBooleanClippingResult - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationType Curve. - * Includes supertypes - */ - public enum CurveRepresentationTypeItems { - IfcBoundedCurve, IfcPolyline, IfcCompositeCurve, IfcTrimmedCurve, IfcBSplineCurve, - IfcConic, IfcCircle, IfcEllipse, IfcLine, IfcOffsetCurve2D, IfcOffsetCurve3D, IfcIndexedPolyCurve - } - - public enum MappedRepresentationTypeItems { - IfcMappedItem - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationTypes Tesselation - */ - public enum TessellationRepresentationTypeItems { - IfcTessellatedFaceSet - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationTypes SurfaceModel - */ - public enum SurfaceModelRepresentationTypeItems { - IfcTessellatedItem, IfcShellBasedSurfaceModel, IfcFaceBasedSurfaceModel, IfcFacetedBrep - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationTypes SweptSolid - */ - public enum SweptSolidRepresentationTypeItems { - IfcExtrudedAreaSolid, IfcRevolvedAreaSolid - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation.RepresentationTypes BoundingBox - */ - public enum BoundingBoxRepresentationTypeItems { - IfcBoundingBox - } - - - // Ifc representation subtypes - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation IfcLoop - */ - public enum LoopSubRepresentationTypeItems { - IfcEdgeLoop, IfcPolyLoop, IfcVertexLoop - } - - /** - * Permitted IfcShapeRepresentation.Items types for IfcShapeRepresentation IfcProfileDef - */ - public enum ProfileDefRepresentationTypeItems { - IfcRectangleProfileDef, IfcTrapeziumProfileDef, IfcCircleProfileDef, IfcEllipseProfileDef, - IfcShapeProfileDef, IfcArbitraryClosedProfileDef - } - - public enum Axis2PlacementRepresentationTypeItems { - IfcAxis2Placement2D, IfcAxis2Placement3D - } - - /** - * This enumeration defines the available predefined types of a slab - */ - public enum IfcSlabTypeEnum { - FLOOR, ROOF, LANDING, BASESLAB, USERDEFINED, NOTDEFINED - } - - /** - * Types of entities which may participate in a Boolean operation to form a CSG solid - */ - public enum IfcBooleanOperandType { - IfcSolidModel, IfcCsgSolid, IfcManifoldSolidBrep, IfcSweptAreaSolid, IfcSweptDiskSolid, - IfcHalfSpaceSolid, IfcBoxedHalfSpace, IfcPolygonalBoundedHalfSpace, - IfcBooleanResult, IfcBooleanClippingResult, - IfcCsgPrimitive3D, IfcBlock, IfcRectangularPyramid, IfcRightCircularCone, IfcRightCircularCylinder, IfcSphere, - IfcExtrudedAreaSolid, IfcFacetedBrep - } - - // Items of IFC void elements - - public enum IfcRelVoidsElementTypes { - IfcOpeningElement, IfcVoidingFeature - } - - - public enum IfcSpatialStructureElementTypes { - IfcBuilding, IfcBuildingStorey, IfcSpace, IfcSite - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcUnitCatalog.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcUnitCatalog.java deleted file mode 100644 index 26d974c..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/data/ifc/IfcUnitCatalog.java +++ /dev/null @@ -1,17 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc; - -/** - * Class holding ifc units - */ -public class IfcUnitCatalog { - - public enum LengthUnit { - M, CM, MM - } - - public enum PlaneAngleUnit { - RAD, DEG - } -} - diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/Matrix3D.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/Matrix3D.java deleted file mode 100644 index 089c915..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/Matrix3D.java +++ /dev/null @@ -1,274 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.math; - -/** - * Class provides 3D matrix - */ -public class Matrix3D { - - private double m00; - private double m01; - private double m02; - private double m10; - private double m11; - private double m12; - private double m20; - private double m21; - private double m22; - - public Matrix3D() { - this.m00 = 0.0; - this.m01 = 0.0; - this.m02 = 0.0; - this.m10 = 0.0; - this.m11 = 0.0; - this.m12 = 0.0; - this.m20 = 0.0; - this.m21 = 0.0; - this.m22 = 0.0; - } - - public Matrix3D(double m00, double m01, double m02, - double m10, double m11, double m12, - double m20, double m21, double m22) { - this.m00 = m00; - this.m01 = m01; - this.m02 = m02; - this.m10 = m10; - this.m11 = m11; - this.m12 = m12; - this.m20 = m20; - this.m21 = m21; - this.m22 = m22; - } - - public Matrix3D(Matrix3D matrix) { - this.m00 = matrix.m00; - this.m01 = matrix.m01; - this.m02 = matrix.m02; - this.m10 = matrix.m10; - this.m11 = matrix.m11; - this.m12 = matrix.m12; - this.m20 = matrix.m20; - this.m21 = matrix.m21; - this.m22 = matrix.m22; - } - - public void setM00(double m00) { - this.m00 = m00; - } - - public double getM00() { - return m00; - } - - public void setM01(double m01) { - this.m01 = m01; - } - - public double getM01() { - return m01; - } - - public void setM02(double m02) { - this.m02 = m02; - } - - public double getM02() { - return m02; - } - - public void setM10(double m10) { - this.m10 = m10; - } - - public double getM10() { - return m10; - } - - public void setM11(double m11) { - this.m11 = m11; - } - - public double getM11() { - return m11; - } - - public void setM12(double m12) { - this.m12 = m12; - } - - public double getM12() { - return m12; - } - - public void setM20(double m20) { - this.m20 = m20; - } - - public double getM20() { - return m20; - } - - public void setM21(double m21) { - this.m21 = m21; - } - - public double getM21() { - return m21; - } - - public void setM22(double m22) { - this.m22 = m22; - } - - public double getM22() { - return m22; - } - - /** - * Sets this matrix to identity - */ - public void setIdentity() { - this.m00 = 1.0; - this.m01 = 0.0; - this.m02 = 0.0; - - this.m10 = 0.0; - this.m11 = 1.0; - this.m12 = 0.0; - - this.m20 = 0.0; - this.m21 = 0.0; - this.m22 = 1.0; - } - - /** - * Sets values of this matrix to values from param matrix - * - * @param matrix to get values from - */ - public void set(Matrix3D matrix) { - this.m00 = matrix.m00; - this.m01 = matrix.m01; - this.m02 = matrix.m02; - this.m10 = matrix.m10; - this.m11 = matrix.m11; - this.m12 = matrix.m12; - this.m20 = matrix.m20; - this.m21 = matrix.m21; - this.m22 = matrix.m22; - } - - /** - * Sets the values of this matrix to multiply result of this matrix with param matrix - * - * @param matrix to multiply - */ - public void multiply(Matrix3D matrix) { - double n00 = this.m00 * matrix.m00 + this.m01 * matrix.m10 + this.m02 * matrix.m20; - double n01 = this.m00 * matrix.m01 + this.m01 * matrix.m11 + this.m02 * matrix.m21; - double n02 = this.m00 * matrix.m02 + this.m01 * matrix.m12 + this.m02 * matrix.m22; - - double n10 = this.m10 * matrix.m00 + this.m11 * matrix.m10 + this.m12 * matrix.m20; - double n11 = this.m10 * matrix.m01 + this.m11 * matrix.m11 + this.m12 * matrix.m21; - double n12 = this.m10 * matrix.m02 + this.m11 * matrix.m12 + this.m12 * matrix.m22; - - double n20 = this.m20 * matrix.m00 + this.m21 * matrix.m10 + this.m22 * matrix.m20; - double n21 = this.m20 * matrix.m01 + this.m21 * matrix.m11 + this.m22 * matrix.m21; - this.m22 = this.m20 * matrix.m02 + this.m21 * matrix.m12 + this.m22 * matrix.m22; - - this.m00 = n00; - this.m01 = n01; - this.m02 = n02; - - this.m10 = n10; - this.m11 = n11; - this.m12 = n12; - - this.m20 = n20; - this.m21 = n21; - } - - /** - * Transforms param vector with using this matrix - * - * @param vec to transform - */ - public void transform(Vector3D vec) { - double x = this.m00 * vec.getX() + this.m01 * vec.getY() + this.m02 * vec.getZ(); - double y = this.m10 * vec.getX() + this.m11 * vec.getY() + this.m12 * vec.getZ(); - vec.setZ(this.m20 * vec.getX() + this.m21 * vec.getY() + this.m22 * vec.getZ()); - vec.setX(x); - vec.setY(y); - } - - /** - * Sets the values of this matrix to multiply result of this matrix with param scalar - * - * @param scalar multiplier - */ - public void multiply(double scalar) { - this.m00 *= scalar; - this.m01 *= scalar; - this.m02 *= scalar; - - this.m10 *= scalar; - this.m11 *= scalar; - this.m12 *= scalar; - - this.m20 *= scalar; - this.m21 *= scalar; - this.m22 *= scalar; - } - - /** - * Inverts and sets this matrix - */ - public void invert() { - Matrix3D inverse = new Matrix3D(); - double det = det(); - if (det == 0) return; - double factor = 1.0 / det; - - double inverse00 = this.m11 * this.m22 - this.m12 * this.m21; - double inverse01 = this.m02 * this.m21 - this.m01 * this.m22; - double inverse02 = this.m01 * this.m12 - this.m02 * this.m11; - - double inverse10 = this.m12 * this.m20 - this.m10 * this.m22; - double inverse11 = this.m00 * this.m22 - this.m02 * this.m20; - double inverse12 = this.m02 * this.m10 - this.m00 * this.m12; - - double inverse20 = this.m10 * this.m21 - this.m11 * this.m20; - double inverse21 = this.m01 * this.m20 - this.m00 * this.m21; - inverse.m22 = this.m00 * this.m11 - this.m01 * this.m10; - - inverse.m00 = inverse00; - inverse.m01 = inverse01; - inverse.m02 = inverse02; - - inverse.m10 = inverse10; - inverse.m11 = inverse11; - inverse.m12 = inverse12; - - inverse.m20 = inverse20; - inverse.m21 = inverse21; - - inverse.multiply(factor); - this.set(inverse); - } - - /** - * Calculates the determinant of this matrix - * - * @return determinant of matrix - */ - public double det() { - return (this.m00 * this.m11 * this.m22 + - this.m01 * this.m12 * this.m20 + - this.m02 * this.m10 * this.m21 - - this.m02 * this.m11 * this.m20 - - this.m01 * this.m10 * this.m22 - - this.m00 * this.m12 * this.m21); - } -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/ParserGeoMath.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/ParserGeoMath.java deleted file mode 100644 index bfa3dc6..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/ParserGeoMath.java +++ /dev/null @@ -1,80 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.math; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcUnitCatalog; -import org.openstreetmap.gui.jmapviewer.OsmMercator; -import org.openstreetmap.josm.data.coor.LatLon; - -/** - * Class providing math functions for geodetic operations - */ -public class ParserGeoMath { - - /** - * Method transforms cartesian point to latlon point with given latlon origin coordinate (latlon for cartesian 0.0/0.0) - * and cartesian unit like m or cm - * - * @param cartesianPoint to translate to latlon - * @param cartesianOrigin cartesian representation of latLonOfCartesianOrigin - * @param latLonOfCartesianOrigin latlon of cartesian origin (0.0/0.0) - * @param cartesianUnit m or cm - * @return latlon of cartesian point - */ - public static LatLon cartesianToGeodetic(Vector3D cartesianPoint, Vector3D cartesianOrigin, LatLon latLonOfCartesianOrigin, IfcUnitCatalog.LengthUnit cartesianUnit) { - // TODO improve the way of transformation - clean up this method - double originCartX = cartesianOrigin.getX(); - double originCartY = cartesianOrigin.getY(); - double originLat = Math.toRadians(latLonOfCartesianOrigin.lat()); - double originLon = Math.toRadians(latLonOfCartesianOrigin.lon()); - double pointX = cartesianPoint.getX(); - double pointY = cartesianPoint.getY(); - - // get bearing - double bearing = Math.atan2(pointY - originCartY, pointX - originCartX); - bearing = Math.toRadians(90.0) - bearing; - - // get distance - if (cartesianUnit.equals(IfcUnitCatalog.LengthUnit.CM)) { - pointX /= 100.0; - pointY /= 100.0; - } else if (cartesianUnit.equals(IfcUnitCatalog.LengthUnit.MM)) { - pointX /= 1000.0; - pointY /= 1000.0; - } - double d = Math.sqrt(Math.pow((pointX - originCartX), 2) + Math.pow((pointY - originCartY), 2)); - - double pointLat = Math.asin( - Math.sin(originLat) * Math.cos(d / OsmMercator.EARTH_RADIUS) + - Math.cos(originLat) * Math.sin(d / OsmMercator.EARTH_RADIUS) * Math.cos(bearing)); - double pointLon = originLon + - Math.atan2( - Math.sin(bearing) * Math.sin(d / OsmMercator.EARTH_RADIUS) * Math.cos(originLat), - Math.cos(d / OsmMercator.EARTH_RADIUS) - Math.sin(originLat) * Math.sin(pointLat)); - - return new LatLon(Math.toDegrees(pointLat), Math.toDegrees(pointLon)); - } - - public static double degreeMinutesSecondsToLatLon(double degrees, double minutes, double seconds) { - return degrees + (minutes / 60.0) + (seconds / 3600.0); - } - - /** - * Method calculates distance between latlon in meter - * - * @param lat1 first point latitude - * @param lon1 first point longitude - * @param lat2 second point latitude - * @param lon2 second point longitude - * @return distance in meter - */ - public static double getDistance(double lat1, double lon1, double lat2, double lon2) { - double dLat = Math.toRadians(lat2 - lat1); // deg2rad below - double dLon = Math.toRadians(lon2 - lon1); - double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + - Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * - Math.sin(dLon / 2) * Math.sin(dLon / 2); - double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - return (OsmMercator.EARTH_RADIUS * c) * 1e3; - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/ParserMath.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/ParserMath.java deleted file mode 100644 index 12dadf7..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/ParserMath.java +++ /dev/null @@ -1,48 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.math; - -/** - * Class providing transformation and rotation methods - */ -public class ParserMath { - - /** - * Creates x-axis rotation matrix with given angle - * - * @param rotAngle in rad - * @return x-axis rotation matrix - */ - public static Matrix3D getRotationMatrixX(double rotAngle) { - return new Matrix3D( - 1.0, 0.0, 0.0, - 0.0, Math.cos(rotAngle), -Math.sin(rotAngle), - 0.0, Math.sin(rotAngle), Math.cos(rotAngle)); - } - - /** - * Creates y-axis rotation matrix with given angle - * - * @param rotAngle in rad - * @return y-axis rotation matrix - */ - public static Matrix3D getRotationMatrixY(double rotAngle) { - return new Matrix3D( - Math.cos(rotAngle), 0.0, Math.sin(rotAngle), - 0.0, 1.0, 0.0, - -Math.sin(rotAngle), 0.0, Math.cos(rotAngle)); - } - - /** - * Creates z-axis rotation matrix with given angle - * - * @param rotAngle in rad - * @return z-axis rotation matrix - */ - public static Matrix3D getRotationMatrixZ(double rotAngle) { - return new Matrix3D( - Math.cos(rotAngle), -Math.sin(rotAngle), 0.0, - Math.sin(rotAngle), Math.cos(rotAngle), 0.0, - 0.0, 0.0, 1.0); - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/Vector3D.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/Vector3D.java deleted file mode 100644 index 5ec46f9..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/math/Vector3D.java +++ /dev/null @@ -1,161 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.math; - -/** - * Class representing 3D vector - */ -public class Vector3D { - private double x; - private double y; - private double z; - - public Vector3D() { - x = 0.0; - y = 0.0; - z = 0.0; - } - - public Vector3D(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Vector3D(Vector3D vector) { - x = vector.x; - y = vector.y; - z = vector.z; - } - - public void setX(double x) { - this.x = x; - } - - public double getX() { - return x; - } - - public void setY(double y) { - this.y = y; - } - - public double getY() { - return y; - } - - public void setZ(double z) { - this.z = z; - } - - public double getZ() { - return z; - } - - public boolean equalsVector(Vector3D vec) { - if (Math.abs(this.x - vec.x) > .0000001) return false; - if (Math.abs(this.y - vec.y) > .0000001) return false; - if (Math.abs(this.z - vec.z) > .0000001) return false; - - return true; - } - - /** - * Adds param vector to this - * - * @param vector to add - */ - public void add(Vector3D vector) { - this.x += vector.x; - this.y += vector.y; - this.z += vector.z; - } - - public void sub(Vector3D vector) { - this.x -= vector.x; - this.y -= vector.y; - this.z -= vector.z; - } - - /** - * Normalizes this vector - */ - public void normalize() { - double n = 1.0 / Math.sqrt(Math.pow(x, 2.0) + Math.pow(y, 2.0) + Math.pow(z, 2.0)); - this.x *= n; - this.y *= n; - this.z *= n; - } - - /** - * Sets values of this vector to normalized values from param vector - * - * @param vector to normalize and use as source for this vector - */ - public void normalize(Vector3D vector) { - double n = 1.0 / Math.sqrt(Math.pow(vector.x, 2.0) + Math.pow(vector.y, 2.0) + Math.pow(vector.z, 2.0)); - this.x *= n; - this.y *= n; - this.z *= n; - } - - /** - * Sets values of this vector to cross product of params vector1, vector2 - * - * @param vector1 first vector - * @param vector2 second vector - */ - public void cross(Vector3D vector1, Vector3D vector2) { - this.x = vector1.y * vector2.z - vector1.z * vector2.y; - this.y = vector2.x * vector1.z - vector2.z * vector1.x; - this.z = vector1.x * vector2.y - vector1.y * vector2.x; - } - - /** - * Returns dot product of this vector and param vector - * - * @param vector for operation - * @return dot product of this vector and param vector - */ - public double dot(Vector3D vector) { - return (this.x * vector.x + this.y * vector.y + this.z * vector.z); - } - - /** - * Returns squared length of this vector - * - * @return squared length of this vector - */ - public double lengthSquared() { - return (this.x * this.x + this.y * this.y + this.z * this.z); - } - - public void scale(double scalar) { - this.x *= scalar; - this.y *= scalar; - this.z *= scalar; - } - - public double angleBetween(Vector3D vector) { - if (this.equalsVector(vector)) return 0.0; - - // check sign - vector order is important for rotation - double result2DWithSign = Math.atan2(this.getY(), this.getX()) - Math.atan2(vector.getY(), vector.getX()); - - double ab; - double a_abs; - double b_abs; - double r; - if (this.getZ() == 0.0 && vector.getZ() == 0.0) { - return result2DWithSign; - } else { - ab = this.getX() * vector.getX() + this.getY() * vector.getY() + this.getZ() * vector.getZ(); - a_abs = Math.sqrt(Math.pow(this.getX(), 2.0) + Math.pow(this.getY(), 2.0) + Math.pow(this.getZ(), 2.0)); - b_abs = Math.sqrt(Math.pow(vector.getX(), 2.0) + Math.pow(vector.getY(), 2.0) + Math.pow(vector.getZ(), 2.0)); - r = ab / (a_abs * b_abs); - if (result2DWithSign < 0 && Math.acos(r) > 0) return -Math.acos(r); - return Math.acos(r); - - } - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ParserUtility.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ParserUtility.java deleted file mode 100644 index 9abd6ce..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ParserUtility.java +++ /dev/null @@ -1,124 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.Vector3D; -import org.openstreetmap.josm.data.osm.DataSet; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.data.osm.Way; -import org.openstreetmap.josm.tools.Logging; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Parser utility methods - */ -public class ParserUtility { - - /** - * Parses a string vector to {@link Vector3D} - * - * @param vector to parse - * @return parsed vector - */ - public static Vector3D stringVectorToVector3D(List vector) { - if (vector.isEmpty()) return null; - double x = 0.0; - double y = 0.0; - double z = 0.0; - if (vector.size() == 2) { - x = prepareDoubleString(vector.get(0)); - y = prepareDoubleString(vector.get(1)); - } else if (vector.size() > 2) { - x = prepareDoubleString(vector.get(0)); - y = prepareDoubleString(vector.get(1)); - z = prepareDoubleString(vector.get(2)); - } - if (Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z)) { - return null; - } - return new Vector3D(x, y, z); - } - - /** - * Parses string of double value from ifc file into double - * - * @param doubleString String of coordinate - * @return double representing double - */ - public static double prepareDoubleString(String doubleString) { - if (doubleString == null) return Double.NaN; - if (doubleString.endsWith(".")) { - doubleString = doubleString + "0"; - } - try { - return Double.parseDouble(doubleString); - } catch (NumberFormatException e) { - Logging.error(e.getMessage()); - return Double.NaN; - } - } - - /** - * Get list of levels included in dataset - * - * @param ds data set - * @return Level list as {@link ArrayList } - */ - public static ArrayList getLevelList(DataSet ds) { - ArrayList l = new ArrayList<>(); - - // TODO optimize this to avoid running thru all nodes and ways - ds.getNodes().forEach(node -> { - try { - int level = Integer.parseInt(node.get("level")); - if (!l.contains(level)) l.add(level); - } catch (NumberFormatException e) { - // do nothing - } - }); - ds.getWays().forEach(way -> { - try { - int level = Integer.parseInt(way.get("level")); - if (!l.contains(level)) l.add(level); - } catch (NumberFormatException e) { - // do nothing - } - }); - Collections.sort(l); - return l; - } - - /** - * Get level tag of node. - * - * @param node to get level tag - * @return level tag or null - */ - public static Number getLevelTag(Node node) { - if (node == null) return null; - if (node.get("level") != null) { - return Integer.parseInt(node.get("level")); - } - if (!node.getParentWays().isEmpty()) { - return Integer.parseInt(node.getParentWays().get(0).get("level")); - } - return null; - } - - /** - * Checks if both nodes are part of the same way - * - * @param node1 to check - * @param node2 to check - * @return true if both nodes are part of the same way, else false - */ - public static boolean nodesPartOfSameWay(Node node1, Node node2) { - for (Way way : node1.getParentWays()) { - if (way.containsNode(node2)) return true; - } - return false; - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/BIMtoOSMUtility.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/BIMtoOSMUtility.java deleted file mode 100644 index 6a7cef5..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/BIMtoOSMUtility.java +++ /dev/null @@ -1,460 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ifc; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentation; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentationCatalog.IfcSlabTypeEnum; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentationCatalog.RepresentationIdentifier; -import org.openstreetmap.josm.plugins.indoorhelper.io.model.BIMtoOSMCatalog; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.BIMDataCollection; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.BIMObject3D; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.*; -import nl.tue.buildingsmart.express.population.EntityInstance; -import nl.tue.buildingsmart.express.population.ModelPopulation; - -import java.util.ArrayList; -import java.util.List; - -import static org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ParserUtility.stringVectorToVector3D; - -/** - * Class providing useful methods to parse BIM data to OSM data - */ -public class BIMtoOSMUtility { - - /** - * Types of geometry precision - */ - public enum GeometrySolution { - BODY, - BOUNDING_BOX - } - - /** - * Filters important OSM data into internal data structure - * - * @param ifcModel ifcModel - * @return FilteredBIMData including BIM objects of ways, rooms, etc. - */ - public static BIMDataCollection extractMajorBIMData(ModelPopulation ifcModel) { - BIMDataCollection bimData = new BIMDataCollection(); - - // get the root element IfcSite - List ifcSiteObjects = new ArrayList<>(); - BIMtoOSMCatalog.getIFCSITETags().forEach(tag -> ifcSiteObjects.addAll(ifcModel.getInstancesOfType(tag))); - - if (!ifcSiteObjects.isEmpty()) { - bimData.setIfcSite(ifcSiteObjects.get(0)); - } - - // get all relevant areas - List areaObjects = new ArrayList<>(); - BIMtoOSMCatalog.getAreaTags().forEach(tag -> ifcModel.getInstancesOfType(tag).forEach(entity -> { - String identifier = (String) entity.getAttributeValueBN("PredefinedType"); - if (!identifier.equals("." + IfcSlabTypeEnum.ROOF + ".")) { - areaObjects.add(entity); - } - })); - bimData.setAreaObjects(areaObjects); - - // get all walls - List wallObjects = new ArrayList<>(); - BIMtoOSMCatalog.getWallTags().forEach(tag -> wallObjects.addAll(ifcModel.getInstancesOfType(tag))); - bimData.setWallObjects(wallObjects); - - // get all columns - List colObjects = new ArrayList<>(); - BIMtoOSMCatalog.getColumnTags().forEach(tag -> colObjects.addAll(ifcModel.getInstancesOfType(tag))); - bimData.setColumnObjects(colObjects); - - // get all doors - List doorObjects = new ArrayList<>(); - BIMtoOSMCatalog.getDoorTags().forEach(tag -> doorObjects.addAll(ifcModel.getInstancesOfType(tag))); - bimData.setDoorObjects(doorObjects); - - // get all doors - List stairObjects = new ArrayList<>(); - BIMtoOSMCatalog.getStairTags().forEach(tag -> stairObjects.addAll(ifcModel.getInstancesOfType(tag))); - bimData.setStairObjects(stairObjects); - - // get all windows - List windowObjects = new ArrayList<>(); - BIMtoOSMCatalog.getWindowTags().forEach(tag -> windowObjects.addAll(ifcModel.getInstancesOfType(tag))); - bimData.setWindowObjects(windowObjects); - - return bimData; - } - - /** - * Transforms BIM objects for further operations. Extracts OSM relevant information and puts it into {@link BIMObject3D} - * - * @param ifcModel ifcModel - * @param solution geometry solution type - * @param objectType relating BIMtoOSMCatalog.BIMObject - * @param bimObjects All BIM objects of objectType - * @return Transformed BIM objects - */ - public static List transformBIMObjects(ModelPopulation ifcModel, GeometrySolution solution, - BIMtoOSMCatalog.BIMObject objectType, List bimObjects) { - ArrayList transformedObjects = new ArrayList<>(); - - for (EntityInstance objectEntity : bimObjects) { - - BIMObject3D object = transformBIMObject(ifcModel, solution, objectType, objectEntity); - if (object == null) { - continue; - } - - // check for loops in data set - List objectGeometry = object.getCartesianGeometryCoordinates(); - if (!objectGeometry.contains(IfcGeometryExtractor.defaultPoint)) { - List> loops = splitClosedLoops(objectGeometry); - loops.forEach(l -> { - object.setCartesianGeometryCoordinates(l); - transformedObjects.add(object); - }); - } else { - transformedObjects.add(object); - } - } - - return transformedObjects; - } - - /** - * Transform BIM object for further operations. Extracts OSM relevant information and puts it into {@link BIMObject3D} - * - * @param ifcModel ifcModel - * @param solution geometry solution type - * @param objectType relating BIMtoOSMCatalog.BIMObject - * @param objectEntity BIM object of objectType - * @return Transformed BIM object - */ - public static BIMObject3D transformBIMObject(ModelPopulation ifcModel, GeometrySolution solution, - BIMtoOSMCatalog.BIMObject objectType, EntityInstance objectEntity) { - - EntityInstance objectIFCLP = objectEntity.getAttributeValueBNasEntityInstance("ObjectPlacement"); - BIMObject3D object = resolveObjectPlacement(objectIFCLP, new BIMObject3D(objectEntity.getId())); - object.setType(objectType); - Vector3D cartesianOrigin = object.getTranslation(); - Matrix3D rotMatrix = getObjectRotationMatrix(objectEntity); - - // get object geometry - ArrayList shapeDataOfObject = (ArrayList) getShapeData(ifcModel, objectEntity, solution); - - // transform and prepare - if (cartesianOrigin != null && rotMatrix != null && (shapeDataOfObject != null && !shapeDataOfObject.isEmpty())) { - transformPoints(shapeDataOfObject, rotMatrix, cartesianOrigin); - object.setCartesianGeometryCoordinates(shapeDataOfObject); - } else { - return null; - } - - return object; - } - - /** - * Method resolves placement of Ifc object and keeps the result in {@link BIMObject3D} - * - * @param objectPlacementEntity of {@link BIMObject3D} - * @param object to resolve placement of - * @return {@link BIMObject3D} with resolved placement - */ - private static BIMObject3D resolveObjectPlacement(EntityInstance objectPlacementEntity, BIMObject3D object) { - if (object == null) return null; - if (objectPlacementEntity == null) return object; - - // get objects IfcRelativePlacement entity - EntityInstance relativePlacement = objectPlacementEntity.getAttributeValueBNasEntityInstance("RelativePlacement"); - - // get rotation of this entity - Matrix3D rotation = getRotationFromRelativePlacement(relativePlacement); - if (rotation == null) return object; - - // get translation of this entity - Vector3D translation = getTranslationFromRelativePlacement(relativePlacement); - if (translation == null) return object; - - // check if this entity has placement parent (PlacementRelTo) - if (objectPlacementEntity.getAttributeValueBNasEntityInstance("PlacementRelTo") != null) { - EntityInstance placementRelTo = objectPlacementEntity.getAttributeValueBNasEntityInstance("PlacementRelTo"); - resolveObjectPlacement(placementRelTo, object); - // set new rotation - object.getRotation().multiply(rotation); - // set new translation - Matrix3D inverse = new Matrix3D(rotation); - inverse.invert(); - inverse.transform(object.getTranslation()); - object.getTranslation().add(translation); - } - return object; - } - - /** - * Method extracts translation vector from relative placement - * - * @param relativePlacement to get translation information of - * @return translation vector for required object - */ - private static Vector3D getTranslationFromRelativePlacement(EntityInstance relativePlacement) { - EntityInstance cPoint = relativePlacement.getAttributeValueBNasEntityInstance("Location"); - @SuppressWarnings("unchecked") - List objectCoords = (List) cPoint.getAttributeValueBN("Coordinates"); - return stringVectorToVector3D(objectCoords); - } - - /** - * Method extracts rotation matrix from relative placement - * - * @param relativePlacement to get rotation matrix of - * @return rotation matrix - */ - private static Matrix3D getRotationFromRelativePlacement(EntityInstance relativePlacement) { - List refDirection; - List zAxis; - try { - // get RefDirection - EntityInstance refDirectionEntity = relativePlacement.getAttributeValueBNasEntityInstance("RefDirection"); - refDirection = (List) refDirectionEntity.getAttributeValueBN("DirectionRatios"); - // get z-Axis - EntityInstance axisEntity = relativePlacement.getAttributeValueBNasEntityInstance("Axis"); - zAxis = (List) axisEntity.getAttributeValueBN("DirectionRatios"); - } catch (NullPointerException e) { - return null; - } - - Vector3D refDirectionVector = stringVectorToVector3D(refDirection); - Vector3D zAxisVector = stringVectorToVector3D(zAxis); - if (refDirectionVector == null || zAxisVector == null) return null; - - // get x-Axis - Vector3D xAxisVector = retrieveXAxis(zAxisVector, refDirectionVector); - - // build rotation matrix - Vector3D xNorm = new Vector3D(); - xNorm.normalize(xAxisVector); - Vector3D yNorm = new Vector3D(); - yNorm.cross(zAxisVector, xAxisVector); - yNorm.normalize(); - Vector3D zNorm = new Vector3D(); - zNorm.normalize(zAxisVector); - - return new Matrix3D( - xNorm.getX(), xNorm.getY(), xNorm.getZ(), - yNorm.getX(), yNorm.getY(), yNorm.getZ(), - zNorm.getX(), zNorm.getY(), zNorm.getZ() - ); - } - - /** - * Method gets local shape representation of ifc object - * - * @param ifcModel ifcModel - * @param object BIM object - * @return Array including points of shape representation - */ - public static List getShapeData(ModelPopulation ifcModel, EntityInstance object, GeometrySolution solution) { - - List repObjectIdentities = getIfcRepresentations(object); - if (repObjectIdentities == null) return null; - - if (solution.equals(GeometrySolution.BODY)) { - IfcRepresentation bodyRepresentation = getIfcRepresentation(repObjectIdentities, RepresentationIdentifier.Body); - if (bodyRepresentation != null) { - return IfcGeometryExtractor.getDataFromBodyRepresentation(ifcModel, bodyRepresentation); - } - } else if (solution.equals(GeometrySolution.BOUNDING_BOX)) { - IfcRepresentation boxRepresentation = getIfcRepresentation(repObjectIdentities, RepresentationIdentifier.Box); - if (boxRepresentation != null) { - return IfcGeometryExtractor.getDataFromBoxRepresentation(ifcModel, boxRepresentation); - } - } - return null; - } - - /** - * Checks the IfcShapeRepresentation objects for object with - * IfcShapeRepresentation.RepresentationIdentifier = "identifier" and returns it - * - * @param repObjectIdentities IfcShapeRepresentation objects - * @param identifier RepresentationIdentifier - * @return returns IfcShapeRepresentation "identifier" or null if not in list - */ - public static IfcRepresentation getIfcRepresentation(List repObjectIdentities, RepresentationIdentifier identifier) { - for (IfcRepresentation repObject : repObjectIdentities) { - if (repObject.getIdentifier().equals(identifier)) return repObject; - } - return null; - } - - /** - * Gets rotation matrix for ifc object - * - * @param object to get rotation matrix for - * @return rotation matrix - */ - @SuppressWarnings("unchecked") - private static Matrix3D getObjectRotationMatrix(EntityInstance object) { - // get objects IfcLocalPlacement entity - EntityInstance objectIFCLP = object.getAttributeValueBNasEntityInstance("ObjectPlacement"); - - // get all RelativePlacements to root - ArrayList objectRP = getRelativePlacementsToRoot(objectIFCLP, new ArrayList<>()); - - double rotAngleX = 0.0; // in rad - double rotAngleZ = 0.0; // in rad - Vector3D parentXVector = null; - Vector3D parentZVector = null; - - // TODO use one rotation matrix instead of each for each axis - for (EntityInstance relativeObject : objectRP) { - // get RefDirection (x axis vector) - List xDirectionRatios; - List zDirectionRatios; - try { - EntityInstance xAxisEntity = relativeObject.getAttributeValueBNasEntityInstance("RefDirection"); - EntityInstance zAxisEntity = relativeObject.getAttributeValueBNasEntityInstance("Axis"); - xDirectionRatios = (List) xAxisEntity.getAttributeValueBN("DirectionRatios"); - zDirectionRatios = (List) zAxisEntity.getAttributeValueBN("DirectionRatios"); - } catch (NullPointerException e) { - return null; - } - - Vector3D xAxis = stringVectorToVector3D(xDirectionRatios); - if (xAxis == null) return null; - Vector3D zAxis = stringVectorToVector3D(zDirectionRatios); - if (zAxis == null) return null; - xAxis = retrieveXAxis(zAxis, xAxis); - - // get x-axis rotation angle - if (parentXVector != null) { - rotAngleX += parentXVector.angleBetween(xAxis); - } else { - parentXVector = new Vector3D(); - } - // update parent vector - parentXVector.setX(xAxis.getX()); - parentXVector.setY(xAxis.getY()); - parentXVector.setZ(xAxis.getZ()); - - // get z-axis rotation angle - if (parentZVector != null) { - rotAngleZ += parentZVector.angleBetween(zAxis); - } else { - parentZVector = new Vector3D(); - } - // update parent vector - parentZVector.setX(zAxis.getX()); - parentZVector.setY(zAxis.getY()); - parentZVector.setZ(zAxis.getZ()); - } - - Matrix3D xMatrix = ParserMath.getRotationMatrixZ(rotAngleX); - Matrix3D zMatrix = ParserMath.getRotationMatrixX(rotAngleZ); - xMatrix.multiply(zMatrix); - - return xMatrix; - } - - /** - * Method runs recursively through ifc file and collects RelativePlacement EntityInstances from - * start to root entity - * - * @param entity you want to collect the RelativePlacement for - * @param relativePlacementsToRoot empty list at beginning, needed for recursive iteration - * @return List with EntityInstances of RelativePlacement - */ - private static ArrayList getRelativePlacementsToRoot(EntityInstance entity, ArrayList relativePlacementsToRoot) { - if (entity == null) return relativePlacementsToRoot; - - // get objects IfcRelativePlacement entity - EntityInstance relativePlacement = entity.getAttributeValueBNasEntityInstance("RelativePlacement"); - relativePlacementsToRoot.add(relativePlacement); - - // get id of placement relative to this (PlacementRelTo) - EntityInstance placementRelTo = entity.getAttributeValueBNasEntityInstance("PlacementRelTo"); - getRelativePlacementsToRoot(placementRelTo, relativePlacementsToRoot); - - return relativePlacementsToRoot; - } - - /** - * Identifies the type of an IfcRepresentation object. - * - * @param object object to get the IfcProductDefinitionShape.Representations from which will be identified - * @return List of IFCShapeRepresentationIdentity holding an IFC representation object and it's identifier - */ - public static List getIfcRepresentations(EntityInstance object) { - ArrayList repObjectIdentities = new ArrayList<>(); - - // get IfcProductDefinitionShape of object - EntityInstance objectIFCPDS = object.getAttributeValueBNasEntityInstance("Representation"); - // get all IfcShapeRepresentation of object - ArrayList objectRepresentations = - objectIFCPDS.getAttributeValueBNasEntityInstanceList("Representations"); - - // identify each object - for (EntityInstance repObject : objectRepresentations) { - //identify IfcShapeRepresentation type - IfcRepresentation repIdentity = IfcObjectIdentifier.identifyShapeRepresentation(repObject); - repIdentity.setRootEntity(object); - if (!repIdentity.isFilled()) return null; - repObjectIdentities.add(repIdentity); - } - - return repObjectIdentities; - } - - /** - * Transforms the list of points using the given rotation matrix and translation vector - * - * @param points to transform - * @param rotation matrix - * @param translation vector - */ - private static void transformPoints(ArrayList points, Matrix3D rotation, Vector3D translation) { - points.forEach(p -> { - rotation.transform(p); - p.add(translation); - }); - } - - /** - * Gets the actual x-axis vector from reference system - * - * @param zAxis of IfcAxis2Placement3D - * @param refDirection of IfcAxis2Placement3D - * @return actual x-axis vector - */ - private static Vector3D retrieveXAxis(Vector3D zAxis, Vector3D refDirection) { - double d = refDirection.dot(zAxis) / zAxis.lengthSquared(); - Vector3D xAxis = new Vector3D(refDirection); - Vector3D refZ = new Vector3D(zAxis); - refZ.scale(d); - xAxis.sub(refZ); - return xAxis; - } - - /** - * Method finds and slips loops in data set - * - * @param data to check for loops - * @return list with data for each loop - */ - private static List> splitClosedLoops(List data) { - List> loops = new ArrayList<>(); - ArrayList loop = new ArrayList<>(); - for (Vector3D point : data) { - if (point.equalsVector(IfcGeometryExtractor.defaultPoint) && !loop.isEmpty()) { - loops.add(loop); - loop = new ArrayList<>(); - } else if (!point.equalsVector(IfcGeometryExtractor.defaultPoint)) { - loop.add(point); - } - if (data.indexOf(point) == data.size() - 1 && !loop.isEmpty()) { - loops.add(loop); - } - } - return loops; - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/IfcGeometryExtractor.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/IfcGeometryExtractor.java deleted file mode 100644 index 1b9b8c5..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/IfcGeometryExtractor.java +++ /dev/null @@ -1,599 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ifc; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentation; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentationCatalog.*; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.Vector3D; -import nl.tue.buildingsmart.express.population.EntityInstance; -import nl.tue.buildingsmart.express.population.ModelPopulation; -import org.openstreetmap.josm.tools.Logging; - -import java.util.ArrayList; -import java.util.List; - -import static org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ParserUtility.prepareDoubleString; - -/** - * Class providing methods to extract OSM data from BIM data - */ -public class IfcGeometryExtractor { - - public static final Vector3D defaultPoint = new Vector3D(-99.0, -99.0, -99.0); - - /** - * Three boolean operators used in definition of CSG solids. - */ - private enum IfcBooleanOperator { - UNION, - INTERSECTION, - DIFFERENCE - } - - /** - * Extract representation data from IfcRepresentationItem body - * - * @param ifcModel ifc Model - * @param bodyRepresentation representation of body - * @return List of points representing object shape or null if object type not supported - */ - public static List getDataFromBodyRepresentation(ModelPopulation ifcModel, IfcRepresentation bodyRepresentation) { - ArrayList shapeRep = new ArrayList<>(); - - // get IfcObject and RepresentationIdentifier - EntityInstance repObject = bodyRepresentation.getEntity(); - - // get IfcRepresentationItems - ArrayList bodyItems = repObject.getAttributeValueBNasEntityInstanceList("Items"); - - // extract information from IfcRepresentationItems - for (EntityInstance item : bodyItems) { - // get type of item - String repItemType = IfcObjectIdentifier.getRepresentationItemType(ifcModel, bodyRepresentation, item); - if (repItemType == null) return null; - - // handle types - if (repItemType.equals(AdvancedBrepRepresentationTypeItems.IfcAdvancedBrep.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(AdvancedSweptSolidRepresentationTypeItems.IfcSweptDiskSolid.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(AdvancedSweptSolidRepresentationTypeItems.IfcSweptDiskSolidPolygonal.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(BrepRepresentationTypeItems.IfcFacetedBrep.name())) { - ArrayList shapeData = getIfcFacetedBrepGeometry(ifcModel, item); - // check if entity includes(floor-)openings and handle them - // shapeDataWithOpeningHandling will be null, if no openings exists or type of opening not supported - ArrayList shapeDataWithOpeningHandling = handleOpenings(ifcModel, shapeData, bodyRepresentation.getRootEntity()); - if (shapeDataWithOpeningHandling != null) shapeRep.addAll(shapeDataWithOpeningHandling); - else if (shapeData != null) shapeRep.addAll(shapeData); - } else if (repItemType.equals(CSGRepresentationTypeItems.IfcBooleanResult.name())) { - Object operatorObject = item.getAttributeValueBN("Operator"); - if (operatorObject == null) return null; - String operator = operatorObject.toString(); - ArrayList shapeData = null; - if (operator.equals("." + IfcBooleanOperator.DIFFERENCE + ".")) { - shapeData = getIfcBooleanResultGeometry(ifcModel, item, IfcBooleanOperator.DIFFERENCE); - } else if (operator.equals("." + IfcBooleanOperator.INTERSECTION + ".")) { - shapeData = getIfcBooleanResultGeometry(ifcModel, item, IfcBooleanOperator.INTERSECTION); - } else if (operator.equals("." + IfcBooleanOperator.UNION + ".")) { - shapeData = getIfcBooleanResultGeometry(ifcModel, item, IfcBooleanOperator.UNION); - } - // check if entity includes(floor-)openings and handle them - // shapeDataWithOpeningHandling will be null, if no openings exists or type of opening not supported - ArrayList shapeDataWithOpeningHandling = handleOpenings(ifcModel, shapeData, bodyRepresentation.getRootEntity()); - if (shapeDataWithOpeningHandling != null) shapeRep.addAll(shapeDataWithOpeningHandling); - else if (shapeData != null) shapeRep.addAll(shapeData); - } else if (repItemType.equals(CSGRepresentationTypeItems.IfcCsgSolid.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(CSGRepresentationTypeItems.IfcPrimitive3D.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(TessellationRepresentationTypeItems.IfcTessellatedFaceSet.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(ClippingRepresentationTypeItems.IfcBooleanClippingResult.name())) { - ArrayList shapeData = getIfcBooleanResultGeometry(ifcModel, item, IfcBooleanOperator.DIFFERENCE); - // check if entity includes(floor-)openings and handle them - // shapeDataWithOpeningHandling will be null, if no openings exists or type of opening not supported - ArrayList shapeDataWithOpeningHandling = handleOpenings(ifcModel, shapeData, bodyRepresentation.getRootEntity()); - if (shapeDataWithOpeningHandling != null) shapeRep.addAll(shapeDataWithOpeningHandling); - else if (shapeData != null) shapeRep.addAll(shapeData); - } else if (repItemType.equals(SurfaceModelRepresentationTypeItems.IfcTessellatedItem.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(SurfaceModelRepresentationTypeItems.IfcShellBasedSurfaceModel.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(SurfaceModelRepresentationTypeItems.IfcFaceBasedSurfaceModel.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(SweptSolidRepresentationTypeItems.IfcExtrudedAreaSolid.name())) { - ArrayList shapeData = getIfcExtrudedAreaSolidGeometry(ifcModel, item); - // check if entity includes(floor-)openings and handle them - // shapeDataWithOpeningHandling will be null, if no openings exists or type of opening not supported - ArrayList shapeDataWithOpeningHandling = handleOpenings(ifcModel, shapeData, bodyRepresentation.getRootEntity()); - if (shapeDataWithOpeningHandling != null) shapeRep.addAll(shapeDataWithOpeningHandling); - else if (shapeData != null) shapeRep.addAll(shapeData); - } else if (repItemType.equals(SweptSolidRepresentationTypeItems.IfcRevolvedAreaSolid.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else if (repItemType.equals(MappedRepresentationTypeItems.IfcMappedItem.name())) { - // TODO extract data - logUnsupportedRepresentationInfo(repItemType); - } else { - logUnsupportedRepresentationInfo(repItemType); - } - } - - return shapeRep; - } - - /** - * Extract representation data from IfcRepresentationItem box - * - * @param ifcModel ifc Model - * @param boxRepresentation representation of box - * @return List of points representing object shape or null if object type not supported - */ - public static List getDataFromBoxRepresentation(ModelPopulation ifcModel, IfcRepresentation boxRepresentation) { - ArrayList shapeRep = new ArrayList<>(); - - // get IfcObject and RepresentationIdentifier - EntityInstance repObject = boxRepresentation.getEntity(); - - // get IfcRepresentationItems - ArrayList boxItems = repObject.getAttributeValueBNasEntityInstanceList("Items"); - - // extract information from IfcRepresentationItems - for (EntityInstance item : boxItems) { - // get type of IfcRepresentationItem - String repItemType = IfcObjectIdentifier.getRepresentationItemType(ifcModel, boxRepresentation, item); - if (repItemType == null) return null; - - if (repItemType.equals(BoundingBoxRepresentationTypeItems.IfcBoundingBox.name())) { - // get cartesian point of bounding box - EntityInstance cartesianCorner = item.getAttributeValueBNasEntityInstance("Corner"); - Vector3D cPointAsVector3D = ifcCoordinatesToVector3D(cartesianCorner); - if (cPointAsVector3D == null) return null; - double xDim = prepareDoubleString((String) item.getAttributeValueBN("XDim")); - double yDim = prepareDoubleString((String) item.getAttributeValueBN("YDim")); - // get points of shape - ArrayList cartesianPointsOfBB = new ArrayList<>(); - cartesianPointsOfBB.add(new Vector3D(cPointAsVector3D.getX(), cPointAsVector3D.getY(), cPointAsVector3D.getZ())); - cartesianPointsOfBB.add(new Vector3D(cPointAsVector3D.getX() + xDim, cPointAsVector3D.getY(), cPointAsVector3D.getZ())); - cartesianPointsOfBB.add(new Vector3D(cPointAsVector3D.getX() + xDim, cPointAsVector3D.getY() + yDim, cPointAsVector3D.getZ())); - cartesianPointsOfBB.add(new Vector3D(cPointAsVector3D.getX(), cPointAsVector3D.getY() + yDim, cPointAsVector3D.getZ())); - cartesianPointsOfBB.add(new Vector3D(cPointAsVector3D.getX(), cPointAsVector3D.getY(), cPointAsVector3D.getZ())); - shapeRep.addAll(cartesianPointsOfBB); - } else { - logUnsupportedRepresentationInfo(repItemType); - } - } - - return shapeRep; - } - - /** - * Method extracts shape representation coordinates from IfcFacetedBrep object - * - * @param ifcModel ifc model - * @param faceBrepItem to get shape representation coordinates for - * @return points representing shape of IfcFacetedBrep - */ - private static ArrayList getIfcFacetedBrepGeometry(ModelPopulation ifcModel, EntityInstance faceBrepItem) { - // get IfcClosedShell stored in IfcFacetedBrep.Outer - EntityInstance closedShell = faceBrepItem.getAttributeValueBNasEntityInstance("Outer"); - return getIfcClosedShellGeometry(ifcModel, closedShell); - } - - /** - * Method extracts shape representation coordinates from IfcClosedShell object - * - * @param ifcModel ifc model - * @param shellItem to get shape representation coordinates for - * @return points representing shape of IfcClosedShell - */ - private static ArrayList getIfcClosedShellGeometry(ModelPopulation ifcModel, EntityInstance shellItem) { - // get IfcFaces of IfcClosedShell - ArrayList facesOfClosedShell = shellItem.getAttributeValueBNasEntityInstanceList("CfsFaces"); - - // get IfcFaceBounds of every IfcFace - ArrayList faceBoundsOfClosedShell = new ArrayList<>(); - facesOfClosedShell.forEach(face -> faceBoundsOfClosedShell.addAll(face.getAttributeValueBNasEntityInstanceList("Bounds"))); - - // get IfcLoop of every IfcFaceBounds - ArrayList loopsOfClosedShell = new ArrayList<>(); - faceBoundsOfClosedShell.forEach(bound -> loopsOfClosedShell.addAll(bound.getAttributeValueBNasEntityInstanceList("Bound"))); - - // collect points of IfcLoops - ArrayList shapePoints = new ArrayList<>(); - for (EntityInstance loop : loopsOfClosedShell) { - ArrayList pointsOfLoop = getIfcLoopGeometry(ifcModel, loop); - if (pointsOfLoop == null) return null; - // workaround: Add points of each loop to shapePoints. Also add a default point after each loop as separator - // (needed later on for rendering) - shapePoints.addAll(pointsOfLoop); - shapePoints.add(defaultPoint); - } - - return shapePoints; - } - - /** - * Method extracts shape representation coordinates from IfcLoop object - * - * @param ifcModel ifc model - * @param loop to get shape representation coordinates for - * @return points representing shape of IfcLoop - */ - private static ArrayList getIfcLoopGeometry(ModelPopulation ifcModel, EntityInstance loop) { - // get loop type - String loopType = IfcObjectIdentifier.getIFCLoopType(ifcModel, loop); - if (loopType == null) return null; - - if (loopType.equals(LoopSubRepresentationTypeItems.IfcPolyLoop.name())) { - // get all IfcCartesianPoints - ArrayList cartesianPointsOfClosedShell = new ArrayList<>(); - for (EntityInstance cPoint : loop.getAttributeValueBNasEntityInstanceList("Polygon")) { - Vector3D cPointAsVector3D = ifcCoordinatesToVector3D(cPoint); - if (cPointAsVector3D == null) return null; - cartesianPointsOfClosedShell.add(cPointAsVector3D); - } - return cartesianPointsOfClosedShell; - } - - // other loop types are not supported right now - logUnsupportedRepresentationInfo(loopType); - return null; - } - - /** - * Method extracts shape representation coordinates from IfcCurve object - * - * @param ifcModel ifc model - * @param curve to get shape representation coordinates for - * @return points representing shape of IfcCurve - */ - private static ArrayList getIfcCurveGeometry(ModelPopulation ifcModel, EntityInstance curve) { - if (IfcObjectIdentifier.isIfcPolyline(ifcModel, curve)) { - return getIfcPolylineGeometry(curve); - } else if (IfcObjectIdentifier.isIfcCompositeCurve(ifcModel, curve)) { - return getIfcCompositeCurveGeometry(ifcModel, curve); - } else if (IfcObjectIdentifier.isIfcTrimmedCurve(ifcModel, curve)) { - // TODO implement proper; handle trim of basis curve - EntityInstance basisCurve = curve.getAttributeValueBNasEntityInstance("BasisCurve"); - if (basisCurve == null) return null; - return getIfcCurveGeometry(ifcModel, basisCurve); - } else if (IfcObjectIdentifier.isIfcCircle(ifcModel, curve)) { - // TODO implement - logUnsupportedRepresentationInfo(IfcObjectIdentifier.getIfcCurveType(ifcModel, curve)); - return new ArrayList<>(); - } else { - logUnsupportedRepresentationInfo(IfcObjectIdentifier.getIfcCurveType(ifcModel, curve)); - } - return null; - } - - /** - * Method extracts local coordinates of polyline - * - * @param polyline o get coordinates from - * @return coordinates of polyline (local) - */ - private static ArrayList getIfcPolylineGeometry(EntityInstance polyline) { - ArrayList points = polyline.getAttributeValueBNasEntityInstanceList("Points"); - ArrayList cartesianPointsOfSArea = new ArrayList<>(); - points.forEach(point -> { - Vector3D pointAsVector3D = ifcCoordinatesToVector3D(point); - assert pointAsVector3D != null; - cartesianPointsOfSArea.add(new Vector3D(pointAsVector3D.getX(), pointAsVector3D.getY(), 0.0)); - }); - return cartesianPointsOfSArea; - } - - /** - * Method extracts local coordinates of ifcCompositeCurve - * - * @param ifcModel ifc model - * @param curveSegment to get coordinates from - * @return Extracts coordinate data from IfcCompositeCurve - */ - private static ArrayList getIfcCompositeCurveGeometry(ModelPopulation ifcModel, EntityInstance curveSegment) { - ArrayList shapeData = new ArrayList<>(); - ArrayList curveSegments = curveSegment.getAttributeValueBNasEntityInstanceList("Segments"); - for (EntityInstance segment : curveSegments) { - EntityInstance parentCurve = segment.getAttributeValueBNasEntityInstance("ParentCurve"); - ArrayList parentCurveShape = getIfcCurveGeometry(ifcModel, parentCurve); - if (parentCurveShape == null) - return null; // if one element null, return null to void wrong mapped elements - shapeData.addAll(parentCurveShape); - } - if (shapeData.isEmpty()) return null; - return shapeData; - } - - /** - * Extracts coordinate data from IfcBooleanResult. If IfcBooleanResult holds operands of type IfcBooleanResult it will - * recursive run thru every operation. - * - * @param ifcModel ifc model - * @param resultEntity to get coordinates from - * @param operator IfcBooleanOperator - * @return Extracts coordinate data from IfcBooleanResult - */ - private static ArrayList getIfcBooleanResultGeometry(ModelPopulation ifcModel, EntityInstance resultEntity, IfcBooleanOperator operator) { - // get and identify both operands - EntityInstance operand1 = resultEntity.getAttributeValueBNasEntityInstance("FirstOperand"); - EntityInstance operand2 = resultEntity.getAttributeValueBNasEntityInstance("SecondOperand"); - - // extract shape data from operands - ArrayList pointsOfOperand1 = getBooleanOperandGeometry(ifcModel, operand1); - ArrayList pointsOfOperand2 = getBooleanOperandGeometry(ifcModel, operand2); - - if (pointsOfOperand1 == null || pointsOfOperand2 == null) return pointsOfOperand1; - - // do operation - if (operator.equals(IfcBooleanOperator.DIFFERENCE)) { - ArrayList pointsOfOperand1Copy = new ArrayList<>(pointsOfOperand1); - for (Vector3D point1 : pointsOfOperand1) { - for (Vector3D point2 : pointsOfOperand2) { - if (point1.equalsVector(point2)) { - pointsOfOperand1Copy.remove(point1); - } - } - } - return pointsOfOperand1Copy; - } - if (operator.equals(IfcBooleanOperator.INTERSECTION)) { - // TODO implement - logUnsupportedRepresentationInfo(operator.name()); - } - if (operator.equals(IfcBooleanOperator.UNION)) { - // TODO implement - logUnsupportedRepresentationInfo(operator.name()); - } - - logUnsupportedRepresentationInfo(operator.name()); - return null; - } - - /** - * Method extracts shape data from boolean operand. For this the operand will be identified and - * handled dependent on type. - * - * @param ifcModel ifc model - * @param operand to get shape data from - * @return points representing shape of operand - */ - private static ArrayList getBooleanOperandGeometry(ModelPopulation ifcModel, EntityInstance operand) { - String operandType = IfcObjectIdentifier.getIfcBooleanOperandType(ifcModel, operand); - - if (operandType == null) return null; - - if (operandType.equals(IfcBooleanOperandType.IfcSolidModel.name())) { - // TODO implement - logUnsupportedRepresentationInfo(operandType); - } - if (operandType.equals(IfcBooleanOperandType.IfcHalfSpaceSolid.name())) { - // TODO implement - logUnsupportedRepresentationInfo(operandType); - } - if (operandType.equals(IfcBooleanOperandType.IfcPolygonalBoundedHalfSpace.name())) { - return getIfcPolygonalBoundedHalfSpaceGeometry(ifcModel, operand); - } - if (operandType.equals(IfcBooleanOperandType.IfcBooleanResult.name()) || operandType.equals(IfcBooleanOperandType.IfcBooleanClippingResult.name())) { - String operand1Operator = (String) operand.getAttributeValueBN("Operator"); - if (operand1Operator.equals("." + IfcBooleanOperator.DIFFERENCE + ".")) { - return getIfcBooleanResultGeometry(ifcModel, operand, IfcBooleanOperator.DIFFERENCE); - } - if (operand1Operator.equals("." + IfcBooleanOperator.INTERSECTION + ".")) { - return getIfcBooleanResultGeometry(ifcModel, operand, IfcBooleanOperator.INTERSECTION); - } - if (operand1Operator.equals("." + IfcBooleanOperator.UNION + ".")) { - return getIfcBooleanResultGeometry(ifcModel, operand, IfcBooleanOperator.UNION); - } - } - if (operandType.equals(IfcBooleanOperandType.IfcCsgPrimitive3D.name())) { - // TODO implement - logUnsupportedRepresentationInfo(operandType); - } - if (operandType.equals(SweptSolidRepresentationTypeItems.IfcExtrudedAreaSolid.name())) { - return getIfcExtrudedAreaSolidGeometry(ifcModel, operand); - } - if (operandType.equals(IfcBooleanOperandType.IfcFacetedBrep.name())) { - return getIfcFacetedBrepGeometry(ifcModel, operand); - } - - // other types are not supported right now - logUnsupportedRepresentationInfo(operandType); - return null; - } - - /** - * Method gets result shape data from IfcFeatureElementSubtraction operation - * - * @param masterElement of operation (RelatingBuildingElement) - * @param dependentElement of operation (RelatedOpeningElement) - * @return result of IfcFeatureElementSubtraction - */ - private static ArrayList getIfcFeatureElementSubtractionGeometry(ArrayList masterElement, ArrayList dependentElement) { - ArrayList masterElementsCopy = new ArrayList<>(masterElement); - // remove all points from master which are in both lists - for (Vector3D masterPoint : masterElementsCopy) { - dependentElement.forEach(dependentPoint -> { - if (masterPoint.equalsVector(dependentPoint)) { - masterElement.remove(masterPoint); - } - }); - } - // add all points from dependent to master which are not already in master - // for workaround add default point - masterElement.add(defaultPoint); - dependentElement.forEach(dependentPoint -> { - if (!masterElement.contains(dependentPoint)) { - masterElement.add(dependentPoint); - } - }); - - return masterElement; - } - - /** - * Method extracts shape representation coordinates from IfcPolygonalBoundedHalfSpace object - * - * @param ifcModel ifc model - * @param polygon object to get shape coordinates from - * @return points representing shape of IfcPolygonalBoundedHalfSpace - */ - private static ArrayList getIfcPolygonalBoundedHalfSpaceGeometry(ModelPopulation ifcModel, EntityInstance polygon) { - // TODO rotation to parent system necessary? - - // get local origin position - EntityInstance localSystemPosition = polygon.getAttributeValueBNasEntityInstance("Position"); - EntityInstance locationPoint = localSystemPosition.getAttributeValueBNasEntityInstance("Location"); - Vector3D locationVector3D = ifcCoordinatesToVector3D(locationPoint); - if (locationVector3D == null) return null; - - // get boundary - EntityInstance localPolygonBoundary = polygon.getAttributeValueBNasEntityInstance("PolygonalBoundary"); - - // get coordinates of boundary - if (localPolygonBoundary == null) return null; - ArrayList pointsOfPolygonBoundary = getIfcCurveGeometry(ifcModel, localPolygonBoundary); - if (pointsOfPolygonBoundary != null) { - pointsOfPolygonBoundary.forEach(point -> point = new Vector3D(locationVector3D.getX() + point.getX(), locationVector3D.getY() + point.getY(), 0.0)); - return pointsOfPolygonBoundary; - } - - // other types are not supported right now - logUnsupportedRepresentationInfo(IfcObjectIdentifier.getIfcCurveType(ifcModel, localPolygonBoundary)); - return null; - } - - /** - * Method extracts shape representation coordinates from IfcExtrudedAreaSolid object - * - * @param ifcModel ifc model - * @param extrudedArea to get shape representation for - * @return points representing shape of IfcExtrudedAreaSolid - */ - private static ArrayList getIfcExtrudedAreaSolidGeometry(ModelPopulation ifcModel, EntityInstance extrudedArea) { - // get POSITION attribute and extract local object origin coordinates - EntityInstance axisPlacement = extrudedArea.getAttributeValueBNasEntityInstance("Position"); - EntityInstance locationPoint = axisPlacement.getAttributeValueBNasEntityInstance("Location"); - // object axis origin - Vector3D locationVector3D = ifcCoordinatesToVector3D(locationPoint); - if (locationVector3D == null) return null; - - // get IfcProfileDef attribute - EntityInstance profileDef = extrudedArea.getAttributeValueBNasEntityInstance("SweptArea"); - // handle different SweptArea types - String sweptAreaType = IfcObjectIdentifier.getIFCProfileDefType(ifcModel, profileDef); - if (sweptAreaType == null) return null; - - if (sweptAreaType.equals(ProfileDefRepresentationTypeItems.IfcRectangleProfileDef.name())) { - // extract xDim, yDim - double xDim = prepareDoubleString((String) profileDef.getAttributeValueBN("XDim")); - double yDim = prepareDoubleString((String) profileDef.getAttributeValueBN("YDim")); - double halfxDim = xDim / 2.0; - double halfyDim = yDim / 2.0; - - // get points of shape - ArrayList cartesianPointsOfSArea = new ArrayList<>(); - cartesianPointsOfSArea.add(new Vector3D(locationVector3D.getX() - halfxDim, locationVector3D.getY() - halfyDim, 0.0)); - cartesianPointsOfSArea.add(new Vector3D(locationVector3D.getX() + halfxDim, locationVector3D.getY() - halfyDim, 0.0)); - cartesianPointsOfSArea.add(new Vector3D(locationVector3D.getX() + halfxDim, locationVector3D.getY() + halfyDim, 0.0)); - cartesianPointsOfSArea.add(new Vector3D(locationVector3D.getX() - halfxDim, locationVector3D.getY() + halfyDim, 0.0)); - cartesianPointsOfSArea.add(new Vector3D(locationVector3D.getX() - halfxDim, locationVector3D.getY() - halfyDim, 0.0)); - return cartesianPointsOfSArea; - } - if (sweptAreaType.equals(ProfileDefRepresentationTypeItems.IfcArbitraryClosedProfileDef.name())) { - String profileType = (String) profileDef.getAttributeValueBN("ProfileType"); - - if (profileType.equals(".AREA.")) { - EntityInstance outerCurve = profileDef.getAttributeValueBNasEntityInstance("OuterCurve"); - ArrayList curvePoints = getIfcCurveGeometry(ifcModel, outerCurve); - if (curvePoints == null) return null; - curvePoints.forEach(point -> point = new Vector3D(locationVector3D.getX() + point.getX(), locationVector3D.getY() + point.getY(), 0.0)); - return curvePoints; - } - if (profileType.equals(".CURVE.")) { - // TODO implement - logUnsupportedRepresentationInfo(sweptAreaType); - } - } - - // other types are not supported right now - logUnsupportedRepresentationInfo(sweptAreaType); - return null; - } - - /** - * Helper method to handle (floor-)openings in entities. - * Adds opening coordinates to entity shape data. If no opening, returns null - * - * @param ifcModel ifc model - * @param shapeDataOfEntity shape data of entity without opening handling - * @param rootEntityOfShapeDataEntity root entity of shape representation entity - * @return shape data of entity with opening handling or null if no handling or no opening - */ - private static ArrayList handleOpenings(ModelPopulation ifcModel, ArrayList shapeDataOfEntity, EntityInstance rootEntityOfShapeDataEntity) { - if (shapeDataOfEntity == null) return null; - // for now opening handling supported for IFCSLAB only - if (!IfcObjectIdentifier.isIfcSlab(ifcModel, rootEntityOfShapeDataEntity)) return null; - - // get relVoidsElement which describes the opening - EntityInstance relVoidsElement = IfcObjectIdentifier.getRelVoidsElementOfEntity(ifcModel, rootEntityOfShapeDataEntity); - if (relVoidsElement == null) return null; - - // get element which describes the opening - EntityInstance openingElement = relVoidsElement.getAttributeValueBNasEntityInstance("RelatedOpeningElement"); - - if (IfcObjectIdentifier.isIfcOpeningElement(ifcModel, openingElement)) { - // get shape data of RelatedOpeningElement and RelatingBuildingObject - BIMtoOSMUtility.GeometrySolution activeSolution = BIMtoOSMUtility.GeometrySolution.BOUNDING_BOX; // set for now - List shapeDataOfRelatedOpeningElement = BIMtoOSMUtility.getShapeData(ifcModel, openingElement, activeSolution); - // subtract points of shapeDataOfRelatinBuildingElement from shapeDataOfRelatinBuildingElement - return getIfcFeatureElementSubtractionGeometry(shapeDataOfEntity, (ArrayList) shapeDataOfRelatedOpeningElement); - } - - // IfcVoidingFeature as opening element is not supported right now - Logging.info(IfcGeometryExtractor.class.getName() + ": IfcVoidingFeature is not supported right now"); - return null; - } - - /** - * Transforms IfcCartesianCoordinate entity into {@link Vector3D} - * - * @param cartesianCoordinate to transform - * @return coordinate as {@link Vector3D} - */ - public static Vector3D ifcCoordinatesToVector3D(EntityInstance cartesianCoordinate) { - @SuppressWarnings("unchecked") - List objectCoords = (List) cartesianCoordinate.getAttributeValueBN("Coordinates"); - if (objectCoords.isEmpty()) return null; - double x = prepareDoubleString(objectCoords.get(0)); - double y = prepareDoubleString(objectCoords.get(1)); - double z = 0.0; - if (objectCoords.size() == 3) { - z = prepareDoubleString(objectCoords.get(2)); - } - if (Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z)) { - return null; - } - return new Vector3D(x, y, z); - } - - /** - * Logs info if representation type is not supported. - * - * @param representationItemType representation item as string - */ - private static void logUnsupportedRepresentationInfo(String representationItemType) { - Logging.info(IfcGeometryExtractor.class.getName() + ": " + representationItemType + " is not supported right now"); - } - -} diff --git a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/IfcObjectIdentifier.java b/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/IfcObjectIdentifier.java deleted file mode 100644 index 8cadfce..0000000 --- a/src/org/openstreetmap/josm/plugins/indoorhelper/io/parser/utils/ifc/IfcObjectIdentifier.java +++ /dev/null @@ -1,515 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.indoorhelper.io.parser.utils.ifc; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentation; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.data.ifc.IfcRepresentationCatalog.*; -import org.openstreetmap.josm.plugins.indoorhelper.io.model.BIMtoOSMCatalog.BIMObject; -import nl.tue.buildingsmart.express.population.EntityInstance; -import nl.tue.buildingsmart.express.population.ModelPopulation; -import org.openstreetmap.josm.tools.Logging; - -import java.util.ArrayList; - -/** - * Class to identify the type on an IfcShapeRepresentation object - */ -public class IfcObjectIdentifier { - - /** - * Method gets IfcShapeRepresentation.RepresentationIdentifier and IfcShapeRepresentation.RepresentationType of object - * - * @param shapeRepresentation IFCShapeRepresentationIdentity - * @return Returns object containing IfcShapeRepresentation.RepresentationIdentifier and IfcShapeRepresentation.RepresentationType - */ - public static IfcRepresentation identifyShapeRepresentation(EntityInstance shapeRepresentation) { - IfcRepresentation rep = new IfcRepresentation(); - String identifier = prepareRepresentationAttribute(shapeRepresentation.getAttributeValueBN("RepresentationIdentifier").toString()); - String type = prepareRepresentationAttribute(shapeRepresentation.getAttributeValueBN("RepresentationType").toString()); - - // set representationObjectId - rep.setEntity(shapeRepresentation); - - // get identifier - for (RepresentationIdentifier i : RepresentationIdentifier.values()) { - if (identifier.equals(i.name())) { - rep.setIdentifier(i); - break; - } - - } - // get type - for (RepresentationType t : RepresentationType.values()) { - if (type.equals(t.name())) { - rep.setType(t); - break; - } - } - return rep; - } - - /** - * Gets the type of specific IfcShapeRepresentation.ITEM. If item type is not supported for IfcShapeRepresentation.RepresentationType - * method will return null. - * - * @param ifcModel ifcModel - * @param ident IfcRepresentationTypeObject object - * @param item to get the representation type for (IfcShapeRepresentation.ITEM packed into EntityInstance object) - * @return String with IfcShapeRepresentation.ITEM type definition or null if not allowed in standard - */ - public static String getRepresentationItemType(ModelPopulation ifcModel, IfcRepresentation ident, EntityInstance item) { - - if (ident.getType().equals(RepresentationType.AdvancedBrep)) { - ArrayList ifcAdvancedBrep = new ArrayList<>(ifcModel.getInstancesOfType(AdvancedBrepRepresentationTypeItems.IfcAdvancedBrep.name())); - if (ifcAdvancedBrep.contains(item)) return AdvancedBrepRepresentationTypeItems.IfcAdvancedBrep.name(); - - ArrayList ifcFacetedBrep = new ArrayList<>(ifcModel.getInstancesOfType(AdvancedBrepRepresentationTypeItems.IfcFacetedBrep.name())); - if (ifcFacetedBrep.contains(item)) return AdvancedBrepRepresentationTypeItems.IfcFacetedBrep.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.AdvancedSweptSolid)) { - ArrayList ifcSweptDiskSolids = new ArrayList<>(ifcModel.getInstancesOfType(AdvancedSweptSolidRepresentationTypeItems.IfcSweptDiskSolid.name())); - if (ifcSweptDiskSolids.contains(item)) - return AdvancedSweptSolidRepresentationTypeItems.IfcSweptDiskSolid.name(); - - ArrayList ifcSweptDiskSolidPolygonals = new ArrayList<>(ifcModel.getInstancesOfType(AdvancedSweptSolidRepresentationTypeItems.IfcSweptDiskSolidPolygonal.name())); - if (ifcSweptDiskSolidPolygonals.contains(item)) - return AdvancedSweptSolidRepresentationTypeItems.IfcSweptDiskSolidPolygonal.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.Brep)) { - if (ifcModel.getInstancesOfType(BrepRepresentationTypeItems.IfcFacetedBrep.name()).contains(item)) { - return BrepRepresentationTypeItems.IfcFacetedBrep.name(); - } - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.CSG)) { - ArrayList ifcBooleanResults = new ArrayList<>(ifcModel.getInstancesOfType(CSGRepresentationTypeItems.IfcBooleanResult.name())); - if (ifcBooleanResults.contains(item)) return CSGRepresentationTypeItems.IfcBooleanResult.name(); - - ArrayList ifcCSGSolids = new ArrayList<>(ifcModel.getInstancesOfType(CSGRepresentationTypeItems.IfcCsgSolid.name())); - if (ifcCSGSolids.contains(item)) return CSGRepresentationTypeItems.IfcCsgSolid.name(); - - ArrayList ifcPrimitive3Ds = new ArrayList<>(ifcModel.getInstancesOfType(CSGRepresentationTypeItems.IfcPrimitive3D.name())); - if (ifcPrimitive3Ds.contains(item)) return CSGRepresentationTypeItems.IfcPrimitive3D.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.Tessellation)) { - if (ifcModel.getInstancesOfType(TessellationRepresentationTypeItems.IfcTessellatedFaceSet.name()).contains(item)) { - return TessellationRepresentationTypeItems.IfcTessellatedFaceSet.name(); - } - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.Clipping)) { - if (ifcModel.getInstancesOfType(ClippingRepresentationTypeItems.IfcBooleanClippingResult.name()).contains(item)) { - return ClippingRepresentationTypeItems.IfcBooleanClippingResult.name(); - } - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.Curve2D) || ident.getType().equals(RepresentationType.Curve3D)) { - ArrayList ifcBoundedCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcBoundedCurve.name())); - if (ifcBoundedCurves.contains(item)) return CurveRepresentationTypeItems.IfcBoundedCurve.name(); - - ArrayList ifcPolylines = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcPolyline.name())); - if (ifcPolylines.contains(item)) return CurveRepresentationTypeItems.IfcPolyline.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.SurfaceModel)) { - ArrayList ifcTessellatedItems = new ArrayList<>(ifcModel.getInstancesOfType(SurfaceModelRepresentationTypeItems.IfcTessellatedItem.name())); - if (ifcTessellatedItems.contains(item)) - return SurfaceModelRepresentationTypeItems.IfcTessellatedItem.name(); - - ArrayList ifcShellBasedSurfaceModels = new ArrayList<>(ifcModel.getInstancesOfType(SurfaceModelRepresentationTypeItems.IfcShellBasedSurfaceModel.name())); - if (ifcShellBasedSurfaceModels.contains(item)) - return SurfaceModelRepresentationTypeItems.IfcShellBasedSurfaceModel.name(); - - ArrayList ifcFaceBasedSurfaceModels = new ArrayList<>(ifcModel.getInstancesOfType(SurfaceModelRepresentationTypeItems.IfcFaceBasedSurfaceModel.name())); - if (ifcFaceBasedSurfaceModels.contains(item)) - return SurfaceModelRepresentationTypeItems.IfcFaceBasedSurfaceModel.name(); - - ArrayList ifcFacetedBreps = new ArrayList<>(ifcModel.getInstancesOfType(SurfaceModelRepresentationTypeItems.IfcFacetedBrep.name())); - if (ifcFacetedBreps.contains(item)) return SurfaceModelRepresentationTypeItems.IfcFacetedBrep.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.SweptSolid)) { - ArrayList ifcExtrudedAreaSolid = new ArrayList<>(ifcModel.getInstancesOfType(SweptSolidRepresentationTypeItems.IfcExtrudedAreaSolid.name())); - if (ifcExtrudedAreaSolid.contains(item)) - return SweptSolidRepresentationTypeItems.IfcExtrudedAreaSolid.name(); - - ArrayList ifcRevolvedAreaSolid = new ArrayList<>(ifcModel.getInstancesOfType(SweptSolidRepresentationTypeItems.IfcRevolvedAreaSolid.name())); - if (ifcRevolvedAreaSolid.contains(item)) - return SweptSolidRepresentationTypeItems.IfcRevolvedAreaSolid.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.BoundingBox)) { - if (ifcModel.getInstancesOfType(BoundingBoxRepresentationTypeItems.IfcBoundingBox.name()).contains(item)) { - return BoundingBoxRepresentationTypeItems.IfcBoundingBox.name(); - } - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - if (ident.getType().equals(RepresentationType.MappedRepresentation)) { - if (ifcModel.getInstancesOfType(MappedRepresentationTypeItems.IfcMappedItem.name()).contains(item)) { - return MappedRepresentationTypeItems.IfcMappedItem.name(); - } - Logging.info(IfcObjectIdentifier.class.getName() + ": " + item.getEntityDefinition() + " is not supported"); - return null; - } - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + ident.getType() + " RepresentationType is not supported"); - return null; - } - - - /** - * Gets the type of IfcLoop. Types can be IfcEdgeLoop, IfcPolyLoop, IfcPolyLoop - * - * @param ifcModel ifcModel - * @param loop to get type of - * @return type as string - */ - public static String getIFCLoopType(ModelPopulation ifcModel, EntityInstance loop) { - ArrayList edgeLoops = new ArrayList<>(ifcModel.getInstancesOfType(LoopSubRepresentationTypeItems.IfcEdgeLoop.name())); - if (edgeLoops.contains(loop)) return LoopSubRepresentationTypeItems.IfcEdgeLoop.name(); - - ArrayList polyLoops = new ArrayList<>(ifcModel.getInstancesOfType(LoopSubRepresentationTypeItems.IfcPolyLoop.name())); - if (polyLoops.contains(loop)) return LoopSubRepresentationTypeItems.IfcPolyLoop.name(); - - ArrayList vertexLoops = new ArrayList<>(ifcModel.getInstancesOfType(LoopSubRepresentationTypeItems.IfcVertexLoop.name())); - if (vertexLoops.contains(loop)) return LoopSubRepresentationTypeItems.IfcVertexLoop.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + loop.getEntityDefinition() + " LoopRepresentationType is not supported"); - return null; - } - - /** - * Gets the type of IFCPROFILEDEF. - * - * @param ifcModel ifcModel - * @param profileDef to get type of - * @return type as string - */ - public static String getIFCProfileDefType(ModelPopulation ifcModel, EntityInstance profileDef) { - ArrayList rectanglePD = new ArrayList<>(ifcModel.getInstancesOfType(ProfileDefRepresentationTypeItems.IfcRectangleProfileDef.name())); - - if (rectanglePD.contains(profileDef)) return ProfileDefRepresentationTypeItems.IfcRectangleProfileDef.name(); - - ArrayList trapeziumPD = new ArrayList<>(ifcModel.getInstancesOfType(ProfileDefRepresentationTypeItems.IfcTrapeziumProfileDef.name())); - if (trapeziumPD.contains(profileDef)) return ProfileDefRepresentationTypeItems.IfcTrapeziumProfileDef.name(); - - ArrayList circlePD = new ArrayList<>(ifcModel.getInstancesOfType(ProfileDefRepresentationTypeItems.IfcCircleProfileDef.name())); - if (circlePD.contains(profileDef)) return ProfileDefRepresentationTypeItems.IfcCircleProfileDef.name(); - - ArrayList ellipsePD = new ArrayList<>(ifcModel.getInstancesOfType(ProfileDefRepresentationTypeItems.IfcEllipseProfileDef.name())); - if (ellipsePD.contains(profileDef)) return ProfileDefRepresentationTypeItems.IfcEllipseProfileDef.name(); - - ArrayList shapePD = new ArrayList<>(ifcModel.getInstancesOfType(ProfileDefRepresentationTypeItems.IfcShapeProfileDef.name())); - if (shapePD.contains(profileDef)) return ProfileDefRepresentationTypeItems.IfcShapeProfileDef.name(); - - ArrayList arbitraryPD = new ArrayList<>(ifcModel.getInstancesOfType(ProfileDefRepresentationTypeItems.IfcArbitraryClosedProfileDef.name())); - if (arbitraryPD.contains(profileDef)) - return ProfileDefRepresentationTypeItems.IfcArbitraryClosedProfileDef.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + profileDef.getEntityDefinition() + " ProfileDefRepresentationType is not supported"); - return null; - } - - /** - * Method gets type of IfcBooleanOperand - * - * @param ifcModel ifc model - * @param entity to get type of - * @return type of IfcBooleanOperand - */ - public static String getIfcBooleanOperandType(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList extrudedAreas = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcExtrudedAreaSolid.name())); - if (extrudedAreas.contains(entity)) return IfcBooleanOperandType.IfcExtrudedAreaSolid.name(); - - ArrayList facetedBreps = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcFacetedBrep.name())); - if (facetedBreps.contains(entity)) return IfcBooleanOperandType.IfcFacetedBrep.name(); - - ArrayList solidModels = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcSolidModel.name())); - if (solidModels.contains(entity)) return IfcBooleanOperandType.IfcSolidModel.name(); - - ArrayList csgSolid = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcCsgSolid.name())); - if (csgSolid.contains(entity)) return IfcBooleanOperandType.IfcCsgSolid.name(); - - ArrayList manifoldSolid = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcManifoldSolidBrep.name())); - if (manifoldSolid.contains(entity)) return IfcBooleanOperandType.IfcManifoldSolidBrep.name(); - - ArrayList sweptAreaSolid = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcSweptAreaSolid.name())); - if (sweptAreaSolid.contains(entity)) return IfcBooleanOperandType.IfcSweptAreaSolid.name(); - - ArrayList sweptDiskSolid = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcSweptDiskSolid.name())); - if (sweptDiskSolid.contains(entity)) return IfcBooleanOperandType.IfcSweptDiskSolid.name(); - - ArrayList halfSpaceSolids = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcHalfSpaceSolid.name())); - if (halfSpaceSolids.contains(entity)) return IfcBooleanOperandType.IfcHalfSpaceSolid.name(); - - ArrayList boxedHalfSpaceSolids = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcBoxedHalfSpace.name())); - if (boxedHalfSpaceSolids.contains(entity)) return IfcBooleanOperandType.IfcBoxedHalfSpace.name(); - - ArrayList polygonBoundedHalfSpaces = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcPolygonalBoundedHalfSpace.name())); - if (polygonBoundedHalfSpaces.contains(entity)) return IfcBooleanOperandType.IfcPolygonalBoundedHalfSpace.name(); - - ArrayList booleanResults = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcBooleanResult.name())); - if (booleanResults.contains(entity)) return IfcBooleanOperandType.IfcBooleanResult.name(); - - ArrayList clippingResult = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcBooleanClippingResult.name())); - if (clippingResult.contains(entity)) return IfcBooleanOperandType.IfcBooleanClippingResult.name(); - - ArrayList csgPrimitive3Ds = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcCsgPrimitive3D.name())); - if (csgPrimitive3Ds.contains(entity)) return IfcBooleanOperandType.IfcCsgPrimitive3D.name(); - - ArrayList blocks = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcBlock.name())); - if (blocks.contains(entity)) return IfcBooleanOperandType.IfcBlock.name(); - - ArrayList rectPyramids = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcRectangularPyramid.name())); - if (rectPyramids.contains(entity)) return IfcBooleanOperandType.IfcRectangularPyramid.name(); - - ArrayList rightCircularCones = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcRightCircularCone.name())); - if (rightCircularCones.contains(entity)) return IfcBooleanOperandType.IfcRightCircularCone.name(); - - ArrayList rightCircularCylinders = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcRightCircularCylinder.name())); - if (rightCircularCylinders.contains(entity)) return IfcBooleanOperandType.IfcRightCircularCylinder.name(); - - ArrayList spheres = new ArrayList<>(ifcModel.getInstancesOfType(IfcBooleanOperandType.IfcSphere.name())); - if (spheres.contains(entity)) return IfcBooleanOperandType.IfcSphere.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + entity.getEntityDefinition() + " is not supported as IfcBooleanOperand"); - return null; - } - - /** - * Method gets type of IfcBoundedCurve - * - * @param ifcModel ifc model - * @param entity to get type of - * @return type of IfcBoundedCurve - */ - public static String getIfcCurveType(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList compositeCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcCompositeCurve.name())); - if (compositeCurves.contains(entity)) return CurveRepresentationTypeItems.IfcCompositeCurve.name(); - - ArrayList polylines = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcPolyline.name())); - if (polylines.contains(entity)) return CurveRepresentationTypeItems.IfcPolyline.name(); - - ArrayList trimmedCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcTrimmedCurve.name())); - if (trimmedCurves.contains(entity)) return CurveRepresentationTypeItems.IfcTrimmedCurve.name(); - - ArrayList bSplineCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcBSplineCurve.name())); - if (bSplineCurves.contains(entity)) return CurveRepresentationTypeItems.IfcBSplineCurve.name(); - - ArrayList conicCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcConic.name())); - if (conicCurves.contains(entity)) return CurveRepresentationTypeItems.IfcConic.name(); - - ArrayList circleCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcCircle.name())); - if (circleCurves.contains(entity)) return CurveRepresentationTypeItems.IfcCircle.name(); - - ArrayList ellCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcEllipse.name())); - if (ellCurves.contains(entity)) return CurveRepresentationTypeItems.IfcEllipse.name(); - - ArrayList lineCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcLine.name())); - if (lineCurves.contains(entity)) return CurveRepresentationTypeItems.IfcLine.name(); - - ArrayList offsetCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcOffsetCurve2D.name())); - if (offsetCurves.contains(entity)) return CurveRepresentationTypeItems.IfcOffsetCurve2D.name(); - - ArrayList offsetCurves3D = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcOffsetCurve3D.name())); - if (offsetCurves3D.contains(entity)) return CurveRepresentationTypeItems.IfcOffsetCurve3D.name(); - - ArrayList indexesCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcIndexedPolyCurve.name())); - if (indexesCurves.contains(entity)) return CurveRepresentationTypeItems.IfcIndexedPolyCurve.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + entity.getEntityDefinition() + " is not supported as IfcBoundedCurveType"); - return null; - } - - /** - * Method gets type of IfcSpatialStructureElement - * - * @param ifcModel ifc model - * @param entity to get type of - * @return type of IfcSpatialStructureElement - */ - public static String getSpatialStructureElementType(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList buildings = new ArrayList<>(ifcModel.getInstancesOfType(IfcSpatialStructureElementTypes.IfcBuilding.name())); - if (buildings.contains(entity)) return IfcSpatialStructureElementTypes.IfcBuilding.name(); - - ArrayList storeys = new ArrayList<>(ifcModel.getInstancesOfType(IfcSpatialStructureElementTypes.IfcBuildingStorey.name())); - if (storeys.contains(entity)) return IfcSpatialStructureElementTypes.IfcBuildingStorey.name(); - - ArrayList spaces = new ArrayList<>(ifcModel.getInstancesOfType(IfcSpatialStructureElementTypes.IfcSpace.name())); - if (spaces.contains(entity)) return IfcSpatialStructureElementTypes.IfcSpace.name(); - - ArrayList sites = new ArrayList<>(ifcModel.getInstancesOfType(IfcSpatialStructureElementTypes.IfcSite.name())); - if (sites.contains(entity)) return IfcSpatialStructureElementTypes.IfcSite.name(); - - Logging.info(IfcObjectIdentifier.class.getName() + ": " + entity.getEntityDefinition() + " is not supported as IfcSpatialStructureElement"); - return null; - } - - /** - * Checks if entity is part of IfcRelVoidsElement, if yes than returns IfcRelVoidsElement, else null - * - * @param ifcModel ifc model - * @param entity to get IfcRelVoidsElement for - * @return if entity part of an IfcRelVoidsElement the EntityInstance if IfcRelVoidsElement, else null - */ - public static EntityInstance getRelVoidsElementOfEntity(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList relVoidsElements = new ArrayList<>(ifcModel.getInstancesOfType(BIMObject.IfcRelVoidsElement.name())); - for (EntityInstance relVoidsElement : relVoidsElements) { - int relatingBuildingElementId = relVoidsElement.getAttributeValueBNasEntityInstance("RelatingBuildingElement").getId(); - if (relatingBuildingElementId == entity.getId()) return relVoidsElement; - } - return null; - } - - /** - * Checks if entity is of type IfcPolyline - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcPolyline, else false - */ - public static boolean isIfcPolyline(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList polylines = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcPolyline.name())); - return polylines.contains(entity); - } - - /** - * Checks if entity is of type IfcCompositeCurve - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcCompositeCurve, else false - */ - public static boolean isIfcCompositeCurve(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList cCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcCompositeCurve.name())); - return cCurves.contains(entity); - } - - /** - * Checks if entity is of type IfcTrimmedCurve - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcTrimmedCurve, else false - */ - public static boolean isIfcTrimmedCurve(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList tCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcTrimmedCurve.name())); - return tCurves.contains(entity); - } - - /** - * Checks if entity is of type IfcCircle - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcCircle, else false - */ - public static boolean isIfcCircle(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList cCurves = new ArrayList<>(ifcModel.getInstancesOfType(CurveRepresentationTypeItems.IfcCircle.name())); - return cCurves.contains(entity); - } - - /** - * Checks if entity is of type IfcAxis2Placement3D - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcAxis2Placement3D, else false - */ - public static boolean isIfcAxis2Placement3D(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList axis2placement3Ds = new ArrayList<>(ifcModel.getInstancesOfType(Axis2PlacementRepresentationTypeItems.IfcAxis2Placement3D.name())); - return axis2placement3Ds.contains(entity); - } - - /** - * Checks if entity is of type IfcOpeningElement - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcOpeningElement, else false - */ - public static boolean isIfcOpeningElement(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList openingElement = new ArrayList<>(ifcModel.getInstancesOfType(IfcRelVoidsElementTypes.IfcOpeningElement.name())); - return openingElement.contains(entity); - } - - /** - * Checks if entity is of type IfcSlab - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcSlab, else false - */ - public static boolean isIfcSlab(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList slabElements = new ArrayList<>(ifcModel.getInstancesOfType(BIMObject.IfcSlab.name())); - return slabElements.contains(entity); - } - - /** - * Checks if entity is of type IfcDoor - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcDoor, else false - */ - public static boolean isIfcDoor(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList doorElements = new ArrayList<>(ifcModel.getInstancesOfType(BIMObject.IfcDoor.name())); - return doorElements.contains(entity); - } - - /** - * Checks if entity is of type IfcWindow - * - * @param ifcModel ifc model - * @param entity to check type of - * @return true if IfcWindow, else false - */ - public static boolean isIfcWindow(ModelPopulation ifcModel, EntityInstance entity) { - ArrayList windowElements = new ArrayList<>(ifcModel.getInstancesOfType(BIMObject.IfcWindow.name())); - return windowElements.contains(entity); - } - - public static boolean isIfcWindowOrIfcDoor(ModelPopulation ifcModel, EntityInstance entity) { - return isIfcWindow(ifcModel, entity) || isIfcDoor(ifcModel, entity); - } - - /** - * Removes unnecessary chars from representation attribute string - * - * @param attribute representation attribute (RepresentationIdentifier, RepresentationType) - * @return prepared string - */ - private static String prepareRepresentationAttribute(String attribute) { - return attribute.substring(1, attribute.length() - 1); - } - -} - diff --git a/test/unit/io/parser/BIMtoOSMParserTest.java b/test/unit/io/parser/BIMtoOSMParserTest.java deleted file mode 100644 index cfbd1ee..0000000 --- a/test/unit/io/parser/BIMtoOSMParserTest.java +++ /dev/null @@ -1,64 +0,0 @@ -// License: AGPL. For details, see LICENSE file. -package io.parser; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.BIMtoOSMParser; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.jupiter.api.Disabled; -import org.openstreetmap.josm.TestUtils; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Unit tests of {@link BIMtoOSMParser} class. - */ -@Ignore("Causes unexpected error in Jenkins build") -@Disabled("Causes unexpected error in Jenkins build\n") -public class BIMtoOSMParserTest { - - /** - * Setup test. - */ -// @Rule -// public JOSMTestRules test = new JOSMTestRules().preferences(); - - String pluginDir = System.getProperty("user.dir"); - String resourcePathDir = TestUtils.getTestDataRoot(); - - /** - * Test case for {@link BIMtoOSMParser#parse} method. - */ - @Test - public void testParse() { - // IFC2X3 - assertParseTrue("test1_IFC2X3_TC1.ifc"); - assertParseTrue("test2_IFC2X3_TC1.ifc"); - - // IFC4 - disabled for now - causes ExceptionInInitializerError in test case but works with JOSM BIM-import functionality -// assertParseTrue("test1_IFC4.ifc"); -// assertParseTrue("test2_IFC4.ifc"); - - // Pre-Optimize test - files with block comments (_BC) - assertParseTrue("test1_IFC2X3_TC1_BC.ifc"); - assertParseFalse("test2_IFC2X3_TC1_BC.ifc"); - - // Cannot load because of missing IFCSITE element - assertParseFalse("test3_IFC4.ifc"); - assertParseFalse("test4_IFC4.ifc"); - - // Schema is not supported - assertParseFalse("test1_IFC4X2.ifc"); - assertParseFalse("test1_IFC4X3.ifc"); - } - - private void assertParseFalse(String filename) { - String ifcTestFile = resourcePathDir + filename; - assertFalse(new BIMtoOSMParser(null, pluginDir).parse(ifcTestFile), ifcTestFile); - } - - private void assertParseTrue(String filename) { - String ifcTestFile = resourcePathDir + filename; - assertTrue(new BIMtoOSMParser(null, pluginDir).parse(ifcTestFile), ifcTestFile); - } -} diff --git a/test/unit/io/parser/data/math/Matrix3DTest.java b/test/unit/io/parser/data/math/Matrix3DTest.java deleted file mode 100644 index 2774cf8..0000000 --- a/test/unit/io/parser/data/math/Matrix3DTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package io.parser.data.math; - -//import org.junit.jupiter.api.Test; - -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.Matrix3D; -import org.openstreetmap.josm.plugins.indoorhelper.io.parser.math.Vector3D; -import org.junit.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Unit tests of {@link Matrix3D} class. - */ -public class Matrix3DTest { - /** - * Setup test - */ - Vector3D vector1 = new Vector3D(2.1, 3.1, 9.4); - - Matrix3D matrix1 = new Matrix3D( - 1.2, 5.4, 7.1, - 3.0, 4.2, 9.2, - 10.1, 6.23, 9.0); - - Matrix3D matrix2 = new Matrix3D( - 4.9, 5.4, 9.55, - 0.1, 1.7, 1.1, - 8.1, 6.23, 99.1); - - Matrix3D matrix3 = new Matrix3D( - 1, 2, 0, - 2, 4, 1, - 2, 1, 0); - - Vector3D matrix1TransformedPoint1 = new Vector3D(86.0, 105.8, 125.123); - - @Test - public void testTransform() { - Vector3D v = new Vector3D(vector1); - matrix1.transform(v); - assertEquals(v.getX(), matrix1TransformedPoint1.getX(), 0.005); - assertEquals(v.getY(), matrix1TransformedPoint1.getY(), 0.005); - assertEquals(v.getZ(), matrix1TransformedPoint1.getZ(), 0.005); - } - - @Test - public void testMultiply() { - Matrix3D m = new Matrix3D(matrix1); - m.multiply(10.0); - assertEquals(m.getM00(), matrix1.getM00() * 10.0, 0.005); - assertEquals(m.getM01(), matrix1.getM01() * 10.0, 0.005); - assertEquals(m.getM02(), matrix1.getM02() * 10.0, 0.005); - - assertEquals(m.getM10(), matrix1.getM10() * 10.0, 0.005); - assertEquals(m.getM11(), matrix1.getM11() * 10.0, 0.005); - assertEquals(m.getM12(), matrix1.getM12() * 10.0, 0.005); - - assertEquals(m.getM20(), matrix1.getM20() * 10.0, 0.005); - assertEquals(m.getM21(), matrix1.getM21() * 10.0, 0.005); - assertEquals(m.getM22(), matrix1.getM22() * 10.0, 0.005); - - Matrix3D m1 = new Matrix3D(matrix2); - m1.multiply(8.5); - assertEquals(m1.getM00(), matrix2.getM00() * 8.5, 0.005); - assertEquals(m1.getM01(), matrix2.getM01() * 8.5, 0.005); - assertEquals(m1.getM02(), matrix2.getM02() * 8.5, 0.005); - - assertEquals(m1.getM10(), matrix2.getM10() * 8.5, 0.005); - assertEquals(m1.getM11(), matrix2.getM11() * 8.5, 0.005); - assertEquals(m1.getM12(), matrix2.getM12() * 8.5, 0.005); - - assertEquals(m1.getM20(), matrix2.getM20() * 8.5, 0.005); - assertEquals(m1.getM21(), matrix2.getM21() * 8.5, 0.005); - assertEquals(m1.getM22(), matrix2.getM22() * 8.5, 0.005); - } - - @Test - public void testInvert() { - Matrix3D m = new Matrix3D(matrix3); - m.invert(); - - assertEquals(m.getM00(), -(1.0 / 3.0), 0.005); - assertEquals(m.getM01(), 0.0, 0.005); - assertEquals(m.getM02(), (2.0 / 3.0), 0.005); - - assertEquals(m.getM10(), (2.0 / 3.0), 0.005); - assertEquals(m.getM11(), 0.0, 0.005); - assertEquals(m.getM12(), -(1.0 / 3.0), 0.005); - - assertEquals(m.getM20(), -2.0, 0.005); - assertEquals(m.getM21(), 1.0, 0.005); - assertEquals(m.getM22(), 0.0, 0.005); - } - - @Test - public void testDet() { - assertEquals(matrix3.det(), 3.0); - } -} \ No newline at end of file diff --git a/test/unit/io/parser/optimizer/OutputOptimizerTest.java b/test/unit/io/parser/optimizer/OutputOptimizerTest.java deleted file mode 100644 index c47a613..0000000 --- a/test/unit/io/parser/optimizer/OutputOptimizerTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.parser.optimizer; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import org.openstreetmap.josm.plugins.indoorhelper.io.optimizer.OutputOptimizer; -import org.junit.Test; -import org.junit.jupiter.api.Disabled; -import org.openstreetmap.josm.data.coor.LatLon; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.testutils.DatasetFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -@Disabled("Causes java.lang.SecurityException: class \"org.openstreetmap.josm.tools.MemoryManagerTest\"'s " + - "signer information does not match signer information of other classes in the same package\n") -public class OutputOptimizerTest { - - /** - * Setup test. - */ -// @Rule -// public JOSMTestRules test = new JOSMTestRules().preferences(); - @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - - public ArrayList testNodes1 = new ArrayList() { - { - add(new LatLon(50.81400880917, 12.9240191164)); - add(new LatLon(50.81410474868, 12.92479892858)); - add(new LatLon(50.81385983524, 12.92487440414)); - add(new LatLon(50.81376389523, 2.92409459195)); - add(new LatLon(50.81400148316, 12.92402966682)); - add(new LatLon(50.81377465301, 12.92411024043)); - add(new LatLon(50.81378210558, 12.92416279334)); - add(new LatLon(50.81400893569, 12.92408221974)); - add(new LatLon(50.81400798293, 12.92402096965)); - add(new LatLon(50.81400418702, 12.92402214016)); - add(new LatLon(50.8140999079, 12.92479970393)); - add(new LatLon(50.81410370381, 12.92479853342)); - } - }; - - /** - * Test case for {@link OutputOptimizer#optimize} method. - */ - @Test - public void testOptimize() { -// ArrayList nodes = llsToNodes(testNodes1); -// ArrayList ways = new ArrayList<>(); -// Pair, ArrayList> testData = new Pair<>(nodes, ways); -// OutputOptimizer.optimize(testData); - // TODO implement after fixing java.lang.SecurityException - } - - private ArrayList llsToNodes(List lls) { - ArrayList nodes = new ArrayList<>(); - AtomicInteger id = new AtomicInteger(); - lls.forEach(ll -> nodes.add(llToNode(ll, id.incrementAndGet()))); - return nodes; - } - - private Node llToNode(LatLon ll, int id) { - DatasetFactory dsFactory = new DatasetFactory(); - dsFactory.addNode(id); - Node n = dsFactory.getNode(id); - n.setCoor(ll); - return n; - } -} \ No newline at end of file