Example #1
0
        public static int ProcessImage(ProcessMoldParams moldParams)
        {
            var pixelsWithAllPointsLost = 0;
            var parameters = new Params(moldParams);

            for (var j = 1; j <= parameters.YPixels; j++)
            {
                for (var i = 1; i <= parameters.XPixels; i++)
                {
                    var isSameRgbColor = IsSameRgbColor(i, j, parameters.MProcessMoldParams.ImageParams.InvalidColor, parameters.ImageHandler);
                    if (isSameRgbColor)
                    {
                        continue;
                    }

                    var blnAValidPtFound = false;
                    if (!HelperFunctions.ProcessImgPixelPositions(parameters, (uint)i, (uint)i, (uint)j, MoldActionType.CheckForAllPtsSetToInvalid, ref blnAValidPtFound))
                    {
                        return(-1);
                    }

                    if (!blnAValidPtFound)
                    {
                        pixelsWithAllPointsLost++;
                        parameters.ImageHandler.SetLostDataColorForPixel(Convert.ToInt32(i), Convert.ToInt32(j));
                    }
                    else if (parameters.MProcessMoldParams.SetColorForRetainedPixels)
                    {
                        parameters.ImageHandler.SetRetainedDataColorForPixel(Convert.ToInt32(i), Convert.ToInt32(j));
                    }
                }
            }

            return(pixelsWithAllPointsLost);
        }
Example #2
0
 public ImagesToObject(ProcessMoldParams objProcessMoldParams, string logFilePath)
 {
     mp      = new Params(objProcessMoldParams);
     _logger = new Logger(logFilePath);
 }
Example #3
0
        public Params(ProcessMoldParams objProcessMoldParams)
        {
            //Get the handle to the data object
            mobjProcessMoldParams = objProcessMoldParams;

            //initialize the MoldDataHandler object
            mobjMoldDataHandler = new MoldDataHandler(mobjProcessMoldParams.MoldData);

            mobjMoldDataHandler.RetrieveValues(ref mTargetCuboid, false);

            if (mTargetCuboid.uintXPoints == 0 || mTargetCuboid.uintYPoints == 0 || mTargetCuboid.uintZPoints == 0)
            {
                throw new Exception("One or more of the points set along the three axes is invalid.");
            }

            /* Modified on 28th Jan 2004: Rather than offsetting the points from the corners, now I
             * am placing them right from one corner to the other.
             * //calculate the distance between two points on the target cuboid
             * dX = (targetCuboid.fltMaxx-targetCuboid.fltMinx) /  ((double)targetCuboid.uintXPoints) ;
             * dY = (targetCuboid.fltMaxy-targetCuboid.fltMiny) /  ((double)targetCuboid.uintYPoints) ;
             * dZ = (targetCuboid.fltMaxz-targetCuboid.fltMinz) /  ((double)targetCuboid.uintZPoints) ;
             *
             * //Find the positions of the first cuboid point along the three axes
             * xFirst = targetCuboid.fltMinx + dX / 2.0f;
             * yFirst = targetCuboid.fltMiny + dY / 2.0f;
             * zFirst = targetCuboid.fltMinz + dZ / 2.0f;
             *
             * //Find the positions of the last cuboid point along the three axes
             * xLast  = targetCuboid.fltMaxx - dX / 2.0f;
             * yLast  = targetCuboid.fltMaxy - dY / 2.0f;
             * zLast  = targetCuboid.fltMaxz - dZ / 2.0f;
             */

            //Beginnning of modified code=======================================
            mdX = (mTargetCuboid.fltMaxx - mTargetCuboid.fltMinx) / ((double)(mTargetCuboid.uintXPoints - 1));
            mdY = (mTargetCuboid.fltMaxy - mTargetCuboid.fltMiny) / ((double)(mTargetCuboid.uintYPoints - 1));
            mdZ = (mTargetCuboid.fltMaxz - mTargetCuboid.fltMinz) / ((double)(mTargetCuboid.uintZPoints - 1));

            //Find the positions of the first cuboid point along the three axes
            mxFirst = mTargetCuboid.fltMinx;
            myFirst = mTargetCuboid.fltMiny;
            mzFirst = mTargetCuboid.fltMinz;

            //Find the positions of the last cuboid point along the three axes
            mxLast = mTargetCuboid.fltMaxx;
            myLast = mTargetCuboid.fltMaxy;
            mzLast = mTargetCuboid.fltMaxz;
            //End of modified code==============================================

            //Store the corners of the cuboid in an array
            //We start from the top left in anticlockwise direction
            marrCuboidFt[0] = new Point3D(mTargetCuboid.fltMinx, mTargetCuboid.fltMaxy, mTargetCuboid.fltMaxz);

            marrCuboidFt[1] = new Point3D(mTargetCuboid.fltMinx, mTargetCuboid.fltMiny, mTargetCuboid.fltMaxz);

            marrCuboidFt[2] = new Point3D(mTargetCuboid.fltMaxx, mTargetCuboid.fltMiny, mTargetCuboid.fltMaxz);

            marrCuboidFt[3] = new Point3D(mTargetCuboid.fltMaxx, mTargetCuboid.fltMaxy, mTargetCuboid.fltMaxz);

            marrCuboidBk[0] = new Point3D(mTargetCuboid.fltMinx, mTargetCuboid.fltMaxy, mTargetCuboid.fltMinz);

            marrCuboidBk[1] = new Point3D(mTargetCuboid.fltMinx, mTargetCuboid.fltMiny, mTargetCuboid.fltMinz);

            marrCuboidBk[2] = new Point3D(mTargetCuboid.fltMaxx, mTargetCuboid.fltMiny, mTargetCuboid.fltMinz);

            marrCuboidBk[3] = new Point3D(mTargetCuboid.fltMaxx, mTargetCuboid.fltMaxy, mTargetCuboid.fltMinz);


            //Added on 29-Jan-2004. See top of the file for details.
            mdblProximityVal = CommonFunctions.GetMin(mdX, mdY, mdZ) / Params.mcdblProximityConstant;

            if (!HelperFunctions.SetNearFarRectangle(
                    ref marrFarPlane, ref marrNearPlane, ref mdNear, ref mdFar, ref mblnCamInCuboid,
                    marrCuboidFt, marrCuboidBk,
                    mobjProcessMoldParams.ImageParams.cameraLocation, mobjProcessMoldParams.ImageParams.lookingAt,
                    mobjProcessMoldParams.ImageParams.CameraRatio, mobjProcessMoldParams.ImageParams.CameraAtInfinity,
                    mdblProximityVal))
            {
                throw new Exception("The SetNearFarRectangle function failed");
            }

            mobjImageHandler = new ImageHandler(mobjProcessMoldParams.ImageParams.Image);
            muintXPixels     = Convert.ToUInt32(mobjImageHandler.Width);
            muintYPixels     = Convert.ToUInt32(mobjImageHandler.Height);
        }
