Advertisement
Guest User

Untitled

a guest
May 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.47 KB | None | 0 0
  1. #include <vtkSmartPointer.h>
  2. #include <vtkHedgeHog.h>
  3. #include <vtkActor.h>
  4. #include <vtkCamera.h>
  5. #include "vtkPointSet.h"
  6. #include "vtkVolume16Reader.h"
  7. #include "vtkOutlineFilter.h"
  8. #include "vtkRenderer.h"
  9. #include "vtkPolyDataNormals.h"
  10. #include "vtkContourFilter.h"
  11. #include "vtkColorTransferFunction.h"
  12. #include "vtkPiecewiseFunction.h"
  13. #include "vtkVolumeProperty.h"
  14. #include <vtkFloatArray.h>
  15. #include <vtkMath.h>
  16. #include <vtkPointData.h>
  17. #include <vtkPoints.h>
  18. #include <vtkPolyDataMapper.h>
  19. #include <vtkProperty.h>
  20. #include <vtkRenderWindow.h>
  21. #include <vtkRenderWindowInteractor.h>
  22. #include <vtkRenderer.h>
  23. #include "vtkMarchingCubes.h"
  24. #include "vtkRecursiveDividingCubes.h"
  25. #include "vtkScalarBarWidget.h"
  26. #include "vtkScalarBarActor.h"
  27. #include "vtkPiecewiseFunction.h"
  28. #include "vtkThresholdPoints.h"
  29. #include "vtkStructuredPointsReader.h"
  30. #include "vtkMaskPoints.h"
  31. #include "vtkConeSource.h"
  32. #include "vtkVolumeRayCastCompositeFunction.h"
  33. #include "vtkVolumeRayCastMapper.h"
  34. #include "vtkVolumeRayCastMIPFunction.h"
  35. #include "vtkGlyph3D.h"
  36. #include "vtkLookupTable.h"
  37. #include "vtkCommand.h"
  38. #include <vtkStructuredGrid.h>
  39. #include <vtkStreamLine.h>
  40. #include "vtkStreamPoints.h"
  41. #include <vtkNamedColors.h>
  42. #include "vtkPointSource.h"
  43. #include "vtkPointSet.h"
  44.  
  45. int main(int argc, char **argv)
  46. {
  47.  
  48. // Create the renderer, the render window, and the interactor. The renderer
  49. // draws into the render window, the interactor enables mouse- and
  50. // keyboard-based interaction with the data within the render window.
  51. vtkRenderer *aRenderer = vtkRenderer::New();
  52. vtkRenderWindow *renWin = vtkRenderWindow::New();
  53. renWin->AddRenderer(aRenderer);
  54. vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  55. iren->SetRenderWindow(renWin);
  56.  
  57. // Read
  58. vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
  59. reader->SetFileName("../data/wind.vtk");
  60. reader->Update();
  61.  
  62. // Hedgehog setup.
  63. //vtkHedgeHog *hhog = vtkHedgeHog::New();
  64. //hhog->SetInputConnection(reader->GetOutputPort());
  65. //hhog->SetScaleFactor(1.0);
  66.  
  67. /* vtkConeSource *coneSource = vtkConeSource::New();
  68.  
  69. vtkGlyph3D *glyph = vtkGlyph3D::New();
  70. glyph->SetInputConnection(reader->GetOutputPort());
  71. glyph->SetScaleFactor(1.6);
  72. glyph->SetSourceConnection(coneSource->GetOutputPort());
  73.  
  74. coneSource->SetResolution(6);
  75. coneSource->SetHeight(1.5);
  76. coneSource->SetRadius(1.5);
  77.  
  78. glyph->SetScaleModeToScaleByVector();
  79.  
  80. //glyph.SetScaleFactor(5);
  81.  
  82. //vtkExtractGrid extg = new vtkExtractGrid();
  83. //extg.SetInput(vtkStructuredGrid.SafeDownCast(
  84. //glyph.GetOutput()));
  85. //extg.SetSampleRate(2, 2, 1);
  86.  
  87. // Lookup Table
  88. //lut.SetHueRange(0.667, 1.0);
  89. vtkLookupTable *lut = vtkLookupTable::New();
  90. lut->SetHueRange(0.667, 0.0);
  91. lut->Build();
  92.  
  93. // Poly Mapper
  94. vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
  95. mapper->SetInputConnection(glyph->GetOutputPort());
  96. mapper->SetScalarRange(0.0, 1.0);
  97. mapper->SetLookupTable(lut);*/
  98.  
  99.  
  100. /************** Streamline DATA 1 *******************************************/
  101. /*int count = 0;
  102. vtkPoints *points = vtkPoints::New(); //DIMENSIONS 36 36 1 ORIGIN 0.0 0.0 0.0
  103. for (int x = 0; x <= 36; x+=5) { // can change to += 3 5 6, 4 will error
  104. for (int y = 0; y <= 36; y++) {
  105. for (int z = 0; z <=1 ; z++) {
  106. points->InsertPoint(count, x, y, z);
  107. count++;
  108. }
  109.  
  110. }
  111. }
  112.  
  113. vtkPolyData *startPoints = vtkPolyData::New();
  114. startPoints->SetPoints(points);
  115.  
  116. //StreamLine Setup
  117. vtkStreamLine *streamLine = vtkStreamLine::New();
  118. streamLine->SetInputConnection(reader->GetOutputPort());
  119. streamLine->SetSourceData(startPoints);
  120. streamLine->SetMaximumPropagationTime(100);
  121. streamLine->SetStepLength(0.2);
  122. streamLine->SetIntegrationStepLength(0.02);
  123. streamLine->SetNumberOfThreads(2);
  124. streamLine->SetIntegrationDirectionToIntegrateBothDirections();
  125. */
  126. /***********************************************************/
  127.  
  128.  
  129.  
  130. /************** Streamline DATA 2 *******************************************/
  131. /*int count = 0;
  132. vtkPoints *points = vtkPoints::New(); //DIMENSIONS 357 357 1 ORIGIN 0.0 0.0 0.0
  133. for (int x = 0; x <= 357; x+=10) {
  134. for (int y = 0; y <= 357; y+=10) {
  135. for (int z = 0; z <= 1; z++) {
  136. points->InsertPoint(count, x, y, z);
  137. count++;
  138. }
  139. }
  140. }
  141. vtkPolyData *startPoints = vtkPolyData::New();
  142. startPoints->SetPoints(points);
  143. //StreamLine Setup
  144. vtkStreamLine *streamLine = vtkStreamLine::New();
  145. streamLine->SetInputConnection(reader->GetOutputPort());
  146. streamLine->SetSourceData(startPoints);
  147. streamLine->SetMaximumPropagationTime(100);
  148. streamLine->SetStepLength(0.2);
  149. streamLine->SetIntegrationStepLength(0.02);
  150. streamLine->SetNumberOfThreads(2);
  151. streamLine->SetIntegrationDirectionToIntegrateBothDirections();
  152. */
  153. /***********************************************************/
  154.  
  155. /************** Streamline Carotid *******************************************/
  156. /*int count = 0;
  157. vtkPoints *points = vtkPoints::New();
  158. for (int x = 100; x < 176; x+=7) { // DIMENSIONS 76 49 45 ORIGIN 100.0 80.0 1.0
  159. for (int y = 80; y < 129; y+=7) {
  160. for (int z = 1; z < 46; z+=2) {
  161.  
  162. points->InsertPoint(count, x, y, z);
  163. count++;
  164.  
  165. }
  166. }
  167. }
  168. vtkPolyData *startPoints = vtkPolyData::New();
  169. startPoints->SetPoints(points);
  170. //StreamLine Setup
  171. vtkStreamLine *streamLine = vtkStreamLine::New();
  172. streamLine->SetInputConnection(reader->GetOutputPort());
  173. streamLine->SetSourceData(startPoints);
  174. streamLine->SetMaximumPropagationTime(100);
  175. streamLine->SetStepLength(0.2);
  176. streamLine->SetIntegrationStepLength(0.02);
  177. streamLine->SetNumberOfThreads(2);
  178. streamLine->SetIntegrationDirectionToIntegrateBothDirections();
  179. */
  180. /***********************************************************/
  181.  
  182.  
  183. /************** Streamline wind *******************************************/
  184.  
  185.  
  186. int count = 0;
  187. vtkPoints *point = vtkPoints::New();
  188. for (int x = 18; x <= 53; x += 1) { // DIMENSIONS 35 41 15
  189. for (int y = 70; y <= 111; y += 1) {
  190. for (int z = 0; z <= 15; z += 5) {
  191. point->InsertPoint(count, x, y, z);
  192. count++;
  193.  
  194. }
  195. }
  196. }
  197. vtkPolyData *startPointz = vtkPolyData::New();
  198. startPointz->SetPoints(point);
  199.  
  200. //StreamLine Setup
  201. //vtkStreamLine *streamLine = vtkStreamLine::New();/////////////////////////////////////////////////
  202. //streamLine->SetInputConnection(reader->GetOutputPort());
  203. //streamLine->SetSourceData(startPoints);
  204. //streamLine->SetMaximumPropagationTime(100);
  205. //streamLine->SetStepLength(0.2);
  206. //streamLine->SetIntegrationStepLength(0.02);
  207. //streamLine->SetNumberOfThreads(2);
  208. //streamLine->SetIntegrationDirectionToIntegrateBothDirections();
  209.  
  210. //StreamPoints Setup
  211. vtkStreamPoints *streamPoints = vtkStreamPoints::New();
  212. streamPoints->SetInputConnection(reader->GetOutputPort());
  213. streamPoints->SetSourceData(startPointz);
  214. streamPoints->SetMaximumPropagationTime(100);
  215. streamPoints->SetIntegrationStepLength(0.02);
  216. streamPoints->SetNumberOfThreads(2);
  217. streamPoints->SetIntegrationDirectionToIntegrateBothDirections();
  218.  
  219. //Glyph Setup
  220. vtkConeSource *coneSource = vtkConeSource::New();
  221. vtkGlyph3D *glyph = vtkGlyph3D::New();
  222. glyph->SetInputConnection(reader->GetOutputPort());
  223. glyph->SetScaleFactor(0.1);
  224. glyph->SetSourceConnection(coneSource->GetOutputPort());
  225. coneSource->SetResolution(5);
  226. coneSource->SetHeight(0.5);
  227. coneSource->SetRadius(0.05);
  228. glyph->SetScaleModeToScaleByVector();
  229.  
  230. /***********************************************************/
  231. // Lookup Table
  232.  
  233. //lut.SetHueRange(0.667, 1.0);
  234. vtkLookupTable *lut = vtkLookupTable::New();
  235. lut->SetHueRange(0.667, 1.0);
  236. lut->Build();
  237.  
  238.  
  239.  
  240. //vtkLookupTable *lut2 = vtkLookupTable::New();
  241. //lut2->SetHueRange(0.667, 1.0);
  242. //lut2->Build();
  243.  
  244. // Poly Mapper glyph
  245. vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
  246. mapper->SetInputConnection(glyph->GetOutputPort());
  247. //mapper->SetScalarRange(0.0, 0.5);
  248. mapper->ScalarVisibilityOff();
  249. mapper->SetLookupTable(lut);
  250.  
  251. // Poly Mapper streamPoints
  252. vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
  253. mapper2->SetInputConnection(streamPoints->GetOutputPort());
  254. mapper2->SetScalarRange(0, 0.05);
  255. mapper2->ScalarVisibilityOff();
  256. mapper2->SetLookupTable(lut);
  257.  
  258.  
  259. // Poly Mapper streamLine
  260. //vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New();/////////////////////////////////////////////////
  261. //mapper3->SetInputConnection(streamLine->GetOutputPort());
  262. //mapper3->SetScalarRange(0.0, 0.5);
  263. //mapper3->SetLookupTable(lut);
  264.  
  265. // Actor
  266. vtkActor *actor = vtkActor::New();
  267. actor->SetMapper(mapper);
  268. actor->GetProperty()->SetColor(0, 0, 255);
  269.  
  270. // Actor2 for streamPoints
  271. vtkActor *actor2 = vtkActor::New();
  272. actor2->SetMapper(mapper2);
  273. actor2->GetProperty()->SetColor(255, 255, 255);
  274.  
  275. // Actor2 for streamPoints
  276. //vtkActor *actor3 = vtkActor::New();/////////////////////////////////////////////////
  277. //actor3->SetMapper(mapper3);
  278.  
  279. // Actors are added to the renderer. An initial camera view is created.
  280. // The Dolly() method moves the camera towards the FocalPoint,
  281. // thereby enlarging the image.
  282. aRenderer->AddActor(actor);//////
  283. aRenderer->AddActor(actor2);
  284. //aRenderer->AddActor(actor3);/////////////////////////////////////////////////
  285.  
  286.  
  287. // Set a background color for the renderer and set the size of the
  288. // render window (expressed in pixels).
  289. aRenderer->SetBackground(0, 0, 0);
  290. renWin->SetSize(800, 600);
  291.  
  292.  
  293. // Initialize the event loop and then start it.
  294. iren->Initialize();
  295. renWin->SetWindowName("Simple Volume Renderer");
  296. renWin->Render();
  297. iren->Start();
  298.  
  299.  
  300. return 0;
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement