Search in sources :

Example 1 with CameraModelSettings

use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings in project GDSC-SMLM by aherbert.

the class CameraModelManager method listCameraModels.

/**
 * List the camera models with the correct dimensions.
 *
 * @param includeNone Set to true to include an empty string
 * @param width the width
 * @param height the height
 * @return the list
 */
public static String[] listCameraModels(boolean includeNone, int width, int height) {
    final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
    final List<String> list = createList(includeNone);
    for (final Map.Entry<String, CameraModelResource> entry : settings.getCameraModelResourcesMap().entrySet()) {
        final CameraModelResource resource = entry.getValue();
        if (resource.getWidth() == width && resource.getHeight() == height) {
            list.add(entry.getKey());
        }
    }
    return list.toArray(new String[0]);
}
Also used : CameraModelResource(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CameraModelSettings(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings)

Example 2 with CameraModelSettings

use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings in project GDSC-SMLM by aherbert.

the class CameraModelManager method load.

/**
 * Load the camera model. Returns null if the named model does not exist. Writes to the ImageJ log
 * if a problems occurred loading the model.
 *
 * @param name the name
 * @return the per pixel camera model (or null)
 */
public static PerPixelCameraModel load(String name) {
    PerPixelCameraModel model = cameraModels.get(name);
    if (model == null) {
        final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
        // Try and get the named resource
        final CameraModelResource resource = settings.getCameraModelResourcesMap().get(name);
        if (resource == null) {
            return null;
        }
        model = loadFromFile(name, resource.getFilename());
        // Cache this
        cameraModels.put(name, model);
    }
    return model;
}
Also used : CameraModelResource(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource) PerPixelCameraModel(uk.ac.sussex.gdsc.smlm.model.camera.PerPixelCameraModel) CameraModelSettings(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings)

Example 3 with CameraModelSettings

use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings in project GDSC-SMLM by aherbert.

the class CameraModelManager method saveResource.

private static void saveResource(PerPixelCameraModel cameraModel, String filename, String name) {
    final CameraModelResource.Builder resource = CameraModelResource.newBuilder();
    resource.setX(cameraModel.getXOrigin());
    resource.setY(cameraModel.getYOrigin());
    resource.setWidth(cameraModel.getWidth());
    resource.setHeight(cameraModel.getHeight());
    resource.setFilename(filename);
    final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
    CameraModelSettingsHolder.setSettings(settings.toBuilder().putCameraModelResources(name, resource.build()).build());
    // Cache this
    cameraModels.put(name, cameraModel);
}
Also used : CameraModelResource(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource) CameraModelSettings(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings)

Example 4 with CameraModelSettings

use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings in project GDSC-SMLM by aherbert.

the class CameraModelManager method listCameraModels.

/**
 * List the camera models.
 *
 * @param includeNone Set to true to include an invalid none model string
 * @return the list
 */
public static String[] listCameraModels(boolean includeNone) {
    final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
    final List<String> list = createList(includeNone);
    list.addAll(settings.getCameraModelResourcesMap().keySet());
    return list.toArray(new String[0]);
}
Also used : CameraModelSettings(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings)

Example 5 with CameraModelSettings

use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings in project GDSC-SMLM by aherbert.

the class CameraModelManager method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    String[] options = OPTIONS;
    final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
    if (settings.getCameraModelResourcesCount() == 0) {
        options = Arrays.copyOf(OPTIONS, 2);
    }
    pluginSettings = readCameraModelManagerSettings();
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addChoice("Option", options, pluginSettings.getOption());
    gd.addHelp(HelpUrls.getUrl("camera-model-manager"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    pluginSettings.setOption(gd.getNextChoiceIndex());
    switch(pluginSettings.getOption()) {
        case 5:
            runFilterImage();
            break;
        case 4:
            runDeleteCameraModel(settings);
            break;
        case 3:
            runViewCameraModel(settings);
            break;
        case 2:
            runPrintCameraModels(settings);
            break;
        case 1:
            runLoadFromDirectory();
            break;
        case 0:
        default:
            runLoadFromFile();
    }
    writeCameraModelManagerSettings(pluginSettings);
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) CameraModelSettings(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings)

Aggregations

CameraModelSettings (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelSettings)5 CameraModelResource (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource)3 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 PerPixelCameraModel (uk.ac.sussex.gdsc.smlm.model.camera.PerPixelCameraModel)1