KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
g_cylinder.h
Go to the documentation of this file.
1 /* $Id: g_cylinder.h 13673 2013-01-29 23:17:18Z elh $ */
2 /* ===========================================================================*
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * ===========================================================================*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef KJB_G_CPP_CYLINDER_H
23 #define KJB_G_CPP_CYLINDER_H
24 
25 #include <m_cpp/m_vector.h>
26 #include <l_cpp/l_readable.h>
27 #include <l_cpp/l_writeable.h>
28 
29 namespace kjb
30 {
31 // Geometric cylinder class. For renderable cylinder, see kjb::opengl::Cylinder
32 class Cylinder : public Readable, public Writeable
33 {
34 public:
35  Cylinder(const Vector& p1, const Vector& p2, double radius) :
36  Readable(),
37  Writeable(),
38  p1_(p1),
39  p2_(p2),
40  r_(radius)
41  {
42  if(p1_.size() != 3 || p2_.size() != 3)
43  {
45  "Cylinder() both points must be 3-dimensional.");
46  }
47  }
48 
49  Cylinder(const char * filename)
50  : Readable(), Writeable(), p1_(3, 0.0), p2_(3, 0.0)
51  {
52  read(filename);
53  }
54 
55  Cylinder(std::istream & in)
56  : Readable(), Writeable(), p1_(3, 0.0), p2_(3, 0.0)
57  {
58  read(in);
59  }
60 
62  virtual Cylinder& operator= (const Cylinder& c);
63 
64  virtual void read(std::istream & in);
65 
66  virtual void read(const char * filename)
67  {
68  Readable::read(filename);
69  }
70 
71  virtual void write(std::ostream & out) const;
72 
73  virtual void write(const char * filename) const
74  {
75  Writeable::write(filename);
76  }
77 
78  const Vector& get_p1() const {return p1_;}
79  const Vector& get_p2() const {return p2_;}
80  double get_radius() const { return r_; }
81 
82 // alternative parameterization: length, width, direction
83  double get_length() const { return norm2(p1_ - p2_); }
84  double get_width() const { return 2 * r_; }
85 
86  // Get direction vector from p1 to p2.
87  Vector get_direction() const { return (p2_ - p1_).normalize(); }
88 
89 //private:
90 protected:
93  double r_;
94 };
95 
96 
97 } // namespace kjb
98 
99 #endif
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
double get_length() const
Definition: g_cylinder.h:83
double r_
Definition: g_cylinder.h:93
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
virtual void write(std::ostream &out) const
Writes this Writeable to an output stream.
Definition: g_cylinder.cpp:94
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
virtual void write(std::ostream &out) const =0
Writes this Writeable to an output stream.
virtual Cylinder & operator=(const Cylinder &c)
Copies a Cylinder into this one.
Definition: g_cylinder.cpp:36
double get_radius() const
Definition: g_cylinder.h:80
Cylinder(const char *filename)
Definition: g_cylinder.h:49
Cylinder(std::istream &in)
Definition: g_cylinder.h:55
Vector p1_
Definition: g_cylinder.h:91
virtual void read(std::istream &in)
Reads this Readable from an input stream.
Definition: g_cylinder.cpp:46
virtual void read(const char *filename)
Reads this Readable from a file.
Definition: g_cylinder.h:66
virtual void write(const char *filename) const
Writes this Writeable to a file.
Definition: g_cylinder.h:73
Vector get_direction() const
Definition: g_cylinder.h:87
Vector p2_
Definition: g_cylinder.h:92
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Cylinder(const Vector &p1, const Vector &p2, double radius)
Definition: g_cylinder.h:35
Vector & normalize(kjb_c::Norm_method method=kjb_c::NORMALIZE_BY_MAGNITUDE)
Normalize vector in place by choice of method (default by magnitude).
Definition: m_vector.h:1524
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Definition: g_cylinder.h:32
double norm2(const Int_vector &op1)
Compute l2-norm of vector.
Definition: l_int_vector.h:1558
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
double get_width() const
Definition: g_cylinder.h:84
const Vector & get_p1() const
Definition: g_cylinder.h:78
const Vector & get_p2() const
Definition: g_cylinder.h:79
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...