Пример #1
0
        public Form1()
        {
            this.InitializeComponent();
            int    selectedInstrId = 0;
            string resourceName    = default(string);

            Console.WriteLine("==============================================================");
            Console.WriteLine(" Thorlabs instrument driver sample for WFS series instruments");
            Console.WriteLine("==============================================================");

            StringBuilder wfsDriverRev      = new StringBuilder(WFS.BufferSize);
            StringBuilder camDriverRevision = new StringBuilder(WFS.BufferSize);

            instrument.revision_query(wfsDriverRev, camDriverRevision);
            Console.WriteLine();
            Console.Write("WFS instrument driver version : ");
            Console.WriteLine(wfsDriverRev.ToString(), camDriverRevision.ToString());
            Console.WriteLine();

            // implementation with driver functions
            this.SelectInstrument(out selectedInstrId, out resourceName);

            instrument = new WFS(resourceName, false, false);


            this.SelectMla();

            StringBuilder manufacturerName = new StringBuilder(WFS.BufferSize);
            StringBuilder instrumentName   = new StringBuilder(WFS.BufferSize);
            StringBuilder serialNumberWfs  = new StringBuilder(WFS.BufferSize);
            StringBuilder serialNumberCam  = new StringBuilder(WFS.BufferSize);

            if (0 == instrument.GetInstrumentInfo(manufacturerName, instrumentName, serialNumberWfs, serialNumberCam))
            {
                this.textBox_instrumentName.Text  = instrumentName.ToString();
                this.textBox_serialNumberCam.Text = serialNumberCam.ToString();
            }


            // Configure the camera resolution to a pre-defined setting
            Console.WriteLine("\n>> Configure Device, use pre-defined settings <<");
            this.ConfigureDevice(selectedInstrId);
            //---



            this.DefinePupil();
            this.textBox_PupilDiameterX.Text = samplePupilDiameterX.ToString();



            Console.WriteLine("\nWFS instrument is ready.");
        }
