Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/Geometry/JCylinder.hpp

Go to the documentation of this file.
00001 // Check if the parameters are defined...
00002 #ifndef Type
00003   #error "Type is not defined."
00004 #endif
00005 
00006 #ifndef  FType 
00007   #error "FType is not defined."
00008 #endif
00009 
00010 #ifndef JPoint  
00011   #error "JPoint is not defined."
00012 #endif
00013 
00014 #ifndef JPoint_t
00015   #error "JPoint_t is not defined."
00016 #endif
00017 
00018 #ifndef JCircle 
00019   #error "JCircle is not defined."
00020 #endif
00021 
00022 #ifndef JCircle_t
00023   #error "JCircle_t is not defined."
00024 #endif
00025 
00026 #ifndef JCylinder
00027   #error "JCylinder is not defined."
00028 #endif
00029 
00030 #ifndef JCylinder_t
00031   #error "JCylinder_t is not defined."
00032 #endif
00033 
00034 struct JCylinder_t {
00035    FType  height;                      // height of the JCylinder
00036    FType  area_cache;                  // Area   cache valid > 0.0
00037    FType  volume_cache;                // Volume cache valid > 0.0
00038 };
00039 
00040 class JCylinder : public JCircle {
00041 public:
00042    inline JCylinder() : JCircle( 0, 0, 0 )
00043    {
00044       memset( &cyl, 0, sizeof( JCylinder_t ) );
00045    }
00046 
00047    inline JCylinder( Type X ) : JCircle( X, 0, 0 )
00048    {
00049      memset( &cyl, 0, sizeof( JCylinder_t ) );
00050    }
00051 
00052    inline JCylinder( Type X, Type Y ) : JCircle( X, Y, 0 )
00053    {
00054      memset( &cyl, 0, sizeof( JCylinder_t ) );
00055    }
00056 
00057    inline JCylinder( Type X, Type Y, FType radius )
00058      : JCircle( X, Y, radius )
00059    {
00060      memset( &cyl, 0, sizeof( JCylinder_t ) );
00061      cyl.area_cache   = -1;
00062      cyl.volume_cache = -1;
00063    }
00064 
00065    inline JCylinder( Type X, Type Y, FType Radius, FType Height )
00066      : JCircle( X, Y, Radius )
00067    {
00068       memset( &cyl, 0, sizeof( JCylinder_t ) );
00069       cyl.height       = Height;
00070       cyl.area_cache   = -1;
00071       cyl.volume_cache = -1;
00072    }
00073 
00074    inline JCylinder( const JCylinder& src )
00075      : JCircle( (const JCircle&) src )
00076    {
00077      memcpy( &cyl, &src.cyl, sizeof( JCylinder_t ) );
00078    }
00079 
00080    inline const JCircle&  operator=( const JCircle& src )
00081    {
00082      memcpy( &pt,  &src.pt,  sizeof( JPoint_t    ) );
00083      memcpy( &c,   &src.c,   sizeof( JCircle_t   ) );
00084      memcpy( &cyl, &src.cyl, sizeof( JCylinder_t ) );
00085      return *this;
00086    }
00087 
00088    /////////////////////////////////////////////////////////////////////////
00089    ///  JCylinder specific functions.                                    ///
00090    /////////////////////////////////////////////////////////////////////////
00091 
00092    // Set height of JCylinder
00093    inline const JCylinder&  setHeight( FType Height )
00094    {
00095      cyl.height = Height;
00096      return *this;
00097    }
00098 
00099    // Get height of JCylinder
00100    inline FType getHeight() const {
00101      return cyl.height;
00102    }
00103 
00104    // Calculate surface area of JCylinder
00105    inline FType area() const   //  Area = 2 ( pi ) R^2 + 2 ( pi ) R H
00106    {
00107      if ( cyl.area_cache < 0 ) {
00108        FType a = JCircle::area();
00109        FType r = JCircle::getRadius();
00110 
00111        cyl.area_cache = ( 2 * a ) + \
00112                         ( 2 * Math_PI * r * cyl.height );
00113      }
00114      return area_cache;
00115    }
00116 
00117    // Calculate volume of JCylinder
00118    inline FType volume() const   // Volume = ( pi ) R^2 H
00119    {
00120       if ( cyl.volume_cache < 0 ) {
00121         FType a = JCircle::area();
00122         cyl.volume_cache = a * cyl.height;
00123       }
00124       return cyl.volume_cache;
00125    }
00126 
00127 ////////////////////////////////////////////////////////////////////////////
00128 ///  JCircle related functions.                                           ///
00129 ////////////////////////////////////////////////////////////////////////////
00130 
00131    // Set radius
00132    inline const JCylinder& setRadius( FType r )
00133    {
00134      JCircle::setRadius( r );
00135      return *this;
00136    }
00137 
00138 ////////////////////////////////////////////////////////////////////////////
00139 ///  Point related functions.                                            ///
00140 ////////////////////////////////////////////////////////////////////////////
00141 
00142    // Set the x and y coordinates
00143    inline const JCylinder& setPoint( Type X, Type Y )
00144    {
00145       JCircle::setPoint( X, Y );
00146       return *this;
00147    }
00148 
00149    // Set coordinates (r,t)
00150    inline const JCylinder& setPolar( FType R, FType Theta )
00151    {
00152       JCircle::setPolar( R, Theta );
00153       return *this;
00154    }
00155 
00156    // Set the x and y coordinates
00157    inline const JCylinder& setCircle( Type X, Type Y, FType Radius )
00158    {
00159       JCircle::setCircle( X, Y, Radius );
00160       return *this;
00161    }
00162 
00163    inline const JCylinder& setX( Type X )
00164    {
00165       JCircle::setX( X );
00166       return *this;
00167    }
00168    
00169    inline const JCylinder& setY( Type Y )
00170    {
00171       JCircle::setY( Y );
00172       return *this;
00173    }
00174    
00175    inline const JCylinder& setR( FType R )
00176    {
00177       JCircle::setR( R );
00178       return *this;
00179    }
00180    
00181    inline const JCylinder& setAngle( FType Theta )
00182    {
00183       JCircle::setAngle( Theta );
00184       return *this;
00185    }
00186 
00187    // Output JCylinder dimensions
00188    friend ostream&  operator<<( ostream& os, const JCylinder& Cyl )
00189    {
00190      os << (const JCircle&)Cyl << "; Height = " << Cyl.cyl.height;
00191      return os;
00192    }
00193 
00194 protected:
00195   struct JCylinder_t  cyl;   
00196 };

Generated on Sun Oct 14 18:46:10 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001