doc-geo.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. devil1geo.h / devil1geo.c
  2. Handles files containing geometry.
  3. Functions
  4. All functions are static but exposed by a function pointer in a constant
  5. struct called DEVIL1GEO. For example, clients call functions using
  6. DEVIL1GEO.printheader(...);
  7. void printheader(struct Header*);
  8. Show attributes and values of a Header for the package.
  9. input: pointer to Header, pass by reference of a struct.
  10. Can not be NULL.
  11. void printmeshheader(struct MeshHeader*);
  12. Show attributes and values of a MeshHeader.
  13. input: pointer to MeshHeader, pass by reference of a struct.
  14. Can not be NULL.
  15. void printbatch(struct Batch*);
  16. Show attribute and values of a Batch and three sample position
  17. coordinates.
  18. input: pointer to Batch, pass by reference of a struct.
  19. Can not be NULL.
  20. void printcoordinate(struct Coordinate*, unsigned int);
  21. Show a specified quantity of Coordinates.
  22. input:
  23. pointer to array of Coordinates.
  24. Can not be NULL.
  25. unsigned int, for quantity of coordinates to be printed.
  26. bool getheader(struct Header**, const char*);
  27. Retrieves the header for a geometry package.
  28. input:
  29. Pointer of a pointer to struct Header.
  30. Pass by reference of a pointer to the function.
  31. The pointer of Header can be NULL and will be set to point to
  32. a region in the buffer.
  33. const char*, the buffer containing the whole geometry package.
  34. Can not be NULL.
  35. bool getmeshheader(struct MeshHeader**,
  36. unsigned int,
  37. const char * const);
  38. Retrieves the i-th MeshHeader in a buffer.
  39. input:
  40. Pointer of a pointer to MeshHeader.
  41. Pass by reference of a pointer to the function.
  42. The pointer of MeshHeader can be NULL and will be set to point to
  43. a region in the buffer.
  44. unsigned int, the i-th instance of MeshHeader in the buffer.
  45. const char*, the buffer containing the whole mesh package.
  46. output:
  47. true on success.
  48. false when failing checks against segmentation faults.
  49. If parameter 'struct MeshHeader**' is NULL.
  50. If parameter 'const char*' is NULL.
  51. bool getbatch(struct Batch*,
  52. unsigned int offset,
  53. const char * const);
  54. Retrieves the i-th Batch in a buffer.
  55. input:
  56. Pointer to a Batch.
  57. Pass by reference of a struct to the function.
  58. Can not be NULL.
  59. unsigned int, the i-th instance of Batch in the buffer.
  60. const char*, the buffer containing the whole mesh package.
  61. output:
  62. true on success.
  63. false when failing checks against segmentation faults.
  64. If parameter 'struct Batch*' is NULL.
  65. If parameter 'const char*' is NULL.
  66. bool getmesh(struct Mesh*,
  67. unsigned int,
  68. const char*,
  69. unsigned int);
  70. Retrieves the i-th Mesh in a buffer.
  71. input:
  72. Pointer to mesh.
  73. Pass by reference of a struct to the function.
  74. unsigned int, the i-th instance of Mesh in the buffer.
  75. const char*, the buffer containing the whole mesh package.
  76. output:
  77. true on success.
  78. false when failing checks against segmentation faults.
  79. If parameter 'struct Mesh*' is NULL.
  80. If attribute 'b' of parameter 'struct Mesh' is NULL.
  81. if parameter 'const char*' is NULL.
  82. When file size is detected to be too small for a given i-th
  83. Mesh.
  84. Example logic to interact with all meshes:
  85. {
  86. // After the file has been read in.
  87. // Need to know how many meshes are in the file.
  88. struct Header *h = (struct Header*)filedata;
  89. // Need to know about a specific mesh (how many batches).
  90. struct MeshHeader *mh = NULL;
  91. // Need to hold information about mesh.
  92. struct Mesh m;
  93. // As a precaution - empty for now.
  94. m.b = NULL;
  95. unsigned int i;
  96. for (i = 0; i < h -> numMesh; i++) {
  97. DEVIL1GEO.getmeshheader(&mh, i, filedata);
  98. // Allocate space to hold batch data.
  99. m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
  100. if (m.b != NULL) {
  101. DEVIL1GEO.getmesh(&m, i, filedata, filesize);
  102. // Do whatever you want with the mesh.
  103. free(m.b);
  104. }
  105. }