position.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*!
  2. \file lib/nviz/position.c
  3. \brief Nviz library -- Position, focus settings
  4. Based on visualization/nviz/src/position.c
  5. (C) 2008, 2010 by the GRASS Development Team
  6. This program is free software under the GNU General Public License
  7. (>=v2). Read the file COPYING that comes with GRASS for details.
  8. \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  9. */
  10. #include <grass/glocale.h>
  11. #include <grass/nviz.h>
  12. /*!
  13. Initialize view, position, lighting settings (focus)
  14. Set position to center of view
  15. */
  16. void Nviz_init_view(nv_data * data)
  17. {
  18. GS_init_view();
  19. Nviz_set_focus_state(1); /* center of view */
  20. /* set default lights (1 & 2) */
  21. Nviz_set_light_position(data, 1, 0.68, -0.68, 0.80, 0.0);
  22. Nviz_set_light_bright(data, 1, 0.8);
  23. Nviz_set_light_color(data, 1, 255, 255, 255);
  24. Nviz_set_light_ambient(data, 1, 0.2);
  25. Nviz_set_light_position(data, 2, 0.0, 0.0, 1.0, 0.0);
  26. Nviz_set_light_bright(data, 2, 0.5);
  27. Nviz_set_light_color(data, 2, 255, 255, 255);
  28. Nviz_set_light_ambient(data, 2, 0.3);
  29. return;
  30. }
  31. /*!
  32. \brief Set focus state
  33. \param state_flag 1 for center view, 0 use viewdir
  34. \return 1 on success
  35. \return 0 on failure
  36. */
  37. int Nviz_set_focus_state(int state_flag)
  38. {
  39. if (state_flag == 1)
  40. GS_set_infocus(); /* return center of view */
  41. else if (state_flag == 0)
  42. GS_set_nofocus(); /* no center of view -- use viewdir */
  43. else {
  44. G_warning(_("Unable to set focus"));
  45. return 0;
  46. }
  47. return 1;
  48. }
  49. /*!
  50. \brief Set focus based on loaded map
  51. If <i>map</i> is MAP_OBJ_UNDEFINED, set focus from first
  52. surface/volume in the list.
  53. \param type map object type
  54. \param id map object id
  55. \return 0 on no focus
  56. \return id id of map object used for setting focus
  57. */
  58. int Nviz_set_focus_map(int type, int id)
  59. {
  60. if (GS_num_surfs() < 0 && GVL_num_vols() < 0) {
  61. GS_set_nofocus();
  62. return 0;
  63. }
  64. if (type == MAP_OBJ_UNDEFINED) {
  65. int *surf_list, num_surfs, *vol_list;
  66. if (GS_num_surfs() > 0) {
  67. surf_list = GS_get_surf_list(&num_surfs);
  68. id = surf_list[0];
  69. G_free(surf_list);
  70. GS_set_focus_center_map(id);
  71. }
  72. if (GVL_num_vols() > 0) {
  73. vol_list = GVL_get_vol_list(&num_surfs);
  74. id = vol_list[0];
  75. G_free(vol_list);
  76. GVL_set_focus_center_map(id);
  77. }
  78. return id;
  79. }
  80. if (type == MAP_OBJ_SURF) {
  81. GS_set_focus_center_map(id);
  82. }
  83. else if (type == MAP_OBJ_VOL) {
  84. GVL_set_focus_center_map(id);
  85. }
  86. return id;
  87. }
  88. /*!
  89. \brief Get focus
  90. \param data nviz data
  91. \param x,y,z focus coordinates
  92. */
  93. int Nviz_get_focus(nv_data * data, float *x, float *y, float *z)
  94. {
  95. float realto[3];
  96. /* Get current center */
  97. GS_get_focus(realto);
  98. *x = realto[0];
  99. *y = realto[1];
  100. *z = realto[2];
  101. /* old nviz code is more complicated and it doesn't work properly, */
  102. /* no idea why */
  103. return 1;
  104. }
  105. /*!
  106. \brief Set focus
  107. \param data nviz data
  108. \param x, y, z focus coordinates
  109. */
  110. int Nviz_set_focus(nv_data * data, float x, float y, float z)
  111. {
  112. float realto[3];
  113. realto[0] = x;
  114. realto[1] = y;
  115. realto[2] = z;
  116. GS_set_focus(realto);
  117. /* old nviz code is more complicated and it doesn't work properly, */
  118. /* no idea why */
  119. return 1;
  120. }
  121. /*!
  122. \brief Test focus
  123. \param data nviz data
  124. */
  125. int Nviz_has_focus(nv_data * data)
  126. {
  127. float realto[3];
  128. if (GS_get_focus(realto))
  129. return 1;
  130. else
  131. return 0;
  132. }
  133. /*!
  134. \brief Get xy range
  135. \param data nviz data
  136. */
  137. float Nviz_get_xyrange(nv_data * data)
  138. {
  139. return data->xyrange;
  140. }
  141. /*!
  142. \brief Get z range
  143. \param data nviz data
  144. \param min,max z range
  145. */
  146. int Nviz_get_zrange(nv_data * data, float *min, float *max)
  147. {
  148. GS_get_zrange_nz(min, max);
  149. return 1;
  150. }
  151. /*!
  152. \brief Get largest dimension
  153. \param data nviz data
  154. */
  155. float Nviz_get_longdim(nv_data * data)
  156. {
  157. float dim;
  158. GS_get_longdim(&dim);
  159. return dim;
  160. }