Ejemplo n.º 1
0
        public Snapper(
            SessionData sessionData,
            UiState uiState,
            ILoggerFacade logger,
            IEventAggregator eventAggregator,
            IAnnotationInference annotationInference,
            IConstrainedOptimizer constrainedOptimizer,
            SnapOptions snapOptions)
        {
            this.sessionData          = sessionData;
            this.eventAggregator      = eventAggregator;
            this.annotationInference  = annotationInference;
            this.constrainedOptimizer = constrainedOptimizer;
            this.snapOptions          = snapOptions;

            primitivesReaderWriterFactory = new PrimitivesReaderWriterFactory();
            var annotationConstraintsExtractor = new AnnotationConstraintsExtractor();

            snappersManager = new SnappersManager(uiState, sessionData);
            snappersManager.RegisterSnapper(new ConeSnapper());
            snappersManager.RegisterSnapper(new CylinderSnapper());
            snappersManager.RegisterSnapper(new SphereSnapper());
            snappersManager.RegisterSnapper(new SgcSnapper());
            snappersManager.RegisterSnapper(new BgcSnapper());
            snappersManager.RegisterSnapper(new CuboidSnapper());

            wholeShapeOptimizationModel = new WholeShapeOptimizationModel(sessionData, snappersManager, annotationConstraintsExtractor, primitivesReaderWriterFactory);

            eventAggregator.GetEvent <GlobalShortcutEvent>().Subscribe(OnGlobalShortcut);

            logger.Log("NewSnapper created", Category.Debug, Priority.None);
        }
Ejemplo n.º 2
0
 private IObservable <Unit> OptimizeAsync(DispatcherScheduler scheduler, IOptimizationModel optimizationModel)
 {
     return
         (from optimizationProblem in Observable.Start <OptimizationProblem>(optimizationModel.CreateProblem, scheduler)
          from unit in IterativelySolveAndUpdateAsync(optimizationProblem, optimizationModel, scheduler)
          select unit);
 }
Ejemplo n.º 3
0
 private IOptimizationModel CreateOptimizationModel(IOptimizationModel basicOptimizationModel)
 {
     if (snapOptions.IsSnapEnabled)
     {
         return(basicOptimizationModel);
     }
     else
     {
         return(new NoSnappingOptimizationModel(basicOptimizationModel));
     }
 }
 public NoSnappingOptimizationModel(IOptimizationModel innerOptimizationModel)
 {
     this.innerOptimizationModel = innerOptimizationModel;
 }
Ejemplo n.º 5
0
        private IObservable <Unit> IterativelySolveAndUpdateAsync(OptimizationProblem problem, IOptimizationModel optimizationModel, DispatcherScheduler scheduler)
        {
            var optimizationSequence = Minimize(problem);

            var optimumObservations =
                optimizationSequence.ToObservable(Scheduler.ThreadPool);

            var solutionSequence = from optimumBuffer in optimumObservations.Buffer(TimeSpan.FromSeconds(1)) // take optimization result every 1 second
                                   where optimumBuffer.Any()
                                   let optimum = optimumBuffer.Last()
                                                 from unit in Observable.Start(() =>
            {
                optimizationModel.UpdateSolution(optimum);
                NotifySnapComplete();
            }, scheduler)
                                                 select unit;

            return(solutionSequence.TakeLast(1));
        }
Ejemplo n.º 6
0
 private IObservable <Unit> OptimizeWithAnnotationsAsync(DispatcherScheduler scheduler, IEnumerable <Annotation> annotations, IOptimizationModel optimizationModel)
 {
     return(from unit1 in Observable.Start(() => sessionData.Annotations.AddRange(annotations), scheduler)
            from unit2 in OptimizeAsync(scheduler, optimizationModel)
            select unit2);
 }