コード例 #1
0
        public void Snap()
        {
            var selectedPolylines = sessionData.SelectedSketchObjects.OfType <Polyline>().ToArray();
            var selectedPolygons  = sessionData.SelectedSketchObjects.OfType <Polygon>().ToArray();
            var selectedCylinder  = sessionData.SelectedNewPrimitives.OfType <NewCylinder>().FirstOrDefault();
            var selectedCone      = sessionData.SelectedNewPrimitives.OfType <NewCone>().FirstOrDefault();

            if (sessionData.SelectedNewPrimitives.Count == 1)
            {
                // initialize our snapped primitive
                var newPrimitive     = sessionData.SelectedNewPrimitives.First();
                var selectedCurves   = sessionData.SelectedSketchObjects.ToArray();
                var snappedPrimitive = snappersManager.Create(selectedCurves, newPrimitive);
                snappedPrimitive.UpdateFeatureCurves();

                // update session data
                sessionData.SnappedPrimitives.Add(snappedPrimitive);
                sessionData.NewPrimitives.Remove(newPrimitive);
                sessionData.FeatureCurves.AddRange(snappedPrimitive.FeatureCurves);
            }

            OptimizeAll();

            eventAggregator.GetEvent <SnapCompleteEvent>().Publish(null);
        }
コード例 #2
0
        private void DoUpdate()
        {
            if (optimizationTask != null)
            {
                shouldOptimizeAgain = true;
                return;
            }

            oldSnappedPrimitive = snappedPrimitive;
            snappedPrimitive    = snappersManager.Create(newPrimitive);
            snappedPrimitive.UpdateFeatureCurves();

            var emptyCurvesToAnnotations = new Dictionary <FeatureCurve, ISet <Annotation> >();

            var objectivesAndConstraints = snappersManager.Reconstruct(snappedPrimitive, emptyCurvesToAnnotations);
            var objective   = objectivesAndConstraints.Item1;
            var constraints = objectivesAndConstraints.Item2;

            var primitivesWriter = primitivesReaderWriterFactory.CreateWriter();

            primitivesWriter.Write(snappedPrimitive);

            var vars = primitivesWriter.GetVariables();
            var vals = primitivesWriter.GetValues();

            optimizationTask = Task.Factory.StartNew <double[]>(
                _ => optimizer.Minimize(objective, constraints, vars, vals).Last(), TaskScheduler.Default)
                               .ContinueWith(task =>
            {
                if (disposed)
                {
                    return;
                }

                var optimum = task.Result;

                // update primitives from the optimal values
                primitivesReaderWriterFactory.CreateReader().Read(optimum, snappedPrimitive);
                snappedPrimitive.UpdateFeatureCurves();

                // update the task managment fields.
                sessionData.SnappedPrimitives.Remove(oldSnappedPrimitive);
                optimizationTask = null;
                if (shouldOptimizeAgain)
                {
                    shouldOptimizeAgain = false;
                    DoUpdate();
                }
                else
                {
                    sessionData.SnappedPrimitives.Add(snappedPrimitive);
                    eventAggregator.GetEvent <SnapCompleteEvent>().Publish(null);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #3
0
ファイル: Snapper.cs プロジェクト: alexshtf/SketchModeller
        private Tuple <NewPrimitive, SnappedPrimitive> ConvertToSnapped()
        {
            // initialize our snapped primitive
            var newPrimitive     = sessionData.SelectedNewPrimitives.First();
            var snappedPrimitive = snappersManager.Create(newPrimitive);

            snappedPrimitive.UpdateFeatureCurves();

            // update session data
            sessionData.SnappedPrimitives.Add(snappedPrimitive);
            sessionData.NewPrimitives.Remove(newPrimitive);
            sessionData.FeatureCurves.AddRange(snappedPrimitive.FeatureCurves);

            return(Tuple.Create(newPrimitive, snappedPrimitive));
        }