00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H
00008 #define BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H
00009
00010 #ifndef BALL_STRUCTURE_SESEDGE_H
00011 # include <BALL/STRUCTURE/SESEdge.h>
00012 #endif
00013
00014 #ifndef BALL_STRUCTURE_SESFACE_H
00015 # include <BALL/STRUCTURE/SESFace.h>
00016 #endif
00017
00018 #ifndef BALL_STRUCTURE_SESVERTEX_H
00019 # include <BALL/STRUCTURE/SESVertex.h>
00020 #endif
00021
00022 #ifndef BALL_STRUCTURE_REDUCEDSURFACE_H
00023 # include <BALL/STRUCTURE/reducedSurface.h>
00024 #endif
00025
00026 #ifndef BALL_MATHS_ANGLE_H
00027 # include <BALL/MATHS/angle.h>
00028 #endif
00029
00030 #ifndef BALL_MATHS_CIRCLE3_H
00031 # include <BALL/MATHS/circle3.h>
00032 #endif
00033
00034 #ifndef BALL_MATHS_SPHERE3_H
00035 # include <BALL/MATHS/sphere3.h>
00036 #endif
00037
00038 #ifndef BALL_MATHS_VECTOR3_H
00039 # include <BALL/MATHS/vector3.h>
00040 #endif
00041
00042 #ifndef BALL_MATHS_VECTOR4_H
00043 # include <BALL/MATHS/vector4.h>
00044 #endif
00045
00046 #ifndef BALL_DATATYPE_HASHGRID_H
00047 # include <BALL/DATATYPE/hashGrid.h>
00048 #endif
00049
00050 #ifndef BALL_DATATYPE_HASHMAP_H
00051 # include <BALL/DATATYPE/hashMap.h>
00052 #endif
00053
00054 #include <vector>
00055 #include <list>
00056
00057
00058 namespace BALL
00059 {
00060 class SESComputer;
00061 class SESSingularityCleaner;
00062 class TriangulatedSES;
00063 class SESTriangulator;
00064
00068 class BALL_EXPORT SolventExcludedSurface
00069 {
00070 public:
00071
00080 friend class SESComputer;
00081 friend class SESSingularityCleaner;
00082 friend class TriangulatedSES;
00083 friend class SESTriangulator;
00084
00085 BALL_CREATE(SolventExcludedSurface)
00086
00087
00090
00091 typedef std::vector<SESVertex*>::iterator
00092 VertexIterator;
00093 typedef std::vector<SESVertex*>::const_iterator
00094 ConstVertexIterator;
00095 typedef std::vector<SESEdge*>::iterator
00096 EdgeIterator;
00097 typedef std::vector<SESEdge*>::const_iterator
00098 ConstEdgeIterator;
00099 typedef std::list<SESEdge*>::iterator
00100 SingularEdgeIterator;
00101 typedef std::list<SESEdge*>::const_iterator
00102 ConstSingularEdgeIterator;
00103 typedef std::vector<SESFace*>::iterator
00104 ContactFaceIterator;
00105 typedef std::vector<SESFace*>::const_iterator
00106 ConstContactFaceIterator;
00107 typedef std::vector<SESFace*>::iterator
00108 SphericFaceIterator;
00109 typedef std::vector<SESFace*>::const_iterator
00110 ConstSphericFaceIterator;
00111 typedef std::vector<SESFace*>::iterator
00112 ToricFaceIterator;
00113 typedef std::vector<SESFace*>::const_iterator
00114 ConstToricFaceIterator;
00115
00117
00120
00124 SolventExcludedSurface()
00125 ;
00126
00132 SolventExcludedSurface
00133 (const SolventExcludedSurface& ses, bool = false)
00134 ;
00135
00138 SolventExcludedSurface(ReducedSurface* reduced_surface)
00139 ;
00140
00144 virtual ~SolventExcludedSurface()
00145 ;
00146
00148
00151
00152 void clear();
00153
00154 void clean(const double& density);
00155
00158 void compute()
00159 throw(Exception::GeneralException);
00160
00161 void splitSphericFaces()
00162 ;
00163
00164 bool check()
00165 ;
00166
00168
00171
00172 VertexIterator beginVertex()
00173 ;
00174 ConstVertexIterator beginVertex() const
00175 ;
00176 VertexIterator endVertex()
00177 ;
00178 ConstVertexIterator endVertex() const
00179 ;
00180
00181 EdgeIterator beginEdge()
00182 ;
00183 ConstEdgeIterator beginEdge() const
00184 ;
00185 EdgeIterator endEdge()
00186 ;
00187 ConstEdgeIterator endEdge() const
00188 ;
00189
00190 SingularEdgeIterator beginSingularEdge()
00191 ;
00192 ConstSingularEdgeIterator beginSingularEdge() const
00193 ;
00194 SingularEdgeIterator endSingularEdge()
00195 ;
00196 ConstSingularEdgeIterator endSingularEdge() const
00197 ;
00198
00199 ContactFaceIterator beginContactFace()
00200 ;
00201 ConstContactFaceIterator beginContactFace() const
00202 ;
00203 ContactFaceIterator endContactFace()
00204 ;
00205 ConstContactFaceIterator endContactFace() const
00206 ;
00207
00208 SphericFaceIterator beginSphericFace()
00209 ;
00210 ConstSphericFaceIterator beginSphericFace() const
00211 ;
00212 SphericFaceIterator endSphericFace()
00213 ;
00214 ConstSphericFaceIterator endSphericFace() const
00215 ;
00216
00217 ToricFaceIterator beginToricFace()
00218 ;
00219 ConstToricFaceIterator beginToricFace() const
00220 ;
00221 ToricFaceIterator endToricFace()
00222 ;
00223 ConstToricFaceIterator endToricFace() const
00224 ;
00225
00227
00228 private:
00229
00230 void splitSphericFace(Position i)
00231 ;
00232
00233 void deleteSmallToricFace(SESFace* face)
00234 ;
00235
00236 void deleteSmallSingularToricFace(SESFace* face)
00237 ;
00238
00239 bool cleanToricFace(SESFace* face, const double& sqrt_density)
00240 ;
00241
00242 bool cleanSingularToricFace(SESFace* face, const double& sqrt_density)
00243 ;
00244
00245 void cleanVertices()
00246 ;
00247
00248 void cleanEdges()
00249 ;
00250
00251 void cleanContactFaces()
00252 ;
00253
00254 void cleanToricFaces()
00255 ;
00256
00257 void cleanSphericFaces()
00258 ;
00259
00260
00261 protected:
00262
00263
00264
00265 Position number_of_vertices_;
00266
00267
00268 ::std::vector<SESVertex*> vertices_;
00269
00270
00271 Position number_of_edges_;
00272
00273
00274 ::std::vector<SESEdge*> edges_;
00275
00276
00277 Position number_of_singular_edges_;
00278
00279
00280 ::std::list<SESEdge*> singular_edges_;
00281
00282
00283 Position number_of_contact_faces_;
00284
00285
00286 ::std::vector<SESFace*> contact_faces_;
00287
00288
00289 Position number_of_toric_faces_;
00290
00291
00292 ::std::vector<SESFace*> toric_faces_;
00293
00294
00295 Position number_of_spheric_faces_;
00296
00297
00298 ::std::vector<SESFace*> spheric_faces_;
00299
00300
00301 ReducedSurface* reduced_surface_;
00302
00303 };
00304
00305
00309
00312 BALL_EXPORT std::ostream& operator <<
00313 (std::ostream& s, const SolventExcludedSurface& ses);
00314
00316
00317
00318
00322 class BALL_EXPORT SESComputer
00323 {
00324 public:
00325
00326 BALL_CREATE(SESComputer)
00327
00328
00331
00335 SESComputer()
00336 ;
00337
00340 SESComputer(SolventExcludedSurface* ses)
00341 ;
00342
00346 virtual ~SESComputer()
00347 ;
00348
00350
00353
00356 void run()
00357 throw(Exception::GeneralException);
00358
00360
00361 private:
00362
00363
00364
00366
00367 void preProcessing()
00368 ;
00369
00370 void get()
00371 ;
00372
00373 void createSphericFace(Position j)
00374 ;
00375
00376 SESVertex* createVertex
00377 (const TVector3<double>& probe_center,
00378 Index index)
00379 ;
00380
00381 void pushVertex
00382 (SESFace* face,
00383 const TSphere3<double>& probe,
00384 RSVertex* rsvertex)
00385 ;
00386
00387 SESEdge* createConcaveEdge
00388 (SESFace* spheric_face,
00389 Position p1,
00390 Position p2,
00391 Index index,
00392 const double& radius_of_probe)
00393 ;
00394
00395 void pushConcaveEdge
00396 (SESFace* face,
00397 Position p1,
00398 Position p2,
00399 const double& radius_of_probe)
00400 ;
00401
00402 SESEdge* createConvexEdge
00403 (SESFace* toric_face,
00404 RSVertex* rsvertex)
00405 ;
00406
00407 void createToricFace(Position i)
00408 ;
00409
00410 void treatSingularToricFace(Position i)
00411 ;
00412
00413 void createFreeToricFace(Position i)
00414 ;
00415
00416 SESVertex* createSingularVertex
00417 (Position ip,
00418 const TVector3<double>& dir,
00419 SESFace* face0,
00420 SESFace* face1,
00421 SESFace* face2,
00422 SESEdge* edge0,
00423 SESEdge* edge1,
00424 SESEdge* edge2)
00425 ;
00426
00427 void updateEdge
00428 (SESEdge* edge,
00429 SESVertex* vertex1,
00430 SESVertex* vertex2,
00431 bool is_new)
00432 ;
00433
00434 void getPoint
00435 (const TVector3<double>& p1,
00436 const TVector3<double>& p2,
00437 const double& dist,
00438 TVector3<double>& result)
00439 ;
00440
00441 Index vertexExists(const TVector3<double>& point)
00442 ;
00443
00445
00446
00447 protected:
00448
00449
00450
00451 SolventExcludedSurface* ses_;
00452
00453
00454 HashGrid3<Index> vertex_grid_;
00455
00456 };
00457
00458
00459
00460
00464 class BALL_EXPORT SESSingularityCleaner
00465 {
00466 public:
00467
00468 BALL_CREATE(SESSingularityCleaner)
00469
00470 typedef std::pair< std::pair<TAngle<double>,Index>,TVector3<double> > Intersection;
00471
00472 struct ProbeIntersection
00473 {
00474 TVector3<double> point[2];
00475 };
00476
00477 friend class SESComputer;
00478
00482
00486 SESSingularityCleaner()
00487 ;
00488
00491 SESSingularityCleaner
00492 (SolventExcludedSurface* ses,
00493 HashGrid3<Index>* vertex_grid_)
00494 ;
00495
00499 virtual ~SESSingularityCleaner()
00500 ;
00501
00503
00506
00509 bool run()
00510 throw(Exception::GeneralException);
00511
00513
00514 private:
00515
00519
00520 Index vertexExists(TVector3<double> point)
00521 ;
00522
00523 void treatSingularities()
00524 ;
00525
00526 void getSingularFaces(std::list<SESFace*>& faces)
00527 ;
00528
00529 bool treatFirstCategory()
00530 ;
00531
00532 void treatSecondCategory()
00533 ;
00534
00535 void getFirstCategoryFaces(std::list<SESFace*>& first_category_faces)
00536 ;
00537
00538 void noCut(SESFace* face1, SESFace* face2)
00539 ;
00540
00541 void twoCuts(SESFace* face1, SESFace* face2)
00542 ;
00543
00544 void treatSingularEdge
00545 (SESEdge* edge,
00546 HashGrid3<Position>& grid,
00547 ::std::list<SESEdge*>& deletable_edges)
00548 ;
00549
00550 void getIntersectionsOfSingularEdge
00551 (SESEdge* edge,
00552 const TAngle<double>& phi,
00553 HashGrid3<Position>& grid,
00554 std::list<Intersection>& intersections)
00555 ;
00556
00557 bool getIntersectionPointsAndAngles
00558 (const TCircle3<double>& circle,
00559 const TVector3<double>& point,
00560 Position index1,
00561 Position index2,
00562 Position probe_index,
00563 TAngle<double>& phi1,
00564 TVector3<double>& point1,
00565 TAngle<double>& phi2,
00566 TVector3<double>& point2)
00567 ;
00568
00569 bool isIntersection
00570 (const TAngle<double>& min_phi,
00571 const TAngle<double>& max_phi,
00572 const TAngle<double>& phi,
00573 const TVector3<double>& middle,
00574 const TSphere3<double>& probe)
00575 ;
00576
00577 void buildEndEdges
00578 (SESEdge* edge,
00579 const std::list<Intersection>& min,
00580 const std::list<Intersection>& max,
00581 SESVertex*& vertex1,
00582 SESVertex*& vertex2,
00583 Index& actual_min,
00584 Index& actual_max)
00585 ;
00586
00587 void buildEdge
00588 (SESEdge* edge,
00589 Index face1,
00590 Index& face2,
00591 Index end,
00592 SESVertex*& vertex,
00593 const HashSet<Index>& indices,
00594 bool minimum)
00595 ;
00596
00597 void getExtrema
00598 (const std::list<Intersection>& intersections,
00599 std::list<Intersection>& min,
00600 std::list<Intersection>& max)
00601 ;
00602
00603 void buildEndEdge
00604 (SESEdge* edge,
00605 const std::list<Intersection>& extrema,
00606 SESVertex*& vertex,
00607 Index& actual_extremum,
00608 bool min)
00609 ;
00610
00611 bool probeIntersection
00612 (Index face1,
00613 Index face2,
00614 Index face3,
00615 TVector3<double>& point1,
00616 TVector3<double>& point2)
00617 ;
00618
00619 void sort
00620 (SESFace* face1,
00621 SESFace* face2,
00622 std::vector<SESEdge*>& sesedge1,
00623 std::vector<SESEdge*>& sesedge2,
00624 std::vector<SESVertex*>& sesvertex1,
00625 std::vector<SESVertex*>& sesvertex2)
00626 ;
00627
00628 void sort
00629 (Index u1, Index u2, Index u3,
00630 Index& s1, Index& s2, Index& s3)
00631 ;
00632
00634
00635
00636 protected:
00637
00638
00639
00640 SolventExcludedSurface* ses_;
00641
00642
00643
00644 HashGrid3<Index>* vertex_grid_;
00645
00646
00647 HashMap< Position,
00648 HashMap< Position,
00649 HashMap< Position,
00650 ProbeIntersection*
00651 >
00652 >
00653 > probe_intersections_;
00654
00655 };
00656
00657
00658 }
00659
00660 #endif // BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H