List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private void setXYItemLabelsData(XYItemRenderer renderer, cfCHARTSERIESData seriesData) throws cfmRunTimeException { // Set them as visible renderer.setItemLabelsVisible(true); // Set their color renderer.setItemLabelPaint(convertStringToColor(seriesData.getDataLabelColor())); // Set their font renderer.setItemLabelFont(getFont(seriesData.getDataLabelFont(), seriesData.getDataLabelFontBold(), seriesData.getDataLabelFontItalic(), seriesData.getDataLabelFontSize())); // Set the item label position for negative data values double degrees = seriesData.getDataLabelAngle(); double radians = Math.toRadians(degrees); String negPosition = seriesData.getNegativeDataLabelPosition(); if (negPosition.equals("top")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians)); else if (negPosition.equals("top_inside")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians)); else if (negPosition.equals("left")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians)); else if (negPosition.equals("left_inside")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE9, TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians)); else if (negPosition.equals("center")) renderer.setNegativeItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, radians)); else if (negPosition.equals("right")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians)); else if (negPosition.equals("right_inside")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians)); else if (negPosition.equals("bottom_inside")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians)); else if (negPosition.equals("bottom")) renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians)); // Set the item label position for positive data values String posPosition = seriesData.getPositiveDataLabelPosition(); if (posPosition.equals("top")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians)); else if (posPosition.equals("top_inside")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians)); else if (posPosition.equals("left")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians)); else if (posPosition.equals("left_inside")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE9, TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians)); else if (posPosition.equals("center")) renderer.setPositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, radians)); else if (posPosition.equals("right")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians)); else if (posPosition.equals("right_inside")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians)); else if (posPosition.equals("bottom_inside")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians)); else if (posPosition.equals("bottom")) renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians)); }
From source file:org.micromanager.asidispim.AcquisitionPanel.java
/** * Actually runs the acquisition; does the dirty work of setting * up the controller, the circular buffer, starting the cameras, * grabbing the images and putting them into the acquisition, etc. * @param testAcq true if running test acquisition only (see runTestAcquisition() javadoc) * @param testAcqSide only applies to test acquisition, passthrough from runTestAcquisition() * @return true if ran without any fatal errors. *///from ww w. j a v a2 s . c o m private boolean runAcquisitionPrivate(boolean testAcq, Devices.Sides testAcqSide) { // sanity check, shouldn't call this unless we aren't running an acquisition if (gui_.isAcquisitionRunning()) { MyDialogUtils.showError("An acquisition is already running"); return false; } if (ASIdiSPIM.getFrame().getHardwareInUse()) { MyDialogUtils.showError("Hardware is being used by something else (maybe autofocus?)"); return false; } boolean liveModeOriginally = gui_.isLiveModeOn(); if (liveModeOriginally) { gui_.enableLiveMode(false); } // make sure slice timings are up to date // do this automatically; we used to prompt user if they were out of date // do this before getting snapshot of sliceTiming_ in acqSettings recalculateSliceTiming(!minSlicePeriodCB_.isSelected()); if (!sliceTiming_.valid) { MyDialogUtils.showError("Error in calculating the slice timing; is the camera mode set correctly?"); return false; } AcquisitionSettings acqSettingsOrig = getCurrentAcquisitionSettings(); if (acqSettingsOrig.cameraMode == CameraModes.Keys.LIGHT_SHEET && core_.getPixelSizeUm() < 1e-6) { // can't compare equality directly with floating point values so call < 1e-9 is zero or negative ReportingUtils.showError("Need to configure pixel size in Micro-Manager to use light sheet mode."); return false; } // if a test acquisition then only run single timpoint, no autofocus // allow multi-positions for test acquisition for now, though perhaps this is not desirable if (testAcq) { acqSettingsOrig.useTimepoints = false; acqSettingsOrig.numTimepoints = 1; acqSettingsOrig.useAutofocus = false; acqSettingsOrig.separateTimepoints = false; // if called from the setup panels then the side will be specified // so we can do an appropriate single-sided acquisition // if called from the acquisition panel then NONE will be specified // and run according to existing settings if (testAcqSide != Devices.Sides.NONE) { acqSettingsOrig.numSides = 1; acqSettingsOrig.firstSideIsA = (testAcqSide == Devices.Sides.A); } // work around limitation of not being able to use PLogic per-volume switching with single side // => do per-volume switching instead (only difference should be extra time to switch) if (acqSettingsOrig.useChannels && acqSettingsOrig.channelMode == MultichannelModes.Keys.VOLUME_HW && acqSettingsOrig.numSides < 2) { acqSettingsOrig.channelMode = MultichannelModes.Keys.VOLUME; } } double volumeDuration = computeActualVolumeDuration(acqSettingsOrig); double timepointDuration = computeTimepointDuration(); long timepointIntervalMs = Math.round(acqSettingsOrig.timepointInterval * 1000); // use hardware timing if < 1 second between timepoints // experimentally need ~0.5 sec to set up acquisition, this gives a bit of cushion // cannot do this in getCurrentAcquisitionSettings because of mutually recursive // call with computeActualVolumeDuration() if (acqSettingsOrig.numTimepoints > 1 && timepointIntervalMs < (timepointDuration + 750) && !acqSettingsOrig.isStageScanning) { acqSettingsOrig.hardwareTimepoints = true; } if (acqSettingsOrig.useMultiPositions) { if (acqSettingsOrig.hardwareTimepoints || ((acqSettingsOrig.numTimepoints > 1) && (timepointIntervalMs < timepointDuration * 1.2))) { // change to not hardwareTimepoints and warn user // but allow acquisition to continue acqSettingsOrig.hardwareTimepoints = false; MyDialogUtils.showError("Timepoint interval may not be sufficient " + "depending on actual time required to change positions. " + "Proceed at your own risk."); } } // now acqSettings should be read-only final AcquisitionSettings acqSettings = acqSettingsOrig; // generate string for log file Gson gson = new GsonBuilder().setPrettyPrinting().create(); final String acqSettingsJSON = gson.toJson(acqSettings); // get MM device names for first/second cameras to acquire String firstCamera, secondCamera; Devices.Keys firstCameraKey, secondCameraKey; boolean firstSideA = acqSettings.firstSideIsA; if (firstSideA) { firstCamera = devices_.getMMDevice(Devices.Keys.CAMERAA); firstCameraKey = Devices.Keys.CAMERAA; secondCamera = devices_.getMMDevice(Devices.Keys.CAMERAB); secondCameraKey = Devices.Keys.CAMERAB; } else { firstCamera = devices_.getMMDevice(Devices.Keys.CAMERAB); firstCameraKey = Devices.Keys.CAMERAB; secondCamera = devices_.getMMDevice(Devices.Keys.CAMERAA); secondCameraKey = Devices.Keys.CAMERAA; } boolean sideActiveA, sideActiveB; final boolean twoSided = acqSettings.numSides > 1; if (twoSided) { sideActiveA = true; sideActiveB = true; } else { secondCamera = null; if (firstSideA) { sideActiveA = true; sideActiveB = false; } else { sideActiveA = false; sideActiveB = true; } } final boolean acqBothCameras = acqSettings.acquireBothCamerasSimultaneously; boolean camActiveA = sideActiveA || acqBothCameras; boolean camActiveB = sideActiveB || acqBothCameras; if (camActiveA) { if (!devices_.isValidMMDevice(Devices.Keys.CAMERAA)) { MyDialogUtils.showError("Using side A but no camera specified for that side."); return false; } Devices.Keys camKey = Devices.Keys.CAMERAA; Devices.Libraries camLib = devices_.getMMDeviceLibrary(camKey); if (!CameraModes.getValidModeKeys(camLib).contains(getSPIMCameraMode())) { MyDialogUtils.showError("Camera trigger mode set to " + getSPIMCameraMode().toString() + " but camera A doesn't support it."); return false; } // Hamamatsu only supports light sheet mode with USB cameras. Tt seems due to static architecture of getValidModeKeys // there is no good way to tell earlier that light sheet mode isn't supported. I don't like this but don't see another option. if (camLib == Devices.Libraries.HAMCAM && props_.getPropValueString(camKey, Properties.Keys.CAMERA_BUS) .equals(Properties.Values.USB3)) { if (getSPIMCameraMode() == CameraModes.Keys.LIGHT_SHEET) { MyDialogUtils.showError("Hamamatsu only supports light sheet mode with CameraLink readout."); return false; } } } if (sideActiveA) { if (!devices_.isValidMMDevice(Devices.Keys.GALVOA)) { MyDialogUtils.showError("Using side A but no scanner specified for that side."); return false; } if (requiresPiezos(acqSettings.spimMode) && !devices_.isValidMMDevice(Devices.Keys.PIEZOA)) { MyDialogUtils.showError( "Using side A and acquisition mode requires piezos but no piezo specified for that side."); return false; } } if (camActiveB) { if (!devices_.isValidMMDevice(Devices.Keys.CAMERAB)) { MyDialogUtils.showError("Using side B but no camera specified for that side."); return false; } if (!CameraModes.getValidModeKeys(devices_.getMMDeviceLibrary(Devices.Keys.CAMERAB)) .contains(getSPIMCameraMode())) { MyDialogUtils.showError("Camera trigger mode set to " + getSPIMCameraMode().toString() + " but camera B doesn't support it."); return false; } } if (sideActiveB) { if (!devices_.isValidMMDevice(Devices.Keys.GALVOB)) { MyDialogUtils.showError("Using side B but no scanner specified for that side."); return false; } if (requiresPiezos(acqSettings.spimMode) && !devices_.isValidMMDevice(Devices.Keys.PIEZOB)) { MyDialogUtils.showError( "Using side B and acquisition mode requires piezos but no piezo specified for that side."); return false; } } boolean usingDemoCam = (devices_.getMMDeviceLibrary(Devices.Keys.CAMERAA).equals(Devices.Libraries.DEMOCAM) && camActiveA) || (devices_.getMMDeviceLibrary(Devices.Keys.CAMERAB).equals(Devices.Libraries.DEMOCAM) && camActiveB); // set up channels int nrChannelsSoftware = acqSettings.numChannels; // how many times we trigger the controller per stack int nrSlicesSoftware = acqSettings.numSlices; String originalChannelConfig = ""; boolean changeChannelPerVolumeSoftware = false; if (acqSettings.useChannels) { if (acqSettings.numChannels < 1) { MyDialogUtils.showError("\"Channels\" is checked, but no channels are selected"); return false; } // get current channel so that we can restore it, then set channel appropriately originalChannelConfig = multiChannelPanel_.getCurrentConfig(); switch (acqSettings.channelMode) { case VOLUME: changeChannelPerVolumeSoftware = true; multiChannelPanel_.initializeChannelCycle(); break; case VOLUME_HW: case SLICE_HW: if (acqSettings.numChannels == 1) { // only 1 channel selected so don't have to really use hardware switching multiChannelPanel_.initializeChannelCycle(); multiChannelPanel_.selectNextChannel(); } else { // we have at least 2 channels boolean success = controller_.setupHardwareChannelSwitching(acqSettings); if (!success) { MyDialogUtils.showError("Couldn't set up slice hardware channel switching."); return false; } nrChannelsSoftware = 1; nrSlicesSoftware = acqSettings.numSlices * acqSettings.numChannels; } break; default: MyDialogUtils .showError("Unsupported multichannel mode \"" + acqSettings.channelMode.toString() + "\""); return false; } } if (twoSided && acqBothCameras) { nrSlicesSoftware *= 2; } if (acqSettings.hardwareTimepoints) { // in hardwareTimepoints case we trigger controller once for all timepoints => need to // adjust number of frames we expect back from the camera during MM's SequenceAcquisition if (acqSettings.cameraMode == CameraModes.Keys.OVERLAP) { // For overlap mode we are send one extra trigger per channel per side for volume-switching (both PLogic and not) // This holds for all multi-channel modes, just the order in which the extra trigger comes varies // Very last trigger won't ever return a frame so subtract 1. nrSlicesSoftware = ((acqSettings.numSlices + 1) * acqSettings.numChannels * acqSettings.numTimepoints); if (twoSided && acqBothCameras) { nrSlicesSoftware *= 2; } nrSlicesSoftware -= 1; } else { // we get back one image per trigger for all trigger modes other than OVERLAP // and we have already computed how many images that is (nrSlicesSoftware) nrSlicesSoftware *= acqSettings.numTimepoints; if (twoSided && acqBothCameras) { nrSlicesSoftware *= 2; } } } // set up XY positions int nrPositions = 1; PositionList positionList = new PositionList(); if (acqSettings.useMultiPositions) { try { positionList = gui_.getPositionList(); nrPositions = positionList.getNumberOfPositions(); } catch (MMScriptException ex) { MyDialogUtils.showError(ex, "Error getting position list for multiple XY positions"); } if (nrPositions < 1) { MyDialogUtils.showError("\"Positions\" is checked, but no positions are in position list"); return false; } } // make sure we have cameras selected if (!checkCamerasAssigned(true)) { return false; } final float cameraReadoutTime = computeCameraReadoutTime(); final double exposureTime = acqSettings.sliceTiming.cameraExposure; final boolean save = saveCB_.isSelected() && !testAcq; final String rootDir = rootField_.getText(); // make sure we have a valid directory to save in final File dir = new File(rootDir); if (save) { try { if (!dir.exists()) { if (!dir.mkdir()) { throw new Exception(); } } } catch (Exception ex) { MyDialogUtils.showError("Could not create directory for saving acquisition data."); return false; } } if (acqSettings.separateTimepoints) { // because separate timepoints closes windows when done, force the user to save data to disk to avoid confusion if (!save) { MyDialogUtils.showError("For separate timepoints, \"Save while acquiring\" must be enabled."); return false; } // for separate timepoints, make sure the directory is empty to make sure naming pattern is "clean" // this is an arbitrary choice to avoid confusion later on when looking at file names if (dir.list().length > 0) { MyDialogUtils.showError("For separate timepoints the saving directory must be empty."); return false; } } int nrFrames; // how many Micro-manager "frames" = time points to take if (acqSettings.separateTimepoints) { nrFrames = 1; nrRepeats_ = acqSettings.numTimepoints; } else { nrFrames = acqSettings.numTimepoints; nrRepeats_ = 1; } AcquisitionModes.Keys spimMode = acqSettings.spimMode; boolean autoShutter = core_.getAutoShutter(); boolean shutterOpen = false; // will read later String originalCamera = core_.getCameraDevice(); // more sanity checks // TODO move these checks earlier, before we set up channels and XY positions // make sure stage scan is supported if selected if (acqSettings.isStageScanning) { if (!devices_.isTigerDevice(Devices.Keys.XYSTAGE) || !props_.hasProperty(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_NUMLINES)) { MyDialogUtils.showError("Must have stage with scan-enabled firmware for stage scanning."); return false; } if (acqSettings.spimMode == AcquisitionModes.Keys.STAGE_SCAN_INTERLEAVED && acqSettings.numSides < 2) { MyDialogUtils.showError("Interleaved mode requires two sides."); return false; } } double sliceDuration = acqSettings.sliceTiming.sliceDuration; if (exposureTime + cameraReadoutTime > sliceDuration) { // should only only possible to mess this up using advanced timing settings // or if there are errors in our own calculations MyDialogUtils.showError("Exposure time of " + exposureTime + " is longer than time needed for a line scan with" + " readout time of " + cameraReadoutTime + "\n" + "This will result in dropped frames. " + "Please change input"); return false; } // if we want to do hardware timepoints make sure there's not a problem // lots of different situations where hardware timepoints can't be used... if (acqSettings.hardwareTimepoints) { if (acqSettings.useChannels && acqSettings.channelMode == MultichannelModes.Keys.VOLUME_HW) { // both hardware time points and volume channel switching use SPIMNumRepeats property // TODO this seems a severe limitation, maybe this could be changed in the future via firmware change MyDialogUtils.showError("Cannot use hardware time points (small time point interval)" + " with hardware channel switching volume-by-volume."); return false; } if (acqSettings.isStageScanning) { // stage scanning needs to be triggered for each time point MyDialogUtils.showError( "Cannot use hardware time points (small time point interval)" + " with stage scanning."); return false; } if (acqSettings.separateTimepoints) { MyDialogUtils.showError("Cannot use hardware time points (small time point interval)" + " with separate viewers/file for each time point."); return false; } if (acqSettings.useAutofocus) { MyDialogUtils.showError("Cannot use hardware time points (small time point interval)" + " with autofocus during acquisition."); return false; } if (acqSettings.useMovementCorrection) { MyDialogUtils.showError("Cannot use hardware time points (small time point interval)" + " with movement correction during acquisition."); return false; } if (acqSettings.useChannels && acqSettings.channelMode == MultichannelModes.Keys.VOLUME) { MyDialogUtils.showError("Cannot use hardware time points (small time point interval)" + " with software channels (need to use PLogic channel switching)."); return false; } if (spimMode == AcquisitionModes.Keys.NO_SCAN) { MyDialogUtils.showError("Cannot do hardware time points when no scan mode is used." + " Use the number of slices to set the number of images to acquire."); return false; } } if (acqSettings.useChannels && acqSettings.channelMode == MultichannelModes.Keys.VOLUME_HW && acqSettings.numSides < 2) { MyDialogUtils.showError("Cannot do PLogic channel switching of volume when only one" + " side is selected. Pester the developers if you need this."); return false; } // make sure we aren't trying to collect timepoints faster than we can if (!acqSettings.useMultiPositions && acqSettings.numTimepoints > 1) { if (timepointIntervalMs < volumeDuration) { MyDialogUtils .showError("Time point interval shorter than" + " the time to collect a single volume.\n"); return false; } } // Autofocus settings; only used if acqSettings.useAutofocus is true boolean autofocusAtT0 = false; int autofocusEachNFrames = 10; String autofocusChannel = ""; if (acqSettings.useAutofocus) { autofocusAtT0 = prefs_.getBoolean(MyStrings.PanelNames.AUTOFOCUS.toString(), Properties.Keys.PLUGIN_AUTOFOCUS_ACQBEFORESTART, false); autofocusEachNFrames = props_.getPropValueInteger(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_AUTOFOCUS_EACHNIMAGES); autofocusChannel = props_.getPropValueString(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_AUTOFOCUS_CHANNEL); // double-check that selected channel is valid if we are doing multi-channel if (acqSettings.useChannels) { String channelGroup = props_.getPropValueString(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_MULTICHANNEL_GROUP); StrVector channels = gui_.getMMCore().getAvailableConfigs(channelGroup); boolean found = false; for (String channel : channels) { if (channel.equals(autofocusChannel)) { found = true; break; } } if (!found) { MyDialogUtils.showError("Invalid autofocus channel selected on autofocus tab."); return false; } } } // Movement Correction settings; only used if acqSettings.useMovementCorrection is true int correctMovementEachNFrames = 10; String correctMovementChannel = ""; int cmChannelNumber = -1; if (acqSettings.useMovementCorrection) { correctMovementEachNFrames = props_.getPropValueInteger(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_AUTOFOCUS_CORRECTMOVEMENT_EACHNIMAGES); correctMovementChannel = props_.getPropValueString(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_AUTOFOCUS_CORRECTMOVEMENT_CHANNEL); // double-check that selected channel is valid if we are doing multi-channel if (acqSettings.useChannels) { String channelGroup = props_.getPropValueString(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_MULTICHANNEL_GROUP); StrVector channels = gui_.getMMCore().getAvailableConfigs(channelGroup); boolean found = false; for (String channel : channels) { if (channel.equals(correctMovementChannel)) { found = true; break; } } if (!found) { MyDialogUtils.showError("Invalid movement correction channel selected on autofocus tab."); return false; } } } // the circular buffer, which is used by both cameras, can only have one image size setting // => require same image height and width for both cameras if both are used if (twoSided || acqBothCameras) { try { Rectangle roi_1 = core_.getROI(firstCamera); Rectangle roi_2 = core_.getROI(secondCamera); if (roi_1.width != roi_2.width || roi_1.height != roi_2.height) { MyDialogUtils.showError( "Two cameras' ROI height and width must be equal because of Micro-Manager's circular buffer"); return false; } } catch (Exception ex) { MyDialogUtils.showError(ex, "Problem getting camera ROIs"); } } cameras_.setCameraForAcquisition(firstCameraKey, true); if (twoSided || acqBothCameras) { cameras_.setCameraForAcquisition(secondCameraKey, true); } // save exposure time, will restore at end of acquisition try { prefs_.putFloat(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_CAMERA_LIVE_EXPOSURE_FIRST.toString(), (float) core_.getExposure(devices_.getMMDevice(firstCameraKey))); if (twoSided || acqBothCameras) { prefs_.putFloat(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_CAMERA_LIVE_EXPOSURE_SECOND.toString(), (float) core_.getExposure(devices_.getMMDevice(secondCameraKey))); } } catch (Exception ex) { MyDialogUtils.showError(ex, "could not cache exposure"); } try { core_.setExposure(firstCamera, exposureTime); if (twoSided || acqBothCameras) { core_.setExposure(secondCamera, exposureTime); } gui_.refreshGUIFromCache(); } catch (Exception ex) { MyDialogUtils.showError(ex, "could not set exposure"); } // seems to have a problem if the core's camera has been set to some other // camera before we start doing things, so set to a SPIM camera try { core_.setCameraDevice(firstCamera); } catch (Exception ex) { MyDialogUtils.showError(ex, "could not set camera"); } // empty out circular buffer try { core_.clearCircularBuffer(); } catch (Exception ex) { MyDialogUtils.showError(ex, "Error emptying out the circular buffer"); return false; } // stop the serial traffic for position updates during acquisition // if we return from this function (including aborting) we need to unpause posUpdater_.pauseUpdates(true); // initialize stage scanning so we can restore state Point2D.Double xyPosUm = new Point2D.Double(); float origXSpeed = 1f; // don't want 0 in case something goes wrong float origXAccel = 1f; // don't want 0 in case something goes wrong if (acqSettings.isStageScanning) { try { xyPosUm = core_.getXYStagePosition(devices_.getMMDevice(Devices.Keys.XYSTAGE)); origXSpeed = props_.getPropValueFloat(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_SPEED); origXAccel = props_.getPropValueFloat(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_ACCEL); } catch (Exception ex) { MyDialogUtils.showError( "Could not get XY stage position, speed, or acceleration for stage scan initialization"); posUpdater_.pauseUpdates(false); return false; } // if X speed is less than 0.2 mm/s then it probably wasn't restored to correct speed some other time // we offer to set it to a more normal speed in that case, until the user declines and we stop asking if (origXSpeed < 0.2 && resetXaxisSpeed_) { resetXaxisSpeed_ = MyDialogUtils.getConfirmDialogResult( "Max speed of X axis is small, perhaps it was not correctly restored after stage scanning previously. Do you want to set it to 1 mm/s now?", JOptionPane.YES_NO_OPTION); // once the user selects "no" then resetXaxisSpeed_ will be false and stay false until plugin is launched again if (resetXaxisSpeed_) { props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_SPEED, 1f); origXSpeed = 1f; } } } numTimePointsDone_ = 0; // force saving as image stacks, not individual files // implementation assumes just two options, either // TaggedImageStorageDiskDefault.class or TaggedImageStorageMultipageTiff.class boolean separateImageFilesOriginally = ImageUtils.getImageStorageClass() .equals(TaggedImageStorageDiskDefault.class); ImageUtils.setImageStorageClass(TaggedImageStorageMultipageTiff.class); // Set up controller SPIM parameters (including from Setup panel settings) // want to do this, even with demo cameras, so we can test everything else if (!controller_.prepareControllerForAquisition(acqSettings)) { posUpdater_.pauseUpdates(false); return false; } boolean nonfatalError = false; long acqButtonStart = System.currentTimeMillis(); String acqName = ""; acq_ = null; // do not want to return from within this loop => throw exception instead // loop is executed once per acquisition (i.e. once if separate viewers isn't selected // or once per timepoint if separate viewers is selected) long repeatStart = System.currentTimeMillis(); for (int acqNum = 0; !cancelAcquisition_.get() && acqNum < nrRepeats_; acqNum++) { // handle intervals between (software-timed) repeats // only applies when doing separate viewers for each timepoint // and have multiple timepoints long repeatNow = System.currentTimeMillis(); long repeatdelay = repeatStart + acqNum * timepointIntervalMs - repeatNow; while (repeatdelay > 0 && !cancelAcquisition_.get()) { updateAcquisitionStatus(AcquisitionStatus.WAITING, (int) (repeatdelay / 1000)); long sleepTime = Math.min(1000, repeatdelay); try { Thread.sleep(sleepTime); } catch (InterruptedException e) { ReportingUtils.showError(e); } repeatNow = System.currentTimeMillis(); repeatdelay = repeatStart + acqNum * timepointIntervalMs - repeatNow; } BlockingQueue<TaggedImage> bq = new LinkedBlockingQueue<TaggedImage>(10); // try to close last acquisition viewer if there could be one open (only in single acquisition per timepoint mode) if (acqSettings.separateTimepoints && (acq_ != null) && !cancelAcquisition_.get()) { try { // following line needed due to some arcane internal reason, otherwise // call to closeAcquisitionWindow() fails silently. // See http://sourceforge.net/p/micro-manager/mailman/message/32999320/ acq_.promptToSave(false); gui_.closeAcquisitionWindow(acqName); } catch (Exception ex) { // do nothing if unsuccessful } } if (acqSettings.separateTimepoints) { // call to getUniqueAcquisitionName is extra safety net, we have checked that directory is empty before starting acqName = gui_.getUniqueAcquisitionName(prefixField_.getText() + "_" + acqNum); } else { acqName = gui_.getUniqueAcquisitionName(prefixField_.getText()); } long extraStageScanTimeout = 0; if (acqSettings.isStageScanning) { // approximately compute the extra time to wait for stack to begin (ramp up time) // by getting the volume duration and subtracting the acquisition duration and then dividing by two extraStageScanTimeout = (long) Math.ceil(computeActualVolumeDuration(acqSettings) - (acqSettings.numSlices * acqSettings.numChannels * acqSettings.sliceTiming.sliceDuration)) / 2; } long extraMultiXYTimeout = 0; if (acqSettings.useMultiPositions) { // give 20 extra seconds to arrive at intended XY position instead of trying to get fancy about computing actual move time extraMultiXYTimeout = XYSTAGETIMEOUT; // furthermore make sure that the main timeout value is at least 20ms because MM's position list uses this (via MultiStagePosition.goToPosition) if (props_.getPropValueInteger(Devices.Keys.CORE, Properties.Keys.CORE_TIMEOUT_MS) < XYSTAGETIMEOUT) { props_.setPropValue(Devices.Keys.CORE, Properties.Keys.CORE_TIMEOUT_MS, XYSTAGETIMEOUT); } } VirtualAcquisitionDisplay vad = null; WindowListener wl_acq = null; WindowListener[] wls_orig = null; try { // check for stop button before each acquisition if (cancelAcquisition_.get()) { throw new IllegalMonitorStateException("User stopped the acquisition"); } // flag that we are actually running acquisition now acquisitionRunning_.set(true); ReportingUtils.logMessage("diSPIM plugin starting acquisition " + acqName + " with following settings: " + acqSettingsJSON); final int numMMChannels = acqSettings.numSides * acqSettings.numChannels * (acqBothCameras ? 2 : 1); if (spimMode == AcquisitionModes.Keys.NO_SCAN && !acqSettings.separateTimepoints) { // swap nrFrames and numSlices gui_.openAcquisition(acqName, rootDir, acqSettings.numSlices, numMMChannels, nrFrames, nrPositions, true, save); } else { gui_.openAcquisition(acqName, rootDir, nrFrames, numMMChannels, acqSettings.numSlices, nrPositions, true, save); } channelNames_ = new String[numMMChannels]; // generate channel names and colors // also builds viewString for MultiViewRegistration metadata String viewString = ""; final String SEPARATOR = "_"; for (int reflect = 0; reflect < 2; reflect++) { // only run for loop once unless acqBothCameras is true // if acqBothCameras is true then run second time to add "epi" channels if (reflect > 0 && !acqBothCameras) { continue; } // set up channels (side A/B is treated as channel too) if (acqSettings.useChannels) { ChannelSpec[] channels = multiChannelPanel_.getUsedChannels(); for (int i = 0; i < channels.length; i++) { String chName = "-" + channels[i].config_ + (reflect > 0 ? "-epi" : ""); // same algorithm for channel index vs. specified channel and side as in comments of code below // that figures out the channel where to file each incoming image int channelIndex = i; if (twoSided) { channelIndex *= 2; } channelIndex += reflect * numMMChannels / 2; channelNames_[channelIndex] = firstCamera + chName; viewString += NumberUtils.intToDisplayString(0) + SEPARATOR; if (twoSided) { channelNames_[channelIndex + 1] = secondCamera + chName; viewString += NumberUtils.intToDisplayString(90) + SEPARATOR; } } } else { // single-channel int channelIndex = reflect * numMMChannels / 2; channelNames_[channelIndex] = firstCamera + (reflect > 0 ? "-epi" : ""); viewString += NumberUtils.intToDisplayString(0) + SEPARATOR; if (twoSided) { channelNames_[channelIndex + 1] = secondCamera + (reflect > 0 ? "-epi" : ""); viewString += NumberUtils.intToDisplayString(90) + SEPARATOR; } } } // strip last separator of viewString (for Multiview Reconstruction) viewString = viewString.substring(0, viewString.length() - 1); // assign channel names and colors for (int i = 0; i < numMMChannels; i++) { gui_.setChannelName(acqName, i, channelNames_[i]); gui_.setChannelColor(acqName, i, getChannelColor(i)); } if (acqSettings.useMovementCorrection) { for (int i = 0; i < acqSettings.numChannels; i++) { if (channelNames_[i].equals(firstCamera + "-" + correctMovementChannel)) { cmChannelNumber = i; } } if (cmChannelNumber == -1) { MyDialogUtils.showError( "The channel selected for movement correction on the auitofocus tab was not found in this acquisition"); return false; } } zStepUm_ = acqSettings.isStageScanning ? controller_.getActualStepSizeUm() // computed step size, accounting for quantization of controller : acqSettings.stepSizeUm; // should be same as PanelUtils.getSpinnerFloatValue(stepSize_) // initialize acquisition gui_.initializeAcquisition(acqName, (int) core_.getImageWidth(), (int) core_.getImageHeight(), (int) core_.getBytesPerPixel(), (int) core_.getImageBitDepth()); gui_.promptToSaveAcquisition(acqName, !testAcq); // These metadata have to be added after initialization, // otherwise they will not be shown?! gui_.setAcquisitionProperty(acqName, "NumberOfSides", NumberUtils.doubleToDisplayString(acqSettings.numSides)); gui_.setAcquisitionProperty(acqName, "FirstSide", acqSettings.firstSideIsA ? "A" : "B"); gui_.setAcquisitionProperty(acqName, "SlicePeriod_ms", actualSlicePeriodLabel_.getText()); gui_.setAcquisitionProperty(acqName, "LaserExposure_ms", NumberUtils.doubleToDisplayString(acqSettings.desiredLightExposure)); gui_.setAcquisitionProperty(acqName, "VolumeDuration", actualVolumeDurationLabel_.getText()); gui_.setAcquisitionProperty(acqName, "SPIMmode", spimMode.toString()); // Multi-page TIFF saving code wants this one (cameras are all 16-bits, so not much reason for anything else) gui_.setAcquisitionProperty(acqName, "PixelType", "GRAY16"); gui_.setAcquisitionProperty(acqName, "UseAutofocus", acqSettings.useAutofocus ? Boolean.TRUE.toString() : Boolean.FALSE.toString()); gui_.setAcquisitionProperty(acqName, "UseMotionCorrection", acqSettings.useMovementCorrection ? Boolean.TRUE.toString() : Boolean.FALSE.toString()); gui_.setAcquisitionProperty(acqName, "HardwareTimepoints", acqSettings.hardwareTimepoints ? Boolean.TRUE.toString() : Boolean.FALSE.toString()); gui_.setAcquisitionProperty(acqName, "SeparateTimepoints", acqSettings.separateTimepoints ? Boolean.TRUE.toString() : Boolean.FALSE.toString()); gui_.setAcquisitionProperty(acqName, "CameraMode", acqSettings.cameraMode.toString()); gui_.setAcquisitionProperty(acqName, "z-step_um", NumberUtils.doubleToDisplayString(zStepUm_)); // Properties for use by MultiViewRegistration plugin // Format is: x_y_z, set to 1 if we should rotate around this axis. gui_.setAcquisitionProperty(acqName, "MVRotationAxis", "0_1_0"); gui_.setAcquisitionProperty(acqName, "MVRotations", viewString); // save XY and SPIM head position in metadata // update positions first at expense of two extra serial transactions refreshXYZPositions(); gui_.setAcquisitionProperty(acqName, "Position_X", positions_.getPositionString(Devices.Keys.XYSTAGE, Directions.X)); gui_.setAcquisitionProperty(acqName, "Position_Y", positions_.getPositionString(Devices.Keys.XYSTAGE, Directions.Y)); gui_.setAcquisitionProperty(acqName, "Position_SPIM_Head", positions_.getPositionString(Devices.Keys.UPPERZDRIVE)); gui_.setAcquisitionProperty(acqName, "SPIMAcqSettings", acqSettingsJSON); gui_.setAcquisitionProperty(acqName, "SPIMtype", ASIdiSPIM.oSPIM ? "oSPIM" : "diSPIM"); gui_.setAcquisitionProperty(acqName, "AcquisitionName", acqName); gui_.setAcquisitionProperty(acqName, "Prefix", acqName); // get circular buffer ready // do once here but not per-trigger; need to ensure ROI changes registered core_.initializeCircularBuffer(); // superset of clearCircularBuffer() // TODO: use new acquisition interface that goes through the pipeline //gui_.setAcquisitionAddImageAsynchronous(acqName); acq_ = gui_.getAcquisition(acqName); // Dive into MM internals since script interface does not support pipelines ImageCache imageCache = acq_.getImageCache(); vad = acq_.getAcquisitionWindow(); imageCache.addImageCacheListener(vad); // Start pumping images into the ImageCache DefaultTaggedImageSink sink = new DefaultTaggedImageSink(bq, imageCache); sink.start(); // remove usual window listener(s) and replace it with our own // that will prompt before closing and cancel acquisition if confirmed // this should be considered a hack, it may not work perfectly // I have confirmed that there is only one windowListener and it seems to // also be related to window closing // Note that ImageJ's acquisition window is AWT instead of Swing wls_orig = vad.getImagePlus().getWindow().getWindowListeners(); for (WindowListener l : wls_orig) { vad.getImagePlus().getWindow().removeWindowListener(l); } wl_acq = new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { // if running acquisition only close if user confirms if (acquisitionRunning_.get()) { boolean stop = MyDialogUtils.getConfirmDialogResult( "Do you really want to abort the acquisition?", JOptionPane.YES_NO_OPTION); if (stop) { cancelAcquisition_.set(true); } } } }; vad.getImagePlus().getWindow().addWindowListener(wl_acq); // patterned after implementation in MMStudio.java // will be null if not saving to disk lastAcquisitionPath_ = acq_.getImageCache().getDiskLocation(); lastAcquisitionName_ = acqName; // only used when motion correction was requested MovementDetector[] movementDetectors = new MovementDetector[nrPositions]; // Transformation matrices to convert between camera and stage coordinates final Vector3D yAxis = new Vector3D(0.0, 1.0, 0.0); final Rotation camARotation = new Rotation(yAxis, Math.toRadians(-45)); final Rotation camBRotation = new Rotation(yAxis, Math.toRadians(45)); final Vector3D zeroPoint = new Vector3D(0.0, 0.0, 0.0); // cache a zero point for efficiency // make sure all devices have arrived, e.g. a stage isn't still moving try { core_.waitForSystem(); } catch (Exception e) { ReportingUtils.logError("error waiting for system"); } // Loop over all the times we trigger the controller's acquisition // (although if multi-channel with volume switching is selected there // is inner loop to trigger once per channel) // remember acquisition start time for software-timed timepoints // For hardware-timed timepoints we only trigger the controller once long acqStart = System.currentTimeMillis(); for (int trigNum = 0; trigNum < nrFrames; trigNum++) { // handle intervals between (software-timed) time points // when we are within the same acquisition // (if separate viewer is selected then nothing bad happens here // but waiting during interval handled elsewhere) long acqNow = System.currentTimeMillis(); long delay = acqStart + trigNum * timepointIntervalMs - acqNow; while (delay > 0 && !cancelAcquisition_.get()) { updateAcquisitionStatus(AcquisitionStatus.WAITING, (int) (delay / 1000)); long sleepTime = Math.min(1000, delay); Thread.sleep(sleepTime); acqNow = System.currentTimeMillis(); delay = acqStart + trigNum * timepointIntervalMs - acqNow; } // check for stop button before each time point if (cancelAcquisition_.get()) { throw new IllegalMonitorStateException("User stopped the acquisition"); } int timePoint = acqSettings.separateTimepoints ? acqNum : trigNum; // this is where we autofocus if requested if (acqSettings.useAutofocus) { // Note that we will not autofocus as expected when using hardware // timing. Seems OK, since hardware timing will result in short // acquisition times that do not need autofocus. We have already // ensured that we aren't doing both if ((autofocusAtT0 && timePoint == 0) || ((timePoint > 0) && (timePoint % autofocusEachNFrames == 0))) { if (acqSettings.useChannels) { multiChannelPanel_.selectChannel(autofocusChannel); } if (sideActiveA) { AutofocusUtils.FocusResult score = autofocus_.runFocus(this, Devices.Sides.A, false, sliceTiming_, false); updateCalibrationOffset(Devices.Sides.A, score); } if (sideActiveB) { AutofocusUtils.FocusResult score = autofocus_.runFocus(this, Devices.Sides.B, false, sliceTiming_, false); updateCalibrationOffset(Devices.Sides.B, score); } // Restore settings of the controller controller_.prepareControllerForAquisition(acqSettings); if (acqSettings.useChannels && acqSettings.channelMode != MultichannelModes.Keys.VOLUME) { controller_.setupHardwareChannelSwitching(acqSettings); } // make sure circular buffer is cleared core_.clearCircularBuffer(); } } numTimePointsDone_++; updateAcquisitionStatus(AcquisitionStatus.ACQUIRING); // loop over all positions for (int positionNum = 0; positionNum < nrPositions; positionNum++) { if (acqSettings.useMultiPositions) { // make sure user didn't stop things if (cancelAcquisition_.get()) { throw new IllegalMonitorStateException("User stopped the acquisition"); } // want to move between positions move stage fast, so we // will clobber stage scanning setting so need to restore it float scanXSpeed = 1f; float scanXAccel = 1f; if (acqSettings.isStageScanning) { scanXSpeed = props_.getPropValueFloat(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_SPEED); props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_SPEED, origXSpeed); scanXAccel = props_.getPropValueFloat(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_ACCEL); props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_ACCEL, origXAccel); } final MultiStagePosition nextPosition = positionList.getPosition(positionNum); // blocking call; will wait for stages to move MultiStagePosition.goToPosition(nextPosition, core_); // for stage scanning: restore speed and set up scan at new position // non-multi-position situation is handled in prepareControllerForAquisition instead if (acqSettings.isStageScanning) { props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_SPEED, scanXSpeed); props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_ACCEL, scanXAccel); StagePosition pos = nextPosition.get(devices_.getMMDevice(Devices.Keys.XYSTAGE)); // get ideal position from position list, not current position controller_.prepareStageScanForAcquisition(pos.x, pos.y); } refreshXYZPositions(); // wait any extra time the user requests Thread.sleep(Math.round(PanelUtils.getSpinnerFloatValue(positionDelay_))); } // loop over all the times we trigger the controller // usually just once, but will be the number of channels if we have // multiple channels and aren't using PLogic to change between them for (int channelNum = 0; channelNum < nrChannelsSoftware; channelNum++) { try { // flag that we are using the cameras/controller ASIdiSPIM.getFrame().setHardwareInUse(true); // deal with shutter before starting acquisition shutterOpen = core_.getShutterOpen(); if (autoShutter) { core_.setAutoShutter(false); if (!shutterOpen) { core_.setShutterOpen(true); } } // start the cameras core_.startSequenceAcquisition(firstCamera, nrSlicesSoftware, 0, true); if (twoSided || acqBothCameras) { core_.startSequenceAcquisition(secondCamera, nrSlicesSoftware, 0, true); } // deal with channel if needed (hardware channel switching doesn't happen here) if (changeChannelPerVolumeSoftware) { multiChannelPanel_.selectNextChannel(); } // special case: single-sided piezo acquisition risks illumination piezo sleeping // prevent this from happening by sending relative move of 0 like we do in live mode before each trigger // NB: this won't help for hardware-timed timepoints final Devices.Keys piezoIllumKey = firstSideA ? Devices.Keys.PIEZOB : Devices.Keys.PIEZOA; if (!twoSided && props_.getPropValueInteger(piezoIllumKey, Properties.Keys.AUTO_SLEEP_DELAY) > 0) { core_.setRelativePosition(devices_.getMMDevice(piezoIllumKey), 0); } // trigger the state machine on the controller // do this even with demo cameras to test everything else boolean success = controller_.triggerControllerStartAcquisition(spimMode, firstSideA); if (!success) { throw new Exception("Controller triggering not successful"); } ReportingUtils.logDebugMessage("Starting time point " + (timePoint + 1) + " of " + nrFrames + " with (software) channel number " + channelNum); // Wait for first image to create ImageWindow, so that we can be sure about image size // Do not actually grab first image here, just make sure it is there long start = System.currentTimeMillis(); long now = start; final long timeout = Math.max(3000, Math.round(10 * sliceDuration + 2 * acqSettings.delayBeforeSide)) + extraStageScanTimeout + extraMultiXYTimeout; while (core_.getRemainingImageCount() == 0 && (now - start < timeout) && !cancelAcquisition_.get()) { now = System.currentTimeMillis(); Thread.sleep(5); } if (now - start >= timeout) { String msg = "Camera did not send first image within a reasonable time.\n"; if (acqSettings.isStageScanning) { msg += "Make sure jumpers are correct on XY card and also micro-micromirror card."; } else { msg += "Make sure camera trigger cables are connected properly."; } throw new Exception(msg); } // grab all the images from the cameras, put them into the acquisition int[] channelImageNr = new int[4 * acqSettings.numChannels]; // keep track of how many frames we have received for each MM "channel" int[] cameraImageNr = new int[2]; // keep track of how many images we have received from the camera int[] tpNumber = new int[2 * acqSettings.numChannels]; // keep track of which timepoint we are on for hardware timepoints int imagesToSkip = 0; // hardware timepoints have to drop spurious images with overlap mode final boolean checkForSkips = acqSettings.hardwareTimepoints && (acqSettings.cameraMode == CameraModes.Keys.OVERLAP); boolean done = false; long timeout2 = Math.max(1000, Math.round(5 * sliceDuration)); if (acqSettings.isStageScanning) { // for stage scanning have to allow extra time for turn-around timeout2 += (2 * (long) Math.ceil(getStageRampDuration(acqSettings))); // ramp up and then down timeout2 += 5000; // ample extra time for turn-around (e.g. antibacklash move in Y), interestingly 500ms extra seems insufficient for reasons I don't understand yet so just pad this for now // TODO figure out why turn-aronud is taking so long if (acqSettings.spimMode == AcquisitionModes.Keys.STAGE_SCAN_UNIDIRECTIONAL) { timeout2 += (long) Math.ceil(getStageRetraceDuration(acqSettings)); // in unidirectional case also need to rewind } } start = System.currentTimeMillis(); long last = start; try { while ((core_.getRemainingImageCount() > 0 || core_.isSequenceRunning(firstCamera) || ((twoSided || acqBothCameras) && core_.isSequenceRunning(secondCamera))) && !done) { now = System.currentTimeMillis(); if (core_.getRemainingImageCount() > 0) { // we have an image to grab TaggedImage timg = core_.popNextTaggedImage(); if (checkForSkips && imagesToSkip != 0) { imagesToSkip--; continue; // goes to next iteration of this loop without doing anything else } // figure out which channel index this frame belongs to // "channel index" is channel of MM acquisition // channel indexes will go from 0 to (numSides * numChannels - 1) for standard (non-reflective) imaging // if double-sided then second camera gets odd channel indexes (1, 3, etc.) // and adjacent pairs will be same color (e.g. 0 and 1 will be from first color, 2 and 3 from second, etc.) // if acquisition from both cameras (reflective imaging) then // second half of channel indices are from opposite (epi) view // e.g. for 3-color 1-sided (A first) standard (non-reflective) then // 0 will be A-illum A-cam 1st color // 2 will be A-illum A-cam 2nd color // 4 will be A-illum A-cam 3rd color // e.g. for 3-color 2-sided (A first) standard (non-reflective) then // 0 will be A-illum A-cam 1st color // 1 will be B-illum B-cam 1st color // 2 will be A-illum A-cam 2nd color // 3 will be B-illum B-cam 2nd color // 4 will be A-illum A-cam 3rd color // 5 will be B-illum B-cam 3rd color // e.g. for 3-color 1-sided (A first) both camera (reflective) then // 0 will be A-illum A-cam 1st color // 1 will be A-illum A-cam 2nd color // 2 will be A-illum A-cam 3rd color // 3 will be A-illum B-cam 1st color // 4 will be A-illum B-cam 2nd color // 5 will be A-illum B-cam 3rd color // e.g. for 3-color 2-sided (A first) both camera (reflective) then // 0 will be A-illum A-cam 1st color // 1 will be B-illum B-cam 1st color // 2 will be A-illum A-cam 2nd color // 3 will be B-illum B-cam 2nd color // 4 will be A-illum A-cam 3rd color // 5 will be B-illum B-cam 3rd color // 6 will be A-illum B-cam 1st color // 7 will be B-illum A-cam 1st color // 8 will be A-illum B-cam 2nd color // 9 will be B-illum A-cam 2nd color // 10 will be A-illum B-cam 3rd color // 11 will be B-illum A-cam 3rd color String camera = (String) timg.tags.get("Camera"); int cameraIndex = camera.equals(firstCamera) ? 0 : 1; int channelIndex_tmp; switch (acqSettings.channelMode) { case NONE: case VOLUME: channelIndex_tmp = channelNum; break; case VOLUME_HW: channelIndex_tmp = cameraImageNr[cameraIndex] / acqSettings.numSlices; // want quotient only break; case SLICE_HW: channelIndex_tmp = cameraImageNr[cameraIndex] % acqSettings.numChannels; // want modulo arithmetic break; default: // should never get here throw new Exception("Undefined channel mode"); } if (acqBothCameras) { if (twoSided) { // 2-sided, both cameras channelIndex_tmp = channelIndex_tmp * 2 + cameraIndex; // determine whether first or second side by whether we've seen half the images yet if (cameraImageNr[cameraIndex] > nrSlicesSoftware / 2) { // second illumination side => second half of channels channelIndex_tmp += 2 * acqSettings.numChannels; } } else { // 1-sided, both cameras channelIndex_tmp += cameraIndex * acqSettings.numChannels; } } else { // normal situation, non-reflective imaging if (twoSided) { channelIndex_tmp *= 2; } channelIndex_tmp += cameraIndex; } final int channelIndex = channelIndex_tmp; int actualTimePoint = timePoint; if (acqSettings.hardwareTimepoints) { actualTimePoint = tpNumber[channelIndex]; } if (acqSettings.separateTimepoints) { // if we are doing separate timepoints then frame is always 0 actualTimePoint = 0; } // note that hardwareTimepoints and separateTimepoints can never both be true // add image to acquisition if (spimMode == AcquisitionModes.Keys.NO_SCAN && !acqSettings.separateTimepoints) { // create time series for no scan addImageToAcquisition(acq_, channelImageNr[channelIndex], channelIndex, actualTimePoint, positionNum, now - acqStart, timg, bq); } else { // standard, create Z-stacks addImageToAcquisition(acq_, actualTimePoint, channelIndex, channelImageNr[channelIndex], positionNum, now - acqStart, timg, bq); } // update our counters to be ready for next image channelImageNr[channelIndex]++; cameraImageNr[cameraIndex]++; // if hardware timepoints then we only send one trigger and // manually keep track of which channel/timepoint comes next if (acqSettings.hardwareTimepoints && channelImageNr[channelIndex] >= acqSettings.numSlices) { // only do this if we are done with the slices in this MM channel // we just finished filling one MM channel with all its slices so go to next timepoint for this channel channelImageNr[channelIndex] = 0; tpNumber[channelIndex]++; // see if we are supposed to skip next image if (checkForSkips) { // one extra image per MM channel, this includes case of only 1 color (either multi-channel disabled or else only 1 channel selected) // if we are interleaving by slice then next nrChannel images will be from extra slice position // any other configuration we will just drop the next image if (acqSettings.useChannels && acqSettings.channelMode == MultichannelModes.Keys.SLICE_HW) { imagesToSkip = acqSettings.numChannels; } else { imagesToSkip = 1; } } // update acquisition status message for hardware acquisition // (for non-hardware acquisition message is updated elsewhere) // Arbitrarily choose one possible channel to do this on. if (channelIndex == 0 && (numTimePointsDone_ < acqSettings.numTimepoints)) { numTimePointsDone_++; updateAcquisitionStatus(AcquisitionStatus.ACQUIRING); } } last = now; // keep track of last image timestamp } else { // no image ready yet done = cancelAcquisition_.get(); Thread.sleep(1); if (now - last >= timeout2) { ReportingUtils .logError("Camera did not send all expected images within" + " a reasonable period for timepoint " + numTimePointsDone_ + ". Continuing anyway."); nonfatalError = true; done = true; } } } // update count if we stopped in the middle if (cancelAcquisition_.get()) { numTimePointsDone_--; } // if we are using demo camera then add some extra time to let controller finish // since we got images without waiting for controller to actually send triggers if (usingDemoCam) { Thread.sleep(200); // for serial communication overhead Thread.sleep((long) volumeDuration / nrChannelsSoftware); // estimate the time per channel, not ideal in case of software channel switching if (acqSettings.isStageScanning) { Thread.sleep(1000 + extraStageScanTimeout); // extra 1 second plus ramp time for stage scanning } } } catch (InterruptedException iex) { MyDialogUtils.showError(iex); } if (acqSettings.hardwareTimepoints) { break; // only trigger controller once } } catch (Exception ex) { MyDialogUtils.showError(ex); } finally { // cleanup at the end of each time we trigger the controller ASIdiSPIM.getFrame().setHardwareInUse(false); // put shutter back to original state core_.setShutterOpen(shutterOpen); core_.setAutoShutter(autoShutter); // make sure cameras aren't running anymore if (core_.isSequenceRunning(firstCamera)) { core_.stopSequenceAcquisition(firstCamera); } if ((twoSided || acqBothCameras) && core_.isSequenceRunning(secondCamera)) { core_.stopSequenceAcquisition(secondCamera); } // make sure SPIM state machine on micromirror and SCAN of XY card are stopped (should normally be but sanity check) if ((acqSettings.numSides > 1) || acqSettings.firstSideIsA) { props_.setPropValue(Devices.Keys.GALVOA, Properties.Keys.SPIM_STATE, Properties.Values.SPIM_IDLE, true); } if ((acqSettings.numSides > 1) || !acqSettings.firstSideIsA) { props_.setPropValue(Devices.Keys.GALVOB, Properties.Keys.SPIM_STATE, Properties.Values.SPIM_IDLE, true); } if (acqSettings.isStageScanning) { props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_STATE, Properties.Values.SPIM_IDLE); } } } if (acqSettings.useMovementCorrection && (timePoint % correctMovementEachNFrames) == 0) { if (movementDetectors[positionNum] == null) { // Transform from camera space to stage space: Rotation rotation = camBRotation; if (firstSideA) { rotation = camARotation; } movementDetectors[positionNum] = new MovementDetector(prefs_, acq_, cmChannelNumber, positionNum, rotation); } Vector3D movement = movementDetectors[positionNum] .detectMovement(Method.PhaseCorrelation); String msg1 = "TimePoint: " + timePoint + ", Detected movement. X: " + movement.getX() + ", Y: " + movement.getY() + ", Z: " + movement.getZ(); System.out.println(msg1); if (!movement.equals(zeroPoint)) { String msg = "ASIdiSPIM motion corrector moving stages: X: " + movement.getX() + ", Y: " + movement.getY() + ", Z: " + movement.getZ(); gui_.logMessage(msg); System.out.println(msg); // if we are using the position list, update the position in the list if (acqSettings.useMultiPositions) { MultiStagePosition position = positionList.getPosition(positionNum); StagePosition pos = position.get(devices_.getMMDevice(Devices.Keys.XYSTAGE)); pos.x += movement.getX(); pos.y += movement.getY(); StagePosition zPos = position .get(devices_.getMMDevice(Devices.Keys.UPPERZDRIVE)); if (zPos != null) { zPos.x += movement.getZ(); } } else { // only a single position, move the stage now core_.setRelativeXYPosition(devices_.getMMDevice(Devices.Keys.XYSTAGE), movement.getX(), movement.getY()); core_.setRelativePosition(devices_.getMMDevice(Devices.Keys.UPPERZDRIVE), movement.getZ()); } } } } if (acqSettings.hardwareTimepoints) { break; } } } catch (IllegalMonitorStateException ex) { // do nothing, the acquisition was simply halted during its operation // will log error message during finally clause } catch (MMScriptException mex) { MyDialogUtils.showError(mex); } catch (Exception ex) { MyDialogUtils.showError(ex); } finally { // end of this acquisition (could be about to restart if separate viewers) try { // restore original window listeners try { vad.getImagePlus().getWindow().removeWindowListener(wl_acq); for (WindowListener l : wls_orig) { vad.getImagePlus().getWindow().addWindowListener(l); } } catch (Exception ex) { // do nothing, window is probably gone } if (cancelAcquisition_.get()) { ReportingUtils.logMessage("User stopped the acquisition"); } bq.put(TaggedImageQueue.POISON); // TODO: evaluate closeAcquisition call // at the moment, the Micro-Manager api has a bug that causes // a closed acquisition not be really closed, causing problems // when the user closes a window of the previous acquisition // changed r14705 (2014-11-24) // gui_.closeAcquisition(acqName); ReportingUtils.logMessage("diSPIM plugin acquisition " + acqName + " took: " + (System.currentTimeMillis() - acqButtonStart) + "ms"); // while(gui_.isAcquisitionRunning()) { // Thread.sleep(10); // ReportingUtils.logMessage("waiting for acquisition to finish."); // } // flag that we are done with acquisition acquisitionRunning_.set(false); // write acquisition settings if requested if (lastAcquisitionPath_ != null && prefs_.getBoolean(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_WRITE_ACQ_SETTINGS_FILE, false)) { String path = ""; try { path = lastAcquisitionPath_ + File.separator + "AcqSettings.txt"; PrintWriter writer = new PrintWriter(path); writer.println(acqSettingsJSON); writer.flush(); writer.close(); } catch (Exception ex) { MyDialogUtils.showError(ex, "Could not save acquisition settings to file as requested to path " + path); } } } catch (Exception ex) { // exception while stopping sequence acquisition, not sure what to do... MyDialogUtils.showError(ex, "Problem while finishing acquisition"); } } } // for loop over acquisitions // cleanup after end of all acquisitions // TODO be more careful and always do these if we actually started acquisition, // even if exception happened cameras_.setCameraForAcquisition(firstCameraKey, false); if (twoSided || acqBothCameras) { cameras_.setCameraForAcquisition(secondCameraKey, false); } // restore exposure times of SPIM cameras try { core_.setExposure(firstCamera, prefs_.getFloat(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_CAMERA_LIVE_EXPOSURE_FIRST.toString(), 10f)); if (twoSided || acqBothCameras) { core_.setExposure(secondCamera, prefs_.getFloat(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_CAMERA_LIVE_EXPOSURE_SECOND.toString(), 10f)); } gui_.refreshGUIFromCache(); } catch (Exception ex) { MyDialogUtils.showError("Could not restore exposure after acquisition"); } // reset channel to original if we clobbered it if (acqSettings.useChannels) { multiChannelPanel_.setConfig(originalChannelConfig); } // clean up controller settings after acquisition // want to do this, even with demo cameras, so we can test everything else // TODO figure out if we really want to return piezos to 0 position (maybe center position, // maybe not at all since we move when we switch to setup tab, something else??) controller_.cleanUpControllerAfterAcquisition(acqSettings.numSides, acqSettings.firstSideIsA, true); // if we did stage scanning restore its position and speed if (acqSettings.isStageScanning) { try { // make sure stage scanning state machine is stopped, otherwise setting speed/position won't take props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_STATE, Properties.Values.SPIM_IDLE); props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_SPEED, origXSpeed); props_.setPropValue(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MOTOR_ACCEL, origXAccel); core_.setXYPosition(devices_.getMMDevice(Devices.Keys.XYSTAGE), xyPosUm.x, xyPosUm.y); } catch (Exception ex) { MyDialogUtils.showError("Could not restore XY stage position after acquisition"); } } updateAcquisitionStatus(AcquisitionStatus.DONE); posUpdater_.pauseUpdates(false); if (testAcq && prefs_.getBoolean(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_TESTACQ_SAVE, false)) { String path = ""; try { path = prefs_.getString(MyStrings.PanelNames.SETTINGS.toString(), Properties.Keys.PLUGIN_TESTACQ_PATH, ""); IJ.saveAs(acq_.getAcquisitionWindow().getImagePlus(), "raw", path); // TODO consider generating a short metadata file to assist in interpretation } catch (Exception ex) { MyDialogUtils.showError("Could not save raw data from test acquisition to path " + path); } } if (separateImageFilesOriginally) { ImageUtils.setImageStorageClass(TaggedImageStorageDiskDefault.class); } // restore camera try { core_.setCameraDevice(originalCamera); } catch (Exception ex) { MyDialogUtils.showError("Could not restore camera after acquisition"); } if (liveModeOriginally) { gui_.enableLiveMode(true); } if (nonfatalError) { MyDialogUtils.showError("Missed some images during acquisition, see core log for details"); } return true; }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
private XYSeries generatePDFSerie() { LeafAngleDistribution distribution = getLeafAngleDistribution(); XYSeries serie = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie.add(angleInDegrees, pdf);//from ww w . ja v a 2s . c o m } return serie; }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Process the image//from w ww. j av a2 s . com * * @param image The image * @param filename File to write the image to * @param node Node to process * @param props Extra properties * @param viewManager The viewmanager this image came from * @param imageProps the image properties * * * @return The processed image * @throws Throwable On badness */ protected BufferedImage processImage(BufferedImage image, String filename, Element node, Hashtable props, ViewManager viewManager, Hashtable imageProps) throws Throwable { if (node == null) { return image; } if (props == null) { props = new Hashtable(); } if (viewManager != null) { Animation animation = viewManager.getAnimation(); props.put(PROP_ANIMATIONTIME, ""); if (animation != null) { if (animation.getAniValue() != null) { props.put(PROP_ANIMATIONTIME, animation.getAniValue()); } } } getProperties().putAll(props); NodeList elements = XmlUtil.getElements(node); Hashtable seenColorTable = new Hashtable(); for (int childIdx = 0; childIdx < elements.getLength(); childIdx++) { boolean shouldIterateChildren = true; BufferedImage newImage = null; int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); Element child = (Element) elements.item(childIdx); String tagName = child.getTagName(); if (tagName.equals(TAG_RESIZE)) { newImage = ImageUtils.toBufferedImage(resize(image, child)); } else if (tagName.equals(TAG_FILESET)) { //ignore } else if (tagName.equals(TAG_OUTPUT)) { processTagOutput(child); } else if (tagName.equals(TAG_DISPLAYLIST)) { if (viewManager != null) { newImage = ImageUtils.toBufferedImage(image, true); Graphics g = newImage.getGraphics(); String valign = applyMacros(child, ATTR_VALIGN, VALUE_BOTTOM); Font font = getFont(child); if (XmlUtil.hasAttribute(child, ATTR_MATTEBG)) { int height = viewManager.paintDisplayList((Graphics2D) g, null, imageWidth, imageHeight, valign.equals(VALUE_BOTTOM), null, font); int top = (valign.equals(VALUE_TOP) ? height : 0); int bottom = (valign.equals(VALUE_BOTTOM) ? height : 0); newImage = ImageUtils.matte(image, top, bottom, 0, 0, applyMacros(child, ATTR_MATTEBG, Color.white)); g = newImage.getGraphics(); imageHeight += height; } Color c = applyMacros(child, ATTR_COLOR, (Color) null); viewManager.paintDisplayList((Graphics2D) g, null, imageWidth, imageHeight, valign.equals(VALUE_BOTTOM), c, font); } } else if (tagName.equals(TAG_COLORBAR) || tagName.equals(TAG_KML_COLORBAR)) { // only do one colorbar if we are writing to kml Integer index = (Integer) props.get(PROP_IMAGEINDEX); if ((index != null) && (index.intValue() > 0) && tagName.equals(TAG_KML_COLORBAR)) { continue; } boolean showLines = applyMacros(child, ATTR_SHOWLINES, false); List<DisplayControlImpl> controls = (List<DisplayControlImpl>) ((viewManager != null) ? viewManager.getControls() : new ArrayList()); if (XmlUtil.hasAttribute(child, ATTR_DISPLAY)) { DisplayControlImpl display = ((controls.size() > 0) ? findDisplayControl(XmlUtil.getAttribute(child, ATTR_DISPLAY), controls) : findDisplayControl(child)); if (display == null) { error("Could not find display:" + XmlUtil.toString(node)); return null; } controls = Misc.newList(display); } int width = applyMacros(child, ATTR_WIDTH, 150); int height = applyMacros(child, ATTR_HEIGHT, 20); int ticks = applyMacros(child, ATTR_TICKMARKS, 0); double interval = applyMacros(child, ATTR_INTERVAL, -1.0); String valuesStr = applyMacros(child, ATTR_VALUES, (String) null); Color c = applyMacros(child, ATTR_COLOR, Color.black); Color lineColor = applyMacros(child, ATTR_LINECOLOR, c); Rectangle imageRect = new Rectangle(0, 0, imageWidth, imageHeight); Point pp = ImageUtils.parsePoint(applyMacros(child, ATTR_PLACE, "ll,10,-10"), imageRect); Point ap = ImageUtils.parsePoint(applyMacros(child, ATTR_ANCHOR, "ll"), new Rectangle(0, 0, width, height)); String orientation = applyMacros(child, ATTR_ORIENTATION, VALUE_BOTTOM); boolean vertical = orientation.equals(VALUE_RIGHT) || orientation.equals(VALUE_LEFT); int baseY = pp.y - ap.y + (vertical ? 0 : height); int baseX = pp.x - ap.x; List colorTables = new ArrayList(); List ranges = new ArrayList(); List units = new ArrayList(); boolean forKml = tagName.equals(TAG_KML_COLORBAR); for (int i = 0; i < controls.size(); i++) { DisplayControlImpl control = (DisplayControlImpl) controls.get(i); ColorTable colorTable = control.getColorTable(); if (colorTable == null) { continue; } Range range = control.getRangeForColorTable(); //only do unique color tables Object[] key = { colorTable, range }; if (seenColorTable.get(key) != null) { continue; } seenColorTable.put(key, key); colorTables.add(colorTable); ranges.add(range); units.add(control.getDisplayUnit()); } for (int i = 0; i < colorTables.size(); i++) { ColorTable colorTable = (ColorTable) colorTables.get(i); Range range = (Range) ranges.get(i); Unit unit = (Unit) units.get(i); Image imageToDrawIn; if (forKml) { if (vertical) { baseX = 0; baseY = 0; } else { baseX = 0; baseY = height; } int space = applyMacros(child, ATTR_SPACE, (vertical ? width : height)); imageToDrawIn = new BufferedImage(width + (vertical ? space : 0), height + (vertical ? 0 : space), BufferedImage.TYPE_INT_RGB); } else { imageToDrawIn = newImage = ImageUtils.toBufferedImage(image); } Graphics g = imageToDrawIn.getGraphics(); if (forKml) { Color bgColor = applyMacros(child, ATTR_BACKGROUND, Color.white); g.setColor(bgColor); g.fillRect(0, 0, imageToDrawIn.getWidth(null), imageToDrawIn.getHeight(null)); } boolean includeAlpha = applyMacros(child, ATTR_TRANSPARENCY, true); float[][] ctValues; if (includeAlpha) { ctValues = colorTable.getAlphaTable(); } else { ctValues = colorTable.getNonAlphaTable(); } ColorMap colorMap = new BaseRGBMap(ctValues); ColorPreview preview = new ColorPreview(colorMap, (vertical ? width : height)); if (vertical) { preview.setSize(new Dimension(height, width)); } else { preview.setSize(new Dimension(width, height)); } Image previewImage = ColorTableCanvas.getImage(colorTable, (vertical ? height : width), (vertical ? width : height), includeAlpha); if (vertical) { int imageType = includeAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; BufferedImage tmpImage = new BufferedImage(width, height, imageType); Graphics2D tmpG = (Graphics2D) tmpImage.getGraphics(); tmpG.rotate(Math.toRadians(90.0)); tmpG.drawImage(previewImage, 0, 0 - width, null); previewImage = tmpImage; } if (forKml) { g.drawImage(previewImage, 0, 0, null); } else { g.drawImage(previewImage, baseX, (vertical ? baseY : baseY - height), null); } if (showLines) { g.setColor(lineColor); g.drawRect(baseX, (vertical ? baseY : baseY - height), width - 1, height - (vertical ? 1 : 0)); } setFont(g, child); FontMetrics fm = g.getFontMetrics(); List values = new ArrayList(); String suffixFrequency = XmlUtil.getAttribute(child, ATTR_SUFFIXFREQUENCY, XmlUtil.getAttribute(child, ATTR_SHOWUNIT, "false")).toLowerCase(); String unitDefault = (!suffixFrequency.equals("false")) ? " %unit%" : ""; String labelSuffix = applyMacros(child, ATTR_SUFFIX, unitDefault); if (unit != null) { labelSuffix = labelSuffix.replace("%unit%", "" + unit); } else { labelSuffix = labelSuffix.replace("%unit%", ""); } if (valuesStr != null) { double[] valueArray = Misc.parseDoubles(valuesStr, ","); for (int valueIdx = 0; valueIdx < valueArray.length; valueIdx++) { values.add(new Double(valueArray[valueIdx])); } } else if (ticks > 0) { int spacing = ((ticks == 1) ? 0 : (vertical ? height : width) / (ticks - 1)); for (int tickIdx = 0; tickIdx < ticks; tickIdx++) { double percent = ((ticks > 1) ? (double) tickIdx / (double) (ticks - 1) : 0.0); values.add(new Double(range.getValueOfPercent(percent))); } } else if (interval > 0) { double value = range.getMin(); double max = range.getMax(); while (value <= max) { values.add(new Double(value)); value += interval; } } for (int valueIdx = 0; valueIdx < values.size(); valueIdx++) { double value = ((Double) values.get(valueIdx)).doubleValue(); int x; int y; if (vertical) { if (orientation.equals(VALUE_RIGHT)) { x = baseX + width; } else { x = baseX; } y = baseY + (int) (range.getPercent(value) * height); if (y > baseY + height) { break; } } else { if (orientation.equals(VALUE_BOTTOM)) { y = baseY; } else { y = baseY - height; } if (range != null) { x = baseX + (int) (range.getPercent(value) * width); } else { x = baseX; } if (x > baseX + width) { break; } } String tickLabel = getIdv().getDisplayConventions().format(value); if (suffixFrequency.equals(VALUE_LAST) && (valueIdx == values.size() - 1)) { tickLabel += labelSuffix; } else if (suffixFrequency.equals(VALUE_FIRST) && (valueIdx == 0)) { tickLabel += labelSuffix; } else if (suffixFrequency.equals(VALUE_ALL) || suffixFrequency.equals("true")) { tickLabel += labelSuffix; } Rectangle2D rect = fm.getStringBounds(tickLabel, g); g.setColor(lineColor); if (orientation.equals(VALUE_RIGHT)) { g.drawLine(x + 1, y, x, y); if (showLines) { g.drawLine(x, y, x - width, y); } } else if (orientation.equals(VALUE_LEFT)) { g.drawLine(x - 1, y, x, y); if (showLines) { g.drawLine(x, y, x + width, y); } } else if (orientation.equals(VALUE_BOTTOM)) { g.drawLine(x, y + 1, x, y); if (showLines) { g.drawLine(x, y, x, y - height); } } else { g.drawLine(x, y - 1, x, y); if (showLines) { g.drawLine(x, y, x, y + height); } } g.setColor(c); if (orientation.equals(VALUE_RIGHT)) { int yLoc = y + (int) (rect.getHeight() / 2) - 2; if (forKml) { if (valueIdx == 0) { yLoc = y + (int) (rect.getHeight()) - 2; } else if (valueIdx == values.size() - 1) { yLoc = y - (int) (rect.getHeight()) + 6; } } g.drawString(tickLabel, x + 2, yLoc); } else if (orientation.equals(VALUE_LEFT)) { int xLoc = x - 2 - (int) rect.getWidth(); g.drawString(tickLabel, xLoc, y + (int) (rect.getHeight() / 2) - 2); } else if (orientation.equals(VALUE_BOTTOM)) { int xLoc = x - (int) (rect.getWidth() / 2); if (forKml) { if (valueIdx == 0) { xLoc = x + 2; } else if (valueIdx == values.size() - 1) { xLoc = x - (int) rect.getWidth() + 2; } } g.drawString(tickLabel, xLoc, y + (int) rect.getHeight() + 2); } else { g.drawString(tickLabel, x - (int) (rect.getWidth() / 2), y - 2); } } if (vertical) { baseX += width + 30; } else { baseY += height + 30; } if (forKml) { String tmpImageFile = applyMacros(child, ATTR_FILE, getIdv().getStore().getTmpFile("testcolorbar${viewindex}.png")); String template = "<ScreenOverlay><name>${kml.name}</name><Icon><href>${icon}</href></Icon>\n" + "<overlayXY x=\"${kml.overlayXY.x}\" y=\"${kml.overlayXY.y}\" xunits=\"${kml.overlayXY.xunits}\" yunits=\"${kml.overlayXY.yunits}\"/>\n" + "<screenXY x=\"${kml.screenXY.x}\" y=\"${kml.screenXY.y}\" xunits=\"${kml.screenXY.xunits}\" yunits=\"${kml.screenXY.yunits}\"/>\n" + "<size x=\"${kml.size.x}\" y=\"${kml.size.y}\" xunits=\"${kml.size.xunits}\" yunits=\"${kml.size.yunits}\"/>\n" + "</ScreenOverlay>\n"; String[] macros = { "kml.name", "kml.overlayXY.x", "kml.overlayXY.y", "kml.overlayXY.xunits", "kml.overlayXY.yunits", "kml.screenXY.x", "kml.screenXY.y", "kml.screenXY.xunits", "kml.screenXY.yunits", "kml.size.x", "kml.size.y", "kml.size.xunits", "kml.size.yunits" }; String[] macroValues = { "", "0", "1", "fraction", "fraction", "0", "1", "fraction", "fraction", "-1", "-1", "pixels", "pixels" }; for (int macroIdx = 0; macroIdx < macros.length; macroIdx++) { template = template.replace("${" + macros[macroIdx] + "}", applyMacros(child, macros[macroIdx], macroValues[macroIdx])); } template = template.replace("${icon}", IOUtil.getFileTail(tmpImageFile)); imageProps.put("kml", template); List kmlFiles = (List) imageProps.get("kmlfiles"); //TODO: Only do the first one for now if (kmlFiles == null) { kmlFiles = new ArrayList(); imageProps.put("kmlfiles", kmlFiles); } kmlFiles.add(tmpImageFile); // System.out.println(template); ImageUtils.writeImageToFile(imageToDrawIn, tmpImageFile); } } } else if (tagName.equals(TAG_TRANSPARENT) || tagName.equals(TAG_BGTRANSPARENT)) { Color c = null; if (tagName.equals(TAG_BGTRANSPARENT)) { c = viewManager.getBackground(); } else { c = applyMacros(child, ATTR_COLOR, (Color) null); } // System.err.println ("c:" + c); int[] redRange = { 0, 0 }; int[] greenRange = { 0, 0 }; int[] blueRange = { 0, 0 }; if (c != null) { // System.err.println("got color"); redRange[0] = redRange[1] = c.getRed(); greenRange[0] = greenRange[1] = c.getGreen(); blueRange[0] = blueRange[1] = c.getBlue(); } else { } newImage = ImageUtils.makeColorTransparent(image, redRange, greenRange, blueRange); } else if (tagName.equals(TAG_SHOW)) { JComponent contents = new JLabel(new ImageIcon(image)); String message = applyMacros(child, ATTR_MESSAGE, (String) null); if (message != null) { contents = GuiUtils.topCenter(new JLabel(message), contents); } if (!GuiUtils.askOkCancel("Continue?", contents)) { throw new MyQuitException(); } } else if (tagName.equals(TAG_MATTE)) { newImage = doMatte(image, child, 0); } else if (tagName.equals(TAG_LATLONLABELS)) { newImage = doLatLonLabels(child, viewManager, image, imageProps); } else if (tagName.equals(TAG_WRITE)) { ImageUtils.writeImageToFile(image, getImageFileName(applyMacros(child, ATTR_FILE))); } else if (tagName.equals(TAG_PUBLISH)) { getIdv().getPublishManager().publishIslImage(this, node, image); } else if (tagName.equals(TAG_CLIP)) { int[] ul; int[] lr; if (XmlUtil.hasAttribute(child, ATTR_DISPLAY)) { // System.err.println("Clipping from display"); DisplayControlImpl dc = findDisplayControl(child); if (dc == null) { throw new IllegalArgumentException("Could not find display:" + XmlUtil.toString(node)); } NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster(); MapProjection mapProjection = dc.getDataProjection(); java.awt.geom.Rectangle2D rect = mapProjection.getDefaultMapArea(); LatLonPoint llplr = mapProjection.getLatLon(new double[][] { { rect.getX() + rect.getWidth() }, { rect.getY() + rect.getHeight() } }); LatLonPoint llpul = mapProjection .getLatLon(new double[][] { { rect.getX() }, { rect.getY() } }); EarthLocation ulEl = new EarthLocationTuple(llpul, new Real(RealType.Altitude, 0)); EarthLocation lrEl = new EarthLocationTuple(llplr, new Real(RealType.Altitude, 0)); ul = display.getScreenCoordinates(display.getSpatialCoordinates(ulEl, null)); lr = display.getScreenCoordinates(display.getSpatialCoordinates(lrEl, null)); //System.err.println("ul:" + ulEl + " lr:" + lrEl); if (ul[0] > lr[0]) { int tmp = ul[0]; ul[0] = lr[0]; lr[0] = tmp; } if (ul[1] > lr[1]) { int tmp = ul[1]; ul[1] = lr[1]; lr[1] = tmp; } imageProps.put(ATTR_NORTH, new Double(ulEl.getLatitude().getValue())); imageProps.put(ATTR_WEST, new Double(ulEl.getLongitude().getValue())); imageProps.put(ATTR_SOUTH, new Double(lrEl.getLatitude().getValue())); imageProps.put(ATTR_EAST, new Double(lrEl.getLongitude().getValue())); } else if ((viewManager != null) && XmlUtil.hasAttribute(child, ATTR_NORTH)) { NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster(); EarthLocation el1 = DisplayControlImpl.makeEarthLocation(toDouble(child, ATTR_NORTH), toDouble(child, ATTR_WEST), 0); EarthLocation el2 = DisplayControlImpl.makeEarthLocation(toDouble(child, ATTR_SOUTH), toDouble(child, ATTR_EAST), 0); ul = display.getScreenCoordinates(display.getSpatialCoordinates(el1, null)); lr = display.getScreenCoordinates(display.getSpatialCoordinates(el2, null)); imageProps.put(ATTR_NORTH, new Double(el1.getLatitude().getValue())); imageProps.put(ATTR_WEST, new Double(el1.getLongitude().getValue())); imageProps.put(ATTR_SOUTH, new Double(el2.getLatitude().getValue())); imageProps.put(ATTR_EAST, new Double(el2.getLongitude().getValue())); } else if (XmlUtil.hasAttribute(child, ATTR_LEFT)) { ul = new int[] { (int) toDouble(child, ATTR_LEFT, imageWidth), (int) toDouble(child, ATTR_TOP, imageHeight) }; lr = new int[] { (int) toDouble(child, ATTR_RIGHT, imageWidth), (int) toDouble(child, ATTR_BOTTOM, imageHeight) }; } else if (viewManager != null) { //TODO: Clip on visad coordinates NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster(); ul = display.getScreenCoordinates(new double[] { -1, 1, 0 }); lr = display.getScreenCoordinates(new double[] { 1, -1, 0 }); int space = applyMacros(child, ATTR_SPACE, 0); int hspace = applyMacros(child, ATTR_HSPACE, space); int vspace = applyMacros(child, ATTR_VSPACE, space); ul[0] -= applyMacros(child, ATTR_SPACE_LEFT, hspace); ul[1] -= applyMacros(child, ATTR_SPACE_TOP, vspace); lr[0] += applyMacros(child, ATTR_SPACE_RIGHT, hspace); lr[1] += applyMacros(child, ATTR_SPACE_BOTTOM, vspace); } else { continue; } for (String attr : (List<String>) Misc.newList(ATTR_NORTH, ATTR_SOUTH, ATTR_EAST, ATTR_WEST)) { String kmlAttr = "kml." + attr; if (XmlUtil.hasAttribute(child, kmlAttr)) { imageProps.put(attr, new Double(applyMacros(child, kmlAttr, 0.0))); } } ul[0] = Math.max(0, ul[0]); ul[1] = Math.max(0, ul[1]); lr[0] = Math.min(lr[0], imageWidth); lr[1] = Math.min(lr[1], imageHeight); newImage = ImageUtils.clip(image, ul, lr); } else if (tagName.equals(TAG_SPLIT)) { shouldIterateChildren = false; int width = image.getWidth(null); int height = image.getHeight(null); int cols = applyMacros(child, ATTR_COLUMNS, 2); int rows = applyMacros(child, ATTR_ROWS, 2); String file = applyMacros(child, ATTR_FILE); int cnt = 0; int hSpace = width / cols; int vSpace = height / rows; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { pushProperties(); Hashtable myprops = new Hashtable(); putProperty("row", new Integer(row)); putProperty("column", new Integer(col)); putProperty("count", new Integer(++cnt)); String realFile = applyMacros(file, myprops); Image splitImage = image.getSubimage(hSpace * col, vSpace * row, hSpace, vSpace); processImage(ImageUtils.toBufferedImage(splitImage), realFile, child, myprops, viewManager, new Hashtable()); popProperties(); } } } else if (tagName.equals(TAG_THUMBNAIL)) { shouldIterateChildren = false; BufferedImage thumbImage = ImageUtils.toBufferedImage(resize(image, child)); String thumbFile = applyMacros(child, ATTR_FILE, (String) null); if (thumbFile == null) { thumbFile = IOUtil.stripExtension(filename) + "_thumb" + IOUtil.getFileExtension(filename); } processImage(thumbImage, thumbFile, child, null, viewManager, new Hashtable()); } else if (tagName.equals(TAG_KML)) { //NOOP } else if (tagName.equals(TAG_KMZFILE)) { //NOOP } else if (tagName.equals(TAG_OVERLAY)) { double transparency = applyMacros(child, ATTR_TRANSPARENCY, 0.0); Graphics2D g = image.createGraphics(); String imagePath = applyMacros(child, ATTR_IMAGE, (String) null); float scale = (float) applyMacros(child, ATTR_SCALE, 1.0); Rectangle imageRect = new Rectangle(0, 0, imageWidth, imageHeight); Point pp = ImageUtils.parsePoint(applyMacros(child, ATTR_PLACE, "lr,-10,-10"), imageRect); String text = applyMacros(child, ATTR_TEXT, (String) null); Color bg = applyMacros(child, ATTR_BACKGROUND, (Color) null); if (text != null) { double angle = Math.toRadians(applyMacros(child, ATTR_ANGLE, 0.0)); text = applyMacros(text); Color c = applyMacros(child, ATTR_COLOR, Color.white); if ((c != null) && (transparency > 0)) { c = new Color(c.getRed(), c.getGreen(), c.getBlue(), ImageUtils.toAlpha(transparency)); } //Color bg = applyMacros(child, ATTR_BACKGROUND, // (Color) null); if ((bg != null) && (transparency > 0)) { bg = new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), ImageUtils.toAlpha(transparency)); } setFont(g, child); FontMetrics fm = g.getFontMetrics(); Rectangle2D rect = fm.getStringBounds(text, g); int width = (int) rect.getWidth(); int height = (int) (rect.getHeight()); Point ap = ImageUtils.parsePoint(applyMacros(child, ATTR_ANCHOR, "lr,-10,-10"), new Rectangle(0, 0, width, height)); g.rotate(angle); if (bg != null) { g.setColor(bg); g.fillRect(pp.x - ap.x - 1, pp.y - ap.y - 1, (int) width + 2, (int) height + 2); } g.setColor(c); g.drawString(text, pp.x - ap.x, pp.y - ap.y + height); } if (imagePath != null) { Image overlay = ImageUtils.readImage(imagePath); if (overlay != null) { if (transparency > 0) { overlay = ImageUtils.setAlpha(overlay, transparency); } int width = overlay.getWidth(null); int height = overlay.getHeight(null); int scaledWidth = Math.round(width * scale); int scaledHeight = Math.round(height * scale); Image scaled = getScaledImage(overlay, scaledWidth, scaledHeight); Rectangle overlayRect = new Rectangle(0, 0, scaledWidth, scaledHeight); Point ap = ImageUtils.parsePoint(applyMacros(child, ATTR_ANCHOR, "lr,-10,-10"), overlayRect); g.drawImage(scaled, pp.x - ap.x, pp.y - ap.y, bg, null); } } } else { error("Unknown tag:" + tagName); } if (newImage != null) { String newFileName = applyMacros(child, ATTR_FILE, (String) null); if (shouldIterateChildren) { logger.trace("newFileName='{}' viewManager={} newImage={}", newFileName, viewManager, newImage); newImage = processImage(newImage, newFileName, child, null, viewManager, new Hashtable()); logger.trace("finished processImage; result: {}", newImage); } if (newFileName != null) { logger.trace("calling writeImageToFile..."); ImageUtils.writeImageToFile(newImage, getImageFileName(newFileName)); logger.trace("finished writeImageToFile"); debug("Writing image:" + newFileName); } if (!applyMacros(child, ATTR_COPY, false)) { image = newImage; } } } if (filename != null) { float quality = (float) applyMacros(node, ATTR_QUALITY, 1.0); List<String> fileToks = StringUtil.split(filename, ",", true, true); for (String file : fileToks) { file = getImageFileName(file); debug("Writing image:" + file); if (file.endsWith(FileManager.SUFFIX_KMZ) || file.endsWith(FileManager.SUFFIX_KML)) { GeoLocationInfo bounds = null; if (viewManager != null) { bounds = viewManager.getVisibleGeoBounds(); ImageSequenceGrabber.subsetBounds(bounds, imageProps); String tmpImageFile = getOutputPath(file); ImageUtils.writeImageToFile(image, tmpImageFile, quality); ImageWrapper imageWrapper = new ImageWrapper(tmpImageFile, null, bounds, null); imageWrapper.setProperties(imageProps); new ImageSequenceGrabber(file, getIdv(), this, node, (List<ImageWrapper>) Misc.newList(imageWrapper), null, 1); } } else { logger.trace("another writeImageToFile call..."); ImageUtils.writeImageToFile(image, file, quality); logger.trace("and it's done."); } } } logger.trace("result: {}", image); return image; }
From source file:v800_trainer.JCicloTronic.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double Radius = 6369.63; //in km double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.asin(Math.sqrt(a)); return Radius * c; }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
private void displayPDFAllDistributions() { XYSeriesCollection dataset = new XYSeriesCollection(); LeafAngleDistribution distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.ELLIPSOIDAL); XYSeries serie = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie.add(angleInDegrees, pdf);//from w ww .java2s .c om } //elliptical distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.ELLIPTICAL); XYSeries serie2 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie2.add(angleInDegrees, pdf); } //dataset.addSeries(serie2); //erectophile distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.ERECTOPHILE); XYSeries serie3 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie3.add(angleInDegrees, pdf); } dataset.addSeries(serie3); //extremophile distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.EXTREMOPHILE); XYSeries serie4 = new XYSeries(distribution.getType().toString(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie4.add(angleInDegrees, pdf); } dataset.addSeries(serie4); //horizontal distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.HORIZONTAL); XYSeries serie5 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie5.add(angleInDegrees, pdf); } //dataset.addSeries(serie5); //vertical distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.VERTICAL); XYSeries serie6 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie6.add(angleInDegrees, pdf); } //dataset.addSeries(serie6); //plagiophile distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.PLAGIOPHILE); XYSeries serie7 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie7.add(angleInDegrees, pdf); } dataset.addSeries(serie7); //planophile distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.PLANOPHILE); XYSeries serie8 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie8.add(angleInDegrees, pdf); } dataset.addSeries(serie8); //spherical distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.SPHERIC); XYSeries serie9 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie9.add(angleInDegrees, pdf); } dataset.addSeries(serie9); //uniform distribution = new LeafAngleDistribution(LeafAngleDistribution.Type.UNIFORM); XYSeries serie10 = new XYSeries(distribution.getType(), false); for (int i = 0; i < 180; i++) { double angleInDegrees = i / 2.0; double pdf = distribution.getDensityProbability(Math.toRadians(angleInDegrees)); serie10.add(angleInDegrees, pdf); } dataset.addSeries(serie10); ChartViewer viewer = new ChartViewer("PDF", 500, 500, 1); viewer.insertChart( ChartViewer.createBasicChart("f(L)", dataset, "Leaf inclination angle (degrees)", "PDF")); viewer.show(); }
From source file:uk.ac.diamond.scisoft.analysis.dataset.Maths.java
/** * toRadians - convert to radians//from w w w . j a v a 2 s .c om * @param a * @return dataset */ @SuppressWarnings("cast") public static AbstractDataset toRadians(final AbstractDataset a) { final int isize; final IndexIterator it = a.getIterator(); AbstractDataset ds; final int dt = a.getDtype(); switch (dt) { case AbstractDataset.INT8: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final byte[] i8data = ((ByteDataset) a).data; final float[] oi8data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final byte ix = i8data[it.index]; float ox; ox = (float) (Math.toRadians(ix)); oi8data[i++] = ox; } break; case AbstractDataset.INT16: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final short[] i16data = ((ShortDataset) a).data; final float[] oi16data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final short ix = i16data[it.index]; float ox; ox = (float) (Math.toRadians(ix)); oi16data[i++] = ox; } break; case AbstractDataset.INT32: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final int[] i32data = ((IntegerDataset) a).data; final double[] oi32data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final int ix = i32data[it.index]; double ox; ox = (double) (Math.toRadians(ix)); oi32data[i++] = ox; } break; case AbstractDataset.INT64: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final long[] i64data = ((LongDataset) a).data; final double[] oi64data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final long ix = i64data[it.index]; double ox; ox = (double) (Math.toRadians(ix)); oi64data[i++] = ox; } break; case AbstractDataset.ARRAYINT8: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final byte[] ai8data = ((CompoundByteDataset) a).data; final float[] oai8data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final byte ix = ai8data[it.index + j]; float ox; ox = (float) (Math.toRadians(ix)); oai8data[i++] = ox; } } break; case AbstractDataset.ARRAYINT16: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final short[] ai16data = ((CompoundShortDataset) a).data; final float[] oai16data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final short ix = ai16data[it.index + j]; float ox; ox = (float) (Math.toRadians(ix)); oai16data[i++] = ox; } } break; case AbstractDataset.ARRAYINT32: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final int[] ai32data = ((CompoundIntegerDataset) a).data; final double[] oai32data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final int ix = ai32data[it.index + j]; double ox; ox = (double) (Math.toRadians(ix)); oai32data[i++] = ox; } } break; case AbstractDataset.ARRAYINT64: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final long[] ai64data = ((CompoundLongDataset) a).data; final double[] oai64data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final long ix = ai64data[it.index + j]; double ox; ox = (double) (Math.toRadians(ix)); oai64data[i++] = ox; } } break; case AbstractDataset.FLOAT32: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final float[] f32data = ((FloatDataset) a).data; final float[] of32data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final float ix = f32data[it.index]; float ox; ox = (float) (Math.toRadians(ix)); of32data[i++] = ox; } break; case AbstractDataset.FLOAT64: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final double[] f64data = ((DoubleDataset) a).data; final double[] of64data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final double ix = f64data[it.index]; double ox; ox = (double) (Math.toRadians(ix)); of64data[i++] = ox; } break; case AbstractDataset.ARRAYFLOAT32: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final float[] af32data = ((CompoundFloatDataset) a).data; final float[] oaf32data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final float ix = af32data[it.index + j]; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[i++] = ox; } } break; case AbstractDataset.ARRAYFLOAT64: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final double[] af64data = ((CompoundDoubleDataset) a).data; final double[] oaf64data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final double ix = af64data[it.index + j]; double ox; ox = (double) (Math.toRadians(ix)); oaf64data[i++] = ox; } } break; case AbstractDataset.COMPLEX64: ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX64); final float[] c64data = ((ComplexFloatDataset) a).data; final float[] oc64data = ((ComplexFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final float ix = c64data[it.index]; final float iy = c64data[it.index + 1]; float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[i++] = ox; oc64data[i++] = oy; } break; case AbstractDataset.COMPLEX128: ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX128); final double[] c128data = ((ComplexDoubleDataset) a).data; final double[] oc128data = ((ComplexDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final double ix = c128data[it.index]; final double iy = c128data[it.index + 1]; double ox; double oy; ox = (double) (Math.toRadians(ix)); oy = (double) (Math.toRadians(iy)); oc128data[i++] = ox; oc128data[i++] = oy; } break; default: throw new IllegalArgumentException( "toRadians supports integer, compound integer, real, compound real, complex datasets only"); } ds.setName(a.getName()); addFunctionName(ds, "toRadians"); return ds; }
From source file:org.eclipse.january.dataset.GeneratedMaths.java
/** * toRadians - convert to radians/*w ww .ja v a2 s .c o m*/ * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset toRadians(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int as = da.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).getData(); if (as == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).getData(); if (as == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double ox; double oy; ox = (Math.toRadians(ix)); oy = (Math.toRadians(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double ox; double oy; ox = (Math.toRadians(ix)); oy = (Math.toRadians(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "toRadians supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "toRadians"); return result; }
From source file:org.eclipse.january.dataset.Maths.java
/** * toRadians - convert to radians/* w w w .j a v a 2 s .co m*/ * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset toRadians(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double ox; double oy; ox = (Math.toRadians(ix)); oy = (Math.toRadians(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double ox; double oy; ox = (Math.toRadians(ix)); oy = (Math.toRadians(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "toRadians supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "toRadians"); return result; }
From source file:org.eclipse.dataset.Maths.java
/** * toRadians - convert to radians//from w w w .ja va2 s.co m * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset toRadians(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDtype(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.toRadians(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.toRadians(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.toRadians(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.toRadians(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.toRadians(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.toRadians(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.toRadians(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.toRadians(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float ox; float oy; ox = (float) (Math.toRadians(ix)); oy = (float) (Math.toRadians(iy)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double ox; double oy; ox = (Math.toRadians(ix)); oy = (Math.toRadians(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double ox; double oy; ox = (Math.toRadians(ix)); oy = (Math.toRadians(iy)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "toRadians supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "toRadians"); return result; }