Beispiel #1
0
bool
mesh_set_aabb(const Mesh_data *data, const uint32_t key, const math::aabb *set_value)
{
  assert(data);
  assert(key != 0);
  assert(data->field_aabb);
  assert(set_value);

  // Search for its index.
  // If we find it we can set the value.

  size_t index = 0;

  if(mesh_exists(data, key, &index))
  {
    assert(index < data->size);
    if(index < data->size)
    {
      data->field_aabb[index] = *set_value;

      return true;
    }
  }

  return false;
}
Beispiel #2
0
bool
mesh_get_mesh(const Mesh_data *data, const uint32_t key, Graphics_api::Mesh *return_value)
{
  assert(data);
  assert(key != 0);
  assert(data->field_mesh);
  assert(return_value);

  // Search for its index.
  // If we find it we can return the value.

  size_t index = 0;

  if(mesh_exists(data, key, &index))
  {
    assert(index < data->size);

    if(index < data->size)
    {
      *return_value = data->field_mesh[index];

      return true;
    }
  }

  return false;
}
Beispiel #3
0
bool
mesh_set_name(const Mesh_data *data, const uint32_t key, const char *set_value, const size_t size)
{
  assert(data);
  assert(key != 0);
  assert(data->field_name);
  assert(set_value);

  // Search for its index.
  // If we find it we can set the value.

  size_t index = 0;

  if(mesh_exists(data, key, &index))
  {
    assert(index < data->size);
    if(index < data->size)
    {
      memcpy(&data->field_name[index * 32], set_value, sizeof(char) * size);

      return true;
    }
  }

  return false;
}
Beispiel #4
0
bool
mesh_get_name(const Mesh_data *data, const uint32_t key, const char **return_value)
{
  assert(data);
  assert(key != 0);
  assert(data->field_name);
  assert(return_value);

  // Search for its index.
  // If we find it we can return the value.

  size_t index = 0;

  if(mesh_exists(data, key, &index))
  {
    assert(index < data->size);

    if(index < data->size)
    {
      *return_value = &data->field_name[index * 32];

      return true;
    }
  }

  return false;
}
Beispiel #5
0
bool
mesh_remove(Mesh_data *data, const uint32_t key)
{
  size_t index_to_erase = 0;

  if(mesh_exists(data, key, &index_to_erase))
  {
    assert(index_to_erase < data->size);

    const size_t start_index = index_to_erase + 1;
    const size_t size_to_end = data->size - index_to_erase - 1;

    --(data->size);

    // Shuffle the data down
    memmove(&data->keys[index_to_erase], &data->keys[start_index], size_to_end * sizeof(*data->keys));
    memmove(&data->field_name[index_to_erase * 32], &data->field_name[start_index * 32], size_to_end * sizeof(*data->field_name) * 32);
    memmove(&data->field_mesh[index_to_erase * 1], &data->field_mesh[start_index * 1], size_to_end * sizeof(*data->field_mesh) * 1);
    memmove(&data->field_aabb[index_to_erase * 1], &data->field_aabb[start_index * 1], size_to_end * sizeof(*data->field_aabb) * 1);

    return true;
  }

  return false;
}
int main(int argc, char ** argv)
{
    int num_errs = 0;

    hid_t fid, mid;

    char root_file[] = FILE;
    char meshname[] = MESH_NAME1;
    tmesh_t mesh_type = UNSTRUCTURED_MESH;
    telem_t elem_type = HEX_ELEM;
    int elem_order    = HEX_ELEM_ORDER;

    double *coordinates[DIM];

    int exists;
    int nmesh;
    char **meshnames;
    int i,*size;



    if ( DANU_RETURN_FAIL(output_file_create(root_file,&fid)) ) {
        DANU_ERROR_MESS("Failed to create the output file");
        num_errs++;
        goto EXIT_NOW;
    }


    /* Create a mesh */
    if ( DANU_RETURN_FAIL(mesh_create(fid,meshname,DIM,mesh_type,elem_type)) ) {
        DANU_ERROR_MESS("Failed to create the mesh group");
        num_errs++;
        goto EXIT_NOW;
    }

    /* Query the existence of the mesh */
    if ( DANU_RETURN_FAIL(mesh_exists(fid,meshname,&exists) ) ) {
        DANU_ERROR_MESS("Failed to query mesh");
        num_errs++;
        goto EXIT_NOW;
    }

    if ( exists ) {
        printf("Mesh existence query successful\n");
    }

    /* Query a mesh that does not exist */
    if ( DANU_RETURN_FAIL(mesh_exists(fid,"DUHMesh",&exists) ) ) {
        DANU_ERROR_MESS("Failed to query fake mesh");
        num_errs++;
        goto EXIT_NOW;
    }

    if ( ! exists ) {
        printf("Query of fake mesh passed\n");
    }

    /* Create another mesh */
    sprintf(meshname,MESH_NAME2);
    mesh_type = STRUCTURED_MESH;
    elem_type = HEX_ELEM;
    if ( DANU_RETURN_FAIL(mesh_create(fid,meshname,DIM,mesh_type,elem_type)) ) {
        DANU_ERROR_MESS("Failed to create the second mesh group");
        num_errs++;
        goto EXIT_NOW;
    }

    /* Count the number of meshes */
    if ( DANU_RETURN_FAIL(mesh_count(fid,&nmesh) ) ) {
        DANU_ERROR_MESS("Failed to count meshes");
        num_errs++;
        goto EXIT_NOW;
    }


    printf("Found %d meshes in %s\n", nmesh, root_file);

    /* Now get the names */
    meshnames = DANU_MALLOC(char *, nmesh);
    size      = DANU_MALLOC(int,nmesh);
    for(i=0;i<nmesh;i++) {
        size[i] = 64;
        meshnames[i] = DANU_MALLOC(char, size[i]);
    }

    if ( DANU_RETURN_FAIL(mesh_list(fid,nmesh,size,meshnames) ) ) {
        DANU_ERROR_MESS("Failed to get mesh list");
        num_errs++;
        goto EXIT_NOW;
    }

    DANU_FREE(size);
    for(i=0;i<nmesh;i++) {
        printf("\t-->%s\n",meshnames[i]);
        DANU_FREE(meshnames[i]);
    }
    DANU_FREE(meshnames);
       

    danu_file_close(fid);

    goto EXIT_NOW;


EXIT_NOW:
    printf("Found %d errors\n",num_errs);
    return num_errs;

}