Changes in / [271e17:bd61b41]


Ignore:
Files:
19 deleted
41 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r271e17 rbd61b41  
    11ATOMSOURCE = atom.cpp atom_atominfo.cpp atom_bondedparticle.cpp atom_bondedparticleinfo.cpp atom_graphnode.cpp atom_graphnodeinfo.cpp atom_particleinfo.cpp atom_trajectoryparticle.cpp atom_trajectoryparticleinfo.cpp
    22ATOMHEADER = atom.hpp atom_atominfo.hpp atom_bondedparticle.hpp atom_bondedparticleinfo.hpp atom_graphnode.hpp atom_graphnodeinfo.hpp atom_particleinfo.hpp atom_trajectoryparticle.hpp atom_trajectoryparticleinfo.hpp
    3 
    4 LINALGSOURCE = gslmatrix.cpp gslvector.cpp linearsystemofequations.cpp
    5 LINALGHEADER = gslmatrix.hpp gslvector.hpp linearsystemofequations.hpp
    63
    74ANALYSISSOURCE = analysis_bonds.cpp analysis_correlation.cpp
     
    1411INCLUDES = -I$(top_srcdir)/src/unittests
    1512
    16 noinst_LIBRARIES = libmolecuilder.a libgslwrapper.a
     13noinst_LIBRARIES = libmolecuilder.a
    1714bin_PROGRAMS = molecuilder joiner analyzer
    1815molecuilderdir = ${bindir}
    1916libmolecuilder_a_SOURCES = ${SOURCE} ${HEADER}
    20 libgslwrapper_a_SOURCES = ${LINALGSOURCE} ${LINALGHEADER}
    2117molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    2218molecuilder_LDFLAGS = $(BOOST_LIB)
    2319molecuilder_SOURCES = builder.cpp
    24 molecuilder_LDADD = libmolecuilder.a libgslwrapper.a
     20molecuilder_LDADD = libmolecuilder.a
    2521joiner_SOURCES = joiner.cpp datacreator.cpp parser.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp
    2622joiner_LDADD = libmolecuilder.a
  • src/analysis_correlation.cpp

    r271e17 rbd61b41  
    267267        Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
    268268        if ((type == NULL) || (Walker->type == type)) {
    269           triangle = Surface->FindClosestTriangleToVector(Walker->node, LC );
     269          triangle = Surface->FindClosestTriangleToPoint(Walker->node, LC );
    270270          if (triangle != NULL) {
    271271            distance = DistanceToTrianglePlane(Walker->node, triangle);
     
    308308  }
    309309  outmap = new CorrelationToSurfaceMap;
    310   double ShortestDistance = 0.;
    311   BoundaryTriangleSet *ShortestTriangle = NULL;
    312310  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    313311    if ((*MolWalker)->ActiveFlag) {
     
    323321          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    324322          // go through every range in xyz and get distance
    325           ShortestDistance = -1.;
    326323          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    327324            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     
    330327                checkX.AddVector(&periodicX);
    331328                checkX.MatrixMultiplication(FullMatrix);
    332                 triangle = Surface->FindClosestTriangleToVector(&checkX, LC);
    333                 distance = Surface->GetDistanceSquaredToTriangle(checkX, triangle);
    334                 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
    335                   ShortestDistance = distance;
    336                   ShortestTriangle = triangle;
     329                triangle = Surface->FindClosestTriangleToPoint(&checkX, LC );
     330                if (triangle != NULL) {
     331                  distance = DistanceToTrianglePlane(&checkX, triangle);
     332                  outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
    337333                }
    338               }
    339           // insert
    340           ShortestDistance = sqrt(ShortestDistance);
    341           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) );
    342           //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
     334          }
    343335        }
    344336      }
     
    370362{
    371363  Info FunctionInfo(__func__);
    372   *file << "BinStart\tCount" << endl;
     364  *file << "# BinStart\tCount" << endl;
    373365  for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    374366    *file << runner->first << "\t" << runner->second << endl;
     
    383375{
    384376  Info FunctionInfo(__func__);
    385   *file << "BinStart\tAtom1\tAtom2" << endl;
     377  *file << "# BinStart\tAtom1\tAtom2" << endl;
    386378  for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    387379    *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
     
    396388{
    397389  Info FunctionInfo(__func__);
    398   *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
     390  *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl;
    399391  for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    400392    *file << runner->first;
     
    412404{
    413405  Info FunctionInfo(__func__);
    414   *file << "BinStart\tTriangle" << endl;
     406  *file << "# BinStart\tTriangle" << endl;
    415407  for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    416     *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
    417   }
    418 };
    419 
     408    *file << runner->first << "\t" << *(runner->second.second) << endl;
     409  }
     410};
     411
  • src/analysis_correlation.hpp

    r271e17 rbd61b41  
    5353int GetBin ( const double value, const double BinWidth, const double BinStart );
    5454void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
    55 void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map );
    56 void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map );
    57 void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map );
     55void OutputPairCorrelation( ofstream * const file, const BinPairMap * const map );
     56void OutputCorrelationToPoint( ofstream * const file, const BinPairMap * const map );
     57void OutputCorrelationToSurface( ofstream * const file, const BinPairMap * const map );
    5858
    5959
     
    9090/** Puts given correlation data into bins of given size (histogramming).
    9191 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
    92  * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
    93  * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
    94  * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
     92 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater.
    9593 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
    9694 * \param *map map of doubles to count
     
    116114  if (BinStart == BinEnd) { // if same, find range ourselves
    117115    GetMinMax( map, start, end);
    118   } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
    119     GetMinMax( map, start, end);
    120     start = BinStart;
    121   } else { // else take both values
     116  } else { // if not, initialise range to zero
    122117    start = BinStart;
    123118    end = BinEnd;
  • src/analyzer.cpp

    r271e17 rbd61b41  
    77
    88//============================ INCLUDES ===========================
    9 
    10 #include <cstring>
    119
    1210#include "datacreator.hpp"
  • src/bondgraph.cpp

    r271e17 rbd61b41  
    1111#include "bondgraph.hpp"
    1212#include "element.hpp"
    13 #include "info.hpp"
    1413#include "log.hpp"
    1514#include "molecule.hpp"
     
    4342bool BondGraph::LoadBondLengthTable(const string &filename)
    4443{
    45   Info FunctionInfo(__func__);
    4644  bool status = true;
    4745  MatrixContainer *TempContainer = NULL;
     
    5553
    5654  // parse in matrix
    57   if (status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0)) {
    58     Log() << Verbose(1) << "Parsing bond length matrix successful." << endl;
    59   } else {
    60     eLog() << Verbose(1) << "Parsing bond length matrix failed." << endl;
    61   }
     55  status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0);
    6256
    6357  // find greatest distance
  • src/boundary.cpp

    r271e17 rbd61b41  
    1919
    2020#include<gsl/gsl_poly.h>
    21 #include<time.h>
    2221
    2322// ========================================== F U N C T I O N S =================================
     
    655654 * \param *out output stream for debugging
    656655 * \param *mol molecule with atoms and bonds
    657  * \param *TesselStruct Tesselation with boundary triangles
     656 * \param *&TesselStruct Tesselation with boundary triangles
    658657 * \param *filename prefix of filename
    659658 * \param *extraSuffix intermediate suffix
    660659 */
    661 void StoreTrianglesinFile(const molecule * const mol, const Tesselation * const TesselStruct, const char *filename, const char *extraSuffix)
     660void StoreTrianglesinFile(const molecule * const mol, const Tesselation *&TesselStruct, const char *filename, const char *extraSuffix)
    662661{
    663662        Info FunctionInfo(__func__);
     
    790789 * \param configuration contains box dimensions
    791790 * \param distance[NDIM] distance between filling molecules in each direction
    792  * \param boundary length of boundary zone between molecule and filling mollecules
    793  * \param epsilon distance to surface which is not filled
    794791 * \param RandAtomDisplacement maximum distance for random displacement per atom
    795792 * \param RandMolDisplacement maximum distance for random displacement per filler molecule
     
    797794 * \return *mol pointer to new molecule with filled atoms
    798795 */
    799 molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, const double distance[NDIM], const double boundary, const double RandomAtomDisplacement, const double RandomMolDisplacement, const bool DoRandomRotation)
     796molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, double distance[NDIM], double RandomAtomDisplacement, double RandomMolDisplacement, bool DoRandomRotation)
    800797{
    801798        Info FunctionInfo(__func__);
     
    820817  for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) {
    821818    Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl;
    822     LCList[i] = new LinkedCell((*ListRunner), 10.); // get linked cell list
    823     Log() << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl;
    824     TesselStruct[i] = NULL;
    825     FindNonConvexBorder((*ListRunner), TesselStruct[i], (const LinkedCell *&)LCList[i], 5., NULL);
     819    LCList[i] = new LinkedCell((*ListRunner), 5.); // get linked cell list
     820    if (TesselStruct[i] == NULL) {
     821      Log() << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl;
     822      FindNonConvexBorder((*ListRunner), TesselStruct[i], (const LinkedCell *&)LCList[i], 5., NULL);
     823    }
    826824    i++;
    827825  }
     
    837835  FillerDistance.Init(distance[0], distance[1], distance[2]);
    838836  FillerDistance.InverseMatrixMultiplication(M);
    839   for(int i=0;i<NDIM;i++)
     837  Log() << Verbose(1) << "INFO: Grid steps are ";
     838  for(int i=0;i<NDIM;i++) {
    840839    N[i] = (int) ceil(1./FillerDistance.x[i]);
    841   Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl;
    842 
    843   // initialize seed of random number generator to current time
    844   srand ( time(NULL) );
     840    Log() << Verbose(1) << N[i];
     841    if (i != NDIM-1)
     842      Log() << Verbose(1)<< ", ";
     843    else
     844      Log() << Verbose(1) << "." << endl;
     845  }
    845846
    846847  // go over [0,1]^3 filler grid
     
    858859          // get linked cell list
    859860          if (TesselStruct[i] == NULL) {
    860             eLog() << Verbose(0) << "TesselStruct of " << (*ListRunner) << " is NULL. Didn't we pre-create it?" << endl;
     861            eLog() << Verbose(1) << "TesselStruct of " << (*ListRunner) << " is NULL. Didn't we pre-create it?" << endl;
    861862            FillIt = false;
    862863          } else {
    863             const double distance = (TesselStruct[i]->GetDistanceSquaredToSurface(CurrentPosition, LCList[i]));
    864             FillIt = FillIt && (distance > boundary*boundary);
    865             if (FillIt) {
    866               Log() << Verbose(1) << "INFO: Position at " << CurrentPosition << " is outer point." << endl;
    867             } else {
    868               Log() << Verbose(1) << "INFO: Position at " << CurrentPosition << " is inner point or within boundary." << endl;
    869               break;
    870             }
     864            FillIt = FillIt && (!TesselStruct[i]->IsInnerPoint(CurrentPosition, LCList[i]));
    871865            i++;
    872866          }
     
    937931      }
    938932  Free(&M);
    939 
    940   // output to file
    941   TesselStruct[0]->LastTriangle = NULL;
    942   StoreTrianglesinFile(Filling, TesselStruct[0], "Tesselated", ".dat");
    943 
    944933  for (size_t i=0;i<List->ListOfMolecules.size();i++) {
    945934        delete(LCList[i]);
  • src/boundary.hpp

    r271e17 rbd61b41  
    4949
    5050double ConvexizeNonconvexEnvelope(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename);
    51 molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, const double distance[NDIM], const double boundary, const double RandomAtomDisplacement, const double RandomMolDisplacement, const bool DoRandomRotation);
     51molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, double distance[NDIM], double RandAtomDisplacement, double RandMolDisplacement, bool DoRandomRotation);
    5252void FindConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename);
    5353Vector* FindEmbeddingHole(MoleculeListClass *mols, molecule *srcmol);
     
    5858void PrepareClustersinWater(config *configuration, molecule *mol, double ClusterVolume, double celldensity);
    5959bool RemoveAllBoundaryPoints(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename);
    60 void StoreTrianglesinFile(const molecule * const mol, const Tesselation * const TesselStruct, const char *filename, const char *extraSuffix);
     60void StoreTrianglesinFile(const molecule * const mol, const Tesselation *&TesselStruct, const char *filename, const char *extraSuffix);
    6161double VolumeOfConvexEnvelope(class Tesselation *TesselStruct, class config *configuration);
    6262
  • src/builder.cpp

    r271e17 rbd61b41  
    4949
    5050using namespace std;
    51 
    52 #include <cstring>
    5351
    5452#include "analysis_correlation.hpp"
     
    14171415            Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
    14181416            Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl;
    1419             Log() << Verbose(0) << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl;
    1420             Log() << Verbose(0) << "\t-F <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl;
     1417            Log() << Verbose(0) << "\t-f/F <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl;
     1418            Log() << Verbose(0) << "\t-F\tFilling Box with water molecules." << endl;
    14211419            Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl;
    14221420            Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl;
     
    15511549     if (configuration.BG == NULL) {
    15521550       configuration.BG = new BondGraph(configuration.GetIsAngstroem());
    1553        if ((!BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {
     1551       if ((BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {
    15541552         Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
    15551553       } else {
     
    16601658              Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl;
    16611659              // @TODO rather do the dissection afterwards
    1662               molecules->DissectMoleculeIntoConnectedSubgraphs(periode, &configuration);
     1660              molecules->DissectMoleculeIntoConnectedSubgraphs(mol,&configuration);
    16631661              mol = NULL;
    16641662              if (molecules->ListOfMolecules.size() != 0) {
     
    17081706                int ranges[NDIM] = {1,1,1};
    17091707                CorrelationToSurfaceMap *surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges );
    1710                 OutputCorrelationToSurface(&output, surfacemap);
    17111708                BinPairMap *binmap = BinData( surfacemap, 0.5, 0., 0. );
    17121709                OutputCorrelation ( &binoutput, binmap );
     
    17391736              if (argptr+6 >=argc) {
    17401737                ExitFlag = 255;
    1741                 eLog() << Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <dist_x> <dist_y> <dist_z> <boundary> <randatom> <randmol> <DoRotate>" << endl;
     1738                eLog() << Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>" << endl;
    17421739                performCriticalExit();
    17431740              } else {
     
    17451742                Log() << Verbose(1) << "Filling Box with water molecules." << endl;
    17461743                // construct water molecule
    1747                 molecule *filler = new molecule(periode);
     1744                molecule *filler = new molecule(periode);;
    17481745                molecule *Filling = NULL;
    17491746                atom *second = NULL, *third = NULL;
     1747                first = new atom();
     1748                first->type = periode->FindElement(5);
     1749                first->x.Zero();
     1750                filler->AddAtom(first);
    17501751//                first = new atom();
    1751 //                first->type = periode->FindElement(5);
    1752 //                first->x.Zero();
     1752//                first->type = periode->FindElement(1);
     1753//                first->x.Init(0.441, -0.143, 0.);
    17531754//                filler->AddAtom(first);
    1754                 first = new atom();
    1755                 first->type = periode->FindElement(1);
    1756                 first->x.Init(0.441, -0.143, 0.);
    1757                 filler->AddAtom(first);
    1758                 second = new atom();
    1759                 second->type = periode->FindElement(1);
    1760                 second->x.Init(-0.464, 1.137, 0.0);
    1761                 filler->AddAtom(second);
    1762                 third = new atom();
    1763                 third->type = periode->FindElement(8);
    1764                 third->x.Init(-0.464, 0.177, 0.);
    1765                 filler->AddAtom(third);
    1766                 filler->AddBond(first, third, 1);
    1767                 filler->AddBond(second, third, 1);
     1755//                second = new atom();
     1756//                second->type = periode->FindElement(1);
     1757//                second->x.Init(-0.464, 1.137, 0.0);
     1758//                filler->AddAtom(second);
     1759//                third = new atom();
     1760//                third->type = periode->FindElement(8);
     1761//                third->x.Init(-0.464, 0.177, 0.);
     1762//                filler->AddAtom(third);
     1763//                filler->AddBond(first, third, 1);
     1764//                filler->AddBond(second, third, 1);
    17681765                // call routine
    17691766                double distance[NDIM];
  • src/config.cpp

    r271e17 rbd61b41  
    66
    77#include <stdio.h>
    8 #include <cstring>
    98
    109#include "atom.hpp"
     
    2827    char number1[8];
    2928    char number2[8];
    30     const char *dummy1, *dummy2;
     29    char *dummy1, *dummy2;
    3130    //Log() << Verbose(0) << s1 << "  " << s2 << endl;
    3231    dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
     
    21242123              }
    21252124              line++;
    2126             } while ((dummy1 != NULL) && ((dummy1[0] == '#') || (dummy1[0] == '\n')));
     2125            } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n'));
    21272126            dummy = dummy1;
    21282127          } else { // simple int, strings or doubles start in the same line
  • src/helpers.hpp

    r271e17 rbd61b41  
    7474  x = y;
    7575  y = tmp;
    76 };
    77 
    78 /** returns greater of the two values.
    79  * \param x first value
    80  * \param y second value
    81  * \return greater of the two (by operator>())
    82  */
    83 template <typename T> T Max(T x, T y)
    84 {
    85   if (x > y)
    86     return x;
    87   else return y;
    88 };
    89 
    90 /** returns smaller of the two values.
    91  * \param x first value
    92  * \param y second value
    93  * \return smaller of the two (by operator<())
    94  */
    95 template <typename T> T Min(T x, T y)
    96 {
    97   if (x < y)
    98     return x;
    99   else return y;
    10076};
    10177
  • src/joiner.cpp

    r271e17 rbd61b41  
    77
    88//============================ INCLUDES ===========================
    9 
    10 #include <cstring>
    119
    1210#include "datacreator.hpp"
  • src/memoryallocator.hpp

    r271e17 rbd61b41  
    1616#endif
    1717
    18 #include <cstdlib>
    1918#include <iostream>
    2019#include <iomanip>
  • src/memoryusageobserver.cpp

    r271e17 rbd61b41  
    44 * This class represents a Singleton for observing memory usage.
    55 */
    6 
    7 #include <cstdlib>
    86
    97#include "log.hpp"
  • src/molecule.cpp

    r271e17 rbd61b41  
    44 *
    55 */
    6 
    7 #include <cstring>
    86
    97#include "atom.hpp"
     
    589587  else
    590588    molname = filename; // contains no slashes
    591   const char *endname = strchr(molname, '.');
     589  char *endname = strchr(molname, '.');
    592590  if ((endname == NULL) || (endname < molname))
    593591    length = strlen(molname);
  • src/molecule.hpp

    r271e17 rbd61b41  
    110110  TesselPoint *GetPoint() const ;
    111111  TesselPoint *GetTerminalPoint() const ;
    112   int GetMaxId() const;
    113112  void GoToNext() const ;
    114113  void GoToPrevious() const ;
     
    323322  void Enumerate(ofstream *out);
    324323  void Output(ofstream *out);
    325   void DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration);
     324  void DissectMoleculeIntoConnectedSubgraphs(molecule * const mol, config * const configuration);
    326325  int CountAllAtoms() const;
    327326
  • src/molecule_dynamics.cpp

    r271e17 rbd61b41  
    370370
    371371  // argument minimise the constrained potential in this injective PermutationMap
    372   Log() << Verbose(1) << "Argument minimising the PermutationMap." << endl;
     372  Log() << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
    373373  OldPotential = 1e+10;
    374374  round = 0;
    375375  do {
    376     Log() << Verbose(2) << "Starting round " << ++round << ", at current potential " << OldPotential << " ... " << endl;
     376    Log() << Verbose(2) << "Starting round " << ++round << " ... " << endl;
    377377    OlderPotential = OldPotential;
    378378    do {
  • src/molecule_fragmentation.cpp

    r271e17 rbd61b41  
    55 *      Author: heber
    66 */
    7 
    8 #include <cstring>
    97
    108#include "atom.hpp"
  • src/molecule_pointcloud.cpp

    r271e17 rbd61b41  
    5050};
    5151
    52 /** Return the greatest index of all atoms in the list.
    53  * \return greatest index
    54  */
    55 int molecule::GetMaxId() const
    56 {
    57   return last_atom;
    58 };
    59 
    6052/** Go to next atom.
    6153 * Stops at last one.
  • src/moleculelist.cpp

    r271e17 rbd61b41  
    44 *
    55 */
    6 
    7 #include <cstring>
    86
    97#include "atom.hpp"
     
    741739/** Dissects given \a *mol into connected subgraphs and inserts them as new molecules but with old atoms into \a this.
    742740 * \param *out output stream for debugging
    743  * \param *periode periodentafel
     741 * \param *mol molecule with atoms to dissect
    744742 * \param *configuration config with BondGraph
    745743 */
    746 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
    747 {
    748   molecule *mol = new molecule(periode);
    749   atom *Walker = NULL;
    750   atom *Advancer = NULL;
    751   bond *Binder = NULL;
    752   bond *Stepper = NULL;
    753   // 0. gather all atoms into single molecule
    754   for (MoleculeList::iterator MolRunner = ListOfMolecules.begin(); !ListOfMolecules.empty(); MolRunner = ListOfMolecules.begin()) {
    755     // shift all atoms to new molecule
    756     Advancer = (*MolRunner)->start->next;
    757     while (Advancer != (*MolRunner)->end) {
    758       Walker = Advancer;
    759       Advancer = Advancer->next;
    760       Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl;
    761       unlink(Walker);
    762       Walker->father = Walker;
    763       mol->AddAtom(Walker);    // counting starts at 1
    764     }
    765     // remove all bonds
    766     Stepper = (*MolRunner)->first->next;
    767     while (Stepper != (*MolRunner)->last) {
    768       Binder = Stepper;
    769       Stepper = Stepper->next;
    770       delete(Binder);
    771     }
    772     // remove the molecule
    773     delete(*MolRunner);
    774     ListOfMolecules.erase(MolRunner);
    775   }
    776 
     744void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(molecule * const mol, config * const configuration)
     745{
    777746  // 1. dissect the molecule into connected subgraphs
    778747  configuration->BG->ConstructBondGraph(mol);
     
    808777  int *MolMap = Calloc<int>(mol->AtomCount, "config::Load() - *MolMap");
    809778  MoleculeLeafClass *MolecularWalker = Subgraphs;
    810   Walker = NULL;
     779  atom *Walker = NULL;
    811780  while (MolecularWalker->next != NULL) {
    812781    MolecularWalker = MolecularWalker->next;
     
    838807  }
    839808  // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list
    840   Binder = mol->first;
     809  bond *Binder = mol->first;
    841810  while (mol->first->next != mol->last) {
    842811    Binder = mol->first->next;
  • src/parser.cpp

    r271e17 rbd61b41  
    66
    77// ======================================= INCLUDES ==========================================
    8 
    9 #include <cstring>
    108
    119#include "helpers.hpp"
     
    158156
    159157  input.open(name, ios::in);
    160   //Log() << Verbose(1) << "Opening " << name << " ... "  << input << endl;
     158  //Log() << Verbose(0) << "Opening " << name << " ... "  << input << endl;
    161159  if (input == NULL) {
    162160    eLog() << Verbose(1) << endl << "Unable to open " << name << ", is the directory correct?" << endl;
     
    181179  }
    182180  //Log() << Verbose(0) << line.str() << endl;
    183   //Log() << Verbose(1) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;
     181  //Log() << Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;
    184182  if (ColumnCounter[MatrixNr] == 0) {
    185183    eLog() << Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
     
    197195    }
    198196  }
    199   //Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
     197  //Log() << Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
    200198  if (RowCounter[MatrixNr] == 0) {
    201199    eLog() << Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
     
    220218      input.getline(filename, 1023);
    221219      stringstream lines(filename);
    222       //Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
     220      //Log() << Verbose(0) << "Matrix at level " << j << ":";// << filename << endl;
    223221      for(int k=skipcolumns;k--;)
    224222        lines >> filename;
    225223      for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
    226224        lines >> Matrix[MatrixNr][j][k];
    227         //Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl;
     225        //Log() << Verbose(0) << " " << setprecision(2) << Matrix[MatrixNr][j][k];;
    228226      }
     227      //Log() << Verbose(0) << endl;
    229228      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
    230229      for(int j=ColumnCounter[MatrixNr];j--;)
  • src/periodentafel.cpp

    r271e17 rbd61b41  
    99#include <iomanip>
    1010#include <fstream>
    11 #include <cstring>
    1211
    1312#include "element.hpp"
  • src/tesselation.cpp

    r271e17 rbd61b41  
    3535 * \param *Walker TesselPoint this boundary point represents
    3636 */
    37 BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
     37BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker) :
    3838  LinesCount(0),
    3939  node(Walker),
     
    6161 * \param *line line to add
    6262 */
    63 void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
     63void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
    6464{
    6565        Info FunctionInfo(__func__);
     
    105105 * \param number number of the list
    106106 */
    107 BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
     107BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number)
    108108{
    109109        Info FunctionInfo(__func__);
     
    115115  Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
    116116  Point[1]->AddLine(this); //
    117   // set skipped to false
    118   skipped = false;
    119   // clear triangles list
    120   Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    121 };
    122 
    123 /** Constructor of BoundaryLineSet with two endpoints.
    124  * Adds line automatically to each endpoints' LineMap
    125  * \param *Point1 first boundary point
    126  * \param *Point2 second boundary point
    127  * \param number number of the list
    128  */
    129 BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
    130 {
    131   Info FunctionInfo(__func__);
    132   // set number
    133   Nr = number;
    134   // set endpoints in ascending order
    135   SetEndpointsOrdered(endpoints, Point1, Point2);
    136   // add this line to the hash maps of both endpoints
    137   Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
    138   Point2->AddLine(this); //
    139117  // set skipped to false
    140118  skipped = false;
     
    193171 * \param *triangle to add
    194172 */
    195 void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
     173void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
    196174{
    197175        Info FunctionInfo(__func__);
     
    204182 * \return true - common endpoint present, false - not connected
    205183 */
    206 bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
     184bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line)
    207185{
    208186        Info FunctionInfo(__func__);
     
    219197 * \return true - triangles are convex, false - concave or less than two triangles connected
    220198 */
    221 bool BoundaryLineSet::CheckConvexityCriterion() const
     199bool BoundaryLineSet::CheckConvexityCriterion()
    222200{
    223201        Info FunctionInfo(__func__);
     
    243221  int i=0;
    244222  class BoundaryPointSet *node = NULL;
    245   for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
     223  for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    246224    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    247225    NormalCheck.AddVector(&runner->second->NormalVector);
     
    286264 * \return true - point is of the line, false - is not
    287265 */
    288 bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
     266bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    289267{
    290268        Info FunctionInfo(__func__);
     
    299277 * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
    300278 */
    301 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
     279class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point)
    302280{
    303281        Info FunctionInfo(__func__);
     
    339317 * \param number number of triangle
    340318 */
    341 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
     319BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number) :
    342320  Nr(number)
    343321{
     
    398376 * \param &OtherVector direction vector to make normal vector unique.
    399377 */
    400 void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
     378void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector)
    401379{
    402380        Info FunctionInfo(__func__);
     
    410388};
    411389
    412 /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
     390/** Finds the point on the triangle \a *BTS the line defined by \a *MolCenter and \a *x crosses through.
    413391 * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
    414  * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
     392 * This we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    415393 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
    416394 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
     
    422400 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
    423401 */
    424 bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
    425 {
    426   Info FunctionInfo(__func__);
     402bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection)
     403{
     404        Info FunctionInfo(__func__);
    427405  Vector CrossPoint;
    428406  Vector helper;
     
    433411  }
    434412
    435   Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl;
    436   Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl;
    437   Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl;
    438 
    439   if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
    440     Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;
    441     return true;
    442   }   else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
    443     Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;
    444     return true;
    445   }   else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
    446     Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;
    447     return true;
    448   }
    449413  // Calculate cross point between one baseline and the line from the third endpoint to intersection
    450414  int i=0;
     
    453417      helper.CopyVector(endpoints[(i+1)%3]->node->node);
    454418      helper.SubtractVector(endpoints[i%3]->node->node);
    455       CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
    456       const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared();
    457       Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl;
    458       if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    459         Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;
    460         i=4;
    461         break;
    462       }
     419    } else
    463420      i++;
    464     } else
     421    if (i>2)
    465422      break;
    466   } while (i<3);
     423  } while (CrossPoint.NormSquared() < MYEPSILON);
    467424  if (i==3) {
    468     Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;
     425    eLog() << Verbose(0) << "Could not find any cross points, something's utterly wrong here!" << endl;
     426  }
     427  CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     428
     429  // check whether intersection is inside or not by comparing length of intersection and length of cross point
     430  if ((CrossPoint.NormSquared() - helper.NormSquared()) < MYEPSILON) { // inside
    469431    return true;
    470   } else {
    471     Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl;
     432  } else { // outside!
     433    Intersection->Zero();
    472434    return false;
    473435  }
    474 };
    475 
    476 /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
    477  * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
    478  * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    479  * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
    480  * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
    481  * the first two basepoints) or not.
    482  * \param *x point
    483  * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
    484  * \return Distance squared between \a *x and closest point inside triangle
    485  */
    486 double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
    487 {
    488   Info FunctionInfo(__func__);
    489   Vector Direction;
    490 
    491   // 1. get intersection with plane
    492   Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;
    493   GetCenter(&Direction);
    494   if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
    495     ClosestPoint->CopyVector(x);
    496   }
    497 
    498   // 2. Calculate in plane part of line (x, intersection)
    499   Vector InPlane;
    500   InPlane.CopyVector(x);
    501   InPlane.SubtractVector(ClosestPoint);  // points from plane intersection to straight-down point
    502   InPlane.ProjectOntoPlane(&NormalVector);
    503   InPlane.AddVector(ClosestPoint);
    504 
    505   Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl;
    506   Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl;
    507   Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl;
    508 
    509   // Calculate cross point between one baseline and the desired point such that distance is shortest
    510   double ShortestDistance = -1.;
    511   bool InsideFlag = false;
    512   Vector CrossDirection[3];
    513   Vector CrossPoint[3];
    514   Vector helper;
    515   for (int i=0;i<3;i++) {
    516     // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
    517     Direction.CopyVector(endpoints[(i+1)%3]->node->node);
    518     Direction.SubtractVector(endpoints[i%3]->node->node);
    519     // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    520     CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node);
    521     CrossDirection[i].CopyVector(&CrossPoint[i]);
    522     CrossDirection[i].SubtractVector(&InPlane);
    523     CrossPoint[i].SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
    524     const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared();
    525     Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl;
    526     if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
    527       CrossPoint[i].AddVector(endpoints[i%3]->node->node);  // make cross point absolute again
    528       Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl;
    529       const double distance = CrossPoint[i].DistanceSquared(x);
    530       if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    531         ShortestDistance = distance;
    532         ClosestPoint->CopyVector(&CrossPoint[i]);
    533       }
    534     } else
    535       CrossPoint[i].Zero();
    536   }
    537   InsideFlag = true;
    538   for (int i=0;i<3;i++) {
    539     const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+1)%3]);
    540     const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+2)%3]);;
    541     if ((sign > -MYEPSILON) && (othersign > -MYEPSILON))  // have different sign
    542       InsideFlag = false;
    543   }
    544   if (InsideFlag) {
    545     ClosestPoint->CopyVector(&InPlane);
    546     ShortestDistance = InPlane.DistanceSquared(x);
    547   } else {  // also check endnodes
    548     for (int i=0;i<3;i++) {
    549       const double distance = x->DistanceSquared(endpoints[i]->node->node);
    550       if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    551         ShortestDistance = distance;
    552         ClosestPoint->CopyVector(endpoints[i]->node->node);
    553       }
    554     }
    555   }
    556   Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;
    557   return ShortestDistance;
    558436};
    559437
     
    562440 * \return true - line is of the triangle, false - is not
    563441 */
    564 bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
     442bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line)
    565443{
    566444        Info FunctionInfo(__func__);
     
    575453 * \return true - point is of the triangle, false - is not
    576454 */
    577 bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
     455bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    578456{
    579457        Info FunctionInfo(__func__);
     
    588466 * \return true - point is of the triangle, false - is not
    589467 */
    590 bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
     468bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
    591469{
    592470        Info FunctionInfo(__func__);
     
    601479 * \return true - is the very triangle, false - is not
    602480 */
    603 bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
    604 {
    605         Info FunctionInfo(__func__);
    606         Log() << Verbose(1) << "INFO: Checking " << Points[0] << ","  << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl;
     481bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3])
     482{
     483        Info FunctionInfo(__func__);
    607484  return (((endpoints[0] == Points[0])
    608485            || (endpoints[0] == Points[1])
     
    624501 * \return true - is the very triangle, false - is not
    625502 */
    626 bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
     503bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T)
    627504{
    628505        Info FunctionInfo(__func__);
     
    646523 * \return pointer third endpoint or NULL if line does not belong to triangle.
    647524 */
    648 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
     525class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line)
    649526{
    650527        Info FunctionInfo(__func__);
     
    663540 * \param *center central point on return.
    664541 */
    665 void BoundaryTriangleSet::GetCenter(Vector * const center) const
     542void BoundaryTriangleSet::GetCenter(Vector *center)
    666543{
    667544        Info FunctionInfo(__func__);
     
    670547    center->AddVector(endpoints[i]->node->node);
    671548  center->Scale(1./3.);
    672   Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;
    673549}
    674550
     
    939815TesselPoint::TesselPoint()
    940816{
    941   //Info FunctionInfo(__func__);
     817  Info FunctionInfo(__func__);
    942818  node = NULL;
    943819  nr = -1;
     
    949825TesselPoint::~TesselPoint()
    950826{
    951   //Info FunctionInfo(__func__);
     827  Info FunctionInfo(__func__);
    952828};
    953829
     
    976852PointCloud::PointCloud()
    977853{
    978         //Info FunctionInfo(__func__);
     854        Info FunctionInfo(__func__);
    979855};
    980856
     
    983859PointCloud::~PointCloud()
    984860{
    985         //Info FunctionInfo(__func__);
     861        Info FunctionInfo(__func__);
    986862};
    987863
     
    11741050 * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
    11751051 */
    1176 void Tesselation::GuessStartingTriangle()
     1052void
     1053Tesselation::GuessStartingTriangle()
    11771054{
    11781055        Info FunctionInfo(__func__);
     
    15451422  TesselPoint *Walker = NULL;
    15461423  Vector *Center = cloud->GetCenter();
    1547   TriangleList *triangles = NULL;
     1424  list<BoundaryTriangleSet*> *triangles = NULL;
    15481425  bool AddFlag = false;
    15491426  LinkedCell *BoundaryPoints = NULL;
     
    15601437    Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
    15611438    // get the next triangle
    1562     triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
     1439    triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
    15631440    BTS = triangles->front();
    15641441    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
     
    24612338
    24622339  // fill the set of neighbours
    2463   TesselPointSet SetOfNeighbours;
     2340  Center.CopyVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2341  Center.SubtractVector(TurningPoint->node);
     2342  set<TesselPoint*> SetOfNeighbours;
    24642343  SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
    24652344  for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
    24662345    SetOfNeighbours.insert(*Runner);
    2467   TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
     2346  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, &Center);
    24682347
    24692348  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
    2470   Log() << Verbose(0) << "List of Candidates for Turning Point: " << *TurningPoint << "." << endl;
    2471   for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
    2472     Log() << Verbose(0) << **TesselRunner << endl;
    24732349  TesselPointList::iterator Runner = connectedClosestPoints->begin();
    24742350  TesselPointList::iterator Sprinter = Runner;
     
    24802356    AddTesselationPoint((*Sprinter), 2);
    24812357
     2358
    24822359    // add the lines
    24832360    AddTesselationLine(TPS[0], TPS[1], 0);
     
    24962373    Runner = Sprinter;
    24972374    Sprinter++;
    2498     Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl;
    2499     if (Sprinter != connectedClosestPoints->end())
    2500       Log() << Verbose(0) << " There are still more triangles to add." << endl;
    25012375  }
    25022376  delete(connectedClosestPoints);
     
    30832957  const BoundaryLineSet * lines[2] = { line1, line2 };
    30842958  class BoundaryPointSet *node = NULL;
    3085   PointMap OrderMap;
    3086   PointTestPair OrderTest;
     2959  map<int, class BoundaryPointSet *> OrderMap;
     2960  pair<map<int, class BoundaryPointSet *>::iterator, bool> OrderTest;
    30872961  for (int i = 0; i < 2; i++)
    30882962    // for both lines
     
    31042978};
    31052979
    3106 /** Finds the boundary points that are closest to a given Vector \a *x.
    3107  * \param *out output stream for debugging
    3108  * \param *x Vector to look from
    3109  * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
    3110  */
    3111 DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
    3112 {
    3113   Info FunctionInfo(__func__);
    3114   PointMap::const_iterator FindPoint;
    3115   int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    3116 
    3117   if (LinesOnBoundary.empty()) {
    3118     eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl;
    3119     return NULL;
    3120   }
    3121 
    3122   // gather all points close to the desired one
    3123   LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
    3124   for(int i=0;i<NDIM;i++) // store indices of this cell
    3125     N[i] = LC->n[i];
    3126   Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    3127 
    3128   DistanceToPointMap * points = new DistanceToPointMap;
    3129   LC->GetNeighbourBounds(Nlower, Nupper);
    3130   //Log() << Verbose(1) << endl;
    3131   for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    3132     for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    3133       for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    3134         const LinkedNodes *List = LC->GetCurrentCell();
    3135         //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    3136         if (List != NULL) {
    3137           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    3138             FindPoint = PointsOnBoundary.find((*Runner)->nr);
    3139             if (FindPoint != PointsOnBoundary.end()) {
    3140               points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second) );
    3141               Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl;
    3142             }
    3143           }
    3144         } else {
    3145           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
    3146         }
    3147       }
    3148 
    3149   // check whether we found some points
    3150   if (points->empty()) {
    3151     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
    3152     delete(points);
    3153     return NULL;
    3154   }
    3155   return points;
    3156 };
    3157 
    3158 /** Finds the boundary line that is closest to a given Vector \a *x.
    3159  * \param *out output stream for debugging
    3160  * \param *x Vector to look from
    3161  * \return closest BoundaryLineSet or NULL in degenerate case.
    3162  */
    3163 BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
    3164 {
    3165   Info FunctionInfo(__func__);
    3166 
    3167   // get closest points
    3168   DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
    3169   if (points == NULL) {
    3170     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
    3171     return NULL;
    3172   }
    3173 
    3174   // for each point, check its lines, remember closest
    3175   Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl;
    3176   BoundaryLineSet *ClosestLine = NULL;
    3177   double MinDistance = -1.;
    3178   Vector helper;
    3179   Vector Center;
    3180   Vector BaseLine;
    3181   for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
    3182     for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    3183       // calculate closest point on line to desired point
    3184       helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3185       helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
    3186       helper.Scale(0.5);
    3187       Center.CopyVector(x);
    3188       Center.SubtractVector(&helper);
    3189       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3190       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3191       Center.ProjectOntoPlane(&BaseLine);
    3192       const double distance = Center.NormSquared();
    3193       if ((ClosestLine == NULL) || (distance < MinDistance)) {
    3194         // additionally calculate intersection on line (whether it's on the line section or not)
    3195         helper.CopyVector(x);
    3196         helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
    3197         helper.SubtractVector(&Center);
    3198         const double lengthA = helper.ScalarProduct(&BaseLine);
    3199         helper.CopyVector(x);
    3200         helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3201         helper.SubtractVector(&Center);
    3202         const double lengthB = helper.ScalarProduct(&BaseLine);
    3203         if (lengthB*lengthA < 0) {  // if have different sign
    3204           ClosestLine = LineRunner->second;
    3205           MinDistance = distance;
    3206           Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;
    3207         } else {
    3208           Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl;
    3209         }
    3210       } else {
    3211         Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl;
    3212       }
    3213     }
    3214   }
    3215   delete(points);
    3216   // check whether closest line is "too close" :), then it's inside
    3217   if (ClosestLine == NULL) {
    3218     Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
    3219     return NULL;
    3220   }
    3221   return ClosestLine;
    3222 };
    3223 
    3224 
    32252980/** Finds the triangle that is closest to a given Vector \a *x.
    32262981 * \param *out output stream for debugging
    32272982 * \param *x Vector to look from
    3228  * \return BoundaryTriangleSet of nearest triangle or NULL.
    3229  */
    3230 TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
    3231 {
    3232         Info FunctionInfo(__func__);
    3233 
    3234         // get closest points
    3235         DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
    3236   if (points == NULL) {
    3237     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     2983 * \return list of BoundaryTriangleSet of nearest triangles or NULL in degenerate case.
     2984 */
     2985list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
     2986{
     2987        Info FunctionInfo(__func__);
     2988  TesselPoint *trianglePoints[3];
     2989  TesselPoint *SecondPoint = NULL;
     2990  list<BoundaryTriangleSet*> *triangles = NULL;
     2991
     2992  if (LinesOnBoundary.empty()) {
     2993    eLog() << Verbose(1) << "Error: There is no tesselation structure to compare the point with, please create one first.";
    32382994    return NULL;
    32392995  }
    3240 
    3241   // for each point, check its lines, remember closest
    3242   Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;
    3243   LineSet ClosestLines;
    3244   double MinDistance = 1e+16;
    3245   Vector BaseLineIntersection;
    3246   Vector Center;
    3247   Vector BaseLine;
    3248   Vector BaseLineCenter;
    3249   for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
    3250     for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    3251 
    3252       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3253       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3254       const double lengthBase = BaseLine.NormSquared();
    3255 
    3256       BaseLineIntersection.CopyVector(x);
    3257       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
    3258       const double lengthEndA = BaseLineIntersection.NormSquared();
    3259 
    3260       BaseLineIntersection.CopyVector(x);
    3261       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3262       const double lengthEndB = BaseLineIntersection.NormSquared();
    3263 
    3264       if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) {  // intersection would be outside, take closer endpoint
    3265         const double lengthEnd = Min(lengthEndA, lengthEndB);
    3266         if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
    3267           ClosestLines.clear();
    3268           ClosestLines.insert(LineRunner->second);
    3269           MinDistance = lengthEnd;
    3270           Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;
    3271         } else if  (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
    3272           ClosestLines.insert(LineRunner->second);
    3273           Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;
    3274         } else { // line is worse
    3275           Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl;
    3276         }
    3277       } else { // intersection is closer, calculate
    3278         // calculate closest point on line to desired point
    3279         BaseLineIntersection.CopyVector(x);
    3280         BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3281         Center.CopyVector(&BaseLineIntersection);
    3282         Center.ProjectOntoPlane(&BaseLine);
    3283         BaseLineIntersection.SubtractVector(&Center);
    3284         const double distance = BaseLineIntersection.NormSquared();
    3285         if (Center.NormSquared() > BaseLine.NormSquared()) {
    3286           eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;
    3287         }
    3288         if ((ClosestLines.empty()) || (distance < MinDistance)) {
    3289           ClosestLines.insert(LineRunner->second);
    3290           MinDistance = distance;
    3291           Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;
    3292         } else {
    3293           Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;
    3294         }
    3295       }
    3296     }
    3297   }
    3298   delete(points);
    3299 
    3300   // check whether closest line is "too close" :), then it's inside
    3301   if (ClosestLines.empty()) {
     2996  Log() << Verbose(1) << "Finding closest Tesselpoint to " << *x << " ... " << endl;
     2997  trianglePoints[0] = FindClosestPoint(x, SecondPoint, LC);
     2998 
     2999  // check whether closest point is "too close" :), then it's inside
     3000  if (trianglePoints[0] == NULL) {
    33023001    Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
    33033002    return NULL;
    33043003  }
    3305   TriangleList * candidates = new TriangleList;
    3306   for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
    3307     for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
    3308     candidates->push_back(Runner->second);
    3309   }
    3310   return candidates;
     3004  if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
     3005    Log() << Verbose(1) << "Point is right on a tesselation point, no nearest triangle." << endl;
     3006    PointMap::const_iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
     3007    triangles = new list<BoundaryTriangleSet*>;
     3008    if (PointRunner != PointsOnBoundary.end()) {
     3009      for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
     3010        for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
     3011          triangles->push_back(TriangleRunner->second);
     3012      triangles->sort();
     3013      triangles->unique();
     3014    } else {
     3015      PointRunner = PointsOnBoundary.find(SecondPoint->nr);
     3016      trianglePoints[0] = SecondPoint;
     3017      if (PointRunner != PointsOnBoundary.end()) {
     3018        for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
     3019          for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
     3020            triangles->push_back(TriangleRunner->second);
     3021        triangles->sort();
     3022        triangles->unique();
     3023      } else {
     3024        eLog() << Verbose(1) << "I cannot find a boundary point to the tessel point " << *trianglePoints[0] << "." << endl;
     3025        return NULL;
     3026      }
     3027    }
     3028  } else {
     3029    set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(trianglePoints[0]);
     3030    TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(connectedPoints, trianglePoints[0], x);
     3031    delete(connectedPoints);
     3032    if (connectedClosestPoints != NULL) {
     3033      trianglePoints[1] = connectedClosestPoints->front();
     3034      trianglePoints[2] = connectedClosestPoints->back();
     3035      for (int i=0;i<3;i++) {
     3036        if (trianglePoints[i] == NULL) {
     3037          eLog() << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl;
     3038        }
     3039        //Log() << Verbose(1) << "List of triangle points:" << endl;
     3040        //Log() << Verbose(2) << *trianglePoints[i] << endl;
     3041      }
     3042
     3043      triangles = FindTriangles(trianglePoints);
     3044      Log() << Verbose(1) << "List of possible triangles:" << endl;
     3045      for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
     3046        Log() << Verbose(2) << **Runner << endl;
     3047
     3048      delete(connectedClosestPoints);
     3049    } else {
     3050      triangles = NULL;
     3051      eLog() << Verbose(2) << "There is no circle of connected points!" << endl;
     3052    }
     3053  }
     3054 
     3055  if ((triangles == NULL) || (triangles->empty())) {
     3056    eLog() << Verbose(1) << "There is no nearest triangle. Please check the tesselation structure.";
     3057    delete(triangles);
     3058    return NULL;
     3059  } else
     3060    return triangles;
    33113061};
    33123062
     
    33173067 * \return list of BoundaryTriangleSet of nearest triangles or NULL.
    33183068 */
    3319 class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
     3069class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
    33203070{
    33213071        Info FunctionInfo(__func__);
    33223072  class BoundaryTriangleSet *result = NULL;
    3323   TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
    3324   TriangleList candidates;
     3073  list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
    33253074  Vector Center;
    3326   Vector helper;
    3327 
    3328   if ((triangles == NULL) || (triangles->empty()))
     3075
     3076  if (triangles == NULL)
    33293077    return NULL;
    33303078
    3331   // go through all and pick the one with the best alignment to x
    3332   double MinAlignment = 2.*M_PI;
    3333   for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    3334     (*Runner)->GetCenter(&Center);
    3335     helper.CopyVector(x);
    3336     helper.SubtractVector(&Center);
    3337     const double Alignment = helper.Angle(&(*Runner)->NormalVector);
    3338     if (Alignment < MinAlignment) {
    3339       result = *Runner;
    3340       MinAlignment = Alignment;
    3341       Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl;
    3342     } else {
    3343       Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl;
     3079  if (triangles->size() == 1) { // there is no degenerate case
     3080    result = triangles->front();
     3081    Log() << Verbose(1) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
     3082  } else {
     3083    result = triangles->front();
     3084    result->GetCenter(&Center);
     3085    Center.SubtractVector(x);
     3086    Log() << Verbose(1) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
     3087    if (Center.ScalarProduct(&result->NormalVector) < 0) {
     3088      result = triangles->back();
     3089      Log() << Verbose(1) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
     3090      if (Center.ScalarProduct(&result->NormalVector) < 0) {
     3091        eLog() << Verbose(1) << "Front and back side yield NormalVector in wrong direction!" << endl;
     3092      }
    33443093    }
    33453094  }
    33463095  delete(triangles);
    3347 
    33483096  return result;
    33493097};
    33503098
    3351 /** Checks whether the provided Vector is within the Tesselation structure.
    3352  * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
    3353  * @param point of which to check the position
    3354  * @param *LC LinkedCell structure
    3355  *
    3356  * @return true if the point is inside the Tesselation structure, false otherwise
    3357  */
    3358 bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    3359 {
    3360   return (GetDistanceSquaredToSurface(Point, LC) < MYEPSILON);
    3361 }
    3362 
    3363 /** Returns the distance to the surface given by the tesselation.
    3364  * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
    3365  * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
    3366  * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
    3367  * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
    3368  * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
    3369  *  -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
    3370  *  -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
    3371  *  -# If inside, take it to calculate closest distance
    3372  *  -# If not, take intersection with BoundaryLine as distance
    3373  *
    3374  * @note distance is squared despite it still contains a sign to determine in-/outside!
     3099/** Checks whether the provided Vector is within the tesselation structure.
    33753100 *
    33763101 * @param point of which to check the position
    33773102 * @param *LC LinkedCell structure
    33783103 *
    3379  * @return >0 if outside, ==0 if on surface, <0 if inside
    3380  */
    3381 double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
    3382 {
    3383   Info FunctionInfo(__func__);
     3104 * @return true if the point is inside the tesselation structure, false otherwise
     3105 */
     3106bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
     3107{
     3108        Info FunctionInfo(__func__);
     3109  class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
    33843110  Vector Center;
    3385   Vector helper;
    3386   Vector DistanceToCenter;
    3387   Vector Intersection;
    3388   double distance = 0.;
    3389 
    3390   if (triangle == NULL) {// is boundary point or only point in point cloud?
    3391     Log() << Verbose(1) << "No triangle given!" << endl;
    3392     return -1.;
     3111
     3112  if (result == NULL) {// is boundary point or only point in point cloud?
     3113    Log() << Verbose(1) << Point << " is the only point in vicinity." << endl;
     3114    return false;
     3115  }
     3116
     3117  result->GetCenter(&Center);
     3118  Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
     3119  Center.SubtractVector(&Point);
     3120  Log() << Verbose(2) << "INFO: Vector from center to point to test is " << Center << "." << endl;
     3121  if (Center.ScalarProduct(&result->NormalVector) > -MYEPSILON) {
     3122    Log() << Verbose(1) << Point << " is an inner point." << endl;
     3123    return true;
    33933124  } else {
    3394     Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;
    3395   }
    3396 
    3397   triangle->GetCenter(&Center);
    3398   Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
    3399   DistanceToCenter.CopyVector(&Center);
    3400   DistanceToCenter.SubtractVector(&Point);
    3401   Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl;
    3402 
    3403   // check whether we are on boundary
    3404   if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
    3405     // calculate whether inside of triangle
    3406     DistanceToCenter.CopyVector(&Point);
    3407     Center.CopyVector(&Point);
    3408     Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
    3409     DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
    3410     Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;
    3411     if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
    3412       Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;
    3413       return 0.;
    3414     } else {
    3415       Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl;
    3416       return false;
    3417     }
    3418   } else {
    3419     // calculate smallest distance
    3420     distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
    3421     Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;
    3422 
    3423     // then check direction to boundary
    3424     if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
    3425       Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;
    3426       return -distance;
    3427     } else {
    3428       Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl;
    3429       return +distance;
    3430     }
    3431   }
    3432 };
    3433 
    3434 /** Calculates distance to a tesselated surface.
    3435  * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
    3436  * \param &Point point to calculate distance from
    3437  * \param *LC needed for finding closest points fast
    3438  * \return distance squared to closest point on surface
    3439  */
    3440 double Tesselation::GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const
    3441 {
    3442   BoundaryTriangleSet *triangle = FindClosestTriangleToVector(&Point, LC);
    3443   const double distance = GetDistanceSquaredToTriangle(Point, triangle);
    3444   return Min(distance, LC->RADIUS);
    3445 };
     3125    Log() << Verbose(1) << Point << " is NOT an inner point." << endl;
     3126    return false;
     3127  }
     3128}
     3129
     3130/** Checks whether the provided TesselPoint is within the tesselation structure.
     3131 *
     3132 * @param *Point of which to check the position
     3133 * @param *LC Linked Cell structure
     3134 *
     3135 * @return true if the point is inside the tesselation structure, false otherwise
     3136 */
     3137bool Tesselation::IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const
     3138{
     3139        Info FunctionInfo(__func__);
     3140  return IsInnerPoint(*(Point->node), LC);
     3141}
    34463142
    34473143/** Gets all points connected to the provided point by triangulation lines.
     
    34513147 * @return set of the all points linked to the provided one
    34523148 */
    3453 TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    3454 {
    3455         Info FunctionInfo(__func__);
    3456         TesselPointSet *connectedPoints = new TesselPointSet;
     3149set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
     3150{
     3151        Info FunctionInfo(__func__);
     3152  set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
    34573153  class BoundaryPointSet *ReferencePoint = NULL;
    34583154  TesselPoint* current;
     
    34953191  }
    34963192
    3497   if (connectedPoints->empty()) { // if have not found any points
     3193  if (connectedPoints->size() == 0) { // if have not found any points
    34983194    eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;
    34993195    return NULL;
     
    35163212 * @return list of the all points linked to the provided one
    35173213 */
    3518 TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3214list<TesselPoint*> * Tesselation::GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    35193215{
    35203216        Info FunctionInfo(__func__);
    35213217  map<double, TesselPoint*> anglesOfPoints;
    3522   TesselPointList *connectedCircle = new TesselPointList;
     3218  list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
     3219  Vector center;
    35233220  Vector PlaneNormal;
    35243221  Vector AngleZero;
    35253222  Vector OrthogonalVector;
    35263223  Vector helper;
    3527   const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
    3528   TriangleList *triangles = NULL;
    35293224
    35303225  if (SetOfNeighbours == NULL) {
     
    35353230
    35363231  // calculate central point
    3537   triangles = FindTriangles(TrianglePoints);
    3538   if ((triangles != NULL) && (!triangles->empty())) {
    3539     for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    3540       PlaneNormal.AddVector(&(*Runner)->NormalVector);
    3541   } else {
    3542     eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl;
    3543     performCriticalExit();
    3544   }
    3545   PlaneNormal.Scale(1.0/triangles->size());
    3546   Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;
     3232  for (set<TesselPoint*>::const_iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
     3233    center.AddVector((*TesselRunner)->node);
     3234  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
     3235  //  << "; scale factor " << 1.0/connectedPoints.size();
     3236  center.Scale(1.0/SetOfNeighbours->size());
     3237  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3238
     3239  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     3240  PlaneNormal.CopyVector(Point->node);
     3241  PlaneNormal.SubtractVector(&center);
    35473242  PlaneNormal.Normalize();
     3243  Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
    35483244
    35493245  // construct one orthogonal vector
     
    35713267
    35723268  // go through all connected points and calculate angle
    3573   for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     3269  for (set<TesselPoint*>::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    35743270    helper.CopyVector((*listRunner)->node);
    35753271    helper.SubtractVector(Point->node);
     
    35873283}
    35883284
    3589 /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
    3590  * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
    3591  * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
    3592  * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
    3593  * triangle we are looking for.
    3594  *
    3595  * @param *SetOfNeighbours all points for which the angle should be calculated
    3596  * @param *Point of which get all connected points
    3597  * @param *Reference Reference vector for zero angle or NULL for no preference
    3598  * @return list of the all points linked to the provided one
    3599  */
    3600 TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    3601 {
    3602   Info FunctionInfo(__func__);
    3603   map<double, TesselPoint*> anglesOfPoints;
    3604   TesselPointList *connectedCircle = new TesselPointList;
    3605   Vector center;
    3606   Vector PlaneNormal;
    3607   Vector AngleZero;
    3608   Vector OrthogonalVector;
    3609   Vector helper;
    3610 
    3611   if (SetOfNeighbours == NULL) {
    3612     eLog() << Verbose(2) << "Could not find any connected points!" << endl;
    3613     delete(connectedCircle);
    3614     return NULL;
    3615   }
    3616 
    3617   // check whether there's something to do
    3618   if (SetOfNeighbours->size() < 3) {
    3619     for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
    3620       connectedCircle->push_back(*TesselRunner);
    3621     return connectedCircle;
    3622   }
    3623 
    3624   Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;
    3625   // calculate central point
    3626 
    3627   TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
    3628   TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
    3629   TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
    3630   TesselB++;
    3631   TesselC++;
    3632   TesselC++;
    3633   int counter = 0;
    3634   while (TesselC != SetOfNeighbours->end()) {
    3635     helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
    3636     Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;
    3637     counter++;
    3638     TesselA++;
    3639     TesselB++;
    3640     TesselC++;
    3641     PlaneNormal.AddVector(&helper);
    3642   }
    3643   //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    3644   //  << "; scale factor " << counter;
    3645   PlaneNormal.Scale(1.0/(double)counter);
    3646 //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    3647 //
    3648 //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
    3649 //  PlaneNormal.CopyVector(Point->node);
    3650 //  PlaneNormal.SubtractVector(&center);
    3651 //  PlaneNormal.Normalize();
    3652   Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
    3653 
    3654   // construct one orthogonal vector
    3655   if (Reference != NULL) {
    3656     AngleZero.CopyVector(Reference);
    3657     AngleZero.SubtractVector(Point->node);
    3658     AngleZero.ProjectOntoPlane(&PlaneNormal);
    3659   }
    3660   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    3661     Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
    3662     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3663     AngleZero.SubtractVector(Point->node);
    3664     AngleZero.ProjectOntoPlane(&PlaneNormal);
    3665     if (AngleZero.NormSquared() < MYEPSILON) {
    3666       eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
    3667       performCriticalExit();
    3668     }
    3669   }
    3670   Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
    3671   if (AngleZero.NormSquared() > MYEPSILON)
    3672     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
    3673   else
    3674     OrthogonalVector.MakeNormalVector(&PlaneNormal);
    3675   Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
    3676 
    3677   // go through all connected points and calculate angle
    3678   pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
    3679   for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3680     helper.CopyVector((*listRunner)->node);
    3681     helper.SubtractVector(Point->node);
    3682     helper.ProjectOntoPlane(&PlaneNormal);
    3683     double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    3684     if (angle > M_PI) // the correction is of no use here (and not desired)
    3685       angle = 2.*M_PI - angle;
    3686     Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;
    3687     InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
    3688     if (!InserterTest.second) {
    3689       eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;
    3690       performCriticalExit();
    3691     }
    3692   }
    3693 
    3694   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    3695     connectedCircle->push_back(AngleRunner->second);
    3696   }
    3697 
    3698   return connectedCircle;
    3699 }
    3700 
    37013285/** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
    37023286 *
     
    37053289 * @return list of the all points linked to the provided one
    37063290 */
    3707 ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
     3291list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    37083292{
    37093293        Info FunctionInfo(__func__);
    37103294  map<double, TesselPoint*> anglesOfPoints;
    3711   list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
    3712   TesselPointList *connectedPath = NULL;
     3295  list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
     3296  list<TesselPoint*> *connectedPath = NULL;
    37133297  Vector center;
    37143298  Vector PlaneNormal;
     
    37473331      } else if (!LineRunner->second) {
    37483332        LineRunner->second = true;
    3749         connectedPath = new TesselPointList;
     3333        connectedPath = new list<TesselPoint*>;
    37503334        triangle = NULL;
    37513335        CurrentLine = runner->second;
     
    38213405 * @return list of the closed paths
    38223406 */
    3823 ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    3824 {
    3825         Info FunctionInfo(__func__);
    3826   list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    3827   list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
    3828   TesselPointList *connectedPath = NULL;
    3829   TesselPointList *newPath = NULL;
     3407list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
     3408{
     3409        Info FunctionInfo(__func__);
     3410  list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
     3411  list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
     3412  list<TesselPoint*> *connectedPath = NULL;
     3413  list<TesselPoint*> *newPath = NULL;
    38303414  int count = 0;
    38313415
    38323416
    3833   TesselPointList::iterator CircleRunner;
    3834   TesselPointList::iterator CircleStart;
    3835 
    3836   for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     3417  list<TesselPoint*>::iterator CircleRunner;
     3418  list<TesselPoint*>::iterator CircleStart;
     3419
     3420  for(list<list<TesselPoint*> *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    38373421    connectedPath = *ListRunner;
    38383422
     
    38433427
    38443428    // go through list, look for reappearance of starting Point and create list
    3845     TesselPointList::iterator Marker = CircleStart;
     3429    list<TesselPoint*>::iterator Marker = CircleStart;
    38463430    for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
    38473431      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    38483432        // we have a closed circle from Marker to new Marker
    38493433        Log() << Verbose(1) << count+1 << ". closed path consists of: ";
    3850         newPath = new TesselPointList;
    3851         TesselPointList::iterator CircleSprinter = Marker;
     3434        newPath = new list<TesselPoint*>;
     3435        list<TesselPoint*>::iterator CircleSprinter = Marker;
    38523436        for (; CircleSprinter != CircleRunner; CircleSprinter++) {
    38533437          newPath->push_back(*CircleSprinter);
     
    38833467 * \return pointer to allocated list of triangles
    38843468 */
    3885 TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    3886 {
    3887         Info FunctionInfo(__func__);
    3888         TriangleSet *connectedTriangles = new TriangleSet;
     3469set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
     3470{
     3471        Info FunctionInfo(__func__);
     3472  set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
    38893473
    38903474  if (Point == NULL) {
     
    39353519  }
    39363520
    3937   list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
    3938   TesselPointList *connectedPath = NULL;
     3521  list<list<TesselPoint*> *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
     3522  list<TesselPoint*> *connectedPath = NULL;
    39393523
    39403524  // gather all triangles
    39413525  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    39423526    count+=LineRunner->second->triangles.size();
    3943   TriangleMap Candidates;
     3527  map<class BoundaryTriangleSet *, int> Candidates;
    39443528  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    39453529    line = LineRunner->second;
    39463530    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    39473531      triangle = TriangleRunner->second;
    3948       Candidates.insert( TrianglePair (triangle->Nr, triangle) );
     3532      Candidates.insert( pair<class BoundaryTriangleSet *, int> (triangle, triangle->Nr) );
    39493533    }
    39503534  }
     
    39533537  count=0;
    39543538  NormalVector.Zero();
    3955   for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3956     Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;
    3957     NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
    3958     RemoveTesselationTriangle(Runner->second);
     3539  for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
     3540    Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
     3541    NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
     3542    RemoveTesselationTriangle(Runner->first);
    39593543    count++;
    39603544  }
    39613545  Log() << Verbose(1) << count << " triangles were removed." << endl;
    39623546
    3963   list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
    3964   list<TesselPointList *>::iterator ListRunner = ListAdvance;
    3965   TriangleMap::iterator NumberRunner = Candidates.begin();
    3966   TesselPointList::iterator StartNode, MiddleNode, EndNode;
     3547  list<list<TesselPoint*> *>::iterator ListAdvance = ListOfClosedPaths->begin();
     3548  list<list<TesselPoint*> *>::iterator ListRunner = ListAdvance;
     3549  map<class BoundaryTriangleSet *, int>::iterator NumberRunner = Candidates.begin();
     3550  list<TesselPoint*>::iterator StartNode, MiddleNode, EndNode;
    39673551  double angle;
    39683552  double smallestangle;
     
    39783562
    39793563      // re-create all triangles by going through connected points list
    3980       LineList NewLines;
     3564      list<class BoundaryLineSet *> NewLines;
    39813565      for (;!connectedPath->empty();) {
    39823566        // search middle node with widest angle to next neighbours
     
    40843668      // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
    40853669      if (NewLines.size() > 1) {
    4086         LineList::iterator Candidate;
     3670        list<class BoundaryLineSet *>::iterator Candidate;
    40873671        class BoundaryLineSet *OtherBase = NULL;
    40883672        double tmp, maxgain;
    40893673        do {
    40903674          maxgain = 0;
    4091           for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     3675          for(list<class BoundaryLineSet *>::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    40923676            tmp = PickFarthestofTwoBaselines(*Runner);
    40933677            if (maxgain < tmp) {
     
    41313715 * Finds triangles belonging to the three provided points.
    41323716 *
    4133  * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
     3717 * @param *Points[3] list, is expected to contain three points
    41343718 *
    41353719 * @return triangles which belong to the provided points, will be empty if there are none,
    41363720 *         will usually be one, in case of degeneration, there will be two
    41373721 */
    4138 TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    4139 {
    4140         Info FunctionInfo(__func__);
    4141         TriangleList *result = new TriangleList;
     3722list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
     3723{
     3724        Info FunctionInfo(__func__);
     3725  list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
    41423726  LineMap::const_iterator FindLine;
    41433727  TriangleMap::const_iterator FindTriangle;
    41443728  class BoundaryPointSet *TrianglePoints[3];
    4145   size_t NoOfWildcards = 0;
    41463729
    41473730  for (int i = 0; i < 3; i++) {
    4148     if (Points[i] == NULL) {
    4149       NoOfWildcards++;
     3731    PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
     3732    if (FindPoint != PointsOnBoundary.end()) {
     3733      TrianglePoints[i] = FindPoint->second;
     3734    } else {
    41503735      TrianglePoints[i] = NULL;
    4151     } else {
    4152       PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
    4153       if (FindPoint != PointsOnBoundary.end()) {
    4154         TrianglePoints[i] = FindPoint->second;
    4155       } else {
    4156         TrianglePoints[i] = NULL;
    4157       }
    4158     }
    4159   }
    4160 
    4161   switch (NoOfWildcards) {
    4162     case 0: // checks lines between the points in the Points for their adjacent triangles
    4163       for (int i = 0; i < 3; i++) {
    4164         if (TrianglePoints[i] != NULL) {
    4165           for (int j = i+1; j < 3; j++) {
    4166             if (TrianglePoints[j] != NULL) {
    4167               for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
    4168                   (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
    4169                   FindLine++) {
    4170                 for (FindTriangle = FindLine->second->triangles.begin();
    4171                     FindTriangle != FindLine->second->triangles.end();
    4172                     FindTriangle++) {
    4173                   if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    4174                     result->push_back(FindTriangle->second);
    4175                   }
    4176                 }
     3736    }
     3737  }
     3738
     3739  // checks lines between the points in the Points for their adjacent triangles
     3740  for (int i = 0; i < 3; i++) {
     3741    if (TrianglePoints[i] != NULL) {
     3742      for (int j = i+1; j < 3; j++) {
     3743        if (TrianglePoints[j] != NULL) {
     3744          for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
     3745              (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
     3746              FindLine++) {
     3747            for (FindTriangle = FindLine->second->triangles.begin();
     3748                FindTriangle != FindLine->second->triangles.end();
     3749                FindTriangle++) {
     3750              if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
     3751                result->push_back(FindTriangle->second);
    41773752              }
    4178               // Is it sufficient to consider one of the triangle lines for this.
    4179               return result;
    41803753            }
    41813754          }
     3755          // Is it sufficient to consider one of the triangle lines for this.
     3756          return result;
    41823757        }
    41833758      }
    4184       break;
    4185     case 1: // copy all triangles of the respective line
    4186     {
    4187       int i=0;
    4188       for (; i < 3; i++)
    4189         if (TrianglePoints[i] == NULL)
    4190           break;
    4191       for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap!
    4192           (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr);
    4193           FindLine++) {
    4194         for (FindTriangle = FindLine->second->triangles.begin();
    4195             FindTriangle != FindLine->second->triangles.end();
    4196             FindTriangle++) {
    4197           if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    4198             result->push_back(FindTriangle->second);
    4199           }
    4200         }
    4201       }
    4202       break;
    4203     }
    4204     case 2: // copy all triangles of the respective point
    4205     {
    4206       int i=0;
    4207       for (; i < 3; i++)
    4208         if (TrianglePoints[i] != NULL)
    4209           break;
    4210       for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
    4211         for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
    4212           result->push_back(triangle->second);
    4213       result->sort();
    4214       result->unique();
    4215       break;
    4216     }
    4217     case 3: // copy all triangles
    4218     {
    4219       for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
    4220         result->push_back(triangle->second);
    4221       break;
    4222     }
    4223     default:
    4224       eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl;
    4225       performCriticalExit();
    4226       break;
     3759    }
    42273760  }
    42283761
     
    42673800 *         in the list, once as key and once as value
    42683801 */
    4269 IndexToIndex * Tesselation::FindAllDegeneratedLines()
     3802map<int, int> * Tesselation::FindAllDegeneratedLines()
    42703803{
    42713804        Info FunctionInfo(__func__);
    42723805        UniqueLines AllLines;
    4273   IndexToIndex * DegeneratedLines = new IndexToIndex;
     3806  map<int, int> * DegeneratedLines = new map<int, int>;
    42743807
    42753808  // sanity check
     
    42923825
    42933826  Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    4294   IndexToIndex::iterator it;
     3827  map<int,int>::iterator it;
    42953828  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
    42963829    const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
     
    43113844 *         in the list, once as key and once as value
    43123845 */
    4313 IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
    4314 {
    4315         Info FunctionInfo(__func__);
    4316   IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
    4317   IndexToIndex * DegeneratedTriangles = new IndexToIndex;
     3846map<int, int> * Tesselation::FindAllDegeneratedTriangles()
     3847{
     3848        Info FunctionInfo(__func__);
     3849  map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
     3850  map<int, int> * DegeneratedTriangles = new map<int, int>;
    43183851
    43193852  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
     
    43213854  class BoundaryLineSet *line1 = NULL, *line2 = NULL;
    43223855
    4323   for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
     3856  for (map<int, int>::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
    43243857    // run over both lines' triangles
    43253858    Liner = LinesOnBoundary.find(LineRunner->first);
     
    43423875
    43433876  Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    4344   IndexToIndex::iterator it;
     3877  map<int,int>::iterator it;
    43453878  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    43463879      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     
    43563889{
    43573890        Info FunctionInfo(__func__);
    4358   IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
     3891  map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
    43593892  TriangleMap::iterator finder;
    43603893  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    43613894  int count  = 0;
    43623895
    4363   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
     3896  for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    43643897    TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    43653898  ) {
     
    44493982  // find nearest boundary point
    44503983  class TesselPoint *BackupPoint = NULL;
    4451   class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
     3984  class TesselPoint *NearestPoint = FindClosestPoint(point->node, BackupPoint, LC);
    44523985  class BoundaryPointSet *NearestBoundaryPoint = NULL;
    44533986  PointMap::iterator PointRunner;
     
    46164149
    46174150  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    4618   IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
     4151  map <int, int> *DegeneratedTriangles = FindAllDegeneratedTriangles();
    46194152  set < BoundaryPointSet *> EndpointCandidateList;
    46204153  pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
     
    47684301  }
    47694302
    4770   IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
     4303  map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    47714304  Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
    4772   IndexToIndex::iterator it;
     4305  map<int,int>::iterator it;
    47734306  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    47744307      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
  • src/tesselation.hpp

    r271e17 rbd61b41  
    5252// ======================================================= some template functions =========================================
    5353
    54 #define IndexToIndex map <int, int>
    55 
    5654#define PointMap map < int, class BoundaryPointSet * >
    5755#define PointSet set < class BoundaryPointSet * >
     
    7977#define PolygonList list < class BoundaryPolygonSet * >
    8078
    81 #define DistanceToPointMap multimap <double, class BoundaryPointSet * >
    82 #define DistanceToPointPair pair <double, class BoundaryPointSet * >
    83 
    8479#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
    8580#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
     
    8782#define TesselPointList list <TesselPoint *>
    8883#define TesselPointSet set <TesselPoint *>
    89 
    90 #define ListOfTesselPointList list<list <TesselPoint *> *>
    9184
    9285/********************************************** declarations *******************************/
     
    108101  public:
    109102    BoundaryPointSet();
    110     BoundaryPointSet(TesselPoint * const Walker);
     103    BoundaryPointSet(TesselPoint * Walker);
    111104    ~BoundaryPointSet();
    112105
    113     void AddLine(BoundaryLineSet * const line);
     106    void AddLine(class BoundaryLineSet *line);
    114107
    115108    LineMap lines;
     
    127120  public:
    128121    BoundaryLineSet();
    129     BoundaryLineSet(BoundaryPointSet * const Point[2], const int number);
    130     BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number);
     122    BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
    131123    ~BoundaryLineSet();
    132124
    133     void AddTriangle(BoundaryTriangleSet * const triangle);
    134     bool IsConnectedTo(const BoundaryLineSet * const line) const;
    135     bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
    136     bool CheckConvexityCriterion() const;
    137     class BoundaryPointSet *GetOtherEndpoint(const BoundaryPointSet * const point) const;
     125    void AddTriangle(class BoundaryTriangleSet *triangle);
     126    bool IsConnectedTo(class BoundaryLineSet *line);
     127    bool ContainsBoundaryPoint(class BoundaryPointSet *point);
     128    bool CheckConvexityCriterion();
     129    class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
    138130
    139131    class BoundaryPointSet *endpoints[2];
     
    150142  public:
    151143    BoundaryTriangleSet();
    152     BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number);
     144    BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
    153145    ~BoundaryTriangleSet();
    154146
    155     void GetNormalVector(const Vector &NormalVector);
    156     void GetCenter(Vector * const center) const;
    157     bool GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const;
    158     double GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const;
    159     bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
    160     bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
    161     bool ContainsBoundaryPoint(const TesselPoint * const point) const;
    162     class BoundaryPointSet *GetThirdEndpoint(const BoundaryLineSet * const line) const;
    163     bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
    164     bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
     147    void GetNormalVector(Vector &NormalVector);
     148    void GetCenter(Vector *center);
     149    bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
     150    bool ContainsBoundaryLine(class BoundaryLineSet *line);
     151    bool ContainsBoundaryPoint(class BoundaryPointSet *point);
     152    bool ContainsBoundaryPoint(class TesselPoint *point);
     153    class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
     154    bool IsPresentTupel(class BoundaryPointSet *Points[3]);
     155    bool IsPresentTupel(class BoundaryTriangleSet *T);
    165156
    166157    class BoundaryPointSet *endpoints[3];
     
    235226  virtual TesselPoint *GetPoint() const { return NULL; };
    236227  virtual TesselPoint *GetTerminalPoint() const { return NULL; };
    237   virtual int GetMaxId() const { return 0; };
    238228  virtual void GoToNext() const {};
    239229  virtual void GoToPrevious() const {};
     
    300290    double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
    301291    class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
    302     IndexToIndex * FindAllDegeneratedTriangles();
    303     IndexToIndex * FindAllDegeneratedLines();
     292    map<int, int> * FindAllDegeneratedTriangles();
     293    map<int, int> * FindAllDegeneratedLines();
    304294    void RemoveDegeneratedTriangles();
    305295    void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
    306296    int CorrectAllDegeneratedPolygons();
    307297
    308     TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
    309     TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
    310     ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
    311     ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
    312     TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
    313     TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
    314     class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
    315     TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
    316     TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
    317     BoundaryTriangleSet * FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
     298    set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
     299    set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
     300    list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
     301    list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
     302    list<TesselPoint*> * GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
     303    class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
     304    list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
     305    list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
     306    class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
    318307    bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
    319     double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
    320     double GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const;
     308    bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
    321309    bool AddBoundaryPoint(TesselPoint * Walker, const int n);
    322     DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
    323     BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
    324310
    325311    // print for debugging
  • src/tesselationhelpers.cpp

    r271e17 rbd61b41  
    143143  if (fabs(HalfplaneIndicator) < MYEPSILON)
    144144    {
    145       if ((TempNormal.ScalarProduct(AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(AlternativeDirection) >0 && AlternativeIndicator <0))
     145      if ((TempNormal.ScalarProduct(AlternativeDirection) <0 and AlternativeIndicator >0) or (TempNormal.ScalarProduct(AlternativeDirection) >0 and AlternativeIndicator <0))
    146146        {
    147147          TempNormal.Scale(-1);
     
    150150  else
    151151    {
    152       if (((TempNormal.ScalarProduct(Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(Direction)>0) && (HalfplaneIndicator<0)))
     152      if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
    153153        {
    154154          TempNormal.Scale(-1);
     
    558558 * @return point which is second closest to the provided one
    559559 */
    560 TesselPoint* FindSecondClosestTesselPoint(const Vector* Point, const LinkedCell* const LC)
     560TesselPoint* FindSecondClosestPoint(const Vector* Point, const LinkedCell* const LC)
    561561{
    562562        Info FunctionInfo(__func__);
     
    613613 * @return point which is closest to the provided one, NULL if none found
    614614 */
    615 TesselPoint* FindClosestTesselPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC)
     615TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC)
    616616{
    617617        Info FunctionInfo(__func__);
     
    639639            helper.CopyVector(Point);
    640640            helper.SubtractVector((*Runner)->node);
    641             double currentNorm = helper.NormSquared();
     641            double currentNorm = helper. Norm();
    642642            if (currentNorm < distance) {
    643643              secondDistance = distance;
     
    866866    }
    867867    *tecplot << "\", N=" << TesselStruct->PointsOnBoundary.size() << ", E=" << TesselStruct->TrianglesOnBoundary.size() << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl;
    868     int i=cloud->GetMaxId();
     868    int i=0;
     869    for (cloud->GoToFirst(); !cloud->IsEnd(); cloud->GoToNext(), i++);
    869870    int *LookupList = new int[i];
    870871    for (cloud->GoToFirst(), i=0; !cloud->IsEnd(); cloud->GoToNext(), i++)
  • src/tesselationhelpers.hpp

    r271e17 rbd61b41  
    5959bool CheckLineCriteriaForDegeneratedTriangle(const BoundaryPointSet * const nodes[3]);
    6060bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation *candidate2);
    61 TesselPoint* FindClosestTesselPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC);
    62 TesselPoint* FindSecondClosestTesselPoint(const Vector*, const LinkedCell* const LC);
     61TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC);
     62TesselPoint* FindSecondClosestPoint(const Vector*, const LinkedCell* const LC);
    6363Vector * GetClosestPointBetweenLine(const BoundaryLineSet * const Base, const BoundaryLineSet * const OtherBase);
    6464
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r271e17 rbd61b41  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
    13 
    14 #include <cstring>
    1513
    1614#include "analysis_correlation.hpp"
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r271e17 rbd61b41  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
    13 
    14 #include <cstring>
    1513
    1614#include "analysis_correlation.hpp"
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r271e17 rbd61b41  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
    13 
    14 #include <cstring>
    1513
    1614#include "analysis_correlation.hpp"
  • src/unittests/Makefile.am

    r271e17 rbd61b41  
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
    55
    6 TESTS = \
    7   ActOnAllUnitTest \
    8   AnalysisBondsUnitTests \
    9   AnalysisCorrelationToPointUnitTest \
    10   AnalysisCorrelationToSurfaceUnitTest \
    11   AnalysisPairCorrelationUnitTest \
    12   BondGraphUnitTest \
    13   GSLMatrixSymmetricUnitTest \
    14   GSLMatrixUnitTest \
    15   GSLVectorUnitTest \
    16   InfoUnitTest \
    17   LinearSystemOfEquationsUnitTest \
    18   ListOfBondsUnitTest \
    19   LogUnitTest \
    20   MemoryUsageObserverUnitTest \
    21   MemoryAllocatorUnitTest \
    22   StackClassUnitTest \
    23   TesselationUnitTest \
    24   Tesselation_BoundaryTriangleUnitTest \
    25   Tesselation_InOutsideUnitTest \
    26   VectorUnitTest
    27  
     6TESTS = ActOnAllUnitTest AnalysisBondsUnitTests AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest BondGraphUnitTest InfoUnitTest ListOfBondsUnitTest LogUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest VectorUnitTest
    287check_PROGRAMS = $(TESTS)
    298noinst_PROGRAMS = $(TESTS)
    309
    3110ActOnAllUnitTest_SOURCES = ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp
    32 ActOnAllUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     11ActOnAllUnitTest_LDADD = ../libmolecuilder.a
    3312
    3413AnalysisBondsUnitTests_SOURCES = analysisbondsunittest.cpp analysisbondsunittest.hpp
    35 AnalysisBondsUnitTests_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     14AnalysisBondsUnitTests_LDADD = ../libmolecuilder.a
    3615
    3716AnalysisCorrelationToPointUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToPointUnitTest.cpp AnalysisCorrelationToPointUnitTest.hpp
    38 AnalysisCorrelationToPointUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     17AnalysisCorrelationToPointUnitTest_LDADD = ../libmolecuilder.a
    3918
    4019AnalysisCorrelationToSurfaceUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToSurfaceUnitTest.cpp AnalysisCorrelationToSurfaceUnitTest.hpp
    41 AnalysisCorrelationToSurfaceUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     20AnalysisCorrelationToSurfaceUnitTest_LDADD = ../libmolecuilder.a
    4221
    4322AnalysisPairCorrelationUnitTest_SOURCES = analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
    44 AnalysisPairCorrelationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     23AnalysisPairCorrelationUnitTest_LDADD = ../libmolecuilder.a
    4524
    4625BondGraphUnitTest_SOURCES = bondgraphunittest.cpp bondgraphunittest.hpp
    47 BondGraphUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    48 
    49 GSLMatrixSymmetricUnitTest_SOURCES = gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp
    50 GSLMatrixSymmetricUnitTest_LDADD = ../libgslwrapper.a
    51 
    52 GSLMatrixUnitTest_SOURCES = gslmatrixunittest.cpp gslmatrixunittest.hpp
    53 GSLMatrixUnitTest_LDADD = ../libgslwrapper.a
    54 
    55 GSLVectorUnitTest_SOURCES = gslvectorunittest.cpp gslvectorunittest.hpp
    56 GSLVectorUnitTest_LDADD = ../libgslwrapper.a
     26BondGraphUnitTest_LDADD = ../libmolecuilder.a
    5727
    5828InfoUnitTest_SOURCES = infounittest.cpp infounittest.hpp
    59 InfoUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    60 
    61 LinearSystemOfEquationsUnitTest_SOURCES = linearsystemofequationsunittest.cpp linearsystemofequationsunittest.hpp
    62 LinearSystemOfEquationsUnitTest_LDADD = ../libgslwrapper.a ../libmolecuilder.a
     29InfoUnitTest_LDADD = ../libmolecuilder.a
    6330
    6431ListOfBondsUnitTest_SOURCES = listofbondsunittest.cpp listofbondsunittest.hpp
    65 ListOfBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     32ListOfBondsUnitTest_LDADD = ../libmolecuilder.a
    6633
    6734LogUnitTest_SOURCES = logunittest.cpp logunittest.hpp
    68 LogUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     35LogUnitTest_LDADD = ../libmolecuilder.a
    6936
    7037MemoryAllocatorUnitTest_SOURCES = memoryallocatorunittest.cpp memoryallocatorunittest.hpp
    71 MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     38MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a
    7239
    7340MemoryUsageObserverUnitTest_SOURCES = memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
    74 MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     41MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a
    7542
    7643StackClassUnitTest_SOURCES = stackclassunittest.cpp stackclassunittest.hpp
    77 StackClassUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    78 
    79 TesselationUnitTest_SOURCES = tesselationunittest.cpp tesselationunittest.hpp
    80 TesselationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    81 
    82 Tesselation_BoundaryTriangleUnitTest_SOURCES = tesselation_boundarytriangleunittest.cpp tesselation_boundarytriangleunittest.hpp
    83 Tesselation_BoundaryTriangleUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    84 
    85 Tesselation_InOutsideUnitTest_SOURCES = tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp
    86 Tesselation_InOutsideUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     44StackClassUnitTest_LDADD = ../libmolecuilder.a
    8745
    8846VectorUnitTest_SOURCES = vectorunittest.cpp vectorunittest.hpp
    89 VectorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     47VectorUnitTest_LDADD = ../libmolecuilder.a
    9048
    9149
  • src/unittests/analysisbondsunittest.cpp

    r271e17 rbd61b41  
    1414#include <iostream>
    1515#include <stdio.h>
    16 #include <cstring>
    1716
    1817#include "analysis_bonds.hpp"
  • src/unittests/bondgraphunittest.cpp

    r271e17 rbd61b41  
    1414#include <iostream>
    1515#include <stdio.h>
    16 #include <cstring>
    1716
    1817#include "atom.hpp"
  • src/unittests/listofbondsunittest.cpp

    r271e17 rbd61b41  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
    13 
    14 #include <cstring>
    1513
    1614#include "listofbondsunittest.hpp"
  • src/unittests/tesselationunittest.cpp

    r271e17 rbd61b41  
    1313#include <cppunit/ui/text/TestRunner.h>
    1414
    15 #include <cstring>
    16 
    1715#include "defs.hpp"
    1816#include "tesselation.hpp"
     
    3230  class TesselPoint *Walker;
    3331  Walker = new TesselPoint;
    34   Walker->node = new Vector(1., 0., -1.);
    35   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     32  Walker->node = new Vector(1., 0., 0.);
     33  Walker->Name = new char[3];
    3634  strcpy(Walker->Name, "1");
    3735  Walker->nr = 1;
    3836  Corners.push_back(Walker);
    3937  Walker = new TesselPoint;
    40   Walker->node = new Vector(-1., 1., -1.);
    41   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     38  Walker->node = new Vector(-1., 1., 0.);
     39  Walker->Name = new char[3];
    4240  strcpy(Walker->Name, "2");
    4341  Walker->nr = 2;
    4442  Corners.push_back(Walker);
    4543  Walker = new TesselPoint;
    46   Walker->node = new Vector(-1., -1., -1.);
    47   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     44  Walker->node = new Vector(-1., -1., 0.);
     45  Walker->Name = new char[3];
    4846  strcpy(Walker->Name, "3");
    4947  Walker->nr = 3;
     
    5149  Walker = new TesselPoint;
    5250  Walker->node = new Vector(-1., 0., 1.);
    53   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     51  Walker->Name = new char[3];
    5452  strcpy(Walker->Name, "4");
    5553  Walker->nr = 4;
     
    6159  // create tesselation
    6260  TesselStruct = new Tesselation;
    63   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
    64   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
    65   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
     61  TesselStruct->PointsOnBoundary.clear();
     62  TesselStruct->LinesOnBoundary.clear();
     63  TesselStruct->TrianglesOnBoundary.clear();
    6664  TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
    67 
    68   CandidateForTesselation *baseline = NULL;
    69   BoundaryTriangleSet *T = NULL;
    70   bool OneLoopWithoutSuccessFlag = true;
    71   bool TesselationFailFlag = false;
    72   while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
    73     // 2a. fill all new OpenLines
    74     for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    75       baseline = Runner->second;
    76       if (baseline->pointlist.empty()) {
    77         T = (((baseline->BaseLine->triangles.begin()))->second);
    78         TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
    79       }
    80     }
    81 
    82     // 2b. search for smallest ShortestAngle among all candidates
    83     double ShortestAngle = 4.*M_PI;
    84     for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    85       if (Runner->second->ShortestAngle < ShortestAngle) {
    86         baseline = Runner->second;
    87         ShortestAngle = baseline->ShortestAngle;
    88       }
    89     }
    90     if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
    91       OneLoopWithoutSuccessFlag = false;
    92     else {
    93       TesselStruct->AddCandidateTriangle(*baseline);
     65  bool flag = false;
     66
     67  LineMap::iterator baseline = TesselStruct->LinesOnBoundary.begin();
     68  while (baseline != TesselStruct->LinesOnBoundary.end()) {
     69    if (baseline->second->triangles.size() == 1) {
     70      flag = TesselStruct->FindNextSuitableTriangle(*(baseline->second), *(((baseline->second->triangles.begin()))->second), SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
     71    }
     72    baseline++;
     73    if ((baseline == TesselStruct->LinesOnBoundary.end()) && (flag)) {
     74      baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
     75      flag = false;
    9476    }
    9577  }
     
    10284  delete(TesselStruct);
    10385  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
     86    delete[]((*Runner)->Name);
    10487    delete((*Runner)->node);
    10588    delete(*Runner);
    10689  }
    10790  Corners.clear();
    108   MemoryUsageObserver::purgeInstance();
    109   logger::purgeInstance();
    110   errorLogger::purgeInstance();
     91};
     92
     93/** UnitTest for Tesselation::IsInnerPoint()
     94 */
     95void TesselationTest::IsInnerPointTest()
     96{
     97  // true inside points
     98  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.), LinkedList) );
     99  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.5,0.,0.), LinkedList) );
     100  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.5,0.), LinkedList) );
     101  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.5), LinkedList) );
     102
     103  // corners
     104  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
     105    CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((*Runner), LinkedList) );
     106
     107  // true outside points
     108  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,5.,0.), LinkedList) );
     109  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,0.,5.), LinkedList) );
     110  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(1.,1.,1.), LinkedList) );
     111
     112  // tricky point, there are three equally close triangles
     113  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(5.,0.,0.), LinkedList) );
     114
    111115};
    112116
  • src/unittests/tesselationunittest.hpp

    r271e17 rbd61b41  
    2121{
    2222    CPPUNIT_TEST_SUITE( TesselationTest) ;
     23    CPPUNIT_TEST ( IsInnerPointTest );
    2324    CPPUNIT_TEST ( GetAllTrianglesTest );
    2425    CPPUNIT_TEST ( ContainmentTest );
     
    2829      void setUp();
    2930      void tearDown();
     31      void IsInnerPointTest();
    3032      void GetAllTrianglesTest();
    3133      void ContainmentTest();
  • src/vector.cpp

    r271e17 rbd61b41  
    88#include "defs.hpp"
    99#include "helpers.hpp"
    10 #include "info.hpp"
    11 #include "gslmatrix.hpp"
     10#include "memoryallocator.hpp"
    1211#include "leastsquaremin.hpp"
    1312#include "log.hpp"
    14 #include "memoryallocator.hpp"
    1513#include "vector.hpp"
    1614#include "verbose.hpp"
    17 
    18 #include <gsl/gsl_linalg.h>
    19 #include <gsl/gsl_matrix.h>
    20 #include <gsl/gsl_permutation.h>
    21 #include <gsl/gsl_vector.h>
    2215
    2316/************************************ Functions for class vector ************************************/
     
    222215 * \param *Origin first vector of line
    223216 * \param *LineVector second vector of line
    224  * \return true -  \a this contains intersection point on return, false - line is parallel to plane (even if in-plane)
     217 * \return true -  \a this contains intersection point on return, false - line is parallel to plane
    225218 */
    226219bool Vector::GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector)
    227220{
    228   Info FunctionInfo(__func__);
    229221  double factor;
    230222  Vector Direction, helper;
     
    234226  Direction.SubtractVector(Origin);
    235227  Direction.Normalize();
    236   Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl;
    237   //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl;
     228  //Log() << Verbose(4) << "INFO: Direction is " << Direction << "." << endl;
    238229  factor = Direction.ScalarProduct(PlaneNormal);
    239   if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane?
    240     Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl;
     230  if (factor < MYEPSILON) { // Uniqueness: line parallel to plane?
     231    eLog() << Verbose(2) << "Line is parallel to plane, no intersection." << endl;
    241232    return false;
    242233  }
     
    244235  helper.SubtractVector(Origin);
    245236  factor = helper.ScalarProduct(PlaneNormal)/factor;
    246   if (fabs(factor) < MYEPSILON) { // Origin is in-plane
    247     Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl;
     237  if (factor < MYEPSILON) { // Origin is in-plane
     238    //Log() << Verbose(2) << "Origin of line is in-plane, simple." << endl;
    248239    CopyVector(Origin);
    249240    return true;
     
    252243  Direction.Scale(factor);
    253244  CopyVector(Origin);
    254   Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl;
     245  //Log() << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl;
    255246  AddVector(&Direction);
    256247
     
    259250  helper.SubtractVector(PlaneOffset);
    260251  if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    261     Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl;
     252    //Log() << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
    262253    return true;
    263254  } else {
     
    295286
    296287/** Calculates the intersection of the two lines that are both on the same plane.
    297  * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html
     288 * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector
     289 * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and
     290 * project onto the first line's direction and add its offset.
    298291 * \param *out output stream for debugging
    299292 * \param *Line1a first vector of first line
     
    306299bool Vector::GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *PlaneNormal)
    307300{
    308   Info FunctionInfo(__func__);
    309 
    310   GSLMatrix *M = new GSLMatrix(4,4);
    311 
    312   M->SetAll(1.);
    313   for (int i=0;i<3;i++) {
    314     M->Set(0, i, Line1a->x[i]);
    315     M->Set(1, i, Line1b->x[i]);
    316     M->Set(2, i, Line2a->x[i]);
    317     M->Set(3, i, Line2b->x[i]);
    318   }
    319  
    320   //Log() << Verbose(1) << "Coefficent matrix is:" << endl;
    321   //for (int i=0;i<4;i++) {
    322   //  for (int j=0;j<4;j++)
    323   //    cout << "\t" << M->Get(i,j);
    324   //  cout << endl;
    325   //}
    326   if (fabs(M->Determinant()) > MYEPSILON) {
    327     Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl;
     301  bool result = true;
     302  Vector Direction, OtherDirection;
     303  Vector AuxiliaryNormal;
     304  Vector Distance;
     305  const Vector *Normal = NULL;
     306  Vector *ConstructedNormal = NULL;
     307  bool FreeNormal = false;
     308
     309  // construct both direction vectors
     310  Zero();
     311  Direction.CopyVector(Line1b);
     312  Direction.SubtractVector(Line1a);
     313  if (Direction.IsZero())
    328314    return false;
    329   }
    330   Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl;
    331 
    332 
    333   // constuct a,b,c
    334   Vector a;
    335   Vector b;
    336   Vector c;
    337   Vector d;
    338   a.CopyVector(Line1b);
    339   a.SubtractVector(Line1a);
    340   b.CopyVector(Line2b);
    341   b.SubtractVector(Line2a);
    342   c.CopyVector(Line2a);
    343   c.SubtractVector(Line1a);
    344   d.CopyVector(Line2b);
    345   d.SubtractVector(Line1b);
    346   Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl;
    347   if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {
    348    Zero();
    349    Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl;
    350    return false;
    351   }
    352 
    353   // check for parallelity
    354   Vector parallel;
    355   double factor = 0.;
    356   if (fabs(a.ScalarProduct(&b)*a.ScalarProduct(&b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {
    357     parallel.CopyVector(Line1a);
    358     parallel.SubtractVector(Line2a);
    359     factor = parallel.ScalarProduct(&a)/a.Norm();
    360     if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
    361       CopyVector(Line2a);
    362       Log() << Verbose(1) << "Lines conincide." << endl;
    363       return true;
     315  OtherDirection.CopyVector(Line2b);
     316  OtherDirection.SubtractVector(Line2a);
     317  if (OtherDirection.IsZero())
     318    return false;
     319
     320  Direction.Normalize();
     321  OtherDirection.Normalize();
     322
     323  //Log() << Verbose(4) << "INFO: Normalized Direction " << Direction << " and OtherDirection " << OtherDirection << "." << endl;
     324
     325  if (fabs(OtherDirection.ScalarProduct(&Direction) - 1.) < MYEPSILON) { // lines are parallel
     326    if ((Line1a == Line2a) || (Line1a == Line2b))
     327      CopyVector(Line1a);
     328    else if ((Line1b == Line2b) || (Line1b == Line2b))
     329        CopyVector(Line1b);
     330    else
     331      return false;
     332    Log() << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
     333    return true;
     334  } else {
     335    // check whether we have a plane normal vector
     336    if (PlaneNormal == NULL) {
     337      ConstructedNormal = new Vector;
     338      ConstructedNormal->MakeNormalVector(&Direction, &OtherDirection);
     339      Normal = ConstructedNormal;
     340      FreeNormal = true;
     341    } else
     342      Normal = PlaneNormal;
     343
     344    AuxiliaryNormal.MakeNormalVector(&OtherDirection, Normal);
     345    //Log() << Verbose(4) << "INFO: PlaneNormal is " << *Normal << " and AuxiliaryNormal " << AuxiliaryNormal << "." << endl;
     346
     347    Distance.CopyVector(Line2a);
     348    Distance.SubtractVector(Line1a);
     349    //Log() << Verbose(4) << "INFO: Distance is " << Distance << "." << endl;
     350    if (Distance.IsZero()) {
     351      // offsets are equal, match found
     352      CopyVector(Line1a);
     353      result = true;
    364354    } else {
    365       parallel.CopyVector(Line1a);
    366       parallel.SubtractVector(Line2b);
    367       factor = parallel.ScalarProduct(&a)/a.Norm();
    368       if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
    369         CopyVector(Line2b);
    370         Log() << Verbose(1) << "Lines conincide." << endl;
    371         return true;
    372       }
     355      CopyVector(Distance.Projection(&AuxiliaryNormal));
     356      //Log() << Verbose(4) << "INFO: Projected Distance is " << *this << "." << endl;
     357      double factor = Direction.ScalarProduct(&AuxiliaryNormal);
     358      //Log() << Verbose(4) << "INFO: Scaling factor is " << factor << "." << endl;
     359      Scale(1./(factor*factor));
     360      //Log() << Verbose(4) << "INFO: Scaled Distance is " << *this << "." << endl;
     361      CopyVector(Projection(&Direction));
     362      //Log() << Verbose(4) << "INFO: Distance, projected into Direction, is " << *this << "." << endl;
     363      if (this->IsZero())
     364        result = false;
     365      else
     366        result = true;
     367      AddVector(Line1a);
    373368    }
    374     Log() << Verbose(1) << "Lines are parallel." << endl;
    375     Zero();
    376     return false;
    377   }
    378 
    379   // obtain s
    380   double s;
    381   Vector temp1, temp2;
    382   temp1.CopyVector(&c);
    383   temp1.VectorProduct(&b);
    384   temp2.CopyVector(&a);
    385   temp2.VectorProduct(&b);
    386   Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl;
    387   if (fabs(temp2.NormSquared()) > MYEPSILON)
    388     s = temp1.ScalarProduct(&temp2)/temp2.NormSquared();
    389   else
    390     s = 0.;
    391   Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;
    392 
    393   // construct intersection
    394   CopyVector(&a);
    395   Scale(s);
    396   AddVector(Line1a);
    397   Log() << Verbose(1) << "Intersection is at " << *this << "." << endl;
    398 
    399   return true;
     369
     370    if (FreeNormal)
     371      delete(ConstructedNormal);
     372  }
     373  if (result)
     374    Log() << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
     375
     376  return result;
    400377};
    401378
  • tests/regression/Tesselation/1/post/NonConvexEnvelope.dat

    r271e17 rbd61b41  
    20205 6 8
    21216 7 8
     221 2 7
    22232 7 8
    23 1 2 7
    24241 2 3
  • tests/regression/Tesselation/1/post/NonConvexEnvelope.r3d

    r271e17 rbd61b41  
    4848  -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    49491
     50  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
     511
    5052  1.37419 -0.89433 0.89         -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    51 1
    52   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
    53531
    5454  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
  • tests/regression/Tesselation/2/post/ConvexEnvelope.dat

    r271e17 rbd61b41  
    20205 6 8
    21216 7 8
     221 2 7
    22232 7 8
    23 1 2 7
    24241 2 3
  • tests/regression/Tesselation/2/post/ConvexEnvelope.r3d

    r271e17 rbd61b41  
    4848  -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    49491
     50  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
     511
    5052  1.37419 -0.89433 0.89         -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    51 1
    52   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
    53531
    5454  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
  • tests/regression/Tesselation/2/post/NonConvexEnvelope.dat

    r271e17 rbd61b41  
    20205 6 8
    21216 7 8
     221 2 7
    22232 7 8
    23 1 2 7
    24241 2 3
  • tests/regression/Tesselation/2/post/NonConvexEnvelope.r3d

    r271e17 rbd61b41  
    4848  -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    49491
     50  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
     511
    5052  1.37419 -0.89433 0.89         -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    51 1
    52   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
    53531
    5454  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
Note: See TracChangeset for help on using the changeset viewer.