Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r8f215d r112b09  
    33 * Implementations and super-function for envelopes
    44 */
     5
     6#include "Helpers/MemDebug.hpp"
    57
    68#include "World.hpp"
     
    139141{
    140142        Info FunctionInfo(__func__);
    141   atom *Walker = NULL;
    142143  PointMap PointsOnBoundary;
    143144  LineMap LinesOnBoundary;
     
    165166
    166167    // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours
    167     Walker = mol->start;
    168     while (Walker->next != mol->end) {
    169       Walker = Walker->next;
    170       ProjectedVector = Walker->x - (*MolCenter);
     168    for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     169      ProjectedVector = (*iter)->x - (*MolCenter);
    171170      ProjectedVector.ProjectOntoPlane(AxisVector);
    172171
     
    182181        angle = 2. * M_PI - angle;
    183182      }
    184       DoLog(1) && (Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
    185       BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker)));
     183    DoLog(1) && (Log() << Verbose(1) << "Inserting " << **iter << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
     184      BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, (*iter))));
    186185      if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity
    187186        DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl);
    188187        DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl);
    189         DoLog(2) && (Log() << Verbose(2) << "New vector: " << *Walker << endl);
     188        DoLog(2) && (Log() << Verbose(2) << "New vector: " << **iter << endl);
    190189        const double ProjectedVectorNorm = ProjectedVector.NormSquared();
    191190        if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) {
    192191          BoundaryTestPair.first->second.first = ProjectedVectorNorm;
    193           BoundaryTestPair.first->second.second = Walker;
     192          BoundaryTestPair.first->second.second = (*iter);
    194193          DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    195194        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    196           helper = Walker->x - (*MolCenter);
     195          helper = (*iter)->x;
     196          helper -= *MolCenter;
    197197          const double oldhelperNorm = helper.NormSquared();
    198198          helper = BoundaryTestPair.first->second.second->x - (*MolCenter);
    199199          if (helper.NormSquared() < oldhelperNorm) {
    200             BoundaryTestPair.first->second.second = Walker;
     200            BoundaryTestPair.first->second.second = (*iter);
    201201            DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl);
    202202          } else {
     
    226226    do { // do as long as we still throw one out per round
    227227      flag = false;
    228       Boundaries::iterator left = BoundaryPoints[axis].end();
    229       Boundaries::iterator right = BoundaryPoints[axis].end();
    230       for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
     228      Boundaries::iterator left = BoundaryPoints[axis].begin();
     229      Boundaries::iterator right = BoundaryPoints[axis].begin();
     230      Boundaries::iterator runner = BoundaryPoints[axis].begin();
     231      bool LoopOnceDone = false;
     232      while (!LoopOnceDone) {
     233        runner = right;
     234        right++;
    231235        // set neighbours correctly
    232236        if (runner == BoundaryPoints[axis].begin()) {
     
    236240        }
    237241        left--;
    238         right = runner;
    239         right++;
    240242        if (right == BoundaryPoints[axis].end()) {
    241243          right = BoundaryPoints[axis].begin();
     244          LoopOnceDone = true;
    242245        }
    243246        // check distance
     
    279282            DoLog(1) && (Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl);
    280283            BoundaryPoints[axis].erase(runner);
     284            runner = right;
    281285            flag = true;
    282286          }
     
    359363
    360364  // 4. Store triangles in tecplot file
    361   if (filename != NULL) {
    362     if (DoTecplotOutput) {
    363       string OutputName(filename);
    364       OutputName.append("_intermed");
    365       OutputName.append(TecplotSuffix);
    366       ofstream *tecplot = new ofstream(OutputName.c_str());
    367       WriteTecplotFile(tecplot, TesselStruct, mol, 0);
    368       tecplot->close();
    369       delete(tecplot);
    370     }
    371     if (DoRaster3DOutput) {
    372       string OutputName(filename);
    373       OutputName.append("_intermed");
    374       OutputName.append(Raster3DSuffix);
    375       ofstream *rasterplot = new ofstream(OutputName.c_str());
    376       WriteRaster3dFile(rasterplot, TesselStruct, mol);
    377       rasterplot->close();
    378       delete(rasterplot);
    379     }
    380   }
     365  StoreTrianglesinFile(mol, TesselStruct, filename, "_intermed");
    381366
    382367  // 3d. check all baselines whether the peaks of the two adjacent triangles with respect to center of baseline are convex, if not, make the baseline between the two peaks and baseline endpoints become the new peaks
     
    397382          TesselStruct->FlipBaseline(line);
    398383          DoLog(1) && (Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl);
     384          LineRunner = TesselStruct->LinesOnBoundary.begin(); // LineRunner may have been erase if line was deleted from LinesOnBoundary
    399385        }
    400386      }
     
    409395
    410396  // 4. Store triangles in tecplot file
    411   if (filename != NULL) {
    412     if (DoTecplotOutput) {
    413       string OutputName(filename);
    414       OutputName.append(TecplotSuffix);
    415       ofstream *tecplot = new ofstream(OutputName.c_str());
    416       WriteTecplotFile(tecplot, TesselStruct, mol, 0);
    417       tecplot->close();
    418       delete(tecplot);
    419     }
    420     if (DoRaster3DOutput) {
    421       string OutputName(filename);
    422       OutputName.append(Raster3DSuffix);
    423       ofstream *rasterplot = new ofstream(OutputName.c_str());
    424       WriteRaster3dFile(rasterplot, TesselStruct, mol);
    425       rasterplot->close();
    426       delete(rasterplot);
    427     }
    428   }
    429 
     397  StoreTrianglesinFile(mol, TesselStruct, filename, "");
    430398
    431399  // free reference lists
     
    678646/** Creates multiples of the by \a *mol given cluster and suspends them in water with a given final density.
    679647 * We get cluster volume by VolumeOfConvexEnvelope() and its diameters by GetDiametersOfCluster()
     648 * TODO: Here, we need a VolumeOfGeneralEnvelope (i.e. non-convex one)
    680649 * \param *out output stream for debugging
    681650 * \param *configuration needed for path to store convex envelope file
     
    695664  int repetition[NDIM] = { 1, 1, 1 };
    696665  int TotalNoClusters = 1;
    697   atom *Walker = NULL;
    698666  double totalmass = 0.;
    699667  double clustervolume = 0.;
     
    706674  GreatestDiameter = GetDiametersOfCluster(BoundaryPoints, mol, TesselStruct, IsAngstroem);
    707675  BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    708   LinkedCell LCList(mol, 10.);
    709   FindConvexBorder(mol, TesselStruct, &LCList, NULL);
     676  LinkedCell *LCList = new LinkedCell(mol, 10.);
     677  FindConvexBorder(mol, TesselStruct, (const LinkedCell *&)LCList, NULL);
     678  delete (LCList);
     679
    710680
    711681  // some preparations beforehand
     
    719689
    720690  // sum up the atomic masses
    721   Walker = mol->start;
    722   while (Walker->next != mol->end) {
    723       Walker = Walker->next;
    724       totalmass += Walker->type->mass;
     691  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     692      totalmass += (*iter)->type->mass;
    725693  }
    726694  DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl);
     
    804772  Vector Inserter;
    805773  double FillIt = false;
    806   atom *Walker = NULL;
    807774  bond *Binder = NULL;
    808775  double phi[NDIM];
     
    811778
    812779  for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++)
    813     if ((*ListRunner)->AtomCount > 0) {
     780    if ((*ListRunner)->getAtomCount() > 0) {
    814781      DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);
    815782      LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list
     
    822789  filler->CenterEdge(&Inserter);
    823790  filler->Center.Zero();
     791  const int FillerCount = filler->getAtomCount();
    824792  DoLog(2) && (Log() << Verbose(2) << "INFO: Filler molecule has the following bonds:" << endl);
    825   Binder = filler->first;
    826   while(Binder->next != filler->last) {
    827     Binder = Binder->next;
    828     DoLog(2) && (Log() << Verbose(2) << "  " << *Binder << endl);
    829   }
    830 
    831   filler->CountAtoms();
    832   atom * CopyAtoms[filler->AtomCount];
     793  for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner)
     794    for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
     795      if ((*BondRunner)->leftatom == *AtomRunner)
     796        DoLog(2) && (Log() << Verbose(2) << "  " << *(*BondRunner) << endl);
     797
     798  atom * CopyAtoms[FillerCount];
    833799
    834800  // calculate filler grid in [0,1]^3
     
    855821
    856822        // go through all atoms
    857         for (int i=0;i<filler->AtomCount;i++)
     823        for (int i=0;i<FillerCount;i++)
    858824          CopyAtoms[i] = NULL;
    859         Walker = filler->start;
    860         while (Walker->next != filler->end) {
    861           Walker = Walker->next;
     825        for(molecule::const_iterator iter = filler->begin(); iter !=filler->end();++iter){
    862826
    863827          // create atomic random translation vector ...
     
    883847
    884848          // ... and put at new position
    885           Inserter = Walker->x;
     849          Inserter = (*iter)->x;
    886850          if (DoRandomRotation)
    887851            Inserter.MatrixMultiplication(Rotations);
     
    907871            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl);
    908872            // copy atom ...
    909             CopyAtoms[Walker->nr] = Walker->clone();
    910             CopyAtoms[Walker->nr]->x = Inserter;
    911             Filling->AddAtom(CopyAtoms[Walker->nr]);
    912             DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);
     873            CopyAtoms[(*iter)->nr] = (*iter)->clone();
     874            CopyAtoms[(*iter)->nr]->x = Inserter;
     875            Filling->AddAtom(CopyAtoms[(*iter)->nr]);
     876            DoLog(4) && (Log() << Verbose(4) << "Filling atom " << **iter << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[(*iter)->nr]->x) << "." << endl);
    913877          } else {
    914878            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl);
    915             CopyAtoms[Walker->nr] = NULL;
     879            CopyAtoms[(*iter)->nr] = NULL;
    916880            continue;
    917881          }
    918882        }
    919883        // go through all bonds and add as well
    920         Binder = filler->first;
    921         while(Binder->next != filler->last) {
    922           Binder = Binder->next;
    923           if ((CopyAtoms[Binder->leftatom->nr] != NULL) && (CopyAtoms[Binder->rightatom->nr] != NULL)) {
    924             Log()  << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
    925             Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
    926           }
    927         }
     884        for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner)
     885          for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
     886            if ((*BondRunner)->leftatom == *AtomRunner) {
     887              Binder = (*BondRunner);
     888              if ((CopyAtoms[Binder->leftatom->nr] != NULL) && (CopyAtoms[Binder->rightatom->nr] != NULL)) {
     889                Log()  << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
     890                Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
     891              }
     892            }
    928893      }
    929   Free(&M);
    930   Free(&MInverse);
     894  delete[](M);
     895  delete[](MInverse);
    931896
    932897  return Filling;
     
    952917  bool TesselationFailFlag = false;
    953918
     919  mol->getAtomCount();
     920
    954921  if (TesselStruct == NULL) {
    955922    DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl);
     
    1023990//  // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
    1024991//  //->InsertStraddlingPoints(mol, LCList);
    1025 //  mol->GoToFirst();
     992//  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    1026993//  class TesselPoint *Runner = NULL;
    1027 //  while (!mol->IsEnd()) {
    1028 //    Runner = mol->GetPoint();
     994//    Runner = *iter;
    1029995//    Log() << Verbose(1) << "Checking on " << Runner->Name << " ... " << endl;
    1030996//    if (!->IsInnerPoint(Runner, LCList)) {
     
    10341000//      Log() << Verbose(2) << Runner->Name << " is inside of or on envelope." << endl;
    10351001//    }
    1036 //    mol->GoToNext();
    10371002//  }
    10381003
     
    10431008  status = CheckListOfBaselines(TesselStruct);
    10441009
     1010  cout << "before correction" << endl;
     1011
    10451012  // store before correction
    1046   StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1013  StoreTrianglesinFile(mol, TesselStruct, filename, "");
    10471014
    10481015//  // correct degenerated polygons
     
    10541021  // write final envelope
    10551022  CalculateConcavityPerBoundaryPoint(TesselStruct);
    1056   StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1023  cout << "after correction" << endl;
     1024  StoreTrianglesinFile(mol, TesselStruct, filename, "");
    10571025
    10581026  if (freeLC)
Note: See TracChangeset for help on using the changeset viewer.