home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir03 / f016080.re_ / f016080.re
Text File  |  1996-04-02  |  7KB  |  229 lines

  1. /*----------------------------------------------------------------------+
  2. |                                    |
  3. |  Copyright (1985-95) Bentley Systems, Inc., All rights reserved.         |
  4. |                                    |
  5. |  "MicroStation" is a registered trademark and "MDL" and "MicroCSL"    |
  6. |  are trademarks of Bentley Systems, Inc.                    |
  7. |                                    |
  8. |  Limited permission is hereby granted to reproduce and modify this    |
  9. |  copyrighted material provided that the resulting code is used only     |
  10. |  in conjunction with Bentley Systems products under the terms of the    |
  11. |  license agreement provided therein, and that this notice is retained    |
  12. |  in its entirety in any such reproduction or modification.        |
  13. |                                    |
  14. +----------------------------------------------------------------------*/
  15. /*----------------------------------------------------------------------+
  16. |                                    |
  17. |   $Logfile:   J:/mdl/examples/meshsurf/meshsurf.mcv  $
  18. |   $Workfile:   meshsurf.mc  $
  19. |   $Revision:   1.3  $
  20. |       $Date:   26 Jul 1995 07:55:52  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   Include Files                               |
  26. |                                    |
  27. +----------------------------------------------------------------------*/
  28. #include    <mdl.h>
  29. #include    <mdlbspln.h>
  30. #include    <mselems.h>
  31. #include    <rscdefs.h>
  32.  
  33. #include    "msurfcmd.h"
  34.  
  35. #include    <msparse.fdf>
  36. #include    <msoutput.fdf>
  37. #include    <msstate.fdf>
  38. #include    <mslocate.fdf>
  39. #include    <mselemen.fdf>
  40. #include    <mswindow.fdf>
  41. #include    <msrsrc.fdf>
  42. #include    <mselmdsc.fdf>
  43. #include    <msbsplin.fdf>
  44. #include    <msview.fdf>
  45.  
  46. /*----------------------------------------------------------------------+
  47. |                                    |
  48. |   Private Global variables                        |
  49. |                                    |
  50. +----------------------------------------------------------------------*/
  51. /*----------------------------------------------------------------------+
  52. |                                    |
  53. |   Local function declarations                     |
  54. |                                    |
  55. +----------------------------------------------------------------------*/
  56.  
  57. /*ff Major Public Code Section */
  58. /*----------------------------------------------------------------------+
  59. |                                    |
  60. |   Major Public Code Section                        |
  61. |                                    |
  62. +----------------------------------------------------------------------*/
  63.  
  64. /*----------------------------------------------------------------------+
  65. |                                    |
  66. | name        meshSurface_meshFunction                |
  67. |                                    |
  68. | author    BSI                    12/92        |
  69. |                                    |
  70. +----------------------------------------------------------------------*/
  71. Private int meshSurface_meshFunction
  72. (
  73. Dpoint3d    *pointP,
  74. Dpoint3d    *normalP,
  75. Dpoint2d    *paramP,
  76. int        nColumns,
  77. int        nRows,
  78. void        *userDataP
  79. )    
  80.     {
  81.     int        iRow, iColumn;
  82.     Dpoint3d    shapePoints[5];
  83.     MSElement    element;
  84.     
  85.     for (iRow=0; iRow<nRows-1; iRow++)
  86.     for (iColumn=0; iColumn<nColumns-1; iColumn++)
  87.         {
  88.         shapePoints[0] = shapePoints[4] = pointP[iRow * nColumns + iColumn];
  89.         shapePoints[1] = pointP[iRow * nColumns + iColumn + 1];
  90.         shapePoints[2] = pointP[(iRow+1) * nColumns + iColumn +  1];
  91.         shapePoints[3] = pointP[(iRow+1) * nColumns + iColumn];
  92.         
  93.         mdlShape_create (&element, NULL, shapePoints, 5, -1);
  94.         mdlElement_add (&element);
  95.         mdlElement_display (&element, NORMALDRAW);
  96.         }
  97.  
  98.     return SUCCESS;
  99.     }
  100.  
  101. /*----------------------------------------------------------------------+
  102. |                                    |
  103. | name        meshSurface_triangleFunction                |
  104. |                                    |
  105. | author    BSI                    12/92        |
  106. |                                    |
  107. +----------------------------------------------------------------------*/
  108. Private int meshSurface_triangleFunction
  109. (
  110. Dpoint3d    *pointP,
  111. Dpoint3d    *normalP,
  112. Dpoint2d    *paramP,
  113. int        nPoints,
  114. void        *userDataP
  115. )    
  116.    {
  117.     int        i;
  118.     Dpoint3d    shapePoints[4];
  119.     MSElement    element;
  120.     
  121.     for (i=2; i<nPoints; i++)
  122.     {
  123.     shapePoints[0] = shapePoints[3] = pointP[i-2];
  124.     shapePoints[1] = pointP[i-1];
  125.     shapePoints[2] = pointP[i];
  126.     
  127.     mdlShape_create (&element, NULL, shapePoints, 4, -1);
  128.     mdlElement_add (&element);
  129.     mdlElement_display (&element, NORMALDRAW);
  130.     }
  131.     return SUCCESS;
  132.     }
  133.     
  134. /*----------------------------------------------------------------------+
  135. |                                    |
  136. | name        meshSurface_accept                    |
  137. |                                    |
  138. | author    BSI                    6/90        |
  139. |                                    |
  140. +----------------------------------------------------------------------*/
  141. Private void meshSurface_accept
  142. (
  143. Dpoint3d    *pointP,
  144. int        view
  145. )                    
  146.     {
  147.     int            currFile;
  148.     double        viewScale, uorTolerance;
  149.     Dpoint3d        delta;
  150.     MSWindow        *windowP;
  151.     Rectangle        contentRect;
  152.     ULong        filePos;
  153.     MSElementDescr    *edP;
  154.     MSBsplineSurface    surface;
  155.     
  156.     /* Set the tolerance to be the size of 5 pixels on the screen */
  157.     windowP = mdlWindow_viewWindowGet (view);
  158.     mdlWindow_contentRectGetGlobal (&contentRect, windowP);
  159.     mdlView_getParameters (NULL, NULL, &delta, NULL, NULL, view);
  160.     
  161.     /* Scale from pixels to uors */
  162.     viewScale = delta.x / (double) (contentRect.corner.x - contentRect.origin.x);
  163.     uorTolerance = 5.0 * viewScale;
  164.  
  165.     
  166.     filePos = mdlElement_getFilePos (FILEPOS_CURRENT, &currFile);
  167.     if (mdlElmdscr_read (&edP, filePos, currFile, FALSE, NULL))
  168.     {
  169.     if (! mdlBspline_convertToSurface (&surface, edP))
  170.         {
  171.         mdlBspline_meshSurface (meshSurface_meshFunction,
  172.                     meshSurface_triangleFunction,
  173.                     uorTolerance, STROKETOL_ChoordHeight,
  174.                     NULL, NULL, 0.0, NULL, &surface, FALSE, FALSE, NULL);
  175.         mdlBspline_freeSurface (&surface);
  176.         }
  177.     mdlElmdscr_freeAll (&edP);
  178.     }
  179.  
  180.  
  181.     mdlState_restartCurrentCommand();
  182.     }
  183.  
  184. /*----------------------------------------------------------------------+
  185. |                                    |
  186. | name        meshSurface                        |
  187. |                                    |
  188. | author    BSI                     11/90        |
  189. |                                    |
  190. +----------------------------------------------------------------------*/
  191. Public void    meshSurface
  192. (
  193. void
  194. )    
  195. cmdNumber   CMD_MESH_SURFACE
  196.     {
  197.     /* tell MicroStation we want to start a "modification" command */
  198.     mdlLocate_allowLocked ();
  199.     mdlState_startModifyCommand (meshSurface, meshSurface_accept, NULL,
  200.                  NULL, NULL, 1, 0, TRUE, FALSE);
  201.  
  202.     /* set the internal locate pointers to start at beginning of file */
  203.     mdlLocate_init ();
  204.     }
  205.  
  206. /*----------------------------------------------------------------------+
  207. |                                    |
  208. | name        main                            |
  209. |                                    |
  210. | author    BSI                    6/90        |
  211. |                                    |
  212. +----------------------------------------------------------------------*/
  213. Public int main 
  214. (
  215. void
  216. )
  217.     {
  218.     RscFileHandle   rfHandle;
  219.  
  220.     /* Open our file for access to command table */
  221.     mdlResource_openFile (&rfHandle, NULL, FALSE);
  222.     
  223.     /* Load the command table */
  224.     if (mdlParse_loadCommandTable (NULL) == NULL)
  225.     mdlOutput_error ("Unable to load command table.");
  226.  
  227.     return  SUCCESS;
  228.     }
  229.