001/*
002 * Copyright 2010, 2011 Institut Pasteur.
003 * 
004 * This file is part of ICY.
005 * 
006 * ICY is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * ICY is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with ICY. If not, see <http://www.gnu.org/licenses/>.
018 */
019package plugins.tutorial.roi;
020
021import icy.gui.dialog.MessageDialog;
022import icy.gui.frame.progress.AnnounceFrame;
023import icy.plugin.abstract_.PluginActionable;
024import icy.sequence.Sequence;
025
026import java.awt.Polygon;
027
028import plugins.kernel.roi.roi2d.ROI2DPolyLine;
029
030/**
031 * This tutorial details how to create an intensity ruler.
032 * Look at IntensityRulerPainter for the most interesting part.
033 * 
034 * @author Fabrice de Chaumont
035 * @author Stephane Dallongeville
036 */
037public class IntensityOverRoi extends PluginActionable
038{
039    @Override
040    public void run()
041    {
042        Sequence sequence = getActiveSequence();
043
044        if (sequence == null)
045        {
046            MessageDialog.showDialog("Please open an image first.", MessageDialog.ERROR_MESSAGE);
047            return;
048        }
049
050        sequence.addOverlay(new IntensityOverRoiPainter());
051
052        new AnnounceFrame("This tutorial displays an intensity profile over compatible ROIs");
053
054        // creates a ROI2DPolyLine if no ROI exists
055        if (!sequence.hasROI())
056        {
057            ROI2DPolyLine roi = new ROI2DPolyLine();
058            int[] x = {3 * sequence.getWidth() / 4, 2 * sequence.getWidth() / 4, sequence.getWidth() / 4};
059            int[] y = {sequence.getHeight() / 2, sequence.getHeight() / 4, sequence.getHeight() / 2};
060            Polygon polygon = new Polygon(x, y, x.length);
061            roi.setPolygon(polygon);
062            sequence.addROI(roi);
063        }
064    }
065}