6 #if defined( _MSC_VER ) || defined( WIN32 )
7 #define _USE_MATH_DEFINES
22 #define CHECKNEGATIVEAREA
23 #ifdef CHECKNEGATIVEAREA
29 #ifdef MOAB_HAVE_TEMPESTREMAP
30 #include "GridElements.h"
33 #ifdef MOAB_HAVE_EIGEN3
34 #define EIGEN_NO_DEBUG
35 #define EIGEN_MAX_CPP_VER 11
36 #include "Eigen/Dense"
52 #define CORRTAGNAME "__correspondent"
74 for(
int i = 0; i < nX; i++ )
80 double* A = X + 2 * i;
83 for(
int j = 0; j < nY; j++ )
85 double* B = Y + 2 * j;
86 int j1 = ( j + 1 ) % nY;
87 double* C = Y + 2 * j1;
89 double area2 = ( B[0] - A[0] ) * ( C[1] - A[1] ) - ( C[0] - A[0] ) * ( B[1] - A[1] );
90 if( area2 < -epsilon_area )
100 P[extraPoint * 2] = A[0];
101 P[extraPoint * 2 + 1] = A[1];
132 if( nP < 2 )
return 0;
135 double c[2] = { 0., 0. };
137 for( k = 0; k < nP; k++ )
140 c[1] += P[2 * k + 1];
149 for( k = 0; k < nP; k++ )
151 double x = P[2 * k] - c[0], y = P[2 * k + 1] - c[1];
152 if( x != 0. || y != 0. )
154 pairAngleIndex[k].
angle = atan2( y, x );
158 pairAngleIndex[k].
angle = 0;
161 pairAngleIndex[k].
index = k;
165 std::sort( pairAngleIndex, pairAngleIndex + nP,
angleCompare );
169 for( k = 0; k < nP; k++ )
171 int ck = pairAngleIndex[k].
index;
172 PCopy[2 * k] = P[2 * ck];
173 PCopy[2 * k + 1] = P[2 * ck + 1];
176 std::copy( PCopy, PCopy + 2 * nP, P );
186 double d2 =
dist2( &P[2 * i], &P[2 * j] );
191 P[2 * i + 1] = P[2 * j + 1];
198 double d2 =
dist2( P, &P[2 * i] );
205 if( nP == 0 ) nP = 1;
244 markb[i] = markr[i] = 0;
247 for(
int i = 0; i < nsBlue; i++ )
249 for(
int j = 0; j < nsRed; j++ )
253 int iPlus1 = ( i + 1 ) % nsBlue;
254 int jPlus1 = ( j + 1 ) % nsRed;
255 for(
int k = 0; k < 2; k++ )
257 b[k] = red[2 * j + k] - blue[2 * i + k];
259 a[k][0] = blue[2 * iPlus1 + k] - blue[2 * i + k];
260 a[k][1] = red[2 * j + k] - red[2 * jPlus1 + k];
262 double delta = a[0][0] * a[1][1] - a[0][1] * a[1][0];
263 if( fabs( delta ) > 1.e-14 )
266 double alfa = ( b[0] * a[1][1] - a[0][1] * b[1] ) / delta;
267 double beta = ( -b[0] * a[1][0] + b[1] * a[0][0] ) / delta;
268 if( 0 <= alfa && alfa <= 1. && 0 <= beta && beta <= 1. )
271 for(
int k = 0; k < 2; k++ )
273 points[2 * nPoints + k] = blue[2 * i + k] + alfa * ( blue[2 * iPlus1 + k] - blue[2 * i + k] );
322 for(
int i = 0; i < 4; i++ )
324 markb[i] = markr[i] = 0;
327 for(
int i = 0; i < nsBlue; i++ )
329 int iPlus1 = ( i + 1 ) % nsBlue;
330 if( blueEdgeType[i] == 0 )
332 for(
int j = 0; j < nsRed; j++ )
337 int jPlus1 = ( j + 1 ) % nsRed;
338 for(
int k = 0; k < 2; k++ )
340 b[k] = red[2 * j + k] - blue[2 * i + k];
342 a[k][0] = blue[2 * iPlus1 + k] - blue[2 * i + k];
343 a[k][1] = red[2 * j + k] - red[2 * jPlus1 + k];
345 double delta = a[0][0] * a[1][1] - a[0][1] * a[1][0];
346 if( fabs( delta ) > 1.e-14 )
349 double alfa = ( b[0] * a[1][1] - a[0][1] * b[1] ) / delta;
350 double beta = ( -b[0] * a[1][0] + b[1] * a[0][0] ) / delta;
351 if( 0 <= alfa && alfa <= 1. && 0 <= beta && beta <= 1. )
354 for(
int k = 0; k < 2; k++ )
356 points[2 * nPoints + k] =
357 blue[2 * i + k] + alfa * ( blue[2 * iPlus1 + k] - blue[2 * i + k] );
370 for(
int j = 0; j < nsRed; j++ )
372 int jPlus1 = ( j + 1 ) % nsRed;
378 if( np == 0 )
continue;
381 std::cout <<
"intersection with 2 points :" << A << B << C << D <<
"\n";
383 for(
int k = 0; k < np; k++ )
386 points[2 * nPoints + 1] );
414 if( fabs( pos[0] ) < fabs( pos[1] ) )
416 if( fabs( pos[2] ) < fabs( pos[1] ) )
435 if( fabs( pos[2] ) < fabs( pos[0] ) )
520 double len = sqrt( c1 * c1 + c2 * c2 +
R *
R );
521 double beta =
R / len;
617 std::string parTagName(
"PARALLEL_PARTITION" );
620 ErrorCode rval =
mb->tag_get_handle( parTagName.c_str(), part_tag );
628 rval =
mb->get_entities_by_dimension( inSet, 1, inputRange );
MB_CHK_ERR( rval );
629 rval =
mb->get_entities_by_dimension( inSet, 2, inputRange );
MB_CHK_ERR( rval );
631 std::map< EntityHandle, int > partsAssign;
632 std::map< int, EntityHandle > newPartSets;
633 if( !partSets.
empty() )
640 rval =
mb->get_entities_by_handle( pSet, ents );
MB_CHK_ERR( rval );
642 rval =
mb->tag_get_data( part_tag, &pSet, 1, &val );
MB_CHK_ERR( rval );
646 rval =
mb->tag_set_data( part_tag, &newPartSet, 1, &val );
MB_CHK_ERR( rval );
647 newPartSets[val] = newPartSet;
648 rval =
mb->add_entities( outSet, &newPartSet, 1 );
MB_CHK_ERR( rval );
651 partsAssign[*it] = val;
687 subranges[plane - 1].
insert( cell );
689 for(
int i = 1; i <= 6; i++ )
692 rval =
mb->get_connectivity( subranges[i - 1], verts );
MB_CHK_ERR( rval );
693 std::map< EntityHandle, EntityHandle > corr;
708 for(
Range::iterator eit = subranges[i - 1].begin(); eit != subranges[i - 1].
end(); ++eit )
713 rval =
mb->get_connectivity( eh, conn, num_nodes );
MB_CHK_ERR( rval );
715 for(
int j = 0; j < num_nodes; j++ )
716 new_conn[j] = corr[conn[j]];
717 EntityType type =
mb->type_from_handle( eh );
719 rval =
mb->create_element( type, new_conn, num_nodes, newCell );
MB_CHK_ERR( rval );
720 rval =
mb->add_entities( outSet, &newCell, 1 );
MB_CHK_ERR( rval );
721 std::map< EntityHandle, int >::iterator mit = partsAssign.find( eh );
722 if( mit != partsAssign.end() )
724 int val = mit->second;
725 rval =
mb->add_entities( newPartSets[val], &newCell, 1 );
MB_CHK_ERR( rval );
735 if( projection_type == 1 )
738 avg_position[0] * avg_position[0] + avg_position[1] * avg_position[1] + avg_position[2] * avg_position[2];
740 double lat = asin( avg_position[2] /
R );
741 double lon = atan2( avg_position[1], avg_position[0] );
742 avg_position[0] = lon;
743 avg_position[1] = lat;
746 else if( projection_type == 2 )
797 res.
lat = asin( cart3d[2] / res.
R );
798 res.
lon = atan2( cart3d[1], cart3d[0] );
799 if( res.
lon < 0 ) res.
lon += 2 * M_PI;
827 res[0] = sc.
R * cos( sc.
lat ) * cos( sc.
lon );
828 res[1] = sc.
R * cos( sc.
lat ) * sin( sc.
lon );
829 res[2] = sc.
R * sin( sc.
lat );
845 rval =
mb->get_coords( &nd, 1, (
double*)&( pos[0] ) );
847 double len = pos.
length();
848 if( len == 0. )
return MB_FAILURE;
850 rval =
mb->set_coords( &nd, 1, (
double*)&( pos[0] ) );
864 if( fabs( err1 ) > 0.0001 )
866 std::cout <<
" error in input " << a <<
" radius: " << Radius <<
" error:" << err1 <<
"\n";
870 return angle( normalOAB, normalOCB );
882 CartVect orient = ( c - b ) * ( a - b );
883 double ang =
angle( normalOAB, normalOCB );
887 std::cout << a <<
" " << b <<
" " << c <<
"\n";
888 std::cout << ang <<
"\n";
890 if( orient % b < 0 )
return ( 2 * M_PI - ang );
901 #ifdef MOAB_HAVE_TEMPESTREMAP
903 return area_spherical_triangle_GQ( A, B, C );
917 #ifdef MOAB_HAVE_TEMPESTREMAP
919 return area_spherical_polygon_GQ( A, N ) * Radius * Radius;
931 double area = Radius * Radius * correction;
934 CartVect abc = ( b - a ) * ( c - a );
946 if( N <= 2 )
return 0.;
947 double sum_angles = 0.;
948 for(
int i = 0; i < N; i++ )
950 int i1 = ( i + 1 ) % N;
951 int i2 = ( i + 2 ) % N;
954 double correction = sum_angles - ( N - 2 ) * M_PI;
955 return Radius * Radius * correction;
964 if( N <= 2 )
return 0.;
968 for(
int i = 1; i < N - 1; i++ )
972 if( areaTriangle < 0 )
975 area += areaTriangle;
977 if( sign ) *sign = lsign;
982 #ifdef MOAB_HAVE_TEMPESTREMAP
984 double IntxAreaUtils::area_spherical_polygon_GQ(
const double* A,
int N )
990 if( N <= 2 )
return 0.;
994 for(
int i = 1; i < N - 1; i++ )
996 area += area_spherical_triangle_GQ( A, A + 3 * i, A + 3 * ( i + 1 ) );
1001 template <
typename Derived >
1002 Eigen::Array< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > shift(
1003 const Eigen::ArrayBase< Derived >& array,
1006 Eigen::Array< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > result = array;
1009 result.segment( positions, array.size() - positions ) = array.head( array.size() - positions );
1010 result.head( positions ).setZero();
1012 else if( positions < 0 )
1014 result.head( array.size() + positions ) = array.tail( array.size() + positions );
1015 result.tail( -positions ).setZero();
1020 double IntxAreaUtils::area_spherical_triangle_GQ(
const double* inode1,
const double* inode2,
const double* inode3 )
1022 #if defined( MOAB_HAVE_EIGEN3 )
1023 typedef Eigen::Map< const Eigen::Vector3d > V3d;
1024 const V3d node1( inode1 );
1025 const V3d node2( inode2 );
1026 const V3d node3( inode3 );
1027 const int nOrder = 6;
1030 const double dG[6] = { 0.03376524289842397, 0.1693953067668678, 0.3806904069584016,
1031 0.6193095930415985, 0.8306046932331322, 0.966234757101576 };
1032 const double dW[6] = { 0.08566224618958521, 0.1803807865240693, 0.2339569672863455,
1033 0.2339569672863455, 0.1803807865240693, 0.08566224618958521 };
1035 double dFaceArea = 0.0;
1036 Eigen::Vector3d dF, dF2, dDaF, dDbF, dDaG, dDbG;
1037 double nodeCross[3];
1040 for(
int p = 0; p < nOrder; p++ )
1042 for(
int q = 0; q < nOrder; q++ )
1045 const double dA = dG[p];
1046 const double dB = dG[q];
1049 dF = ( ( ( 1.0 - dB ) * ( 1.0 - dA ) ) * node1 ) + ( ( ( 1.0 - dB ) * dA ) * node2 ) + ( dB * node3 );
1050 dF2 = dF.array().square();
1052 dDaF = ( node1 - node2 );
1055 dDbF = ( node3 - node1 ) + dA * dDaF;
1056 dDaF *= ( dB - 1.0 );
1058 const double dDenomTerm = std::pow( dF.norm(), -3.0 );
1076 dDaG( 0 ) = dDaF( 0 ) * ( dF2( 1 ) + dF2( 2 ) ) - dF( 0 ) * ( dDaF( 1 ) * dF( 1 ) + dDaF( 2 ) * dF( 2 ) );
1077 dDaG( 1 ) = dDaF( 1 ) * ( dF2( 0 ) + dF2( 2 ) ) - dF( 1 ) * ( dDaF( 0 ) * dF( 0 ) + dDaF( 2 ) * dF( 2 ) );
1078 dDaG( 2 ) = dDaF( 2 ) * ( dF2( 0 ) + dF2( 1 ) ) - dF( 2 ) * ( dDaF( 0 ) * dF( 0 ) + dDaF( 1 ) * dF( 1 ) );
1081 dDbG( 0 ) = dDbF( 0 ) * ( dF2( 1 ) + dF2( 2 ) ) - dF( 0 ) * ( dDbF( 1 ) * dF( 1 ) + dDbF( 2 ) * dF( 2 ) );
1082 dDbG( 1 ) = dDbF( 1 ) * ( dF2( 0 ) + dF2( 2 ) ) - dF( 1 ) * ( dDbF( 0 ) * dF( 0 ) + dDbF( 2 ) * dF( 2 ) );
1083 dDbG( 2 ) = dDbF( 2 ) * ( dF2( 0 ) + dF2( 1 ) ) - dF( 2 ) * ( dDbF( 0 ) * dF( 0 ) + dDbF( 1 ) * dF( 1 ) );
1090 nodeCross[0] = dDaG( 1 ) * dDbG( 2 ) - dDaG( 2 ) * dDbG( 1 );
1091 nodeCross[1] = dDaG( 2 ) * dDbG( 0 ) - dDaG( 0 ) * dDbG( 2 );
1092 nodeCross[2] = dDaG( 0 ) * dDbG( 1 ) - dDaG( 1 ) * dDbG( 0 );
1094 const double dJacobian =
1095 std::sqrt( nodeCross[0] * nodeCross[0] + nodeCross[1] * nodeCross[1] + nodeCross[2] * nodeCross[2] );
1098 dFaceArea += dW[p] * dW[q] * dJacobian;
1106 NodeVector nodes( 3 );
1107 nodes[0] = Node( inode1[0], inode1[1], inode1[2] );
1108 nodes[1] = Node( inode2[0], inode2[1], inode2[2] );
1109 nodes[2] = Node( inode3[0], inode3[1], inode3[2] );
1110 face.SetNode( 0, 0 );
1111 face.SetNode( 1, 1 );
1112 face.SetNode( 2, 2 );
1113 return CalculateFaceArea(
face, nodes );
1152 CartVect vA( ptA ), vB( ptB ), vC( ptC );
1158 if( ( vA * vB ) % vC < 0 ) sign = -1;
1159 double s = ( a + b + c ) / 2;
1160 double a1 = ( s - a ) / 2;
1161 double b1 = ( s - b ) / 2;
1162 double c1 = ( s - c ) / 2;
1163 #ifdef MOAB_HAVE_TEMPESTREMAP
1164 if( fabs( a1 ) < 1.e-14 || fabs( b1 ) < 1.e-14 || fabs( c1 ) < 1.e-14 )
1166 double area = area_spherical_triangle_GQ( ptA, ptB, ptC ) * sign;
1168 std::cout <<
" very obtuse angle, use TR to compute area " <<
" a1:" << a1 <<
" b1:" << b1 <<
" c1:" << c1
1170 std::cout <<
" area with TR: " << area <<
"\n";
1175 double tmp = tan( s / 2 ) * tan( a1 ) * tan( b1 ) * tan( c1 );
1176 if( tmp < 0. ) tmp = 0.;
1178 double E = 4 * atan( sqrt( tmp ) );
1179 if(
E !=
E ) std::cout <<
" NaN at spherical triangle area \n";
1181 double area = sign *
E * Radius * Radius;
1183 #ifdef CHECKNEGATIVEAREA
1186 std::cout <<
"negative area: " << area <<
"\n";
1187 std::cout << std::setprecision( 15 );
1188 std::cout <<
"vA: " << vA <<
"\n";
1189 std::cout <<
"vB: " << vB <<
"\n";
1190 std::cout <<
"vC: " << vC <<
"\n";
1191 std::cout <<
"sign: " << sign <<
"\n";
1192 std::cout <<
" a: " << a <<
"\n";
1193 std::cout <<
" b: " << b <<
"\n";
1194 std::cout <<
" c: " << c <<
"\n";
1208 std::vector< int > ownerinfo( inputRange.
size(), -1 );
1210 rval =
mb->tag_get_handle(
"ORIG_PROC", intxOwnerTag );
1213 rval =
mb->tag_get_data( intxOwnerTag, inputRange, &ownerinfo[0] );
MB_CHK_ERR_RET_VAL( rval, -1.0 );
1218 double total_area = 0.;
1223 if( ownerinfo[ie++] >= 0 )
continue;
1229 if( elem_area <= 0 )
1231 std::cout <<
"Area of element " <<
mb->id_from_handle( eh ) <<
" is = " << elem_area <<
"\n";
1232 mb->list_entity( eh );
1234 assert( elem_area > 0 );
1237 total_area += elem_area;
1252 while( verts[nsides - 2] == verts[nsides - 1] && nsides > 3 )
1256 std::vector< double > coords( 3 * nsides );
1269 acos( sin( sph1.
lon ) * sin( sph2.
lon ) + cos( sph1.
lat ) * cos( sph2.
lat ) * cos( sph2.
lon - sph2.
lon ) );
1298 std::vector< double > coords;
1302 std::queue< EntityHandle > newPolys;
1303 int brokenPolys = 0;
1305 while( eit != inputRange.
end() || !newPolys.empty() )
1308 if( eit != inputRange.
end() )
1315 eh = newPolys.front();
1321 rval =
mb->get_connectivity( eh, verts, num_nodes );
MB_CHK_ERR( rval );
1322 int nsides = num_nodes;
1324 while( verts[nsides - 2] == verts[nsides - 1] && nsides > 3 )
1329 rval =
mb->tag_get_data( corrTag, &eh, 1, &corrHandle );
MB_CHK_ERR( rval );
1332 rval =
mb->tag_get_data( gidTag, &eh, 1, &gid );
MB_CHK_ERR( rval );
1333 coords.resize( 3 * nsides );
1334 if( nsides < 4 )
continue;
1336 rval =
mb->get_coords( verts, nsides, &coords[0] );
MB_CHK_ERR( rval );
1338 bool alreadyBroken =
false;
1340 for(
int i = 0; i < nsides; i++ )
1342 double* A = &coords[3 * i];
1343 double* B = &coords[3 * ( ( i + 1 ) % nsides )];
1344 double* C = &coords[3 * ( ( i + 2 ) % nsides )];
1346 if(
angle - M_PI > 0. )
1350 mb->list_entities( &eh, 1 );
1351 mb->list_entities( verts, nsides );
1352 double* D = &coords[3 * ( ( i + 3 ) % nsides )];
1353 std::cout <<
"ABC: " <<
angle <<
" \n";
1357 std::cout <<
" this cell has at least 2 angles > 180, it has serious issues\n";
1368 EntityHandle conn3[3] = { verts[( i + 1 ) % nsides], verts[( i + 2 ) % nsides],
1369 verts[( i + 3 ) % nsides] };
1372 std::vector< EntityHandle > conn( nsides - 1 );
1373 for(
int j = 1; j < nsides; j++ )
1375 conn[j - 1] = verts[( i + j + 2 ) % nsides];
1380 rval =
mb->add_entities( lset, &newElement, 1 );
MB_CHK_ERR( rval );
1383 rval =
mb->tag_set_data( corrTag, &newElement, 1, &corrHandle );
MB_CHK_ERR( rval );
1385 rval =
mb->tag_set_data( gidTag, &newElement, 1, &gid );
MB_CHK_ERR( rval );
1395 newPolys.push( newElement );
1398 rval =
mb->add_entities( lset, &newElement, 1 );
MB_CHK_ERR( rval );
1401 rval =
mb->tag_set_data( corrTag, &newElement, 1, &corrHandle );
MB_CHK_ERR( rval );
1403 rval =
mb->tag_set_data( gidTag, &newElement, 1, &gid );
MB_CHK_ERR( rval );
1404 rval =
mb->remove_entities( lset, &eh, 1 );
MB_CHK_ERR( rval );
1406 alreadyBroken =
true;
1410 if( brokenPolys > 0 )
1412 std::cout <<
"on local process " << my_rank <<
", " << brokenPolys
1413 <<
" concave polygons were decomposed in convex ones \n";
1415 std::stringstream fff;
1416 fff <<
"file_set" <<
mb->id_from_handle( lset ) <<
"rk_" << my_rank <<
".h5m";
1417 rval =
mb->write_file( fff.str().c_str(), 0, 0, &lset, 1 );
MB_CHK_ERR( rval );
1418 std::cout <<
"wrote new file set: " << fff.str() <<
"\n";
1431 gid =
mb->globalId_tag();
1437 rval =
mb->get_connectivity( quad, conn4, num_nodes );
MB_CHK_ERR( rval );
1438 for(
int i = 0; i < num_nodes; i++ )
1440 int next_node_index = ( i + 1 ) % num_nodes;
1441 if( conn4[i] == conn4[next_node_index] )
1446 rval =
mb->tag_get_data( gid, &quad, 1, &global_id );
MB_CHK_ERR( rval );
1447 int i2 = ( i + 2 ) % num_nodes;
1448 int i3 = ( i + 3 ) % num_nodes;
1449 EntityHandle conn3[3] = { conn4[i], conn4[i2], conn4[i3] };
1452 mb->add_entities( set, &tri, 1 );
1453 mb->remove_entities( set, &quad, 1 );
1454 mb->delete_entities( &quad, 1 );
1455 rval =
mb->tag_set_data( gid, &tri, 1, &global_id );
MB_CHK_ERR( rval );
1471 rval =
mb->get_connectivity( cell, conn, num_nodes );
MB_CHK_ERR( rval );
1472 if( num_nodes < 3 )
return MB_FAILURE;
1475 rval =
mb->get_coords( conn, 3, coords );
MB_CHK_ERR( rval );
1485 std::vector< double > coords2( 3 * num_nodes );
1487 rval =
mb->get_coords( conn, num_nodes, &coords2[0] );
MB_CHK_ERR( rval );
1491 std::vector< EntityHandle > newconn( num_nodes );
1492 for(
int i = 0; i < num_nodes; i++ )
1494 newconn[num_nodes - 1 - i] = conn[i];
1496 rval =
mb->set_connectivity( cell, &newconn[0], num_nodes );
MB_CHK_ERR( rval );
1500 std::cout <<
" nonconvex problem first area:" << area <<
" total area: " << totArea << std::endl;
1511 return acos( sin( te1 ) * sin( te2 ) + cos( te1 ) * cos( te2 ) * cos( la1 - la2 ) );
1522 const double Tolerance = 1.e-12 * R2;
1524 CartVect a( A ), b( B ), c( C ), d( D );
1526 if( fabs( a.length_squared() - R2 ) + fabs( b.length_squared() - R2 ) + fabs( c.length_squared() - R2 ) +
1542 if( n1 % n4 >= -Tolerance && n1 % n5 >= -Tolerance )
1547 if( n2 % n4 >= -Tolerance && n2 % n5 >= -Tolerance )
1560 n4 = a * n3, n5 = n3 * b;
1561 if( n1 % n4 >= -Tolerance && n1 % n5 >= -Tolerance )
1566 if( n2 % n4 >= -Tolerance && n2 % n5 >= -Tolerance )
1592 if( n1 % n2 < 0 || n1 % n3 < 0 )
return false;
1595 c[2] = d[2] = s[2] = 0.;
1600 if( n1 % n2 < 0 || n1 % n3 < 0 )
return false;
1613 const double distTol =
R * 1.e-6;
1614 const double Tolerance =
R *
R * 1.e-12;
1616 CartVect a( A ), b( B ), c( C ), d( D );
1619 if( fabs( a.length_squared() - R2 ) + fabs( b.length_squared() - R2 ) + fabs( c.length_squared() - R2 ) +
1629 if( fabs( C[2] - D[2] ) > distTol )
1632 if( fabs(
R - C[2] ) < distTol || fabs(
R + C[2] ) < distTol )
return MB_FAILURE;
1644 if( fabs( n1[0] ) + fabs( n1[1] ) < 2 * Tolerance )
1647 if( fabs( C[2] ) > distTol )
1662 bool agtc = ( ca % cd >= -Tolerance );
1663 bool dgta = ( ad % cd >= -Tolerance );
1664 bool bgtc = ( cb % cd >= -Tolerance );
1665 bool dgtb = ( bd % cd >= -Tolerance );
1772 if( fabs( n1[0] ) <= fabs( n1[1] ) )
1779 double u = -n1[2] / n1[1] * z, v = -n1[0] / n1[1];
1780 double a1 = v * v + 1, b1 = 2 * u * v, c1 = u * u + z * z - R2;
1781 double delta = b1 * b1 - 4 * a1 * c1;
1782 if( delta < -Tolerance )
return MB_FAILURE;
1783 if( delta > Tolerance )
1785 double x1 = ( -b1 + sqrt( delta ) ) / 2 / a1;
1786 double x2 = ( -b1 - sqrt( delta ) ) / 2 / a1;
1787 double y1 = u + v * x1;
1788 double y2 = u + v * x2;
1789 if(
verify( a, b, c, d, x1, y1, z ) )
1796 if(
verify( a, b, c, d, x2, y2, z ) )
1807 double x1 = -b1 / 2 / a1;
1808 double y1 = u + v * x1;
1809 if(
verify( a, b, c, d, x1, y1, z ) )
1826 double u = -n1[2] / n1[0] * z, v = -n1[1] / n1[0];
1827 double a1 = v * v + 1, b1 = 2 * u * v, c1 = u * u + z * z - R2;
1828 double delta = b1 * b1 - 4 * a1 * c1;
1829 if( delta < -Tolerance )
return MB_FAILURE;
1830 if( delta > Tolerance )
1832 double y1 = ( -b1 + sqrt( delta ) ) / 2 / a1;
1833 double y2 = ( -b1 - sqrt( delta ) ) / 2 / a1;
1834 double x1 = u + v * y1;
1835 double x2 = u + v * y2;
1836 if(
verify( a, b, c, d, x1, y1, z ) )
1843 if(
verify( a, b, c, d, x2, y2, z ) )
1854 double y1 = -b1 / 2 / a1;
1855 double x1 = u + v * y1;
1856 if(
verify( a, b, c, d, x1, y1, z ) )
1867 if( np <= 0 )
return MB_FAILURE;
1891 int type_constant_lat=1;
1904 if (fabs( coords[2]-coords[5] )< 1.e-6 )
1928 int extraPoints = 0;
1930 CartVect A( 0. ), B( 0. ), C( 0. ), D( 0. );
1931 for(
int i = 0; i < nsBlue; i++ )
1933 if( blueEdgeType[i] == 0 )
1935 int iP1 = ( i + 1 ) % nsBlue;
1936 if( bluec[i][2] > bluec[iP1][2] )
1940 C = bluec[( i + 2 ) % nsBlue];
1941 D = bluec[( i + 3 ) % nsBlue];
1946 if( nsBlue == 3 && B[2] < 0 )
1955 for(
int i = 0; i < nsRed; i++ )
1958 if( X[2] > A[2] || X[2] < B[2] )
continue;
1960 if( ( ( A * B ) % X >= -epsil ) && ( ( C * D ) % X >= -epsil ) )
1965 P[extraPoints * 2] = red2dc[2 * i];
1966 P[extraPoints * 2 + 1] = red2dc[2 * i + 1];
1984 Tag gid =
mb->globalId_tag();
1990 rval =
mb->get_connectivity( quads, connecVerts );
MB_CHK_ERR( rval );
1992 std::map< EntityHandle, EntityHandle > newNodes;
1994 std::vector< double* > coords;
1996 int num_verts = connecVerts.
size();
1997 rval = read_iface->
get_node_coords( 3, num_verts, 0, start_vert, coords );
2005 rval =
mb->get_coords( &oldV, 1, &( posi[0] ) );
MB_CHK_ERR( rval );
2008 rval =
mb->tag_get_data( gid, &oldV, 1, &global_id );
MB_CHK_ERR( rval );
2011 coords[0][i] = posi[0];
2012 coords[1][i] = posi[1];
2013 coords[2][i] = posi[2];
2015 newNodes[oldV] = new_vert;
2017 rval =
mb->tag_set_data( corrTag, &oldV, 1, &new_vert );
MB_CHK_ERR( rval );
2022 rval =
mb->tag_set_data( corrTag, &new_vert, 1, &oldV );
MB_CHK_ERR( rval );
2024 rval =
mb->tag_set_data( gid, &new_vert, 1, &global_id );
MB_CHK_ERR( rval );
2036 rval =
mb->get_connectivity( q, conn, nnodes );
MB_CHK_ERR( rval );
2038 rval =
mb->tag_get_data( gid, &q, 1, &global_id );
MB_CHK_ERR( rval );
2040 for(
int ii = 0; ii < nnodes; ii++ )
2043 connect[4 * ie + ii] = newNodes[v1];
2048 rval =
mb->tag_set_data( corrTag, &q, 1, &newElement );
MB_CHK_ERR( rval );
2049 rval =
mb->tag_set_data( corrTag, &newElement, 1, &q );
MB_CHK_ERR( rval );
2052 rval =
mb->tag_set_data( gid, &newElement, 1, &global_id );
MB_CHK_ERR( rval );
2054 rval =
mb->add_entities( dest_set, &newElement, 1 );
MB_CHK_ERR( rval );
2065 std::vector< Tag >& tagList )
2069 rval =
mb->remove_entities( file_set, verts );
MB_CHK_ERR( rval );
2090 rval =
mb->get_connectivity( cells, verts );
MB_CHK_ERR( rval );
2092 Range modifiedCells;
2100 rval =
mb->get_connectivity( cell, connec, num_verts );
MB_CHK_SET_ERR( rval,
"Failed to get connectivity" );
2102 std::vector< EntityHandle > newConnec;
2103 newConnec.push_back( connec[0] );
2106 while( index < num_verts - 2 )
2108 int next_index = ( index + 1 );
2109 if( connec[next_index] != newConnec[new_size - 1] )
2111 newConnec.push_back( connec[next_index] );
2117 if( ( connec[num_verts - 1] != connec[num_verts - 2] ) && ( connec[num_verts - 1] != connec[0] ) )
2119 newConnec.push_back( connec[num_verts - 1] );
2122 if( new_size < num_verts )
2125 modifiedCells.
insert( cell );
2127 EntityType type =
MBTRI;
2130 else if( new_size == 4 )
2132 else if( new_size > 4 )
2137 rval =
mb->create_element( type, &newConnec[0], new_size, newCell );
MB_CHK_SET_ERR( rval,
"Failed to create new cell" );
2139 newCells.
insert( newCell );
2141 for(
size_t i = 0; i < tagList.size(); i++ )
2143 rval =
mb->tag_get_data( tagList[i], &cell, 1, (
void*)( &value ) );
MB_CHK_SET_ERR( rval,
"Failed to get tag value" );
2144 rval =
mb->tag_set_data( tagList[i], &newCell, 1, (
void*)( &value ) );
MB_CHK_SET_ERR( rval,
"Failed to set tag value on new cell" );
2149 rval =
mb->remove_entities( file_set, modifiedCells );
MB_CHK_SET_ERR( rval,
"Failed to remove old cells from file set" );
2150 rval =
mb->delete_entities( modifiedCells );
MB_CHK_SET_ERR( rval,
"Failed to delete old cells" );
2151 rval =
mb->add_entities( file_set, newCells );
MB_CHK_SET_ERR( rval,
"Failed to add new cells to file set" );
2152 rval =
mb->add_entities( file_set, verts );
MB_CHK_SET_ERR( rval,
"Failed to add verts to the file set" );