GeoModel - GeoModelCore
GeoSimplePolygonBrep.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoSimplePolygonBrep.h"
6 #include "GeoModelKernel/GeoShapeAction.h"
7 #include "PolygonTriangulator.h"//For volume.
8 #include <cmath>
9 #include <stdexcept>
10 
11 const std::string GeoSimplePolygonBrep::s_classType = "SimplePolygonBrep";
12 const ShapeType GeoSimplePolygonBrep::s_classTypeID = 0x20;
13 
14 GeoSimplePolygonBrep::GeoSimplePolygonBrep(double dz)
15  : m_dZ(dz)
16 {
17 }
18 
19 GeoSimplePolygonBrep::~GeoSimplePolygonBrep()
20 {
21 }
22 
23 double GeoSimplePolygonBrep::volume () const
24 {
25  if (!isValid())
26  throw std::runtime_error ("Volume requested for incomplete simple polygon brep");
27 
28  //Todo: Cache the polygon area so we wont have to do this every time.
29  PolygonTriangulator pt(m_xVertices,m_yVertices);
30 
31  double area(0);//Fixme: Should be cached!
32 
33  double x1, x2, x3, y1, y2, y3;
34  PolygonTriangulator::Triangles::const_iterator it, itE = pt.triangles()->end();
35  for (it = pt.triangles()->begin(); it!=itE; ++it) {
36  x1 = m_xVertices.at(it->at(0)-1);
37  x2 = m_xVertices.at(it->at(1)-1);
38  x3 = m_xVertices.at(it->at(2)-1);
39  y1 = m_yVertices.at(it->at(0)-1);
40  y2 = m_yVertices.at(it->at(1)-1);
41  y3 = m_yVertices.at(it->at(2)-1);
42  area += fabs ( -x2*y1 + x3*y1 + x1 * y2 - x3 * y2 - x1*y3 + x2*y3 );//This is actually twice the area of the triangle we are adding
43  }
44 
45  return area * m_dZ;//area is thus twice the area, but dZ is only half the depth, so the two factors of two cancel out.
46 }
47 
48 const std::string & GeoSimplePolygonBrep::type() const
49 {
50  return s_classType;
51 }
52 
53 ShapeType GeoSimplePolygonBrep::typeID() const
54 {
55  return s_classTypeID;
56 }
57 
58 void GeoSimplePolygonBrep::addVertex(double XVertex, double YVertex)
59 {
60  m_xVertices.push_back(XVertex);
61  m_yVertices.push_back(YVertex);
62 }
63 
64 void GeoSimplePolygonBrep::exec(GeoShapeAction *action) const
65 {
66  action->handleSimplePolygonBrep(this);
67 }
68 
This class is a visitor for shapes. It allows a navigation of the boolean expression tree for shapes...