00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_STRUCTURE_REDUCEDSURFACE_H
00008 #define BALL_STRUCTURE_REDUCEDSURFACE_H
00009
00010 #ifndef BALL_MATHC_COMMON_H
00011 # include <BALL/MATHS/common.h>
00012 #endif
00013
00014 #ifndef BALL_MATHS_SIMPLEBOX3_H
00015 # include <BALL/MATHS/simpleBox3.h>
00016 #endif
00017
00018 #ifndef BALL_MATHS_CIRCLE3_H
00019 # include <BALL/MATHS/circle3.h>
00020 #endif
00021
00022 #ifndef BALL_MATHS_SPHERE_H
00023 # include <BALL/MATHS/sphere3.h>
00024 #endif
00025
00026 #ifndef BALL_MATHS_VECTOR3_H
00027 # include <BALL/MATHS/vector3.h>
00028 #endif
00029
00030 #ifndef BALL_DATATYPE_HASHSET_H
00031 # include <BALL/DATATYPE/hashMap.h>
00032 #endif
00033
00034 #ifndef BALL_DATATYPE_HASHSET_H
00035 # include <BALL/DATATYPE/hashSet.h>
00036 #endif
00037
00038 #ifndef BALL_COMMON_EXCEPTION_H
00039 # include <BALL/COMMON/exception.h>
00040 #endif
00041
00042 #ifndef BALL_STRUCTURE_RSEDGE_H
00043 # include <BALL/STRUCTURE/RSEdge.h>
00044 #endif
00045
00046 #ifndef BALL_STRUCTURE_RSFACE_H
00047 # include <BALL/STRUCTURE/RSFace.h>
00048 #endif
00049
00050 #ifndef BALL_STRUCTURE_RSVERTEX_H
00051 # include <BALL/STRUCTURE/RSVertex.h>
00052 #endif
00053
00054 #include <list>
00055 #include <vector>
00056
00057
00058 namespace BALL
00059 {
00060 class RSComputer;
00061 class SolventExcludedSurface;
00062 class SESComputer;
00063 class SESSingularityCleaner;
00064 class TriangulatedSES;
00065 class SolventAccessibleSurface;
00066 class TriangulatedSAS;
00067 class SESTriangulator;
00068
00072 class BALL_EXPORT ReducedSurface
00073 {
00074 public:
00075
00088 friend class RSComputer;
00089 friend class SolventExcludedSurface;
00090 friend class SESComputer;
00091 friend class SESSingularityCleaner;
00092 friend class SolventAccessibleSurface;
00093 friend class TriangulatedSES;
00094 friend class TriangulatedSAS;
00095 friend class SESTriangulator;
00096
00097 BALL_CREATE(ReducedSurface)
00098
00099
00102
00107 ReducedSurface()
00108 ;
00109
00114 ReducedSurface(const ReducedSurface& reduced_surface, bool = true)
00115 ;
00116
00120 ReducedSurface
00121 (const std::vector< TSphere3<double> >& spheres,
00122 const double& probe_radius)
00123 ;
00124
00127 virtual ~ReducedSurface()
00128 ;
00129
00131
00134
00138 void operator=(const ReducedSurface& reduced_surface)
00139 ;
00140
00144 void set(const ReducedSurface& reduced_surface)
00145 ;
00146
00149 void clear()
00150 ;
00151
00154 void clean()
00155 ;
00156
00158
00161
00165 Size numberOfAtoms() const
00166 ;
00167
00171 Size numberOfVertices() const
00172 ;
00173
00177 Size numberOfEdges() const
00178 ;
00179
00183 Size numberOfFaces() const
00184 ;
00185
00189 double getProbeRadius() const
00190 ;
00191
00196 TSphere3<double> getSphere(Position i) const
00197 throw(Exception::IndexOverflow);
00198
00203 RSVertex* getVertex(Position i) const
00204 throw(Exception::IndexOverflow);
00205
00210 RSEdge* getEdge(Position i) const
00211 throw(Exception::IndexOverflow);
00212
00217 RSFace* getFace(Position i) const
00218 throw(Exception::IndexOverflow);
00219
00223 void insert(RSVertex* rsvertex)
00224 ;
00225
00229 void insert(RSEdge* rsedge)
00230 ;
00231
00235 void insert(RSFace* rsface)
00236 ;
00237
00241 double getMaximalRadius() const
00242 ;
00243
00247 TSimpleBox3<double> getBoundingBox() const
00248 ;
00249
00254 void deleteSimilarFaces(RSFace* face1, RSFace* face2)
00255 ;
00256
00265 bool getAngle
00266 (RSFace* face1,
00267 RSFace* face2,
00268 RSVertex* vertex1,
00269 RSVertex* vertex2,
00270 TAngle<double>& angle,
00271 bool check = false) const
00272 ;
00273
00276 void compute()
00277 throw(Exception::GeneralException,
00278 Exception::DivisionByZero,
00279 Exception::IndexOverflow);
00280
00282
00283 private:
00284
00285
00286
00287 bool canBeCopied(const ReducedSurface& reduced_surface)
00288 ;
00289
00290
00291
00292 void copy(const ReducedSurface& reduced_surface)
00293 ;
00294
00295
00296
00297 void correctEdges
00298 (RSFace* face1,
00299 RSFace* face2,
00300 RSEdge* edge1,
00301 RSEdge* edge2)
00302 ;
00303
00304
00305
00306 void joinVertices
00307 (RSFace* face1,
00308 RSFace* face2,
00309 RSVertex* vertex1,
00310 RSVertex* vertex2)
00311 ;
00312
00313
00314
00315 void findSimilarVertices
00316 (RSFace* face1,
00317 RSFace* face2,
00318 std::vector<RSVertex*>& rsvertex1,
00319 std::vector<RSVertex*>& rsvertex2)
00320 ;
00321
00322
00323
00324 void findSimilarEdges
00325 (RSFace* face1,
00326 RSFace* face2,
00327 std::vector<RSEdge*>& rsedge1,
00328 std::vector<RSEdge*>& rsedge2)
00329 ;
00330
00331 protected:
00332
00333
00334
00335 Size number_of_atoms_;
00336
00337
00338 std::vector< TSphere3<double> > atom_;
00339
00340
00341 double probe_radius_;
00342
00343
00344 Size number_of_vertices_;
00345
00346
00347 std::vector< RSVertex* > vertices_;
00348
00349
00350 Size number_of_edges_;
00351
00352
00353 std::vector< RSEdge* > edges_;
00354
00355
00356 Size number_of_faces_;
00357
00358
00359 std::vector< RSFace* > faces_;
00360
00361
00362 double r_max_;
00363
00364
00365 TSimpleBox3<double> bounding_box_;
00366
00367 };
00368
00369
00373
00377 BALL_EXPORT std::ostream& operator << (std::ostream& s, const ReducedSurface& rs);
00378
00380
00381
00382
00383
00387 class BALL_EXPORT RSComputer
00388 {
00389 public:
00390
00391 BALL_CREATE(RSComputer)
00392
00393
00396
00402 enum ProbeStatus
00403 {
00404 STATUS_OK = 0,
00405 STATUS_NOT_OK = 1,
00406 STATUS_NOT_TESTED = 2
00407 };
00408
00414 enum AtomStatus
00415 {
00416 STATUS_ON_SURFACE = 0,
00417 STATUS_INSIDE = 1,
00418 STATUS_UNKNOWN = 2
00419 };
00421
00422 struct ProbePosition
00423 {
00424 ProbeStatus status[2];
00425 TVector3<double> point[2];
00426 };
00427
00431
00436 RSComputer()
00437 ;
00438
00441 RSComputer(ReducedSurface* rs)
00442 ;
00443
00446 virtual ~RSComputer()
00447 ;
00448
00450
00453
00456 void run()
00457 throw(Exception::GeneralException,
00458 Exception::DivisionByZero,
00459 Exception::IndexOverflow);
00460
00462
00463
00464 private:
00465
00466
00467
00469
00470
00471
00472 void preProcessing()
00473 ;
00474
00475
00476
00477 void getRSComponent()
00478 throw(Exception::GeneralException,
00479 Exception::DivisionByZero,
00480 Exception::IndexOverflow);
00481
00482
00483
00484
00485 bool treatFace(RSFace* face)
00486 throw(Exception::GeneralException,
00487 Exception::DivisionByZero,
00488 Exception::IndexOverflow);
00489
00490
00491
00492
00493 bool treatEdge(RSEdge* edge)
00494 throw(Exception::GeneralException,
00495 Exception::DivisionByZero,
00496 Exception::IndexOverflow);
00497
00498
00499
00500
00501
00502
00503 void correct(Index atom)
00504 ;
00505
00506
00507
00508 void extendComponent()
00509 throw(Exception::GeneralException,
00510 Exception::DivisionByZero,
00511 Exception::IndexOverflow);
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 Index thirdAtom
00529 (RSVertex* vertex1,
00530 RSVertex* vertex2,
00531 RSFace* face,
00532 TSphere3<double>& probe,
00533 TAngle<double>& phi)
00534 throw(Exception::GeneralException,
00535 Exception::DivisionByZero,
00536 Exception::IndexOverflow);
00537
00539
00540
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554 Position getStartPosition()
00555 throw(Exception::DivisionByZero);
00556
00558
00559
00561
00562
00563
00564
00565
00566 RSFace* findFirstFace()
00567 throw(Exception::DivisionByZero);
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 RSFace* findFace(Position direction, Position extrem)
00579 throw(Exception::DivisionByZero);
00580
00582
00583
00585
00586
00587
00588
00589
00590 RSEdge* findFirstEdge()
00591 ;
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602 RSEdge* findEdge(Position direction, Position extrem)
00603 ;
00604
00606
00607
00609
00610
00611
00612
00613
00614 RSVertex* findFirstVertex()
00615 ;
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 Index findFirstAtom(Position direction, Position extrem)
00626 ;
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 Index findSecondAtom(Index atom, Position direction, Position extrem)
00638 ;
00639
00640
00641
00642
00643
00644
00645
00646
00647 void findThirdAtom
00648 (Index atom1,
00649 Index atom2,
00650 const std::list<Index>& third,
00651 std::list< std::pair< Index,TSphere3<double> > >& atoms)
00652 ;
00653
00655
00656
00658
00659
00660
00661
00662
00663
00664
00665
00666 void neighboursOfTwoAtoms(Index atom1, Index atom2)
00667 ;
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 void neighboursOfThreeAtoms
00678 (Index atom1,
00679 Index atom2,
00680 Index atom3,
00681 std::list<Index>& output_list)
00682 ;
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 double getCircleExtremum
00695 (const TCircle3<double>& circle,
00696 Position direction,
00697 Position extrem)
00698 ;
00699
00701
00702
00704
00705
00706
00707
00708
00709
00710
00711 RSEdge* createFreeEdge(RSVertex* vertex1, RSVertex* vertex2)
00712 ;
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725 bool getCircles
00726 (Index atom1,
00727 Index atom2,
00728 TCircle3<double>& circle1,
00729 TCircle3<double>& circle2,
00730 TCircle3<double>& circle3)
00731 ;
00732
00733
00734
00735
00736
00737
00738
00739
00740 TVector3<double> getFaceNormal
00741 (const TSphere3<double>& atom1,
00742 const TSphere3<double>& atom2,
00743 const TSphere3<double>& atom3,
00744 const TSphere3<double>& probe)
00745 ;
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757 void updateFaceAndEdges
00758 (RSVertex* v1,
00759 RSVertex* v2,
00760 RSVertex* v3,
00761 RSEdge* e1,
00762 RSEdge* e2,
00763 RSEdge* e3,
00764 RSFace* f,
00765 const TSphere3<double>& probe)
00766 ;
00767
00768
00769
00770
00771
00772 RSFace* faceExists
00773 (RSFace* face,
00774 const std::list< RSVertex* >& vertices)
00775 ;
00776
00778
00779
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791 bool centerOfProbe
00792 (Index a1,
00793 Index a2,
00794 Index a3,
00795 TVector3<double>& c1,
00796 TVector3<double>& c2)
00797 ;
00798
00799
00800
00801
00802
00803
00804 bool checkProbe
00805 (const TSphere3<double>& probe,
00806 Index atom1,
00807 Index atom2,
00808 Index atom3)
00809 ;
00810
00811
00812
00813 void correctProbePosition(Position atom)
00814 ;
00815
00816
00817
00818 void sort
00819 (Index u1, Index u2, Index u3,
00820 Index& s1, Index& s2, Index& s3)
00821 ;
00822
00823
00824
00825 void correctProbePosition(Position a1, Position a2, Position a3)
00826 ;
00827
00828
00829
00830 void insert(RSVertex* vertex)
00831 ;
00832
00833
00834
00835 void insert(RSEdge* edge)
00836 ;
00837
00838
00839
00840 void insert(RSFace* face)
00841 ;
00842
00844
00845 protected:
00846
00847
00848
00849 ReducedSurface* rs_;
00850
00851
00852 std::vector< std::list<Index> > neighbours_;
00853
00854
00855 std::vector< AtomStatus > atom_status_;
00856
00857
00858 HashMap< Position,
00859 HashMap< Position,
00860 std::list<Index>
00861 >
00862 > neighbours_of_two_;
00863
00864
00865 HashMap< Position,
00866 HashMap< Position,
00867 HashMap< Position,
00868 ProbePosition*
00869 >
00870 >
00871 > probe_positions_;
00872
00873
00874 HashSet<RSVertex*> new_vertices_;
00875
00876
00877 HashSet<RSFace*> new_faces_;
00878
00879
00880 std::vector< std::list<RSVertex*> > vertices_;
00881 };
00882
00883
00884
00885 }
00886
00887 #endif // BALL_STRUCTURE_REDUCEDSURFACE_H