public bool DrawPolygon(IRaster pRaster, ExOriPara pExOriPara, InOriPara pInOriPara, IFeatureClass pFeatureClass, int nID) { try { Point2D[,] ptResult = null; ClsGetCameraView CGetCameraView = new ClsGetCameraView(); if (CGetCameraView.ImageReprojectionRange(pRaster, out ptResult, pExOriPara, pInOriPara, 50)) { IPointCollection pPointCollection = new PolygonClass(); for (int j = 0; j < ptResult.GetLength(1); j++) { if (ptResult[0, j] == null) { continue; } IPoint pPoint1 = new PointClass(); pPoint1.X = ptResult[0, j].X; pPoint1.Y = ptResult[0, j].Y; pPointCollection.AddPoint(pPoint1); } for (int k = ptResult.GetLength(1) - 1; k >= 0; k--) { if (ptResult[1, k] == null) { continue; } IPoint pPoint2 = new PointClass(); pPoint2.X = ptResult[1, k].X; pPoint2.Y = ptResult[1, k].Y; pPointCollection.AddPoint(pPoint2); } IFeature pFeatureTemp = pFeatureClass.CreateFeature(); IPolygon pPolygon = new PolygonClass(); pPolygon = pPointCollection as IPolygon; pPolygon.Close(); pFeatureTemp.Shape = pPolygon as IGeometry; pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("PointID"), nID); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("X"), pExOriPara.pos.X); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("Y"), pExOriPara.pos.Y); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("Z"), pExOriPara.pos.Z); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("omg"), pExOriPara.ori.omg); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("phi"), pExOriPara.ori.phi); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("kap"), pExOriPara.ori.kap); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("width"), pInOriPara.nW); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("height"), pInOriPara.nH); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("fx"), pInOriPara.dfx); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("fy"), pInOriPara.dfy); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("f"), pInOriPara.df); pFeatureTemp.Store(); } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
private void drawRaster(IRaster pRaster, ExOriPara pExOriPara, InOriPara pInOriPara) { IRaster pRasterResult; IRasterLayer pRasterLayer = new RasterLayerClass(); ClsGetCameraView CGetCameraView = new ClsGetCameraView(); if (CGetCameraView.ImageReprojectionRange(pRaster, out pRasterResult, pExOriPara, pInOriPara.df, pInOriPara.dx, pInOriPara.dy, pInOriPara.nW, pInOriPara.nH, 50)) { pRasterLayer.CreateFromRaster(pRasterResult); pMapControl.AddLayer(pRasterLayer as ILayer); pMapControl.Refresh(); } }
public bool GetCamOri(Ex_OriPara exOriCamL, IFeatureClass pFeatureClass, int nID) { try { ExOriPara pExOriPara = new ExOriPara(); InOriPara pInOriPara = new InOriPara(); pExOriPara.ori.omg = exOriCamL.ori.omg; pExOriPara.ori.phi = exOriCamL.ori.phi; pExOriPara.ori.kap = exOriCamL.ori.kap; pExOriPara.pos.X = exOriCamL.pos.X; pExOriPara.pos.Y = exOriCamL.pos.Y; pExOriPara.pos.Z = exOriCamL.pos.Z; pInOriPara.df = 1226.23; pInOriPara.dfx = 512; pInOriPara.dfy = 512; pInOriPara.nW = 1024; pInOriPara.nH = 1024; //pInOriPara.dfx = 50; //pInOriPara.dfy = 50; //pInOriPara.nW = 100; //pInOriPara.nH = 100; //pInOriPara.df = CView.PointInformationList[i].f; //pInOriPara.dfx = CView.PointInformationList[i].fx; //pInOriPara.dfy = CView.PointInformationList[i].fy; //pInOriPara.nW = CView.PointInformationList[i].width; //pInOriPara.nH = CView.PointInformationList[i].height; /////////////////////////////////////////////////////////// //非逐点计算 //DrawPolygon(pRasterDem, pExOriPara, pInOriPara, pFeatureClass, nID); //////////////////////////////////////////////////////////////// //逐点计算 drawRaster(pRasterDem, pExOriPara, pInOriPara); } catch (SystemException e) { return(false); } return(true); }
public bool ImageReprojectionRange(IRaster pSrcRaster, out Point2D[,] ptResult, ExOriPara exori, InOriPara pInOri, int nGeoRange) { double dbFocus = pInOri.df; double fx = pInOri.dfx; double fy = pInOri.dfy; int nImgWidth = pInOri.nW; int nImgHeight = pInOri.nH; ptResult = null; Pt2i ptSubImgLeftTop = new Pt2i(); double[,] dbSubDemData = getSubDem(pSrcRaster, exori.pos, nGeoRange, ref ptSubImgLeftTop); if (dbSubDemData == null) { return(false); } IRasterProps pProps = pSrcRaster as IRasterProps; int nDemHeight = pProps.Height; int nDemWidth = pProps.Width; IRaster2 pRaster2 = pSrcRaster as IRaster2; double dbNoDataValue = getNoDataValue(pProps.NoDataValue); //object pNodata = pProps.NoDataValue; //double value=((double[])pNodata)[0]; //double dbNoDataValue =double.Parse((float[]pNodata)[0].ToString()); //double dbNoDataValue = Convert.ToDouble(((double[]))[0]); //object dbNoDataValue = Convert.ToDouble(pProps.NoDataValue.ToString()); //object nodatavalue = pProps.NoDataValue; //Type type=pProps.NoDataValue.GetType(); //double dbNoDataValue = type.IsArray ? nodatavalue[0] as double : nodatavalue as double; //初始步长 double dbInitialStep = 0; int nGridW = nDemWidth / 10; int nGridH = nDemHeight / 10; int nCount = 0; double dbHeightAvg = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { double dDemZ = double.NaN; double dbGeoX = pRaster2.ToMapX(i * nGridW); double dbGeoY = pRaster2.ToMapY(j * nGridH); if (GetGeoZ(pSrcRaster, dbSubDemData, ptSubImgLeftTop, dbGeoX, dbGeoY, ref dDemZ) && Math.Abs(dDemZ - dbNoDataValue) >= 10e-10) { nCount++; dbHeightAvg += dDemZ; } } } if (nCount != 0) { dbHeightAvg /= nCount; } double dbCurCameraZ = 0; //IRaster2 pRaster2 = pSrcRaster as IRaster2; //int nCameraImgX = pRaster2.ToPixelColumn(exori.pos.X);//dXCumulate - pDem.m_PtOrigin.X) / dXRdem; //int nCameraImgY = pRaster2.ToPixelRow(exori.pos.Y); // (dYCumulate - pDem.m_PtOrigin.Y) / dYRdem; //if (nCameraImgY >= 0 || nCameraImgY < nDemHeight || nCameraImgX >= 0 || nCameraImgX < nDemWidth) //{ if (GetGeoZ(pSrcRaster, dbSubDemData, ptSubImgLeftTop, exori.pos.X, exori.pos.Y, ref dbCurCameraZ) && Math.Abs(dbCurCameraZ - dbNoDataValue) >= 10e-10) { dbHeightAvg = dbCurCameraZ; } //} dbInitialStep = Math.Abs(dbHeightAvg - exori.pos.Z) / 2; Point2D ptLeftTop = new Point2D(0, 0); double[] dbResolution = new double[2]; dbResolution[0] = pProps.MeanCellSize().X; dbResolution[1] = pProps.MeanCellSize().Y; int[] nSize = new int[2]; nSize[0] = nDemWidth; nSize[1] = nDemHeight; //pDstRaster = CreateRaster(ptLeftTop, dbResolution, nSize); //pDstRaster = createRasterWithoutData(ptLeftTop, dbResolution[0], nSize, "testOutput.tif"); // byte[,] dbData = new byte[nDemWidth, nDemHeight]; //double demGrayVal=double.NaN; //Pt3d demXYZ; //byte byteGray; //byte bt = (byte)255; //Pt2d pt; Matrix matA, matB; matA = new Matrix(2, 2); matB = new Matrix(2, 1); Matrix matR; matR = new Matrix(3, 3); //Matrix matX; double[] a = new double[4]; double[] b = new double[2]; OPK2RMat(exori.ori, ref matR); //求解相关系数 double a1 = matR.getNum(0, 0); double a2 = matR.getNum(0, 1); double a3 = matR.getNum(0, 2); double b1 = matR.getNum(1, 0); double b2 = matR.getNum(1, 1); double b3 = matR.getNum(1, 2); double c1 = matR.getNum(2, 0); double c2 = matR.getNum(2, 1); double c3 = matR.getNum(2, 2); double[] dbCoef = new double[] { a1, a2, a3, b1, b2, b3, c1, c2, c3 }; //double X, Y, Z, Z1; // Z = 0.0; //double dthreshold = 0.01; //for (int i = 0; i < nDemWidth; i++) //{ // for (int j = 0; j < nDemHeight; j++) // { // dbData[i, j] = bt; // } //} ptResult = new Point2D[2, nImgWidth]; int nSearchStep = 50; for (int j = 0; j < nImgWidth + nSearchStep - 1; j += nSearchStep) { if (j >= nImgWidth) { j = nImgWidth - 1; } //最下面的点 Point2D ptBottom = null, ptTop = null; Point2D ptLastTime = null; if (getPixelIsCoverd(pSrcRaster, dbSubDemData, ptSubImgLeftTop, j, nImgHeight - 1, out ptBottom, exori, dbCoef, dbFocus, fx, fy, dbInitialStep)) { int nposy = 0; int nStep = nImgHeight - 1; while (nStep > 1 && nposy >= 0 && nposy < nImgHeight) { nStep /= 2; if (getPixelIsCoverd(pSrcRaster, dbSubDemData, ptSubImgLeftTop, j, nposy, out ptTop, exori, dbCoef, dbFocus, fx, fy, dbInitialStep)) { if (ptLastTime == null) { ptLastTime = new Point2D(); } ptLastTime.X = ptTop.X; ptLastTime.Y = ptTop.Y; nposy -= nStep; } else { nposy += nStep; } } } //加入链表 ptResult[0, j] = ptLastTime; ptResult[1, j] = ptBottom; } //write block data //if (!WriteToRaster(pDstRaster, dbData, ptLeftTop)) // return false; //if (!writeBlockDataToFile(ptLeftTop, dbData, nSize, pDstRaster)) // return false; return(true); }