public static void Read(this VectorsReader reader, SnappedCylinder cylinder) { cylinder.BottomCenterResult = reader.ReadPoint3D(); cylinder.AxisResult = reader.ReadVector3D(); cylinder.LengthResult = reader.ReadValue(); cylinder.RadiusResult = Math.Abs(reader.ReadValue()); }
public void Read(double[] values, IEnumerable <SnappedPrimitive> primitives) { var resultReader = new VectorsReader(values); foreach (var snappedCylinder in primitives.OfType <SnappedCylinder>()) { resultReader.Read(snappedCylinder); } foreach (var snappedCone in primitives.OfType <SnappedCone>()) { resultReader.Read(snappedCone); } foreach (var snappedSphere in primitives.OfType <SnappedSphere>()) { resultReader.Read(snappedSphere); } foreach (var snappedSgc in primitives.OfType <SnappedStraightGenCylinder>()) { resultReader.Read(snappedSgc); } foreach (var snappedCuboid in primitives.OfType <SnappedCuboid>()) { resultReader.Read(snappedCuboid); } foreach (var snappedBgc in primitives.OfType <SnappedBendedGenCylinder>()) { resultReader.Read(snappedBgc); } }
public static void Read(this VectorsReader reader, SnappedCone cone) { cone.BottomCenterResult = reader.ReadPoint3D(); cone.AxisResult = reader.ReadVector3D(); cone.LengthResult = reader.ReadValue(); cone.TopRadiusResult = Math.Abs(reader.ReadValue()); cone.BottomRadiusResult = Math.Abs(reader.ReadValue()); }
public static void Read(this VectorsReader reader, SnappedCuboid cuboid) { cuboid.CenterResult = reader.ReadPoint3D(); cuboid.WidthResult = reader.ReadValue(); cuboid.HeightResult = reader.ReadValue(); cuboid.DepthResult = reader.ReadValue(); cuboid.Wresult = reader.ReadVector3D(); cuboid.Hresult = reader.ReadVector3D(); cuboid.Dresult = reader.ReadVector3D(); }
public static void Read(this VectorsReader reader, SnappedStraightGenCylinder sgc) { sgc.BottomCenterResult = reader.ReadPoint3D(); sgc.AxisResult = reader.ReadVector3D(); sgc.LengthResult = reader.ReadValue(); foreach (var i in Enumerable.Range(0, sgc.ComponentResults.Length)) { sgc.ComponentResults[i] = new CylinderComponent(reader.ReadValue(), sgc.ComponentResults[i].Progress); } }
public static void Read(this VectorsReader reader, SnappedBendedGenCylinder bgc) { bgc.BottomCenterResult = reader.ReadPoint3D(); bgc.NPtopResult = reader.ReadVector(); bgc.NPbotResult = reader.ReadVector(); bgc.Uresult = reader.ReadVector3D(); bgc.Vresult = reader.ReadVector3D(); foreach (var i in Enumerable.Range(0, bgc.ComponentResults.Length)) { bgc.ComponentResults[i] = new BendedCylinderComponent(reader.ReadValue(), bgc.ComponentResults[i].Progress, reader.ReadValue(), reader.ReadValue()); } }
private void OptimizeAll() { #region Write all variables and their current values to a vector var variablesWriter = new VariableVectorsWriter(); var startVectorWriter = new VectorsWriter(); // write cylinders foreach (var snappedCylinder in sessionData.SnappedPrimitives.OfType <SnappedCylinder>()) { variablesWriter.Write(snappedCylinder); startVectorWriter.Write(snappedCylinder); } // write cones foreach (var snappedCone in sessionData.SnappedPrimitives.OfType <SnappedCone>()) { variablesWriter.Write(snappedCone); startVectorWriter.Write(snappedCone); } #endregion // all objective functions. Will be summed eventually to form one big objective. var objectives = new List <Term>(); // all equality constraints. var constraints = new List <Term>(); var curvesToAnnotations = new Dictionary <FeatureCurve, ISet <Annotation> >(); #region Get mapping of curves to annotations foreach (var fc in sessionData.FeatureCurves) { curvesToAnnotations[fc] = new HashSet <Annotation>(); } foreach (var annotation in sessionData.Annotations) { IEnumerable <FeatureCurve> curves = null; annotation.MatchClass <Parallelism>(pa => curves = pa.Elements); annotation.MatchClass <Coplanarity>(ca => curves = ca.Elements); annotation.MatchClass <Cocentrality>(ca => curves = ca.Elements); Debug.Assert(curves != null); foreach (var fc in curves) { curvesToAnnotations[fc].Add(annotation); } } #endregion #region get objectives and constraints for primitives foreach (var snappedPrimitive in sessionData.SnappedPrimitives) { var objectiveAndConstraints = snappersManager.Reconstruct(snappedPrimitive, curvesToAnnotations); objectives.Add(objectiveAndConstraints.Item1); constraints.AddRange(objectiveAndConstraints.Item2); } #endregion #region get constraints for annotations foreach (var annotation in sessionData.Annotations) { var constraintTerms = GetAnnotationConstraints(annotation); constraints.AddRange(constraintTerms); } #endregion #region perform optimization var finalObjective = TermUtils.SafeSum(objectives); var vars = variablesWriter.ToArray(); var vals = startVectorWriter.ToArray(); var optimum = Optimizer.MinAugmentedLagrangian(finalObjective, constraints.ToArray(), vars, vals, mu: 10, tolerance: 1E-5); #endregion #region read data back from the optimized vector var resultReader = new VectorsReader(optimum); foreach (var snappedCylinder in sessionData.SnappedPrimitives.OfType <SnappedCylinder>()) { resultReader.Read(snappedCylinder); } foreach (var snappedCone in sessionData.SnappedPrimitives.OfType <SnappedCone>()) { resultReader.Read(snappedCone); } #endregion #region Update feature curves foreach (var snappedPrimitive in sessionData.SnappedPrimitives) { snappedPrimitive.UpdateFeatureCurves(); } #endregion }
public static void Read(this VectorsReader reader, SnappedSphere sphere) { sphere.CenterResult = reader.ReadPoint3D(); sphere.RadiusResult = reader.ReadValue(); }