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