public override MeasureViewModel GetViewModel()
 {
     //init value
     MeasureViewModel viewMoel = new MeasureViewModel()
     {
         Row1 = new HTuple(),
         Col1 = new HTuple(),
         Row2 = new HTuple(),
         Col2 = new HTuple(),
         Distance = new HTuple(),
     };
     if (mResult.rowEdge != null && mResult.rowEdge.TupleLength() > 0)
     {
         HXLDCont edgeXLD;
         HTuple rows, cols;
         edgeXLD = DetermineCrossPoint(mResult.rowEdge.D, mResult.colEdge.D, _crossPointSize, 0.5);
         edgeXLD.GetContourXld(out rows, out cols);
         viewMoel = new MeasureViewModel()
         {
             Row1 = rows[0],
             Col1 = cols[0],
             GeoType = MeasureType.Point,
         };
     }
     return viewMoel;
 }
        public int SaveMeasure(MeasureViewModel model, int userId, int organizationId)
        {
            var measure = new Measure();

            if (model.MeasureId == 0)
            {
                measure                = Mapper.Map <MeasureViewModel, Measure>(model);
                measure.UserId         = userId;
                measure.OrganizationId = organizationId;
                if (measure.Target == null)
                {
                    measure.Target = 0;
                }
                base.RepositoryContext.Measures.Add(measure);
            }
            else
            {
                model.MeasureColumns     = null;
                model.MeasureColumnDatas = null;
                model.MeasureObjectives  = null;
                Mapper.Map(model, measure);
                base.RepositoryContext.Entry(measure).State = EntityState.Modified;
            }
            base.RepositoryContext.SaveChanges();
            return(measure.MeasureId);
        }
Exemple #3
0
        public IActionResult Create(MeasureViewModel model)
        {
            if (ModelState.IsValid)
            {
                var ses = new Measure {
                    MeasureName = model.MeasureName
                };
                var x = _databaseContext.Measure.FirstOrDefault(g => g.MeasureName == ses.MeasureName);

                if (x != null)
                {
                    TempData[Constants.Message]       = $"Mjerna jedinica tog imena već postoji.\n";
                    TempData[Constants.ErrorOccurred] = true;
                    return(View("Add", model));
                }
                _databaseContext.Measure.Add(ses);

                TempData["Success"] = true;
                _databaseContext.SaveChanges();
                TempData[Constants.Message]       = $"Mjerna jedinica je dodana";
                TempData[Constants.ErrorOccurred] = false;
                return(RedirectToAction(nameof(Index)));
            }
            return(View("Add", model));
        }
        private MeasureViewModel translateToDoubleValue(MeasureViewModel model)
        {
            var    newModel = new MeasureViewModel();
            double rowBegin, colBegin, rowEnd, colEnd;

            if (Double.TryParse(model.Row1, out rowBegin))
            {
                newModel.Row1 = new HTuple(rowBegin);
            }

            if (Double.TryParse(model.Row2, out rowEnd))
            {
                newModel.Row2 = new HTuple(rowEnd);
            }

            if (Double.TryParse(model.Col1, out colBegin))
            {
                newModel.Col1 = new HTuple(colBegin);
            }

            if (Double.TryParse(model.Col2, out colEnd))
            {
                newModel.Col2 = new HTuple(colEnd);
            }

            newModel.GeoType = model.GeoType;
            return(newModel);
        }
        public void TestPointToPoint(object row1, object col1, object row2, object col2, double expectedValue)
        {
            //assign
            var pointA = new MeasureViewModel();

            if (row1 != null)
            {
                pointA.Row1 = new HTuple(row1);
            }
            if (col1 != null)
            {
                pointA.Col1 = new HTuple(col1);
            }
            pointA.GeoType = MeasureType.Point;

            var pointB = new MeasureViewModel();

            if (row2 != null)
            {
                pointB.Row1 = new HTuple(row2);
            }
            if (col2 != null)
            {
                pointB.Col1 = new HTuple(col2);
            }
            pointB.GeoType = MeasureType.Point;

            //act
            double distance = DistanceHelper.PointToPoint(pointA, pointB);

            //assert
            Assert.True(distance >= expectedValue);
        }
        public void TestLineToLine(object line1RowBegin, object line1ColBegin, object line1RowEnd, object line1ColEnd
            , object line2RowBegin, object line2ColBegin, object line2RowEnd, object line2ColEnd
            , double expectedValue)
        {
            //assign
            var line1Model = new MeasureViewModel();
            if (line1RowBegin != null) line1Model.Row1 = new HTuple(line1RowBegin);
            if (line1ColBegin != null) line1Model.Col1 = new HTuple(line1ColBegin);
            if (line1RowEnd != null) line1Model.Row2 = new HTuple(line1RowEnd);
            if (line1ColEnd != null) line1Model.Col2 = new HTuple(line1ColEnd);
            line1Model.GeoType = MeasureType.Line;

            var line2Model = new MeasureViewModel();
            if (line2RowBegin != null) line2Model.Row1 = new HTuple(line2RowBegin);
            if (line2ColBegin != null) line2Model.Col1 = new HTuple(line2ColBegin);
            if (line2RowEnd != null) line2Model.Row2 = new HTuple(line2RowEnd);
            if (line2ColEnd != null) line2Model.Col2 = new HTuple(line2ColEnd);
            line2Model.GeoType = MeasureType.Line;

            //act
            var distance = DistanceHelper.LineToLine(line1Model, line2Model);

            //assert
            Assert.True(distance >= expectedValue);
        }
 public IActionResult SaveMeasure(MeasureViewModel measure)
 {
     _context.Add(measure.ToMeasure());
     _context.SaveChanges();
     //var meas = _context.Measures.Single(m => m.Id == Guid.Empty);
     return(new JsonResult(measure));
 }
