1 | /*
|
---|
2 | * CandidateForTesselation.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 29, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "CandidateForTesselation.hpp"
|
---|
9 |
|
---|
10 | #include <iostream>
|
---|
11 | #include <iomanip>
|
---|
12 |
|
---|
13 | #include "BoundaryLineSet.hpp"
|
---|
14 | #include "BoundaryPointSet.hpp"
|
---|
15 | #include "TesselPoint.hpp"
|
---|
16 |
|
---|
17 | #include "Helpers/Assert.hpp"
|
---|
18 | #include "info.hpp"
|
---|
19 | //#include "Line.hpp"
|
---|
20 | #include "linkedcell.hpp"
|
---|
21 | #include "log.hpp"
|
---|
22 | //#include "Plane.hpp"
|
---|
23 | #include "vector.hpp"
|
---|
24 | #include "verbose.hpp"
|
---|
25 |
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | /** Constructor of class CandidateForTesselation.
|
---|
29 | */
|
---|
30 | CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
|
---|
31 | BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
32 | {
|
---|
33 | Info FunctionInfo(__func__);
|
---|
34 | }
|
---|
35 | ;
|
---|
36 |
|
---|
37 | /** Constructor of class CandidateForTesselation.
|
---|
38 | */
|
---|
39 | CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, const Vector &OptCandidateCenter, const Vector &OtherOptCandidateCenter) :
|
---|
40 | BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
41 | {
|
---|
42 | Info FunctionInfo(__func__);
|
---|
43 | OptCenter = OptCandidateCenter;
|
---|
44 | OtherOptCenter = OtherOptCandidateCenter;
|
---|
45 | };
|
---|
46 |
|
---|
47 |
|
---|
48 | /** Destructor for class CandidateForTesselation.
|
---|
49 | */
|
---|
50 | CandidateForTesselation::~CandidateForTesselation()
|
---|
51 | {
|
---|
52 | }
|
---|
53 | ;
|
---|
54 |
|
---|
55 | /** Checks validity of a given sphere of a candidate line.
|
---|
56 | * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
|
---|
57 | * \param RADIUS radius of sphere
|
---|
58 | * \param *LC LinkedCell structure with other atoms
|
---|
59 | * \return true - sphere is valid, false - sphere contains other points
|
---|
60 | */
|
---|
61 | bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
|
---|
62 | {
|
---|
63 | Info FunctionInfo(__func__);
|
---|
64 |
|
---|
65 | const double radiusSquared = RADIUS * RADIUS;
|
---|
66 | list<const Vector *> VectorList;
|
---|
67 | VectorList.push_back(&OptCenter);
|
---|
68 | //VectorList.push_back(&OtherOptCenter); // don't check the other (wrong) center
|
---|
69 |
|
---|
70 | if (!pointlist.empty())
|
---|
71 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
72 | else
|
---|
73 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
74 | // check baseline for OptCenter and OtherOptCenter being on sphere's surface
|
---|
75 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
76 | for (int i = 0; i < 2; i++) {
|
---|
77 | const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->getPosition()) - radiusSquared);
|
---|
78 | if (distance > HULLEPSILON) {
|
---|
79 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
|
---|
86 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
87 | const TesselPoint *Walker = *Runner;
|
---|
88 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
89 | const double distance = fabs((*VRunner)->DistanceSquared(Walker->getPosition()) - radiusSquared);
|
---|
90 | if (distance > HULLEPSILON) {
|
---|
91 | DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
92 | return false;
|
---|
93 | } else {
|
---|
94 | DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
100 | bool flag = true;
|
---|
101 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
102 | // get all points inside the sphere
|
---|
103 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
|
---|
104 |
|
---|
105 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner) << ":" << endl);
|
---|
106 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
107 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->distance(*(*VRunner)) << "." << endl);
|
---|
108 |
|
---|
109 | // remove baseline's endpoints and candidates
|
---|
110 | for (int i = 0; i < 2; i++) {
|
---|
111 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
|
---|
112 | ListofPoints->remove(BaseLine->endpoints[i]->node);
|
---|
113 | }
|
---|
114 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
115 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
|
---|
116 | ListofPoints->remove(*Runner);
|
---|
117 | }
|
---|
118 | if (!ListofPoints->empty()) {
|
---|
119 | DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
120 | flag = false;
|
---|
121 | DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
|
---|
122 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
123 | DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->distance(*(*VRunner)) << setprecision(6) << "." << endl);
|
---|
124 |
|
---|
125 | // check with animate_sphere.tcl VMD script
|
---|
126 | if (ThirdPoint != NULL) {
|
---|
127 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
|
---|
128 | } else {
|
---|
129 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl);
|
---|
130 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | delete (ListofPoints);
|
---|
134 |
|
---|
135 | }
|
---|
136 | return flag;
|
---|
137 | }
|
---|
138 | ;
|
---|
139 |
|
---|
140 | /** output operator for CandidateForTesselation.
|
---|
141 | * \param &ost output stream
|
---|
142 | * \param &a boundary line
|
---|
143 | */
|
---|
144 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
|
---|
145 | {
|
---|
146 | ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->getName() << "," << a.BaseLine->endpoints[1]->node->getName() << "] with ";
|
---|
147 | if (a.pointlist.empty())
|
---|
148 | ost << "no candidate.";
|
---|
149 | else {
|
---|
150 | ost << "candidate";
|
---|
151 | if (a.pointlist.size() != 1)
|
---|
152 | ost << "s ";
|
---|
153 | else
|
---|
154 | ost << " ";
|
---|
155 | for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
|
---|
156 | ost << *(*Runner) << " ";
|
---|
157 | ost << " at angle " << (a.ShortestAngle) << ".";
|
---|
158 | }
|
---|
159 |
|
---|
160 | return ost;
|
---|
161 | }
|
---|
162 | ;
|
---|
163 |
|
---|