// Constructors public FittingModel(string fittingModelId, FittingType fittingType, BoundingBox3D boundingBox) { Id = fittingModelId; FittingType = fittingType; BoundingBox = boundingBox; }
public FittingModel(string fittingModelId, FittingType fittingType, float width, float depth, float height) { Id = fittingModelId; FittingType = fittingType; BoundingBox = new BoundingBox3D(width, depth, height); }
// Methods /// <summary>Load fitting semantics from XML file to memory</summary> public void LoadFittingSemantics(String semanticsFilePath = DefaultSemanticsFilePath) { // Add default face types faceTypes = new List <FaceType>(); faceTypes.Add(wallFaceType); faceTypes.Add(doorFaceType); faceTypes.Add(windowFaceType); // Open semantics XML document file XDocument doc = XDocument.Load(semanticsFilePath); // Load face types List <Tuple <XElement, FaceType> > xFaceTypeRelations = new List <Tuple <XElement, FaceType> >(); foreach (XElement xFaceType in doc.Element("fitting_database").Element("face_types").Elements("face_type")) { faceTypes.Add(new FaceType( xFaceType.Element("face_type_id").Value )); // Save spatial relation elements if (xFaceType.Element("relations") != null) { foreach (XElement xSpatialRelation in xFaceType.Element("relations").Elements("relation")) { xFaceTypeRelations.Add(new Tuple <XElement, FaceType>(xSpatialRelation, faceTypes[faceTypes.Count - 1])); } } } // Load face relations foreach (Tuple <XElement, FaceType> xFaceTypeRelationTuple in xFaceTypeRelations) { XElement xFaceTypeRelation = xFaceTypeRelationTuple.Item1; FaceType relatedFaceType = faceTypes.Find(faceTypeEvaluated => faceTypeEvaluated.Id == xFaceTypeRelation.Element("support_face_type_id").Value); xFaceTypeRelationTuple.Item2.AddRelation( new SpatialRelation( relatedFaceType, (float)(double)xFaceTypeRelation.Element("distance") ) ); } // Load fitting types fittingTypes = new List <FittingType>(); foreach (XElement xFittingType in doc.Element("fitting_database").Element("fitting_types").Elements("fitting_type")) { // Create and add fitting type FittingType fittingType = new FittingType(xFittingType.Element("fitting_type_id").Value); fittingTypes.Add(fittingType); // Save face elements foreach (XElement xFace in xFittingType.Element("faces").Elements("face")) { // Parse and cast facing enum Facing facing; Enum.TryParse <Facing>(xFace.Element("facing").Value, true, out facing); fittingType.AddFace( new Face( facing, faceTypes.Find(faceTypeEvaluated => faceTypeEvaluated.Id == xFace.Element("face_type_id").Value) ) ); } } // Load fitting models fittingModels = new List <FittingModel>(); foreach (XElement xFittingModel in doc.Element("fitting_database").Element("fitting_models").Elements("fitting_model")) { // Parse fitting type and find reference string typeId = xFittingModel.Element("fitting_type_id").Value; FittingType fittingType = fittingTypes.Find(fittingTypeEvaluated => fittingTypeEvaluated.Id == typeId); // Create fitting model with parsed values FittingModel fittingModel = new FittingModel( xFittingModel.Element("fitting_model_id").Value, fittingType, (float)(double)xFittingModel.Element("bounding_box").Element("width"), (float)(double)xFittingModel.Element("bounding_box").Element("depth"), (float)(double)xFittingModel.Element("bounding_box").Element("height") ); // Add clearance areas foreach (XElement xClearanceArea in xFittingModel.Element("clearance_areas").Elements("clearance_area")) { if ((double)xClearanceArea.Element("perpendicular_length") > 0) { // Parse and cast facing enum Facing facing; Enum.TryParse <Facing>(xClearanceArea.Element("side").Value, true, out facing); fittingModel.AddClearanceArea(facing, (float)(double)xClearanceArea.Element("perpendicular_length")); } } // Add fitting model fittingModels.Add(fittingModel); } hasSemanticsLoaded = true; }