- Main Page
- Related Pages
- Classes
- Files

# 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 <set>
    00036
    00037 #include <math/isosurf/volume.h>
    00038 #include <math/scmat/matrix.h>
    00039 #include <math/scmat/vector3.h>
    00040
    00041 namespace sc {
    00042
    00048 class Shape: public Volume {
    00049   public:
    00050     Shape();
    00051     Shape(const Ref<KeyVal>&keyval);
    00052     virtual double distance_to_surface(const SCVector3&r,
    00053                                        SCVector3*grad=0) const = 0;
    00054     virtual int is_outside(const SCVector3&r) const;
    00055     virtual ~Shape();
    00056     void compute();
    00057     void interpolate(const SCVector3& p1,
    00058                      const SCVector3& p2,
    00059                      double val,
    00060                      SCVector3& result);
    00061
    00062     int value_implemented() const;
    00063 };
    00064
    00065
    00066
    00067 class SphereShape: public Shape {
    00068   private:
    00069     SCVector3 _origin;
    00070     double _radius;
    00071   public:
    00072     SphereShape(const SCVector3&,double);
    00073     SphereShape(const Ref<KeyVal>&);
    00074     SphereShape(const SphereShape&);
    00075     ~SphereShape();
    00076     void boundingbox(double minvalue, double maxvalue,
    00077                      SCVector3& p1, SCVector3&p2);
    00078     double radius() const { return _radius; }
    00079     const SCVector3& origin() const { return _origin; }
    00080     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
    00081     void print(std::ostream&o=ExEnv::out0()) const;
    00082
    00083     // these are used to update the parameters describing the sphere
    00084     double radius(double r);
    00085     const SCVector3& origin(const SCVector3& o);
    00086
    00087     int gradient_implemented() const;
    00088 };
    00089
    00090 inline double
    00091 SphereShape::radius(double r)
    00092 {
    00093   obsolete();
    00094   return _radius = r;
    00095 }
    00096
    00097 inline const SCVector3&
    00098 SphereShape::origin(const SCVector3& o)
    00099 {
    00100   obsolete();
    00101   _origin = o;
    00102   return _origin;
    00103 }
    00104
    00105 class UncappedTorusHoleShape: public Shape
    00106 {
    00107   private:
    00108     SphereShape _s1;
    00109     SphereShape _s2;
    00110     double _r;
    00111   protected:
    00112     void in_plane_sphere(const SCVector3& point,
    00113                          SCVector3& origin) const;
    00114     UncappedTorusHoleShape(double r,const SphereShape&,const SphereShape&);
    00115   public:
    00116     static UncappedTorusHoleShape*
    00117     newUncappedTorusHoleShape(double r,
    00118                               const SphereShape&,
    00119                               const SphereShape&);
    00120     inline ~UncappedTorusHoleShape() {};
    00121     inline const SphereShape& sphere(int i) const { return (i?_s2:_s1); };
    00122     inline const SCVector3 A() const { SCVector3 v(_s1.origin()); return v; }
    00123     inline const SCVector3 B() const { SCVector3 v(_s2.origin()); return v; }
    00124     inline double radius() const { return _r; };
    00125     void print(std::ostream&o=ExEnv::out0()) const;
    00126     void boundingbox(double valuemin, double valuemax,
    00127                      SCVector3& p1, SCVector3&p2);
    00128
    00129     int gradient_implemented() const;
    00130 };
    00131
    00132 class NonreentrantUncappedTorusHoleShape: public UncappedTorusHoleShape
    00133 {
    00134   private:
    00135     double rAP;
    00136     double rBP;
    00137     SCVector3 BA;
    00138   public:
    00139     NonreentrantUncappedTorusHoleShape(double r,
    00140                                        const SphereShape&,
    00141                                        const SphereShape&);
    00142     ~NonreentrantUncappedTorusHoleShape();
    00143     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
    00144
    00145     int gradient_implemented() const;
    00146 };
    00147
    00148 class ReentrantUncappedTorusHoleShape: public UncappedTorusHoleShape
    00149 {
    00150   private:
    00151     double rAP;
    00152     double rBP;
    00153     SCVector3 BA;
    00154     SCVector3 I[2]; // the intersect points
    00155   public:
    00156     ReentrantUncappedTorusHoleShape(double r,
    00157                                     const SphereShape&,
    00158                                     const SphereShape&);
    00159     ~ReentrantUncappedTorusHoleShape();
    00160     int is_outside(const SCVector3&r) const;
    00161     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
    00162
    00163     int gradient_implemented() const;
    00164 };
    00165
    00166 class Uncapped5SphereExclusionShape: public Shape
    00167 {
    00168   private:
    00169     int _solution_exists;
    00170     int _reentrant;
    00171     int _folded;
    00172     SphereShape _s1;
    00173     SphereShape _s2;
    00174     SphereShape _s3;
    00175     SCVector3 D[2];
    00176     double BDxCDdotAD[2];
    00177     SCVector3 BDxCD[2];
    00178     double CDxADdotBD[2];
    00179     SCVector3 CDxAD[2];
    00180     double ADxBDdotCD[2];
    00181     SCVector3 ADxBD[2];
    00182     double _r;
    00183
    00184     // these are needed for folded shapes
    00185     // F1 and F2 are the two points of A, B, and C that are closed to M
    00186     SCVector3 F1;
    00187     SCVector3 F2;
    00188
    00189     // these are needed for reentrant surfaces to compute distances
    00190     SCVector3 M;   // projection of D onto ABC plane
    00191     SCVector3 MD[2];  // M - D
    00192     double theta_intersect; // angle M - D - intersect_point
    00193     double r_intersect; // the radius of the intersect circle
    00194     int _intersects_AB;
    00195     SCVector3 IABD[2][2];
    00196     int _intersects_BC;
    00197     SCVector3 IBCD[2][2];
    00198     int _intersects_CA;
    00199     SCVector3 ICAD[2][2];
    00200
    00201   protected:
    00202     Uncapped5SphereExclusionShape(double r,
    00203                                   const SphereShape&,
    00204                                   const SphereShape&,
    00205                                   const SphereShape&);
    00206   public:
    00207     static Uncapped5SphereExclusionShape*
    00208     newUncapped5SphereExclusionShape(double r,
    00209                                      const SphereShape&,
    00210                                      const SphereShape&,
    00211                                      const SphereShape&);
    00212     inline ~Uncapped5SphereExclusionShape() {};
    00213     inline const SCVector3 A() const { SCVector3 v(_s1.origin()); return v; }
    00214     inline const SCVector3 B() const { SCVector3 v(_s2.origin()); return v; }
    00215     inline const SCVector3 C() const { SCVector3 v(_s3.origin()); return v; }
    00216     inline double rA() const { return _s1.radius(); };
    00217     inline double rB() const { return _s2.radius(); };
    00218     inline double rC() const { return _s3.radius(); };
    00219     inline double r() const { return _r; };
    00220     inline int solution_exists() const { return _solution_exists; };
    00221     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
    00222     int is_outside(const SCVector3&) const;
    00223     void boundingbox(double valuemin, double valuemax,
    00224                      SCVector3& p1, SCVector3&p2);
    00225
    00226     int gradient_implemented() const;
    00227 };
    00228
    00230 class UnionShape: public Shape {
    00231   protected:
    00232     std::set<Ref<Shape> > _shapes;
    00233   public:
    00234     void add_shape(Ref<Shape>);
    00235     UnionShape();
    00236     ~UnionShape();
    00237     double distance_to_surface(const SCVector3&r,SCVector3*grad=0) const;
    00238     int is_outside(const SCVector3&r) const;
    00239     void boundingbox(double valuemin, double valuemax,
    00240                      SCVector3& p1, SCVector3& p2);
    00241
    00242     int gradient_implemented() const;
    00243 };
    00244
    00245 }
    00246
    00247 #endif
    00248
    00249 // Local Variables:
    00250 // mode: c++
    00251 // c-file-style: "CLJ"
    00252 // End: