/////////////////////////////////////////////////////////////////////// // Synchronous Full Frame Acquire /////////////////////////////////////////////////////////////////////// private void AcquireFullFrameSync(object sender, RoutedEventArgs e) { // Are we in a state we can do this? if (!ValidateAcquisition()) { return; } // Get the experiment object IExperiment experiment = application_.Experiment; // Full Frame experiment.SetFullSensorRegion(); int images = 3; int frames = 1; experiment.SetValue(ExperimentSettings.AcquisitionFramesToStore, frames); for (int i = 1; i <= images; i++) { // Capture 1 Frame IImageDataSet set = experiment.Capture(frames); // Stop processing if we do not have all frames if (set.Frames != frames) { // Clean up the image data set set.Dispose(); throw new ArgumentException("Frames are not equal"); } // Get the data from the current frame Array imageData = set.GetFrame(0, frames - 1).GetData(); // Cache the frame IImageData imageFrame = set.GetFrame(0, frames - 1); PrintData(imageData, imageFrame, i, images); } }
/////////////////////////////////////////////////////////////////////// // The first index of the filemanager's GetRecentlyAcquireFileNames is // always the last file acquired.. /////////////////////////////////////////////////////////////////////// void ShowImageDataFromLastAcquire() { // Expected resulting file name string resultName = (string)experiment_.GetValue(ExperimentSettings.AcquisitionOutputFilesResult); // Open the last acquired file IList <string> files = fileManager_.GetRecentlyAcquiredFileNames(); // Is our result in the acquired if (files.Contains(resultName)) { // Open file IImageDataSet dataSet = fileManager_.OpenFile(resultName, FileAccess.Read); // Stop processing if we do not have all frames if (dataSet.Frames != frames_) { // Close the file fileManager_.CloseFile(dataSet); throw new ArgumentException("Frames are not equal"); } // Cache image data Array imageData = dataSet.GetFrame(0, frames_ - 1).GetData(); // Cache the frame IImageData imageFrame = dataSet.GetFrame(0, frames_ - 1); // Print some of the cached data PrintData(imageData, imageFrame); // Close the file fileManager_.CloseFile(dataSet); } }
/////////////////////////////////////////////////////////////////////// private void CreateCalibratedFile(double [] calibration, double [] errors) { // No Calibration So Make Something up if (calibration == null) { calibration = new double[720]; for (int i = 0; i < 720; i++) { calibration[i] = i * 3.0; } } // Size of data passed in ushort[] cosine = new ushort[calibration.Length]; // Generate Curves (Amplitude 100) for (int pix = 0; pix < calibration.Length; pix++) { // Convert To Angle double angle = Math.PI * ((double)pix - 360) / 180.0; // Compute Points cosine[pix] = (ushort)((double)100 * (Math.Cos(angle) + (double)1)); } // Mkae a region of interest (Single Strip) RegionOfInterest roi = new RegionOfInterest(0, 0, calibration.Length, 1, 1, 1); // Get the file manager var filemgr = LightFieldApplication.FileManager; if (filemgr != null) { RegionOfInterest[] rois = { roi }; string root = (string)LightFieldApplication.Experiment.GetValue(ExperimentSettings.FileNameGenerationDirectory); IImageDataSet calSampleData = filemgr.CreateFile(root + "\\CalibrationSample.Spe", rois, 1, ImageDataFormat.MonochromeUnsigned16); // Put Data to frame 1 IImageData data1 = calSampleData.GetFrame(0, 0); data1.SetData(cosine); // Update The XML for the new document SetCalibrationAndError(calSampleData, calibration, errors); // Close the file filemgr.CloseFile(calSampleData); } }
void ShowFrame(string fileName) { var filemgr = application_.FileManager; if (filemgr != null) { IImageDataSet dataSet = filemgr.OpenFile(fileName, FileAccess.Read); IImageData d = dataSet.GetFrame(0, 0); // Convert IImageData To Bitmap System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(d.Width, d.Height); ushort[] data = new ushort[bmp.Width * bmp.Height]; // convert them all to the smallest (simple example for now) var pixels = bmp.Width * bmp.Height; switch (d.Format) { case ImageDataFormat.MonochromeFloating32: { float[] ptr = (float[])d.GetData(); for (int k = 0; k < pixels; k++) { data[k] = (ushort)ptr[k]; } } break; case ImageDataFormat.MonochromeUnsigned16: { ushort[] ptr = (ushort[])d.GetData(); for (int k = 0; k < pixels; k++) { data[k] = (ushort)ptr[k]; } } break; case ImageDataFormat.MonochromeUnsigned32: { uint[] ptr = (uint[])d.GetData(); for (int k = 0; k < pixels; k++) { data[k] = (ushort)ptr[k]; } } break; } short rgb_value = 0; int i = 0; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { rgb_value = (short)((ushort)data[i] / (ushort)256); bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(rgb_value, rgb_value, rgb_value)); i++; } } // Convert To WPF Bitmap System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); // Set the source image1.Source = bitmapSource; // Show the image in a new display viewer viewer_.DisplayViewer.Display("Sample Display", dataSet); } }
//////////////////////////////////////////////////////////////////////// // The following routine demonstrates how to create files using the // LightField Addin SDK. // // Create 1 File with 2 Frames and 1 Region (TwoFrameOneRoi.Spe) // Create 1 File with 1 Frames and 2 Regions (OneFrameTwoRoi.Spe) //////////////////////////////////////////////////////////////////////// private void GenerateFiles() { // Get the addin file manager var filemgr = LightFieldApplication.FileManager; if (filemgr != null) { /////////////////////////////////////////////////////////////// // Part 1: Two Frames 1 Region /////////////////////////////////////////////////////////////// int[] w1 = { 100 }; int[] h1 = { 200 }; // Pseudo Frame 1 Region 1, Frame 2 Region 1 ushort[] frame1 = new ushort[100 * 200]; ushort[] frame2 = new ushort[100 * 200]; for (int pix = 0; pix < 100 * 200; pix++) { frame1[pix] = (ushort)pix; frame2[pix] = (ushort)(pix * 2); } // Folder Selector var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Please choose folder for resulting SPE file(s)."; System.Windows.Forms.DialogResult result = dialog.ShowDialog(); // Something bad happened we don't want to write the files. if (result != System.Windows.Forms.DialogResult.OK) { return; } // Local variable containing path string path = dialog.SelectedPath; // Create a file with 2 frames and the proper width and height // The file is initially created as empty and the user must load data to it. RegionOfInterest roi = new RegionOfInterest(0, 0, w1[0], h1[0], 1, 1); RegionOfInterest[] rois = { roi }; IImageDataSet TwoFrameOneRoi = filemgr.CreateFile(path + "\\TwoFrameOneRoi.spe", rois, 2, // Frames ImageDataFormat.MonochromeUnsigned16); // Put Data to frame 1 IImageData data1 = TwoFrameOneRoi.GetFrame(0, 0); data1.SetData(frame1); // Put Data to frame 2 IImageData data2 = TwoFrameOneRoi.GetFrame(0, 1); data2.SetData(frame2); // Finally close this file filemgr.CloseFile(TwoFrameOneRoi); /////////////////////////////////////////////////////////////// // Part 2: 1 Frame 2 Regions /////////////////////////////////////////////////////////////// int[] w2 = { 300, 500 }; int[] h2 = { 400, 600 }; // Pseudo Frame 2 Region 1 ushort[] frame1_roi1 = new ushort[300 * 400]; for (int pix = 0; pix < 300 * 400; pix++) { frame1_roi1[pix] = (ushort)pix; } // Pseudo Frame 2 Region 2 ushort[] frame1_roi2 = new ushort[500 * 600]; for (int pix = 0; pix < 500 * 600; pix++) { frame1_roi2[pix] = (ushort)pix; } // Create a file, get the buffer and fill it in for each region // The file is initially created as empty and the user must load data to it. // The regions can not overlap RegionOfInterest r1 = new RegionOfInterest(0, 0, w2[0], h2[0], 1, 1); RegionOfInterest r2 = new RegionOfInterest(w2[0] + 1, h2[0] + 1, w2[1], h2[1], 1, 1); RegionOfInterest[] rois2 = { r1, r2 }; IImageDataSet OneFrameTwoRoi = filemgr.CreateFile(path + "\\OneFrameTwoRoi.spe", rois2, 1, // Frames ImageDataFormat.MonochromeUnsigned16); // Put Data To Region 1 IImageData data2_roi1 = OneFrameTwoRoi.GetFrame(0, 0); data2_roi1.SetData(frame1_roi1); // Data To Region 2 IImageData data2_roi2 = OneFrameTwoRoi.GetFrame(1, 0); data2_roi2.SetData(frame1_roi2); // Finally close this file filemgr.CloseFile(OneFrameTwoRoi); } }