Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r44fd95 r196a5a  
    22#include "boundary.hpp"
    33
    4 #define DEBUG 1
     4#define DEBUG 0
    55
    66// ======================================== Points on Boundary =================================
     
    14221422 * @param c vector third point of triangle
    14231423 * @param Direction vector indicates up/down
     1424 * @param AlternativeDirection vecotr, needed in case the triangles have 90 deg angle
    14241425 * @param Halfplaneindicator double indicates whether Direction is up or down
     1426 * @param AlternativeIndicator doube indicates in case of orthogonal triangles which direction of AlternativeDirection is suitable
    14251427 * @param alpha double angle at a
    14261428 * @param beta double, angle at b
     
    14301432 */
    14311433
    1432   void Get_center_of_sphere(Vector* Center, Vector a, Vector b, Vector c, Vector* Direction, double HalfplaneIndicator,
    1433       double alpha, double beta, double gamma, double RADIUS, double Umkreisradius)
     1434  void Get_center_of_sphere(Vector* Center, Vector a, Vector b, Vector c, Vector* Direction, Vector* AlternativeDirection,
     1435      double HalfplaneIndicator, double AlternativeIndicator, double alpha, double beta, double gamma, double RADIUS, double Umkreisradius)
    14341436  {
    14351437    Vector TempNormal, helper;
    14361438    double Restradius;
    1437     cout << Verbose(3) << "Begin of Get_center_of_sphere.\n";
     1439
    14381440    *Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ;
    1439     Center->Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
     1441    Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    14401442    // Here we calculated center of circumscribing circle, using barycentric coordinates
    1441     cout << Verbose(4) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n";
    14421443
    14431444    TempNormal.CopyVector(&a);
     
    14461447    helper.SubtractVector(&c);
    14471448    TempNormal.VectorProduct(&helper);
    1448     if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
     1449    if (fabs(HalfplaneIndicator) < MYEPSILON)
    14491450      {
    1450         TempNormal.Scale(-1);
     1451        if ((TempNormal.ScalarProduct(AlternativeDirection) <0 and AlternativeIndicator >0) or (TempNormal.ScalarProduct(AlternativeDirection) >0 and AlternativeIndicator <0))
     1452          {
     1453            TempNormal.Scale(-1);
     1454          }
     1455      }
     1456    else
     1457      {
     1458        if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
     1459          {
     1460            TempNormal.Scale(-1);
     1461          }
    14511462      }
    14521463
    14531464    TempNormal.Normalize();
    14541465    Restradius = sqrt(RADIUS*RADIUS - Umkreisradius*Umkreisradius);
    1455     cout << Verbose(4) << "Height of center of circumference to center of sphere is " << Restradius << ".\n";
    14561466    TempNormal.Scale(Restradius);
    1457     cout << Verbose(4) << "Shift vector to sphere of circumference is " << TempNormal << ".\n";
    14581467
    14591468    Center->AddVector(&TempNormal);
    1460     cout << Verbose(4) << "Center of sphere of circumference is " << *Center << ".\n";
    1461     cout << Verbose(3) << "End of Get_center_of_sphere.\n";
    14621469  }
    14631470  ;
     
    14741481 * @param a first point
    14751482 * @param b second point
     1483 * *param c atom old third point of old triangle
    14761484 * @param Candidate base point along whose bonds to start looking from
    14771485 * @param Parent point to avoid during search as its wrong direction
     
    14871495 */
    14881496
    1489 void Find_next_suitable_point_via_Angle_of_Sphere(atom* a, atom* b, atom* Candidate, atom* Parent,
     1497void Find_next_suitable_point_via_Angle_of_Sphere(atom* a, atom* b, atom* c, atom* Candidate, atom* Parent,
    14901498    int RecursionLevel, Vector *Chord, Vector *direction1, Vector *OldNormal, Vector ReferencePoint,
    14911499    atom*& Opt_Candidate, double *Storage, const double RADIUS, molecule* mol)
    14921500{
    1493   cout << Verbose(2) << "Begin of Find_next_suitable_point_via_Angle_of_Sphere, recursion level " << RecursionLevel << ".\n";
    1494   cout << Verbose(3) << "Candidate is "<< *Candidate << endl;
    1495   cout << Verbose(4) << "Baseline vector is " << *Chord << "." << endl;
    1496   cout << Verbose(4) << "ReferencePoint is " << ReferencePoint << "." << endl;
    1497   cout << Verbose(4) << "Normal of base triangle is " << *OldNormal << "." << endl;
    1498   cout << Verbose(4) << "Search direction is " << *direction1 << "." << endl;
     1501  //cout << "ReferencePoint is " << ReferencePoint.x[0] << " "<< ReferencePoint.x[1] << " "<< ReferencePoint.x[2] << " "<< endl;
    14991502  /* OldNormal is normal vector on the old triangle
    15001503   * direction1 is normal on the triangle line, from which we come, as well as on OldNormal.
     
    15091512  double CurrentEpsilon = 0.1;
    15101513  double alpha, beta, gamma, SideA, SideB, SideC, sign, Umkreisradius, Restradius, Distance;
    1511   double BallAngle;
     1514  double BallAngle, AlternativeSign;
    15121515  atom *Walker; // variable atom point
    15131516
    15141517
    1515   if (a != Candidate and b != Candidate)
    1516     {
    1517       cout << Verbose(3) << "We have a unique candidate!" << endl;
    1518       dif_a.CopyVector(&(a->x));
    1519       dif_a.SubtractVector(&(Candidate->x));
    1520       dif_b.CopyVector(&(b->x));
    1521       dif_b.SubtractVector(&(Candidate->x));
    1522       AngleCheck.CopyVector(&(Candidate->x));
    1523       AngleCheck.SubtractVector(&(a->x));
    1524       AngleCheck.ProjectOntoPlane(Chord);
    1525 
    1526       SideA = dif_b.Norm();
    1527       SideB = dif_a.Norm();
    1528       SideC = Chord->Norm();
    1529       //Chord->Scale(-1);
    1530 
    1531       alpha = Chord->Angle(&dif_a);
    1532       beta = M_PI - Chord->Angle(&dif_b);
    1533       gamma = dif_a.Angle(&dif_b);
    1534 
    1535       cout << Verbose(2) << "Base triangle has sides " << dif_a << ", " << dif_b << ", " << *Chord << " with angles " << alpha/M_PI*180. << ", " << beta/M_PI*180. << ", " << gamma/M_PI*180. << "." << endl;
    1536 
    1537       if (fabs(M_PI - alpha - beta - gamma) > MYEPSILON)
    1538         cerr << Verbose(0) << "WARNING: sum of angles for candidate triangle " << (alpha + beta + gamma)/M_PI*180. << " != 180.\n";
     1518  dif_a.CopyVector(&(a->x));
     1519  dif_a.SubtractVector(&(Candidate->x));
     1520  dif_b.CopyVector(&(b->x));
     1521  dif_b.SubtractVector(&(Candidate->x));
     1522  AngleCheck.CopyVector(&(Candidate->x));
     1523  AngleCheck.SubtractVector(&(a->x));
     1524  AngleCheck.ProjectOntoPlane(Chord);
     1525
     1526  SideA = dif_b.Norm();
     1527  SideB = dif_a.Norm();
     1528  SideC = Chord->Norm();
     1529  //Chord->Scale(-1);
     1530
     1531  alpha = Chord->Angle(&dif_a);
     1532  beta = M_PI - Chord->Angle(&dif_b);
     1533  gamma = dif_a.Angle(&dif_b);
     1534
     1535
     1536  if (a != Candidate and b != Candidate and c != Candidate)
     1537    {
    15391538
    15401539      Umkreisradius = SideA / 2.0 / sin(alpha);
     
    15451544      if (Umkreisradius < RADIUS) //Checking whether ball will at least rest on points.
    15461545        {
    1547           cout << Verbose(3) << "Circle of circumference would fit: " << Umkreisradius << " < " << RADIUS << "." << endl;
     1546          cout << Verbose(1) << "Candidate is "<< *Candidate << endl;
    15481547          sign = AngleCheck.ScalarProduct(direction1);
    1549           if (fabs(sign) < MYEPSILON)
    1550             sign = 0;
    1551           else
    1552             sign /= fabs(sign); // +1 if in direction of triangle plane, -1 if in other direction...
    1553           if (sign >= 0)
     1548          if (fabs(sign)<MYEPSILON)
    15541549            {
    1555             cout << Verbose(3) << "Candidate is in search direction: " << sign << "." << endl;
    1556 
    1557             Get_center_of_sphere(&Mittelpunkt, (a->x), (b->x), (Candidate->x), OldNormal, sign, alpha, beta, gamma, RADIUS, Umkreisradius);
    1558 
    1559             AngleCheck.CopyVector(&ReferencePoint);
    1560             AngleCheck.Scale(-1);
    1561             //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
    1562             AngleCheck.AddVector(&Mittelpunkt);
    1563             //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
    1564             cout << Verbose(4) << "Reference vector to sphere's center is " << AngleCheck << "." << endl;
    1565 
    1566             BallAngle = AngleCheck.Angle(OldNormal);
    1567             cout << Verbose(3) << "Angle between normal of base triangle and center of ball sphere is :" << BallAngle << "." << endl;
    1568   //          cout << "direction1 is " << direction1->x[0] <<" "<< direction1->x[1] <<" "<< direction1->x[2] <<" " << endl;
    1569   //          cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
    1570             sign = AngleCheck.ScalarProduct(direction1);
    1571             if (fabs(sign) < MYEPSILON)
    1572               sign = 0;
    1573             else
    1574               sign /= fabs(sign);
    1575 
    1576 
    1577               if (Storage[0]< -1.5) // first Candidate at all
     1550              if (AngleCheck.ScalarProduct(OldNormal)<0)
    15781551                {
    1579 
    1580                   cout << Verbose(2) << "First good candidate is " << *Candidate << " with ";
    1581                   Opt_Candidate = Candidate;
    1582                   Storage[0] = sign;
    1583                   Storage[1] = BallAngle;
    1584                   cout << " angle " << Storage[1] << " and Up/Down "
    1585                     << Storage[0] << endl;
     1552                  sign =0;
     1553                  AlternativeSign=1;
    15861554                }
    15871555              else
    15881556                {
    1589                   if ( Storage[1] > BallAngle)
     1557                  sign =0;
     1558                  AlternativeSign=-1;
     1559                }
     1560            }
     1561          else
     1562            {
     1563              sign /= fabs(sign);
     1564            }
     1565
     1566
     1567
     1568          Get_center_of_sphere(&Mittelpunkt, (a->x), (b->x), (Candidate->x), OldNormal, direction1, sign, AlternativeSign, alpha, beta, gamma, RADIUS, Umkreisradius);
     1569
     1570          AngleCheck.CopyVector(&ReferencePoint);
     1571          AngleCheck.Scale(-1);
     1572          //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1573          AngleCheck.AddVector(&Mittelpunkt);
     1574          //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1575
     1576          BallAngle = AngleCheck.Angle(OldNormal);
     1577
     1578          //cout << "direction1 is " << direction1->x[0] <<" "<< direction1->x[1] <<" "<< direction1->x[2] <<" " << endl;
     1579          //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1580
     1581          cout << Verbose(1) << "BallAngle is " << BallAngle << " Sign is " << sign << endl;
     1582
     1583          if (AngleCheck.ScalarProduct(direction1) >=0)
     1584            {
     1585              if (Storage[0]< -1.5) // first Candidate at all
     1586                {
     1587
     1588                  cout << "Next better candidate is " << *Candidate << " with ";
     1589                  Opt_Candidate = Candidate;
     1590                  Storage[0] = sign;
     1591                  Storage[1] = AlternativeSign;
     1592                  Storage[2] = BallAngle;
     1593                  cout << "Angle is " << Storage[2] << ", Halbraum ist "
     1594                    << Storage[0] << endl;
     1595
     1596
     1597                }
     1598              else
     1599                {
     1600                  if ( Storage[2] > BallAngle)
    15901601                    {
    1591                       cout << Verbose(2) << "Next better candidate is " << *Candidate << " with ";
     1602                      cout << "Next better candidate is " << *Candidate << " with ";
    15921603                      Opt_Candidate = Candidate;
    15931604                      Storage[0] = sign;
    1594                       Storage[1] = BallAngle;
    1595                       cout << " angle " << Storage[1] << " and Up/Down "
     1605                      Storage[1] = AlternativeSign;
     1606                      Storage[2] = BallAngle;
     1607                      cout << "Angle is " << Storage[2] << ", Halbraum ist "
    15961608                        << Storage[0] << endl;
    15971609                    }
    15981610                  else
    15991611                    {
    1600                       if (DEBUG)
    1601                         {
    1602                           cout << Verbose(3) << *Candidate << " looses against better candidate " << *Opt_Candidate << "." << endl;
    1603                         }
     1612                      //if (DEBUG)
     1613                        cout << "Looses to better candidate" << endl;
     1614
    16041615                    }
    16051616                }
     
    16071618            else
    16081619              {
    1609               if (DEBUG)
    1610                 {
    1611                   cout << Verbose(3) << *Candidate << " refused due to Up/Down sign which is " << sign << endl;
    1612                 }
     1620                //if (DEBUG)
     1621                  cout << "Refused due to bad direction of ball centre." << endl;
    16131622              }
    16141623          }
    16151624        else
    16161625          {
    1617             if (DEBUG)
    1618               {
    1619                 cout << Verbose(3) << *Candidate << " would have circumference of " << Umkreisradius << " bigger than ball's radius " << RADIUS << "." << endl;
    1620               }
     1626            //if (DEBUG)
     1627              cout << "Doesn't satisfy requirements for circumscribing circle" << endl;
    16211628          }
    16221629      }
    16231630    else
    16241631      {
    1625         if (DEBUG)
    1626           {
    1627             cout << Verbose(3) << *Candidate << " is either " << *a << " or " << *b << "." << endl;
    1628           }
     1632        //if (DEBUG)
     1633          cout << "identisch mit Ursprungslinie" << endl;
     1634
    16291635      }
    16301636
    16311637
    16321638
    1633   if (RecursionLevel < 7) // Five is the recursion level threshold.
     1639  if (RecursionLevel < 9) // Seven is the recursion level threshold.
    16341640    {
    16351641      for (int i = 0; i < mol->NumberOfBondsPerAtom[Candidate->nr]; i++) // go through all bond
     
    16431649          else
    16441650            {
    1645               Find_next_suitable_point_via_Angle_of_Sphere(a, b, Walker, Candidate, RecursionLevel
     1651              Find_next_suitable_point_via_Angle_of_Sphere(a, b, c, Walker, Candidate, RecursionLevel
    16461652                  + 1, Chord, direction1, OldNormal, ReferencePoint, Opt_Candidate, Storage, RADIUS,
    16471653                  mol); //call function again
     
    16491655        }
    16501656    }
    1651   cout << Verbose(2) << "End of Find_next_suitable_point_via_Angle_of_Sphere, recursion level " << RecursionLevel << ".\n";
    16521657}
    16531658;
     
    17711776          d1->ProjectOntoPlane(&AngleCheckReference);
    17721777          sign = AngleCheck.ScalarProduct(d1);
    1773           if (fabs(sign) < MYEPSILON)
    1774             sign = 0;
    1775           else
    1776             sign /= fabs(sign); // +1 if in direction of triangle plane, -1 if in other direction...
     1778          sign /= fabs(sign); // +1 if in direction of triangle plane, -1 if in other direction...
    17771779
    17781780
     
    19321934    const double& RADIUS, int N)
    19331935{
    1934   cout << Verbose(1) << "Begin of Find_next_suitable_triangle\n";
     1936  cout << Verbose(1) << "Looking for next suitable triangle \n";
    19351937  Vector direction1;
    19361938  Vector helper;
     
    19381940  ofstream *tempstream = NULL;
    19391941  char filename[255];
    1940   double tmp;
    1941   //atom* Walker;
    1942 
    1943   double Storage[2];
     1942  atom* OldThirdPoint;
     1943
     1944  double Storage[3];
    19441945  Storage[0] = -2.; // This direction is either +1 or -1 one, so any result will take precedence over initial values
    1945   Storage[1] = 9999999.; // This is also lower then any value produced by an eligible atom, which are all positive
     1946  Storage[1] = -2.; // This is also lower then any value produced by an eligible atom, which are all positive
     1947  Storage[2] = 9999999.;
    19461948  atom* Opt_Candidate = NULL;
    19471949  Vector Opt_Mittelpunkt;
    19481950
    1949   cout << Verbose(1) << "Current baseline is " << Line << " of triangle " << T << "." << endl;
    1950 
     1951  cout << Verbose(1) << "Constructing helpful vectors ... " << endl;
    19511952  helper.CopyVector(&(Line.endpoints[0]->node->x));
    19521953  for (int i = 0; i < 3; i++)
     
    19551956          && T.endpoints[i]->node->nr != Line.endpoints[1]->node->nr)
    19561957        {
     1958          OldThirdPoint = T.endpoints[i]->node;
    19571959          helper.SubtractVector(&T.endpoints[i]->node->x);
    19581960          break;
     
    19681970      direction1.Scale(-1);
    19691971    }
    1970   cout << Verbose(2) << "Looking in direction " << direction1 << " for candidates.\n";
    19711972
    19721973  Chord.CopyVector(&(Line.endpoints[0]->node->x)); // bring into calling function
    19731974  Chord.SubtractVector(&(Line.endpoints[1]->node->x));
    1974   cout << Verbose(2) << "Baseline vector is " << Chord << ".\n";
    1975 
    1976 
    1977   Vector Umkreismittelpunkt, a, b, c;
    1978   double alpha, beta, gamma;
    1979   a.CopyVector(&(T.endpoints[0]->node->x));
    1980   b.CopyVector(&(T.endpoints[1]->node->x));
    1981   c.CopyVector(&(T.endpoints[2]->node->x));
    1982   a.SubtractVector(&(T.endpoints[1]->node->x));
    1983   b.SubtractVector(&(T.endpoints[2]->node->x));
    1984   c.SubtractVector(&(T.endpoints[0]->node->x));
    1985 
    1986   alpha = a.Angle(&c) - M_PI/2.;
    1987   beta = b.Angle(&a);
    1988   gamma = c.Angle(&b) - M_PI/2.;
    1989   if (fabs(M_PI - alpha - beta - gamma) > MYEPSILON)
    1990     cerr << Verbose(0) << "WARNING: sum of angles for candidate triangle " << (alpha + beta + gamma)/M_PI*180. << " != 180.\n";
    1991 
    1992   cout << Verbose(2) << "Base triangle has sides " << a << ", " << b << ", " << c << " with angles " << alpha/M_PI*180. << ", " << beta/M_PI*180. << ", " << gamma/M_PI*180. << "." << endl;
    1993   Umkreismittelpunkt = (T.endpoints[0]->node->x) * sin(2.*alpha) + T.endpoints[1]->node->x * sin(2.*beta) + (T.endpoints[2]->node->x) * sin(2.*gamma) ;
    1994   Umkreismittelpunkt.Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
    1995   cout << Verbose(2) << "Center of circumference is " << Umkreismittelpunkt << "." << endl;
    1996   if (DEBUG)
    1997     cout << Verbose(3) << "Check of relative endpoints (same distance, equally spreaded): "<< endl;
    1998   tmp = 0;
    1999   for (int i=0;i<NDIM;i++) {
    2000     helper.CopyVector(&T.endpoints[i]->node->x);
    2001     helper.SubtractVector(&Umkreismittelpunkt);
    2002     if (DEBUG)
    2003       cout << Verbose(3) << "Endpoint[" << i << "]: " << helper << " with length " << helper.Norm() << "." << endl;
    2004     if (tmp == 0) // set on first time for comparison against next ones
    2005       tmp = helper.Norm();
    2006     if (fabs(helper.Norm() - tmp) > MYEPSILON)
    2007       cerr << Verbose(1) << "WARNING: center of circumference is wrong!" << endl;
    2008   }
     1975
     1976
     1977    Vector Umkreismittelpunkt, a, b, c;
     1978    double alpha, beta, gamma;
     1979    a.CopyVector(&(T.endpoints[0]->node->x));
     1980    b.CopyVector(&(T.endpoints[1]->node->x));
     1981    c.CopyVector(&(T.endpoints[2]->node->x));
     1982    a.SubtractVector(&(T.endpoints[1]->node->x));
     1983    b.SubtractVector(&(T.endpoints[2]->node->x));
     1984    c.SubtractVector(&(T.endpoints[0]->node->x));
     1985
     1986    alpha = M_PI - a.Angle(&c);
     1987    beta = M_PI - b.Angle(&a);
     1988    gamma = M_PI - c.Angle(&b);
     1989
     1990    Umkreismittelpunkt = (T.endpoints[0]->node->x) * sin(2.*alpha) + T.endpoints[1]->node->x * sin(2.*beta) + (T.endpoints[2]->node->x) * sin(2.*gamma) ;
     1991    //cout << "UmkreisMittelpunkt is " << Umkreismittelpunkt.x[0] << " "<< Umkreismittelpunkt.x[1] << " "<< Umkreismittelpunkt.x[2] << " "<< endl;
     1992    Umkreismittelpunkt.Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
     1993    cout << "UmkreisMittelpunkt is " << Umkreismittelpunkt.x[0] << " "<< Umkreismittelpunkt.x[1] << " "<< Umkreismittelpunkt.x[2] << " "<< endl;
     1994    cout << " We look over line " << Line << " in direction " << direction1.x[0] << " " << direction1.x[1] << " " << direction1.x[2] << " " << endl;
     1995    cout << " Old Normal is " <<  (T.NormalVector.x)[0] << " " << T.NormalVector.x[1] << " " << (T.NormalVector.x)[2] << " " << endl;
     1996
    20091997
    20101998  cout << Verbose(1) << "Looking for third point candidates for triangle ... " << endl;
    20111999
    2012   Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node,
     2000  Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node, OldThirdPoint,
    20132001      Line.endpoints[0]->node, Line.endpoints[1]->node, 0, &Chord, &direction1,
    20142002      &(T.NormalVector), Umkreismittelpunkt, Opt_Candidate, Storage, RADIUS, mol);
    2015   Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node,
     2003  Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node, OldThirdPoint,
    20162004      Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1,
    20172005      &(T.NormalVector), Umkreismittelpunkt, Opt_Candidate, Storage, RADIUS, mol);
    20182006
    20192007
    2020   if ((TrianglesOnBoundaryCount % 10) == 0)
    2021     {
    2022     cout << Verbose(1) << "Writing temporary non convex hull to file testEnvelope-" << TriangleFilesWritten << "d.dat.\n";
     2008      cout << "Letzter Winkel bei " << TrianglesOnBoundaryCount << " Winkel ist " << Storage[2] << endl;
     2009
     2010
     2011  if ((TrianglesOnBoundaryCount % 1) == 0)
     2012    {
    20232013    sprintf(filename, "testEnvelope-%d.dat", TriangleFilesWritten);
    20242014    tempstream = new ofstream(filename, ios::trunc);
     
    20292019  }
    20302020
    2031   if (TrianglesOnBoundaryCount >1000 )
    2032     {
    2033       cerr << Verbose(0)
    2034           << "WARNING: Already more than " << TrianglesOnBoundaryCount-1 << "triangles, construction probably has crashed." << endl;
     2021  if (TrianglesOnBoundaryCount >189 and TrianglesOnBoundaryCount < 200 )
     2022    {
     2023      cout << Verbose(1)
     2024          << "No new Atom found, triangle construction will crash" << endl;
    20352025      write_tecplot_file(out, tecplot, this, mol, TriangleFilesWritten);
    2036       cout << Verbose(2) << "This is currently added candidate" << Opt_Candidate << endl;
     2026      cout << "This is currently added candidate" << Opt_Candidate << endl;
    20372027    }
    20382028  // Konstruiere nun neues Dreieck am Ende der Liste der Dreiecke
    20392029
    2040   cout << Verbose(2) << " Optimal candidate is " << *Opt_Candidate << endl;
     2030  cout << " Optimal candidate is " << *Opt_Candidate << endl;
    20412031
    20422032  AddTrianglePoint(Opt_Candidate, 0);
     
    20502040  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    20512041  AddTriangleToLines();
    2052 
    2053   BTS->GetNormalVector(T.NormalVector);
    2054 
    2055 //  if ((BTS->NormalVector.ScalarProduct(&(T.NormalVector)) < 0 && Storage[0] > 0)  ||
    2056 //      (BTS->NormalVector.ScalarProduct(&(T.NormalVector)) > 0 && Storage[0] < 0))
    2057 //    {
    2058 //      BTS->NormalVector.Scale(-1);
    2059 //    };
    2060   cout << Verbose(2) << "New triangle with " << *BTS << "and normal vector " << BTS->NormalVector << " for this triangle ... " << endl;
    2061   cout << Verbose(2) << "We have "<< TrianglesOnBoundaryCount << " for line " << Line << "." << endl;
    2062   cout << Verbose(1) << "End of Find_next_suitable_triangle\n";
     2042  cout << "New triangle with " << *BTS << endl;
     2043  cout << "We have "<< TrianglesOnBoundaryCount << endl;
     2044  cout << Verbose(1) << "Constructing normal vector for this triangle ... " << endl;
     2045
     2046  BTS->GetNormalVector(BTS->NormalVector);
     2047
     2048  if ((BTS->NormalVector.ScalarProduct(&(T.NormalVector)) < 0 && Storage[0] > 0)  ||
     2049      (BTS->NormalVector.ScalarProduct(&(T.NormalVector)) > 0 && Storage[0] < 0) ||
     2050      (fabs(Storage[0]) < MYEPSILON && Storage[1]*BTS->NormalVector.ScalarProduct(&direction1) < 0) )
     2051
     2052    {
     2053      BTS->NormalVector.Scale(-1);
     2054    };
     2055
    20632056}
    20642057;
    20652058
    20662059void Find_second_point_for_Tesselation(atom* a, atom* Candidate, atom* Parent,
    2067     int RecursionLevel, Vector Oben, atom*& Opt_Candidate, double Storage[2],
     2060    int RecursionLevel, Vector Oben, atom*& Opt_Candidate, double Storage[3],
    20682061    molecule* mol, double RADIUS)
    20692062{
    2070   cout << Verbose(2)
    2071       << "Begin of Find_second_point_for_Tesselation, recursive level "
    2072       << RecursionLevel << endl;
     2063  cout << Verbose(1)
     2064      << "Looking for second point of starting triangle, recursive level "
     2065      << RecursionLevel << endl;;
    20732066  int i;
    20742067  Vector AngleCheck;
    20752068  atom* Walker;
    2076   double norm = -1., angle;
     2069  double norm = -1.;
    20772070
    20782071  // check if we only have one unique point yet ...
    20792072  if (a != Candidate)
    20802073    {
    2081     cout << Verbose(3) << "Current candidate is " << *Candidate << ": ";
    20822074      AngleCheck.CopyVector(&(Candidate->x));
    20832075      AngleCheck.SubtractVector(&(a->x));
     
    20862078      if (norm < RADIUS)
    20872079        {
    2088         angle = AngleCheck.Angle(&Oben);
    2089           if (angle < Storage[0])
     2080          if (AngleCheck.Angle(&Oben) < Storage[0])
    20902081            {
    2091               //cout << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
    2092               cout << "Is a better candidate with distance " << norm << " and " << angle << ".\n";
     2082              //cout << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[2]);
     2083              cout << "Next better candidate is " << *Candidate
     2084                  << " with distance " << norm << ".\n";
    20932085              Opt_Candidate = Candidate;
    20942086              Storage[0] = AngleCheck.Angle(&Oben);
    2095               //cout << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[1]);
     2087              //cout << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
    20962088            }
    20972089          else
    20982090            {
    2099               cout << "Looses with angle " << angle << " to a better candidate "
     2091              cout << Verbose(1) << "Supposedly looses to a better candidate "
    21002092                  << *Opt_Candidate << endl;
    21012093            }
     
    21032095      else
    21042096        {
    2105           cout << "Refused due to Radius " << norm
     2097          cout << Verbose(1) << *Candidate << " refused due to Radius " << norm
    21062098              << endl;
    21072099        }
     
    21222114        };
    21232115    };
    2124   cout << Verbose(2) << "End of Find_second_point_for_Tesselation, recursive level "
    2125       << RecursionLevel << endl;
    21262116}
    21272117;
     
    21292119void Tesselation::Find_starting_triangle(molecule* mol, const double RADIUS)
    21302120{
    2131   cout << Verbose(1) << "Begin of Find_starting_triangle\n";
     2121  cout << Verbose(1) << "Looking for starting triangle \n";
    21322122  int i = 0;
    21332123  atom* Walker;
    21342124  atom* FirstPoint;
    21352125  atom* SecondPoint;
    2136   atom* max_index[NDIM];
    2137   double max_coordinate[NDIM];
     2126  atom* max_index[3];
     2127  double max_coordinate[3];
    21382128  Vector Oben;
    21392129  Vector helper;
     
    21482138      max_coordinate[i] = -1;
    21492139    }
    2150   cout << Verbose(2) << "Molecule mol is there and has " << mol->AtomCount
     2140  cout << Verbose(1) << "Molecule mol is there and has " << mol->AtomCount
    21512141      << " Atoms \n";
    21522142
     
    21662156    }
    21672157
    2168   cout << Verbose(2) << "Found maximum coordinates: ";
    2169   for (int i=0;i<NDIM;i++)
    2170     cout << i << ": " << *max_index[i] << "\t";
    2171   cout << endl;
     2158  cout << Verbose(1) << "Found maximum coordinates. " << endl;
    21722159  //Koennen dies fuer alle Richtungen, legen hier erstmal Richtung auf k=0
    21732160  const int k = 1;
     
    21752162  FirstPoint = max_index[k];
    21762163
    2177   cout << Verbose(1) << "Coordinates of start atom " << *FirstPoint << " at " << FirstPoint->x << " with " << mol->NumberOfBondsPerAtom[FirstPoint->nr] << " bonds." << endl;
    2178   double Storage[2];
     2164  cout << Verbose(1) << "Coordinates of start atom " << *FirstPoint << ": "
     2165      << FirstPoint->x.x[0] << endl;
     2166  double Storage[3];
    21792167  atom* Opt_Candidate = NULL;
    21802168  Storage[0] = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
    21812169  Storage[1] = 999999.; // This will be an angle looking for the third point.
     2170  Storage[2] = 999999.;
     2171  cout << Verbose(1) << "Number of Bonds: "
     2172      << mol->NumberOfBondsPerAtom[FirstPoint->nr] << endl;
    21822173
    21832174  Find_second_point_for_Tesselation(FirstPoint, FirstPoint, FirstPoint, 0,
    21842175      Oben, Opt_Candidate, Storage, mol, RADIUS); // we give same point as next candidate as its bonds are looked into in find_second_...
    21852176  SecondPoint = Opt_Candidate;
    2186   cout << Verbose(1) << "Found second point is " << *SecondPoint << " at " << SecondPoint->x << ".\n";
     2177  cout << Verbose(1) << "Found second point is " << *SecondPoint << ".\n";
    21872178
    21882179  helper.CopyVector(&(FirstPoint->x));
     
    21942185  Storage[0] = -2.; // This will indicate the quadrant.
    21952186  Storage[1] = 9999999.; // This will be an angle looking for the third point.
     2187  Storage[2] = 9999999.;
    21962188
    21972189  Chord.CopyVector(&(FirstPoint->x)); // bring into calling function
     
    21992191  // Now, oben and helper are two orthonormalized vectors in the plane defined by Chord (not normalized)
    22002192
    2201   cout << Verbose(2) << "Looking for third point candidates \n";
     2193  cout << Verbose(1) << "Looking for third point candidates \n";
     2194  cout << Verbose(1) << " In direction " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << " " << endl;
    22022195  // look in one direction of baseline for initial candidate
    22032196  Opt_Candidate = NULL;
    22042197  CenterOfFirstLine.CopyVector(&Chord);
    2205   CenterOfFirstLine.Scale(-0.5);
     2198  CenterOfFirstLine.Scale(0.5);
    22062199  CenterOfFirstLine.AddVector(&(SecondPoint->x));
    22072200
    2208   cout << Verbose(1) << "Looking for third point candidates from " << *FirstPoint << " onward ...\n";
    2209   Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, FirstPoint, 0,
     2201  Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, SecondPoint, FirstPoint, 0,
    22102202      &Chord, &helper, &Oben, CenterOfFirstLine,  Opt_Candidate, Storage, RADIUS, mol);
    22112203  // look in other direction of baseline for possible better candidate
    2212   cout << Verbose(1) << "Looking for third point candidates from " << *SecondPoint << " onward ...\n";
    2213   Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, FirstPoint, SecondPoint, 0,
     2204  Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, FirstPoint, SecondPoint, 0,
    22142205      &Chord, &helper, &Oben, CenterOfFirstLine, Opt_Candidate, Storage, RADIUS, mol);
    22152206  cout << Verbose(1) << "Third Point is " << *Opt_Candidate << endl;
    22162207
    22172208  // FOUND Starting Triangle: FirstPoint, SecondPoint, Opt_Candidate
     2209
     2210  cout << Verbose(1) << "The found starting triangle consists of "
     2211      << *FirstPoint << ", " << *SecondPoint << " and " << *Opt_Candidate
     2212      << "." << endl;
    22182213
    22192214  // Finally, we only have to add the found points
     
    22312226  Oben.Scale(-1.);
    22322227  BTS->GetNormalVector(Oben);
    2233   cout << Verbose(0) << "==> The found starting triangle consists of "
    2234       << *FirstPoint << ", " << *SecondPoint << " and " << *Opt_Candidate
    2235       << " with normal vector " << BTS->NormalVector << ".\n";
    2236   cout << Verbose(1) << "End of Find_starting_triangle\n";
    22372228}
    22382229;
     
    22462237  const double RADIUS = 6.;
    22472238  LineMap::iterator baseline;
    2248   cout << Verbose(0) << "Begin of Find_non_convex_border\n";
    2249   bool flag = false;  // marks whether we went once through all baselines without finding any without two triangles
    2250 
    22512239  Tess->Find_starting_triangle(mol, RADIUS);
    22522240
    22532241  baseline = Tess->LinesOnBoundary.begin();
    2254   while ((baseline != Tess->LinesOnBoundary.end()) || (!flag))
     2242  while (baseline != Tess->LinesOnBoundary.end())
    22552243    {
    22562244      if (baseline->second->TrianglesCount == 1)
    22572245        {
     2246          cout << Verbose(1) << "Begin of Tesselation ... " << endl;
    22582247          Tess->Find_next_suitable_triangle(out, tecplot, mol,
    22592248              *(baseline->second),
    22602249              *(((baseline->second->triangles.begin()))->second), RADIUS, N); //the line is there, so there is a triangle, but only one.
    2261           flag = true;
     2250          cout << Verbose(1) << "End of Tesselation ... " << endl;
    22622251        }
    22632252      else
    22642253        {
    2265           cout << Verbose(1) << "Line " << &baseline << " has "
     2254          cout << Verbose(1) << "There is a line with "
    22662255              << baseline->second->TrianglesCount << " triangles adjacent"
    22672256              << endl;
     
    22692258      N++;
    22702259      baseline++;
    2271       if ((baseline == Tess->LinesOnBoundary.end()) && (flag)) {
    2272         baseline = Tess->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
    2273         flag = false;
    2274       }
    2275     }
    2276   cout << Verbose(1) << "Writing final tecplot file\n";
     2260    }
    22772261  write_tecplot_file(out, tecplot, Tess, mol, -1);
    22782262
    2279   cout << Verbose(0) << "End of Find_non_convex_border\n";
    2280 }
    2281 ;
     2263}
     2264;
Note: See TracChangeset for help on using the changeset viewer.