Exemple #8
0
        public void Create(MeasureViewModel measure)
        {
            var entity = new Measure();

            entity.Id          = measure.Id;
            entity.captureDate = measure.captureDate;
            entity.value       = measure.value;

            if (entity.sensor == null)
            {
                entity.sensor    = new SensorType();
                entity.sensor.Id = measure.sensorId;
            }

            if (entity.productionUnit == null)
            {
                entity.productionUnit    = new ProductionUnit();
                entity.productionUnit.Id = measure.productionUnitId;
            }

            entities.Measures.Add(entity);
            entities.SaveChanges();

            measure.Id = entity.Id;
        }
Exemple #9
0
        private void Redraw()
        {
            var columns = 7;

            MusicPanel.Children.Clear();

            StackPanel current = null;

            for (int i = 0; i < _measures.Length; i++)
            {
                if (i % (columns - 1) == 0)
                {
                    current = new StackPanel {
                        Orientation = Orientation.Horizontal
                    };
                    MusicPanel.Children.Add(current);

                    var grid = new Grid {
                        Width = 40, Height = 100
                    };
                    grid.Children.Add(MeasureViewModel.BuildClef(4, 4));
                    current.Children.Add(grid);
                }

                current.Children.Add(_measures[i].DisplayGrid);
            }
        }
        public override MeasureViewModel GetViewModel()
        {
            //init value
            MeasureViewModel viewMoel = new MeasureViewModel()
            {
                Row1     = new HTuple(),
                Col1     = new HTuple(),
                Row2     = new HTuple(),
                Col2     = new HTuple(),
                Distance = new HTuple(),
            };

            if (mResult.rowEdge != null && mResult.rowEdge.TupleLength() > 0)
            {
                HXLDCont edgeXLD;
                HTuple   rows, cols;
                edgeXLD = DetermineCrossPoint(mResult.rowEdge.D, mResult.colEdge.D, _crossPointSize, 0.5);
                edgeXLD.GetContourXld(out rows, out cols);
                viewMoel = new MeasureViewModel()
                {
                    Row1    = rows[0],
                    Col1    = cols[0],
                    GeoType = MeasureType.Point,
                };
            }
            return(viewMoel);
        }
Exemple #11
0
        public MeasureView()
        {
            InitializeComponent();

            var viewModel = new MeasureViewModel();

            MeasureValueLabel.DataBindings.Add("Text", viewModel, nameof(viewModel.MeasureValue));
            MeasureButton.Click += (sender, e) => viewModel.Measure();
        }
