Ignore:
Timestamp:
Oct 19, 2014, 5:13:10 PM (10 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
dfe054
Parents:
c2f306
git-author:
Frederik Heber <heber@…> (09/25/14 18:23:50)
git-committer:
Frederik Heber <heber@…> (10/19/14 17:13:10)
Message:

FIX: RemovePointFromTesselatedSurface() needs to pick smallest angle when polygon is not convex.

  • AddTesselationLine() now returns whether new or present line was used.
  • FIX: Last inner line in closed polygon has been added by one but last triangle already, we added it twice.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tesselation/tesselation.cpp

    rc2f306 r75d42a  
    3535#include "CodePatterns/MemDebug.hpp"
    3636
     37#include <algorithm>
     38#include <boost/foreach.hpp>
    3739#include <fstream>
    3840#include <iomanip>
     41#include <iterator>
    3942#include <sstream>
    4043
     
    731734 * @param *b second endpoint
    732735 * @param n index of Tesselation::BLS giving the line with both endpoints
    733  */
    734 void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     736 * @return true - inserted a new line, false - present line used
     737 */
     738bool Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    735739{
    736740  bool insertNewLine = true;
     
    784788    AddExistingTesselationTriangleLine(WinningLine, n);
    785789  }
     790
     791  return insertNewLine;
    786792}
    787793;
     
    31983204;
    31993205
     3206struct CloserToPiHalf
     3207{
     3208  bool operator()(double angle, double smallestangle) {
     3209    return (fabs(angle - M_PI/2.) < fabs(smallestangle - M_PI/2.));
     3210  }
     3211};
     3212
    32003213/** Removes a boundary point from the envelope while keeping it closed.
    32013214 * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
     
    32623275//  TriangleMap::iterator NumberRunner = Candidates.begin();
    32633276  TesselPointList::iterator StartNode, MiddleNode, EndNode;
    3264   double angle;
    3265   double smallestangle;
    32663277  Vector Point, Reference, OrthogonalVector;
    32673278  if (count > 2) { // less than three triangles, then nothing will be created
     
    32753286      // re-create all triangles by going through connected points list
    32763287      LineList NewLines;
     3288      typedef std::vector<double> angles_t;
     3289      angles_t angles;
    32773290      for (; !connectedPath->empty();) {
    32783291        // search middle node with widest angle to next neighbours
    32793292        EndNode = connectedPath->end();
    3280         smallestangle = 0.;
    32813293        for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
    32823294          LOG(1, "INFO: MiddleNode is " << **MiddleNode << ".");
     
    32963308          OrthogonalVector = ((*MiddleNode)->getPosition()) - OldPoint;
    32973309          OrthogonalVector.MakeNormalTo(Reference);
    3298           angle = GetAngle(Point, Reference, OrthogonalVector);
    3299           //if (angle < M_PI)  // no wrong-sided triangles, please?
    3300           if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
    3301             smallestangle = angle;
    3302             EndNode = MiddleNode;
    3303           }
     3310          angles.push_back( GetAngle(Point, Reference, OrthogonalVector) );
    33043311        }
     3312        const angles_t::const_iterator maxiter = std::max_element(angles.begin(), angles.end());
     3313        angles_t::const_iterator miniter = angles.begin();
     3314        // distinguish between convex and nonconvex polygon
     3315        if (*maxiter > M_PI) {
     3316          // connectedPath is not convex
     3317          miniter = std::min_element(angles.begin(), angles.end());
     3318        } else {
     3319          // is convex
     3320          miniter = std::min_element(angles.begin(), angles.end(), CloserToPiHalf());
     3321        }
     3322        EndNode = connectedPath->begin();
     3323        std::advance(EndNode,
     3324            std::distance(const_cast<const angles_t &>(angles).begin(), miniter));
     3325        angles.clear();
     3326
    33053327        MiddleNode = EndNode;
    3306         if (MiddleNode == connectedPath->end()) {
    3307           ELOG(0, "CRITICAL: Could not find a smallest angle!");
    3308           performCriticalExit();
    3309         }
     3328        ASSERT( MiddleNode == connectedPath->end(),
     3329          "Tesselation::RemovePointFromTesselatedSurface() - Could not find a smallest angle!");
    33103330        StartNode = MiddleNode;
    33113331        if (StartNode == connectedPath->begin())
     
    33473367        LOG(3, "Adding new triangle lines.");
    33483368        AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
    3349         AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
    3350         NewLines.push_back(BLS[1]);
     3369        // line between start and end must be new (except for very last triangle)
     3370        if (AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1))
     3371          NewLines.push_back(BLS[1]);
    33513372        AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    33523373        BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
Note: See TracChangeset for help on using the changeset viewer.