vlookup.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef VLOOKUP_H
  2. #define VLOOKUP_H
  3. /*----------------------------------------------------------------------
  4. Copyright (c) 2004 Open Dynamics Framework Group
  5. www.physicstools.org
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification, are permitted provided
  8. that the following conditions are met:
  9. Redistributions of source code must retain the above copyright notice, this list of conditions
  10. and the following disclaimer.
  11. Redistributions in binary form must reproduce the above copyright notice,
  12. this list of conditions and the following disclaimer in the documentation
  13. and/or other materials provided with the distribution.
  14. Neither the name of the Open Dynamics Framework Group nor the names of its contributors may
  15. be used to endorse or promote products derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  17. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. -----------------------------------------------------------------------*/
  24. // http://codesuppository.blogspot.com
  25. //
  26. // mailto: [email protected]
  27. //
  28. // http://www.amillionpixels.us
  29. //
  30. // CodeSnippet provided by John W. Ratcliff
  31. // on March 23, 2006.
  32. //
  33. // mailto: [email protected]
  34. //
  35. // Personal website: http://jratcliffscarab.blogspot.com
  36. // Coding Website: http://codesuppository.blogspot.com
  37. // FundRaising Blog: http://amillionpixels.blogspot.com
  38. // Fundraising site: http://www.amillionpixels.us
  39. // New Temple Site: http://newtemple.blogspot.com
  40. //
  41. // This snippet shows how to 'hide' the complexity of
  42. // the STL by wrapping some useful piece of functionality
  43. // around a handful of discrete API calls.
  44. //
  45. // This API allows you to create an indexed triangle list
  46. // from a collection of raw input triangles. Internally
  47. // it uses an STL set to build the lookup table very rapidly.
  48. //
  49. // Here is how you would use it to build an indexed triangle
  50. // list from a raw list of triangles.
  51. //
  52. // (1) create a 'VertexLookup' interface by calling
  53. //
  54. // VertexLook vl = Vl_createVertexLookup();
  55. //
  56. // (2) For each vertice in each triangle call:
  57. //
  58. // unsigned int i1 = Vl_getIndex(vl,p1);
  59. // unsigned int i2 = Vl_getIndex(vl,p2);
  60. // unsigned int i3 = Vl_getIndex(vl,p3);
  61. //
  62. // save the 3 indices into your triangle list array.
  63. //
  64. // (3) Get the vertex array by calling:
  65. //
  66. // const float *vertices = Vl_getVertices(vl);
  67. //
  68. // (4) Get the number of vertices so you can copy them into
  69. // your own buffer.
  70. // unsigned int vcount = Vl_getVcount(vl);
  71. //
  72. // (5) Release the VertexLookup interface when you are done with it.
  73. // Vl_releaseVertexLookup(vl);
  74. //
  75. // Teaches the following lessons:
  76. //
  77. // How to wrap the complexity of STL and C++ classes around a
  78. // simple API interface.
  79. //
  80. // How to use an STL set and custom comparator operator for
  81. // a complex data type.
  82. //
  83. // How to create a template class.
  84. //
  85. // How to achieve significant performance improvements by
  86. // taking advantage of built in STL containers in just
  87. // a few lines of code.
  88. //
  89. // You could easily modify this code to support other vertex
  90. // formats with any number of interpolants.
  91. //
  92. // Hide C++ classes from the rest of your application by
  93. // keeping them in the CPP and wrapping them in a namespace
  94. // Uses an STL set to create an index table for a bunch of vertex positions
  95. // used typically to re-index a collection of raw triangle data.
  96. typedef void * VertexLookup;
  97. VertexLookup Vl_createVertexLookup(void);
  98. void Vl_releaseVertexLookup(VertexLookup vlook);
  99. unsigned int Vl_getIndex(VertexLookup vlook,const float *pos); // get index.
  100. const float * Vl_getVertices(VertexLookup vlook);
  101. unsigned int Vl_getVcount(VertexLookup vlook);
  102. #endif