Ejemplo n.º 1
0
        /// <summary>
        /// 对指定的RenderWindowControl进行截屏并保存
        /// </summary>
        /// <param name="fn"></param>
        /// <param name="rwc"></param>
        /// <returns></returns>
        public static bool SaveRendererWindowsAsPic(string fn, ref RenderWindowControl rwc)
        {
            bool res = true;

            try
            {
                vtkWindowToImageFilter screenShot = vtkWindowToImageFilter.New();
                screenShot.SetInput(rwc.RenderWindow);
                //screenShot.SetMagnification(3);
                screenShot.SetInputBufferTypeToRGB();
                screenShot.ReadFrontBufferOff();
                screenShot.Update();

                vtkPNGWriter writer = vtkPNGWriter.New();
                writer.SetFileName(fn);
                writer.SetInputConnection(screenShot.GetOutputPort());
                writer.Write();
            }
            catch
            {
                res = false;
            }

            return(res);
        }
Ejemplo n.º 2
0
        private void buttonSaveCurrentPlane_Click(object sender, EventArgs e)
        {
            //make dir
            Random RandNum    = new Random();
            string HashForDir = checkMD5(DateTime.Now.ToLongDateString() + Convert.ToString(RandNum.Next(1111, 9999)));

            Directory.CreateDirectory(Program.TempDir + "\\" + HashForDir);
            StreamWriter IniFileInDir = File.CreateText(Program.TempDir + "\\" + HashForDir + "\\Ini.ini");

            IniFileInDir.WriteLine("[Info]");
            IniFileInDir.WriteLine(@"temp_folder=" + Program.TempDir + "\n" +
                                   "max_scalar = \"\"\n" +
                                   "min_scalar = \"\"\n" +
                                   @"dicom_folder =" + Path.GetDirectoryName(openDicomFileDialog.FileName));
            IniFileInDir.Close();

            Program.IniObj.IniWriteValue("Info", "curr_work_dir", HashForDir);

            Ini localIni = new Ini(Program.TempDir + "\\" + HashForDir + "\\Ini.ini");

            //save scalar data of selected image
            StreamWriter streamWriter = new StreamWriter(Program.TempDir + "\\" + HashForDir + "\\" + "imageScalars.txt");

            for (int i = 0; i < 500; i++)
            {
                for (int j = 0; j < 500; j++)
                {
                    streamWriter.Write(Convert.ToString(
                                           SiteplanesObj.planeWidgetZ.GetResliceOutput().GetScalarComponentAsDouble(i, j, 0, 0)
                                           ) + " ");
                }
                streamWriter.Write("\n");
            }
            streamWriter.Close();

            //save image in png file
            vtkWindowToImageFilter imf = new vtkWindowToImageFilter();

            imf.SetInputBufferTypeToRGBA();
            switch (currentSliceDimension)
            {
            case 1:
            {
                imf.SetInput(vtkFormsWindowControlX.GetRenderWindow());
                localIni.IniWriteValue("Info", "max_scalar", Convert.ToString(SiteplanesObj.rangeXMax));
                localIni.IniWriteValue("Info", "min_scalar", Convert.ToString(SiteplanesObj.rangeXMin));
                break;
            }

            case 2:
            {
                imf.SetInput(vtkFormsWindowControlY.GetRenderWindow());
                localIni.IniWriteValue("Info", "max_scalar", Convert.ToString(SiteplanesObj.rangeYMax));
                localIni.IniWriteValue("Info", "min_scalar", Convert.ToString(SiteplanesObj.rangeYMin));
                break;
            }

            case 3:
            {
                imf.SetInput(vtkFormsWindowControlZ.GetRenderWindow());
                localIni.IniWriteValue("Info", "max_scalar", Convert.ToString(SiteplanesObj.rangeZMax));
                localIni.IniWriteValue("Info", "min_scalar", Convert.ToString(SiteplanesObj.rangeZMin));
                break;
            }
            }
            vtkPNGWriter pngw = new vtkPNGWriter();

            pngw.SetFileName(Program.TempDir + "\\" + HashForDir + "\\" + "\\image.png");
            pngw.SetInputConnection(imf.GetOutputPort());
            pngw.Write();

            System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "imagePreprocessing.exe");

            /*get CT values from
             * SaveFileDialog saveFileDialog1 = new SaveFileDialog();
             *
             * saveFileDialog1.Filter = "jpg files (*.jpg)|*.jpg|png files (*.png)|*.png|tif files (*.tif)|*.tif|tiff files (*.tiff)|*.tiff";
             * saveFileDialog1.FilterIndex = 2;
             *
             * if (saveFileDialog1.ShowDialog() == DialogResult.OK)
             * {
             *
             *
             *
             *  //get CT values from current slice
             *  StreamWriter streamWriter = new StreamWriter(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\" + "imageScalars.txt");
             *  for(int i = 0; i < 500; i++)
             *  {
             *      for(int j = 0; j < 500; j++)
             *      {
             *          streamWriter.Write(Convert.ToString(
             *              SiteplanesObj.planeWidgetZ.GetResliceOutput().GetScalarComponentAsDouble(i, j, 0, 0)
             *              ) + " ");
             *      }
             *      streamWriter.Write("\n");
             *  }
             *  streamWriter.Close();
             *  //get CT values from current slice
             *
             *
             *
             *  vtkWindowToImageFilter imf = new vtkWindowToImageFilter();
             *  imf.SetInputBufferTypeToRGBA();
             *  switch (currentSliceDimension)
             *  {
             *      case 1:
             *          {
             *              imf.SetInput(vtkFormsWindowControlX.GetRenderWindow());
             *              break;
             *          }
             *      case 2:
             *          {
             *              imf.SetInput(vtkFormsWindowControlY.GetRenderWindow());
             *              break;
             *          }
             *      case 3:
             *          {
             *              imf.SetInput(vtkFormsWindowControlZ.GetRenderWindow());
             *              break;
             *          }
             *  }
             *
             *
             *  var estns = Path.GetExtension(saveFileDialog1.FileName);
             *  if (estns == ".jpg")
             *  {
             *      vtkJPEGWriter pngw = new vtkJPEGWriter();
             *      pngw.SetFileName(saveFileDialog1.FileName);
             *      pngw.SetInputConnection(imf.GetOutputPort());
             *      pngw.Write();
             *  }
             *  else if (estns == ".png")
             *  {
             *      vtkPNGWriter pngw = new vtkPNGWriter();
             *      pngw.SetFileName(saveFileDialog1.FileName);
             *      pngw.SetInputConnection(imf.GetOutputPort());
             *      pngw.Write();
             *  }
             *  else if (estns == ".tif" || estns == ".tiff")
             *  {
             *      vtkTIFFWriter pngw = new vtkTIFFWriter();
             *      pngw.SetFileName(saveFileDialog1.FileName);
             *      pngw.SetInputConnection(imf.GetOutputPort());
             *      pngw.Write();
             *  }
             *
             * }*/
        }