Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3. #include <math.h>
  4. #include <conio.h>
  5. #include <vtkAutoInit.h>
  6. VTK_MODULE_INIT(vtkRenderingOpenGL2);
  7. VTK_MODULE_INIT(vtkInteractionStyle);
  8. VTK_MODULE_INIT(vtkRenderingFreeType);
  9. #include "RVLVTK.h"
  10. #include "opencv2\opencv.hpp"
  11. #include "RVLCore2.h"
  12. #include "Display.h"
  13. #include "Graph.h"
  14. #include "NormalEst.h"
  15. using namespace std;
  16. using namespace cv;
  17.  
  18.  
  19.  
  20. NormalEst::NormalEst()
  21. {
  22. poljeNormala = NULL;
  23. poljeP0 = NULL;
  24. poljeZaFilter = NULL;
  25. }
  26.  
  27.  
  28. NormalEst::~NormalEst()
  29. {
  30. if(poljeNormala)
  31. delete[] poljeNormala;
  32. if (poljeP0)
  33. delete[] poljeP0;
  34. if (poljeZaFilter)
  35. delete[] poljeZaFilter;
  36. if (poljeOptimiziranihNormala)
  37. delete[] poljeZaFilter;
  38. }
  39.  
  40.  
  41. void NormalEst::Apply(Graph &G)
  42. {
  43. ::Node *pNode;
  44. ::Node *pNodeHelp;
  45. int NumOfNodes = G.NoOfNodes();
  46. numNodes = NumOfNodes;
  47. Vec3f P0, P1, P2, Vector1, Vector2, Suma;
  48. float LenghtOfVector;
  49. if (poljeNormala)
  50. delete[] poljeNormala;
  51. if (poljeP0)
  52. delete[] poljeP0;
  53. if (poljeZaFilter)
  54. delete[] poljeZaFilter;
  55. poljeNormala = new Vec3f[NumOfNodes];
  56. poljeP0 = new Vec3f[NumOfNodes];
  57. poljeZaFilter = new Vec3f[NumOfNodes];
  58. int k = 0;
  59.  
  60. for (int i = 0; i < NumOfNodes; i++) {
  61. pNode = G.GetNode(i);
  62. // Vec3f a = *(poljeZaFilter + i);
  63.  
  64.  
  65. P0 = Vec3f(pNode->P);
  66. *(poljeP0 + i) = P0;
  67. Suma = 0;
  68. for (int j = 0; j < 4; j++) {
  69. k++;
  70. if (j == 3)
  71. k = 0;
  72. if (pNode->neighbor[j] > 0 && pNode->neighbor[k] > 0) {
  73. pNodeHelp = G.GetNode(pNode->neighbor[j]);
  74. P1 = Vec3f(pNodeHelp->P);
  75. Vector1 = P1 - P0;
  76. pNodeHelp = G.GetNode(pNode->neighbor[k]);
  77. P2 = Vec3f(pNodeHelp->P);
  78. Vector2 = P2 - P0;
  79. Suma = Suma + Vector1.cross(Vector2);
  80. }
  81. }
  82.  
  83. LenghtOfVector = norm(Suma, NORM_L2);
  84. if (LenghtOfVector != 0) {
  85. *(poljeZaFilter + i) = Suma;
  86. Suma = Suma / LenghtOfVector;
  87. *(poljeNormala + i) = Suma;
  88. }
  89. else {
  90. *(poljeNormala + i) = Vec3f(0, 0, 0);
  91. *(poljeZaFilter + i) = Vec3f(0, 0, 0);
  92. }
  93. }
  94.  
  95. }
  96.  
  97.  
  98. void NormalEst::CreateLinesFromNormals(std::vector<Line> &lines)
  99. {
  100. Line line;
  101. float scale = 0.1;
  102.  
  103. for(int i = 0; i < numNodes; i++)
  104. {
  105. line.P1 = *(poljeP0+i);
  106. line.P2 = *(poljeNormala+i)*scale + *(poljeP0+i);
  107. lines.push_back(line);
  108. }
  109.  
  110.  
  111.  
  112. }
  113.  
  114.  
  115. void NormalEst::MjerniSumNormale(Graph &G)
  116. {
  117. ::Node *pNode;
  118. float LenghtOfVector, gamma = 0.5;
  119. Vec3f Suma;
  120. int k;
  121.  
  122. poljeOptimiziranihNormala = new Vec3f[numNodes];
  123.  
  124. for (int i = 0; i < numNodes; i++)
  125. {
  126. Suma = 0;
  127. pNode = G.GetNode(i);
  128. Vec3f a = *(poljeZaFilter+i);
  129. for (int j = 0; j < 4; j++) {
  130. if (pNode->neighbor[j] > 0) {
  131. Suma = Suma + *(poljeZaFilter + pNode->neighbor[j]);
  132. }
  133. }
  134. Suma = Suma * gamma;
  135. Suma = Suma + a;
  136. LenghtOfVector = norm(Suma, NORM_L2);
  137. *(poljeOptimiziranihNormala + i) = Suma / LenghtOfVector;
  138.  
  139.  
  140. }
  141.  
  142. }
  143.  
  144.  
  145.  
  146. void NormalEst::CreateLinesFromOptNormals(std::vector<Line> &lines)
  147. {
  148. Line line;
  149. float scale = 0.1;
  150.  
  151. for (int i = 0; i < numNodes; i++)
  152. {
  153. line.P1 = *(poljeP0 + i);
  154. line.P2 = *(poljeOptimiziranihNormala + i)*scale + *(poljeP0 + i);
  155. lines.push_back(line);
  156. }
  157.  
  158.  
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement