Ejemplo n.º 1
0
        /// <summary>
        /// 由点获取轮廓
        /// </summary>
        /// <param name="isLeft">是否在左边</param>
        /// <param name="IgnorePoints">起始结束忽略点数</param>
        /// <param name="Row">输入轮廓行坐标</param>
        /// <param name="Col">输入轮廓列坐标</param>
        /// <param name="RowNew">输出转换后轮廓列坐标</param>
        /// <param name="ColNew">输出转换后轮廓行坐标</param>
        /// <param name="Region">输处转换后轮廓Region</param>
        /// <returns></returns>
        public string GenProfile(bool isLeft, HTuple Row, HTuple Col, out HTuple RowNew, out HTuple ColNew, out HObject Region, out HObject Contour)
        {
            RowNew  = new HTuple(); ColNew = new HTuple(); Region = new HObject();
            Contour = new HObject();
            try
            {
                HTuple Lenr = Row.Length;
                HTuple Lenc = Col.Length;
                HTuple min  = Lenr.TupleMin2(Lenc);
                Row = -Row.TupleSelectRange(0, min.I - 1);
                Col = Col.TupleSelectRange(0, min.I - 1);
                HOperatorSet.GenContourPolygonXld(out Contour, Row, Col);
                //HOperatorSet.WriteObject(Contour, "1.hobj");
                HTuple hommat2DIdentity = new HTuple(); HTuple Hommat2DRotate = new HTuple();
                HTuple Hommat2DTranslate = new HTuple();
                HOperatorSet.HomMat2dIdentity(out hommat2DIdentity);
                //HOperatorSet.HomMat2dRotate(hommat2DIdentity, 1.57, 0, 0, out Hommat2DRotate);
                //HObject tempContour = new HObject();
                //HOperatorSet.AffineTransContourXld(Contour, out tempContour, Hommat2DRotate);
                //HOperatorSet.GetContourXld(tempContour, out Row, out Col);
                HTuple ColMin = Col.TupleMin();

                HOperatorSet.HomMat2dTranslate(hommat2DIdentity, 500, -ColMin + 500, out Hommat2DTranslate);
                HOperatorSet.AffineTransContourXld(Contour, out Contour, Hommat2DTranslate);
                //HOperatorSet.WriteObject(Contour, "2.hobj");
                HOperatorSet.GetContourXld(Contour, out RowNew, out ColNew);
                HOperatorSet.GenRegionPoints(out Region, RowNew, ColNew);

                if (isLeft == false)
                {
                    //找到最高点进行镜像变换
                    HTuple Rowmin = RowNew.TupleMin();
                    HTuple minInd = RowNew.TupleFindFirst(Rowmin);
                    HTuple HomMat2DId = new HTuple(); HTuple HomMat2dReflect = new HTuple();
                    HOperatorSet.HomMat2dIdentity(out HomMat2DId);
                    HOperatorSet.HomMat2dReflect(HomMat2DId, Rowmin, ColNew[minInd] + 50, Rowmin + 100, ColNew[minInd] + 50, out HomMat2dReflect);
                    HOperatorSet.AffineTransContourXld(Contour, out Contour, HomMat2dReflect);
                    HOperatorSet.AffineTransRegion(Region, out Region, HomMat2dReflect, "nearest_neighbor");
                    HOperatorSet.GetContourXld(Contour, out RowNew, out ColNew);
                    HOperatorSet.GenRegionPoints(out Region, RowNew, ColNew);
                    //HOperatorSet.WriteObject(Region, "4.hobj");
                }
                return("OK");
            }
            catch (Exception ex)
            {
                return("GenProfile error " + ex.Message);
            }
        }