Grid.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. // This code contains NVIDIA Confidential Information and is disclosed
  3. // under the Mutual Non-Disclosure Agreement.
  4. //
  5. // Notice
  6. // ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
  7. // NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
  8. // THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
  9. // MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  10. //
  11. // NVIDIA Corporation assumes no responsibility for the consequences of use of such
  12. // information or for any infringement of patents or other rights of third parties that may
  13. // result from its use. No license is granted by implication or otherwise under any patent
  14. // or patent rights of NVIDIA Corporation. No third party distribution is allowed unless
  15. // expressly authorized by NVIDIA. Details are subject to change without notice.
  16. // This code supersedes and replaces all information previously supplied.
  17. // NVIDIA Corporation products are not authorized for use as critical
  18. // components in life support devices or systems without express written approval of
  19. // NVIDIA Corporation.
  20. //
  21. // Copyright (c) 2015-2016 NVIDIA Corporation. All rights reserved.
  22. //
  23. // NVIDIA Corporation and its licensors retain all intellectual property and proprietary
  24. // rights in and to this software and related documentation and any modifications thereto.
  25. // Any use, reproduction, disclosure or distribution of this software and related
  26. // documentation without an express license agreement from NVIDIA Corporation is
  27. // strictly prohibited.
  28. //
  29. /////////////////////////////////////////////////////////////////////////////////////////
  30. #include "Grid.hpp"
  31. //------------------------------------------------------------------------------
  32. void configureGrid(GridData_t *grid,
  33. uint32_t windowWidth,
  34. uint32_t windowHeight,
  35. uint32_t imageWidth,
  36. uint32_t imageHeight,
  37. uint32_t cellCount)
  38. {
  39. uint32_t rows = 1;
  40. uint32_t cols = 1;
  41. bool increaseRows = false;
  42. while( rows * cols < cellCount ) {
  43. if(increaseRows)
  44. rows++;
  45. else
  46. cols++;
  47. increaseRows = !increaseRows;
  48. }
  49. float camera_aspect_ratio = static_cast<float>(imageWidth) /
  50. static_cast<float>(imageHeight);
  51. uint32_t render_width = windowWidth / cols;
  52. uint32_t render_height = static_cast<uint32_t>(render_width / camera_aspect_ratio);
  53. if( render_height * rows > windowHeight ) {
  54. render_height = windowHeight / rows;
  55. render_width = static_cast<uint32_t>(render_height * camera_aspect_ratio);
  56. }
  57. grid->rows = rows;
  58. grid->cols = cols;
  59. grid->offsetX = 0;
  60. grid->offsetY = windowHeight - render_height;
  61. grid->cellWidth = render_width;
  62. grid->cellHeight = render_height;
  63. }
  64. //------------------------------------------------------------------------------
  65. void gridCellRect(dwRect *rect,
  66. const GridData_t &grid,
  67. uint32_t cellIdx)
  68. {
  69. //Set area
  70. int row = cellIdx / grid.cols;
  71. int col = cellIdx % grid.cols;
  72. rect->width = grid.cellWidth;
  73. rect->height = grid.cellHeight;
  74. rect->x = grid.offsetX + grid.cellWidth*col;
  75. rect->y = grid.offsetY - grid.cellHeight*row;
  76. }