/usr/include/SFCGAL/detail/graph/GeometryGraph.h is in libsfcgal-dev 1.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | /**
* SFCGAL
*
* Copyright (C) 2012-2013 Oslandia <infos@oslandia.com>
* Copyright (C) 2012-2013 IGN (http://www.ign.fr)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SFCGAL_GRAPH_GEOMETRYGRAPH_H_
#define _SFCGAL_GRAPH_GEOMETRYGRAPH_H_
#include <boost/graph/adjacency_list.hpp>
#include <SFCGAL/detail/graph/Vertex.h>
#include <SFCGAL/detail/graph/Edge.h>
namespace SFCGAL {
namespace graph {
/**
*
*/
typedef enum {
DIRECT = 0,
REVERSE = 1
} EdgeDirection ;
/**
* reverse EdgeDirection (DIRECT=>REVERSE, REVERSE=>DIRECT)
*/
inline EdgeDirection reverse( const EdgeDirection& direction )
{
return ( EdgeDirection )( 1 - direction ) ;
}
/**
*
* @brief [private]Represents the vertices and edges for a list of geometries.
*
* A boost::adjancency_list is wrapped in order to be able to annex some information
* and to provide basic functionalities.
*
* @warning duplicate matching is performed in GeometryGraphBuilder (allows to modify position once it's done)
*
*/
template < typename VertexProperties, typename EdgeProperties >
class GeometryGraphT {
public:
typedef VertexProperties vertex_properties ;
typedef EdgeProperties edge_properties ;
/**
* the wrapped graphEdgeProperties
*/
typedef boost::adjacency_list<
boost::listS, /* stable identifiers */
boost::listS, /* parallel edges allowed + stable identifiers */
boost::bidirectionalS,
vertex_properties,
edge_properties
> graph_t ;
typedef typename boost::graph_traits< graph_t >::vertex_descriptor vertex_descriptor ;
typedef typename boost::graph_traits< graph_t >::edge_descriptor edge_descriptor ;
typedef typename boost::graph_traits< graph_t >::vertex_iterator vertex_iterator ;
typedef typename boost::graph_traits< graph_t >::edge_iterator edge_iterator ;
/**
* An edge descriptor, with a direction.
*
* From the vertex point of view, out edges are DIRECT, in edges are REVERSE.
*/
typedef std::pair< edge_descriptor, EdgeDirection> directed_edge_descriptor ;
typedef typename boost::graph_traits< graph_t >::in_edge_iterator in_edge_iterator ;
typedef typename boost::graph_traits< graph_t >::out_edge_iterator out_edge_iterator ;
/**
* [vertex]returns the number of vertices
*/
inline size_t numVertices() const {
return boost::num_vertices( _graph );
}
/**
* [iterator]return vertex iterator
*
* @code
* typename GeometryGraph<V,E>::vertex_iterator it, end ;
* for ( boost::tie( it, end ) = g.vertices(); it != end; ++it ){
* typename GeometryGraph<V,E>::vertex_descriptor vertex = *it ;
* std::cout << g[ vertex ].coordinate << std::endl;
* }
* @endcode
*/
inline std::pair< vertex_iterator, vertex_iterator > vertices() const {
return boost::vertices( _graph );
}
/**
* [vertex]add a vertex to the graph
* @return the identifier of the vertex
*/
vertex_descriptor addVertex( const vertex_properties& properties = vertex_properties() ) {
return boost::add_vertex( properties, _graph );
}
/**
* [vertex]Remove a vertex (and all its adjacent edges)
*/
void removeVertex( const vertex_descriptor& vertex ) {
boost::clear_vertex( vertex );
boost::remove_vertex( vertex );
}
/**
* [edge]returns the number of vertices
*/
inline size_t numEdges() const {
return boost::num_edges( _graph );
}
/**
* [iterator]return edge iterator
*
* @code
* typename GeometryGraph<V,E>::edge_iterator it, end ;
* for ( boost::tie( it, end ) = g.edges(); it != end; ++it ){
* typename GeometryGraph<V,E>::edge_descriptor edge = *it ;
* std::cout << g.source(edge) << "," << g.target(edge) << std::endl;
* }
* @endcode
*/
inline std::pair< edge_iterator, edge_iterator > edges() const {
return boost::edges( _graph );
}
/**
* [edge]Add an Edge to the Graph
* @return the identifier of the vertex
*/
edge_descriptor addEdge(
const vertex_descriptor& source,
const vertex_descriptor& target,
const EdgeProperties& properties = EdgeProperties()
) {
return boost::add_edge( source, target, properties, _graph ).first;
}
/**
* [edge]get the source vertex for an edge
*/
vertex_descriptor source( const edge_descriptor& edge ) const {
return boost::source( edge, _graph ) ;
}
/**
* [edge]get the source vertex for an edge
*/
vertex_descriptor source( const edge_descriptor& edge, const EdgeDirection& direction ) const {
return direction == DIRECT ? boost::source( edge, _graph ) : boost::target( edge, _graph ) ;
}
/**
* [edge]get the source vertex for an edge with a direction
*/
vertex_descriptor source( const directed_edge_descriptor& edge ) const {
return source( edge.first, edge.second ) ;
}
/**
* [edge]get the target vertex for an edge
*/
vertex_descriptor target( const edge_descriptor& edge ) const {
return boost::target( edge, _graph ) ;
}
/**
* [edge]get the target vertex for an edge with a direction
*/
vertex_descriptor target( const edge_descriptor& edge, const EdgeDirection& direction ) const {
return direction == DIRECT ? boost::target( edge, _graph ) : boost::source( edge, _graph ) ;
}
/**
* [edge]get the target vertex for an edge with a direction
*/
vertex_descriptor target( const directed_edge_descriptor& edge ) const {
return target( edge.first, edge.second );
}
/**
* [edge]Remove an edge
*/
void removeEdge( const edge_descriptor& edge ) {
boost::remove_edge( edge, _graph );
}
/**
* [edge]Get edges from a to b and from b to a
*/
std::vector< directed_edge_descriptor > edges( const vertex_descriptor& a, const vertex_descriptor& b ) const {
std::vector< directed_edge_descriptor > result ;
//out_edges from a targeting b
{
out_edge_iterator it, end ;
for ( boost::tie( it,end ) = boost::out_edges( a,_graph ); it != end; ++it ) {
if ( target( *it ) != b ) {
continue ;
}
result.push_back( std::make_pair( *it, DIRECT ) );
}
}
//out_edges from b targeting a
{
out_edge_iterator it, end ;
for ( boost::tie( it,end ) = boost::out_edges( b,_graph ); it != end; ++it ) {
if ( target( *it ) != a ) {
continue ;
}
result.push_back( std::make_pair( *it, REVERSE ) );
}
}
return result ;
}
/**
* returns the degree of a vertex
*/
inline size_t degree( const vertex_descriptor& vertex ) const {
return boost::degree( vertex,_graph );
}
/**
* [adjacency]get in edges
*/
std::vector< edge_descriptor > inEdges( const vertex_descriptor& vertex ) {
std::vector< edge_descriptor > edges ;
in_edge_iterator it, end ;
for ( boost::tie( it, end ) = boost::in_edges( vertex, _graph ); it != end; ++it ) {
edges.push_back( *it );
}
return edges ;
}
/**
* [adjacency]get out edges
*/
std::vector< edge_descriptor > outEdges( const vertex_descriptor& vertex ) const {
std::vector< edge_descriptor > edges ;
out_edge_iterator it, end ;
for ( boost::tie( it, end ) = boost::out_edges( vertex, _graph ); it != end; ++it ) {
edges.push_back( *it );
}
return edges ;
}
/**
* [adjacency]get in/out edges
*/
std::vector< directed_edge_descriptor > inOutEdges( const vertex_descriptor& vertex ) const {
std::vector< directed_edge_descriptor > edges ;
{
in_edge_iterator it, end ;
for ( boost::tie( it, end ) = boost::in_edges( vertex, _graph ); it != end; ++it ) {
edges.push_back( std::make_pair( *it, REVERSE ) );
}
}
//out edges
{
out_edge_iterator it, end ;
for ( boost::tie( it, end ) = boost::out_edges( vertex, _graph ); it != end; ++it ) {
edges.push_back( std::make_pair( *it, DIRECT ) );
}
}
return edges ;
}
/**
* [adjacency]Returns the list of the adjacent vertices using both DIRECT and REVERSE direction
* @param vertex input vertex
* @param withReverseDirection indicates if in_edges are used
*/
std::set< vertex_descriptor > adjacentVertices( const vertex_descriptor& vertex, bool withReverseDirection = true ) {
std::set< vertex_descriptor > vertices ;
// out edges
{
out_edge_iterator it, end ;
for ( boost::tie( it, end ) = boost::out_edges( vertex, _graph ); it != end; ++it ) {
vertex_descriptor reached = target( *it ) ;
if ( reached != vertex ) {
vertices.insert( reached );
}
}
}
// in edges
if ( withReverseDirection ) {
in_edge_iterator it, end ;
for ( boost::tie( it, end ) = boost::in_edges( vertex, _graph ); it != end; ++it ) {
vertex_descriptor reached = source( *it ) ;
if ( reached != vertex ) {
vertices.insert( reached );
}
}
}
return vertices ;
}
/**
* [helper]indicates if edges are opposite
*/
inline bool areOpposite( const edge_descriptor& a, const edge_descriptor& b ) const {
return source( a ) == target( b ) && target( a ) == source( b ) ;
}
/**
* [helper]indicates if edges are opposite
*/
inline bool areParallel( const edge_descriptor& a, const edge_descriptor& b ) const {
return source( a ) == source( b ) && target( a ) == target( b ) ;
}
/**
* [EdgeString]revert the order of a list of edges. Old edges are removed from the graph, new
* ones are created.
*
* @warning properties are kept but oriented one (left face, right face, etc.) are lost.
*/
void reverse( std::vector< edge_descriptor >& edges ) {
std::vector< edge_descriptor > result ;
for ( typename std::vector< edge_descriptor >::reverse_iterator it = edges.rbegin();
it != edges.rend(); ++it ) {
edge_descriptor newEdge = addEdge( target( *it ), source( *it ), ( *this )[*it] );
result.push_back( newEdge );
removeEdge( *it );
}
edges = result ;
}
/**
* returns the VertexProperties attached to a Vertex
*/
inline const vertex_properties& operator [] ( const vertex_descriptor& vertex ) const {
return _graph[ vertex ];
}
/**
* returns the VertexProperties attached to a Vertex
*/
inline vertex_properties& operator [] ( const vertex_descriptor& vertex ) {
return _graph[ vertex ];
}
/**
* returns the VertexProperties attached to a Vertex
*/
inline const edge_properties& operator [] ( const edge_descriptor& edge ) const {
return _graph[ edge ];
}
/**
* returns the VertexProperties attached to a Vertex
*/
inline edge_properties& operator [] ( const edge_descriptor& edge ) {
return _graph[ edge ];
}
/**
* returns the wrapped boost::graph
*/
inline graph_t& graph() {
return _graph ;
}
/**
* returns the wrapped boost::graph
*/
inline const graph_t& graph() const {
return _graph ;
}
/**
* implicit cast to the wrapped boost graph in order to keep boost graph interface
*/
operator graph_t& ( void ) {
return _graph;
}
/**
* implicit cast to the wrapped boost graph in order to keep boost graph interface
*/
operator const graph_t& ( void ) const {
return _graph;
}
private:
/**
* a wrapped boost::graph
*/
graph_t _graph ;
};
/**
* Default GeometryGraph with predefined Vertex and Edge properties for general usage
*/
typedef GeometryGraphT< Vertex, Edge > GeometryGraph ;
}//graph
}//SFCGAL
#endif
|