dune-grid  2.6-git
polyhedron.hh
Go to the documentation of this file.
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 
9 
10 namespace Dune
11 {
12 
13  namespace dgf
14  {
15 
16  // PolyhedronBlock
17  // ---------------
18 
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
Dune::dgf::BasicBlock::reset
void reset()
Definition: basic.hh:49
Dune::VTK::polyhedron
@ polyhedron
Definition: common.hh:188
polygon.hh
Dune::dgf::PolyhedronBlock
Definition: polyhedron.hh:19
Dune::dgf::PolyhedronBlock::PolyhedronBlock
PolyhedronBlock(std::istream &in, int numPolys)
Definition: polyhedron.hh:22
Dune::dgf::BasicBlock::getnextentry
bool getnextentry(ENTRY &entry)
Definition: basic.hh:61
Dune::dgf::PolyhedronBlock::numPolys_
const int numPolys_
Definition: polyhedron.hh:63
Dune::dgf::BasicBlock
Definition: basic.hh:28
Dune::dgf::PolyhedronBlock::get
int get(std::vector< std::vector< int > > &polyhedra)
Definition: polyhedron.hh:26
Dune::dgf::BasicBlock::getnextline
bool getnextline()
Definition: basic.cc:92
Dune
Include standard header files.
Definition: agrid.hh:58
Dune::DGFException
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:12