Пример #2
0
        public static Map InitializeMap()
        {
            try
            {
                // WARNING
                // This sample needs the GeoServer WFS running on your local machine.
                // It uses the GeoServer default sample data. Installing and starting it is all you need to do
                // http://docs.codehaus.org/display/GEOS/Download

                // Sample by Peter Robineau

                const string getCapabilitiesUri = "http://localhost:8080/geoserver/wfs";
                const string serviceUri         = "http://localhost:8080/geoserver/wfs";

                var map = new Map();
                map.BackColor = Color.White;

                var layer1 = new Layer("States");
                var layer2 = new Layer("SelectedStatesAndHousholds");
                var layer3 = new Layer("New Jersey");
                var layer4 = new Layer("Roads");
                var layer5 = new Layer("Landmarks");
                var layer6 = new Layer("Poi");

                // Demo data from Geoserver 1.5.3 and Geoserver 1.6.0

                var prov1 = new WFS(getCapabilitiesUri, "topp", "states", WFS.WFSVersionEnum.WFS1_0_0);

                // Bypass 'GetCapabilities' and 'DescribeFeatureType', if you know all necessary metadata.
                var featureTypeInfo = new WfsFeatureTypeInfo(serviceUri, "topp", null, "states",
                                                             "the_geom");
                // 'WFS.WFSVersionEnum.WFS1_1_0' supported by Geoserver 1.6.x
                var prov2 = new WFS(featureTypeInfo, WFS.WFSVersionEnum.WFS1_1_0);
                // Bypass 'GetCapabilities' and 'DescribeFeatureType' again...
                // It's possible to specify the geometry type, if 'DescribeFeatureType' does not...(.e.g 'GeometryAssociationType')
                // This helps to accelerate the initialization process in case of unprecise geometry information.
                var prov3 = new WFS(serviceUri, "topp", "http://www.openplans.org/topp", "states", "the_geom",
                                    GeometryTypeEnum.MultiSurfacePropertyType, WFS.WFSVersionEnum.WFS1_1_0);

                // Use cached 'GetCapabilities' response of prov1 (featuretype hosted by same service).
                // Compiled XPath expressions are re-used automatically!
                // If you use a cached 'GetCapabilities' response make sure the data provider uses the same version of WFS as the one providing the cache!!!
                var prov4 = new WFS(prov1.GetCapabilitiesCache, "tiger", "tiger_roads", WFS.WFSVersionEnum.WFS1_0_0);
                var prov5 = new WFS(prov1.GetCapabilitiesCache, "tiger", "poly_landmarks", WFS.WFSVersionEnum.WFS1_0_0);
                var prov6 = new WFS(prov1.GetCapabilitiesCache, "tiger", "poi", WFS.WFSVersionEnum.WFS1_0_0);
                // Clear cache of prov1 - data providers do not have any cache, if they use the one of another data provider
                prov1.GetCapabilitiesCache = null;

                //Filters
                IFilter filter1 = new PropertyIsEqualToFilter_FE1_1_0("STATE_NAME", "California");
                IFilter filter2 = new PropertyIsEqualToFilter_FE1_1_0("STATE_NAME", "Vermont");
                IFilter filter3 = new PropertyIsBetweenFilter_FE1_1_0("HOUSHOLD", "600000", "4000000");
                IFilter filter4 = new PropertyIsLikeFilter_FE1_1_0("STATE_NAME", "New*");

                // SelectedStatesAndHousholds: Green
                var filterCollection1 = new OGCFilterCollection();
                filterCollection1.AddFilter(filter1);
                filterCollection1.AddFilter(filter2);
                var filterCollection2 = new OGCFilterCollection();
                filterCollection2.AddFilter(filter3);
                filterCollection1.AddFilterCollection(filterCollection2);
                filterCollection1.Junctor = OGCFilterCollection.JunctorEnum.Or;
                prov2.OGCFilter           = filterCollection1;

                // Like-Filter('New*'): Bisque
                prov3.OGCFilter = filter4;

                // Layer Style
                layer1.Styles.Add(new VectorStyle {
                    Fill = new Brush {
                        Color = Color.Red
                    }
                });
                layer2.Styles.Add(new VectorStyle {
                    Fill = new Brush {
                        Color = Color.Green
                    }
                });                                                                              // SelectedStatesAndHousholds
                layer3.Styles.Add(new VectorStyle {
                    Fill = new Brush {
                        Color = Color.Yellow
                    }
                });                                                                               // e.g. New York, New Jersey,...
                layer5.Styles.Add(new VectorStyle {
                    Fill = new Brush {
                        Color = Color.Blue
                    }
                });

                // Labels
                // Labels are collected when parsing the geometry. So there's just one 'GetFeature' call necessary.
                // Otherwise (when calling twice for retrieving labels) there may be an inconsistent read...
                // If a label property is set, the quick geometry option is automatically set to 'false'.
                prov3.Label = "STATE_NAME";
                //!!!LabelLayer layLabel = new LabelLayer("labels");
                //layLabel.DataSource = prov3;
                //layLabel.Enabled = true;
                //layLabel.LabelColumn = prov3.Label;
                //layLabel.Style = new LabelStyle();
                //layLabel.Style.CollisionDetection = false;
                //layLabel.Style.CollisionBuffer = new SizeF(5, 5);
                //layLabel.Style.ForeColor = Color.Black;
                //layLabel.Style.Font = new Font(FontFamily.GenericSerif, 10);
                //layLabel.MaxVisible = 90;
                //layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
                // Options
                // Defaults: MultiGeometries: true, QuickGeometries: false, GetFeatureGETRequest: false
                // Render with validation...
                prov1.QuickGeometries = false;
                // Important when connecting to an UMN MapServer
                prov1.GetFeatureGETRequest = true;
                // Ignore multi-geometries...
                prov1.MultiGeometries = false;

                // Quick geometries
                // We need this option for prov2 since we have not passed a featuretype namespace
                prov2.QuickGeometries = true;
                prov4.QuickGeometries = true;
                prov5.QuickGeometries = true;
                prov6.QuickGeometries = true;

                layer1.DataSource = prov1;
                layer2.DataSource = prov2;
                layer3.DataSource = prov3;
                layer4.DataSource = prov4;
                layer5.DataSource = prov5;
                layer6.DataSource = prov6;

                map.Layers.Add(layer1);
                map.Layers.Add(layer2);
                map.Layers.Add(layer3);
                map.Layers.Add(layer4);
                map.Layers.Add(layer5);
                map.Layers.Add(layer6);
                //!!!map.Layers.Add(layLabel);

                //!!!map.Center = new Point(-74.0, 40.7);
                //!!!map.Zoom = 10;
                // Alternatively zoom closer
                // demoMap.Zoom = 0.2;

                return(map);
            }
            catch (WebException ex)
            {
                if ((ex.Message.Contains("(502) Bad Gateway")) ||
                    (ex.Message.Contains("Unable to connect to the remote server")))
                {
                    throw new Exception(
                              "The Wfs sample threw an exception. You probably need to install the GeoServer WFS to your local machine. You can get it from here: http://docs.codehaus.org/display/GEOS/Download. The exception message was: " +
                              ex.Message);
                }
                throw;
            }
        }