Exemple #12
0
        public void Destroy(MeasureViewModel message)
        {
            var entity = new Measure();

            entity.Id = message.Id;

            entities.Measures.Attach(entity);
            entities.Measures.Remove(entity);

            entities.SaveChanges();
        }
Exemple #13
0
        public IActionResult Index(MeasureViewModel measureViewModel)
        {
            IList <MeasureViewModel> measurements = new List <MeasureViewModel>();
            //sort the table then pull out the 2 variables

            var regions = context
                          .Measurements
                          .Select(m => m.Region)
                          .Distinct()
                          .ToList();

            foreach (var region in regions)
            {
                //most recent record, pull the size
                var lastMeasurement = context
                                      .Measurements
                                      // m is the RECORD/ENTRY
                                      .OrderBy(m => m.Date)
                                      .Where(m => m.Region == region)
                                      .LastOrDefault();

                // the first entry
                var firstMeasurement = context
                                       .Measurements
                                       .OrderBy(m => m.Date)
                                       .Where(m => m.Region == region)
                                       .FirstOrDefault();

                if (lastMeasurement != null && firstMeasurement != null)
                {
                    // (last - first Size)
                    MeasureViewModel newMeasureViewModel = new MeasureViewModel();
                    double           difference          = lastMeasurement.Size - firstMeasurement.Size;
                    newMeasureViewModel.Size = difference;

                    // also show the region that goes with the size
                    newMeasureViewModel.Region = region;

                    // push variables to the View
                    measurements.Add(newMeasureViewModel);
                }
                else
                {
                    MeasureViewModel newMeasureViewModel = new MeasureViewModel();
                    newMeasureViewModel.Size = 0;
                    measurements.Add(newMeasureViewModel);
                }
            }

            // push these variables to the view
            // show variable in the table in the View
            return(View("Index", measurements));
        }
Exemple #14
0
        public MainWindow()
        {
            InitializeComponent();
            GenerateSwitchToMonitorMenu();

            DataContext           = Resources["MeasureViewModelDataSource"];
            vm                    = Resources["MeasureViewModelDataSource"] as MeasureViewModel;
            vm.FurnitureViewModel = furnitureVM = Resources["FurnitureViewModelDataSource"] as FurnitureViewModel;

            vm.KinectChanged += SensorChooserOnKinectChanged;
            //this.sensorChooserUi.KinectSensorChooser = vm.SensorChooser;
        }
        public void TestLineToLine(object line1RowBegin, object line1ColBegin, object line1RowEnd, object line1ColEnd
                                   , object line2RowBegin, object line2ColBegin, object line2RowEnd, object line2ColEnd
                                   , double expectedValue)
        {
            //assign
            var line1Model = new MeasureViewModel();

            if (line1RowBegin != null)
            {
                line1Model.Row1 = new HTuple(line1RowBegin);
            }
            if (line1ColBegin != null)
            {
                line1Model.Col1 = new HTuple(line1ColBegin);
            }
            if (line1RowEnd != null)
            {
                line1Model.Row2 = new HTuple(line1RowEnd);
            }
            if (line1ColEnd != null)
            {
                line1Model.Col2 = new HTuple(line1ColEnd);
            }
            line1Model.GeoType = MeasureType.Line;

            var line2Model = new MeasureViewModel();

            if (line2RowBegin != null)
            {
                line2Model.Row1 = new HTuple(line2RowBegin);
            }
            if (line2ColBegin != null)
            {
                line2Model.Col1 = new HTuple(line2ColBegin);
            }
            if (line2RowEnd != null)
            {
                line2Model.Row2 = new HTuple(line2RowEnd);
            }
            if (line2ColEnd != null)
            {
                line2Model.Col2 = new HTuple(line2ColEnd);
            }
            line2Model.GeoType = MeasureType.Line;

            //act
            var distance = DistanceHelper.LineToLine(line1Model, line2Model);

            //assert
            Assert.True(distance >= expectedValue);
        }
