Changes in molecuilder/src/boundary.cpp [d6b011:78dac6]
- File:
-
- 1 edited
-
molecuilder/src/boundary.cpp (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/boundary.cpp
rd6b011 r78dac6 118 118 * \param *mol molecule structure with atom positions 119 119 */ 120 void WriteVrmlFile(ofstream *out, ofstream *vrmlfile, class Tesselation *Tess, class molecule *mol)120 void write_vrml_file(ofstream *out, ofstream *vrmlfile, class Tesselation *Tess, class molecule *mol) 121 121 { 122 122 atom *Walker = mol->start; … … 172 172 * \param *mol molecule structure with atom positions 173 173 */ 174 void WriteRaster3dFile(ofstream *out, ofstream *rasterfile, class Tesselation *Tess, class molecule *mol)174 void write_raster3d_file(ofstream *out, ofstream *rasterfile, class Tesselation *Tess, class molecule *mol) 175 175 { 176 176 atom *Walker = mol->start; … … 227 227 * \param N arbitrary number to differentiate various zones in the tecplot format 228 228 */ 229 void WriteTecplotFile(ofstream *out, ofstream *tecplot, class Tesselation *TesselStruct, class molecule *mol, int N)229 void write_tecplot_file(ofstream *out, ofstream *tecplot, class Tesselation *TesselStruct, class molecule *mol, int N) 230 230 { 231 231 if ((tecplot != NULL) && (TesselStruct != NULL)) { … … 308 308 309 309 //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl; 310 if (ProjectedVector. Projection(&AngleReferenceNormalVector) > 0) {310 if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) { 311 311 angle = 2. * M_PI - angle; 312 312 } … … 440 440 * \return *TesselStruct is filled with convex boundary and tesselation is stored under \a *filename. 441 441 */ 442 void Find ConvexBorder(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename)442 void Find_convex_border(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename) 443 443 { 444 444 bool BoundaryFreeFlag = false; 445 445 Boundaries *BoundaryPoints = NULL; 446 446 447 cout << Verbose(1) << "Begin of FindConvexBorder" << endl;447 cout << Verbose(1) << "Begin of find_convex_border" << endl; 448 448 449 449 if (mol->TesselStruct != NULL) // free if allocated … … 509 509 OutputName.append(TecplotSuffix); 510 510 ofstream *tecplot = new ofstream(OutputName.c_str()); 511 WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, 0);511 write_tecplot_file(out, tecplot, mol->TesselStruct, mol, 0); 512 512 tecplot->close(); 513 513 delete(tecplot); … … 518 518 OutputName.append(Raster3DSuffix); 519 519 ofstream *rasterplot = new ofstream(OutputName.c_str()); 520 WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);520 write_raster3d_file(out, rasterplot, mol->TesselStruct, mol); 521 521 rasterplot->close(); 522 522 delete(rasterplot); … … 556 556 OutputName.append(TecplotSuffix); 557 557 ofstream *tecplot = new ofstream(OutputName.c_str()); 558 WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, 0);558 write_tecplot_file(out, tecplot, mol->TesselStruct, mol, 0); 559 559 tecplot->close(); 560 560 delete(tecplot); … … 564 564 OutputName.append(Raster3DSuffix); 565 565 ofstream *rasterplot = new ofstream(OutputName.c_str()); 566 WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);566 write_raster3d_file(out, rasterplot, mol->TesselStruct, mol); 567 567 rasterplot->close(); 568 568 delete(rasterplot); … … 575 575 delete[] (BoundaryPoints); 576 576 577 cout << Verbose(1) << "End of FindConvexBorder" << endl;577 cout << Verbose(1) << "End of find_convex_border" << endl; 578 578 }; 579 579 … … 620 620 } 621 621 622 //CalculateConcavityPerBoundaryPoint(out, TesselStruct); 623 StoreTrianglesinFile(out, mol, filename, "-first"); 624 622 625 // First step: RemovePointFromTesselatedSurface 623 PointRunner = TesselStruct->PointsOnBoundary.begin(); 624 PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed 625 while (PointRunner != TesselStruct->PointsOnBoundary.end()) { 626 PointAdvance++; 627 point = PointRunner->second; 628 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 629 Concavity = true; 630 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 626 do { 627 Concavity = false; 628 PointRunner = TesselStruct->PointsOnBoundary.begin(); 629 PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed 630 while (PointRunner != TesselStruct->PointsOnBoundary.end()) { 631 PointAdvance++; 632 point = PointRunner->second; 633 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 634 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 635 line = LineRunner->second; 636 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 637 } 638 if (!line->CheckConvexityCriterion(out)) { 639 *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl; 640 // remove the point 641 Concavity = true; 642 TesselStruct->RemovePointFromTesselatedSurface(out, point); 643 } 644 PointRunner = PointAdvance; 645 } 646 647 //CalculateConcavityPerBoundaryPoint(out, TesselStruct); 648 //StoreTrianglesinFile(out, mol, filename, "-second"); 649 650 // second step: PickFarthestofTwoBaselines 651 LineRunner = TesselStruct->LinesOnBoundary.begin(); 652 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 653 while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 654 LineAdvance++; 631 655 line = LineRunner->second; 632 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 633 Concavity = Concavity && (!line->CheckConvexityCriterion(out)); 634 } 635 if (Concavity) { 636 *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl; 637 // remove the point 638 TesselStruct->RemovePointFromTesselatedSurface(out, point); 639 } 640 PointRunner = PointAdvance; 641 } 642 643 644 // // print all lines 645 // LineRunner = TesselStruct->LinesOnBoundary.begin(); 646 // LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 647 // *out << Verbose(1) << "Printing all boundary lines for debugging." << endl; 648 // while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 649 // LineAdvance++; 650 // line = LineRunner->second; 651 // *out << Verbose(2) << "INFO: Current line is " << *line << "." << endl; 652 // if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 653 // *out << Verbose(2) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl; 654 // LineRunner = LineAdvance; 655 // } 656 // 657 // // print all triangles 658 // TriangleRunner = TesselStruct->TrianglesOnBoundary.begin(); 659 // TriangleAdvance = TriangleRunner; // we need an advanced line, as the LineRunner might get removed 660 // *out << Verbose(1) << "Printing all boundary triangles for debugging." << endl; 661 // while (TriangleRunner != TesselStruct->TrianglesOnBoundary.end()) { 662 // TriangleAdvance++; 663 // *out << Verbose(2) << "INFO: Current triangle is " << *(TriangleRunner->second) << "." << endl; 664 // if (TriangleAdvance != TesselStruct->TrianglesOnBoundary.end()) 665 // *out << Verbose(2) << "INFO: Next triangle will be " << *(TriangleAdvance->second) << "." << endl; 666 // TriangleRunner = TriangleAdvance; 667 // } 668 669 // second step: PickFarthestofTwoBaselines 656 *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl; 657 // take highest of both lines 658 if (TesselStruct->IsConvexRectangle(out, line) == NULL) { 659 TesselStruct->PickFarthestofTwoBaselines(out, line); 660 Concavity = true; 661 } 662 LineRunner = LineAdvance; 663 } 664 } while (Concavity); 665 CalculateConcavityPerBoundaryPoint(out, TesselStruct); 666 StoreTrianglesinFile(out, mol, filename, "-third"); 667 668 // third step: IsConvexRectangle 670 669 LineRunner = TesselStruct->LinesOnBoundary.begin(); 671 670 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed … … 673 672 LineAdvance++; 674 673 line = LineRunner->second; 675 *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl; 676 if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 677 // take highest of both lines 678 TesselStruct->PickFarthestofTwoBaselines(out, line); 674 *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl; 675 //if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 676 //*out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl; 677 if (!line->CheckConvexityCriterion(out)) { 678 *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl; 679 680 // take highest of both lines 681 point = TesselStruct->IsConvexRectangle(out, line); 682 if (point != NULL) 683 TesselStruct->RemovePointFromTesselatedSurface(out, point); 684 } 679 685 LineRunner = LineAdvance; 680 686 } 681 687 688 CalculateConcavityPerBoundaryPoint(out, TesselStruct); 689 StoreTrianglesinFile(out, mol, filename, "-fourth"); 690 691 // end 692 *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl; 693 return volume; 694 }; 695 696 /** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation. 697 * Sets BoundaryPointSet::value equal to the number of connected lines that are not convex. 698 * \param *out output stream for debugging 699 * \param *TesselStruct pointer to Tesselation structure 700 */ 701 void CalculateConcavityPerBoundaryPoint(ofstream *out, class Tesselation *TesselStruct) 702 { 703 class BoundaryPointSet *point = NULL; 704 class BoundaryLineSet *line = NULL; 682 705 // calculate remaining concavity 683 for (Point Runner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {706 for (PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 684 707 point = PointRunner->second; 685 708 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; … … 692 715 } 693 716 } 694 717 }; 718 719 /** Stores triangles to file. 720 * \param *out output stream for debugging 721 * \param *mol molecule with atoms and bonds 722 * \param *filename prefix of filename 723 * \param *extraSuffix intermediate suffix 724 */ 725 void StoreTrianglesinFile(ofstream *out, molecule *mol, const char *filename, const char *extraSuffix) 726 { 695 727 // 4. Store triangles in tecplot file 696 728 if (filename != NULL) { 697 729 if (DoTecplotOutput) { 698 730 string OutputName(filename); 699 OutputName.append( "_intermed");731 OutputName.append(extraSuffix); 700 732 OutputName.append(TecplotSuffix); 701 733 ofstream *tecplot = new ofstream(OutputName.c_str()); 702 WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, 0);734 write_tecplot_file(out, tecplot, mol->TesselStruct, mol, 0); 703 735 tecplot->close(); 704 736 delete(tecplot); … … 706 738 if (DoRaster3DOutput) { 707 739 string OutputName(filename); 708 OutputName.append( "_intermed");740 OutputName.append(extraSuffix); 709 741 OutputName.append(Raster3DSuffix); 710 742 ofstream *rasterplot = new ofstream(OutputName.c_str()); 711 WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);743 write_raster3d_file(out, rasterplot, mol->TesselStruct, mol); 712 744 rasterplot->close(); 713 745 delete(rasterplot); 714 746 } 715 747 } 716 717 // third step: IsConvexRectangle718 LineRunner = TesselStruct->LinesOnBoundary.begin();719 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed720 while (LineRunner != TesselStruct->LinesOnBoundary.end()) {721 LineAdvance++;722 line = LineRunner->second;723 *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl;724 if (LineAdvance != TesselStruct->LinesOnBoundary.end())725 *out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl;726 if (!line->CheckConvexityCriterion(out)) {727 *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl;728 729 // take highest of both lines730 point = TesselStruct->IsConvexRectangle(out, line);731 if (point != NULL)732 TesselStruct->RemovePointFromTesselatedSurface(out, point);733 }734 LineRunner = LineAdvance;735 }736 737 // calculate remaining concavity738 for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {739 point = PointRunner->second;740 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;741 point->value = 0;742 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {743 line = LineRunner->second;744 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;745 if (!line->CheckConvexityCriterion(out))746 point->value += 1;747 }748 }749 750 // 4. Store triangles in tecplot file751 if (filename != NULL) {752 if (DoTecplotOutput) {753 string OutputName(filename);754 OutputName.append(TecplotSuffix);755 ofstream *tecplot = new ofstream(OutputName.c_str());756 WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, 0);757 tecplot->close();758 delete(tecplot);759 }760 if (DoRaster3DOutput) {761 string OutputName(filename);762 OutputName.append(Raster3DSuffix);763 ofstream *rasterplot = new ofstream(OutputName.c_str());764 WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);765 rasterplot->close();766 delete(rasterplot);767 }768 }769 770 // end771 *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;772 return volume;773 748 }; 774 749 … … 804 779 G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 805 780 x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node); 806 x.Scale(runner->second->endpoints[1]->node->node-> Projection(&x));781 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x)); 807 782 h = x.Norm(); // distance of CoG to triangle 808 783 PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak) … … 841 816 class Tesselation *TesselStruct = NULL; 842 817 LinkedCell LCList(mol, 10.); 843 Find ConvexBorder(out, mol, &LCList, NULL);818 Find_convex_border(out, mol, &LCList, NULL); 844 819 double clustervolume; 845 820 if (ClusterVolume == 0) … … 982 957 if ((*ListRunner)->TesselStruct == NULL) { 983 958 *out << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl; 984 Find NonConvexBorder((ofstream *)&cout, (*ListRunner), LCList[i], NULL, 5.);959 Find_non_convex_border((ofstream *)&cout, (*ListRunner), LCList[i], NULL, 5.); 985 960 } 986 961 i++; … … 1107 1082 * \para RADIUS radius of the virtual sphere 1108 1083 */ 1109 void Find NonConvexBorder(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename, const double RADIUS)1084 void Find_non_convex_border(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename, const double RADIUS) 1110 1085 { 1111 1086 int N = 0; … … 1126 1101 LineMap::iterator baseline; 1127 1102 LineMap::iterator testline; 1128 *out << Verbose(0) << "Begin of Find NonConvexBorder\n";1103 *out << Verbose(0) << "Begin of Find_non_convex_border\n"; 1129 1104 bool flag = false; // marks whether we went once through all baselines without finding any without two triangles 1130 1105 bool failflag = false; … … 1135 1110 } 1136 1111 1137 mol->TesselStruct->Find StartingTriangle(out, RADIUS, LCList);1112 mol->TesselStruct->Find_starting_triangle(out, RADIUS, LCList); 1138 1113 1139 1114 baseline = mol->TesselStruct->LinesOnBoundary.begin(); … … 1144 1119 while ((baseline != mol->TesselStruct->LinesOnBoundary.end()) || (flag)) { 1145 1120 if (baseline->second->triangles.size() == 1) { 1146 failflag = mol->TesselStruct->Find NextSuitableTriangle(out, *(baseline->second), *(((baseline->second->triangles.begin()))->second), RADIUS, N, LCList); //the line is there, so there is a triangle, but only one.1121 failflag = mol->TesselStruct->Find_next_suitable_triangle(out, *(baseline->second), *(((baseline->second->triangles.begin()))->second), RADIUS, N, LCList); //the line is there, so there is a triangle, but only one. 1147 1122 flag = flag || failflag; 1148 1123 if (!failflag) 1149 cerr << "WARNING: Find NextSuitableTriangle failed." << endl;1124 cerr << "WARNING: Find_next_suitable_triangle failed." << endl; 1150 1125 // write temporary envelope 1151 1126 if ((DoSingleStepOutput && (mol->TesselStruct->TrianglesOnBoundaryCount % SingleStepWidth == 0))) { // if we have a new triangle and want to output each new triangle configuration … … 1163 1138 *out << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n"; 1164 1139 tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc); 1165 WriteTecplotFile(out, tempstream, mol->TesselStruct, mol, TriangleFilesWritten);1140 write_tecplot_file(out, tempstream, mol->TesselStruct, mol, TriangleFilesWritten); 1166 1141 tempstream->close(); 1167 1142 tempstream->flush(); … … 1177 1152 *out << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n"; 1178 1153 tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc); 1179 WriteRaster3dFile(out, tempstream, mol->TesselStruct, mol);1154 write_raster3d_file(out, tempstream, mol->TesselStruct, mol); 1180 1155 // // include the current position of the virtual sphere in the temporary raster3d file 1181 1156 // // make the circumsphere's center absolute again … … 1216 1191 } 1217 1192 1218 // Purges surplus triangles.1219 mol->TesselStruct->RemoveDegeneratedTriangles();1220 1221 1193 // write final envelope 1222 1194 if (filename != 0) { … … 1226 1198 OutputName.append(TecplotSuffix); 1227 1199 ofstream *tecplot = new ofstream(OutputName.c_str()); 1228 WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, -1);1200 write_tecplot_file(out, tecplot, mol->TesselStruct, mol, -1); 1229 1201 tecplot->close(); 1230 1202 delete(tecplot); … … 1234 1206 OutputName.append(Raster3DSuffix); 1235 1207 ofstream *raster = new ofstream(OutputName.c_str()); 1236 WriteRaster3dFile(out, raster, mol->TesselStruct, mol);1208 write_raster3d_file(out, raster, mol->TesselStruct, mol); 1237 1209 raster->close(); 1238 1210 delete(raster); … … 1285 1257 // << "for atom " << a << " (inside)." << endl; 1286 1258 1259 1287 1260 if (freeLC) 1288 1261 delete(LCList); 1289 *out << Verbose(0) << "End of Find NonConvexBorder\n";1262 *out << Verbose(0) << "End of Find_non_convex_border\n"; 1290 1263 }; 1291 1264
Note:
See TracChangeset
for help on using the changeset viewer.
