Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

shape.h

00001 //
00002 // shape.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _math_isosurf_shape_h
00029 #define _math_isosurf_shape_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <math/isosurf/volume.h>
00036 #include <math/scmat/matrix.h>
00037 #include <math/scmat/vector3.h>
00038 #include <util/container/array.h>
00039 #include <util/container/avlset.h>
00040 
00046 class Shape: public Volume {
00047   public:
00048     Shape();
00049     Shape(const Ref<KeyVal>&keyval);
00050     virtual double distance_to_surface(const SCVector3&r,
00051                                        SCVector3*grad=0) const = 0;
00052     virtual int is_outside(const SCVector3&r) const;
00053     virtual ~Shape();
00054     void compute();
00055     void interpolate(const SCVector3& p1,
00056                      const SCVector3& p2,
00057                      double val,
00058                      SCVector3& result);
00059 
00060     int value_implemented() const;
00061 };
00062 
00063 
00064 
00065 class SphereShape: public Shape {
00066   private:
00067     SCVector3 _origin;
00068     double _radius;
00069   public:
00070     SphereShape(const SCVector3&,double);
00071     SphereShape(const Ref<KeyVal>&);
00072     SphereShape(const SphereShape&);
00073     ~SphereShape();
00074     void boundingbox(double minvalue, double maxvalue,
00075                      SCVector3& p1, SCVector3&p2);
00076     double radius() const { return _radius; }
00077     const SCVector3& origin() const { return _origin; }
00078     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
00079     void print(std::ostream&o=ExEnv::out()) const;
00080 
00081     // these are used to update the parameters describing the sphere
00082     double radius(double r);
00083     const SCVector3& origin(const SCVector3& o);
00084 
00085     int gradient_implemented() const;
00086 };
00087 
00088 inline double
00089 SphereShape::radius(double r)
00090 {
00091   obsolete();
00092   return _radius = r;
00093 }
00094 
00095 inline const SCVector3&
00096 SphereShape::origin(const SCVector3& o)
00097 {
00098   obsolete();
00099   _origin = o;
00100   return _origin;
00101 }
00102 
00103 class UncappedTorusHoleShape: public Shape
00104 {
00105   private:
00106     SphereShape _s1;
00107     SphereShape _s2;
00108     double _r;
00109   protected:
00110     void in_plane_sphere(const SCVector3& point,
00111                          SCVector3& origin) const;
00112     UncappedTorusHoleShape(double r,const SphereShape&,const SphereShape&);
00113   public:
00114     static UncappedTorusHoleShape*
00115     newUncappedTorusHoleShape(double r,
00116                               const SphereShape&,
00117                               const SphereShape&);
00118     inline ~UncappedTorusHoleShape() {};
00119     inline const SphereShape& sphere(int i) const { return (i?_s2:_s1); };
00120     inline const SCVector3 A() const { SCVector3 v(_s1.origin()); return v; }
00121     inline const SCVector3 B() const { SCVector3 v(_s2.origin()); return v; }
00122     inline double radius() const { return _r; };
00123     void print(std::ostream&o=ExEnv::out()) const;
00124     void boundingbox(double valuemin, double valuemax,
00125                      SCVector3& p1, SCVector3&p2);
00126 
00127     int gradient_implemented() const;
00128 };
00129 
00130 class NonreentrantUncappedTorusHoleShape: public UncappedTorusHoleShape
00131 {
00132   private:
00133     double rAP;
00134     double rBP;
00135     SCVector3 BA;
00136   public:
00137     NonreentrantUncappedTorusHoleShape(double r,
00138                                        const SphereShape&,
00139                                        const SphereShape&);
00140     ~NonreentrantUncappedTorusHoleShape();
00141     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
00142 
00143     int gradient_implemented() const;
00144 };
00145 
00146 class ReentrantUncappedTorusHoleShape: public UncappedTorusHoleShape
00147 {
00148   private:
00149     double rAP;
00150     double rBP;
00151     SCVector3 BA;
00152     SCVector3 I[2]; // the intersect points
00153   public:
00154     ReentrantUncappedTorusHoleShape(double r,
00155                                     const SphereShape&,
00156                                     const SphereShape&);
00157     ~ReentrantUncappedTorusHoleShape();
00158     int is_outside(const SCVector3&r) const;
00159     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
00160 
00161     int gradient_implemented() const;
00162 };
00163 
00164 class Uncapped5SphereExclusionShape: public Shape
00165 {
00166   private:
00167     int _solution_exists;
00168     int _reentrant;
00169     int _folded;
00170     SphereShape _s1;
00171     SphereShape _s2;
00172     SphereShape _s3;
00173     SCVector3 D[2];
00174     double BDxCDdotAD[2];
00175     SCVector3 BDxCD[2];
00176     double CDxADdotBD[2];
00177     SCVector3 CDxAD[2];
00178     double ADxBDdotCD[2];
00179     SCVector3 ADxBD[2];
00180     double _r;
00181 
00182     // these are needed for folded shapes
00183     // F1 and F2 are the two points of A, B, and C that are closed to M
00184     SCVector3 F1;
00185     SCVector3 F2;
00186     
00187     // these are needed for reentrant surfaces to compute distances
00188     SCVector3 M;   // projection of D onto ABC plane
00189     SCVector3 MD[2];  // M - D 
00190     double theta_intersect; // angle M - D - intersect_point
00191     double r_intersect; // the radius of the intersect circle
00192     int _intersects_AB;
00193     SCVector3 IABD[2][2];
00194     int _intersects_BC;
00195     SCVector3 IBCD[2][2];
00196     int _intersects_CA;
00197     SCVector3 ICAD[2][2];
00198     
00199   protected:
00200     Uncapped5SphereExclusionShape(double r,
00201                                   const SphereShape&,
00202                                   const SphereShape&,
00203                                   const SphereShape&);
00204   public:
00205     static Uncapped5SphereExclusionShape*
00206     newUncapped5SphereExclusionShape(double r,
00207                                      const SphereShape&,
00208                                      const SphereShape&,
00209                                      const SphereShape&);
00210     inline ~Uncapped5SphereExclusionShape() {};
00211     inline const SCVector3 A() const { SCVector3 v(_s1.origin()); return v; }
00212     inline const SCVector3 B() const { SCVector3 v(_s2.origin()); return v; }
00213     inline const SCVector3 C() const { SCVector3 v(_s3.origin()); return v; }
00214     inline double rA() const { return _s1.radius(); };
00215     inline double rB() const { return _s2.radius(); };
00216     inline double rC() const { return _s3.radius(); };
00217     inline double r() const { return _r; };
00218     inline int solution_exists() const { return _solution_exists; };
00219     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
00220     int is_outside(const SCVector3&) const;
00221     void boundingbox(double valuemin, double valuemax,
00222                      SCVector3& p1, SCVector3&p2);
00223 
00224     int gradient_implemented() const;
00225 };
00226 
00228 class UnionShape: public Shape {
00229   protected:
00230     AVLSet<Ref<Shape> > _shapes;
00231   public:
00232     void add_shape(Ref<Shape>);
00233     UnionShape();
00234     ~UnionShape();
00235     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
00236     int is_outside(const SCVector3&r) const;
00237     void boundingbox(double valuemin, double valuemax,
00238                      SCVector3& p1, SCVector3& p2);
00239 
00240     int gradient_implemented() const;
00241 };
00242 
00243 
00244 #endif
00245 
00246 // Local Variables:
00247 // mode: c++
00248 // c-file-style: "CLJ"
00249 // End:

Generated at Thu Oct 4 18:08:47 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.