Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
vtriangle.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2011-2013,2017 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 
44 #ifndef VTRIANGLE_HPP
45 #define VTRIANGLE_HPP 1
46 
47 
48 #include <iostream>
49 #include <vector>
50 #include <vec3d.hpp>
51 #include <stdint.h>
52 
53 
56 class VTriangle {
57 
58  uint32_t _v[3];
59 
60 public:
61 
62  VTriangle( uint32_t v1, uint32_t v2, uint32_t v3 );
63  VTriangle( const uint32_t v[3] );
64  ~VTriangle();
65 
66  const uint32_t &operator[]( uint32_t i ) const {
67  return( _v[i] );
68  }
69 
70  uint32_t &operator[]( uint32_t i ) {
71  return( _v[i] );
72  }
73 
74  void debug_print( std::ostream &os ) const;
75 };
76 
77 
88 
89  double _vertex_matching_eps;
91 protected:
92 
93  std::vector<Vec3D> _vertex;
94  std::vector<VTriangle> _triangle;
96 public:
97 
103  VTriangleSurface( double vertex_matching_eps = 1.0e-9 );
104 
108 
113  void set_vertex_matching_eps( double vertex_matching_eps );
114 
117  uint32_t vertexc( void ) const {
118  return( _vertex.size() );
119  }
120 
123  const Vec3D &vertex( uint32_t i ) const {
124  return( _vertex[i] );
125  }
126 
129  uint32_t trianglec( void ) const {
130  return( _triangle.size() );
131  }
132 
135  const VTriangle &triangle( uint32_t i ) const {
136  return( _triangle[i] );
137  }
138 
143  uint32_t add_vertex_no_check( const Vec3D &x ) {
144  _vertex.push_back( x );
145  return( _vertex.size()-1 );
146  }
147 
152  uint32_t add_vertex( const Vec3D &x );
153 
165  uint32_t add_triangle( const Vec3D &x1, const Vec3D &x2, const Vec3D &x3 );
166 
172  uint32_t add_triangle( const Vec3D x[3] );
173 
177  uint32_t add_triangle( uint32_t v1, uint32_t v2, uint32_t v3 ) {
178  _triangle.push_back( VTriangle( v1, v2, v3 ) );
179  return( _triangle.size()-1 );
180  }
181 
187  uint32_t add_triangle( const uint32_t v[3] ) {
188  _triangle.push_back( VTriangle( v ) );
189  return( _triangle.size()-1 );
190  }
191 
194  void clear( void );
195 
198  void debug_print( std::ostream &os ) const;
199 };
200 
201 
210 
211  double _signed_volume_eps;
213  Vec3D _offset;
214  Vec3D _bbox[2];
216  int signvol4( const Vec3D &q0, const Vec3D &q1,
217  const Vec3D &q2, const Vec3D &q3 ) const;
218  int signvol3( const Vec3D &q1, const Vec3D &q2, const Vec3D &q3 ) const;
219  int classify_original_tetrahedron( int ss, const Vec3D &p,
220  const Vec3D &q1, const Vec3D &q2, const Vec3D &q3 ) const;
221 
222  void update_bbox( Vec3D &min, Vec3D &max, const Vec3D x ) const;
223 
224 public:
225 
233  VTriangleSurfaceSolid( double vertex_matching_eps = 1.0e-9,
234  double signed_volume_eps = 1.0e-15 );
235 
239 
244  void set_signed_volume_eps( double signed_volume_eps );
245 
248  Vec3D vertex( uint32_t i ) const {
249  return( VTriangleSurface::vertex(i) - _offset );
250  }
251 
262  void prepare_for_inside();
263 
274  bool inside( const Vec3D &x ) const;
275 
281  void get_bbox( Vec3D &min, Vec3D &max ) const;
282 
285  void remove_duplicate_triangles( void );
286 
296  void check_data( void ) const;
297 
300  void clear( void );
301 
304  void debug_print( std::ostream &os ) const;
305 };
306 
307 
308 #endif
VTriangleSolid solid.
Definition: vtriangle.hpp:209
void set_signed_volume_eps(double signed_volume_eps)
Set signed volume tolerance.
Definition: vtriangle.cpp:368
~VTriangleSurfaceSolid()
Destructor.
Definition: vtriangle.cpp:187
VTriangleSurfaceSolid(double vertex_matching_eps=1.0e-9, double signed_volume_eps=1.0e-15)
Constructor for vertex triangle surface solid.
Definition: vtriangle.cpp:178
void debug_print(std::ostream &os) const
Debug print.
Definition: vtriangle.cpp:486
Vec3D vertex(uint32_t i) const
Return vertex i coordinates.
Definition: vtriangle.hpp:248
void prepare_for_inside()
Prepare for inside tests.
Definition: vtriangle.cpp:343
void clear(void)
Clear surface.
Definition: vtriangle.cpp:478
void remove_duplicate_triangles(void)
Remove duplicate triangles.
Definition: vtriangle.cpp:381
void get_bbox(Vec3D &min, Vec3D &max) const
Return bounding box in vectors min and max.
Definition: vtriangle.cpp:374
bool inside(const Vec3D &x) const
Return if point x is inside solid.
Definition: vtriangle.cpp:284
void check_data(void) const
Check data.
Definition: vtriangle.cpp:411
VTriangle surface.
Definition: vtriangle.hpp:87
uint32_t add_triangle(const uint32_t v[3])
Add a triangle consiting of already defined vertices v.
Definition: vtriangle.hpp:187
std::vector< VTriangle > _triangle
List of surface triangles.
Definition: vtriangle.hpp:94
uint32_t trianglec(void) const
Return triangle count.
Definition: vtriangle.hpp:129
VTriangleSurface(double vertex_matching_eps=1.0e-9)
Constructor for vertex triangle surface.
Definition: vtriangle.cpp:87
uint32_t add_vertex(const Vec3D &x)
Add a vertex x with duplicate vertex elimination.
Definition: vtriangle.cpp:113
const Vec3D & vertex(uint32_t i) const
Return vertex i coordinates.
Definition: vtriangle.hpp:123
void debug_print(std::ostream &os) const
Debug print.
Definition: vtriangle.cpp:154
uint32_t add_triangle(const Vec3D &x1, const Vec3D &x2, const Vec3D &x3)
Add a triangle consiting of vertices x1, x2 and x3 with duplicate vertex elimination.
Definition: vtriangle.cpp:141
~VTriangleSurface()
Destructor.
Definition: vtriangle.cpp:94
uint32_t vertexc(void) const
Return vertex count.
Definition: vtriangle.hpp:117
uint32_t add_vertex_no_check(const Vec3D &x)
Add a vertex x without checking.
Definition: vtriangle.hpp:143
const VTriangle & triangle(uint32_t i) const
Return triangle i.
Definition: vtriangle.hpp:135
std::vector< Vec3D > _vertex
List of vertices for surface triangles.
Definition: vtriangle.hpp:93
void set_vertex_matching_eps(double vertex_matching_eps)
Set vertex matching tolerance.
Definition: vtriangle.cpp:100
void clear(void)
Clear surface.
Definition: vtriangle.cpp:106
uint32_t add_triangle(uint32_t v1, uint32_t v2, uint32_t v3)
Add a triangle consiting of already defined vertices v1, v2 and v3.
Definition: vtriangle.hpp:177
Vertex-based triangle representation.
Definition: vtriangle.hpp:56
Three dimensional vector.
Definition: vec3d.hpp:58
Three dimensional vectors.


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.