MEPP2 Project
AIFPropertiesHelpers.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 // Warning: do NOT include this file outside of AIFMesh.hpp
14 
15 namespace FEVV {
16 namespace DataStructures {
17 namespace AIF {
18 
28 {
29 public:
40 
49  static void set_point(const ptr_mesh m,
54  {
56  "v:point", v->GetIndex(), Point(x, y, z));
57  }
58 
67  static void set_point(const smart_ptr_mesh m,
72  {
73  set_point(m.get(), v, x, y, z);
74  }
75 
84  static void set_point(/*const*/ ref_mesh m,
89  {
91  "v:point", v->GetIndex(), Point(x, y, z));
92  }
93 
101  {
102  return m->GetProperty< AIFVertex::ptr, Point >("v:point", v->GetIndex());
103  }
111  {
112  return get_point(m.get(), v);
113  }
120  static Point &get_point(/*const*/ ref_mesh m, vertex_descriptor v)
121  {
122  return m.GetProperty< AIFVertex::ptr, Point >("v:point", v->GetIndex());
123  }
124 
129  static Vector
130  compute_normal(const Point &p1, const Point &p2, const Point &p3)
131  {
132  // calculate two vectors from the three first points
133  Vector vector1(p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2]);
134  Vector vector2(p1[0] - p3[0], p1[1] - p3[1], p1[2] - p3[2]);
135 
136  // take the cross product of the two vectors to get
137  NormalCoordinateType nx = static_cast< NormalCoordinateType >(
138  vector1[1] * vector2[2] - vector1[2] * vector2[1]);
139  NormalCoordinateType ny = static_cast< NormalCoordinateType >(
140  vector1[2] * vector2[0] - vector1[0] * vector2[2]);
141  NormalCoordinateType nz = static_cast< NormalCoordinateType >(
142  vector1[0] * vector2[1] - vector1[1] * vector2[0]);
143 
144  Vector normal(nx, ny, nz);
145 
146  return normal;
147  }
148 
153  template< typename mesh >
154  static Vector compute_normal(const mesh m,
155  const vertex_descriptor v1,
156  const vertex_descriptor v2,
157  const vertex_descriptor v3)
158  {
159  const Point &p1 = get_point(m, v1);
160  const Point &p2 = get_point(m, v2);
161  const Point &p3 = get_point(m, v3);
162  return compute_normal(p1, p2, p3);
163  }
164 
169  static Vector
170  compute_unit_normal(const Point &p1, const Point &p2, const Point &p3)
171  {
172  Vector normal = compute_normal(p1, p2, p3);
173  double length = normal.length();
174 
175  if(length > 1e-8)
176  {
177  normal[0] /= (NormalCoordinateType)length;
178  normal[1] /= (NormalCoordinateType)length;
179  normal[2] /= (NormalCoordinateType)length;
180  }
181 
182  return normal;
183  }
184 
189  template< typename mesh >
190  static Vector compute_unit_normal(const mesh m,
191  const vertex_descriptor v1,
192  const vertex_descriptor v2,
193  const vertex_descriptor v3)
194  {
195  const Point &p1 = get_point(m, v1);
196  const Point &p2 = get_point(m, v2);
197  const Point &p3 = get_point(m, v3);
198  return compute_unit_normal(p1, p2, p3);
199  }
200 
204  template< typename mesh >
205  static CoordinateType length(const mesh m, const edge_descriptor e)
206  {
209 
210  const Point &p1 = get_point(m, v1);
211  const Point &p2 = get_point(m, v2);
212 
213  AIFVector< CoordinateType > v(p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2]);
214  return v.length();
215  }
216 };
217 
218 
219 } // namespace AIF
220 } // namespace DataStructures
221 } // namespace FEVV
FEVV::DataStructures::AIF::AIFTopologyHelpers::incident_vertices
static boost::iterator_range< vertex_container_in_edge::const_iterator > incident_vertices(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:1189
FEVV::DataStructures::AIF::AIFVertex::ptr
boost::shared_ptr< self > ptr
Definition: AIFVertex.hpp:47
FEVV::DataStructures::AIF::AIFPropertiesHelpers::set_point
static void set_point(const ptr_mesh m, vertex_descriptor v, CoordinateType x, CoordinateType y, CoordinateType z)
Definition: AIFPropertiesHelpers.h:49
FEVV::DataStructures::AIF::AIFPropertiesHelpers::NormalCoordinateType
AIFMesh::NormalCoordinateType NormalCoordinateType
Definition: AIFPropertiesHelpers.h:32
FEVV::DataStructures::AIF::AIFTopologyHelpers::vertex_descriptor
vertex_type::ptr vertex_descriptor
Definition: AIFTopologyHelpers.h:70
FEVV::DataStructures::AIF::AIFMesh::SetProperty
void SetProperty(const std::string &mapName, std::size_t cellId, T value)
Definition: AIFMesh.hpp:451
FEVV::DataStructures::AIF::AIFPropertiesHelpers::AIFMesh
FEVV::DataStructures::AIF::AIFMesh AIFMesh
Definition: AIFPropertiesHelpers.h:30
FEVV::DataStructures::AIF::AIFPropertiesHelpers::compute_normal
static Vector compute_normal(const mesh m, const vertex_descriptor v1, const vertex_descriptor v2, const vertex_descriptor v3)
Definition: AIFPropertiesHelpers.h:154
FEVV::DataStructures::AIF::AIFPropertiesHelpers::get_point
static Point & get_point(const ptr_mesh m, vertex_descriptor v)
Definition: AIFPropertiesHelpers.h:100
FEVV::DataStructures::AIF::AIFPropertiesHelpers::ref_mesh
AIFTopologyHelpers::ref_mesh ref_mesh
Definition: AIFPropertiesHelpers.h:37
FEVV::DataStructures::AIF::AIFPropertiesHelpers::smart_ptr_mesh
AIFTopologyHelpers::smart_ptr_mesh smart_ptr_mesh
Definition: AIFPropertiesHelpers.h:35
FEVV::DataStructures::AIF::AIFTopologyHelpers::edge_descriptor
edge_type::ptr edge_descriptor
Definition: AIFTopologyHelpers.h:71
FEVV::DataStructures::AIF::AIFPropertiesHelpers::get_point
static Point & get_point(ref_mesh m, vertex_descriptor v)
Definition: AIFPropertiesHelpers.h:120
FEVV::DataStructures::AIF::AIFPropertiesHelpers::set_point
static void set_point(const smart_ptr_mesh m, vertex_descriptor v, CoordinateType x, CoordinateType y, CoordinateType z)
Definition: AIFPropertiesHelpers.h:67
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::DataStructures::AIF::AIFPropertiesHelpers::compute_normal
static Vector compute_normal(const Point &p1, const Point &p2, const Point &p3)
Definition: AIFPropertiesHelpers.h:130
FEVV::DataStructures::AIF::AIFPropertiesHelpers::get_point
static Point & get_point(const smart_ptr_mesh m, vertex_descriptor v)
Definition: AIFPropertiesHelpers.h:110
FEVV::DataStructures::AIF::AIFPropertiesHelpers::CoordinateType
AIFMesh::CoordinateType CoordinateType
Definition: AIFPropertiesHelpers.h:31
FEVV::DataStructures::AIF::AIFMesh::CoordinateType
AIFVertex::CoordinateType CoordinateType
Definition: AIFMesh.hpp:62
FEVV::DataStructures::AIF::AIFPropertiesHelpers::edge_descriptor
AIFTopologyHelpers::edge_descriptor edge_descriptor
Definition: AIFPropertiesHelpers.h:39
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
FEVV::DataStructures::AIF::AIFPropertiesHelpers::Vector
AIFMesh::Vector Vector
Definition: AIFPropertiesHelpers.h:34
FEVV::DataStructures::AIF::AIFPropertiesHelpers::vertex_descriptor
AIFTopologyHelpers::vertex_descriptor vertex_descriptor
Definition: AIFPropertiesHelpers.h:38
FEVV::DataStructures::AIF::AIFPropertiesHelpers::ptr_mesh
AIFTopologyHelpers::ptr_mesh ptr_mesh
Definition: AIFPropertiesHelpers.h:36
FEVV::DataStructures::AIF::AIFTopologyHelpers::smart_ptr_mesh
mesh_type::ptr smart_ptr_mesh
Definition: AIFTopologyHelpers.h:64
FEVV::DataStructures::AIF::AIFPropertiesHelpers::compute_unit_normal
static Vector compute_unit_normal(const Point &p1, const Point &p2, const Point &p3)
Definition: AIFPropertiesHelpers.h:170
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::DataStructures::AIF::AIFPropertiesHelpers::Point
AIFMesh::Point Point
Definition: AIFPropertiesHelpers.h:33
FEVV::DataStructures::AIF::AIFPropertiesHelpers::compute_unit_normal
static Vector compute_unit_normal(const mesh m, const vertex_descriptor v1, const vertex_descriptor v2, const vertex_descriptor v3)
Definition: AIFPropertiesHelpers.h:190
FEVV::DataStructures::AIF::AIFMesh::GetProperty
T & GetProperty(const std::string &mapName, std::size_t cellId)
Definition: AIFMesh.hpp:465
FEVV::DataStructures::AIF::AIFPropertiesHelpers::length
static CoordinateType length(const mesh m, const edge_descriptor e)
Definition: AIFPropertiesHelpers.h:205
FEVV::DataStructures::AIF::AIFVector::length
CoordinateType length(void) const
Definition: AIFProperties.h:208
FEVV::DataStructures::AIF::AIFMesh::NormalCoordinateType
AIFFace::NormalCoordinateType NormalCoordinateType
Definition: AIFMesh.hpp:68
FEVV::DataStructures::AIF::AIFPropertiesHelpers::set_point
static void set_point(ref_mesh m, vertex_descriptor v, CoordinateType x, CoordinateType y, CoordinateType z)
Definition: AIFPropertiesHelpers.h:84
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
FEVV::DataStructures::AIF::AIFPropertiesHelpers
This class is an helper class associated to the AIFMesh structure. AIFPropertiesHelpers implements al...
Definition: AIFPropertiesHelpers.h:28