Example #4
0
        public static void ApplyImage(CreateMeshContract inputParams, int index, ref Stream moldDataPtr, Logger logger)
        {
            var clickInput = inputParams.ClickInputs.ImageClickInputDetailsList[index];
            var angle      = inputParams.ClickInputs.Angles[index];

            var imageAlterationParameters = new ImageAlterationParams
            {
                MoldPtDensity        = inputParams.PtDensity,
                MinImageHeightRatio  = inputParams.MinImageHeightRatio,
                PercentExtraWidth    = inputParams.PercentExtraWidth,
                ImageFolder          = inputParams.ImageFolder,
                InvalidColor         = inputParams.InvalidColor,
                ResizeType           = ResizeType.ComputeSizeBasedOnPtDensity,
                BottomPaddingPercent = inputParams.BottomPaddingPercent
            };
            var imageParams = ImageProcessor.GetImageParams(inputParams.VariationIn3DCoordinates, inputParams.BackgroundStrippingParams, clickInput, angle, imageAlterationParameters);

            if (moldDataPtr == null)
            {
                moldDataPtr = CreateMoldDataStream(imageParams.Image.Width, imageParams.Image.Height, (float)inputParams.VariationIn3DCoordinates, inputParams.PtDensity, logger);
            }

            var processMoldParams = new ProcessMoldParams
            {
                MoldData    = moldDataPtr,
                ImageParams = imageParams
            };
            var imagesToObject = new ImagesToObject(processMoldParams, inputParams.LogFilePath);

            imagesToObject.ProcessImage();

            #region track_changes_for_troubleshooting

            if (inputParams.SaveProcessedImages)
            {
                SaveProcessedImages(processMoldParams.ImageParams.Image, inputParams.ImageFolder, "ibmodeler3_modified_images", index, angle, logger);
            }

            var imageParamsToBeReused = false;
            if (AnalyzeMoldForDataLosses)
            {
                //if first time, just set values for subsequent use
                if (index == 0)
                {
                    FirstImageParams      = imageParams;
                    imageParamsToBeReused = true;
                }
                else
                {
                    var processMoldParamsForAnalysis = new ProcessMoldParams
                    {
                        MoldData    = moldDataPtr,
                        ImageParams = FirstImageParams,
                        SetColorForRetainedPixels = false
                    };
                    int pixelsWithAllPointsLost = MoldFileAnalyzerForImg.ProcessImage(processMoldParamsForAnalysis);
                    if (pixelsWithAllPointsLost > 0)
                    {
                        SaveDataLossImages(FirstImageParams.Image, inputParams.ImageFolder, "ibmodeler3_data_loss_analysis", index, angle, pixelsWithAllPointsLost, logger);
                    }
                }
            }

            #endregion

            //this will dispose off the image data from memory
            if (!imageParamsToBeReused)
            {
                imageParams.Dispose();
            }

            logger.Log(string.Format("Image applied for camera at an angle of {0} degrees", Math.Round(angle * 180 / Math.PI, 2)));
        }