001:
002: /*
003: * The JTS Topology Suite is a collection of Java classes that
004: * implement the fundamental operations required to validate a given
005: * geo-spatial data set to a known topological specification.
006: *
007: * Copyright (C) 2001 Vivid Solutions
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: *
023: * For more information, contact:
024: *
025: * Vivid Solutions
026: * Suite #1A
027: * 2328 Government Street
028: * Victoria BC V8T 5G5
029: * Canada
030: *
031: * (250)385-6040
032: * www.vividsolutions.com
033: */
034: package com.vividsolutions.jts.geomgraph;
035:
036: import com.vividsolutions.jts.util.*;
037: import com.vividsolutions.jts.geomgraph.Label;
038: import com.vividsolutions.jts.geom.Coordinate;
039: import com.vividsolutions.jts.geom.IntersectionMatrix;
040: import com.vividsolutions.jts.util.Assert;
041:
042: /**
043: * A GraphComponent is the parent class for the objects'
044: * that form a graph. Each GraphComponent can carry a
045: * Label.
046: * @version 1.7
047: */
048: abstract public class GraphComponent {
049:
050: protected Label label;
051: /**
052: * isInResult indicates if this component has already been included in the result
053: */
054: private boolean isInResult = false;
055: private boolean isCovered = false;
056: private boolean isCoveredSet = false;
057: private boolean isVisited = false;
058:
059: public GraphComponent() {
060: }
061:
062: public GraphComponent(Label label) {
063: this .label = label;
064: }
065:
066: public Label getLabel() {
067: return label;
068: }
069:
070: public void setLabel(Label label) {
071: this .label = label;
072: }
073:
074: public void setInResult(boolean isInResult) {
075: this .isInResult = isInResult;
076: }
077:
078: public boolean isInResult() {
079: return isInResult;
080: }
081:
082: public void setCovered(boolean isCovered) {
083: this .isCovered = isCovered;
084: this .isCoveredSet = true;
085: }
086:
087: public boolean isCovered() {
088: return isCovered;
089: }
090:
091: public boolean isCoveredSet() {
092: return isCoveredSet;
093: }
094:
095: public boolean isVisited() {
096: return isVisited;
097: }
098:
099: public void setVisited(boolean isVisited) {
100: this .isVisited = isVisited;
101: }
102:
103: /**
104: * @return a coordinate in this component (or null, if there are none)
105: */
106: abstract public Coordinate getCoordinate();
107:
108: /**
109: * compute the contribution to an IM for this component
110: */
111: abstract protected void computeIM(IntersectionMatrix im);
112:
113: /**
114: * An isolated component is one that does not intersect or touch any other
115: * component. This is the case if the label has valid locations for
116: * only a single Geometry.
117: *
118: * @return true if this component is isolated
119: */
120: abstract public boolean isIsolated();
121:
122: /**
123: * Update the IM with the contribution for this component.
124: * A component only contributes if it has a labelling for both parent geometries
125: */
126: public void updateIM(IntersectionMatrix im) {
127: Assert.isTrue(label.getGeometryCount() >= 2,
128: "found partial label");
129: computeIM(im);
130: }
131:
132: }
|