public void UpdateSolution(double[] solution)
 {
     primitivesReaderWriterFactory.CreateReader().Read(solution, sessionData.SnappedPrimitives);
     foreach (var snappedPrimitive in sessionData.SnappedPrimitives)
     {
         snappedPrimitive.UpdateFeatureCurves();
     }
 }
Exemplo n.º 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());
        }
Exemplo n.º 3
0
 public void UpdateSolution(double[] solution)
 {
     primitivesReaderWriterFactory.CreateReader().Read(solution, snappedPrimitive);
     snappedPrimitive.UpdateFeatureCurves();
 }