xc
GeomObj.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //GeomObj.h
22 
23 #ifndef GEOMOBJ_H
24 #define GEOMOBJ_H
25 
26 #include <iostream>
27 #include "ProtoGeom.h"
28 #include "lists/PolyPos.h"
29 
30 class Pos2d;
31 class Pos3d;
32 class Vector2d;
33 class Trf2d;
34 class Plotter;
35 
36 
38 //
40 class GeomObj: public ProtoGeom
41  {
42  public:
43  typedef PolyPos<Pos3d> list_Pos3d;
44  typedef PolyPos<Pos2d> list_Pos2d;
45 
46  GeomObj(void);
47  virtual ~GeomObj(void) {}
48  virtual GeomObj *getCopy(void) const=0;
50  virtual unsigned short int Dimension(void) const= 0;
52  virtual GEOM_FT getLength(void) const= 0;
54  virtual GEOM_FT getArea(void) const= 0;
56  virtual GEOM_FT getVolume(void) const= 0;
58  inline virtual bool hasCenterOfMass(void) const
59  { return false;}
60  GEOM_FT getCenterOfMassArea(void) const;
61 
62  virtual void Print(std::ostream &os) const= 0;
63  virtual void Plot(Plotter &) const {}
64  };
65 
66 std::ostream &operator<<(std::ostream &, const GeomObj &);
67 
68 
70 template <class input_iterator>
71 GEOM_FT area(input_iterator begin,input_iterator end)
72  {
73  GEOM_FT retval= 0.0;
74  for(input_iterator i=begin;i!=end;i++)
75  retval+= i->getArea();
76  return retval;
77  }
78 
80 template <class input_iterator>
81 GEOM_FT volume(input_iterator begin,input_iterator end)
82  {
83  GEOM_FT retval= 0.0;
84  for(input_iterator i=begin;i!=end;i++)
85  retval+= i->getVolume();
86  return retval;
87  }
88 
90 template <class input_iterator>
91 GEOM_FT length(input_iterator begin,input_iterator end)
92  {
93  GEOM_FT retval= 0.0;
94  for(input_iterator i=begin;i!=end;i++)
95  retval+= i->getLength();
96  return retval;
97  }
98 
100 template <class input_iterator>
101 void print(std::ostream &os,input_iterator begin,input_iterator end)
102  {
103  if(begin!=end)
104  {
105  input_iterator i= begin;
106  os << *i; i++;
107  for(;i!=end;i++)
108  os << ", " << *i;
109  }
110  }
111 #endif
virtual bool hasCenterOfMass(void) const
Return true if the object has a center of mass.
Definition: GeomObj.h:58
Base class for position lists.
Definition: PolyPos.h:35
Posición en dos dimensiones.
Definition: Pos2d.h:41
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
GeomObj(void)
Constructor.
Definition: GeomObj.cc:28
Vector en dos dimensiones.
Definition: Vector2d.h:40
virtual GEOM_FT getVolume(void) const =0
Return the volume of the object.
Base class for geometry objects.
Definition: ProtoGeom.h:33
GEOM_FT getCenterOfMassArea(void) const
Return the dimension used to compute the center of mass, as follows:
Definition: GeomObj.cc:36
virtual GEOM_FT getLength(void) const =0
Return the length of the object.
virtual unsigned short int Dimension(void) const =0
Return the dimension of the object 0, 1, 2 or 3.
Posición en tres dimensiones.
Definition: Pos3d.h:44
virtual GEOM_FT getArea(void) const =0
Return the area of the object.
Clase base para las entidades geométricas.
Definition: GeomObj.h:40