nodemap.cpp

来自「一个很好的vc底层代码」· C++ 代码 · 共 181 行

CPP
181
字号
/********************************************************************** * $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 <geos/geomgraph.h>#define DEBUG 0namespace geos {NodeMap::NodeMap(NodeFactory *newNodeFact){#if DEBUG	cerr<<"["<<this<<"] NodeMap::NodeMap"<<endl;#endif	nodeFact=newNodeFact;	nodeMap=new map<Coordinate,Node*,CoordLT>();}NodeMap::~NodeMap(){	map<Coordinate,Node*,CoordLT>::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<<"["<<this<<"] NodeMap::addNode("<<coord.toString()<<")";#endif	Node *node=find(coord);	if (node==NULL) {#if DEBUG		cerr<<" is new"<<endl;#endif		node=nodeFact->createNode(coord);		(*nodeMap)[coord]=node;	}	else	{#if DEBUG		cerr<<" already found ("<<node->getCoordinate().toString()<<") - adding Z"<<endl;#endif		node->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<<"["<<this<<"] NodeMap::addNode("<<n->print()<<")";#endif	Node *node=find(n->getCoordinate());	if (node==NULL) {#if DEBUG		cerr<<" is new"<<endl;#endif		(*nodeMap)[n->getCoordinate()]=n;		return n;	}#if DEBUG	else	{		cerr<<" found already, merging label"<<endl;		const vector<double>&zvals = n->getZ();		for (unsigned int i=0; i<zvals.size(); i++)		{			node->addZ(zvals[i]);		}	}#endif // DEBUG	node->mergeLabel(n);	return node;}voidNodeMap::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<Coordinate,Node*,CoordLT>::iterator found=nodeMap->find(coord);	if (found==nodeMap->end())		return NULL;	else		return found->second;}map<Coordinate,Node*,CoordLT>::iteratorNodeMap::iterator() const{	return nodeMap->begin();}//Doesn't work yet. Use iterator.//public Collection NodeMap::values(){//	return nodeMap.values();//}vector<Node*>*NodeMap::getBoundaryNodes(int geomIndex) const{	vector<Node*>* bdyNodes=new vector<Node*>();	map<Coordinate,Node*,CoordLT>::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;}stringNodeMap::print() const{	string out="";	map<Coordinate,Node*,CoordLT>::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. * * **********************************************************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?