source: src/Tesselation/TriangleMatcher/Triangle.hpp@ b9d387

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
Last change on this file since b9d387 was 7d146a, checked in by Frederik Heber <heber@…>, 9 years ago

Added TriangleMatcher to safely compare tesselation .dat files.

  • is used in tests/regression Tesselations, tests/Tesselations, and has its own regression test, too.
  • added trianglematcher to testsuite dependencies.
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Triangle.hpp
3 *
4 * Created on: Jun 15, 2015
5 * Author: heber
6 */
7
8#ifndef TRIANGLE_HPP_
9#define TRIANGLE_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <array>
17#include <cassert>
18#include <utility>
19
20#include "types.hpp"
21
22namespace detail {
23
24struct Triangle
25{
26 //!> typedef for the triangle index type
27 typedef size_t index_t;
28
29 //!> typedef for the structure to store triangle indices
30 typedef std::array<index_t, 3> indices_t;
31
32 //!> constant for invalid index
33 enum { INVALIDINDEX=-1 };
34
35 /** Constructor for struct triangle.
36 *
37 */
38 Triangle()
39 {
40 indices = {{
41 (index_t)INVALIDINDEX,
42 (index_t)INVALIDINDEX,
43 (index_t)INVALIDINDEX
44 }};
45 }
46
47 /** Constructor for struct triangle.
48 *
49 * \param _indices initial indices to set
50 */
51 Triangle(const indices_t &_indices) :
52 indices(_indices)
53 {
54 if (!isSorted())
55 sortIndices();
56 }
57
58 /** Setter for the indices of the triangle.
59 *
60 * \param _elements indices to be set (need not be sorted)
61 */
62 void set(const indices_t &_elements) {
63 indices = _elements;
64 if (!isSorted())
65 sortIndices();
66 }
67
68 /** Getter for the indices.
69 *
70 * \return set of sorted indices
71 */
72 const indices_t &get() const {
73 return indices;
74 }
75
76 /** Less comparator for triangle, comparing indices.
77 *
78 * \return true - at least one index in this triangle is smaller
79 */
80 bool operator<(const Triangle &_other) const {
81 return indices < _other.indices;
82 }
83
84 /** Comparator for equivalence of triangle.
85 *
86 * \return true - both index triples are the same
87 */
88 bool operator==(const Triangle &_other) const {
89 return indices == _other.indices;
90 }
91
92 /** Comparator for non-equivalence of triangle.
93 *
94 * \return true - both index triples are not the same
95 */
96 bool operator!=(const Triangle &_other) const {
97 return !(*this == _other);
98 }
99
100private:
101 /** Sort the indices.
102 *
103 */
104 void sortIndices() {
105 std::sort(indices.begin(), indices.end());
106// if (indices[0] > indices[1]) {
107// if (indices[0] > indices[2])
108// std::swap(indices[0], indices[2]);
109// if (indices[0] > indices[1])
110// std::swap(indices[0], indices[1]);
111// } else {
112// // last element in between or up front?
113// if (indices[0] > indices[2]) {
114// std::swap(indices[1], indices[2]);
115// std::swap(indices[0], indices[1]);
116// } else
117// std::swap(indices[1], indices[2]);
118// }
119 assert( isSorted() );
120 }
121
122private:
123 /** Check whether indices are sorted.
124 *
125 * \return true - indices are sorted ascendingly
126 */
127 bool isSorted() const
128 {
129 return (( indices[0] <= indices[1]) && (indices[1] <= indices[2]));
130 }
131
132private:
133 //!> fixed size array for containing indices
134 indices_t indices;
135};
136
137}; /* namespace detail */
138
139std::ostream& operator<<(std::ostream &_ost, const detail::Triangle &_t) {
140 const detail::Triangle::indices_t &indices = _t.get();
141 _ost << "[" << indices[0] << "," << indices[1] << "," << indices[2] << "]";
142 return _ost;
143}
144
145#endif /* TRIANGLE_HPP_ */
Note: See TracBrowser for help on using the repository browser.