001/*******************************************************************************
002 * This software is provided as a supplement to the authors' textbooks on digital
003 *  image processing published by Springer-Verlag in various languages and editions.
004 * Permission to use and distribute this software is granted under the BSD 2-Clause 
005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 
006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 
007 * Visit http://imagingbook.com for additional details.
008 *******************************************************************************/
009
010package imagingbook.pub.regions;
011
012import ij.gui.Overlay;
013import ij.gui.Roi;
014import ij.gui.ShapeRoi;
015
016import java.awt.BasicStroke;
017import java.awt.Color;
018import java.awt.Shape;
019import java.util.List;
020
021
022/**
023 * Updated: 2014-11-12
024 *
025 */
026public class ContourOverlay extends Overlay {
027
028        static float defaultStrokeWidth = 1.0f; //0.2f;
029        static Color defaultOuterColor = Color.red;
030        static Color defaultInnerColor = Color.green;
031        
032//      static int capsstyle = BasicStroke.CAP_ROUND;
033//      static int joinstyle = BasicStroke.JOIN_ROUND;
034//      static float[] outerDashing = {12, 4}; 
035//      static float[] innerDashing = {12, 4}; 
036//      static boolean DRAW_CONTOURS = true;
037        
038        public ContourOverlay(ContourTracer tracer) {
039                this(tracer, defaultStrokeWidth, defaultOuterColor, defaultInnerColor);
040        }
041        
042        public ContourOverlay(ContourTracer tracer, 
043                        double strokeWidth, Color outerColor, Color innerColor) {
044                
045                List<Contour> outerContours = tracer.getOuterContours();
046                List<Contour> innerContours = tracer.getInnerContours();
047                addContours(outerContours, outerColor, strokeWidth);
048                addContours(innerContours, innerColor, strokeWidth);
049        }
050        
051        public void addContours(List<Contour> contours, Color color, double strokeWidth) {
052                BasicStroke stroke = new BasicStroke((float)strokeWidth);
053                for (Contour c : contours) {
054                        Shape s = c.getPolygonPath();
055                        Roi roi = new ShapeRoi(s);
056                        roi.setStrokeColor(color);
057                        roi.setStroke(stroke);
058                        add(roi);
059                }
060        }
061
062}
063
064
065