Пример #3
0
        //------------------------------------------------ METHOD FUNCTION 1 ------------------------------------------------
        public void CameraConnectionAndSetup(double exposure)
        {
            //int selectedInstrId = 0;//I believe this is a handler index in the situation that there would be mulitple SHA's connected to the computer.
            string resourceName = default(string);//Just creating a string initially set to null.

            //These two lines are also constructors, but creating StringBuilders. They create strings up to a specified size (WFS.BufferSize, in this case).
            StringBuilder camDriverRev = new StringBuilder(WFS.BufferSize);
            StringBuilder wfsDriverRev = new StringBuilder(WFS.BufferSize);

            //This function comes from the WFS class, which means this structure can be used in the future as a reference (of how to write the code).
            instrument.revision_query(wfsDriverRev, camDriverRev);//Checks for the current revision of computer (installed) and camera (installed) drivers.

            //This chuck writes the driver information to the console.
            Console.WriteLine("");
            Console.Write("WFS instrument driver version : ");
            Console.WriteLine(wfsDriverRev.ToString(), camDriverRev.ToString());
            Console.WriteLine();

            //Calls the helper function, which uses functions from the namespace find connected WFS, get information on the connected WFS, allow the user to select one.
            SelectInstrument(out selectedInstrId, out resourceName);

            //Error Handling, checking that the selected WFS isn't a negative index.
            if (0 > selectedInstrId)
            {
                return;
            }

            //Yields resource name of connected sensor.
            Console.Write("\nResource name of selected WFS: ");
            Console.WriteLine(resourceName.ToString());
            Console.WriteLine();

            Console.WriteLine("\n-----------------------------------------------------------\n");
            Console.WriteLine(">> Initialize Device <<");

            //Not totally sure what is going on here. Having trouble gaining insight into this constructor.
            instrument = new WFS(resourceName, false, false);

            //Fairly straightforward. Getting information about the selected WFS. From the ThorLabs namespace.
            Console.WriteLine(">> Get Device Info <<");
            StringBuilder manufacturerName = new StringBuilder(WFS.BufferSize);
            StringBuilder instrumentName   = new StringBuilder(WFS.BufferSize);
            StringBuilder serialNumberWfs  = new StringBuilder(WFS.BufferSize);
            StringBuilder serialNumberCam  = new StringBuilder(WFS.BufferSize);

            //If this line succeeds, the connection was successful, as we access unit-specific information.
            instrument.GetInstrumentInfo(manufacturerName, instrumentName, serialNumberWfs, serialNumberCam);

            //Writing unit-specific information to the console for verification.
            Console.WriteLine(">> Opened Instrument <<");
            Console.Write("Manufacturer           : ");
            Console.WriteLine(manufacturerName);
            Console.Write("Instrument Name        : ");
            Console.WriteLine(instrumentName);
            Console.Write("Serial Number WFS      : ");
            Console.WriteLine(serialNumberWfs);

            //---NOTE--- This will need to be configured such that it can take in the exposure time and set this (as well as the gain) without console input (for automation).
            // select a microlens array, WFS kits can operate 2 or more MLAs
            SelectMla();

            // Configure the camera resolution to a pre-defined setting
            Console.WriteLine("\n>> Configure Device, use pre-defined settings <<");
            ConfigureDevice(selectedInstrId);

            // set camera exposure time and gain if you don't want to use auto exposure
            // use functions GetExposureTimeRange, SetExposureTime, GetMasterGainRange, SetMasterGain

            double actualGain = 0;

            // set WFS internal reference plane
            Console.WriteLine("\nSet WFS to internal reference plane.\n");
            instrument.SetReferencePlane(InternalRefPlane); // Good. Set to use the internal reference plane to the MLA.
            instrument.SetMasterGain(gain, out actualGain);

            Console.WriteLine("Actual Gain Set to SHA: " + Convert.ToString(actualGain));
            //To define the pupil, I want to just use the beam width. To do this, I first need to find the beam dimensions, and then input them to DefinePupil.
            double beamCentroidX, beamCentroidY, beamDiameterX, beamDiameterY;

            instrument.CalcBeamCentroidDia(out beamCentroidX, out beamCentroidY, out beamDiameterX, out beamDiameterY);

            instrument.SetPupil(beamCentroidX, beamCentroidY, beamDiameterX, beamDiameterY);
        }
Пример #4
0
        int selectedInstrId = 0;               // Created to be a property of the ASEN_SHA object, so it can be used in all ASEN_SHA methods.
        #endregion

        //------------------------------------------------ CONSTRUCTOR ------------------------------------------------
        public ASEN_SHA(short inputGain)
        {
            instrument = new WFS(IntPtr.Zero);
            gain       = inputGain;
        }