Exemple #16
0
        /// <summary>
        /// getting KPI question based on checkListType
        /// </summary>
        /// <param name="checkListTypeId"></param>
        /// <returns></returns>
        public List <MeasureViewModel> GetKPIQuestionBasedOnCheckListType(string checkListTypeCode)
        {
            List <MeasureViewModel> measures = new List <MeasureViewModel>();

            try
            {
                if (checkListTypeCode != ChecklistType.M3.ToString())
                {
                    IEnumerable <Question> questionsDTO = _kpiRepository.GetKPIQuestionBasedOnCheckListType(checkListTypeCode);
                    if (questionsDTO != null)
                    {
                        foreach (Question questionDto in questionsDTO)
                        {
                            MeasureViewModel measure = new MeasureViewModel();
                            measure.MeasureId   = questionDto.QuestionId;
                            measure.MeasureText = questionDto.QuestionText;
                            measure.MeasureCode = questionDto.QuestionCode;
                            measure.Standard    = questionDto.ExpectedResponse;
                            measure.Universal   = questionDto.IsUniversal;
                            measure.KPIID       = GetKPIIdBasedonQuestion(questionDto.QuestionId, checkListTypeCode);
                            measures.Add(measure);
                        }
                    }
                }
                else
                {
                    List <M3metricsQuestion> questionsDTO = _kpiRepository.GetM3metricsQuestion();
                    if (questionsDTO != null)
                    {
                        foreach (M3metricsQuestion questionDto in questionsDTO)
                        {
                            MeasureViewModel measure = new MeasureViewModel();
                            measure.MeasureId   = questionDto.M3metricsQuestionId;
                            measure.MeasureText = questionDto.M3metricsQuestionText;
                            measure.MeasureCode = questionDto.M3metricsQuestionCode;
                            measure.MeasureUnit = questionDto.M3metricsUnit;
                            measure.KPIID       = GetKPIIdBasedonQuestion(questionDto.M3metricsQuestionId, checkListTypeCode);

                            measures.Add(measure);
                        }
                    }
                }

                return(measures);
            }
            catch (Exception ex)
            {
                _logger.Log(ex, LogLevel.Error, ex.Message);
                return(null);
            }
        }
Exemple #17
0
        public async Task <IActionResult> Edit(int id, MeasureViewModel vm)
        {
            var result = await _measureServices.Update(vm, GetAccount());

            if (result.Status == Status.ok)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "保存失败: " + result.Message);
                return(View(vm));
            }
        }
        public void Test_計測_シナリオ()
        {
            var sensorMock = new Mock <ISensorRepository>();

            sensorMock.Setup(x => x.GetData()).Returns(new MeasureValue(1.23456f));

            var viewModel = new MeasureViewModel(sensorMock.Object);

            viewModel.Measure();
            viewModel.MeasureValue.Is("1.23m/s");

            sensorMock.Setup(x => x.GetData()).Returns(new MeasureValue(2.2f));
            viewModel.Measure();
            viewModel.MeasureValue.Is("2.2m/s");
        }
Exemple #19
0
        public void 計測_シナリオ()
        {
            var sensorMock = new Mock <ISensorRepository>();
            var viewModel  = new MeasureViewModel(sensorMock.Object);

            Assert.AreEqual("--", viewModel.MeasureValue);

            sensorMock.Setup(x => x.GetData()).Returns(new MeasureValue(1.23456f));
            viewModel.Measure();
            Assert.AreEqual("1.23m/s", viewModel.MeasureValue);

            sensorMock.Setup(x => x.GetData()).Returns(new MeasureValue(2.2f));
            viewModel.Measure();
            Assert.AreEqual("2.2m/s", viewModel.MeasureValue);
        }
 public static IMeasureGeoModel Resolve(GeoDataGridViewModel rawModel)
 {
     MeasureViewModel model = null;
     if (rawModel != null)
     {
         model = new MeasureViewModel()
         {
             Row1 = new HTuple(rawModel.Row1),
             Row2 = new HTuple(rawModel.Row2),
             Col1 = new HTuple(rawModel.Col1),
             Col2 = new HTuple(rawModel.Col2),
             Distance = new HTuple(rawModel.Distance),
             GeoType = rawModel.GeoType
         };
     }
     return model;
 }
        public static IMeasureGeoModel Resolve(GeoDataGridViewModel rawModel)
        {
            MeasureViewModel model = null;

            if (rawModel != null)
            {
                model = new MeasureViewModel()
                {
                    Row1     = new HTuple(rawModel.Row1),
                    Row2     = new HTuple(rawModel.Row2),
                    Col1     = new HTuple(rawModel.Col1),
                    Col2     = new HTuple(rawModel.Col2),
                    Distance = new HTuple(rawModel.Distance),
                    GeoType  = rawModel.GeoType
                };
            }
            return(model);
        }
        public ActionResult SaveMeasure(MeasureViewModel model)
        {
            Measure measure = new Measure();

            measure = Mapper.Map <MeasureViewModel, Measure>(model);

            var measureRepo = new MeasureRepository();
            var item        = measureRepo.SaveMeasure(measure);

            if (item.Success)
            {
                return(Json(item.Value));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "An error has occured !!!"));
            }
        }
        public void TestPointToLine(object pointRow, object pointCol
                                    , object lineRowBegin, object lineColBegin, object lineRowEnd, object lineColEnd
                                    , double expectedValue)
        {
            //assign
            var pointModel = new MeasureViewModel();

            if (pointRow != null)
            {
                pointModel.Row1 = new HTuple(pointRow);
            }
            if (pointCol != null)
            {
                pointModel.Col1 = new HTuple(pointCol);
            }
            pointModel.GeoType = MeasureType.Point;

            var lineModel = new MeasureViewModel();

            if (lineRowBegin != null)
            {
                lineModel.Row1 = new HTuple(lineRowBegin);
            }
            if (lineColBegin != null)
            {
                lineModel.Col1 = new HTuple(lineColBegin);
            }
            if (lineRowEnd != null)
            {
                lineModel.Row2 = new HTuple(lineRowEnd);
            }
            if (lineColEnd != null)
            {
                lineModel.Col2 = new HTuple(lineColEnd);
            }
            lineModel.GeoType = MeasureType.FitLine;

            //act
            var distance = DistanceHelper.PointToLine(pointModel, lineModel);

            //assert
            Assert.True(distance >= expectedValue);
        }
Exemple #24
0
        public void TestMethod1()
        {
            //var viewModel = new MeasureViesModel(new SensorMock());
            //viewModel.MeasureValue.Equals("--");

            //viewModel.Measure();
            //viewModel.MeasureValue.Equals("1.23 m/s");

            var sensorMock = new Moq.Mock <ISensorRepository>();
            var viewModel  = new MeasureViewModel(sensorMock.Object);

            sensorMock.Setup(x => x.GetData()).Returns(new MeasureValue(1.23456f));
            viewModel.Measure();
            Assert.AreEqual(viewModel.MeasureValue, "1.23m/s");


            sensorMock.Setup(x => x.GetData()).Returns(new MeasureValue(2.2f));
            viewModel.Measure();
            Assert.AreEqual(viewModel.MeasureValue, "2.2m/s");
        }
Exemple #25
0
        //Get data by Id for view info
        public int GetDetail(long ID, out MeasureViewModel Model)
        {
            int returnCode = (int)Common.ReturnCode.Succeed;

            Model = new MeasureViewModel();
            try
            {
                if (ID != 0)
                {
                    string strQuery = "SELECT `id`, `code`, `name`, `description`";
                    strQuery += " FROM product_measure WHERE `id` = @id";
                    Model     = _db.Query <MeasureViewModel>(strQuery, new { id = ID }).SingleOrDefault();
                }
            }
            catch (Exception)
            {
                returnCode = (int)Common.ReturnCode.UnSuccess;
            }

            return(returnCode);
        }
Exemple #26
0
        public ActionResult View(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }

            MeasureViewModel Model = new MeasureViewModel();
            int returnCode         = _measureBL.GetDetail(long.Parse(id), out Model);

            if (Model == null)
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }
            if (!((int)Common.ReturnCode.Succeed == returnCode))
            {
                Model = new MeasureViewModel();
            }

            return(View(Model));
        }
