00001
00002
00003
00004
00005 #ifndef BALL_STRUCTURE_REDUCEDSURFACE_H
00006 #define BALL_STRUCTURE_REDUCEDSURFACE_H
00007
00008 #ifndef BALL_MATHC_COMMON_H
00009 # include <BALL/MATHS/common.h>
00010 #endif
00011
00012 #ifndef BALL_MATHS_SIMPLEBOX3_H
00013 # include <BALL/MATHS/simpleBox3.h>
00014 #endif
00015
00016 #ifndef BALL_MATHS_CIRCLE3_H
00017 # include <BALL/MATHS/circle3.h>
00018 #endif
00019
00020 #ifndef BALL_MATHS_SPHERE_H
00021 # include <BALL/MATHS/sphere3.h>
00022 #endif
00023
00024 #ifndef BALL_MATHS_VECTOR3_H
00025 # include <BALL/MATHS/vector3.h>
00026 #endif
00027
00028 #ifndef BALL_DATATYPE_HASHSET_H
00029 # include <BALL/DATATYPE/hashMap.h>
00030 #endif
00031
00032 #ifndef BALL_DATATYPE_HASHSET_H
00033 # include <BALL/DATATYPE/hashSet.h>
00034 #endif
00035
00036 #ifndef BALL_COMMON_EXCEPTION_H
00037 # include <BALL/COMMON/exception.h>
00038 #endif
00039
00040 #ifndef BALL_STRUCTURE_RSEDGE_H
00041 # include <BALL/STRUCTURE/RSEdge.h>
00042 #endif
00043
00044 #ifndef BALL_STRUCTURE_RSFACE_H
00045 # include <BALL/STRUCTURE/RSFace.h>
00046 #endif
00047
00048 #ifndef BALL_STRUCTURE_RSVERTEX_H
00049 # include <BALL/STRUCTURE/RSVertex.h>
00050 #endif
00051
00052 #include <list>
00053 #include <vector>
00054
00055 namespace BALL
00056 {
00057 class RSComputer;
00058 class SolventExcludedSurface;
00059 class SESComputer;
00060 class SESSingularityCleaner;
00061 class TriangulatedSES;
00062 class SolventAccessibleSurface;
00063 class TriangulatedSAS;
00064 class SESTriangulator;
00065
00069 class BALL_EXPORT ReducedSurface
00070 {
00071 public:
00072
00085 friend class RSComputer;
00086 friend class SolventExcludedSurface;
00087 friend class SESComputer;
00088 friend class SESSingularityCleaner;
00089 friend class SolventAccessibleSurface;
00090 friend class TriangulatedSES;
00091 friend class TriangulatedSAS;
00092 friend class SESTriangulator;
00093
00094 BALL_CREATE(ReducedSurface)
00095
00096
00099
00104 ReducedSurface();
00105
00110 ReducedSurface(const ReducedSurface& reduced_surface, bool = true);
00111
00115 ReducedSurface(const std::vector< TSphere3<double> >& spheres,
00116 const double& probe_radius);
00117
00120 virtual ~ReducedSurface();
00121
00123
00126
00130 void operator = (const ReducedSurface& reduced_surface);
00131
00135 void set(const ReducedSurface& reduced_surface);
00136
00139 void clear();
00140
00143 void clean();
00144
00146
00149
00153 Size numberOfAtoms() const;
00154
00158 Size numberOfVertices() const;
00159
00163 Size numberOfEdges() const;
00164
00168 Size numberOfFaces() const;
00169
00173 double getProbeRadius() const;
00174
00179 TSphere3<double> getSphere(Position i) const
00180 throw(Exception::IndexOverflow);
00181
00186 RSVertex* getVertex(Position i) const
00187 throw(Exception::IndexOverflow);
00188
00193 RSEdge* getEdge(Position i) const
00194 throw(Exception::IndexOverflow);
00195
00200 RSFace* getFace(Position i) const
00201 throw(Exception::IndexOverflow);
00202
00206 void insert(RSVertex* rsvertex);
00207
00211 void insert(RSEdge* rsedge);
00212
00216 void insert(RSFace* rsface);
00217
00221 double getMaximalRadius() const;
00222
00226 TSimpleBox3<double> getBoundingBox() const;
00227
00232 void deleteSimilarFaces(RSFace* face1, RSFace* face2);
00233
00242 bool getAngle(RSFace* face1, RSFace* face2,
00243 RSVertex* vertex1, RSVertex* vertex2,
00244 TAngle<double>& angle, bool check = false) const;
00245
00248 void compute()
00249 throw(Exception::GeneralException,
00250 Exception::DivisionByZero,
00251 Exception::IndexOverflow);
00252
00254
00255 private:
00256
00257
00258
00259 bool canBeCopied(const ReducedSurface& reduced_surface);
00260
00261
00262
00263 void copy(const ReducedSurface& reduced_surface);
00264
00265
00266
00267 void correctEdges(RSFace* face1, RSFace* face2,
00268 RSEdge* edge1, RSEdge* edge2);
00269
00270
00271
00272 void joinVertices(RSFace* face1, RSFace* face2,
00273 RSVertex* vertex1, RSVertex* vertex2);
00274
00275
00276
00277 void findSimilarVertices(RSFace* face1, RSFace* face2,
00278 std::vector<RSVertex*>& rsvertex1,
00279 std::vector<RSVertex*>& rsvertex2);
00280
00281
00282
00283 void findSimilarEdges(RSFace* face1, RSFace* face2,
00284 std::vector<RSEdge*>& rsedge1,
00285 std::vector<RSEdge*>& rsedge2);
00286
00287 protected:
00288
00289
00290
00291 Size number_of_atoms_;
00292
00293
00294
00295
00296 std::vector< TSphere3<double> > atom_;
00297
00298
00299
00300 double probe_radius_;
00301
00302
00303
00304 Size number_of_vertices_;
00305
00306
00307
00308 std::vector< RSVertex* > vertices_;
00309
00310
00311
00312 Size number_of_edges_;
00313
00314
00315
00316 std::vector< RSEdge* > edges_;
00317
00318
00319
00320 Size number_of_faces_;
00321
00322
00323
00324 std::vector< RSFace* > faces_;
00325
00326
00327
00328 double r_max_;
00329
00330
00331
00332 TSimpleBox3<double> bounding_box_;
00333 };
00334
00338
00342 BALL_EXPORT std::ostream& operator << (std::ostream& s, const ReducedSurface& rs);
00343
00345
00349 class BALL_EXPORT RSComputer
00350 {
00351 public:
00352
00353 BALL_CREATE(RSComputer)
00354
00355
00358
00364 enum ProbeStatus
00365 {
00366 STATUS_OK = 0,
00367 STATUS_NOT_OK,
00368 STATUS_NOT_TESTED
00369 };
00370
00376 enum AtomStatus
00377 {
00378 STATUS_ON_SURFACE = 0,
00379 STATUS_INSIDE,
00380 STATUS_UNKNOWN
00381 };
00383
00384 struct ProbePosition
00385 {
00386 ProbeStatus status[2];
00387 TVector3<double> point[2];
00388 };
00389
00393
00398 RSComputer();
00399
00402 RSComputer(ReducedSurface* rs);
00403
00406 virtual ~RSComputer();
00407
00409
00412
00415 void run()
00416 throw(Exception::GeneralException,
00417 Exception::DivisionByZero,
00418 Exception::IndexOverflow);
00419
00421
00422
00423 private:
00424
00425
00426
00428
00429
00430
00431 void preProcessing();
00432
00433
00434
00435 void getRSComponent()
00436 throw(Exception::GeneralException,
00437 Exception::DivisionByZero,
00438 Exception::IndexOverflow);
00439
00440
00441
00442
00443 bool treatFace(RSFace* face)
00444 throw(Exception::GeneralException,
00445 Exception::DivisionByZero,
00446 Exception::IndexOverflow);
00447
00448
00449
00450
00451 bool treatEdge(RSEdge* edge)
00452 throw(Exception::GeneralException,
00453 Exception::DivisionByZero,
00454 Exception::IndexOverflow);
00455
00456
00457
00458
00459
00460
00461 void correct(Index atom);
00462
00463
00464
00465 void extendComponent()
00466 throw(Exception::GeneralException,
00467 Exception::DivisionByZero,
00468 Exception::IndexOverflow);
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 Index thirdAtom(RSVertex* vertex1, RSVertex* vertex2,
00485 RSFace* face, TSphere3<double>& probe, TAngle<double>& phi)
00486 throw(Exception::GeneralException,
00487 Exception::DivisionByZero,
00488 Exception::IndexOverflow);
00489
00491
00492
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 Position getStartPosition()
00507 throw(Exception::DivisionByZero);
00508
00510
00511
00513
00514
00515
00516
00517
00518 RSFace* findFirstFace()
00519 throw(Exception::DivisionByZero);
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 RSFace* findFace(Position direction, Position extrem)
00531 throw(Exception::DivisionByZero);
00532
00534
00535
00537
00538
00539
00540
00541
00542 RSEdge* findFirstEdge();
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553 RSEdge* findEdge(Position direction, Position extrem);
00554
00556
00557
00559
00560
00561
00562
00563
00564 RSVertex* findFirstVertex();
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 Index findFirstAtom(Position direction, Position extrem);
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 Index findSecondAtom(Index atom, Position direction, Position extrem);
00586
00587
00588
00589
00590
00591
00592
00593
00594 void findThirdAtom(Index atom1, Index atom2, const std::list<Index>& third,
00595 std::list< std::pair< Index,TSphere3<double> > >& atoms);
00596
00598
00599
00601
00602
00603
00604
00605
00606
00607
00608
00609 void neighboursOfTwoAtoms(Index atom1, Index atom2);
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619 void neighboursOfThreeAtoms(Index atom1, Index atom2, Index atom3,
00620 std::list<Index>& output_list);
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 double getCircleExtremum(const TCircle3<double>& circle,
00632 Position direction, Position extrem);
00633
00635
00636
00638
00639
00640
00641
00642
00643
00644
00645 RSEdge* createFreeEdge(RSVertex* vertex1, RSVertex* vertex2);
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658 bool getCircles(Index atom1, Index atom2, TCircle3<double>& circle1,
00659 TCircle3<double>& circle2, TCircle3<double>& circle3);
00660
00661
00662
00663
00664
00665
00666
00667
00668 TVector3<double> getFaceNormal(const TSphere3<double>& atom1, const TSphere3<double>& atom2,
00669 const TSphere3<double>& atom3, const TSphere3<double>& probe);
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681 void updateFaceAndEdges(RSVertex* v1, RSVertex* v2, RSVertex* v3,
00682 RSEdge* e1, RSEdge* e2, RSEdge* e3,
00683 RSFace* f, const TSphere3<double>& probe);
00684
00685
00686
00687
00688
00689 RSFace* faceExists(RSFace* face, const std::list< RSVertex* >& vertices);
00690
00692
00693
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705 bool centerOfProbe(Index a1, Index a2, Index a3,
00706 TVector3<double>& c1, TVector3<double>& c2);
00707
00708
00709
00710
00711
00712
00713 bool checkProbe(const TSphere3<double>& probe,
00714 Index atom1, Index atom2, Index atom3);
00715
00716
00717
00718 void correctProbePosition(Position atom);
00719
00720
00721
00722 void sort(Index u1, Index u2, Index u3,
00723 Index& s1, Index& s2, Index& s3);
00724
00725
00726
00727 void correctProbePosition(Position a1, Position a2, Position a3);
00728
00729
00730
00731 void insert(RSVertex* vertex);
00732
00733
00734
00735 void insert(RSEdge* edge);
00736
00737
00738
00739 void insert(RSFace* face);
00740
00742
00743 protected:
00744
00745
00746
00747 ReducedSurface* rs_;
00748
00749
00750
00751 std::vector< std::list<Index> > neighbours_;
00752
00753
00754
00755 std::vector< AtomStatus > atom_status_;
00756
00757
00758
00759 HashMap< Position, HashMap< Position, std::list<Index> > > neighbours_of_two_;
00760
00761
00762
00763 HashMap< Position,
00764 HashMap< Position, HashMap< Position, ProbePosition* > > > probe_positions_;
00765
00766
00767
00768 HashSet<RSVertex*> new_vertices_;
00769
00770
00771
00772 HashSet<RSFace*> new_faces_;
00773
00774
00775
00776 std::vector< std::list<RSVertex*> > vertices_;
00777 };
00778 }
00779
00780 #endif // BALL_STRUCTURE_REDUCEDSURFACE_H