RINGMesh  Version 5.0.0
A programming library for geological model meshes
stratigraphic_column_builder.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 
37 
38 #include <tinyxml2/tinyxml2.h>
39 
42 
43 namespace RINGMesh
44 {
46  StratigraphicColumn& column, GeoModel3D& model, std::string filename )
47  : StratigraphicColumnBuilder( column, model ),
48  filename_( std::move( filename ) )
49  {
50  }
51 
53  StratigraphicColumn& column, GeoModel3D& model )
54  : column_( column ), model_( model )
55  {
56  if( model_.nb_geological_entities( GeologicalEntityType( "Layer" ) )
57  == 0 )
58  {
59  throw RINGMeshException(
60  "I/O", "The GeoModel have to be defined with layers." );
61  }
62  }
63 
65  {
66  tinyxml2::XMLDocument column;
67  tinyxml2::XMLError Result = column.LoadFile( filename_.c_str() );
68  if( Result != tinyxml2::XML_SUCCESS )
69  {
70  throw RINGMeshException(
71  "I/O", "Error while loading Stratigraphic Column XML file." );
72  }
73  tinyxml2::XMLNode* root = column.FirstChild();
74  if( root == nil )
75  {
76  throw RINGMeshException( "I/O",
77  "Error while getting root of Stratigraphic Column XML file." );
78  }
79  tinyxml2::XMLElement* local =
80  root->FirstChildElement( "LocalStratigraphicColumn" );
81  tinyxml2::XMLElement* name_column = local->FirstChildElement( "name" );
82  const std::string name_of_column = name_column->GetText();
83 
84  tinyxml2::XMLElement* paradigm =
85  local->FirstChildElement( "classification_type" );
86  std::string paradigm_str = paradigm->GetText();
87 
88  tinyxml2::XMLElement* units = local->FirstChildElement( "units" );
89  tinyxml2::XMLElement* unit = units->FirstChildElement( "unit" );
90 
91  std::vector< std::string > unitList;
92  while( unit != 0 )
93  {
94  tinyxml2::XMLElement* name = unit->FirstChildElement( "name" );
95  unitList.push_back( name->GetText() );
96  tinyxml2::XMLElement* top = unit->FirstChildElement( "top" );
97  if( top != 0 )
98  {
99  tinyxml2::XMLElement* name_top =
100  top->FirstChildElement( "name" );
101  unitList.push_back( name_top->GetText() );
102  }
103  else
104  {
105  unitList.push_back( "none" );
106  }
107  tinyxml2::XMLElement* base = unit->FirstChildElement( "base" );
108  if( base != 0 )
109  {
110  tinyxml2::XMLElement* name_base =
111  base->FirstChildElement( "name" );
112  unitList.push_back( name_base->GetText() );
113  }
114  else
115  {
116  unitList.push_back( "none" );
117  }
118  unit = unit->NextSiblingElement( "unit" );
119  }
120 
121  // Creation of StratigraphicUnit
122 
123  std::vector< const StratigraphicUnit* > units_vec_construction;
124  for( index_t i = 0; i < unitList.size(); i += 3 )
125  {
126  const std::string& name_of_unit = unitList[i];
127  if( name_of_unit != "none" )
128  {
129  index_t layer_id = find_geological_entity_id_from_name(
130  model_, GeologicalEntityType( "Layer" ), name_of_unit );
131  const Layer< 3 >* layer = dynamic_cast< const Layer< 3 >* >(
132  &( model_.geological_entity(
133  GeologicalEntityType( "Layer" ), layer_id ) ) );
134  ringmesh_assert( layer != nullptr );
135  const Interface< 3 >* top_interface = nil;
136  const Interface< 3 >* base_interface = nil;
137  RockFeature rock( name_of_unit );
138  if( unitList[i + 1] != "none" )
139  {
140  std::string name_of_interface_top = unitList[i + 1];
141  index_t top_interface_id =
143  GeologicalEntityType( "Interface" ),
144  name_of_interface_top );
145  top_interface = dynamic_cast< const Interface< 3 >* >(
146  &( model_.geological_entity(
147  GeologicalEntityType( "Interface" ),
148  top_interface_id ) ) );
149  ringmesh_assert( layer != nullptr );
150  }
151  if( unitList[i + 2] != "none" )
152  {
153  std::string name_of_interface_base = unitList[i + 2];
154  index_t base_interface_id =
156  GeologicalEntityType( "Interface" ),
157  name_of_interface_base );
158  base_interface = dynamic_cast< const Interface< 3 >* >(
159  &( model_.geological_entity(
160  GeologicalEntityType( "Interface" ),
161  base_interface_id ) ) );
162  ringmesh_assert( layer != nullptr );
163  }
164  UnsubdividedStratigraphicUnit unit( name_of_unit,
165  *top_interface, *base_interface, *layer,
167  std::numeric_limits< double >::max() );
168  units_vec_construction.push_back( &unit );
169  }
170  }
171  const std::vector< const StratigraphicUnit* > units_vec =
172  units_vec_construction;
173  STRATIGRAPHIC_PARADIGM paradigm_upper;
174  if( paradigm_str == "chronostratigraphy" )
175  {
177  }
178  else if( paradigm_str == "lithostratigraphy" )
179  {
181  }
182  else
183  {
185  }
186  column_ =
187  StratigraphicColumn( name_of_column, units_vec, paradigm_upper );
188  }
189 
190 } // namespace RINGMesh
Manages the RockFeature, which contains a RockType and more informations.
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
StratigraphicColumnBuilder(StratigraphicColumn &column, GeoModel3D &model)
index_t find_geological_entity_id_from_name(const RINGMesh::GeoModel< DIMENSION > &geomodel, const RINGMesh::GeologicalEntityType &gmge_type, const std::string &name)
A stratigraphic column is composed of several stratigraphic units.
#define ringmesh_assert(x)
StratigraphicColumnBuilderFile(StratigraphicColumn &column, GeoModel3D &model, std::string filename)
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48