ctkVTKSliceView.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QDebug>
  16. #include <QResizeEvent>
  17. // CTK includes
  18. #include "ctkPimpl.h"
  19. #include "ctkVTKSliceView.h"
  20. #include "ctkVTKSliceView_p.h"
  21. // VTK includes
  22. #include <vtkRendererCollection.h>
  23. #include <vtkRenderWindowInteractor.h>
  24. #include <vtkTextProperty.h>
  25. #include <vtkProperty2D.h>
  26. #include <vtkCamera.h>
  27. #include <vtkImageData.h>
  28. #include <vtkCellArray.h>
  29. #include <vtkPoints.h>
  30. #include <vtkPolyData.h>
  31. #include <vtkPolyDataMapper2D.h>
  32. // Convenient macro
  33. #define VTK_CREATE(type, name) \
  34. vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
  35. // --------------------------------------------------------------------------
  36. // ctkVTKSliceViewPrivate methods
  37. // --------------------------------------------------------------------------
  38. ctkVTKSliceViewPrivate::ctkVTKSliceViewPrivate(ctkVTKSliceView& object)
  39. : ctkVTKAbstractViewPrivate(object)
  40. {
  41. this->LightBoxRendererManager = vtkSmartPointer<vtkLightBoxRendererManager>::New();
  42. this->OverlayRenderer = vtkSmartPointer<vtkRenderer>::New();
  43. }
  44. // --------------------------------------------------------------------------
  45. void ctkVTKSliceViewPrivate::setupCornerAnnotation()
  46. {
  47. this->ctkVTKAbstractViewPrivate::setupCornerAnnotation();
  48. this->LightBoxRendererManager->SetCornerAnnotation(this->CornerAnnotation);
  49. }
  50. //---------------------------------------------------------------------------
  51. void ctkVTKSliceViewPrivate::setupRendering()
  52. {
  53. Q_ASSERT(this->RenderWindow);
  54. this->RenderWindow->SetNumberOfLayers(2);
  55. // Initialize light box
  56. this->LightBoxRendererManager->Initialize(this->RenderWindow);
  57. this->LightBoxRendererManager->SetRenderWindowLayout(1, 1);
  58. // Setup overlay renderer
  59. this->OverlayRenderer->SetLayer(1);
  60. this->RenderWindow->AddRenderer(this->OverlayRenderer);
  61. // Create cornerAnnotation and set its default property
  62. this->OverlayCornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
  63. this->OverlayCornerAnnotation->SetMaximumLineHeight(0.07);
  64. vtkTextProperty *tprop = this->OverlayCornerAnnotation->GetTextProperty();
  65. tprop->ShadowOn();
  66. this->OverlayCornerAnnotation->ClearAllTexts();
  67. // Add corner annotation to overlay renderer
  68. this->OverlayRenderer->AddViewProp(this->OverlayCornerAnnotation);
  69. this->ctkVTKAbstractViewPrivate::setupRendering();
  70. }
  71. //---------------------------------------------------------------------------
  72. // ctkVTKSliceView methods
  73. // --------------------------------------------------------------------------
  74. ctkVTKSliceView::ctkVTKSliceView(QWidget* parentWidget)
  75. : Superclass(new ctkVTKSliceViewPrivate(*this), parentWidget)
  76. {
  77. Q_D(ctkVTKSliceView);
  78. d->init();
  79. }
  80. // --------------------------------------------------------------------------
  81. ctkVTKSliceView::~ctkVTKSliceView()
  82. {
  83. }
  84. //----------------------------------------------------------------------------
  85. void ctkVTKSliceView::setActiveCamera(vtkCamera * newActiveCamera)
  86. {
  87. Q_D(ctkVTKSliceView);
  88. d->LightBoxRendererManager->SetActiveCamera(newActiveCamera);
  89. d->OverlayRenderer->SetActiveCamera(newActiveCamera);
  90. }
  91. //----------------------------------------------------------------------------
  92. CTK_GET_CPP(ctkVTKSliceView, vtkLightBoxRendererManager*,
  93. lightBoxRendererManager, LightBoxRendererManager);
  94. //----------------------------------------------------------------------------
  95. CTK_GET_CPP(ctkVTKSliceView, vtkRenderer*, overlayRenderer, OverlayRenderer);
  96. //----------------------------------------------------------------------------
  97. void ctkVTKSliceView::resetCamera()
  98. {
  99. Q_D(ctkVTKSliceView);
  100. d->OverlayRenderer->ResetCamera();
  101. d->LightBoxRendererManager->ResetCamera();
  102. }
  103. //----------------------------------------------------------------------------
  104. void ctkVTKSliceView::setImageData(vtkImageData* newImageData)
  105. {
  106. Q_D(ctkVTKSliceView);
  107. d->LightBoxRendererManager->SetImageData(newImageData);
  108. }
  109. //----------------------------------------------------------------------------
  110. vtkCornerAnnotation * ctkVTKSliceView::overlayCornerAnnotation()const
  111. {
  112. Q_D(const ctkVTKSliceView);
  113. return d->OverlayCornerAnnotation;
  114. }
  115. //----------------------------------------------------------------------------
  116. QColor ctkVTKSliceView::backgroundColor()const
  117. {
  118. Q_D(const ctkVTKSliceView);
  119. double* color = d->LightBoxRendererManager->GetBackgroundColor();
  120. QColor c;
  121. c.setRgbF(color[0], color[1], color[2]);
  122. return c;
  123. }
  124. //----------------------------------------------------------------------------
  125. void ctkVTKSliceView::setBackgroundColor(const QColor& newBackgroundColor)
  126. {
  127. Q_D(ctkVTKSliceView);
  128. double color[3];
  129. color[0] = newBackgroundColor.redF();
  130. color[1] = newBackgroundColor.greenF();
  131. color[2] = newBackgroundColor.blueF();
  132. d->LightBoxRendererManager->SetBackgroundColor(color);
  133. }
  134. //----------------------------------------------------------------------------
  135. QColor ctkVTKSliceView::highlightedBoxColor()const
  136. {
  137. Q_D(const ctkVTKSliceView);
  138. double* color = d->LightBoxRendererManager->GetHighlightedBoxColor();
  139. QColor c;
  140. c.setRgbF(color[0], color[1], color[2]);
  141. return c;
  142. }
  143. //----------------------------------------------------------------------------
  144. void ctkVTKSliceView::setHighlightedBoxColor(const QColor& newHighlightedBoxColor)
  145. {
  146. Q_D(ctkVTKSliceView);
  147. double color[3];
  148. color[0] = newHighlightedBoxColor.redF();
  149. color[1] = newHighlightedBoxColor.greenF();
  150. color[2] = newHighlightedBoxColor.blueF();
  151. d->LightBoxRendererManager->SetHighlightedBoxColor(color);
  152. }
  153. //----------------------------------------------------------------------------
  154. ctkVTKSliceView::RenderWindowLayoutType ctkVTKSliceView::renderWindowLayoutType()const
  155. {
  156. Q_D(const ctkVTKSliceView);
  157. return static_cast<ctkVTKSliceView::RenderWindowLayoutType>(
  158. d->LightBoxRendererManager->GetRenderWindowLayoutType());
  159. }
  160. //----------------------------------------------------------------------------
  161. void ctkVTKSliceView::setRenderWindowLayoutType(RenderWindowLayoutType layoutType)
  162. {
  163. Q_D(ctkVTKSliceView);
  164. d->LightBoxRendererManager->SetRenderWindowLayoutType(layoutType);
  165. }
  166. //----------------------------------------------------------------------------
  167. double ctkVTKSliceView::colorLevel()const
  168. {
  169. Q_D(const ctkVTKSliceView);
  170. return d->LightBoxRendererManager->GetColorLevel();
  171. }
  172. //----------------------------------------------------------------------------
  173. void ctkVTKSliceView::setColorLevel(double newColorLevel)
  174. {
  175. Q_D(ctkVTKSliceView);
  176. d->LightBoxRendererManager->SetColorLevel(newColorLevel);
  177. }
  178. //----------------------------------------------------------------------------
  179. double ctkVTKSliceView::colorWindow()const
  180. {
  181. Q_D(const ctkVTKSliceView);
  182. return d->LightBoxRendererManager->GetColorWindow();
  183. }
  184. //----------------------------------------------------------------------------
  185. void ctkVTKSliceView::setColorWindow(double newColorWindow)
  186. {
  187. Q_D(ctkVTKSliceView);
  188. d->LightBoxRendererManager->SetColorWindow(newColorWindow);
  189. }
  190. //----------------------------------------------------------------------------
  191. void ctkVTKSliceView::resizeEvent(QResizeEvent * event)
  192. {
  193. this->QWidget::resizeEvent(event);
  194. emit this->resized(event->size());
  195. }
  196. //----------------------------------------------------------------------------
  197. void ctkVTKSliceView::setLightBoxRendererManagerRowCount(int newRowCount)
  198. {
  199. Q_D(ctkVTKSliceView);
  200. d->LightBoxRendererManager->SetRenderWindowRowCount(newRowCount);
  201. }
  202. //----------------------------------------------------------------------------
  203. void ctkVTKSliceView::setLightBoxRendererManagerColumnCount(int newColumnCount)
  204. {
  205. Q_D(ctkVTKSliceView);
  206. d->LightBoxRendererManager->SetRenderWindowColumnCount(newColumnCount);
  207. }