[MOAB-dev] commit/MOAB: 10 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Jun 13 09:45:51 CDT 2014
10 new commits in MOAB:
https://bitbucket.org/fathomteam/moab/commits/a9e20c357e48/
Changeset: a9e20c357e48
Branch: None
User: gonuke
Date: 2014-06-12 12:49:28
Summary: Check magnitude of norm to avoid divide by zero.
Affected #: 1 file
diff --git a/src/io/WriteSTL.cpp b/src/io/WriteSTL.cpp
index 45718d8..6e7cf03 100644
--- a/src/io/WriteSTL.cpp
+++ b/src/io/WriteSTL.cpp
@@ -35,6 +35,7 @@
#include <math.h>
#include <fcntl.h>
#include <limits.h>
+#include <float.h>
namespace moab {
@@ -247,7 +248,14 @@ ErrorCode WriteSTL::get_triangle_data( const double coords[9],
n[0] = e1[1]*e2[2] - e1[2]*e2[1];
n[1] = e1[2]*e2[0] - e1[0]*e2[2];
n[2] = e1[0]*e2[1] - e1[1]*e2[0];
- float inv_len = 1.0f / (float)sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] );
+ float inv_len = (float)sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] );
+ if (inv_len > FLT_MIN)
+ {
+ inv_len = 1.0f / inv_len;
+ }
+ else
+ inv_len = 0;
+
n[0] *= inv_len;
n[1] *= inv_len;
n[2] *= inv_len;
https://bitbucket.org/fathomteam/moab/commits/a60a59a33dfd/
Changeset: a60a59a33dfd
Branch: None
User: gonuke
Date: 2014-06-12 12:49:28
Summary: Change CartVect normalization to handle zero length vectors
Affected #: 1 file
diff --git a/src/moab/CartVect.hpp b/src/moab/CartVect.hpp
index a249fef..eed2a43 100644
--- a/src/moab/CartVect.hpp
+++ b/src/moab/CartVect.hpp
@@ -104,7 +104,12 @@ inline double CartVect::length_squared() const
{ return d[0]*d[0] + d[1]*d[1] + d[2]*d[2]; }
inline void CartVect::normalize()
- { *this /= length(); }
+ { double tmp=length();
+ if (tmp < FLT_MIN)
+ *this = {0,0,0};
+ else
+ *this /= tmp;
+ }
inline void CartVect::flip()
{ d[0] = -d[0]; d[1] = -d[1]; d[2] = -d[2]; }
https://bitbucket.org/fathomteam/moab/commits/df32b84d4b13/
Changeset: df32b84d4b13
Branch: None
User: gonuke
Date: 2014-06-12 12:49:28
Summary: add include for FLT_MIN
Affected #: 1 file
diff --git a/src/moab/CartVect.hpp b/src/moab/CartVect.hpp
index eed2a43..277bf8c 100644
--- a/src/moab/CartVect.hpp
+++ b/src/moab/CartVect.hpp
@@ -3,6 +3,7 @@
#include <cmath>
#include <iosfwd>
+#include <float.h>
namespace moab {
https://bitbucket.org/fathomteam/moab/commits/5e2f9c3772a5/
Changeset: 5e2f9c3772a5
Branch: None
User: gonuke
Date: 2014-06-12 12:49:28
Summary: Complete changes to normalize to compare to DBL_MIN
Affected #: 1 file
diff --git a/src/moab/CartVect.hpp b/src/moab/CartVect.hpp
index 277bf8c..3255048 100644
--- a/src/moab/CartVect.hpp
+++ b/src/moab/CartVect.hpp
@@ -106,8 +106,8 @@ inline double CartVect::length_squared() const
inline void CartVect::normalize()
{ double tmp=length();
- if (tmp < FLT_MIN)
- *this = {0,0,0};
+ if (tmp < DBL_MIN)
+ d[0] = d[1] = d[2] = 0;
else
*this /= tmp;
}
https://bitbucket.org/fathomteam/moab/commits/4101e56838b7/
Changeset: 4101e56838b7
Branch: None
User: gonuke
Date: 2014-06-12 12:49:28
Summary: Change get_triangle_info to use CartVect, primarily to centralize improvement of normalize()
Affected #: 2 files
diff --git a/src/io/WriteSTL.cpp b/src/io/WriteSTL.cpp
index 6e7cf03..fd6a111 100644
--- a/src/io/WriteSTL.cpp
+++ b/src/io/WriteSTL.cpp
@@ -35,7 +35,6 @@
#include <math.h>
#include <fcntl.h>
#include <limits.h>
-#include <float.h>
namespace moab {
@@ -227,38 +226,37 @@ ErrorCode WriteSTL::get_triangle_data( const double coords[9],
float v1[3],
float v2[3],
float v3[3],
- float n[3] )
+ float n[3])
{
- float e1[3], e2[3];
- v1[0] = (float)coords[0];
- v1[1] = (float)coords[1];
- v1[2] = (float)coords[2];
- v2[0] = (float)coords[3];
- v2[1] = (float)coords[4];
- v2[2] = (float)coords[5];
- v3[0] = (float)coords[6];
- v3[1] = (float)coords[7];
- v3[2] = (float)coords[8];
- e1[0] = v2[0] - v1[0];
- e1[1] = v2[1] - v1[1];
- e1[2] = v2[2] - v1[2];
- e2[0] = v3[0] - v1[0];
- e2[1] = v3[1] - v1[1];
- e2[2] = v3[2] - v1[2];
- n[0] = e1[1]*e2[2] - e1[2]*e2[1];
- n[1] = e1[2]*e2[0] - e1[0]*e2[2];
- n[2] = e1[0]*e2[1] - e1[1]*e2[0];
- float inv_len = (float)sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] );
- if (inv_len > FLT_MIN)
- {
- inv_len = 1.0f / inv_len;
- }
- else
- inv_len = 0;
- n[0] *= inv_len;
- n[1] *= inv_len;
- n[2] *= inv_len;
+ CartVect cv1, cv2, cv3, cn;
+ ErrorCode rval = get_triangle_data(coords,cv1,cv2,cv2,cn);
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ v1[0] = cv1[0]; v1[1] = cv1[1]; v1[2] = cv1[2];
+ v2[0] = cv2[0]; v2[1] = cv2[1]; v2[2] = cv2[2];
+ v3[0] = cv3[0]; v3[1] = cv3[1]; v3[2] = cv3[2];
+ n[0] = cn[0]; n[1] = cn[1]; n[2] = cn[2];
+
+ return MB_SUCCESS;
+
+}
+
+ErrorCode WriteSTL::get_triangle_data( const double coords[9],
+ CartVect& v1,
+ CartVect& v2,
+ CartVect& v3,
+ CartVect& n )
+{
+ v1 = coords;
+ v2 = coords+3;
+ v3 = coords+6;
+
+ n = (v2-v1)*(v3-v1);
+
+ n.normalize();
+
return MB_SUCCESS;
}
@@ -279,8 +277,7 @@ ErrorCode WriteSTL::ascii_write_triangles( FILE* file,
ErrorCode rval;
double coords[9];
- float v1[3], v2[3], v3[3];
- float n[3];
+ CartVect v1, v2, v3, n;
for (Range::const_iterator iter = triangles.begin();
iter != triangles.end(); ++iter)
{
@@ -303,9 +300,9 @@ ErrorCode WriteSTL::ascii_write_triangles( FILE* file,
fprintf( file,"facet normal %e %e %e\n", n[0], n[1], n[2] );
fprintf( file,"outer loop\n" );
- fprintf( file,"vertex %.*e %.*e %.*e\n", prec, v1[0], prec, v1[1], prec, v1[2] );
- fprintf( file,"vertex %.*e %.*e %.*e\n", prec, v2[0], prec, v2[1], prec, v2[2] );
- fprintf( file,"vertex %.*e %.*e %.*e\n", prec, v3[0], prec, v3[1], prec, v3[2] );
+ fprintf( file,"vertex %.*e %.*e %.*e\n", prec, (float)v1[0], prec, (float)v1[1], prec, (float)v1[2] );
+ fprintf( file,"vertex %.*e %.*e %.*e\n", prec, (float)v2[0], prec, (float)v2[1], prec, (float)v2[2] );
+ fprintf( file,"vertex %.*e %.*e %.*e\n", prec, (float)v3[0], prec, (float)v3[1], prec, (float)v3[2] );
fprintf( file,"endloop\n" );
fprintf( file,"endfacet\n" );
}
@@ -364,8 +361,9 @@ ErrorCode WriteSTL::binary_write_triangles( FILE* file,
rval = mbImpl->get_coords( conn, 3, coords );
if (MB_SUCCESS != rval)
return rval;
-
+
rval = get_triangle_data( coords, tri.vertex1, tri.vertex2, tri.vertex3, tri.normal );
+
if (MB_SUCCESS != rval)
return rval;
diff --git a/src/io/WriteSTL.hpp b/src/io/WriteSTL.hpp
index 4329de8..5e5fd77 100644
--- a/src/io/WriteSTL.hpp
+++ b/src/io/WriteSTL.hpp
@@ -17,6 +17,7 @@
#ifndef WRITE_STL_HPP
#define WRITE_STL_HPP
+#include "moab/CartVect.hpp"
#include "moab/Forward.hpp"
#include "moab/WriterIface.hpp"
@@ -86,7 +87,13 @@ protected:
float v2[3],
float v3[3],
float n[3] );
-
+
+ ErrorCode get_triangle_data( const double vtx_coords[9],
+ CartVect& v1,
+ CartVect& v2,
+ CartVect& v3,
+ CartVect& n);
+
//! interface instance
Interface *mbImpl;
WriteUtilIface* mWriteIface;
https://bitbucket.org/fathomteam/moab/commits/932feb0a4b2c/
Changeset: 932feb0a4b2c
Branch: None
User: gonuke
Date: 2014-06-12 12:49:29
Summary: add float based method to extract from CartVect
Affected #: 2 files
diff --git a/src/io/WriteSTL.cpp b/src/io/WriteSTL.cpp
index fd6a111..231d748 100644
--- a/src/io/WriteSTL.cpp
+++ b/src/io/WriteSTL.cpp
@@ -233,11 +233,8 @@ ErrorCode WriteSTL::get_triangle_data( const double coords[9],
ErrorCode rval = get_triangle_data(coords,cv1,cv2,cv2,cn);
if (MB_SUCCESS != rval)
return rval;
-
- v1[0] = cv1[0]; v1[1] = cv1[1]; v1[2] = cv1[2];
- v2[0] = cv2[0]; v2[1] = cv2[1]; v2[2] = cv2[2];
- v3[0] = cv3[0]; v3[1] = cv3[1]; v3[2] = cv3[2];
- n[0] = cn[0]; n[1] = cn[1]; n[2] = cn[2];
+
+ cv1.get(v1); cv2.get(v2); cv3.get(v3); cn.get(n);
return MB_SUCCESS;
diff --git a/src/moab/CartVect.hpp b/src/moab/CartVect.hpp
index 3255048..7427695 100644
--- a/src/moab/CartVect.hpp
+++ b/src/moab/CartVect.hpp
@@ -58,7 +58,7 @@ class CartVect
inline double length_squared() const;
- inline void normalize(); //!< make unit length
+ inline void normalize(); //!< make unit length, or 0 if length < DBL_MIN
inline void flip(); //!< flip direction
@@ -75,6 +75,11 @@ class CartVect
/** initialize array from this */
inline void get( double v[3] ) const
{ v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
+
+ /** initialize array from this */
+ inline void get( float v[3] ) const
+ { v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
+
};
inline CartVect operator+( const CartVect& u, const CartVect& v )
https://bitbucket.org/fathomteam/moab/commits/be76ee525623/
Changeset: be76ee525623
Branch: None
User: gonuke
Date: 2014-06-12 15:45:41
Summary: Fix typo-bug: pass 2 different variables by reference instead of the same variable twice\!
Affected #: 1 file
diff --git a/src/io/WriteSTL.cpp b/src/io/WriteSTL.cpp
index 231d748..997d418 100644
--- a/src/io/WriteSTL.cpp
+++ b/src/io/WriteSTL.cpp
@@ -230,7 +230,7 @@ ErrorCode WriteSTL::get_triangle_data( const double coords[9],
{
CartVect cv1, cv2, cv3, cn;
- ErrorCode rval = get_triangle_data(coords,cv1,cv2,cv2,cn);
+ ErrorCode rval = get_triangle_data(coords,cv1,cv2,cv3,cn);
if (MB_SUCCESS != rval)
return rval;
https://bitbucket.org/fathomteam/moab/commits/169c3ea7c480/
Changeset: 169c3ea7c480
Branch: None
User: gonuke
Date: 2014-06-12 15:46:47
Summary: Fix inconsistent data in this sample file. Didn't affect any tests.
Affected #: 1 file
diff --git a/MeshFiles/unittest/io/sample.stl b/MeshFiles/unittest/io/sample.stl
index 5aa4dc6..6ae22ff 100644
--- a/MeshFiles/unittest/io/sample.stl
+++ b/MeshFiles/unittest/io/sample.stl
@@ -13,7 +13,7 @@ solid cube_corner
vertex 1.0 0.0 0.0
endloop
endfacet
- facet normal 0.0 0.0 -1.0
+ facet normal -1.0 0.0 0.0
outer loop
vertex 0.0 0.0 0.0
vertex 0.0 0.0 1.0
https://bitbucket.org/fathomteam/moab/commits/ac20223dbff1/
Changeset: ac20223dbff1
Branch: None
User: gonuke
Date: 2014-06-13 16:35:46
Summary: Add static cast for CartVect::get(float*)
Affected #: 1 file
diff --git a/src/moab/CartVect.hpp b/src/moab/CartVect.hpp
index 7427695..0c3c38e 100644
--- a/src/moab/CartVect.hpp
+++ b/src/moab/CartVect.hpp
@@ -72,13 +72,13 @@ class CartVect
inline const double* array() const
{ return d; }
- /** initialize array from this */
+ /** initialize double array from this */
inline void get( double v[3] ) const
{ v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
- /** initialize array from this */
+ /** initialize float array from this */
inline void get( float v[3] ) const
- { v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
+ { v[0] = static_cast<float>(d[0]); v[1] = static_cast<float>(d[1]); v[2] = static_cast<float>(d[2]); }
};
https://bitbucket.org/fathomteam/moab/commits/cda940e65ad3/
Changeset: cda940e65ad3
Branch: master
User: vijaysm
Date: 2014-06-13 16:45:36
Summary: Merged in gonuke/moab/stl_inf_norm_fix (pull request #25)
Check magnitude of norm to avoid divide by zero.
Affected #: 4 files
diff --git a/MeshFiles/unittest/io/sample.stl b/MeshFiles/unittest/io/sample.stl
index 5aa4dc6..6ae22ff 100644
--- a/MeshFiles/unittest/io/sample.stl
+++ b/MeshFiles/unittest/io/sample.stl
@@ -13,7 +13,7 @@ solid cube_corner
vertex 1.0 0.0 0.0
endloop
endfacet
- facet normal 0.0 0.0 -1.0
+ facet normal -1.0 0.0 0.0
outer loop
vertex 0.0 0.0 0.0
vertex 0.0 0.0 1.0
diff --git a/src/io/WriteSTL.cpp b/src/io/WriteSTL.cpp
index 45718d8..997d418 100644
--- a/src/io/WriteSTL.cpp
+++ b/src/io/WriteSTL.cpp
@@ -226,31 +226,34 @@ ErrorCode WriteSTL::get_triangle_data( const double coords[9],
float v1[3],
float v2[3],
float v3[3],
- float n[3] )
+ float n[3])
{
- float e1[3], e2[3];
- v1[0] = (float)coords[0];
- v1[1] = (float)coords[1];
- v1[2] = (float)coords[2];
- v2[0] = (float)coords[3];
- v2[1] = (float)coords[4];
- v2[2] = (float)coords[5];
- v3[0] = (float)coords[6];
- v3[1] = (float)coords[7];
- v3[2] = (float)coords[8];
- e1[0] = v2[0] - v1[0];
- e1[1] = v2[1] - v1[1];
- e1[2] = v2[2] - v1[2];
- e2[0] = v3[0] - v1[0];
- e2[1] = v3[1] - v1[1];
- e2[2] = v3[2] - v1[2];
- n[0] = e1[1]*e2[2] - e1[2]*e2[1];
- n[1] = e1[2]*e2[0] - e1[0]*e2[2];
- n[2] = e1[0]*e2[1] - e1[1]*e2[0];
- float inv_len = 1.0f / (float)sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] );
- n[0] *= inv_len;
- n[1] *= inv_len;
- n[2] *= inv_len;
+
+ CartVect cv1, cv2, cv3, cn;
+ ErrorCode rval = get_triangle_data(coords,cv1,cv2,cv3,cn);
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ cv1.get(v1); cv2.get(v2); cv3.get(v3); cn.get(n);
+
+ return MB_SUCCESS;
+
+}
+
+ErrorCode WriteSTL::get_triangle_data( const double coords[9],
+ CartVect& v1,
+ CartVect& v2,
+ CartVect& v3,
+ CartVect& n )
+{
+ v1 = coords;
+ v2 = coords+3;
+ v3 = coords+6;
+
+ n = (v2-v1)*(v3-v1);
+
+ n.normalize();
+
return MB_SUCCESS;
}
@@ -271,8 +274,7 @@ ErrorCode WriteSTL::ascii_write_triangles( FILE* file,
ErrorCode rval;
double coords[9];
- float v1[3], v2[3], v3[3];
- float n[3];
+ CartVect v1, v2, v3, n;
for (Range::const_iterator iter = triangles.begin();
iter != triangles.end(); ++iter)
{
@@ -295,9 +297,9 @@ ErrorCode WriteSTL::ascii_write_triangles( FILE* file,
fprintf( file,"facet normal %e %e %e\n", n[0], n[1], n[2] );
fprintf( file,"outer loop\n" );
- fprintf( file,"vertex %.*e %.*e %.*e\n", prec, v1[0], prec, v1[1], prec, v1[2] );
- fprintf( file,"vertex %.*e %.*e %.*e\n", prec, v2[0], prec, v2[1], prec, v2[2] );
- fprintf( file,"vertex %.*e %.*e %.*e\n", prec, v3[0], prec, v3[1], prec, v3[2] );
+ fprintf( file,"vertex %.*e %.*e %.*e\n", prec, (float)v1[0], prec, (float)v1[1], prec, (float)v1[2] );
+ fprintf( file,"vertex %.*e %.*e %.*e\n", prec, (float)v2[0], prec, (float)v2[1], prec, (float)v2[2] );
+ fprintf( file,"vertex %.*e %.*e %.*e\n", prec, (float)v3[0], prec, (float)v3[1], prec, (float)v3[2] );
fprintf( file,"endloop\n" );
fprintf( file,"endfacet\n" );
}
@@ -356,8 +358,9 @@ ErrorCode WriteSTL::binary_write_triangles( FILE* file,
rval = mbImpl->get_coords( conn, 3, coords );
if (MB_SUCCESS != rval)
return rval;
-
+
rval = get_triangle_data( coords, tri.vertex1, tri.vertex2, tri.vertex3, tri.normal );
+
if (MB_SUCCESS != rval)
return rval;
diff --git a/src/io/WriteSTL.hpp b/src/io/WriteSTL.hpp
index 4329de8..5e5fd77 100644
--- a/src/io/WriteSTL.hpp
+++ b/src/io/WriteSTL.hpp
@@ -17,6 +17,7 @@
#ifndef WRITE_STL_HPP
#define WRITE_STL_HPP
+#include "moab/CartVect.hpp"
#include "moab/Forward.hpp"
#include "moab/WriterIface.hpp"
@@ -86,7 +87,13 @@ protected:
float v2[3],
float v3[3],
float n[3] );
-
+
+ ErrorCode get_triangle_data( const double vtx_coords[9],
+ CartVect& v1,
+ CartVect& v2,
+ CartVect& v3,
+ CartVect& n);
+
//! interface instance
Interface *mbImpl;
WriteUtilIface* mWriteIface;
diff --git a/src/moab/CartVect.hpp b/src/moab/CartVect.hpp
index a249fef..0c3c38e 100644
--- a/src/moab/CartVect.hpp
+++ b/src/moab/CartVect.hpp
@@ -3,6 +3,7 @@
#include <cmath>
#include <iosfwd>
+#include <float.h>
namespace moab {
@@ -57,7 +58,7 @@ class CartVect
inline double length_squared() const;
- inline void normalize(); //!< make unit length
+ inline void normalize(); //!< make unit length, or 0 if length < DBL_MIN
inline void flip(); //!< flip direction
@@ -71,9 +72,14 @@ class CartVect
inline const double* array() const
{ return d; }
- /** initialize array from this */
+ /** initialize double array from this */
inline void get( double v[3] ) const
{ v[0] = d[0]; v[1] = d[1]; v[2] = d[2]; }
+
+ /** initialize float array from this */
+ inline void get( float v[3] ) const
+ { v[0] = static_cast<float>(d[0]); v[1] = static_cast<float>(d[1]); v[2] = static_cast<float>(d[2]); }
+
};
inline CartVect operator+( const CartVect& u, const CartVect& v )
@@ -104,7 +110,12 @@ inline double CartVect::length_squared() const
{ return d[0]*d[0] + d[1]*d[1] + d[2]*d[2]; }
inline void CartVect::normalize()
- { *this /= length(); }
+ { double tmp=length();
+ if (tmp < DBL_MIN)
+ d[0] = d[1] = d[2] = 0;
+ else
+ *this /= tmp;
+ }
inline void CartVect::flip()
{ d[0] = -d[0]; d[1] = -d[1]; d[2] = -d[2]; }
Repository URL: https://bitbucket.org/fathomteam/moab/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the moab-dev
mailing list