RINGMesh  Version 5.0.0
A programming library for geological model meshes
test-nn-search.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #include <ringmesh/ringmesh_tests_config.h>
37 
38 #include <vector>
39 
42 
47 using namespace RINGMesh;
48 
49 template < index_t DIMENSION >
51 {
52  std::vector< vecn< DIMENSION > > hardcoded_unique_vertices( 4 );
53  for( index_t p : range( hardcoded_unique_vertices.size() ) )
54  {
55  vecn< DIMENSION >& point = hardcoded_unique_vertices[p];
56  for( index_t i : range( DIMENSION ) )
57  {
58  point[i] = p;
59  }
60  }
61 
62  std::vector< vecn< DIMENSION > > vertices( 7 );
63  vertices[0] = hardcoded_unique_vertices[0];
64  vertices[1] = hardcoded_unique_vertices[1];
65  vertices[2] = hardcoded_unique_vertices[0];
66  vertices[3] = hardcoded_unique_vertices[2];
67  vertices[4] = hardcoded_unique_vertices[1];
68  vertices[5] = hardcoded_unique_vertices[3];
69  vertices[6] = hardcoded_unique_vertices[0];
70 
71  std::vector< index_t > hardcoded_index_map( 7 );
72 
73  hardcoded_index_map[0] = 0;
74  hardcoded_index_map[1] = 1;
75  hardcoded_index_map[2] = 0;
76  hardcoded_index_map[3] = 2;
77  hardcoded_index_map[4] = 1;
78  hardcoded_index_map[5] = 3;
79  hardcoded_index_map[6] = 0;
80 
81  NNSearch< DIMENSION > nn_search( vertices );
82  std::vector< vecn< DIMENSION > > unique_vertices;
83  std::vector< index_t > index_map;
84  std::tie( std::ignore, index_map, unique_vertices ) =
86  global_epsilon );
87  for( index_t i : range( index_map.size() ) )
88  {
89  if( index_map[i] != hardcoded_index_map[i] )
90  {
91  throw RINGMeshException( "TEST", "Index map found is wrong" );
92  }
93  }
94 
95  for( index_t v : range( unique_vertices.size() ) )
96  {
97  if( unique_vertices[v] != hardcoded_unique_vertices[v] )
98  {
99  throw RINGMeshException(
100  "TEST", "Unique vertices found are wrong" );
101  }
102  }
103 }
104 
105 int main()
106 {
107  try
108  {
110 
111  Logger::out( "TEST", "Test NNsearch 2D" );
112  test_nn_search< 2 >();
113  Logger::out( "TEST", "Test NNsearch 3D" );
114  test_nn_search< 3 >();
115  }
116  catch( const RINGMeshException& e )
117  {
118  Logger::err( e.category(), e.what() );
119  return 1;
120  }
121  catch( const std::exception& e )
122  {
123  Logger::err( "Exception", e.what() );
124  return 1;
125  }
126  Logger::out( "TEST", "SUCCESS" );
127  return 0;
128 }
GEO::vecng< DIMENSION, double > vecn
Definition: types.h:74
void test_nn_search()
int main()
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
static void out(const std::string &feature, const Args &... args)
Definition: logger.h:61
const std::string & category() const
Definition: common.h:165
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
std::tuple< index_t, std::vector< index_t >, std::vector< vecn< DIMENSION > > > get_colocated_index_mapping_and_unique_points(double epsilon) const
Gets the index_map that link all the points to a no duplicated list of index in the list of unique_po...
Definition: nn_search.cpp:177
void RINGMESH_API default_configure()
Definition: common.cpp:99