[MOAB-dev] commit/MOAB: iulian07: allow padded polygons for intersection algorithm
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Feb 6 14:30:45 CST 2014
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/ba2ef654493a/
Changeset: ba2ef654493a
Branch: master
User: iulian07
Date: 2014-02-06 21:28:27
Summary: allow padded polygons for intersection algorithm
padded polygons have less memory fragmentation; it may help for fusion
problems with memory
Affected #: 3 files
diff --git a/tools/mbcslam/CslamUtils.cpp b/tools/mbcslam/CslamUtils.cpp
index 43668a6..0c8d5f3 100644
--- a/tools/mbcslam/CslamUtils.cpp
+++ b/tools/mbcslam/CslamUtils.cpp
@@ -960,6 +960,10 @@ ErrorCode enforce_convexity(Interface * mb, EntityHandle lset, int my_rank)
rval = mb->get_connectivity(eh, verts, num_nodes);
if (MB_SUCCESS != rval)
return rval;
+ int nsides = num_nodes;
+ // account for possible padded polygons
+ while (verts[nsides-2]==verts[nsides-1] && nsides>3)
+ nsides--;
EntityHandle corrHandle=0;
if (corrTag)
{
@@ -971,34 +975,34 @@ ErrorCode enforce_convexity(Interface * mb, EntityHandle lset, int my_rank)
rval = mb->tag_get_data(gidTag, &eh, 1, &gid);
if (MB_SUCCESS != rval)
return rval;
- coords.resize(3 * num_nodes);
- if (num_nodes < 4)
+ coords.resize(3 * nsides);
+ if (nsides < 4)
continue; // if already triangles, don't bother
// get coordinates
- rval = mb->get_coords(verts, num_nodes, &coords[0]);
+ rval = mb->get_coords(verts, nsides, &coords[0]);
if (MB_SUCCESS != rval)
return rval;
// compute each angle
bool alreadyBroken = false;
- for (int i=0; i<num_nodes; i++)
+ for (int i=0; i<nsides; i++)
{
double * A = &coords[3*i];
- double * B = &coords[3*((i+1)%num_nodes)];
- double * C = &coords[3*((i+2)%num_nodes)];
+ double * B = &coords[3*((i+1)%nsides)];
+ double * C = &coords[3*((i+2)%nsides)];
double angle = oriented_spherical_angle(A, B, C);
if (angle-M_PI > 0.) // even almost reflex is bad; break it!
{
if (alreadyBroken)
{
mb->list_entities(&eh, 1);
- mb->list_entities(verts, num_nodes);
- double * D = &coords[3*((i+3)%num_nodes)];
+ mb->list_entities(verts, nsides);
+ double * D = &coords[3*((i+3)%nsides)];
std::cout<< "ABC: " << angle << " \n";
std::cout<< "BCD: " << oriented_spherical_angle( B, C, D) << " \n";
std::cout<< "CDA: " << oriented_spherical_angle( C, D, A) << " \n";
std::cout<< "DAB: " << oriented_spherical_angle( D, A, B)<< " \n";
- std::cout << " this quad has at least 2 angles > 180, it has serious issues\n";
+ std::cout << " this cell has at least 2 angles > 180, it has serious issues\n";
return MB_FAILURE;
}
@@ -1009,15 +1013,15 @@ ErrorCode enforce_convexity(Interface * mb, EntityHandle lset, int my_rank)
// break the next triangle, even though not optimal
// so create the triangle i+1, i+2, i+3; remove i+2 from original list
// even though not optimal in general, it is good enough.
- EntityHandle conn3[3]={ verts[ (i+1)%num_nodes],
- verts[ (i+2)%num_nodes],
- verts[ (i+3)%num_nodes] };
+ EntityHandle conn3[3]={ verts[ (i+1)%nsides],
+ verts[ (i+2)%nsides],
+ verts[ (i+3)%nsides] };
// create a polygon with num_nodes-1 vertices, and connectivity
// verts[i+1], verts[i+3], (all except i+2)
- std::vector<EntityHandle> conn(num_nodes-1);
- for (int j=1; j<num_nodes; j++)
+ std::vector<EntityHandle> conn(nsides-1);
+ for (int j=1; j<nsides; j++)
{
- conn[j-1]=verts[(i+j+2)%num_nodes];
+ conn[j-1]=verts[(i+j+2)%nsides];
}
EntityHandle newElement;
rval = mb->create_element(MBTRI, conn3, 3, newElement);
@@ -1036,7 +1040,7 @@ ErrorCode enforce_convexity(Interface * mb, EntityHandle lset, int my_rank)
rval = mb->tag_set_data(gidTag, &newElement, 1, &gid);
if (MB_SUCCESS != rval)
return rval;
- if (num_nodes == 4)
+ if (nsides == 4)
{
// create another triangle
rval = mb->create_element(MBTRI, &conn[0], 3, newElement);
@@ -1046,7 +1050,7 @@ ErrorCode enforce_convexity(Interface * mb, EntityHandle lset, int my_rank)
else
{
// create another polygon, and add it to the inputRange
- rval = mb->create_element(MBPOLYGON, &conn[0], num_nodes-1, newElement);
+ rval = mb->create_element(MBPOLYGON, &conn[0], nsides-1, newElement);
if (MB_SUCCESS != rval)
return rval;
newPolys.push(newElement); // because it has less number of edges, the
diff --git a/tools/mbcslam/Intx2Mesh.cpp b/tools/mbcslam/Intx2Mesh.cpp
index 99d7ca3..311bfd4 100644
--- a/tools/mbcslam/Intx2Mesh.cpp
+++ b/tools/mbcslam/Intx2Mesh.cpp
@@ -110,7 +110,10 @@ ErrorCode Intx2Mesh::GetOrderedNeighbors(EntityHandle set, EntityHandle cell,
// first cell is for nodes 0, 1, second to 1, 2, third to 2, 3, last to nnodes-1,
const EntityHandle * conn4;
ErrorCode rval = mb->get_connectivity(cell, conn4, nnodes);
- int nsides = nnodes; // just keep it for historical purposes; it is indeed nnodes
+ int nsides = nnodes;
+ // account for possible padded polygons
+ while (conn4[nsides-2]==conn4[nsides-1] && nsides>3)
+ nsides--;
ERRORR(rval, "can't get connectivity on an element");
for (int i = 0; i < nsides; i++)
{
diff --git a/tools/mbcslam/Intx2MeshOnSphere.cpp b/tools/mbcslam/Intx2MeshOnSphere.cpp
index ef4d219..ac33e91 100644
--- a/tools/mbcslam/Intx2MeshOnSphere.cpp
+++ b/tools/mbcslam/Intx2MeshOnSphere.cpp
@@ -45,9 +45,12 @@ int Intx2MeshOnSphere::computeIntersectionBetweenRedAndBlue(EntityHandle red, En
if (MB_SUCCESS != rval )
return 1;
nsRed = num_nodes;
+ // account for possible padded polygons
+ while (redConn[nsRed-2]==redConn[nsRed-1] && nsRed>3)
+ nsRed--;
//CartVect coords[4];
- rval = mb->get_coords(redConn, num_nodes, &(redCoords[0][0]));
+ rval = mb->get_coords(redConn, nsRed, &(redCoords[0][0]));
if (MB_SUCCESS != rval)
return 1;
CartVect middle = redCoords[0];
@@ -61,6 +64,9 @@ int Intx2MeshOnSphere::computeIntersectionBetweenRedAndBlue(EntityHandle red, En
if (MB_SUCCESS != rval )
return 1;
nsBlue = num_nodes;
+ // account for possible padded polygons
+ while (blueConn[nsBlue-2]==blueConn[nsBlue-1] && nsBlue>3)
+ nsBlue--;
rval = mb->get_coords(blueConn, nsBlue, &(blueCoords[0][0]));
if (MB_SUCCESS != rval)
return 1;
@@ -202,7 +208,7 @@ int Intx2MeshOnSphere::findNodes(EntityHandle red, int nsRed, EntityHandle blue,
int i = 0;
for (i = 0; i < nsRed; i++)
{
- EntityHandle v[2] = { redConn[i], redConn[(i + 1) % nsRed] };
+ EntityHandle v[2] = { redConn[i], redConn[(i + 1) % nsRed] };// this is fine even for padded polygons
std::vector<EntityHandle> adj_entities;
ErrorCode rval = mb->get_adjacencies(v, 2, 1, false, adj_entities,
Interface::INTERSECT);
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