BALL  1.4.1
solventExcludedSurface.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 #ifndef BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H
00006 #define BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H
00007 
00008 #ifndef BALL_STRUCTURE_SESEDGE_H
00009 # include <BALL/STRUCTURE/SESEdge.h>
00010 #endif
00011 
00012 #ifndef BALL_STRUCTURE_SESFACE_H
00013 # include <BALL/STRUCTURE/SESFace.h>
00014 #endif
00015 
00016 #ifndef BALL_STRUCTURE_SESVERTEX_H
00017 # include <BALL/STRUCTURE/SESVertex.h>
00018 #endif
00019 
00020 #ifndef BALL_STRUCTURE_REDUCEDSURFACE_H
00021 # include <BALL/STRUCTURE/reducedSurface.h>
00022 #endif
00023 
00024 #ifndef BALL_MATHS_ANGLE_H
00025 # include <BALL/MATHS/angle.h>
00026 #endif
00027 
00028 #ifndef BALL_MATHS_CIRCLE3_H
00029 # include <BALL/MATHS/circle3.h>
00030 #endif
00031 
00032 #ifndef BALL_MATHS_SPHERE3_H
00033 # include <BALL/MATHS/sphere3.h>
00034 #endif
00035 
00036 #ifndef BALL_MATHS_VECTOR3_H
00037 # include <BALL/MATHS/vector3.h>
00038 #endif
00039 
00040 #ifndef BALL_MATHS_VECTOR4_H
00041 # include <BALL/MATHS/vector4.h>
00042 #endif
00043 
00044 #ifndef BALL_DATATYPE_HASHGRID_H
00045 # include <BALL/DATATYPE/hashGrid.h>
00046 #endif
00047 
00048 #ifndef BALL_DATATYPE_HASHMAP_H
00049 # include <BALL/DATATYPE/hashMap.h>
00050 #endif
00051 
00052 #include <vector>
00053 #include <list>
00054 
00055 
00056 namespace BALL
00057 {
00058   class SESComputer;
00059   class SESSingularityCleaner;
00060   class TriangulatedSES;
00061   class SESTriangulator;
00062 
00066   class BALL_EXPORT SolventExcludedSurface
00067   {
00068     public:
00069 
00078     friend class SESComputer;
00079     friend class SESSingularityCleaner;
00080     friend class TriangulatedSES;
00081     friend class SESTriangulator;
00082 
00083     BALL_CREATE(SolventExcludedSurface)
00084 
00085     
00088 
00089     typedef std::vector<SESVertex*>::iterator
00090             VertexIterator;
00091     typedef std::vector<SESVertex*>::const_iterator
00092             ConstVertexIterator;
00093     typedef std::vector<SESEdge*>::iterator
00094             EdgeIterator;
00095     typedef std::vector<SESEdge*>::const_iterator
00096             ConstEdgeIterator;
00097     typedef std::list<SESEdge*>::iterator
00098             SingularEdgeIterator;
00099     typedef std::list<SESEdge*>::const_iterator
00100             ConstSingularEdgeIterator;
00101     typedef std::vector<SESFace*>::iterator
00102             ContactFaceIterator;
00103     typedef std::vector<SESFace*>::const_iterator
00104             ConstContactFaceIterator;
00105     typedef std::vector<SESFace*>::iterator
00106             SphericFaceIterator;
00107     typedef std::vector<SESFace*>::const_iterator
00108             ConstSphericFaceIterator;
00109     typedef std::vector<SESFace*>::iterator
00110             ToricFaceIterator;
00111     typedef std::vector<SESFace*>::const_iterator
00112             ConstToricFaceIterator;
00113 
00115 
00118 
00122     SolventExcludedSurface();
00123 
00129     SolventExcludedSurface
00130         (const SolventExcludedSurface& ses, bool = false);
00131 
00134     SolventExcludedSurface(ReducedSurface* reduced_surface);
00135 
00139     virtual ~SolventExcludedSurface()
00140       ;
00141 
00143 
00146 
00147     void clear();
00148 
00149     void clean(const double& density);
00150 
00153     void compute()
00154       throw(Exception::GeneralException);
00155 
00156     void splitSphericFaces()
00157       ;
00158 
00159     bool check()
00160       ;
00161 
00163 
00166 
00167     VertexIterator beginVertex()
00168       ;
00169     ConstVertexIterator beginVertex() const
00170       ;
00171     VertexIterator endVertex()
00172       ;
00173     ConstVertexIterator endVertex() const
00174       ;
00175 
00176     EdgeIterator beginEdge()
00177       ;
00178     ConstEdgeIterator beginEdge() const
00179       ;
00180     EdgeIterator endEdge()
00181       ;
00182     ConstEdgeIterator endEdge() const
00183       ;
00184 
00185     SingularEdgeIterator beginSingularEdge()
00186       ;
00187     ConstSingularEdgeIterator beginSingularEdge() const
00188       ;
00189     SingularEdgeIterator endSingularEdge()
00190       ;
00191     ConstSingularEdgeIterator endSingularEdge() const
00192       ;
00193 
00194     ContactFaceIterator beginContactFace()
00195       ;
00196     ConstContactFaceIterator beginContactFace() const
00197       ;
00198     ContactFaceIterator endContactFace()
00199       ;
00200     ConstContactFaceIterator endContactFace() const
00201       ;
00202 
00203     SphericFaceIterator beginSphericFace()
00204       ;
00205     ConstSphericFaceIterator beginSphericFace() const
00206       ;
00207     SphericFaceIterator endSphericFace()
00208       ;
00209     ConstSphericFaceIterator endSphericFace() const
00210       ;
00211 
00212     ToricFaceIterator beginToricFace()
00213       ;
00214     ConstToricFaceIterator beginToricFace() const
00215       ;
00216     ToricFaceIterator endToricFace()
00217       ;
00218     ConstToricFaceIterator endToricFace() const
00219       ;
00220 
00222 
00223     private:
00224 
00225     void splitSphericFace(Position i)
00226       ;
00227 
00228     void deleteSmallToricFace(SESFace* face)
00229       ;
00230 
00231     void deleteSmallSingularToricFace(SESFace* face)
00232       ;
00233 
00234     bool cleanToricFace(SESFace* face, const double& sqrt_density)
00235       ;
00236 
00237     bool cleanSingularToricFace(SESFace* face, const double& sqrt_density)
00238       ;
00239 
00240     void cleanVertices()
00241       ;
00242 
00243     void cleanEdges()
00244       ;
00245 
00246     void cleanContactFaces()
00247       ;
00248 
00249     void cleanToricFaces()
00250       ;
00251 
00252     void cleanSphericFaces()
00253       ;
00254 
00255 
00256     protected:
00257 
00258     /*_ the number of vertices of the solvent exluded surface
00259     */
00260     Position number_of_vertices_;
00261     /*_ the vertices of the solvent exluded surface
00262     */
00263     ::std::vector<SESVertex*> vertices_;
00264     /*_ the number of edges of the solvent exluded surface
00265     */
00266     Position number_of_edges_;
00267     /*_ the edges of the solvent exluded surface
00268     */
00269     ::std::vector<SESEdge*> edges_;
00270     /*_ the number of singular edges of the solvent exluded surface
00271     */
00272     Position number_of_singular_edges_;
00273     /*_ the singular edges of the solvent exluded surface
00274     */
00275     ::std::list<SESEdge*> singular_edges_;
00276     /*_ the number of contact faces of the solvent exluded surface
00277     */
00278     Position number_of_contact_faces_;
00279     /*_ the contact faces of the solvent exluded surface
00280     */
00281     ::std::vector<SESFace*> contact_faces_;
00282     /*_ the number of toric reentrant faces of the solvent exluded surface
00283     */
00284     Position number_of_toric_faces_;
00285     /*_ the toric reentrant faces of the solvent exluded surface
00286     */
00287     ::std::vector<SESFace*> toric_faces_;
00288     /*_ the number of spheric reentrant faces of the solvent exluded surface
00289     */
00290     Position number_of_spheric_faces_;
00291     /*_ the spheric reentrant faces of the solvent exluded surface
00292     */
00293     ::std::vector<SESFace*> spheric_faces_;
00294     /*_ the corresponding reduced surface
00295     */
00296     ReducedSurface* reduced_surface_;
00297 
00298   };
00299 
00300 
00304 
00307   BALL_EXPORT std::ostream& operator <<
00308       (std::ostream& s, const SolventExcludedSurface& ses);
00309 
00311 
00312 
00313 
00317   class BALL_EXPORT SESComputer
00318   {
00319     public:
00320 
00321     BALL_CREATE(SESComputer)
00322 
00323     
00326 
00330     SESComputer()
00331       ;
00332 
00335     SESComputer(SolventExcludedSurface* ses)
00336       ;
00337 
00341     virtual ~SESComputer()
00342       ;
00343 
00345 
00348 
00351     void run()
00352       throw(Exception::GeneralException);
00353 
00355 
00356     private:
00357 
00358     /*_ @name SES computation (private)
00359     */
00361 
00362     void preProcessing()
00363       ;
00364 
00365     void get()
00366       ;
00367 
00368     void createSphericFace(Position j)
00369       ;
00370 
00371     SESVertex* createVertex
00372       (const TVector3<double>& probe_center,
00373        Index index)
00374       ;
00375 
00376     void pushVertex
00377       (SESFace* face,
00378        const TSphere3<double>& probe,
00379        RSVertex* rsvertex)
00380       ;
00381 
00382     SESEdge* createConcaveEdge
00383       (SESFace* spheric_face,
00384        Position p1,
00385        Position p2,
00386        Index index,
00387        const double& radius_of_probe)
00388       ;
00389 
00390     void pushConcaveEdge
00391       (SESFace* face,
00392        Position p1,
00393        Position p2,
00394        const double& radius_of_probe)
00395       ;
00396 
00397     SESEdge* createConvexEdge
00398       (SESFace* toric_face,
00399        RSVertex* rsvertex)
00400       ;
00401 
00402     void createToricFace(Position i)
00403       ;
00404 
00405     void treatSingularToricFace(Position i)
00406       ;
00407 
00408     void createFreeToricFace(Position i)
00409       ;
00410 
00411     SESVertex* createSingularVertex
00412         (Position ip,
00413          const TVector3<double>& dir,
00414          SESFace* face0,
00415          SESFace* face1,
00416          SESFace* face2,
00417          SESEdge* edge0,
00418          SESEdge* edge1,
00419          SESEdge* edge2)
00420       ;
00421 
00422     void updateEdge
00423         (SESEdge*   edge,
00424          SESVertex* vertex1,
00425          SESVertex* vertex2,
00426          bool           is_new)
00427       ;
00428 
00429     void getPoint
00430       (const TVector3<double>& p1,
00431        const TVector3<double>& p2,
00432        const double&            dist,
00433        TVector3<double>&        result);
00434 
00435     Index vertexExists(const TVector3<double>& point);
00436 
00438 
00439 
00440     protected:
00441 
00442     /*_ a pointer to the solvent excluded surface to compute
00443     */
00444     SolventExcludedSurface* ses_;
00445     /*_ a HashGrid to store and find the vertices in an efficient way
00446     */
00447     HashGrid3<Index> vertex_grid_;
00448   };
00449 
00450 
00451 
00452 
00456   class BALL_EXPORT SESSingularityCleaner
00457   {
00458     public:
00459 
00460     BALL_CREATE(SESSingularityCleaner)
00461 
00462     typedef std::pair< std::pair<TAngle<double>,Index>,TVector3<double> > Intersection;
00463 
00464     struct ProbeIntersection
00465     {
00466       TVector3<double> point[2];
00467     };
00468 
00469     friend class SESComputer;
00470 
00474 
00478     SESSingularityCleaner()
00479       ;
00480 
00483     SESSingularityCleaner
00484         (SolventExcludedSurface*  ses,
00485          HashGrid3<Index>*        vertex_grid_)
00486       ;
00487 
00491     virtual ~SESSingularityCleaner()
00492       ;
00493 
00495 
00498 
00501     bool run()
00502       throw(Exception::GeneralException);
00503 
00505 
00506     private:
00507 
00511 
00512     Index vertexExists(TVector3<double> point)
00513       ;
00514 
00515     void treatSingularities()
00516       ;
00517 
00518     void getSingularFaces(std::list<SESFace*>& faces)
00519       ;
00520 
00521     bool treatFirstCategory()
00522       ;
00523 
00524     void treatSecondCategory()
00525       ;
00526 
00527     void getFirstCategoryFaces(std::list<SESFace*>& first_category_faces)
00528       ;
00529 
00530     void noCut(SESFace* face1, SESFace* face2)
00531       ;
00532 
00533     void twoCuts(SESFace* face1, SESFace* face2)
00534       ;
00535 
00536     void treatSingularEdge
00537       (SESEdge*               edge,
00538        HashGrid3<Position>&   grid,
00539        ::std::list<SESEdge*>& deletable_edges)
00540       ;
00541 
00542     void getIntersectionsOfSingularEdge
00543       (SESEdge*                 edge,
00544        const TAngle<double>&              phi,
00545        HashGrid3<Position>&     grid,
00546        std::list<Intersection>& intersections)
00547       ;
00548 
00549     bool getIntersectionPointsAndAngles
00550       (const TCircle3<double>&  circle,
00551        const TVector3<double>&  point,
00552        Position       index1,
00553        Position       index2,
00554        Position       probe_index,
00555        TAngle<double>&          phi1,
00556        TVector3<double>&        point1,
00557        TAngle<double>&          phi2,
00558        TVector3<double>&        point2)
00559       ;
00560 
00561     bool isIntersection
00562        (const TAngle<double>&  min_phi,
00563         const TAngle<double>&  max_phi,
00564         const TAngle<double>&  phi,
00565         const TVector3<double>& middle,
00566         const TSphere3<double>& probe)
00567       ;
00568 
00569     void buildEndEdges
00570       (SESEdge*                       edge,
00571        const std::list<Intersection>& min,
00572        const std::list<Intersection>& max,
00573        SESVertex*&                    vertex1,
00574        SESVertex*&                    vertex2,
00575        Index&                         actual_min,
00576        Index&                         actual_max)
00577       ;
00578 
00579     void buildEdge
00580       (SESEdge*               edge,
00581        Index                  face1,
00582        Index&                 face2,
00583        Index                  end,
00584        SESVertex*&            vertex,
00585        const HashSet<Index>&  indices,
00586        bool                   minimum);
00587 
00588     void getExtrema
00589         (const std::list<Intersection>& intersections,
00590          std::list<Intersection>& min,
00591          std::list<Intersection>& max);
00592 
00593     void buildEndEdge
00594       (SESEdge*                       edge,
00595        const std::list<Intersection>& extrema,
00596        SESVertex*&                    vertex,
00597        Index&                         actual_extremum,
00598        bool                           min);
00599 
00600     bool probeIntersection
00601        (Index    face1,
00602         Index    face2,
00603         Index    face3,
00604         TVector3<double>& point1,
00605         TVector3<double>& point2);
00606 
00607     void sort
00608         (SESFace* face1,
00609          SESFace* face2,
00610          std::vector<SESEdge*>& sesedge1,
00611          std::vector<SESEdge*>& sesedge2,
00612          std::vector<SESVertex*>& sesvertex1,
00613          std::vector<SESVertex*>& sesvertex2);
00614 
00615     void sort
00616        (Index   u1, Index   u2, Index   u3,
00617         Index&  s1, Index&  s2, Index&  s3);
00618 
00620 
00621 
00622     protected:
00623 
00624     /*_ a pointer to the solvent excluded surface to compute
00625     */
00626     SolventExcludedSurface* ses_;
00627     /*_ a pointer to a HashGrid to store and find the vertices
00628         in an efficient way
00629     */
00630     HashGrid3<Index>* vertex_grid_;
00631     /*_ for each triple of probe spheres its intersections
00632     */
00633     HashMap< Position,
00634              HashMap< Position,
00635                       HashMap< Position,
00636                                ProbeIntersection*
00637                              >
00638                     >
00639            > probe_intersections_;
00640 
00641   };
00642 
00643    
00644 } // namespace BALL
00645 
00646 #endif  // BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines