private void HandleSimpleCase(MeshData meshData, MultiPlaneMeshIndex meshIndex, GradientWrapper gradient, Skeleton skeleton, EdgeResult edge, float roofOffset, float roofHeight) { var polygon = edge.Polygon; var distances = skeleton.Distances; for (int i = 0; i <= polygon.Count - 2; i += 2) { var p0 = polygon[i]; var p1 = polygon[i + 1]; var p2 = polygon[i + 2 == polygon.Count ? 0 : i + 2]; var v0 = new Vector3((float)p0.X, distances[p0] > 0 ? roofHeight + roofOffset : roofOffset, (float)p0.Y); var v1 = new Vector3((float)p1.X, distances[p1] > 0 ? roofHeight + roofOffset : roofOffset, (float)p1.Y); var v2 = new Vector3((float)p2.X, distances[p2] > 0 ? roofHeight + roofOffset : roofOffset, (float)p2.Y); if (i == 0) { meshIndex.AddPlane(v0, v1, v2, meshData.NextIndex); } AddTriangle(meshData, gradient, v0, v1, v2); } }
private void HandleComplexCase(MeshData meshData, MultiPlaneMeshIndex meshIndex, GradientWrapper gradient, Skeleton skeleton, EdgeResult edge, float roofOffset, float roofHeight) { var polygon = edge.Polygon; var distances = skeleton.Distances; using (var trianglePolygon = new Polygon(polygon.Count, ObjectPool)) { trianglePolygon.AddContour(polygon.Select(p => new Point(p.X, p.Y)).ToList()); var mesh = trianglePolygon.Triangulate(); bool planeIsAdded = false; foreach (var triangle in mesh.Triangles) { var p0 = new Vector2d(triangle.vertices[0].X, triangle.vertices[0].Y); var p1 = new Vector2d(triangle.vertices[1].X, triangle.vertices[1].Y); var p2 = new Vector2d(triangle.vertices[2].X, triangle.vertices[2].Y); double y; if (distances.TryGetValue(p0, out y) && y > 0) { y = roofHeight + roofOffset; } else { y = roofOffset; } var v0 = new Vector3((float)p0.X, (float)y, (float)p0.Y); if (distances.TryGetValue(p1, out y) && y > 0) { y = roofHeight + roofOffset; } else { y = roofOffset; } var v1 = new Vector3((float)p1.X, (float)y, (float)p1.Y); if (distances.TryGetValue(p2, out y) && y > 0) { y = roofHeight + roofOffset; } else { y = roofOffset; } var v2 = new Vector3((float)p2.X, (float)y, (float)p2.Y); if (!planeIsAdded) { meshIndex.AddPlane(v0, v1, v2, meshData.NextIndex); planeIsAdded = true; } AddTriangle(meshData, gradient, v0, v1, v2); } } }
public AutoFitPoint(ROI roi, MeasureAssistant mAssist) : base(roi, mAssist) { mResult = new EdgeResult(); mResultWorld = new EdgeResult(); if (mMeasAssist.IsCalibrationValid) { _cameraOut = HMisc.ChangeRadialDistortionCamPar("adaptive", mMeasAssist.CameraIn, 0.0); } UpdateMeasure(); }
public AutoFitPoint(ROI roi, MeasureAssistant mAssist) : base(roi, mAssist) { mResult = new EdgeResult(); mResultWorld = new EdgeResult(); if (mMeasAssist.IsCalibrationValid) { _cameraOut = HMisc.ChangeRadialDistortionCamPar("adaptive", mMeasAssist.CameraIn, 0.0); } UpdateMeasure(); }
/// <summary> /// 演算法改這裡 /// </summary> public override void UpdateResults() { if (mHandle == null) return; mMeasAssist.exceptionText = ""; try { HObject imageReduced; HOperatorSet.GenEmptyObj(out imageReduced); //建 ROI var roiModel = mRoi.getModelData(); HTuple row = roiModel[0]; var column = roiModel[1]; var phi = roiModel[2]; var length1 = roiModel[3]; var length2 = roiModel[4]; //Halcon 徑度轉角度 double degree = phi.D.HalconPhiToDegree(); bool terminate = false; double degreeSeed, finalDegree; degreeSeed = finalDegree = degree; //reset result mResult = new EdgeResult(); //旋轉角度, Search Point while (!HasResult) { var region = getRectangle2(row, column, degreeSeed, length1, length2); var regionImage = getRegionImage(region); //Reset Handle and mResult mHandle = new HMeasure(mMeasROI[0].D, mMeasROI[1].D, degreeSeed.ToHalconPhi(), mMeasROI[3].D, mMeasROI[4].D, mMeasAssist.mWidth, mMeasAssist.mHeight, mMeasAssist.mInterpolation); measurePos(regionImage); finalDegree = degreeSeed; degreeSeed = getNextSeed(degreeSeed, phi.D, ref terminate); if (terminate) break; } mResultWorld = new EdgeResult(mResult); //Update Model var updateableROI = mRoi as ViewROI.Interface.IROIModelUpdateable; if (updateableROI != null) { mMeasROI[2].D = finalDegree.ToHalconPhi(); var updateROIModel = new ROIViewModel() { CenterRow = row.D, CenterCol = column.D, Phi = finalDegree.ToHalconPhi(), Length = length1.D, Width = length2.D, }; updateableROI.UpdateROIModel(updateROIModel); } } catch (HOperatorException e) { mEdgeXLD.Dispose(); mMeasAssist.exceptionText = e.Message; mResultWorld = new EdgeResult(); return; } UpdateXLD(); }
public override void ClearResultData() { mResultWorld = new EdgeResult(); }
/// <summary> /// 演算法改這裡 /// </summary> public override void UpdateResults() { if (mHandle == null) { return; } mMeasAssist.exceptionText = ""; try { HObject imageReduced; HOperatorSet.GenEmptyObj(out imageReduced); //建 ROI var roiModel = mRoi.getModelData(); HTuple row = roiModel[0]; var column = roiModel[1]; var phi = roiModel[2]; var length1 = roiModel[3]; var length2 = roiModel[4]; //Halcon 徑度轉角度 double degree = phi.D.HalconPhiToDegree(); bool terminate = false; double degreeSeed, finalDegree; degreeSeed = finalDegree = degree; //reset result mResult = new EdgeResult(); //旋轉角度, Search Point while (!HasResult) { var region = getRectangle2(row, column, degreeSeed, length1, length2); var regionImage = getRegionImage(region); //Reset Handle and mResult mHandle = new HMeasure(mMeasROI[0].D, mMeasROI[1].D, degreeSeed.ToHalconPhi(), mMeasROI[3].D, mMeasROI[4].D, mMeasAssist.mWidth, mMeasAssist.mHeight, mMeasAssist.mInterpolation); measurePos(regionImage); finalDegree = degreeSeed; degreeSeed = getNextSeed(degreeSeed, phi.D, ref terminate); if (terminate) { break; } } mResultWorld = new EdgeResult(mResult); //Update Model var updateableROI = mRoi as ViewROI.Interface.IROIModelUpdateable; if (updateableROI != null) { mMeasROI[2].D = finalDegree.ToHalconPhi(); var updateROIModel = new ROIViewModel() { CenterRow = row.D, CenterCol = column.D, Phi = finalDegree.ToHalconPhi(), Length = length1.D, Width = length2.D, }; updateableROI.UpdateROIModel(updateROIModel); } } catch (HOperatorException e) { mEdgeXLD.Dispose(); mMeasAssist.exceptionText = e.Message; mResultWorld = new EdgeResult(); return; } UpdateXLD(); }
public override void ClearResultData() { mResultWorld = new EdgeResult(); }