Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/boundary.cpp

    rd6b011 r78dac6  
    118118 * \param *mol molecule structure with atom positions
    119119 */
    120 void WriteVrmlFile(ofstream *out, ofstream *vrmlfile, class Tesselation *Tess, class molecule *mol)
     120void write_vrml_file(ofstream *out, ofstream *vrmlfile, class Tesselation *Tess, class molecule *mol)
    121121{
    122122  atom *Walker = mol->start;
     
    172172 * \param *mol molecule structure with atom positions
    173173 */
    174 void WriteRaster3dFile(ofstream *out, ofstream *rasterfile, class Tesselation *Tess, class molecule *mol)
     174void write_raster3d_file(ofstream *out, ofstream *rasterfile, class Tesselation *Tess, class molecule *mol)
    175175{
    176176  atom *Walker = mol->start;
     
    227227 * \param N arbitrary number to differentiate various zones in the tecplot format
    228228 */
    229 void WriteTecplotFile(ofstream *out, ofstream *tecplot, class Tesselation *TesselStruct, class molecule *mol, int N)
     229void write_tecplot_file(ofstream *out, ofstream *tecplot, class Tesselation *TesselStruct, class molecule *mol, int N)
    230230{
    231231  if ((tecplot != NULL) && (TesselStruct != NULL)) {
     
    308308
    309309      //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    310       if (ProjectedVector.Projection(&AngleReferenceNormalVector) > 0) {
     310      if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
    311311        angle = 2. * M_PI - angle;
    312312      }
     
    440440 * \return *TesselStruct is filled with convex boundary and tesselation is stored under \a *filename.
    441441 */
    442 void FindConvexBorder(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename)
     442void Find_convex_border(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename)
    443443{
    444444  bool BoundaryFreeFlag = false;
    445445  Boundaries *BoundaryPoints = NULL;
    446446
    447   cout << Verbose(1) << "Begin of FindConvexBorder" << endl;
     447  cout << Verbose(1) << "Begin of find_convex_border" << endl;
    448448
    449449  if (mol->TesselStruct != NULL) // free if allocated
     
    509509      OutputName.append(TecplotSuffix);
    510510      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);
    512512      tecplot->close();
    513513      delete(tecplot);
     
    518518      OutputName.append(Raster3DSuffix);
    519519      ofstream *rasterplot = new ofstream(OutputName.c_str());
    520       WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);
     520      write_raster3d_file(out, rasterplot, mol->TesselStruct, mol);
    521521      rasterplot->close();
    522522      delete(rasterplot);
     
    556556      OutputName.append(TecplotSuffix);
    557557      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);
    559559      tecplot->close();
    560560      delete(tecplot);
     
    564564      OutputName.append(Raster3DSuffix);
    565565      ofstream *rasterplot = new ofstream(OutputName.c_str());
    566       WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);
     566      write_raster3d_file(out, rasterplot, mol->TesselStruct, mol);
    567567      rasterplot->close();
    568568      delete(rasterplot);
     
    575575    delete[] (BoundaryPoints);
    576576
    577   cout << Verbose(1) << "End of FindConvexBorder" << endl;
     577  cout << Verbose(1) << "End of find_convex_border" << endl;
    578578};
    579579
     
    620620  }
    621621
     622  //CalculateConcavityPerBoundaryPoint(out, TesselStruct);
     623  StoreTrianglesinFile(out, mol, filename, "-first");
     624
    622625  // 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++;
    631655      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
    670669  LineRunner = TesselStruct->LinesOnBoundary.begin();
    671670  LineAdvance = LineRunner;  // we need an advanced line, as the LineRunner might get removed
     
    673672    LineAdvance++;
    674673    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    }
    679685    LineRunner = LineAdvance;
    680686  }
    681687
     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 */
     701void CalculateConcavityPerBoundaryPoint(ofstream *out, class Tesselation *TesselStruct)
     702{
     703  class BoundaryPointSet *point = NULL;
     704  class BoundaryLineSet *line = NULL;
    682705  // calculate remaining concavity
    683   for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
     706  for (PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
    684707    point = PointRunner->second;
    685708    *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
     
    692715    }
    693716  }
    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 */
     725void StoreTrianglesinFile(ofstream *out, molecule *mol, const char *filename, const char *extraSuffix)
     726{
    695727  // 4. Store triangles in tecplot file
    696728  if (filename != NULL) {
    697729    if (DoTecplotOutput) {
    698730      string OutputName(filename);
    699       OutputName.append("_intermed");
     731      OutputName.append(extraSuffix);
    700732      OutputName.append(TecplotSuffix);
    701733      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);
    703735      tecplot->close();
    704736      delete(tecplot);
     
    706738    if (DoRaster3DOutput) {
    707739      string OutputName(filename);
    708       OutputName.append("_intermed");
     740      OutputName.append(extraSuffix);
    709741      OutputName.append(Raster3DSuffix);
    710742      ofstream *rasterplot = new ofstream(OutputName.c_str());
    711       WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);
     743      write_raster3d_file(out, rasterplot, mol->TesselStruct, mol);
    712744      rasterplot->close();
    713745      delete(rasterplot);
    714746    }
    715747  }
    716 
    717   // third step: IsConvexRectangle
    718   LineRunner = TesselStruct->LinesOnBoundary.begin();
    719   LineAdvance = LineRunner;  // we need an advanced line, as the LineRunner might get removed
    720   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 lines
    730       point = TesselStruct->IsConvexRectangle(out, line);
    731       if (point != NULL)
    732         TesselStruct->RemovePointFromTesselatedSurface(out, point);
    733     }
    734     LineRunner = LineAdvance;
    735   }
    736 
    737   // calculate remaining concavity
    738   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 file
    751   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   // end
    771   *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;
    772   return volume;
    773748};
    774749
     
    804779      G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle
    805780      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));
    807782      h = x.Norm(); // distance of CoG to triangle
    808783      PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
     
    841816  class Tesselation *TesselStruct = NULL;
    842817  LinkedCell LCList(mol, 10.);
    843   FindConvexBorder(out, mol, &LCList, NULL);
     818  Find_convex_border(out, mol, &LCList, NULL);
    844819  double clustervolume;
    845820  if (ClusterVolume == 0)
     
    982957    if ((*ListRunner)->TesselStruct == NULL) {
    983958      *out << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl;
    984       FindNonConvexBorder((ofstream *)&cout, (*ListRunner), LCList[i], NULL, 5.);
     959      Find_non_convex_border((ofstream *)&cout, (*ListRunner), LCList[i], NULL, 5.);
    985960    }
    986961    i++;
     
    11071082 * \para RADIUS radius of the virtual sphere
    11081083 */
    1109 void FindNonConvexBorder(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename, const double RADIUS)
     1084void Find_non_convex_border(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename, const double RADIUS)
    11101085{
    11111086  int N = 0;
     
    11261101  LineMap::iterator baseline;
    11271102  LineMap::iterator testline;
    1128   *out << Verbose(0) << "Begin of FindNonConvexBorder\n";
     1103  *out << Verbose(0) << "Begin of Find_non_convex_border\n";
    11291104  bool flag = false;  // marks whether we went once through all baselines without finding any without two triangles
    11301105  bool failflag = false;
     
    11351110  }
    11361111
    1137   mol->TesselStruct->FindStartingTriangle(out, RADIUS, LCList);
     1112  mol->TesselStruct->Find_starting_triangle(out, RADIUS, LCList);
    11381113
    11391114  baseline = mol->TesselStruct->LinesOnBoundary.begin();
     
    11441119  while ((baseline != mol->TesselStruct->LinesOnBoundary.end()) || (flag)) {
    11451120    if (baseline->second->triangles.size() == 1) {
    1146       failflag = mol->TesselStruct->FindNextSuitableTriangle(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.
    11471122      flag = flag || failflag;
    11481123      if (!failflag)
    1149         cerr << "WARNING: FindNextSuitableTriangle failed." << endl;
     1124        cerr << "WARNING: Find_next_suitable_triangle failed." << endl;
    11501125      // write temporary envelope
    11511126      if ((DoSingleStepOutput && (mol->TesselStruct->TrianglesOnBoundaryCount % SingleStepWidth == 0))) { // if we have a new triangle and want to output each new triangle configuration
     
    11631138            *out << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
    11641139            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);
    11661141            tempstream->close();
    11671142            tempstream->flush();
     
    11771152            *out << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
    11781153            tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    1179             WriteRaster3dFile(out, tempstream, mol->TesselStruct, mol);
     1154            write_raster3d_file(out, tempstream, mol->TesselStruct, mol);
    11801155    //        // include the current position of the virtual sphere in the temporary raster3d file
    11811156    //        // make the circumsphere's center absolute again
     
    12161191  }
    12171192
    1218   // Purges surplus triangles.
    1219   mol->TesselStruct->RemoveDegeneratedTriangles();
    1220 
    12211193  // write final envelope
    12221194  if (filename != 0) {
     
    12261198      OutputName.append(TecplotSuffix);
    12271199      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);
    12291201      tecplot->close();
    12301202      delete(tecplot);
     
    12341206      OutputName.append(Raster3DSuffix);
    12351207      ofstream *raster = new ofstream(OutputName.c_str());
    1236       WriteRaster3dFile(out, raster, mol->TesselStruct, mol);
     1208      write_raster3d_file(out, raster, mol->TesselStruct, mol);
    12371209      raster->close();
    12381210      delete(raster);
     
    12851257//    << "for atom " << a << " (inside)." << endl;
    12861258
     1259
    12871260  if (freeLC)
    12881261    delete(LCList);
    1289   *out << Verbose(0) << "End of FindNonConvexBorder\n";
     1262  *out << Verbose(0) << "End of Find_non_convex_border\n";
    12901263};
    12911264
Note: See TracChangeset for help on using the changeset viewer.