示例#1
0
inline iMesh::Error
iMesh::getEntArrAdj( const EntityHandle* entity_handles,
                           int entity_handles_size,
                           EntityType type_requested,
                           std::vector<EntityHandle>& adj_entities_out,
                           int* offsets_out ) const
{
  if (adj_entities_out.capacity() == 0) 
    adj_entities_out.resize(12*entity_handles_size);
  else
    adj_entities_out.resize( adj_entities_out.capacity() );
  
  int err, alloc = adj_entities_out.size(), size = 0;
  int off_alloc = entity_handles_size+1, junk;
  EntityHandle* ptr = &adj_entities_out[0];
  iMesh_getEntArrAdj( mInstance, entity_handles, entity_handles_size, 
                      type_requested,
                      &ptr, &alloc, &size,
                      &offsets_out, &off_alloc, &junk,
                      &err );
  adj_entities_out.resize(size);
  
  if (iBase_BAD_ARRAY_DIMENSION == err || iBase_BAD_ARRAY_SIZE == err) {
    alloc = adj_entities_out.size();
    ptr = &adj_entities_out[0];
    iMesh_getEntArrAdj( mInstance, entity_handles, entity_handles_size, 
                        type_requested,
                        &ptr, &alloc, &size,
                        &offsets_out, &off_alloc, &junk,
                        &err );
  }
  
  return (Error)err;
}
示例#2
0
void test_getEntArrAdj_invalid_size()
{
  iMesh_Instance mesh = create_mesh();
  int err = -1;
  
  const int SPECIAL1 = 0xDeadBeef;
  const int SPECIAL2 = 0xCafe5;
  const int SPECIAL3 = 0xbabb1e;
  
    // test a downward query
  volatile int marker1 = SPECIAL1;
  iBase_EntityHandle adj1[8*INTERVALS-1]; // one too small
  volatile int marker2 = SPECIAL2;
  int off1[INTERVALS+1];
  int adj1_alloc = sizeof(adj1)/sizeof(adj1[0]);
  int off1_alloc = sizeof(off1)/sizeof(off1[0]);
  int adj_size, off_size;
  iBase_EntityHandle* adj_ptr = adj1;
  int* off_ptr = off1;
  iMesh_getEntArrAdj( mesh, HEXES[0][0], INTERVALS, iBase_VERTEX,
                      &adj_ptr, &adj1_alloc, &adj_size, 
                      &off_ptr, &off1_alloc, &off_size,
                      &err );
  CHECK_EQUAL( &adj1[0], adj_ptr );
  CHECK_EQUAL( &off1[0], off_ptr );
    // first ensure no stack corruption from writing off end of array
  CHECK_EQUAL( SPECIAL1, marker1 );
  CHECK_EQUAL( SPECIAL2, marker2 );
    // now verify that it correctly failed
  CHECK_EQUAL( iBase_BAD_ARRAY_SIZE, err );
  
    // now test an upwards query
  volatile int marker3 = SPECIAL3;
  int off2[INTERVALS];
  volatile int marker4 = SPECIAL1;
  int off2_alloc = sizeof(off2)/sizeof(off2[0]);
  err = iBase_SUCCESS;
  adj_ptr = adj1;
  off_ptr = off2;
  iMesh_getEntArrAdj( mesh, VERTS[0][0], INTERVALS+1, iBase_REGION,
                      &adj_ptr, &adj1_alloc, &adj_size, 
                      &off_ptr, &off2_alloc, &off_size,
                      &err );
    // first ensure no stack corruption from writing off end of array
  CHECK_EQUAL( &adj1[0], adj_ptr );
  CHECK_EQUAL( &off2[0], off_ptr );
  CHECK_EQUAL( SPECIAL3, marker3 );
  CHECK_EQUAL( SPECIAL1, marker4 );
    // now verify that it correctly failed
  CHECK_EQUAL( iBase_BAD_ARRAY_SIZE, err );
}
示例#3
0
void test_getEntArrAdj_up()
{
  iMesh_Instance mesh = create_mesh();
  int err;
  
  // get hexes adjacent to a row of faces in the z=0 plane
  iBase_EntityHandle *adj = 0;
  int *off = 0;
  int adj_alloc = 0, off_alloc = 0;
  int adj_size = -1, off_size = -1;
  iMesh_getEntArrAdj( mesh, FACES[4][0], INTERVALS, iBase_REGION,
                      &adj, &adj_alloc, &adj_size,
                      &off, &off_alloc, &off_size,
                      &err );
  CHECK_EQUAL( iBase_SUCCESS, err );
  CHECK( 0 != adj );
  CHECK( 0 != off );
  CHECK_EQUAL( INTERVALS, adj_size ); // one hex adjacent to each skin face
  CHECK_EQUAL( INTERVALS+1, off_size ); // one more than number of input handles
  CHECK( adj_alloc >= adj_size );
  CHECK( off_alloc >= off_size );
  
  for (int i = 0; i < INTERVALS; ++i) {
    CHECK_EQUAL( 1, off[i+1] - off[i] );
    CHECK_EQUAL( HEXES[0][i][0], adj[off[i]] );
  }
  
  free(adj);
  free(off);
}
示例#4
0
文件: genblock.c 项目: jedbrown/dohp
static dErr doMaterial(iMesh_Instance mesh,iBase_EntitySetHandle root)
{
  static const char matSetName[] = "MAT_SET",matNumName[] = "MAT_NUM";
  dMeshTag matSetTag,matNumTag;
  dMeshESH mat[2];
  dMeshEH *ents;
  MeshListEH r=MLZ,v=MLZ;
  MeshListInt rvo=MLZ;
  MeshListReal x=MLZ;
  dReal fx,center[3],*matnum;
  dInt nents;
  dErr err;

  dFunctionBegin;
  iMesh_createTag(mesh,matSetName,1,iBase_INTEGER,&matSetTag,&err,sizeof(matSetName));dICHK(mesh,err);
  iMesh_createTag(mesh,matNumName,1,iBase_DOUBLE,&matNumTag,&err,sizeof(matNumName));dICHK(mesh,err);
  iMesh_getEntities(mesh,root,iBase_REGION,iMesh_ALL_TOPOLOGIES,MLREF(r),&err);dICHK(mesh,err);
  iMesh_getEntArrAdj(mesh,r.v,r.s,iBase_VERTEX,MLREF(v),MLREF(rvo),&err);dICHK(mesh,err);
  iMesh_getVtxArrCoords(mesh,v.v,v.s,iBase_INTERLEAVED,MLREF(x),&err);dICHK(mesh,err);
  err = dMalloc(r.s*sizeof(ents[0]),&ents);dCHK(err);
  err = dMalloc(r.s*sizeof(matnum[0]),&matnum);dCHK(err);
  for (dInt i=0; i<2; i++) {
    iMesh_createEntSet(mesh,0,&mat[i],&err);dICHK(mesh,err);
    iMesh_setEntSetData(mesh,mat[i],matSetTag,(char*)&i,sizeof(i),&err);dICHK(mesh,err);
    nents = 0;
    for (dInt j=0; j<r.s; j++) {
      dGeomVecMeanI(8,x.v+3*rvo.v[j],center);
      fx = sqrt(dGeomDotProd(center,center)); /* material 0 if inside the unit ball, else material 1 */
      if (i == (fx < 1.0) ? 0 : 1) {
        ents[nents] = r.v[j];
        matnum[nents] = 1.0 * i;
        nents++;
      }
    }
    iMesh_addEntArrToSet(mesh,ents,nents,mat[i],&err);dICHK(mesh,err);
    iMesh_setArrData(mesh,ents,nents,matNumTag,(char*)matnum,nents*(int)sizeof(matnum[0]),&err);dICHK(mesh,err);
  }
  err = dFree(ents);dCHK(err);
  err = dFree(matnum);dCHK(err);
  MeshListFree(r); MeshListFree(v); MeshListFree(rvo); MeshListFree(x);
  dFunctionReturn(0);
}
示例#5
0
void test_getEntArrAdj_none()
{
  iMesh_Instance mesh = create_mesh();
  int err = -1;

  iBase_EntityHandle* adj = 0;
  int* off = 0;
  int adj_alloc = 0, off_alloc = 0;
  int adj_size = -1, off_size = -1;
  iMesh_getEntArrAdj( mesh, NULL, 0, iBase_REGION, 
                      &adj, &adj_alloc, &adj_size,
                      &off, &off_alloc, &off_size,
                      &err );
  CHECK_EQUAL( iBase_SUCCESS, err );
  CHECK_EQUAL( 0, adj_alloc );
  CHECK_EQUAL( 0, adj_size );
  CHECK_EQUAL( 1, off_size );
  CHECK( off_alloc >= 1 );
  CHECK_EQUAL( 0, off[0] );  
  
  free(off);
}
示例#6
0
void test_getEntArrAdj_vertex()
{
  iMesh_Instance mesh = create_mesh();
  int err;
  
  // get hexes adjacent to row of vertices at x=0,y=0;
  iBase_EntityHandle *adj = 0;
  int *off = 0;
  int adj_alloc = 0, off_alloc = 0;
  int adj_size = -1, off_size = -1;
  iMesh_getEntArrAdj( mesh, VERTS[0][0], INTERVALS+1, iBase_REGION,
                      &adj, &adj_alloc, &adj_size,
                      &off, &off_alloc, &off_size,
                      &err );
  CHECK_EQUAL( iBase_SUCCESS, err );
  CHECK( 0 != adj );
  CHECK( 0 != off );
  CHECK_EQUAL( 2*INTERVALS, adj_size ); // INTERVALS+1 verts, end ones with one hex, others with two
  CHECK_EQUAL( INTERVALS+2, off_size ); // one more than number of input handles
  CHECK( adj_alloc >= adj_size );
  CHECK( off_alloc >= off_size );
  
    // first and last vertices should have one adjacent hex
  CHECK_EQUAL( 1, off[1] - off[0] );
  CHECK_EQUAL( HEXES[0][0][0], adj[off[0]] );
  CHECK_EQUAL( 1, off[INTERVALS+1] - off[INTERVALS] );
  CHECK_EQUAL( HEXES[0][0][INTERVALS-1], adj[off[INTERVALS]] );
    // middle ones should have two adjacent hexes
  for (int i = 1; i < INTERVALS; ++i) {
    CHECK_EQUAL( 2, off[i+1] - off[i] );
    CHECK_EQUAL( HEXES[0][0][i-1], adj[off[i]  ] );
    CHECK_EQUAL( HEXES[0][0][i  ], adj[off[i]+1] );
  }
  
  free(adj);
  free(off);
}
示例#7
0
void test_getEntArrAdj_down()
{
  iMesh_Instance mesh = create_mesh();
  int err;
  
  // get quads adjacent to a edge-row of hexes
  iBase_EntityHandle *adj = 0;
  int *off = 0;
  int adj_alloc = 0, off_alloc = 0;
  int adj_size = -1, off_size = -1;
  iMesh_getEntArrAdj( mesh, HEXES[0][0], INTERVALS, iBase_FACE,
                      &adj, &adj_alloc, &adj_size,
                      &off, &off_alloc, &off_size,
                      &err );
  CHECK_EQUAL( iBase_SUCCESS, err );
  CHECK( 0 != adj );
  CHECK( 0 != off );
  CHECK_EQUAL( 2*INTERVALS+2, adj_size ); // corner hexes adj to 3 faces, others adj to 2
  CHECK_EQUAL( INTERVALS+1, off_size ); // one more than number of input handles
  CHECK( adj_alloc >= adj_size );
  CHECK( off_alloc >= off_size );
  
    // first (corner) hex should have three adjacent faces
  CHECK_EQUAL( 3, off[1] - off[0] );
  iBase_EntityHandle exp[3] = { FACES[0][0][0],
                                FACES[3][0][0],
                                FACES[4][0][0] };
  iBase_EntityHandle act[3];
  std::copy( adj + off[0], adj+off[1], act );
  std::sort( exp, exp+3 );
  std::sort( act, act+3 );
  CHECK_ARRAYS_EQUAL( exp, 3, act, 3 );
  
    // last (corner) hex should have three adjacent faces
  CHECK_EQUAL( 3, off[INTERVALS] - off[INTERVALS-1] );
  iBase_EntityHandle exp2[3] = { FACES[0][0][INTERVALS-1],
                                 FACES[3][0][INTERVALS-1],
                                 FACES[5][0][0] };
  std::copy( adj + off[INTERVALS-1], adj+off[INTERVALS], act );
  std::sort( exp2, exp2+3 );
  std::sort( act, act+3 );
  CHECK_ARRAYS_EQUAL( exp2, 3, act, 3 );
  
    // all middle hexes should have two adjacent faces
  for (int i = 1; i < INTERVALS-1; ++i) {
    iBase_EntityHandle e1, e2, a1, a2;
    e1 = FACES[0][0][i];
    e2 = FACES[3][0][i];
    if (e1 > e2) std::swap(e1,e2);
    
    CHECK_EQUAL( 2, off[i+1] - off[i] );
    a1 = adj[off[i]  ];
    a2 = adj[off[i]+1];
    if (a1 > a2) std::swap(a1,a2);
    
    CHECK_EQUAL( e1, a1 );
    CHECK_EQUAL( e2, a2 );
  }
  
  free(adj);
  free(off);
}
示例#8
0
void test_getEntArrAdj_conn()
{
  iMesh_Instance mesh = create_mesh();
  int err;
  
    // test hex vertices
  for (int i = 0; i < INTERVALS; ++i) {
    for (int j = 0; j < INTERVALS; ++j) {
      iBase_EntityHandle adj[8*INTERVALS];
      int off[INTERVALS+1];
      int adj_alloc = sizeof(adj)/sizeof(adj[0]);
      int off_alloc = sizeof(off)/sizeof(off[0]);
      int adj_size = -1, off_size = -1;
      iBase_EntityHandle* adj_ptr = adj;
      int* off_ptr = off;
      iMesh_getEntArrAdj( mesh, HEXES[i][j], INTERVALS, iBase_VERTEX,
                          &adj_ptr, &adj_alloc, &adj_size, 
                          &off_ptr, &off_alloc, &off_size,
                          &err );
      CHECK_EQUAL( &adj[0], adj_ptr );
      CHECK_EQUAL( &off[0], off_ptr );
      CHECK_EQUAL( iBase_SUCCESS, err );
      CHECK_EQUAL( 8*INTERVALS, adj_size );
      CHECK_EQUAL( 8*INTERVALS, adj_alloc );
      CHECK_EQUAL( INTERVALS+1, off_size );
      CHECK_EQUAL( INTERVALS+1, off_alloc );
      for (int k = 0; k < INTERVALS; ++k) {
        CHECK_EQUAL( 8*k, off[k] );
        iBase_EntityHandle conn[8];
        HEX_VERTS( i, j, k, conn );
        CHECK_ARRAYS_EQUAL( conn, 8, adj + off[k], off[k+1]-off[k] );
      }
    }
  }
  
    // test quad vertices for one side of mesh
  const int f = 0;
  for (int i = 0; i < INTERVALS; ++i) {
    iBase_EntityHandle adj[4*INTERVALS];
    int off[INTERVALS+1];
    int adj_alloc = sizeof(adj)/sizeof(adj[0]);
    int off_alloc = sizeof(off)/sizeof(off[0]);
    int adj_size = -1, off_size = -1;
      iBase_EntityHandle* adj_ptr = adj;
      int* off_ptr = off;
    iMesh_getEntArrAdj( mesh, FACES[f][i], INTERVALS, iBase_VERTEX,
                        &adj_ptr, &adj_alloc, &adj_size, 
                        &off_ptr, &off_alloc, &off_size,
                        &err );
    CHECK_EQUAL( &adj[0], adj_ptr );
    CHECK_EQUAL( &off[0], off_ptr );
    CHECK_EQUAL( iBase_SUCCESS, err );
    CHECK_EQUAL( 4*INTERVALS, adj_size );
    CHECK_EQUAL( 4*INTERVALS, adj_alloc );
    CHECK_EQUAL( INTERVALS+1, off_size );
    CHECK_EQUAL( INTERVALS+1, off_alloc );
    for (int k = 0; k < INTERVALS; ++k) {
      CHECK_EQUAL( 4*k, off[k] );
      iBase_EntityHandle conn[4];
      QUAD_VERTS( f, i, k, conn );
      CHECK_ARRAYS_EQUAL( conn, 4, adj + off[k], off[k+1]-off[k] );
    }
  }
}