Пример #5
0
        int selectedInstrId = 0;               // Created to be a property of the ASEN_SHA object, so it can be used in all ASEN_SHA methods.
        #endregion

        //------------------------------------------------ CONSTRUCTOR ------------------------------------------------
        public ASEN_SHA()
        {
            instrument = new WFS(IntPtr.Zero);
        }
        private static WFS.instrument = new WFS(IntPtr.Zero);//This calls the WFS constructor to create a new WFS object, called "instrument".



        static void Main(string[] args)
        {
            //----------------------------------- DRIVER CHECKS ---------------------------------------
            //Note: A lot of the functions used from the driver software won't work in highspeed mode.
            //Note: I believe there needs to be additional code to initially calibrate the MLAs, as (I believe) this code assumes the user has previously calibrated the MLAs.
            //      This could most likely be automated because (I believe) there is a way to save the calibration over time, or else we can just calibrate before each batch of testing.

            ConsoleKeyInfo waitKey;                   //This key allows one to read from the console (when user input in necessary).

            int    selectedInstrId = 0;               //I believe this is a handler index in the situation that there would be mulitple SHA's connected to the computer.
            string resourceName    = default(string); //Just creating a string initially set to null.

            Console.WriteLine("=================================================================");
            Console.WriteLine("Jake's Attempt at Creating a SHA API to Take Images, Set Exposure");
            Console.WriteLine("=================================================================");

            //These two lines are also constructors, but creating StringBuilders. They create strings up to a specified size (WFS.BufferSize, in this case).
            StringBuilder camDriverRev = new StringBuilder(WFS.BufferSize);
            StringBuilder wfsDriverRev = new StringBuilder(WFS.BufferSize);

            //This function comes from the WFS class, which means this structure can be used in the future as a reference (of how to write the code).
            instrument.revision_query(wfsDriverRev, camDriverRev);//Checks for the current revision of computer (installed) and camera (installed) drivers.

            //This chuck writes the driver information to the console.
            Console.WriteLine("");
            Console.Write("WFS instrument driver version : ");
            Console.WriteLine(wfsDriverRev.ToString(), camDriverRev.ToString());
            Console.WriteLine();

            //----------------------------------- CAMERA CONNECTION ---------------------------------------

            //Calls the helper function, which uses functions from the namespace find connected WFS, get information on the connected WFS, allow the user to select one.
            SelectInstrument(out selectedInstrId, out resourceName);

            //Error Handling, checking that the selected WFS isn't a negative index.
            if (0 > selectedInstrId)
            {
                return;
            }

            //Yields resource name of connected sensor.
            Console.Write("\nResource name of selected WFS: ");
            Console.WriteLine(resourceName.ToString());
            Console.WriteLine();

            Console.WriteLine("\n-----------------------------------------------------------\n");
            Console.WriteLine(">> Initialize Device <<");

            //Not totally sure what is going on here. Having trouble gaining insight into this constructor.
            instrument = new WFS(resourceName, false, false);

            //Fairly straightforward. Getting information about the selected WFS. From the ThorLabs namespace.
            Console.WriteLine(">> Get Device Info <<");
            StringBuilder manufacturerName = new StringBuilder(WFS.BufferSize);
            StringBuilder instrumentName   = new StringBuilder(WFS.BufferSize);
            StringBuilder serialNumberWfs  = new StringBuilder(WFS.BufferSize);
            StringBuilder serialNumberCam  = new StringBuilder(WFS.BufferSize);

            //If this line succeeds, the connection was successful, as we access unit-specific information.
            instrument.GetInstrumentInfo(manufacturerName, instrumentName, serialNumberWfs, serialNumberCam);

            //Writing unit-specific information to the console for verification.
            Console.WriteLine(">> Opened Instrument <<");
            Console.Write("Manufacturer           : ");
            Console.WriteLine(manufacturerName);
            Console.Write("Instrument Name        : ");
            Console.WriteLine(instrumentName);
            Console.Write("Serial Number WFS      : ");
            Console.WriteLine(serialNumberWfs);

            //----------------------------------- CAMERA CONFIGURATION ---------------------------------------
            //In the future, I believe this is where a loop would go, varying the exposure of the SHA, using the information from the experimental variables

            //I believe you need to predefine these variables before you use them for the first time as "out" variables, which are essentially pointers.
            int exposureTimeMin;
            int exposureTimeMax;
            int exposureTimeIncr;
            int exposureTimeAct;

            int masterGainMin;
            int masterGainMax;
            int masterGainAct;

            //SelectMla aids with the selection of the MLA from the list of pre-calibrated MLAs (helper function).
            SelectMla();

            Console.WriteLine("\n>> Configure Device, use pre-defined settings <<");
            ConfigureDevice(selectedInstrId);//ConfigureDevice selects the resolution and bit width per pixel (currently only 8 bit supported) of the WFS.


            Console.WriteLine(">> Setting Exposure <<");

            //This function finds the maximum and minimum exposure times possible with the selected resolution. (these inputs supposedly need to be passed by reference, which seems to be what "out" does).
            instrument.GetExposureTimeRange(out exposureTimeMin, out exposureTimeMax, out exposureTimeIncr);
            Console.Write("Minimum Exposure (ms)       : ");
            Console.WriteLine(exposureTimeMin);
            Console.Write("Maximum Exposure (ms)       : ");
            Console.WriteLine(exposureTimeMax);
            Console.Write("Exposure Time Increment (ms): ");
            Console.WriteLine(exposureTimeIncr);

            Console.Write("\nInput the desired Exposure (ms): ");
            int exposureTimeSet = Console.ReadLine();

            //This function sets the exposure time of the camera, and returns the actual exposure time set.
            instrument.SetExposureTime(exposureTimeSet, out exposureTimeAct);
            Console.Write("\nActual Exposure Set: ");
            Console.WriteLine(exposureTimeAct);


            Console.WriteLine(">> Setting Master Gain <<");

            //This function finds the max and min linear master gain values for the WFS.
            instrument.GetMasterGainRange(out masterGainMin, out masterGainMax);
            Console.Write("Minimum Linear Master Gain: ");
            Console.WriteLine(masterGainMin);
            Console.Write("Maximum Linear Master Gain: ");
            Console.WriteLine(masterGainMax);

            //Prompt the user to provide the master gain value.
            Console.Write("\nInput the desired master Gain: ");
            int masterGainSet = Console.ReadLine();

            //Set the master gain.
            instrument.SetMasterGain(masterGainSet, out masterGainAct);
            Console.Write("\nActual Master Gain Set: ");
            Console.WriteLine(masterGainAct);

            //Set WFS internal reference plane
            Console.WriteLine("\nSet WFS to internal reference plane.\n");
            instrument.SetReferencePlane(sampleRefPlane);

            // define pupil size and position, Zernike results are related to pupil (not sure what to do if we aren't in the pupil. Maybe define Radius of curvature?
            DefinePupil();

            //Here, removed AdjustImageBrightness(), since I am setting the exposure and gain manually.

            //----------------------------------- GATHER CAMERA DATA ---------------------------------------

            //Helper function. The camera image can be retrieved for later display.
            GetSpotfieldImage();

            //----------------------------------- PROCESS CAMERA DATA ---------------------------------------

            //Helper function. Calculate and display the centroid positions of the spots.
            CalcSpotCentroids();
            Console.WriteLine("Calculating Spot Centroids...");
            //Console.WriteLine("\nPress <ANY_KEY> to proceed...");
            //waitKey = Console.ReadKey(true);

            //Calculate and display the beam parameters, derived from the centroid intensities
            CalcBeamCentroid();
            Console.WriteLine("Calculating Beam Centroids...");
            //Console.WriteLine("\nPress <ANY_KEY> to proceed...");
            //waitKey = Console.ReadKey(true);

            //Calculate spot deviations to internal reference positions
            CalcSpotDeviations();
            Console.WriteLine("Calculating Spot Deviations...");
            //Console.WriteLine("\nPress <ANY_KEY> to proceed...");
            //waitKey = Console.ReadKey(true);

            // calculate and display the wavefront
            CalcWavefront();
            Console.WriteLine("Calculating Wavefront...");
            //Console.WriteLine("\nPress <ANY_KEY> to proceed...");
            //waitKey = Console.ReadKey(true);

            // calculate and display a pre-defined number of Zernike results
            CalcZernikes();
            Console.WriteLine("Calculating Zernikes...");
            //Console.WriteLine("\nPress <ANY_KEY> to proceed...");
            //waitKey = Console.ReadKey(true);

            // enter highspeed mode and read calculated spot centroids directly from the camera
            // this enables faster measurements
            //I got rid of this. Highspeed mode is only available for WFS10 and WFS20, and we have the WFS150.
            //HighspeedMode(selectedInstrId);
            Console.WriteLine("\nEnd of Sample Program, press <ANY_KEY> to exit.");
            waitKey = Console.ReadKey(false);

            // Close instrument, important to release allocated driver data!
            instrument.Dispose();

            //----------------------------------- END PROGRAM ---------------------------------------
        }