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