/********************************************************************** * $Id: NodeMap.cpp,v 1.5 2004/11/20 15:45:47 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 #define DEBUG 0 namespace geos { NodeMap::NodeMap(NodeFactory *newNodeFact) { #if DEBUG cerr<<"["<(); } NodeMap::~NodeMap() { map::iterator it=nodeMap->begin(); for (;it!=nodeMap->end();it++) { Node *node=it->second; delete node; } delete nodeMap; delete nodeFact; } Node* NodeMap::addNode(const Coordinate& coord) { #if DEBUG cerr<<"["<createNode(coord); (*nodeMap)[coord]=node; } else { #if DEBUG cerr<<" already found ("<getCoordinate().toString()<<") - adding Z"<addZ(coord.z); } return node; } // first arg cannot be const because // it is liable to label-merging ... --strk; Node* NodeMap::addNode(Node *n) { #if DEBUG cerr<<"["<print()<<")"; #endif Node *node=find(n->getCoordinate()); if (node==NULL) { #if DEBUG cerr<<" is new"<getCoordinate()]=n; return n; } #if DEBUG else { cerr<<" found already, merging label"<&zvals = n->getZ(); for (unsigned int i=0; iaddZ(zvals[i]); } } #endif // DEBUG node->mergeLabel(n); return node; } void NodeMap::add(EdgeEnd *e) { Coordinate& p=e->getCoordinate(); Node *n=addNode(p); n->add(e); } /* * @return the node if found; null otherwise */ Node* NodeMap::find(const Coordinate& coord) const { map::iterator found=nodeMap->find(coord); if (found==nodeMap->end()) return NULL; else return found->second; } map::iterator NodeMap::iterator() const { return nodeMap->begin(); } //Doesn't work yet. Use iterator. //public Collection NodeMap::values(){ // return nodeMap.values(); //} vector* NodeMap::getBoundaryNodes(int geomIndex) const { vector* bdyNodes=new vector(); map::iterator it=nodeMap->begin(); for (;it!=nodeMap->end();it++) { Node *node=it->second; if (node->getLabel()->getLocation(geomIndex)==Location::BOUNDARY) bdyNodes->push_back(node); } return bdyNodes; } string NodeMap::print() const { string out=""; map::iterator it=nodeMap->begin(); for (;it!=nodeMap->end();it++) { Node *node=it->second; out+=node->print(); } return out; } } /********************************************************************** * $Log: NodeMap.cpp,v $ * Revision 1.5 2004/11/20 15:45:47 strk * Fixed Z merging in addNode(Node *) * * Revision 1.4 2004/11/20 15:41:41 strk * Added Z merging in ::addNode * * 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. * * **********************************************************************/