Пример #1
0
        private void PrepareHeaderAndMap(string path, Image imageGain, decimal scaleFactor, out MapHeader header, out Image stack)
        {
            header = MapHeader.ReadFromFile(path,
                                            new int2(MainWindow.Options.InputDatWidth, MainWindow.Options.InputDatHeight),
                                            MainWindow.Options.InputDatOffset,
                                            ImageFormatsHelper.StringToType(MainWindow.Options.InputDatType));

            if (scaleFactor == 1M)
            {
                stack = StageDataLoad.LoadMap(path,
                                              new int2(MainWindow.Options.InputDatWidth, MainWindow.Options.InputDatHeight),
                                              MainWindow.Options.InputDatOffset,
                                              ImageFormatsHelper.StringToType(MainWindow.Options.InputDatType));

                if (imageGain != null)
                    stack.MultiplySlices(imageGain);
                stack.Xray(20f);
            }
            else
            {
                int3 ScaledDims = new int3((int)Math.Round(header.Dimensions.X * scaleFactor),
                                           (int)Math.Round(header.Dimensions.Y * scaleFactor),
                                           header.Dimensions.Z);
                header.Dimensions = ScaledDims;

                stack = new Image(ScaledDims);
                float[][] OriginalStackData = stack.GetHost(Intent.Write);

                //Parallel.For(0, ScaledDims.Z, new ParallelOptions {MaxDegreeOfParallelism = 4}, z =>
                for (int z = 0; z < ScaledDims.Z; z++)
                {
                    Image Layer = StageDataLoad.LoadMap(path,
                                                        new int2(MainWindow.Options.InputDatWidth, MainWindow.Options.InputDatHeight),
                                                        MainWindow.Options.InputDatOffset,
                                                        ImageFormatsHelper.StringToType(MainWindow.Options.InputDatType),
                                                        z);
                    //lock (OriginalStackData)
                    {
                        if (imageGain != null)
                            Layer.MultiplySlices(imageGain);
                        Layer.Xray(20f);

                        Image ScaledLayer = Layer.AsScaledMassive(new int2(ScaledDims));
                        Layer.Dispose();

                        OriginalStackData[z] = ScaledLayer.GetHost(Intent.Read)[0];
                        ScaledLayer.Dispose();
                    }
                }//);

                //stack.WriteMRC("d_stack.mrc");
            }
        }