public static bool WithinFrustum(Point3D inP, BoundingPlanes boundingPlanes, double mdblProximityValue) { if (!IsInsideOfPlane(inP, boundingPlanes.FrontPlane, mdblProximityValue))//front { return(false); } else if (!IsInsideOfPlane(inP, boundingPlanes.BackPlane, mdblProximityValue))//back { return(false); } else if (!IsInsideOfPlane(inP, boundingPlanes.RightPlane, mdblProximityValue))//right { return(false); } else if (!IsInsideOfPlane(inP, boundingPlanes.TopPlane, mdblProximityValue))//top { return(false); } else if (!IsInsideOfPlane(inP, boundingPlanes.LeftPlane, mdblProximityValue))//left { return(false); } else if (!IsInsideOfPlane(inP, boundingPlanes.BottomPlane, mdblProximityValue))//bottom { return(false); } else { return(true); } }
public static bool ProcessMoldPoints(Params mp, uint y1, uint z1, uint y2, uint z2, double y1Pos, double z1Pos, BoundingPlanes objBoundingPlanes, MoldActionType actionType, ref bool blnAValidPtFound) { Point3D startPoint = new Point3D(); Point3D endPoint = new Point3D(); Point3D testPoint = new Point3D(); byte btPointsFound, btCtr; PlaneEquation curPlane = new PlaneEquation(1.0f, 0.0f, 0.0f, 0.0f);//temp initialization double dblTempPt; bool blnInside; uint iy; uint iz; double y, z; //variables used while traversing uint uintInvalidPtX1, uintInvalidPtX2; //X1 and X2 specify the starting and ending indices //of the range of invalid points found in a horizontal line at a particular y and z value //traverse through the array of points to set the points as invalid for (z = z1Pos, iz = z1; iz <= z2; z += mp.DZ, iz++) { //all pts //Since the line is along x axis, the y and z value for the point of //intersection will remain the same testPoint.Z = z; for (y = y1Pos, iy = y1; iy <= y2; y += mp.DY, iy++) { //pts along x-y plane //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// //Major change: Checking each point along any axis is taking too much of time which is //undesirable. Now onwards, I have decided to change this to find all the invalid points at //one go. First we find the points of intersection of the line with the faces of the invalid //region, such that the points of intersection lie inside the invalid region. We should always //get two such points if there exists an invalid region for the particular value of y and z. // //After identifying the points of intersection, we will set all the points that lie in between //them as invalid. btPointsFound = 0; //Since the line is along x axis, the y and z value for the point of //intersection will remain the same testPoint.Y = y; //Try the point of intersection with the bounding planes. We should get two such points byte btTotalPlanes; if (!mp.CamInCuboid) { btTotalPlanes = 6; } else { btTotalPlanes = 5; } for (btCtr = 1; btCtr <= btTotalPlanes; btCtr++) { switch (btCtr) { case 1: curPlane = objBoundingPlanes.LeftPlane; break; case 2: curPlane = objBoundingPlanes.RightPlane; break; case 3: curPlane = objBoundingPlanes.TopPlane; break; case 4: curPlane = objBoundingPlanes.BottomPlane; break; case 5: curPlane = objBoundingPlanes.BackPlane; break; case 6: curPlane = objBoundingPlanes.FrontPlane; break; } if (curPlane.A != 0.0f) { //Not parallel to the X axis //Find the x value of the point of intersection testPoint.X = (curPlane.B * y + curPlane.C * z + curPlane.D) / (-curPlane.A); if (!mp.CamInCuboid) { blnInside = HelperFunctions.WithinFrustum(testPoint, objBoundingPlanes, mp.ProximityVal); } else { blnInside = HelperFunctions.WithinPyramid(testPoint, objBoundingPlanes, mp.ProximityVal); } if (blnInside && btPointsFound == 1) { //compare for duplicate points if (CommonFunctions.ModValue(testPoint.X - startPoint.X) <= mp.ProximityVal) { //The points can be assumed to be the same blnInside = false; } } if (blnInside) { btPointsFound++; if (btPointsFound == 2) { endPoint = testPoint; } else { startPoint = testPoint; } } } if (btPointsFound == 2) { break; //Don't look further if two points are already found } } if (btPointsFound > 0) { //Find invalid points and set their status in the file if (btPointsFound == 2) { if (endPoint.X < startPoint.X) { //Swap the points dblTempPt = endPoint.X; endPoint.X = startPoint.X; startPoint.X = dblTempPt; } } else { //Just one point has been found endPoint = startPoint; } uintInvalidPtX1 = HelperFunctions.GetClosestPtIndex(startPoint.X, true, mp.Cuboid, mp.DX, mp.ProximityVal); if (uintInvalidPtX1 == 0) { continue; } uintInvalidPtX2 = HelperFunctions.GetClosestPtIndex(endPoint.X, false, mp.Cuboid, mp.DX, mp.ProximityVal); if (uintInvalidPtX2 == 0 || (uintInvalidPtX1 > uintInvalidPtX2)) { continue; } if (actionType == MoldActionType.SetInvalidPts) { //set the points as invalid in the file if (!mp.MoldDataHandler.SetPointRanges(uintInvalidPtX1, uintInvalidPtX2, iy, iz)) { return(false); } } else if (actionType == MoldActionType.CheckForAllPtsSetToInvalid) { //traverse the mold points and see if any point is valid if (!mp.MoldDataHandler.CheckPointRangesForValidity(uintInvalidPtX1, uintInvalidPtX2, iy, iz, ref blnAValidPtFound)) { return(false); } if (blnAValidPtFound) //Currently we will only lookout for the presence of any valid point even if it is just one { return(true); } } else { throw new Exception("Invalid mold action type"); } } } //y } //z return(true); }
public static bool ProcessImgPixelPositions(Params mp, uint inX1, uint inX2, uint inY, MoldActionType actionType, ref bool blnAValidPtFound) { #region variable definitions Point3D[] frstmFt = new Point3D[4]; //end points of the frustum or pyramid Point3D[] frstmBk = new Point3D[4]; Point3D upFLeft, upFRight, downFLeft, downFRight; //points at the same height on the //far rectangle as that of the corners of the invalid rectangle Point3D upNLeft, upNRight, downNLeft, downNRight; //points at the same height on the //far rectangle as that of the corners of the invalid rectangle double miny, maxy, minz, maxz; //defines the limit within which cuboid points //are to be considered uint y1, z1; //first indexes from where we start traversing the cuboid points uint y2, z2; //Last indexes double y1Pos, z1Pos; #endregion variable definitions #region define the back face on the far rectangle #region first get the heights of the four sides of the invalid rectangle if (inY == mp.YPixels) { //top most pixel upFLeft = mp.FarPlane[0]; upFRight = mp.FarPlane[3]; } else { upFLeft = CommonFunctions.GetMiddlePoint(mp.FarPlane[1], mp.FarPlane[0], inY, mp.YPixels); upFRight = CommonFunctions.GetMiddlePoint(mp.FarPlane[2], mp.FarPlane[3], inY, mp.YPixels); } if (inY == 1) { //inY is one for the bottommost pixel downFLeft = mp.FarPlane[1]; downFRight = mp.FarPlane[2]; } else { downFLeft = CommonFunctions.GetMiddlePoint(mp.FarPlane[1], mp.FarPlane[0], inY - 1, mp.YPixels); downFRight = CommonFunctions.GetMiddlePoint(mp.FarPlane[2], mp.FarPlane[3], inY - 1, mp.YPixels); } #endregion #region now move these points horizontally to make the actual invalid rectangle if (inX1 == 0) { frstmBk[0] = upFLeft; frstmBk[1] = downFLeft; } else { frstmBk[0] = CommonFunctions.GetMiddlePoint(upFLeft, upFRight, inX1, mp.XPixels); frstmBk[1] = CommonFunctions.GetMiddlePoint(downFLeft, downFRight, inX1, mp.XPixels); } if (inX2 == mp.XPixels) { frstmBk[3] = upFRight; frstmBk[2] = downFRight; } else { frstmBk[3] = CommonFunctions.GetMiddlePoint(upFLeft, upFRight, inX2, mp.XPixels); frstmBk[2] = CommonFunctions.GetMiddlePoint(downFLeft, downFRight, inX2, mp.XPixels); } #endregion move horizontally #endregion back face #region define the front face if (mp.MProcessMoldParams.ImageParams.CameraAtInfinity) { #region first get the heights of the four sides of the invalid rectangle if (inY == mp.YPixels) { //top most pixel upNLeft = mp.NearPlane[0]; upNRight = mp.NearPlane[3]; } else { upNLeft = CommonFunctions.GetMiddlePoint(mp.NearPlane[1], mp.NearPlane[0], inY, mp.YPixels); upNRight = CommonFunctions.GetMiddlePoint(mp.NearPlane[2], mp.NearPlane[3], inY, mp.YPixels); } if (inY == 1) { //inY is one for the bottommost pixel downNLeft = mp.NearPlane[1]; downNRight = mp.NearPlane[2]; } else { downNLeft = CommonFunctions.GetMiddlePoint(mp.NearPlane[1], mp.NearPlane[0], inY - 1, mp.YPixels); downNRight = CommonFunctions.GetMiddlePoint(mp.NearPlane[2], mp.NearPlane[3], inY - 1, mp.YPixels); } #endregion #region now move these points horizontally to make the actual invalid rectangle if (inX1 == 0) { frstmFt[0] = upNLeft; frstmFt[1] = downNLeft; } else { frstmFt[0] = CommonFunctions.GetMiddlePoint(upNLeft, upNRight, inX1, mp.XPixels); frstmFt[1] = CommonFunctions.GetMiddlePoint(downNLeft, downNRight, inX1, mp.XPixels); } if (inX2 == mp.XPixels) { frstmFt[3] = upNRight; frstmFt[2] = downNRight; } else { frstmFt[3] = CommonFunctions.GetMiddlePoint(upNLeft, upNRight, inX2, mp.XPixels); frstmFt[2] = CommonFunctions.GetMiddlePoint(downNLeft, downNRight, inX2, mp.XPixels); } #endregion move horizontally } else if (!mp.CamInCuboid) { //camera outside the target cuboid but not at infinity #region use the distance formula frstmFt[0] = CommonFunctions.GetMiddlePoint(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[0], mp.DNear, mp.DFar); frstmFt[1] = CommonFunctions.GetMiddlePoint(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[1], mp.DNear, mp.DFar); frstmFt[2] = CommonFunctions.GetMiddlePoint(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[2], mp.DNear, mp.DFar); frstmFt[3] = CommonFunctions.GetMiddlePoint(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[3], mp.DNear, mp.DFar); #endregion } #endregion front face #region calculate the equations of the bounding planes var objBoundingPlanes = new BoundingPlanes(); if (mp.CamInCuboid) { objBoundingPlanes.BackPlane = new PlaneEquation(frstmBk[3], frstmBk[2], frstmBk[1]); //back objBoundingPlanes.RightPlane = new PlaneEquation(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[2], frstmBk[3]); //right objBoundingPlanes.TopPlane = new PlaneEquation(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[3], frstmBk[0]); //top objBoundingPlanes.LeftPlane = new PlaneEquation(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[0], frstmBk[1]); //left objBoundingPlanes.BottomPlane = new PlaneEquation(mp.MProcessMoldParams.ImageParams.cameraLocation, frstmBk[1], frstmBk[2]); //bottom } else { objBoundingPlanes.FrontPlane = new PlaneEquation(frstmFt[0], frstmFt[1], frstmFt[2]); //front objBoundingPlanes.BackPlane = new PlaneEquation(frstmBk[3], frstmBk[2], frstmBk[1]); //back objBoundingPlanes.RightPlane = new PlaneEquation(frstmFt[2], frstmBk[2], frstmBk[3]); //right objBoundingPlanes.TopPlane = new PlaneEquation(frstmFt[3], frstmBk[3], frstmBk[0]); //top objBoundingPlanes.LeftPlane = new PlaneEquation(frstmFt[0], frstmBk[0], frstmBk[1]); //left objBoundingPlanes.BottomPlane = new PlaneEquation(frstmFt[1], frstmBk[1], frstmBk[2]); //bottom } #endregion #region get the coordinate ranges within which the invalid frustum or pyramid lies if (!mp.CamInCuboid) { //minx = Min(frstmFt[0].X, frstmFt[1].X, frstmFt[2].X, frstmFt[3].X, // frstmBk[0].X, frstmBk[1].X, frstmBk[2].X, frstmBk[3].X ); // maxx = Max(frstmFt[0].X, frstmFt[1].X, frstmFt[2].X, frstmFt[3].X, // frstmBk[0].X, frstmBk[1].X, frstmBk[2].X, frstmBk[3].X ); miny = CommonFunctions.Min(frstmFt[0].Y, frstmFt[1].Y, frstmFt[2].Y, frstmFt[3].Y, frstmBk[0].Y, frstmBk[1].Y, frstmBk[2].Y, frstmBk[3].Y); maxy = CommonFunctions.Max(frstmFt[0].Y, frstmFt[1].Y, frstmFt[2].Y, frstmFt[3].Y, frstmBk[0].Y, frstmBk[1].Y, frstmBk[2].Y, frstmBk[3].Y); minz = CommonFunctions.Min(frstmFt[0].Z, frstmFt[1].Z, frstmFt[2].Z, frstmFt[3].Z, frstmBk[0].Z, frstmBk[1].Z, frstmBk[2].Z, frstmBk[3].Z); maxz = CommonFunctions.Max(frstmFt[0].Z, frstmFt[1].Z, frstmFt[2].Z, frstmFt[3].Z, frstmBk[0].Z, frstmBk[1].Z, frstmBk[2].Z, frstmBk[3].Z); } else { //minx = Min(mp.MProcessMoldParams.imgParams.cameraLocation.X, // frstmBk[0].X, frstmBk[1].X, frstmBk[2].X, frstmBk[3].X ); //maxx = Max(mp.MProcessMoldParams.imgParams.cameraLocation.X, // frstmBk[0].X, frstmBk[1].X, frstmBk[2].X, frstmBk[3].X ); miny = CommonFunctions.Min(mp.MProcessMoldParams.ImageParams.cameraLocation.Y, frstmBk[0].Y, frstmBk[1].Y, frstmBk[2].Y, frstmBk[3].Y); maxy = CommonFunctions.Max(mp.MProcessMoldParams.ImageParams.cameraLocation.Y, frstmBk[0].Y, frstmBk[1].Y, frstmBk[2].Y, frstmBk[3].Y); minz = CommonFunctions.Min(mp.MProcessMoldParams.ImageParams.cameraLocation.Z, frstmBk[0].Z, frstmBk[1].Z, frstmBk[2].Z, frstmBk[3].Z); maxz = CommonFunctions.Max(mp.MProcessMoldParams.ImageParams.cameraLocation.Z, frstmBk[0].Z, frstmBk[1].Z, frstmBk[2].Z, frstmBk[3].Z); } //check whether min values lie outside target cuboid if ( //minx > xLast || maxx < xFirst || miny > mp.YLast || maxy < mp.YFirst || minz > mp.ZLast || maxz < mp.ZFirst) { return(true); //no points effected } //set the starting and ending values within range of target cuboid /*Modified on 29-Jan-2004 Using proximity value in the calculations * //min values * if(minx <= xFirst) * x1 = 1 ; * else * x1 = 1 + CommonFunctions.GetIntFromFloat ((minx - xFirst) /dX) ; * * if(miny <= yFirst) * y1 = 1 ; * else * y1 = 1 + CommonFunctions.GetIntFromFloat ((miny - yFirst) /dY) ; * * if(minz <= zFirst) * z1 = 1 ; * else * z1 = 1 + CommonFunctions.GetIntFromFloat ((minz - zFirst) /dZ) ; */ // if(minx <= xFirst + fltProximityValue) // x1 = 1 ; // else // x1 = 1 + CommonFunctions.GetIntFromFloat ((minx - (xFirst + fltProximityValue)) /dX) ; if (miny <= mp.YFirst) { y1 = 1; } else { y1 = 1 + CommonFunctions.GetUIntFromDouble((miny - (mp.YFirst + mp.ProximityVal)) / mp.DY); } if (minz <= mp.ZFirst) { z1 = 1; } else { z1 = 1 + CommonFunctions.GetUIntFromDouble((minz - (mp.ZFirst + mp.ProximityVal)) / mp.DZ); } //End of modification============================================== // x1Pos = xFirst + dX * ( (double)(x1-1) ) ; y1Pos = mp.YFirst + mp.DY * ((double)(y1 - 1)); z1Pos = mp.ZFirst + mp.DZ * ((double)(z1 - 1)); /*Modified on 29-Jan-2004 Using proximity value in the calculations * //max values * if(maxx >= xLast) * x2 = targetCuboid.uintXPoints; * else * x2 = 1 + CommonFunctions.GetIntFromFloat ((maxx - xFirst) /dX) ; * * * if(maxy >= yLast) * y2 = targetCuboid.uintYPoints ; * else * y2 = 1 + CommonFunctions.GetIntFromFloat ((maxy - yFirst) /dY) ; * * * if(maxz >= zLast) * z2 = targetCuboid.uintZPoints ; * else * z2 = 1 + CommonFunctions.GetIntFromFloat ((maxz - zFirst) /dZ) ; */ // if(maxx >= xLast - fltProximityValue) // x2 = targetCuboid.uintXPoints ; // else // x2 = 1 + CommonFunctions.GetIntFromFloat ((maxx - (xFirst - fltProximityValue)) /dX) ; if (maxy >= mp.YLast) { y2 = mp.Cuboid.uintYPoints; } else { y2 = 1 + CommonFunctions.GetUIntFromDouble((maxy - (mp.YFirst - mp.ProximityVal)) / mp.DY); } if (maxz >= mp.ZLast) { z2 = mp.Cuboid.uintZPoints; } else { z2 = 1 + CommonFunctions.GetUIntFromDouble((maxz - (mp.ZFirst - mp.ProximityVal)) / mp.DZ); } //End of modification #endregion //process the evaluated mold points using the bounding plane values return(ProcessMoldPoints(mp, y1, z1, y2, z2, y1Pos, z1Pos, objBoundingPlanes, actionType, ref blnAValidPtFound)); }