ctkVTKSliceView.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. // --------------------------------------------------------------------------
  33. // ctkVTKSliceViewPrivate methods
  34. // --------------------------------------------------------------------------
  35. ctkVTKSliceViewPrivate::ctkVTKSliceViewPrivate(ctkVTKSliceView& object)
  36. : ctkVTKAbstractViewPrivate(object)
  37. {
  38. this->LightBoxRendererManager = vtkSmartPointer<vtkLightBoxRendererManager>::New();
  39. this->OverlayRenderer = vtkSmartPointer<vtkRenderer>::New();
  40. }
  41. // --------------------------------------------------------------------------
  42. void ctkVTKSliceViewPrivate::setupCornerAnnotation()
  43. {
  44. this->ctkVTKAbstractViewPrivate::setupCornerAnnotation();
  45. this->LightBoxRendererManager->SetCornerAnnotation(this->CornerAnnotation);
  46. }
  47. //---------------------------------------------------------------------------
  48. void ctkVTKSliceViewPrivate::setupRendering()
  49. {
  50. Q_ASSERT(this->RenderWindow);
  51. this->RenderWindow->SetNumberOfLayers(2);
  52. // Initialize light box
  53. this->LightBoxRendererManager->Initialize(this->RenderWindow);
  54. this->LightBoxRendererManager->SetRenderWindowLayout(1, 1);
  55. // Setup overlay renderer
  56. this->OverlayRenderer->SetLayer(1);
  57. this->RenderWindow->AddRenderer(this->OverlayRenderer);
  58. // Create cornerAnnotation and set its default property
  59. this->OverlayCornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
  60. this->OverlayCornerAnnotation->SetMaximumLineHeight(0.07);
  61. vtkTextProperty *tprop = this->OverlayCornerAnnotation->GetTextProperty();
  62. tprop->ShadowOn();
  63. this->OverlayCornerAnnotation->ClearAllTexts();
  64. // Add corner annotation to overlay renderer
  65. this->OverlayRenderer->AddViewProp(this->OverlayCornerAnnotation);
  66. this->ctkVTKAbstractViewPrivate::setupRendering();
  67. }
  68. //---------------------------------------------------------------------------
  69. // ctkVTKSliceView methods
  70. // --------------------------------------------------------------------------
  71. ctkVTKSliceView::ctkVTKSliceView(QWidget* parentWidget)
  72. : Superclass(new ctkVTKSliceViewPrivate(*this), parentWidget)
  73. {
  74. Q_D(ctkVTKSliceView);
  75. d->init();
  76. }
  77. // --------------------------------------------------------------------------
  78. ctkVTKSliceView::~ctkVTKSliceView()
  79. {
  80. }
  81. //----------------------------------------------------------------------------
  82. void ctkVTKSliceView::setActiveCamera(vtkCamera * newActiveCamera)
  83. {
  84. Q_D(ctkVTKSliceView);
  85. d->LightBoxRendererManager->SetActiveCamera(newActiveCamera);
  86. d->OverlayRenderer->SetActiveCamera(newActiveCamera);
  87. }
  88. //----------------------------------------------------------------------------
  89. CTK_GET_CPP(ctkVTKSliceView, vtkLightBoxRendererManager*,
  90. lightBoxRendererManager, LightBoxRendererManager);
  91. //----------------------------------------------------------------------------
  92. CTK_GET_CPP(ctkVTKSliceView, vtkRenderer*, overlayRenderer, OverlayRenderer);
  93. //----------------------------------------------------------------------------
  94. void ctkVTKSliceView::resetCamera()
  95. {
  96. Q_D(ctkVTKSliceView);
  97. d->OverlayRenderer->ResetCamera();
  98. d->LightBoxRendererManager->ResetCamera();
  99. }
  100. //----------------------------------------------------------------------------
  101. void ctkVTKSliceView::setImageData(vtkImageData* newImageData)
  102. {
  103. Q_D(ctkVTKSliceView);
  104. d->LightBoxRendererManager->SetImageData(newImageData);
  105. }
  106. //----------------------------------------------------------------------------
  107. vtkCornerAnnotation * ctkVTKSliceView::overlayCornerAnnotation()const
  108. {
  109. Q_D(const ctkVTKSliceView);
  110. return d->OverlayCornerAnnotation;
  111. }
  112. //----------------------------------------------------------------------------
  113. QColor ctkVTKSliceView::backgroundColor()const
  114. {
  115. Q_D(const ctkVTKSliceView);
  116. double* color = d->LightBoxRendererManager->GetBackgroundColor();
  117. QColor c;
  118. c.setRgbF(color[0], color[1], color[2]);
  119. return c;
  120. }
  121. //----------------------------------------------------------------------------
  122. void ctkVTKSliceView::setBackgroundColor(const QColor& newBackgroundColor)
  123. {
  124. Q_D(ctkVTKSliceView);
  125. double color[3];
  126. color[0] = newBackgroundColor.redF();
  127. color[1] = newBackgroundColor.greenF();
  128. color[2] = newBackgroundColor.blueF();
  129. d->LightBoxRendererManager->SetBackgroundColor(color);
  130. }
  131. //----------------------------------------------------------------------------
  132. QColor ctkVTKSliceView::highlightedBoxColor()const
  133. {
  134. Q_D(const ctkVTKSliceView);
  135. double* color = d->LightBoxRendererManager->GetHighlightedBoxColor();
  136. QColor c;
  137. c.setRgbF(color[0], color[1], color[2]);
  138. return c;
  139. }
  140. //----------------------------------------------------------------------------
  141. void ctkVTKSliceView::setHighlightedBoxColor(const QColor& newHighlightedBoxColor)
  142. {
  143. Q_D(ctkVTKSliceView);
  144. double color[3];
  145. color[0] = newHighlightedBoxColor.redF();
  146. color[1] = newHighlightedBoxColor.greenF();
  147. color[2] = newHighlightedBoxColor.blueF();
  148. d->LightBoxRendererManager->SetHighlightedBoxColor(color);
  149. }
  150. //----------------------------------------------------------------------------
  151. ctkVTKSliceView::RenderWindowLayoutType ctkVTKSliceView::renderWindowLayoutType()const
  152. {
  153. Q_D(const ctkVTKSliceView);
  154. return static_cast<ctkVTKSliceView::RenderWindowLayoutType>(
  155. d->LightBoxRendererManager->GetRenderWindowLayoutType());
  156. }
  157. //----------------------------------------------------------------------------
  158. void ctkVTKSliceView::setRenderWindowLayoutType(RenderWindowLayoutType layoutType)
  159. {
  160. Q_D(ctkVTKSliceView);
  161. d->LightBoxRendererManager->SetRenderWindowLayoutType(layoutType);
  162. }
  163. //----------------------------------------------------------------------------
  164. double ctkVTKSliceView::colorLevel()const
  165. {
  166. Q_D(const ctkVTKSliceView);
  167. return d->LightBoxRendererManager->GetColorLevel();
  168. }
  169. //----------------------------------------------------------------------------
  170. void ctkVTKSliceView::setColorLevel(double newColorLevel)
  171. {
  172. Q_D(ctkVTKSliceView);
  173. d->LightBoxRendererManager->SetColorLevel(newColorLevel);
  174. }
  175. //----------------------------------------------------------------------------
  176. double ctkVTKSliceView::colorWindow()const
  177. {
  178. Q_D(const ctkVTKSliceView);
  179. return d->LightBoxRendererManager->GetColorWindow();
  180. }
  181. //----------------------------------------------------------------------------
  182. void ctkVTKSliceView::setColorWindow(double newColorWindow)
  183. {
  184. Q_D(ctkVTKSliceView);
  185. d->LightBoxRendererManager->SetColorWindow(newColorWindow);
  186. }
  187. //----------------------------------------------------------------------------
  188. void ctkVTKSliceView::resizeEvent(QResizeEvent * event)
  189. {
  190. this->QWidget::resizeEvent(event);
  191. emit this->resized(event->size());
  192. }
  193. //----------------------------------------------------------------------------
  194. void ctkVTKSliceView::setLightBoxRendererManagerRowCount(int newRowCount)
  195. {
  196. Q_D(ctkVTKSliceView);
  197. d->LightBoxRendererManager->SetRenderWindowRowCount(newRowCount);
  198. }
  199. //----------------------------------------------------------------------------
  200. void ctkVTKSliceView::setLightBoxRendererManagerColumnCount(int newColumnCount)
  201. {
  202. Q_D(ctkVTKSliceView);
  203. d->LightBoxRendererManager->SetRenderWindowColumnCount(newColumnCount);
  204. }