source: src/Tesselation/TriangleMatcher/TriangleMatcher.cpp@ 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 c66ae6, checked in by Frederik Heber <heber@…>, 9 years ago

TESTFIX: Added AdjacencyMatcher to correctly compare .adj files in save-adjacency regression test.

  • GuiChecks sees a different (but still valid) ordering in the .adj file in the save-adjacency regression test.
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2015 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * TriangleMatcher.cpp
25 *
26 * Created on: Jun 15, 2015
27 * Author: heber
28 *
29 *
30 * This is a small study in C++11 that compares at least two
31 * files containing the triangle index triples of tesselations
32 * for equivalence
33 */
34
35// include config.h
36#ifdef HAVE_CONFIG_H
37#include <config.h>
38#endif
39
40#include "CodePatterns/MemDebug.hpp"
41
42#include <boost/exception/all.hpp>
43#include <boost/filesystem/operations.hpp>
44#include <boost/filesystem/path.hpp>
45#include <boost/tokenizer.hpp>
46
47#include <algorithm>
48#include <fstream>
49#include <iostream>
50#include <iterator>
51#include <sstream>
52#include <string>
53#include <map>
54
55#include "types.hpp"
56
57using namespace detail;
58
59namespace bf = boost::filesystem;
60
61typedef boost::error_info<
62 struct tag_IllegalTesselationFileContent_LineNumber,
63 int> IllegalTesselationFileContent_LineNumber;
64
65typedef boost::error_info<
66 struct tag_IllegalTesselationFileContent_Entries,
67 int> IllegalTesselationFileContent_Entries;
68
69typedef boost::error_info<
70 struct tag_IllegalTesselationFileContent_Line,
71 int> IllegalTesselationFileContent_Line;
72
73//!> Exception for illegal lines encountered in tesselation files
74struct IllegalTesselationFileContentException:
75 virtual boost::exception, virtual std::exception { };
76
77Triangle::index_t toIndex(const std::string &_element)
78{
79 Triangle::index_t index;
80 std::stringstream tokenstring(_element);
81 tokenstring >> index;
82 return index;
83}
84
85template <class T>
86std::ostream& operator<<(
87 std::ostream &_ost,
88 const std::set<T> &elements)
89{
90 for( const T elem : elements)
91 _ost << elem << std::endl;
92 return _ost;
93}
94
95/** Parses a tesselation file into a vector of Triangles.
96 *
97 * \param _filename name of file to parse
98 * \return tesselation_t structure filled with triangle index triples
99 */
100const tesselation_t parseFile(const boost::filesystem::path &_filename)
101{
102 tesselation_t tesselation;
103
104 std::ifstream infile(_filename.string().c_str());
105 boost::char_separator<char> sep(" \t");
106
107 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
108 std::string line;
109 int line_number = 1;
110 // read up till encountering an empty line
111 while (!infile.eof()) {
112 std::getline(infile, line);
113 if (line.empty())
114 break;
115 }
116 while (!infile.eof()) {
117 std::getline(infile, line);
118 tokenizer tokens(line, sep);
119 Triangle::indices_t indices;
120 const int entries = std::distance( tokens.begin(), tokens.end() );
121 // check for empty lines
122 if (entries == 0)
123 continue;
124 // entries must be exactly three if any
125 if ( entries != NUMBERINDICESTRIANGLE )
126 throw IllegalTesselationFileContentException()
127 << IllegalTesselationFileContent_LineNumber(line_number)
128 << IllegalTesselationFileContent_Entries(entries);
129 std::transform(
130 tokens.begin(),
131 tokens.end(),
132 indices.begin(),
133 toIndex);
134 tesselation.insert(Triangle(indices));
135
136 ++line_number;
137 }
138 infile.close();
139
140 return tesselation;
141}
142
143int main(int argc, char **argv) {
144
145 /// check arguments and give usage
146 if (argc <= 2) {
147 std::cerr << "Usage: " << argv[0] << " <list of files>\n";
148 std::cerr << "At least two tesselation files need to be specified that contain\n";
149 std::cerr << "each three indices per line.\n";
150
151 return 255;
152 }
153
154 /// read in files and parse into structures
155 typedef std::multimap<tesselation_t, std::string> tesselations_filename_t;
156 //!> contains all tesselations parsed from files
157 tesselations_filename_t tesselations;
158 for (int i=1; i<argc;++i) {
159 const bf::path filename(argv[i]);
160 if (bf::exists(filename)) {
161 try {
162 tesselation_t tesselation = parseFile(filename);
163 tesselations.insert(
164 std::make_pair(tesselation, filename.string()) );
165 } catch (IllegalTesselationFileContentException &e) {
166 std::cerr << "Illegal line at "
167 << *boost::get_error_info<IllegalTesselationFileContent_LineNumber>(e)
168 << " encountered with "
169 << *boost::get_error_info<IllegalTesselationFileContent_Entries>(e)
170 << " entries in "
171 << filename.string()
172 << ", aborting.\n";
173 return 5;
174 }
175 } else {
176 std::cerr << "The following file does not exist "
177 << filename.string() << ", aborting.\n";
178 return 5;
179 }
180 }
181
182 /// make comparison for equivalence
183 assert( tesselations.size() >= 2 );
184 tesselations_filename_t::const_iterator advancer = tesselations.begin();
185 tesselations_filename_t::const_iterator iter = advancer++;
186
187 bool AllEqual = true;
188 while( advancer != tesselations.end() ) {
189 if (advancer->first == iter->first) {
190 std::cout << "MATCH: "
191 << advancer->second << " and " << iter->second
192 << std::endl;
193 } else {
194 std::cout << advancer->first << " and " << iter->first
195 << " don't match.\n";
196 AllEqual = false;
197 }
198 iter = advancer++;
199 }
200
201 // exit (convert bool to int)
202 return (AllEqual ? 0 : 1);
203}
Note: See TracBrowser for help on using the repository browser.