RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_builder_2d_from_3d.h
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 #pragma once
37 
38 #include <ringmesh/basic/common.h>
39 
41 
43 
44 namespace RINGMesh
45 {
49  class RINGMESH_API GeoModelBuilder2DFrom3D : public GeoModelBuilder< 2 >
50  {
51  public:
52  GeoModelBuilder2DFrom3D( GeoModel2D& geomodel2d,
53  const GeoModel3D& geomodel3d_from,
54  const Geometry::Plane& plane )
55  : GeoModelBuilder( geomodel2d ),
56  geomodel3d_from_( geomodel3d_from ),
57  plane_( plane )
58  {
59  // Definition of v axis (upward) of the 2D space (along the plane)
60  auto upward_point = plane_.origin + vec3{ 0., 0., 1. };
61  vec3 v_axis_point_direction;
62  std::tie( std::ignore, v_axis_point_direction ) =
63  Distance::point_to_plane( upward_point, plane_ );
64  if( ( plane_.origin - v_axis_point_direction ).length()
65  < geomodel3d_from.epsilon() )
66  {
67  // Case where plane is sub-horizontal
68  // (v axis is set towards 3D x direction)
69  auto towards_x_point = plane_.origin + vec3{ 1., 0., 0. };
70  std::tie( std::ignore, v_axis_point_direction ) =
71  Distance::point_to_plane( towards_x_point, plane_ );
73  ( plane_.origin - v_axis_point_direction ).length()
74  < geomodel3d_from.epsilon() );
75  }
76  v_axis = normalize( v_axis_point_direction - plane_.origin );
77  u_axis = cross( v_axis, plane_.normal );
78  }
79 
80  protected:
81  vec2 get_2d_coord( const vec3& coord3d )
82  {
83  return { dot( coord3d, u_axis ), dot( coord3d, v_axis ) };
84  }
85 
86  protected:
87  const GeoModel3D& geomodel3d_from_;
89  vec3 u_axis{};
90  vec3 v_axis{};
91  };
92 
101  class RINGMESH_API GeoModelBuilder2DProjection
102  : public GeoModelBuilder2DFrom3D
103  {
104  public:
105  GeoModelBuilder2DProjection( GeoModel2D& geomodel2d,
106  const GeoModel3D& geomodel3d_from,
107  const Geometry::Plane& plane )
108  : GeoModelBuilder2DFrom3D( geomodel2d, geomodel3d_from, plane )
109  {
110  info.set_geomodel_name( geomodel3d_from_.name() + "_projected" );
111  }
112 
113  void build_geomodel();
114 
115  private:
116  void copy_geomodel_3d_topology();
117 
118  void copy_geomodel_3d_geological_informations();
119 
120  void project_geomodel_3d_mesh_entities();
121 
122  std::vector< vec2 > compute_projected_vertices(
123  const GeoModelMeshEntity3D& entity );
124  };
125 }
Builder of GeoModel2D which project a GeoModel3D onto a plane.
GeoModelBuilder2DProjection(GeoModel2D &geomodel2d, const GeoModel3D &geomodel3d_from, const Geometry::Plane &plane)
vecn< 3 > vec3
Definition: types.h:76
void build_geomodel(GeoModel3D &geomodel)
vecn< 2 > vec2
Definition: types.h:78
GeoModelBuilder2DFrom3D(GeoModel2D &geomodel2d, const GeoModel3D &geomodel3d_from, const Geometry::Plane &plane)
std::tuple< double, vec3 > RINGMESH_API point_to_plane(const Geometry::Point3D &point, const Geometry::Plane &plane)
#define ringmesh_assert(x)
Base class for GeoModel2D building from GeoModel3D.
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48