Dune Core Modules (2.8.0)

polyhedron.hh
1// -*- mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=2 sw=2 sts=2:
3#ifndef DUNE_POLYHEDRON_HH
4#define DUNE_POLYHEDRON_HH
5
6#include <algorithm>
7
8#include <dune/grid/io/file/dgfparser/blocks/polygon.hh>
9
10namespace Dune
11{
12
13 namespace dgf
14 {
15
16 // PolyhedronBlock
17 // ---------------
18
19 struct PolyhedronBlock
20 : public BasicBlock
21 {
22 explicit PolyhedronBlock ( std::istream &in, int numPolys )
23 : BasicBlock( in, "Polyhedron" ), numPolys_( numPolys )
24 {}
25
26 int get ( std::vector< std::vector< int > > &polyhedra )
27 {
28 reset();
29 std::vector< int > polyhedron;
30 int minPolyId = 1;
31 while( getnextline() )
32 {
33 polyhedron.clear();
34 for( int polyIdx; getnextentry( polyIdx ); )
35 {
36 if( (polyIdx < 0) || (polyIdx > numPolys_) )
37 DUNE_THROW( DGFException, "Error in " << *this << ": Invalid polygon index (" << polyIdx << " not int [0, " << numPolys_ << "])" );
38
39 minPolyId = std::min( minPolyId, polyIdx );
40 polyhedron.push_back( polyIdx );
41 }
42
43 polyhedra.push_back( polyhedron );
44 }
45
46 // subtract minimal number to have 0 starting numbering
47 if( minPolyId > 0 )
48 {
49 const size_t polySize = polyhedra.size();
50 for( size_t i=0; i<polySize; ++i )
51 {
52 const size_t pSize = polyhedra[ i ].size();
53 for( size_t j=0; j<pSize; ++j )
54 {
55 polyhedra[ i ][ j ] -= minPolyId;
56 }
57 }
58 }
59 return polyhedra.size();
60 }
61
62 protected:
63 const int numPolys_;
64 };
65
66 } // namespace dgf
67} // end namespace Dune
68
69#endif // #ifndef DUNE_POLYHEDRON_HH
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)