Dune Core Modules (2.9.1)

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