Changes in src/boundary.cpp [112b09:8f215d]
- File:
-
- 1 edited
-
src/boundary.cpp (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/boundary.cpp
r112b09 r8f215d 3 3 * Implementations and super-function for envelopes 4 4 */ 5 6 #include "Helpers/MemDebug.hpp"7 5 8 6 #include "World.hpp" … … 141 139 { 142 140 Info FunctionInfo(__func__); 141 atom *Walker = NULL; 143 142 PointMap PointsOnBoundary; 144 143 LineMap LinesOnBoundary; … … 166 165 167 166 // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours 168 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 169 ProjectedVector = (*iter)->x - (*MolCenter); 167 Walker = mol->start; 168 while (Walker->next != mol->end) { 169 Walker = Walker->next; 170 ProjectedVector = Walker->x - (*MolCenter); 170 171 ProjectedVector.ProjectOntoPlane(AxisVector); 171 172 … … 181 182 angle = 2. * M_PI - angle; 182 183 } 183 DoLog(1) && (Log() << Verbose(1) << "Inserting " << **iter << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);184 BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, (*iter))));184 DoLog(1) && (Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl); 185 BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker))); 185 186 if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity 186 187 DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl); 187 188 DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl); 188 DoLog(2) && (Log() << Verbose(2) << "New vector: " << * *iter << endl);189 DoLog(2) && (Log() << Verbose(2) << "New vector: " << *Walker << endl); 189 190 const double ProjectedVectorNorm = ProjectedVector.NormSquared(); 190 191 if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) { 191 192 BoundaryTestPair.first->second.first = ProjectedVectorNorm; 192 BoundaryTestPair.first->second.second = (*iter);193 BoundaryTestPair.first->second.second = Walker; 193 194 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl); 194 195 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) { 195 helper = (*iter)->x; 196 helper -= *MolCenter; 196 helper = Walker->x - (*MolCenter); 197 197 const double oldhelperNorm = helper.NormSquared(); 198 198 helper = BoundaryTestPair.first->second.second->x - (*MolCenter); 199 199 if (helper.NormSquared() < oldhelperNorm) { 200 BoundaryTestPair.first->second.second = (*iter);200 BoundaryTestPair.first->second.second = Walker; 201 201 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl); 202 202 } else { … … 226 226 do { // do as long as we still throw one out per round 227 227 flag = false; 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++; 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++) { 235 231 // set neighbours correctly 236 232 if (runner == BoundaryPoints[axis].begin()) { … … 240 236 } 241 237 left--; 238 right = runner; 239 right++; 242 240 if (right == BoundaryPoints[axis].end()) { 243 241 right = BoundaryPoints[axis].begin(); 244 LoopOnceDone = true;245 242 } 246 243 // check distance … … 282 279 DoLog(1) && (Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl); 283 280 BoundaryPoints[axis].erase(runner); 284 runner = right;285 281 flag = true; 286 282 } … … 363 359 364 360 // 4. Store triangles in tecplot file 365 StoreTrianglesinFile(mol, TesselStruct, filename, "_intermed"); 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 } 366 381 367 382 // 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 … … 382 397 TesselStruct->FlipBaseline(line); 383 398 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 LinesOnBoundary385 399 } 386 400 } … … 395 409 396 410 // 4. Store triangles in tecplot file 397 StoreTrianglesinFile(mol, TesselStruct, filename, ""); 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 398 430 399 431 // free reference lists … … 646 678 /** Creates multiples of the by \a *mol given cluster and suspends them in water with a given final density. 647 679 * We get cluster volume by VolumeOfConvexEnvelope() and its diameters by GetDiametersOfCluster() 648 * TODO: Here, we need a VolumeOfGeneralEnvelope (i.e. non-convex one)649 680 * \param *out output stream for debugging 650 681 * \param *configuration needed for path to store convex envelope file … … 664 695 int repetition[NDIM] = { 1, 1, 1 }; 665 696 int TotalNoClusters = 1; 697 atom *Walker = NULL; 666 698 double totalmass = 0.; 667 699 double clustervolume = 0.; … … 674 706 GreatestDiameter = GetDiametersOfCluster(BoundaryPoints, mol, TesselStruct, IsAngstroem); 675 707 BoundaryPoints = GetBoundaryPoints(mol, TesselStruct); 676 LinkedCell *LCList = new LinkedCell(mol, 10.); 677 FindConvexBorder(mol, TesselStruct, (const LinkedCell *&)LCList, NULL); 678 delete (LCList); 679 708 LinkedCell LCList(mol, 10.); 709 FindConvexBorder(mol, TesselStruct, &LCList, NULL); 680 710 681 711 // some preparations beforehand … … 689 719 690 720 // sum up the atomic masses 691 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 692 totalmass += (*iter)->type->mass; 721 Walker = mol->start; 722 while (Walker->next != mol->end) { 723 Walker = Walker->next; 724 totalmass += Walker->type->mass; 693 725 } 694 726 DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl); … … 772 804 Vector Inserter; 773 805 double FillIt = false; 806 atom *Walker = NULL; 774 807 bond *Binder = NULL; 775 808 double phi[NDIM]; … … 778 811 779 812 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) 780 if ((*ListRunner)-> getAtomCount()> 0) {813 if ((*ListRunner)->AtomCount > 0) { 781 814 DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl); 782 815 LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list … … 789 822 filler->CenterEdge(&Inserter); 790 823 filler->Center.Zero(); 791 const int FillerCount = filler->getAtomCount();792 824 DoLog(2) && (Log() << Verbose(2) << "INFO: Filler molecule has the following bonds:" << endl); 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]; 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]; 799 833 800 834 // calculate filler grid in [0,1]^3 … … 821 855 822 856 // go through all atoms 823 for (int i=0;i< FillerCount;i++)857 for (int i=0;i<filler->AtomCount;i++) 824 858 CopyAtoms[i] = NULL; 825 for(molecule::const_iterator iter = filler->begin(); iter !=filler->end();++iter){ 859 Walker = filler->start; 860 while (Walker->next != filler->end) { 861 Walker = Walker->next; 826 862 827 863 // create atomic random translation vector ... … … 847 883 848 884 // ... and put at new position 849 Inserter = (*iter)->x;885 Inserter = Walker->x; 850 886 if (DoRandomRotation) 851 887 Inserter.MatrixMultiplication(Rotations); … … 871 907 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl); 872 908 // copy atom ... 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);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); 877 913 } else { 878 914 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl); 879 CopyAtoms[ (*iter)->nr] = NULL;915 CopyAtoms[Walker->nr] = NULL; 880 916 continue; 881 917 } 882 918 } 883 919 // go through all bonds and add as well 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 } 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 } 893 928 } 894 delete[](M);895 delete[](MInverse);929 Free(&M); 930 Free(&MInverse); 896 931 897 932 return Filling; … … 917 952 bool TesselationFailFlag = false; 918 953 919 mol->getAtomCount();920 921 954 if (TesselStruct == NULL) { 922 955 DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl); … … 990 1023 // // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles 991 1024 // //->InsertStraddlingPoints(mol, LCList); 992 // for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {1025 // mol->GoToFirst(); 993 1026 // class TesselPoint *Runner = NULL; 994 // Runner = *iter; 1027 // while (!mol->IsEnd()) { 1028 // Runner = mol->GetPoint(); 995 1029 // Log() << Verbose(1) << "Checking on " << Runner->Name << " ... " << endl; 996 1030 // if (!->IsInnerPoint(Runner, LCList)) { … … 1000 1034 // Log() << Verbose(2) << Runner->Name << " is inside of or on envelope." << endl; 1001 1035 // } 1036 // mol->GoToNext(); 1002 1037 // } 1003 1038 … … 1008 1043 status = CheckListOfBaselines(TesselStruct); 1009 1044 1010 cout << "before correction" << endl;1011 1012 1045 // store before correction 1013 StoreTrianglesinFile(mol, TesselStruct, filename, "");1046 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, ""); 1014 1047 1015 1048 // // correct degenerated polygons … … 1021 1054 // write final envelope 1022 1055 CalculateConcavityPerBoundaryPoint(TesselStruct); 1023 cout << "after correction" << endl; 1024 StoreTrianglesinFile(mol, TesselStruct, filename, ""); 1056 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, ""); 1025 1057 1026 1058 if (freeLC)
Note:
See TracChangeset
for help on using the changeset viewer.
