private static IfcShellBasedSurfaceModel createShellBasedSurfaceModelViaTin(IfcStore model, Vector3 origin, Tin tin, out RepresentationType representationType, out RepresentationIdentifier representationIdentifier) { /* Validierung -> bereits bei Reader implementieren? * if (mesh.MaxFaceCorners < 3) * { throw new Exception("Mesh has no Faces"); } */ //init Logger Logger logger = LogManager.GetCurrentClassLogger(); using (var txn = model.BeginTransaction("Create Tin")) { var vmap = new Dictionary <int, int>(); var cpl = new List <IfcCartesianPoint>(); for (int i = 0, j = 0; i < tin.Points.Count; i++) { vmap.Add(i, j); var pt = tin.Points[i]; cpl.Add(model.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(pt.X - origin.X, pt.Y - origin.Y, pt.Z - origin.Z))); j++; } var sbsm = model.Instances.New <IfcShellBasedSurfaceModel>(s => s.SbsmBoundary.Add(model.Instances.New <IfcOpenShell>(o => o.CfsFaces .AddRange(tin.TriangleVertexPointIndizes().Select(tri => model.Instances.New <IfcFace>(x => x.Bounds .Add(model.Instances.New <IfcFaceOuterBound>(b => { b.Bound = model.Instances.New <IfcPolyLoop>(p => { p.Polygon.Add(cpl[vmap[tri[0]]]); p.Polygon.Add(cpl[vmap[tri[1]]]); p.Polygon.Add(cpl[vmap[tri[2]]]); }); b.Orientation = true; })))))))); //logger.Debug("Processed: " + ); txn.Commit(); representationIdentifier = RepresentationIdentifier.Body; representationType = RepresentationType.SurfaceModel; //TRASHLÖSUNG below: long numTri = ((sbsm.Model.Instances.Count - vmap.Count) / 3) - 10; logger.Debug("Processed: " + vmap.Count + " points; " + numTri + " triangels)"); return(sbsm); } }
/// <summary> /// Geländemodell aus Punkten und Bruchlinien /// </summary> /// <param name="model"> </param> /// <param name="points"> Geländepunkte </param> /// <param name="breaklines"> Bruchlinien mit indizes der Punkte </param> /// <returns> </returns> private static IfcGeometricCurveSet createGeometricCurveSetViaTin(IfcStore model, Vector3 origin, Tin tin, double?breakDist, out RepresentationType representationType, out RepresentationIdentifier representationIdentifier) { //init Logger Logger logger = LogManager.GetCurrentClassLogger(); //begin a transaction using (var txn = model.BeginTransaction("Create DTM")) { // CartesianPoints erzeugen //TODO: Punkte filtern, die nicht im DGM enthalten sind var cps = tin.Points.Select(p => model.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(p.X - origin.X, p.Y - origin.Y, p.Z - origin.Z))).ToList(); // DTM var dtm = model.Instances.New <IfcGeometricCurveSet>(g => { var edges = new HashSet <TupleIdx>(); g.Elements.AddRange(cps); if (breakDist is double dist) { /* ÜBERARBEITEN - ist noch die Funktionalität aus MESH * // Hilfsfunktion zum Punkte auf Kante erzeugen * void addEdgePoints(Point3 start, Point3 dest) * { * var dir = dest - start; * double len = Vector3.Norm(dir); * double fac = len / dist; * if (fac > 1.0) * { * start -= origin; * dir /= len; * double currLen = dist; * while (currLen < len) * { * var p = start + (dir * currLen); * g.Elements.Add(model.Instances.New<IfcCartesianPoint>(c => c.SetXYZ(p.X, p.Y, p.Z))); * currLen += dist; * } * } * } * /* * // evtl. Bruchlinien erzeugen * foreach (var edge in mesh.FixedEdges) * { * addEdgePoints(mesh.Points[edge.Idx1], mesh.Points[edge.Idx2]); * edges.Add(edge); * } * * // Kanten der Faces (falls vorhanden und ohne Doppelung) * foreach (var edge in mesh.EdgeIndices.Keys) * { * if (!edges.Contains(TupleIdx.Flipped(edge)) && edges.Add(edge)) * { addEdgePoints(mesh.Points[edge.Idx1], mesh.Points[edge.Idx2]); } * } */ } else { //Read out each triangle foreach (var tri in tin.TriangleVertexPointIndizes()) { //first edge g.Elements.Add(model.Instances.New <IfcPolyline>(p => p.Points.AddRange(new[] { cps[tri[0]], cps[tri[1]] }))); //next edge g.Elements.Add(model.Instances.New <IfcPolyline>(p => p.Points.AddRange(new[] { cps[tri[1]], cps[tri[2]] }))); //last edge g.Elements.Add(model.Instances.New <IfcPolyline>(p => p.Points.AddRange(new[] { cps[tri[2]], cps[tri[0]] }))); } } }); int numEdges = dtm.Elements.Count - cps.Count; logger.Debug("Processed: " + cps.Count + " points; " + numEdges + " edges (of " + numEdges / 3 + " triangels)"); //nach dem commit von txn loggen .. nur für Debugging hier stehen lassen txn.Commit(); representationIdentifier = RepresentationIdentifier.SurveyPoints; representationType = RepresentationType.GeometricCurveSet; return(dtm); } }