1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/**********************************************************************
* $Id: Node.cpp,v 1.10 2004/12/08 13:54:43 strk Exp $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#include <geos/geomgraph.h>
//#include "../headers/util.h"
#ifndef DEBUG
#define DEBUG 0
#endif
#ifndef COMPUTE_Z
#define COMPUTE_Z 1
#endif
namespace geos {
Node::Node(Coordinate& newCoord, EdgeEndStar* newEdges): GraphComponent(new Label(0,Location::UNDEF)) {
coord=newCoord;
#if DEBUG
cerr<<"["<<this<<"] Node::Node("<<newCoord.toString()<<")"<<endl;
#endif
#if COMPUTE_Z
ztot = 0;
addZ(newCoord.z);
if ( newEdges )
{
vector<EdgeEnd*>*eev = newEdges->getEdges();
for (unsigned int i=0; i<eev->size(); i++)
{
EdgeEnd *ee = (*eev)[i];
addZ(ee->getCoordinate().z);
}
}
#endif // COMPUTE_Z
edges=newEdges;
}
Node::~Node(){
#if DEBUG
cerr<<"["<<this<<"] Node::~Node()"<<endl;
#endif
delete edges;
}
const Coordinate& Node::getCoordinate() const {
return coord;
}
EdgeEndStar* Node::getEdges() {
return edges;
}
bool Node::isIsolated() {
return (label->getGeometryCount()==1);
}
void Node::add(EdgeEnd *e) {
#if DEBUG
cerr<<"["<<this<<"] Node::add("<<e->print()<<")"<<endl;
#endif
// Assert: start pt of e is equal to node point
if (edges==NULL) edges=new EdgeEndStar();
edges->insert(e);
e->setNode(this);
#if COMPUTE_Z
addZ(e->getCoordinate().z);
#endif
}
void Node::mergeLabel(const Node* n) {
mergeLabel(n->label);
}
void Node::mergeLabel(const Label* label2) {
for (int i=0; i<2; i++) {
int loc=computeMergedLocation(label2, i);
int thisLoc=label->getLocation(i);
if (thisLoc==Location::UNDEF) label->setLocation(i,loc);
}
}
void Node::setLabel(int argIndex, int onLocation) {
if (label==NULL) {
label=new Label(argIndex, onLocation);
} else
label->setLocation(argIndex, onLocation);
}
void Node::setLabelBoundary(int argIndex) {
int loc=Location::UNDEF;
if (label!=NULL)
loc=label->getLocation(argIndex);
// flip the loc
int newLoc;
switch (loc){
case Location::BOUNDARY: newLoc=Location::INTERIOR; break;
case Location::INTERIOR: newLoc=Location::BOUNDARY; break;
default: newLoc=Location::BOUNDARY; break;
}
label->setLocation(argIndex, newLoc);
}
int Node::computeMergedLocation(const Label* label2, int eltIndex){
int loc=Location::UNDEF;
loc=label->getLocation(eltIndex);
if (!label2->isNull(eltIndex)) {
int nLoc=label2->getLocation(eltIndex);
if (loc!=Location::BOUNDARY) loc=nLoc;
}
return loc;
}
string Node::print(){
string out="node "+coord.toString()+" lbl: "+label->toString();
return out;
}
void
Node::addZ(double z)
{
#if DEBUG
cerr<<"["<<this<<"] Node::addZ("<<z<<")";
#endif
if ( ISNAN(z) )
{
#if DEBUG
cerr<<" skipped"<<endl;
#endif
return;
}
for (unsigned int i=0; i<zvals.size(); i++) if ( zvals[i] == z )
{
#if DEBUG
cerr<<" already stored"<<endl;
#endif
return;
}
zvals.push_back(z);
ztot+=z;
coord.z=ztot/zvals.size();
#if DEBUG
cerr<<" added "<<z<<": ["<<ztot<<"/"<<zvals.size()<<"="<<coord.z<<"]"<<endl;
#endif
}
const vector<double>&
Node::getZ() const
{
return zvals;
}
} // namespace geos
/**********************************************************************
* $Log: Node.cpp,v $
* Revision 1.10 2004/12/08 13:54:43 strk
* gcc warnings checked and fixed, general cleanups.
*
* Revision 1.9 2004/11/29 16:05:33 strk
* Fixed a bug in LineIntersector::interpolateZ causing NaN values
* to come out.
* Handled dimensional collapses in ElevationMatrix.
* Added ISNAN macro and changed ISNAN/FINITE macros to avoid
* dispendious isnan() and finite() calls.
*
* Revision 1.8 2004/11/26 09:53:48 strk
* Added more FINITE calls, and added inf and -inf to FINITE checks
*
* Revision 1.7 2004/11/20 15:41:18 strk
* Added management of vector of composing Z values.
*
* Revision 1.6 2004/11/19 10:10:23 strk
* COMPUTE_Z re-enabled by default
*
* Revision 1.5 2004/11/17 15:09:08 strk
* Changed COMPUTE_Z defaults to be more conservative
*
* Revision 1.4 2004/11/17 08:13:16 strk
* Indentation changes.
* Some Z_COMPUTATION activated by default.
*
* Revision 1.3 2004/10/21 22:29:54 strk
* Indentation changes and some more COMPUTE_Z rules
*
* Revision 1.2 2004/07/02 13:28:26 strk
* Fixed all #include lines to reflect headers layout change.
* Added client application build tips in README.
*
* Revision 1.1 2004/03/19 09:48:45 ybychkov
* "geomgraph" and "geomgraph/indexl" upgraded to JTS 1.4
*
* Revision 1.12 2003/11/07 01:23:42 pramsey
* Add standard CVS headers licence notices and copyrights to all cpp and h
* files.
*
*
**********************************************************************/
|