/usr/include/SFCGAL/detail/GeometrySet.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 | /**
* 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_DETAIL_GEOMETRY_SET_H_
#define _SFCGAL_DETAIL_GEOMETRY_SET_H_
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/variant.hpp>
#include <SFCGAL/config.h>
#include <SFCGAL/Kernel.h>
#include <SFCGAL/detail/TypeForDimension.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/Box_intersection_d/Box_with_handle_d.h>
// comparison operator on segments, for use in a std::set
bool operator< ( const CGAL::Segment_2<SFCGAL::Kernel>& sega, const CGAL::Segment_2<SFCGAL::Kernel>& segb );
bool operator< ( const CGAL::Segment_3<SFCGAL::Kernel>& sega, const CGAL::Segment_3<SFCGAL::Kernel>& segb );
namespace SFCGAL {
class Geometry;
namespace detail {
///
/// Primitive type enumeration. Note that the value is the dimension !
enum PrimitiveType {
PrimitivePoint = 0,
PrimitiveSegment = 1,
PrimitiveSurface = 2,
PrimitiveVolume = 3
};
///
/// Primitive handle. Holds a pointer to a primitive, through the 'handle' member
template <int Dim>
struct PrimitiveHandle {
//
// We use boost::variant here for convenience, whereas it is needed
typedef boost::variant< const typename Point_d<Dim>::Type*,
const typename Segment_d<Dim>::Type*,
const typename Surface_d<Dim>::Type*,
const typename Volume_d<Dim>::Type* > Type;
Type handle;
template <class T>
PrimitiveHandle( const T* p ) : handle( p ) {}
template <class T>
inline const T* as() const {
return boost::get<const T*>( handle );
}
};
///
/// PrimitiveBox. Type used for CGAL::Box_intersection_d
template <int Dim>
struct PrimitiveBox {
typedef CGAL::Box_intersection_d::Box_with_handle_d<double, Dim, PrimitiveHandle<Dim>*> Type;
};
///
/// BoxCollection for use with CGAL::Box_intersection_d
template <int Dim>
struct BoxCollection {
typedef std::vector<typename PrimitiveBox<Dim>::Type> Type;
};
///
/// HandleCollection. Used to store PrimitiveHandle
template <int Dim>
struct HandleCollection {
typedef std::list<PrimitiveHandle<Dim> > Type;
};
///
/// Flags available for each type of Geometry type.
/// Primitives can be 'flagged' in order to speed up recomposition
enum ElementFlag {
// the polyhedron is planar => build a triangle or a polygon
FLAG_IS_PLANAR = 1
};
///
/// CollectionElement, a Primitive with flags
/// Primitive : Point_d, Segment_d, Surface_d, Volume_d
template <class Primitive>
class CollectionElement {
public:
int flags() const {
return _flags;
}
void setFlags( int flags ) {
_flags = flags;
}
Primitive& primitive() {
return _primitive;
}
const Primitive& primitive() const {
return _primitive;
}
// constructor from Primitive
CollectionElement() : _flags( 0 ) {}
CollectionElement( const Primitive& p ) : _primitive( p ), _flags( 0 ) {}
CollectionElement( const Primitive& p, int f ) : _primitive( p ), _flags( f ) {}
CollectionElement( const CollectionElement& other ) :
_primitive( other._primitive ),
_flags( other._flags ) {
}
bool operator< ( const CollectionElement& other ) const {
return _primitive < other._primitive;
}
private:
Primitive _primitive;
int _flags;
};
template <class Primitive>
std::ostream& operator<<( std::ostream& ostr, const CollectionElement<Primitive>& p )
{
ostr << p.primitive() << " flags: " << p.flags();
return ostr;
}
///
/// A GeometrySet represents a set of CGAL primitives.
/// Primitive are either of dimension 0 (points),
/// dimension 1 (segments), dimension 2 (surfaces, a.k.a. polygon or triangles)
/// or dimension 3 (polyhedron)
template <int Dim>
class GeometrySet {
public:
// Points are stored in an ordered set
typedef std::set<CollectionElement<typename Point_d<Dim>::Type> > PointCollection;
// Segments are stored in an ordered set
typedef std::set<CollectionElement<typename Segment_d<Dim>::Type> > SegmentCollection;
typedef std::list<CollectionElement<typename Surface_d<Dim>::Type> > SurfaceCollection;
typedef std::list<CollectionElement<typename Volume_d<Dim>::Type> > VolumeCollection;
GeometrySet();
/**
* Construct a GeometrySet from a SFCGAL::Geometry
*/
GeometrySet( const Geometry& g );
/**
* Construct a GeometrySet from a Point
*/
GeometrySet( const typename TypeForDimension<Dim>::Point& g, int flags = 0 );
/**
* Construct a GeometrySet from a Segment
*/
GeometrySet( const typename TypeForDimension<Dim>::Segment& g, int flags = 0 );
/**
* Construct a GeometrySet from a Surface
*/
GeometrySet( const typename TypeForDimension<Dim>::Surface& g, int flags = 0 );
/**
* Construct a GeometrySet from a Volume
*/
GeometrySet( const typename TypeForDimension<Dim>::Volume& g, int flags = 0 );
/**
* Add primitives from another set
*/
void merge( const GeometrySet<Dim>& g );
/**
* Add a geometry by decomposing it into CGAL primitives
*/
void addGeometry( const Geometry& g );
/**
* add a primitive from a PrimitiveHandle to the set
*/
void addPrimitive( const PrimitiveHandle<Dim>& p );
/**
* add a primitive from a CGAL::Object to the set
* pointsAsRing : if set to true, build a polygon if o is a vector of points
*/
void addPrimitive( const CGAL::Object& o, bool pointsAsRing = false );
/**
* add a point to the set
*/
void addPrimitive( const typename TypeForDimension<Dim>::Point& g, int flags = 0 );
template <class IT>
void addPoints( IT ibegin, IT iend ) {
std::copy( ibegin, iend, std::inserter( _points, _points.end() ) );
}
/**
* collect all points of b and add them to the point list
*/
void collectPoints( const PrimitiveHandle<Dim>& b );
/**
* add a segment to the set
*/
void addPrimitive( const typename TypeForDimension<Dim>::Segment& g, int flags = 0 );
template <class IT>
void addSegments( IT ibegin, IT iend ) {
std::copy( ibegin, iend, std::inserter( _segments, _segments.end() ) );
}
/**
* add a surface to the set
*/
void addPrimitive( const typename TypeForDimension<Dim>::Surface& g, int flags = 0 );
template <class IT>
void addSurfaces( IT ibegin, IT iend ) {
std::copy( ibegin, iend, std::back_inserter( _surfaces ) );
}
/**
* add a volume to the set
*/
void addPrimitive( const typename TypeForDimension<Dim>::Volume& g, int flags = 0 );
template <class IT>
void addVolumes( IT ibegin, IT iend ) {
std::copy( ibegin, iend, std::back_inserter( _volumes ) );
}
/**
* Get the maximum geometry dimension of the set
* -1 : empty
* 0 : there are points
* 1 : there are segments
* 2 : there are surfaces
* 3 : there are volumes
*/
int dimension() const;
/**
* Add the boundary (segments) of a surface
*/
void addBoundary( const typename TypeForDimension<Dim>::Surface& surface );
/**
* Add the boundary (surfaces) of a volume
*/
void addBoundary( const typename TypeForDimension<Dim>::Volume& volume );
/**
* Compute all bounding boxes and handles of the set
*/
void computeBoundingBoxes( typename HandleCollection<Dim>::Type& handles, typename BoxCollection<Dim>::Type& boxes ) const;
inline PointCollection& points() {
return _points;
}
inline const PointCollection& points() const {
return _points;
}
inline SegmentCollection& segments() {
return _segments;
}
inline const SegmentCollection& segments() const {
return _segments;
}
inline SurfaceCollection& surfaces() {
return _surfaces;
}
inline const SurfaceCollection& surfaces() const {
return _surfaces;
}
inline VolumeCollection& volumes() {
return _volumes;
}
inline const VolumeCollection& volumes() const {
return _volumes;
}
/**
* Returns true if the set holds points
*/
bool hasPoints() const;
/**
* Returns true if the set holds segments
*/
bool hasSegments() const;
/**
* Returns true if the set holds surfaces
*/
bool hasSurfaces() const;
/**
* Returns true if the set holds volumes
*/
bool hasVolumes() const;
/**
* convert the set to a SFCGAL::Geometry
*/
std::auto_ptr<Geometry> recompose() const;
/**
* Filter (remove) primitives that are already covered by others
*/
void filterCovered( GeometrySet<Dim>& output ) const;
private:
///
/// Given an input SFCGAL::Geometry, decompose it into CGAL primitives
void _decompose( const Geometry& g );
PointCollection _points;
SegmentCollection _segments;
SurfaceCollection _surfaces;
VolumeCollection _volumes;
};
///
/// Display operator
SFCGAL_API std::ostream& operator<<( std::ostream&, const GeometrySet<2>& g );
///
/// Display operator
SFCGAL_API std::ostream& operator<<( std::ostream&, const GeometrySet<3>& g );
// bbox of a 'volume' for 2D, will never be called
inline
CGAL::Bbox_2 compute_solid_bbox( const NoVolume&, dim_t<2> )
{
return CGAL::Bbox_2();
}
inline
CGAL::Bbox_3 compute_solid_bbox( const TypeForDimension<3>::Volume& vol, dim_t<3> )
{
BOOST_ASSERT( vol.size_of_vertices () );
MarkedPolyhedron::Point_const_iterator pit = vol.points_begin();
CGAL::Bbox_3 ret( pit->bbox() );
++pit;
for ( ; pit != vol.points_end(); ++pit ) {
ret = ret + pit->bbox();
}
return ret;
}
} // namespace detail
} // namespace SFCGAL
#endif
|