Commit 77ac4687 authored by Lynn Garren's avatar Lynn Garren
Browse files

get Evgueni Tcherniaev's changes for 1.9 release

parent f3b3ce39
Makefile.in
configure
aclocal.m4
autom4te.cache
This diff is collapsed.
......@@ -8,5 +8,6 @@ pkginclude_HEADERS = \
Plane3D.h \
Point3D.h \
Transform3D.h \
Transform3D.icc \
Vector3D.h \
defs.h
// -*- C++ -*-
// $Id: Normal3D.h,v 1.1.1.1 2003/07/15 20:15:05 garren Exp $
// $Id: Normal3D.h,v 1.2 2003/07/17 09:05:28 garren Exp $
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
// 13.09.96 E.Chernyaev - initial version
// 09.09.96 E.Chernyaev - initial version
// 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
// the functionality from Hep3Vector
// the functionality from CLHEP::Hep3Vector
// 01.04.03 E.Chernyaev - CLHEP-1.9: template version
//
#ifndef HEP_NORMAL3D_H
#define HEP_NORMAL3D_H
#include <iosfwd>
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Geometry/BasicVector3D.h"
class HepTransform3D;
/**
* Geometrical 3D Normal with components of double type.
* HepPoint3D, HepVector3D and HepNormal3D have very similar
* set of member functions. The difference among these classes
* is how they are transformed by HepTransform3D.
*
* @see BasicVector3D
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class HepNormal3D : public BasicVector3D {
public:
/// Default constructor.
HepNormal3D() {}
/// Constructor from three doubles.
HepNormal3D(double x, double y, double z) : BasicVector3D(x,y,z) {}
/// Constructor from base class.
HepNormal3D(const BasicVector3D & v) : BasicVector3D(v) {}
namespace HepGeom {
class Transform3D;
/**
* Geometrical 3D Normal.
* This is just a declaration of the class needed to define
* specializations Normal3D<float> and Normal3D<double>.
*
* @ingroup geometry
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class T>
class Normal3D : public BasicVector3D<T> {};
/**
* Constructor from Hep3Vector.
* This constructor is needed only for backward compatibility and
* in principle should be absent.
* Geometrical 3D Normal with components of float type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
HepNormal3D(const CLHEP::Hep3Vector & v) : BasicVector3D(v) {}
template<>
class Normal3D<float> : public BasicVector3D<float> {
public:
/**
* Default constructor. */
Normal3D() {}
/**
* Constructor from three numbers. */
Normal3D(float x, float y, float z) : BasicVector3D<float>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Normal3D(const float * a)
: BasicVector3D<float>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Normal3D(const Normal3D<float> & v) : BasicVector3D<float>(v) {}
/// Destructor.
~HepNormal3D() {}
/**
* Constructor from BasicVector3D<float>. */
Normal3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
/// Assignment.
HepNormal3D & operator=(const HepNormal3D & v) {
set(v.x(), v.y(), v.z()); return *this;
}
/**
* Destructor. */
~Normal3D() {}
/// Assignment from BasicVector3D and
/// classes derived from it: HepPoint3D, HepVector3D.
HepNormal3D & operator=(const BasicVector3D & v) {
set(v.x(), v.y(), v.z()); return *this;
}
/**
* Assignment. */
Normal3D<float> & operator=(const Normal3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Normal3D<float> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Transformation by Transform3D. */
Normal3D<float> & transform(const Transform3D & m);
};
/**
* Transformation of Normal<float> by Transform3D.
* @relates Normal3D
*/
Normal3D<float>
operator*(const Transform3D & m, const Normal3D<float> & n);
/**
* Geometrical 3D Normal with components of double type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Normal3D<double> : public BasicVector3D<double> {
public:
/**
* Default constructor. */
Normal3D() {}
/// Transformation by HepTransform3D.
HepNormal3D & transform(const HepTransform3D & m);
};
/**
* Constructor from three numbers. */
Normal3D(double x, double y, double z) : BasicVector3D<double>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Normal3D(const float * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Constructor from array of doubles. */
explicit Normal3D(const double * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Normal3D(const Normal3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Normal3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<double>. */
Normal3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Destructor. */
~Normal3D() {}
/**
* Constructor from CLHEP::Hep3Vector.
* This constructor is needed only for backward compatibility and
* in principle should be absent.
*/
Normal3D(const CLHEP::Hep3Vector & v)
: BasicVector3D<double>(v.x(),v.y(),v.z()) {}
/**
* Conversion (cast) to CLHEP::Hep3Vector.
* This operator is needed only for backward compatibility and
* in principle should not exit.
*/
operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
/**
* Assignment. */
Normal3D<double> & operator=(const Normal3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Normal3D<double> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<double>. */
Normal3D<double> & operator=(const BasicVector3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Transformation by Transform3D. */
Normal3D<double> & transform(const Transform3D & m);
};
/**
* Transformation of Normal<double> by Transform3D.
* @relates Normal3D
*/
Normal3D<double>
operator*(const Transform3D & m, const Normal3D<double> & n);
#include "CLHEP/Geometry/Transform3D.h"
} /* namespace HepGeom */
inline HepNormal3D & HepNormal3D::transform(const HepTransform3D & m) {
return *this = m * (*this);
}
typedef HepGeom::Normal3D<double> HepNormal3D;
#endif /* HEP_NORMAL3D_H */
// -*- C++ -*-
// $Id: Plane3D.h,v 1.1.1.1 2003/07/15 20:15:05 garren Exp $
// $Id: Plane3D.h,v 1.2 2003/07/17 09:05:28 garren Exp $
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
......@@ -7,117 +7,152 @@
// History:
// 22.09.96 E.Chernyaev - initial version
// 19.10.96 J.Allison - added == and <<.
// 15.04.03 E.Chernyaev - CLHEP-1.9: template version
#ifndef HEP_PLANE3D_H
#define HEP_PLANE3D_H
#include <iosfwd>
#include "CLHEP/Geometry/Point3D.h"
#include "CLHEP/Geometry/Normal3D.h"
#include <iostream>
/**
* Geometrical 3D Plane.
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class HepPlane3D {
protected:
double aa, bb, cc, dd;
#include "CLHEP/Geometry/Transform3D.h"
namespace HepGeom {
/**
* Template class for geometrical plane in 3D.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<class T>
class Plane3D {
protected:
T a_, b_, c_, d_;
public:
public:
/**
* Default constructor - creates plane z=0. */
Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.) {}
/**
* Constructor from four numbers - creates plane a*x+b*y+c*z+d=0. */
Plane3D(T a, T b, T c, T d) : a_(a), b_(b), c_(c), d_(d) {}
/**
* Constructor from normal and point. */
Plane3D(const Normal3D<T> & n, const Point3D<T> & p)
: a_(n.x()), b_(n.y()), c_(n.z()), d_(-n*p) {}
/**
* Constructor from three points. */
Plane3D(const Point3D<T> & p1,
const Point3D<T> & p2,
const Point3D<T> & p3) {
Normal3D<T> n = (p2-p1).cross(p3-p1);
a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ = -n*p1;
}
/** Copy constructor.
* Plane3D<double> has two constructors:
* from Plane3D<double> (provided by compiler) and
* from Plane3D<float> (defined in this file).
* Plane3D<float> has only the last one.
*/
Plane3D(const Plane3D<float> & p)
: a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {}
/**
* Destructor. */
~Plane3D() {};
/**
* Assignment. */
Plane3D<T> & operator=(const Plane3D<T> & p) {
a_ = p.a_; b_ = p.b_; c_ = p.c_; d_ = p.d_; return *this;
}
/**
* Returns the a-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
T a() const { return a_; }
/**
* Returns the b-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
T b() const { return b_; }
/**
* Returns the c-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
T c() const { return c_; }
/**
* Returns the free member of the plane equation: a*x+b*y+c*z+d=0. */
T d() const { return d_; }
/**
* Returns normal. */
Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); }
/**
* Normalization. */
Plane3D<T> & normalize() {
double ll = sqrt(a_*a_ + b_*b_ + c_*c_);
if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; }
return *this;
}
/**
* Returns distance to the point. */
T distance(const Point3D<T> & p) const {
return a()*p.x() + b()*p.y() + c()*p.z() + d();
}
/**
* Returns projection of the point to the plane. */
Point3D<T> point(const Point3D<float> & p) const {
T k = distance(p)/(a()*a()+b()*b()+c()*c());
return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k);
}
/**
* Returns projection of the origin to the plane. */
Point3D<T> point() const {
T k = -d()/(a()*a()+b()*b()+c()*c());
return Point3D<T>(a()*k, b()*k, c()*k);
}
/**
* Test for equality. */
bool operator == (const Plane3D<T> & p) const {
return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d();
}
/**
* Test for inequality. */
bool operator != (const Plane3D<T> & p) const {
return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d();
}
/**
* Transformation by Transform3D. */
Plane3D<T> & transform(const Transform3D & m) {
Normal3D<T> n = normal();
n.transform(m);
d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z();
return *this;
}
};
/**
* Constructor from four numbers.
* The numbers are the coefficients of the equation of the plane:
* @code
* a*x+b*y+c*z+d=0
* @endcode
* Output to the stream.
* @relates Plane3D
*/
HepPlane3D(double a=0, double b=0, double c=0, double d=0)
: aa(a), bb(b), cc(c), dd(d) {}
/// Constructor from normal and point.
HepPlane3D(const HepNormal3D &n, const HepPoint3D &p)
: aa(n.x()), bb(n.y()), cc(n.z()), dd(-n*p) {}
/// Constructor from three points.
HepPlane3D(const HepPoint3D &p1, const HepPoint3D &p2, const HepPoint3D &p3)
{
HepNormal3D n = (p2-p1).cross(p3-p1);
aa = n.x(); bb = n.y(); cc = n.z(); dd = -n*p1;
}
/// Copy constructor.
HepPlane3D(const HepPlane3D &plane)
: aa(plane.aa), bb(plane.bb), cc(plane.cc), dd(plane.dd) {}
/// Destructor.
~HepPlane3D() {};
/// Assignment.
HepPlane3D& operator=(const HepPlane3D &plane) {
aa = plane.aa; bb = plane.bb; cc = plane.cc; dd = plane.dd; return *this;
}
/// Test for equality.
bool operator == (const HepPlane3D& p) const {
return aa == p.aa && bb == p.bb && cc == p.cc && dd == p.dd;
}
/// Test for inequality.
bool operator != (const HepPlane3D& p) const {
return aa != p.aa || bb != p.bb || cc != p.cc || dd != p.dd;
}
/// Normalization.
HepPlane3D& normalize() {
double ll = sqrt(aa*aa + bb*bb + cc*cc);
if (ll > 0.0) { aa /= ll; bb /= ll; cc /= ll, dd /= ll; }
return *this;
}
/// Returns coefficient a from the plane defining equation.
double a() const { return aa; }
/// Returns coefficient b from the plane defining equation.
double b() const { return bb; }
/// Returns coefficient c from the plane defining equation.
double c() const { return cc; }
/// Returns free member d from the plane defining equation.
double d() const { return dd; }
/// Returns normal.
HepNormal3D normal() const { return HepNormal3D(aa,bb,cc); }
/// Returns distance from the point.
double distance(const HepPoint3D &p) const {
return aa*p.x() + bb*p.y() + cc*p.z() + dd;
}
/// Returns projection of the point to the plane.
HepPoint3D point(const HepPoint3D &p) const {
double k = distance(p)/(aa*aa+bb*bb+cc*cc);
return HepPoint3D(p.x()-aa*k, p.y()-bb*k, p.z()-cc*k);
}
/// Returns projection of the origin to the plane.
HepPoint3D point() const {
double k = -dd/(aa*aa+bb*bb+cc*cc);
return HepPoint3D(aa*k, bb*k, cc*k);
}
/// Transformation by HepTransform3D.
HepPlane3D& transform(const HepTransform3D &m) {
HepNormal3D n(aa,bb,cc);
n.transform(m);
dd = -n*point().transform(m); aa = n.x(); bb = n.y(); cc = n.z();
return *this;
}
};
/**
* Output to the stream.
* @relates HepPlane3D
*/
std::ostream & operator << (std::ostream &, const HepPlane3D &);
std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p);
/**
* Output to the stream.
* @relates Plane3D
*/
std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p);
} /* namespace HepGeom */
typedef HepGeom::Plane3D<double> HepPlane3D;
#endif /* HEP_PLANE3D_H */
// -*- C++ -*-
// $Id: Point3D.h,v 1.1.1.1 2003/07/15 20:15:05 garren Exp $
// $Id: Point3D.h,v 1.2 2003/07/17 09:05:28 garren Exp $
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
......@@ -7,81 +7,222 @@
// History:
// 09.09.96 E.Chernyaev - initial version
// 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
// the functionality from Hep3Vector
// the functionality from CLHEP::Hep3Vector
// 01.04.03 E.Chernyaev - CLHEP-1.9: template version
//
#ifndef HEP_POINT3D_H
#define HEP_POINT3D_H
#include <iosfwd>
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Geometry/BasicVector3D.h"
class HepTransform3D;
/**
* Geometrical 3D Point with components of double type.
* HepPoint3D, HepVector3D and HepNormal3D have very similar
* set of member functions. The difference among these classes
* is how they are transformed by HepTransform3D.
*
* @see BasicVector3D
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class HepPoint3D : public BasicVector3D {
public:
/// Default constructor.
HepPoint3D() {}
/// Constructor from three doubles.
HepPoint3D(double x, double y, double z) : BasicVector3D(x,y,z) {}
/// Constructor from base class.
HepPoint3D(const BasicVector3D & v) : BasicVector3D(v) {}
namespace HepGeom {
class Transform3D;
/**
* Geometrical 3D Point.
* This is just a declaration of the class needed to define
* specializations Point3D<float> and Point3D<double>.
*
* @ingroup geometry
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class T>
class Point3D : public BasicVector3D<T> {};
/**
* Constructor from Hep3Vector.
* This constructor is needed only for backward compatibility and
* in principle should be absent.
* Geometrical 3D Point with components of float type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
HepPoint3D(const CLHEP::Hep3Vector & v) : BasicVector3D(v) {}
/// Destructor.
~HepPoint3D() {}
/// Assignment.
HepPoint3D & operator=(const HepPoint3D & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/// Assignment from BasicVector3D and
/// classes derived from it: HepVector3D, HepNormal3D.
HepPoint3D & operator=(const BasicVector3D & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/// Returns distance to the origin squared.
double distance2() const { return mag2(); }
/// Returns distance to the point squared.
double distance2(const HepPoint3D & p) const {
double delx = p.x()-x(), dely = p.y()-y(), delz = p.z()-z();
return delx*delx + dely*dely + delz*delz;
}
/// Returns distance to the origin.
double distance() const { return sqrt(distance2()); }