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
00131 SolventExcludedSurface
00132 (const SolventExcludedSurface& ses, bool = false);
00133
00136 SolventExcludedSurface(ReducedSurface* reduced_surface);
00137
00141 virtual ~SolventExcludedSurface()
00142 ;
00143
00145
00148
00149 void clear();
00150
00151 void clean(const double& density);
00152
00155 void compute()
00156 throw(Exception::GeneralException);
00157
00158 void splitSphericFaces()
00159 ;
00160
00161 bool check()
00162 ;
00163
00165
00168
00169 VertexIterator beginVertex()
00170 ;
00171 ConstVertexIterator beginVertex() const
00172 ;
00173 VertexIterator endVertex()
00174 ;
00175 ConstVertexIterator endVertex() const
00176 ;
00177
00178 EdgeIterator beginEdge()
00179 ;
00180 ConstEdgeIterator beginEdge() const
00181 ;
00182 EdgeIterator endEdge()
00183 ;
00184 ConstEdgeIterator endEdge() const
00185 ;
00186
00187 SingularEdgeIterator beginSingularEdge()
00188 ;
00189 ConstSingularEdgeIterator beginSingularEdge() const
00190 ;
00191 SingularEdgeIterator endSingularEdge()
00192 ;
00193 ConstSingularEdgeIterator endSingularEdge() const
00194 ;
00195
00196 ContactFaceIterator beginContactFace()
00197 ;
00198 ConstContactFaceIterator beginContactFace() const
00199 ;
00200 ContactFaceIterator endContactFace()
00201 ;
00202 ConstContactFaceIterator endContactFace() const
00203 ;
00204
00205 SphericFaceIterator beginSphericFace()
00206 ;
00207 ConstSphericFaceIterator beginSphericFace() const
00208 ;
00209 SphericFaceIterator endSphericFace()
00210 ;
00211 ConstSphericFaceIterator endSphericFace() const
00212 ;
00213
00214 ToricFaceIterator beginToricFace()
00215 ;
00216 ConstToricFaceIterator beginToricFace() const
00217 ;
00218 ToricFaceIterator endToricFace()
00219 ;
00220 ConstToricFaceIterator endToricFace() const
00221 ;
00222
00224
00225 private:
00226
00227 void splitSphericFace(Position i)
00228 ;
00229
00230 void deleteSmallToricFace(SESFace* face)
00231 ;
00232
00233 void deleteSmallSingularToricFace(SESFace* face)
00234 ;
00235
00236 bool cleanToricFace(SESFace* face, const double& sqrt_density)
00237 ;
00238
00239 bool cleanSingularToricFace(SESFace* face, const double& sqrt_density)
00240 ;
00241
00242 void cleanVertices()
00243 ;
00244
00245 void cleanEdges()
00246 ;
00247
00248 void cleanContactFaces()
00249 ;
00250
00251 void cleanToricFaces()
00252 ;
00253
00254 void cleanSphericFaces()
00255 ;
00256
00257
00258 protected:
00259
00260
00261
00262 Position number_of_vertices_;
00263
00264
00265 ::std::vector<SESVertex*> vertices_;
00266
00267
00268 Position number_of_edges_;
00269
00270
00271 ::std::vector<SESEdge*> edges_;
00272
00273
00274 Position number_of_singular_edges_;
00275
00276
00277 ::std::list<SESEdge*> singular_edges_;
00278
00279
00280 Position number_of_contact_faces_;
00281
00282
00283 ::std::vector<SESFace*> contact_faces_;
00284
00285
00286 Position number_of_toric_faces_;
00287
00288
00289 ::std::vector<SESFace*> toric_faces_;
00290
00291
00292 Position number_of_spheric_faces_;
00293
00294
00295 ::std::vector<SESFace*> spheric_faces_;
00296
00297
00298 ReducedSurface* reduced_surface_;
00299
00300 };
00301
00302
00306
00309 BALL_EXPORT std::ostream& operator <<
00310 (std::ostream& s, const SolventExcludedSurface& ses);
00311
00313
00314
00315
00319 class BALL_EXPORT SESComputer
00320 {
00321 public:
00322
00323 BALL_CREATE(SESComputer)
00324
00325
00328
00332 SESComputer()
00333 ;
00334
00337 SESComputer(SolventExcludedSurface* ses)
00338 ;
00339
00343 virtual ~SESComputer()
00344 ;
00345
00347
00350
00353 void run()
00354 throw(Exception::GeneralException);
00355
00357
00358 private:
00359
00360
00361
00363
00364 void preProcessing()
00365 ;
00366
00367 void get()
00368 ;
00369
00370 void createSphericFace(Position j)
00371 ;
00372
00373 SESVertex* createVertex
00374 (const TVector3<double>& probe_center,
00375 Index index)
00376 ;
00377
00378 void pushVertex
00379 (SESFace* face,
00380 const TSphere3<double>& probe,
00381 RSVertex* rsvertex)
00382 ;
00383
00384 SESEdge* createConcaveEdge
00385 (SESFace* spheric_face,
00386 Position p1,
00387 Position p2,
00388 Index index,
00389 const double& radius_of_probe)
00390 ;
00391
00392 void pushConcaveEdge
00393 (SESFace* face,
00394 Position p1,
00395 Position p2,
00396 const double& radius_of_probe)
00397 ;
00398
00399 SESEdge* createConvexEdge
00400 (SESFace* toric_face,
00401 RSVertex* rsvertex)
00402 ;
00403
00404 void createToricFace(Position i)
00405 ;
00406
00407 void treatSingularToricFace(Position i)
00408 ;
00409
00410 void createFreeToricFace(Position i)
00411 ;
00412
00413 SESVertex* createSingularVertex
00414 (Position ip,
00415 const TVector3<double>& dir,
00416 SESFace* face0,
00417 SESFace* face1,
00418 SESFace* face2,
00419 SESEdge* edge0,
00420 SESEdge* edge1,
00421 SESEdge* edge2)
00422 ;
00423
00424 void updateEdge
00425 (SESEdge* edge,
00426 SESVertex* vertex1,
00427 SESVertex* vertex2,
00428 bool is_new)
00429 ;
00430
00431 void getPoint
00432 (const TVector3<double>& p1,
00433 const TVector3<double>& p2,
00434 const double& dist,
00435 TVector3<double>& result);
00436
00437 Index vertexExists(const TVector3<double>& point);
00438
00440
00441
00442 protected:
00443
00444
00445
00446 SolventExcludedSurface* ses_;
00447
00448
00449 HashGrid3<Index> vertex_grid_;
00450 };
00451
00452
00453
00454
00458 class BALL_EXPORT SESSingularityCleaner
00459 {
00460 public:
00461
00462 BALL_CREATE(SESSingularityCleaner)
00463
00464 typedef std::pair< std::pair<TAngle<double>,Index>,TVector3<double> > Intersection;
00465
00466 struct ProbeIntersection
00467 {
00468 TVector3<double> point[2];
00469 };
00470
00471 friend class SESComputer;
00472
00476
00480 SESSingularityCleaner()
00481 ;
00482
00485 SESSingularityCleaner
00486 (SolventExcludedSurface* ses,
00487 HashGrid3<Index>* vertex_grid_)
00488 ;
00489
00493 virtual ~SESSingularityCleaner()
00494 ;
00495
00497
00500
00503 bool run()
00504 throw(Exception::GeneralException);
00505
00507
00508 private:
00509
00513
00514 Index vertexExists(TVector3<double> point)
00515 ;
00516
00517 void treatSingularities()
00518 ;
00519
00520 void getSingularFaces(std::list<SESFace*>& faces)
00521 ;
00522
00523 bool treatFirstCategory()
00524 ;
00525
00526 void treatSecondCategory()
00527 ;
00528
00529 void getFirstCategoryFaces(std::list<SESFace*>& first_category_faces)
00530 ;
00531
00532 void noCut(SESFace* face1, SESFace* face2)
00533 ;
00534
00535 void twoCuts(SESFace* face1, SESFace* face2)
00536 ;
00537
00538 void treatSingularEdge
00539 (SESEdge* edge,
00540 HashGrid3<Position>& grid,
00541 ::std::list<SESEdge*>& deletable_edges)
00542 ;
00543
00544 void getIntersectionsOfSingularEdge
00545 (SESEdge* edge,
00546 const TAngle<double>& phi,
00547 HashGrid3<Position>& grid,
00548 std::list<Intersection>& intersections)
00549 ;
00550
00551 bool getIntersectionPointsAndAngles
00552 (const TCircle3<double>& circle,
00553 const TVector3<double>& point,
00554 Position index1,
00555 Position index2,
00556 Position probe_index,
00557 TAngle<double>& phi1,
00558 TVector3<double>& point1,
00559 TAngle<double>& phi2,
00560 TVector3<double>& point2)
00561 ;
00562
00563 bool isIntersection
00564 (const TAngle<double>& min_phi,
00565 const TAngle<double>& max_phi,
00566 const TAngle<double>& phi,
00567 const TVector3<double>& middle,
00568 const TSphere3<double>& probe)
00569 ;
00570
00571 void buildEndEdges
00572 (SESEdge* edge,
00573 const std::list<Intersection>& min,
00574 const std::list<Intersection>& max,
00575 SESVertex*& vertex1,
00576 SESVertex*& vertex2,
00577 Index& actual_min,
00578 Index& actual_max)
00579 ;
00580
00581 void buildEdge
00582 (SESEdge* edge,
00583 Index face1,
00584 Index& face2,
00585 Index end,
00586 SESVertex*& vertex,
00587 const HashSet<Index>& indices,
00588 bool minimum);
00589
00590 void getExtrema
00591 (const std::list<Intersection>& intersections,
00592 std::list<Intersection>& min,
00593 std::list<Intersection>& max);
00594
00595 void buildEndEdge
00596 (SESEdge* edge,
00597 const std::list<Intersection>& extrema,
00598 SESVertex*& vertex,
00599 Index& actual_extremum,
00600 bool min);
00601
00602 bool probeIntersection
00603 (Index face1,
00604 Index face2,
00605 Index face3,
00606 TVector3<double>& point1,
00607 TVector3<double>& point2);
00608
00609 void sort
00610 (SESFace* face1,
00611 SESFace* face2,
00612 std::vector<SESEdge*>& sesedge1,
00613 std::vector<SESEdge*>& sesedge2,
00614 std::vector<SESVertex*>& sesvertex1,
00615 std::vector<SESVertex*>& sesvertex2);
00616
00617 void sort
00618 (Index u1, Index u2, Index u3,
00619 Index& s1, Index& s2, Index& s3);
00620
00622
00623
00624 protected:
00625
00626
00627
00628 SolventExcludedSurface* ses_;
00629
00630
00631
00632 HashGrid3<Index>* vertex_grid_;
00633
00634
00635 HashMap< Position,
00636 HashMap< Position,
00637 HashMap< Position,
00638 ProbeIntersection*
00639 >
00640 >
00641 > probe_intersections_;
00642
00643 };
00644
00645
00646 }
00647
00648 #endif // BALL_STRUCTURE_SOLVENTEXCLUDEDSURFACE_H