Exemple #27
0
        public async Task <ServiceResponseBase> Create(MeasureViewModel vm, AccountViewModel account)
        {
            try
            {
                var isExist = await _context.Measure.AnyAsync(o => o.MeasureName == vm.MeasureName &&
                                                              o.CompanyId == account.CompanyId);

                if (isExist)
                {
                    return(new ServiceResponseBase()
                    {
                        Status = Status.error, Message = "存在重复名称"
                    });
                }
                vm.CompanyId = account.CompanyId;
                var measure = Mapper.Map <Measure>(vm);
                measure.MeasureNum = "";
                measure.Sn         = "";
                await _context.Measure.AddAsync(measure);

                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
Exemple #28
0
        public void Update(MeasureViewModel measure)
        {
            Measure target = new Measure();

            target = entities.Measures.Where(m => m.Id == measure.Id).Include(m => m.sensor).FirstOrDefault();

            if (target != null)
            {
                target.captureDate = measure.captureDate;
                target.value       = measure.value;

                SensorType currentSensorType = new SensorType();
                currentSensorType = entities.SensorTypes.Where(m => m.Id == measure.sensorId).FirstOrDefault();

                target.sensor = currentSensorType;

                ProductionUnit currentProductionUnit = new ProductionUnit();
                currentProductionUnit = entities.ProductionUnits.Where(m => m.Id == measure.productionUnitId).FirstOrDefault();

                target.productionUnit = currentProductionUnit;
            }

            entities.SaveChanges();
        }
Exemple #29
0
        public async Task <ServiceResponseBase> Update(MeasureViewModel vm, AccountViewModel account)
        {
            try
            {
                var isExist = await _context.Measure.AnyAsync(o => o.MeasureName == vm.MeasureName &&
                                                              o.CompanyId == account.CompanyId && o.Id != vm.Id);

                if (isExist)
                {
                    return(new ServiceResponseBase()
                    {
                        Status = Status.error, Message = "存在重复名称"
                    });
                }
                var measure = await _context.Measure.FirstOrDefaultAsync(o => o.Id == vm.Id);

                Mapper.Map(vm, measure);
                measure.MeasureNum            = "";
                measure.Sn                    = "";
                _context.Entry(measure).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
        public MeasureViewModel GetMidLine()
        {
            #region 輸出結果
            DistanceResult   mResult      = null;
            MeasureViewModel midLineModel = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            //HTuple f_ROI_Row = 528.01953125;
            //HTuple f_ROI_Col = 821.555555555556;
            //HTuple f_angle = 0;
            //HTuple f_ROI_Length1 = 20;
            //HTuple f_ROI_Length2 = 93;
            HTuple f_ROI_Row     = 528.01953125;
            HTuple f_ROI_Col     = 1067.82352941176;
            HTuple f_angle       = 0;
            HTuple f_ROI_Length1 = 20.9019607843137;
            HTuple f_ROI_Length2 = 90.669921875;



            HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //第二個 線段 ROI
            //HTuple s_ROI_Row = 528.03515625;
            //HTuple s_ROI_Col = 858.300653594771;
            //HTuple s_angle = 3.14159265358979;
            //HTuple s_ROI_Length1 = 20;
            //HTuple s_ROI_Length2 = 93;
            HTuple s_ROI_Row     = 528.03515625;
            HTuple s_ROI_Col     = 1102.59477124183;
            HTuple s_angle       = 3.14159265358979;
            HTuple s_ROI_Length1 = 17.3856209150328;
            HTuple s_ROI_Length2 = 91.6015625;



            HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle;
            HTuple s_ROI_Cur_Row, s_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                                      , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant     = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh         = 40.0;
            cAssistant.mSigma          = 1.0;
            cAssistant.mRoiWidth       = 10;
            cAssistant.mInterpolation  = "nearest_neighbor";
            cAssistant.mSelPair        = false;
            cAssistant.mTransition     = "all";
            cAssistant.mPosition       = "all";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth   = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh   = 40.0;
            cAssistant.mInitSigma    = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROIRectangle2()
            {
                ROIMeasureType = MeasureType.Line
            };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2);

            var roiS = new ROIRectangle2()
            {
                ROIMeasureType = MeasureType.Line
            };
            //roiS.MakeROI(400, 1041, 0, 13.3, 75.7);
            roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2);

            var lineF = new MeasurementEdge(roiF, cAssistant);
            var lineS = new MeasurementEdge(roiS, cAssistant);
            mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal);



            var firstModel  = lineF.GetViewModel();
            var secondModel = lineS.GetViewModel();
            if (firstModel != null && secondModel != null && firstModel.Distance != null && secondModel.Distance != null &&
                firstModel.Distance.TupleLength() > 0 && secondModel.Distance.TupleLength() > 0)
            {
                //作線段
                var centerRow = (f_ROI_Cur_Row + s_ROI_Cur_Row) / 2.0;
                var centerCol = (f_ROI_Cur_Col + s_ROI_Cur_Col) / 2.0;

                midLineModel = DistanceHelper.MakeLine(centerRow, centerCol, hv_AllModelAngle, mResult.Distance / 2.0);
            }

            return(midLineModel);

            #endregion
        }
        private MeasureViewModel translateToDoubleValue(MeasureViewModel model)
        {
            var newModel = new MeasureViewModel();
            double rowBegin, colBegin, rowEnd, colEnd;
            if (Double.TryParse(model.Row1, out rowBegin))
                newModel.Row1 = new HTuple(rowBegin);

            if (Double.TryParse(model.Row2, out rowEnd))
                newModel.Row2 = new HTuple(rowEnd);

            if (Double.TryParse(model.Col1, out colBegin))
                newModel.Col1 = new HTuple(colBegin);

            if (Double.TryParse(model.Col2, out colEnd))
                newModel.Col2 = new HTuple(colEnd);

            newModel.GeoType = model.GeoType;
            return newModel;
        }
Exemple #32
0
 public MeasureView()
 {
     InitializeComponent();
     BindingContext = _viewModel = new MeasureViewModel();
 }
Exemple #33
0
        public MeasureViewModel GetMidLine()
        {
            #region 輸出結果
            LineResult       mResult      = null;
            MeasureViewModel midLineModel = null;
            #endregion

            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol;
            HOperatorSet.SetSystem("border_shape_models", "false");

            //STD 中心點
            hv_STD_Row = 839.5;
            hv_STD_Col = 1046.5;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //第一個 線段 ROI
            HTuple f_ROI_Row     = 528.064453125;
            HTuple f_ROI_Col     = 802.751633986928;
            HTuple f_angle       = 0;
            HTuple f_ROI_Length1 = 38.2679738562091;
            HTuple f_ROI_Length2 = 99.6328125;



            HTuple f_angle_offset = f_angle - hv_Img_Rotate_Angle;
            HTuple f_ROI_Cur_Row, f_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol, f_ROI_Row, f_ROI_Col, out f_ROI_Cur_Row, out f_ROI_Cur_Col);

            //第二個 線段 ROI
            HTuple s_ROI_Row     = 523.408203125;
            HTuple s_ROI_Col     = 853.542483660131;
            HTuple s_angle       = 3.14159265358979;
            HTuple s_ROI_Length1 = 27.4509803921568;
            HTuple s_ROI_Length2 = 105.341796875;



            HTuple s_angle_offset = s_angle - hv_Img_Rotate_Angle;
            HTuple s_ROI_Cur_Row, s_ROI_Cur_Col;
            PositionLocater.ReLocater(hv_STD_Row, hv_STD_Col, hv_AllModelAngle, hv_OffsetRow, hv_OffsetCol
                                      , s_ROI_Row, s_ROI_Col, out s_ROI_Cur_Row, out s_ROI_Cur_Col);

            #region Measure
            var cROIController = new ROIController();
            var cAssistant     = new MeasureAssistant(cROIController);

            var hImage = ho_Image as HImage;
            cAssistant.setImage(hImage);

            /*參數值*/
            cAssistant.mThresh         = 40.0;
            cAssistant.mSigma          = 1.0;
            cAssistant.mRoiWidth       = 10;
            cAssistant.mInterpolation  = "bilinear";
            cAssistant.mSelPair        = false;
            cAssistant.mTransition     = "all";
            cAssistant.mPosition       = "last";
            cAssistant.mDispEdgeLength = 30;
            cAssistant.mDispROIWidth   = true;
            cAssistant.setUnit("cm");

            cAssistant.mInitThresh   = 40.0;
            cAssistant.mInitSigma    = 1.0;
            cAssistant.mInitRoiWidth = 10;

            var roiF = new ROIRectangle2()
            {
                ROIMeasureType = MeasureType.Line
            };
            //roiF.MakeROI(416, 998, 0, 26.5, 71.2);
            roiF.MakeROI(f_ROI_Cur_Row, f_ROI_Cur_Col, f_angle_offset, f_ROI_Length1, f_ROI_Length2);

            var roiS = new ROIRectangle2()
            {
                ROIMeasureType = MeasureType.Line
            };
            //roiS.MakeROI(400, 1041, 0, 13.3, 75.7);
            roiS.MakeROI(s_ROI_Cur_Row, s_ROI_Cur_Col, s_angle_offset, s_ROI_Length1, s_ROI_Length2);

            var lineF = new MeasurementEdge(roiF, cAssistant);
            var lineS = new MeasurementEdge(roiS, cAssistant);
            mResult = DistanceHelper.CalculateSymmetryLine(lineF.GetViewModel(), lineS.GetViewModel());
            //mResult = DistanceHelper.LineToLine(lineF, lineS, this.hv_AllModelAngle, LineDirection.Horizontal);

            midLineModel = new MeasureViewModel()
            {
                Row1     = mResult.Row1,
                Row2     = mResult.Row2,
                Col1     = mResult.Col1,
                Col2     = mResult.Col2,
                Distance = mResult.Distance,
            };


            //var firstModel = lineF.GetViewModel();
            //var secondModel = lineS.GetViewModel();
            //if (firstModel != null && secondModel != null && firstModel.Distance != null && secondModel.Distance != null
            //	&& firstModel.Distance.TupleLength() > 0 && secondModel.Distance.TupleLength() > 0)
            //{
            //	//作線段
            //	var centerRow = (f_ROI_Cur_Row + s_ROI_Cur_Row) / 2.0;
            //	var centerCol = (f_ROI_Cur_Col + s_ROI_Cur_Col) / 2.0;

            //	midLineModel = DistanceHelper.MakeLine(centerRow, centerCol, hv_AllModelAngle, mResult.Distance / 2.0);
            //}

            return(midLineModel);

            #endregion
        }
        public void TestPointToPoint(object row1, object col1, object row2, object col2, double expectedValue)
        {
            //assign
            var pointA = new MeasureViewModel();
            if (row1 != null) pointA.Row1 = new HTuple(row1);
            if (col1 != null) pointA.Col1 = new HTuple(col1);
            pointA.GeoType = MeasureType.Point;

            var pointB = new MeasureViewModel();
            if (row2 != null) pointB.Row1 = new HTuple(row2);
            if (col2 != null) pointB.Col1 = new HTuple(col2);
            pointB.GeoType = MeasureType.Point;

            //act
            double distance = DistanceHelper.PointToPoint(pointA, pointB);

            //assert
            Assert.True(distance >= expectedValue);
        }
        public void TestPointToLine(object pointRow, object pointCol
            , object lineRowBegin, object lineColBegin, object lineRowEnd, object lineColEnd
            , double expectedValue)
        {
            //assign
            var pointModel = new MeasureViewModel();
            if (pointRow != null) pointModel.Row1 = new HTuple(pointRow);
            if (pointCol != null) pointModel.Col1 = new HTuple(pointCol);
            pointModel.GeoType = MeasureType.Point;

            var lineModel = new MeasureViewModel();
            if (lineRowBegin != null) lineModel.Row1 = new HTuple(lineRowBegin);
            if (lineColBegin != null) lineModel.Col1 = new HTuple(lineColBegin);
            if (lineRowEnd != null) lineModel.Row2 = new HTuple(lineRowEnd);
            if (lineColEnd != null) lineModel.Col2 = new HTuple(lineColEnd);
            lineModel.GeoType = MeasureType.FitLine;

            //act
            var distance = DistanceHelper.PointToLine(pointModel, lineModel);

            //assert
            Assert.True(distance >= expectedValue);
        }
Exemple #36
0
        public async Task <IActionResult> Create()
        {
            var vm = new MeasureViewModel();

            return(View(vm));
        }