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