vtkLightBoxRendererManager.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. #include "vtkLightBoxRendererManager.h"
  2. // VTK includes
  3. #include <vtkObjectFactory.h>
  4. #include <vtkSmartPointer.h>
  5. #include <vtkWeakPointer.h>
  6. #include <vtkRenderWindow.h>
  7. #include <vtkRendererCollection.h>
  8. #include <vtkRenderWindowInteractor.h>
  9. #include <vtkTextProperty.h>
  10. #include <vtkProperty2D.h>
  11. #include <vtkCamera.h>
  12. #include <vtkImageData.h>
  13. #include <vtkImageMapper.h>
  14. #include <vtkCellArray.h>
  15. #include <vtkPoints.h>
  16. #include <vtkPolyData.h>
  17. #include <vtkPolyDataMapper2D.h>
  18. #include <vtkCornerAnnotation.h>
  19. // STD includes
  20. #include <vector>
  21. #include <cassert>
  22. // Convenient macro
  23. #define VTK_CREATE(type, name) \
  24. vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
  25. //----------------------------------------------------------------------------
  26. vtkCxxRevisionMacro(vtkLightBoxRendererManager, "$Revision:$");
  27. vtkStandardNewMacro(vtkLightBoxRendererManager);
  28. namespace
  29. {
  30. //-----------------------------------------------------------------------------
  31. // RenderWindowItem
  32. //-----------------------------------------------------------------------------
  33. /// A RenderWindow can be split in 1x1, 2x3, ... grid view, each element of that grid
  34. /// will be identified as RenderWindowItem
  35. class RenderWindowItem
  36. {
  37. public:
  38. RenderWindowItem(const double rendererBackgroundColor[3], const double highlightedBoxColor[3],
  39. double colorWindow, double colorLevel);
  40. void SetViewport(double xMin, double yMin, double viewportWidth, double viewportHeight);
  41. /// Create the actor supporing the image mapper
  42. void SetupImageMapperActor(double colorWindow, double colorLevel);
  43. /// Create a box around the renderer.
  44. void SetupHighlightedBoxActor(const double highlightedBoxColor[3], bool visible = false);
  45. /// Set HighlightedBox color
  46. void SetHighlightedBoxColor(double* newHighlightedBoxColor);
  47. vtkSmartPointer<vtkRenderer> Renderer;
  48. vtkSmartPointer<vtkImageMapper> ImageMapper;
  49. vtkSmartPointer<vtkActor2D> HighlightedBoxActor;
  50. };
  51. }
  52. // --------------------------------------------------------------------------
  53. // RenderWindowItem methods
  54. //-----------------------------------------------------------------------------
  55. RenderWindowItem::RenderWindowItem(const double rendererBackgroundColor[3],
  56. const double highlightedBoxColor[3],
  57. double colorWindow, double colorLevel)
  58. {
  59. // Instantiate a renderer
  60. this->Renderer = vtkSmartPointer<vtkRenderer>::New();
  61. this->Renderer->SetBackground(rendererBackgroundColor[0],
  62. rendererBackgroundColor[1],
  63. rendererBackgroundColor[2]);
  64. this->SetupImageMapperActor(colorWindow, colorLevel);
  65. this->SetupHighlightedBoxActor(highlightedBoxColor);
  66. }
  67. //-----------------------------------------------------------------------------
  68. void RenderWindowItem::SetViewport(double xMin, double yMin,
  69. double viewportWidth, double viewportHeight)
  70. {
  71. assert(this->Renderer);
  72. this->Renderer->SetViewport( xMin, yMin, (xMin + viewportWidth), (yMin + viewportHeight));
  73. }
  74. //---------------------------------------------------------------------------
  75. void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLevel)
  76. {
  77. assert(this->Renderer);
  78. assert(!this->ImageMapper);
  79. // Instantiate an image mapper
  80. this->ImageMapper = vtkSmartPointer<vtkImageMapper>::New();
  81. this->ImageMapper->SetColorWindow(colorWindow);
  82. this->ImageMapper->SetColorLevel(colorLevel);
  83. // .. and its corresponding 2D actor
  84. VTK_CREATE(vtkActor2D, actor2D);
  85. actor2D->SetMapper(this->ImageMapper);
  86. actor2D->GetProperty()->SetDisplayLocationToBackground();
  87. // .. and add it to the renderer
  88. this->Renderer->AddActor2D(actor2D);
  89. }
  90. //---------------------------------------------------------------------------
  91. void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor[3], bool visible)
  92. {
  93. assert(this->Renderer);
  94. assert(!this->HighlightedBoxActor);
  95. // Create a highlight actor (2D box around viewport)
  96. VTK_CREATE(vtkPolyData, poly);
  97. VTK_CREATE(vtkPoints, points);
  98. double eps = 0.00;
  99. points->InsertNextPoint(eps, eps, 0); // bottom-left
  100. points->InsertNextPoint(1 + eps, eps, 0); // bottom-right
  101. points->InsertNextPoint(1 + eps, 1 + eps, 0); // top-right
  102. points->InsertNextPoint(eps, 1 + eps, 0); // top-left
  103. VTK_CREATE(vtkCellArray, cells);
  104. cells->InsertNextCell(5);
  105. cells->InsertCellPoint(0);
  106. cells->InsertCellPoint(1);
  107. cells->InsertCellPoint(2);
  108. cells->InsertCellPoint(3);
  109. cells->InsertCellPoint(0);
  110. poly->SetPoints(points);
  111. poly->SetLines(cells);
  112. VTK_CREATE(vtkCoordinate, coordinate);
  113. coordinate->SetCoordinateSystemToNormalizedViewport();
  114. coordinate->SetViewport(this->Renderer);
  115. VTK_CREATE(vtkPolyDataMapper2D, polyDataMapper);
  116. polyDataMapper->SetInput(poly);
  117. polyDataMapper->SetTransformCoordinate(coordinate);
  118. this->HighlightedBoxActor = vtkSmartPointer<vtkActor2D>::New();
  119. this->HighlightedBoxActor->SetMapper(polyDataMapper);
  120. this->HighlightedBoxActor->GetProperty()->SetColor(
  121. highlightedBoxColor[0], highlightedBoxColor[1], highlightedBoxColor[2]); // Default to green
  122. this->HighlightedBoxActor->GetProperty()->SetDisplayLocationToForeground();
  123. this->HighlightedBoxActor->GetProperty()->SetLineWidth(3); // wide enough so not clipped
  124. this->HighlightedBoxActor->SetVisibility(visible);
  125. this->Renderer->AddActor2D(this->HighlightedBoxActor);
  126. }
  127. //-----------------------------------------------------------------------------
  128. void RenderWindowItem::SetHighlightedBoxColor(double* newHighlightedBoxColor)
  129. {
  130. this->HighlightedBoxActor->GetProperty()->SetColor(newHighlightedBoxColor);
  131. }
  132. //-----------------------------------------------------------------------------
  133. // vtkInternal
  134. //-----------------------------------------------------------------------------
  135. class vtkLightBoxRendererManager::vtkInternal
  136. {
  137. public:
  138. vtkInternal(vtkLightBoxRendererManager* external);
  139. ~vtkInternal();
  140. /// Convenient setup methods
  141. void SetupCornerAnnotation();
  142. void setupRendering();
  143. /// Update render window ImageMapper Z slice according to \a layoutType
  144. void updateRenderWindowItemsZIndex(int layoutType);
  145. vtkSmartPointer<vtkRenderWindow> RenderWindow;
  146. int RenderWindowRowCount;
  147. int RenderWindowColumnCount;
  148. int RenderWindowLayoutType;
  149. double HighlightedBoxColor[3];
  150. int RendererLayer;
  151. vtkWeakPointer<vtkRenderWindowInteractor> CurrentInteractor;
  152. vtkSmartPointer<vtkCornerAnnotation> CornerAnnotation;
  153. std::string CornerAnnotationText;
  154. vtkWeakPointer<vtkImageData> ImageData;
  155. double ColorWindow;
  156. double ColorLevel;
  157. double RendererBackgroundColor[3];
  158. /// Collection of RenderWindowItem
  159. std::vector<RenderWindowItem* > RenderWindowItemList;
  160. /// .. and its associated convenient typedef
  161. typedef std::vector<RenderWindowItem*>::iterator RenderWindowItemListIt;
  162. /// Reference to the public interface
  163. vtkLightBoxRendererManager* External;
  164. };
  165. // --------------------------------------------------------------------------
  166. // vtkInternal methods
  167. // --------------------------------------------------------------------------
  168. vtkLightBoxRendererManager::vtkInternal::vtkInternal(vtkLightBoxRendererManager* external):
  169. External(external)
  170. {
  171. this->CornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
  172. this->RenderWindowRowCount = 0;
  173. this->RenderWindowColumnCount = 0;
  174. this->RenderWindowLayoutType = vtkLightBoxRendererManager::LeftRightTopBottom;
  175. this->ColorWindow = 255;
  176. this->ColorLevel = 127.5;
  177. this->RendererLayer = 0;
  178. // Default background color: black
  179. this->RendererBackgroundColor[0] = 0.0;
  180. this->RendererBackgroundColor[1] = 0.0;
  181. this->RendererBackgroundColor[2] = 0.0;
  182. // Default highlightedBox color: green
  183. this->HighlightedBoxColor[0] = 0.0;
  184. this->HighlightedBoxColor[1] = 1.0;
  185. this->HighlightedBoxColor[2] = 0.0;
  186. this->CornerAnnotation->SetMaximumLineHeight(0.07);
  187. vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
  188. tprop->ShadowOn();
  189. }
  190. // --------------------------------------------------------------------------
  191. vtkLightBoxRendererManager::vtkInternal::~vtkInternal()
  192. {
  193. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  194. it != this->RenderWindowItemList.end();
  195. ++it)
  196. {
  197. delete *it;
  198. }
  199. this->RenderWindowItemList.clear();
  200. }
  201. // --------------------------------------------------------------------------
  202. void vtkLightBoxRendererManager::vtkInternal::SetupCornerAnnotation()
  203. {
  204. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  205. it != this->RenderWindowItemList.end();
  206. ++it)
  207. {
  208. if (!(*it)->Renderer->HasViewProp(this->CornerAnnotation))
  209. {
  210. (*it)->Renderer->AddViewProp(this->CornerAnnotation);
  211. }
  212. }
  213. this->CornerAnnotation->ClearAllTexts();
  214. this->CornerAnnotation->SetText(2, this->CornerAnnotationText.c_str());
  215. }
  216. //---------------------------------------------------------------------------
  217. void vtkLightBoxRendererManager::vtkInternal::setupRendering()
  218. {
  219. assert(this->RenderWindow);
  220. // Remove only renderers managed by this light box
  221. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  222. it != this->RenderWindowItemList.end();
  223. ++it)
  224. {
  225. this->RenderWindow->GetRenderers()->RemoveItem((*it)->Renderer);
  226. }
  227. // Compute the width and height of each RenderWindowItem
  228. double viewportWidth = 1.0 / static_cast<double>(this->RenderWindowColumnCount);
  229. double viewportHeight = 1.0 / static_cast<double>(this->RenderWindowRowCount);
  230. // Postion of the Top-Left corner of the RenderWindowItem
  231. float xMin, yMin;
  232. // Loop through RenderWindowItem
  233. for ( int rowId = 0; rowId < this->RenderWindowRowCount; ++rowId )
  234. {
  235. yMin = (this->RenderWindowRowCount - 1 - rowId) * viewportHeight;
  236. xMin = 0.0;
  237. for ( int columnId = 0; columnId < this->RenderWindowColumnCount; ++columnId )
  238. {
  239. // Get reference to the renderWindowItem
  240. RenderWindowItem * item =
  241. this->RenderWindowItemList.at(
  242. this->External->ComputeRenderWindowItemId(rowId, columnId));
  243. // Set viewport
  244. item->SetViewport(xMin, yMin, viewportWidth, viewportHeight);
  245. // Add to RenderWindow
  246. this->RenderWindow->AddRenderer(item->Renderer);
  247. xMin += viewportWidth;
  248. }
  249. }
  250. }
  251. // --------------------------------------------------------------------------
  252. void vtkLightBoxRendererManager::vtkInternal::updateRenderWindowItemsZIndex(int layoutType)
  253. {
  254. for (int rowId = 0; rowId < this->RenderWindowRowCount; ++rowId)
  255. {
  256. for (int columnId = 0; columnId < this->RenderWindowColumnCount; ++columnId)
  257. {
  258. int itemId = this->External->ComputeRenderWindowItemId(rowId, columnId);
  259. assert(itemId <= static_cast<int>(this->RenderWindowItemList.size()));
  260. RenderWindowItem * item = this->RenderWindowItemList.at(itemId);
  261. assert(item->ImageMapper->GetInput());
  262. // Default to ctkVTKSliceView::LeftRightTopBottom
  263. int zSliceIndex = rowId * this->RenderWindowColumnCount + columnId;
  264. if (layoutType == vtkLightBoxRendererManager::LeftRightBottomTop)
  265. {
  266. zSliceIndex = (this->RenderWindowRowCount - rowId - 1) *
  267. this->RenderWindowColumnCount + columnId;
  268. }
  269. item->ImageMapper->SetZSlice(zSliceIndex);
  270. }
  271. }
  272. }
  273. //---------------------------------------------------------------------------
  274. // vtkLightBoxRendererManager methods
  275. // --------------------------------------------------------------------------
  276. vtkLightBoxRendererManager::vtkLightBoxRendererManager() : Superclass()
  277. {
  278. this->Internal = new vtkInternal(this);
  279. }
  280. // --------------------------------------------------------------------------
  281. vtkLightBoxRendererManager::~vtkLightBoxRendererManager()
  282. {
  283. delete this->Internal;
  284. }
  285. //----------------------------------------------------------------------------
  286. void vtkLightBoxRendererManager::PrintSelf(ostream& os, vtkIndent indent)
  287. {
  288. this->Superclass::PrintSelf(os, indent);
  289. }
  290. //----------------------------------------------------------------------------
  291. void vtkLightBoxRendererManager::SetRendererLayer(int newLayer)
  292. {
  293. if (this->IsInitialized())
  294. {
  295. vtkErrorMacro(<< "SetRendererLayer failed - vtkLightBoxRendererManager is initialized");
  296. return;
  297. }
  298. if (newLayer == this->Internal->RendererLayer)
  299. {
  300. return;
  301. }
  302. this->Internal->RendererLayer = newLayer;
  303. this->Modified();
  304. }
  305. //----------------------------------------------------------------------------
  306. vtkRenderWindow* vtkLightBoxRendererManager::GetRenderWindow()
  307. {
  308. return this->Internal->RenderWindow;
  309. }
  310. //----------------------------------------------------------------------------
  311. void vtkLightBoxRendererManager::Initialize(vtkRenderWindow* renderWindow)
  312. {
  313. if (this->Internal->RenderWindow)
  314. {
  315. vtkWarningMacro( << "vtkLightBoxRendererManager has already been initialized");
  316. return;
  317. }
  318. if (!renderWindow)
  319. {
  320. vtkErrorMacro("Failed to initialize vtkLightBoxRendererManager with a NULL renderWindow");
  321. return;
  322. }
  323. this->Internal->RenderWindow = renderWindow;
  324. // Set default Layout
  325. this->SetRenderWindowLayout(1, 1); // Modified() is invoked by SetRenderWindowLayout
  326. }
  327. //----------------------------------------------------------------------------
  328. bool vtkLightBoxRendererManager::IsInitialized()
  329. {
  330. return this->Internal->RenderWindow;
  331. }
  332. //----------------------------------------------------------------------------
  333. void vtkLightBoxRendererManager::SetImageData(vtkImageData* newImageData)
  334. {
  335. if (!this->IsInitialized())
  336. {
  337. vtkErrorMacro(<< "SetImageData failed - vtkLightBoxRendererManager is NOT initialized");
  338. return;
  339. }
  340. vtkInternal::RenderWindowItemListIt it;
  341. for(it = this->Internal->RenderWindowItemList.begin();
  342. it != this->Internal->RenderWindowItemList.end();
  343. ++it)
  344. {
  345. (*it)->ImageMapper->SetInput(newImageData);
  346. }
  347. if (newImageData)
  348. {
  349. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  350. }
  351. this->Internal->ImageData = newImageData;
  352. this->Modified();
  353. }
  354. //----------------------------------------------------------------------------
  355. vtkCamera* vtkLightBoxRendererManager::GetActiveCamera()
  356. {
  357. if (this->Internal->RenderWindowItemList.size() == 0)
  358. {
  359. return 0;
  360. }
  361. // Obtain reference of the first renderer
  362. vtkRenderer * firstRenderer = this->Internal->RenderWindowItemList.at(0)->Renderer;
  363. if (firstRenderer->IsActiveCameraCreated())
  364. {
  365. return firstRenderer->GetActiveCamera();
  366. }
  367. else
  368. {
  369. return 0;
  370. }
  371. return 0;
  372. }
  373. //----------------------------------------------------------------------------
  374. void vtkLightBoxRendererManager::SetActiveCamera(vtkCamera* newActiveCamera)
  375. {
  376. if (!this->IsInitialized())
  377. {
  378. vtkErrorMacro(<< "SetActiveCamera failed - vtkLightBoxRendererManager is NOT initialized");
  379. return;
  380. }
  381. if (newActiveCamera == this->GetActiveCamera())
  382. {
  383. return;
  384. }
  385. newActiveCamera->ParallelProjectionOn();
  386. vtkInternal::RenderWindowItemListIt it;
  387. for(it = this->Internal->RenderWindowItemList.begin();
  388. it != this->Internal->RenderWindowItemList.end();
  389. ++it)
  390. {
  391. (*it)->Renderer->SetActiveCamera(newActiveCamera);
  392. }
  393. this->Modified();
  394. }
  395. //----------------------------------------------------------------------------
  396. void vtkLightBoxRendererManager::ResetCamera()
  397. {
  398. if (!this->IsInitialized())
  399. {
  400. vtkErrorMacro(<< "ResetCamera failed - vtkLightBoxRendererManager is NOT initialized");
  401. return;
  402. }
  403. vtkInternal::RenderWindowItemListIt it;
  404. for(it = this->Internal->RenderWindowItemList.begin();
  405. it != this->Internal->RenderWindowItemList.end();
  406. ++it)
  407. {
  408. (*it)->Renderer->ResetCamera();
  409. }
  410. this->Modified();
  411. }
  412. //----------------------------------------------------------------------------
  413. int vtkLightBoxRendererManager::GetRenderWindowItemCount()
  414. {
  415. return static_cast<int>(this->Internal->RenderWindowItemList.size());
  416. }
  417. //----------------------------------------------------------------------------
  418. vtkRenderer* vtkLightBoxRendererManager::GetRenderer(int id)
  419. {
  420. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  421. {
  422. return 0;
  423. }
  424. return this->Internal->RenderWindowItemList.at(id)->Renderer;
  425. }
  426. //----------------------------------------------------------------------------
  427. vtkRenderer* vtkLightBoxRendererManager::GetRenderer(int rowId, int columnId)
  428. {
  429. return this->GetRenderer(this->ComputeRenderWindowItemId(rowId, columnId));
  430. }
  431. //----------------------------------------------------------------------------
  432. void vtkLightBoxRendererManager::SetRenderWindowLayoutType(int layoutType)
  433. {
  434. if (this->Internal->RenderWindowLayoutType == layoutType)
  435. {
  436. return;
  437. }
  438. if (this->Internal->ImageData)
  439. {
  440. this->Internal->updateRenderWindowItemsZIndex(layoutType);
  441. }
  442. this->Internal->RenderWindowLayoutType = layoutType;
  443. this->Modified();
  444. }
  445. //----------------------------------------------------------------------------
  446. int vtkLightBoxRendererManager::GetRenderWindowLayoutType() const
  447. {
  448. return this->Internal->RenderWindowLayoutType;
  449. }
  450. //----------------------------------------------------------------------------
  451. void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnCount)
  452. {
  453. if (!this->IsInitialized())
  454. {
  455. vtkErrorMacro(<< "SetRenderWindowLayout failed - "
  456. "vtkLightBoxRendererManager is NOT initialized");
  457. return;
  458. }
  459. // Sanity checks
  460. assert(rowCount >= 0 && columnCount >= 0);
  461. if(!(rowCount >= 0 && columnCount >= 0))
  462. {
  463. return;
  464. }
  465. if (this->Internal->RenderWindowRowCount == rowCount &&
  466. this->Internal->RenderWindowColumnCount == columnCount)
  467. {
  468. return;
  469. }
  470. int extraItem = (rowCount * columnCount)
  471. - static_cast<int>(this->Internal->RenderWindowItemList.size());
  472. if (extraItem > 0)
  473. {
  474. //std::cout << "Creating " << extraItem << " RenderWindowItem";
  475. // Create extra RenderWindowItem(s)
  476. while(extraItem > 0)
  477. {
  478. RenderWindowItem * item =
  479. new RenderWindowItem(this->Internal->RendererBackgroundColor,
  480. this->Internal->HighlightedBoxColor,
  481. this->Internal->ColorWindow, this->Internal->ColorLevel);
  482. item->Renderer->SetLayer(this->Internal->RendererLayer);
  483. item->ImageMapper->SetInput(this->Internal->ImageData);
  484. this->Internal->RenderWindowItemList.push_back(item);
  485. --extraItem;
  486. }
  487. }
  488. else
  489. {
  490. //std::cout << "Removing " << extraItem << " RenderWindowItem";
  491. // Remove extra RenderWindowItem(s)
  492. extraItem = extraItem >= 0 ? extraItem : -extraItem; // Compute Abs
  493. while(extraItem > 0)
  494. {
  495. delete this->Internal->RenderWindowItemList.back();
  496. this->Internal->RenderWindowItemList.pop_back();
  497. --extraItem;
  498. }
  499. }
  500. this->Internal->RenderWindowRowCount = rowCount;
  501. this->Internal->RenderWindowColumnCount = columnCount;
  502. this->Internal->setupRendering();
  503. this->Internal->SetupCornerAnnotation();
  504. if (this->Internal->ImageData)
  505. {
  506. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  507. }
  508. this->Modified();
  509. }
  510. //----------------------------------------------------------------------------
  511. int vtkLightBoxRendererManager::GetRenderWindowRowCount()
  512. {
  513. return this->Internal->RenderWindowRowCount;
  514. }
  515. //----------------------------------------------------------------------------
  516. void vtkLightBoxRendererManager::SetRenderWindowRowCount(int newRowCount)
  517. {
  518. this->SetRenderWindowLayout(newRowCount, this->GetRenderWindowColumnCount());
  519. }
  520. //----------------------------------------------------------------------------
  521. int vtkLightBoxRendererManager::GetRenderWindowColumnCount()
  522. {
  523. return this->Internal->RenderWindowColumnCount;
  524. }
  525. //----------------------------------------------------------------------------
  526. void vtkLightBoxRendererManager::SetRenderWindowColumnCount(int newColumnCount)
  527. {
  528. this->SetRenderWindowLayout(this->GetRenderWindowRowCount(), newColumnCount);
  529. }
  530. //----------------------------------------------------------------------------
  531. bool vtkLightBoxRendererManager::GetHighlightedById(int id)
  532. {
  533. if (!this->IsInitialized())
  534. {
  535. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  536. return false;
  537. }
  538. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  539. {
  540. return false;
  541. }
  542. return this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->GetVisibility();
  543. }
  544. //----------------------------------------------------------------------------
  545. bool vtkLightBoxRendererManager::GetHighlighted(int rowId, int columnId)
  546. {
  547. return this->GetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId));
  548. }
  549. //----------------------------------------------------------------------------
  550. void vtkLightBoxRendererManager::SetHighlightedById(int id, bool highlighted)
  551. {
  552. if (!this->IsInitialized())
  553. {
  554. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  555. return;
  556. }
  557. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  558. {
  559. return;
  560. }
  561. this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->SetVisibility(highlighted);
  562. this->Modified();
  563. }
  564. //----------------------------------------------------------------------------
  565. void vtkLightBoxRendererManager::SetHighlighted(int rowId, int columnId, bool highlighted)
  566. {
  567. this->SetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId), highlighted);
  568. }
  569. //----------------------------------------------------------------------------
  570. void vtkLightBoxRendererManager::SetHighlightedBoxColor(double newHighlightedBoxColor[3])
  571. {
  572. if (!this->IsInitialized())
  573. {
  574. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  575. return;
  576. }
  577. if (this->Internal->HighlightedBoxColor[0] == newHighlightedBoxColor[0] &&
  578. this->Internal->HighlightedBoxColor[1] == newHighlightedBoxColor[1] &&
  579. this->Internal->HighlightedBoxColor[2] == newHighlightedBoxColor[2])
  580. {
  581. return;
  582. }
  583. this->Internal->HighlightedBoxColor[0] = newHighlightedBoxColor[0];
  584. this->Internal->HighlightedBoxColor[1] = newHighlightedBoxColor[1];
  585. this->Internal->HighlightedBoxColor[2] = newHighlightedBoxColor[2];
  586. vtkInternal::RenderWindowItemListIt it;
  587. for(it = this->Internal->RenderWindowItemList.begin();
  588. it != this->Internal->RenderWindowItemList.end();
  589. ++it)
  590. {
  591. (*it)->SetHighlightedBoxColor(newHighlightedBoxColor);
  592. }
  593. this->Modified();
  594. }
  595. //----------------------------------------------------------------------------
  596. double* vtkLightBoxRendererManager::GetHighlightedBoxColor() const
  597. {
  598. return this->Internal->HighlightedBoxColor;
  599. }
  600. //----------------------------------------------------------------------------
  601. int vtkLightBoxRendererManager::ComputeRenderWindowItemId(int rowId, int columnId)
  602. {
  603. return this->Internal->RenderWindowColumnCount * rowId + columnId;
  604. }
  605. //----------------------------------------------------------------------------
  606. void vtkLightBoxRendererManager::SetCornerAnnotationText(const std::string& text)
  607. {
  608. if (!this->IsInitialized())
  609. {
  610. vtkErrorMacro(<< "SetCornerAnnotationText failed - "
  611. "vtkLightBoxRendererManager is NOT initialized");
  612. return;
  613. }
  614. if (text.compare(this->Internal->CornerAnnotationText) == 0)
  615. {
  616. return;
  617. }
  618. this->Internal->CornerAnnotation->ClearAllTexts();
  619. this->Internal->CornerAnnotation->SetText(2, text.c_str());
  620. this->Internal->CornerAnnotationText = text;
  621. this->Modified();
  622. }
  623. //----------------------------------------------------------------------------
  624. const std::string vtkLightBoxRendererManager::GetCornerAnnotationText() const
  625. {
  626. const char * text = this->Internal->CornerAnnotation->GetText(2);
  627. return text ? text : "";
  628. }
  629. // --------------------------------------------------------------------------
  630. vtkCornerAnnotation * vtkLightBoxRendererManager::GetCornerAnnotation() const
  631. {
  632. return this->Internal->CornerAnnotation;
  633. }
  634. // --------------------------------------------------------------------------
  635. void vtkLightBoxRendererManager::SetCornerAnnotation(vtkCornerAnnotation* annotation)
  636. {
  637. // Remove current corner annotation
  638. vtkInternal::RenderWindowItemListIt it;
  639. for(it = this->Internal->RenderWindowItemList.begin();
  640. it != this->Internal->RenderWindowItemList.end();
  641. ++it)
  642. {
  643. if (!(*it)->Renderer->HasViewProp(this->Internal->CornerAnnotation))
  644. {
  645. (*it)->Renderer->RemoveViewProp(this->Internal->CornerAnnotation);
  646. }
  647. }
  648. this->Internal->CornerAnnotation = annotation;
  649. }
  650. // --------------------------------------------------------------------------
  651. void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
  652. {
  653. if (!this->IsInitialized())
  654. {
  655. vtkErrorMacro(<< "SetBackgroundColor failed - vtkLightBoxRendererManager is NOT initialized");
  656. return;
  657. }
  658. vtkInternal::RenderWindowItemListIt it;
  659. for(it = this->Internal->RenderWindowItemList.begin();
  660. it != this->Internal->RenderWindowItemList.end();
  661. ++it)
  662. {
  663. (*it)->Renderer->SetBackground(newBackgroundColor[0],
  664. newBackgroundColor[1],
  665. newBackgroundColor[2]);
  666. }
  667. this->Internal->RendererBackgroundColor[0] = newBackgroundColor[0];
  668. this->Internal->RendererBackgroundColor[1] = newBackgroundColor[1];
  669. this->Internal->RendererBackgroundColor[2] = newBackgroundColor[2];
  670. this->Modified();
  671. }
  672. //----------------------------------------------------------------------------
  673. double* vtkLightBoxRendererManager::GetBackgroundColor()const
  674. {
  675. return this->Internal->RendererBackgroundColor;
  676. }
  677. //----------------------------------------------------------------------------
  678. void vtkLightBoxRendererManager::SetColorLevel(double colorLevel)
  679. {
  680. this->SetColorWindowAndLevel(this->Internal->ColorWindow, colorLevel);
  681. }
  682. //----------------------------------------------------------------------------
  683. double vtkLightBoxRendererManager::GetColorLevel()const
  684. {
  685. return this->Internal->ColorLevel;
  686. }
  687. //----------------------------------------------------------------------------
  688. void vtkLightBoxRendererManager::SetColorWindow(double colorWindow)
  689. {
  690. this->SetColorWindowAndLevel(colorWindow, this->Internal->ColorLevel);
  691. }
  692. //----------------------------------------------------------------------------
  693. double vtkLightBoxRendererManager::GetColorWindow()const
  694. {
  695. return this->Internal->ColorWindow;
  696. }
  697. //----------------------------------------------------------------------------
  698. void vtkLightBoxRendererManager::SetColorWindowAndLevel(double colorWindow, double colorLevel)
  699. {
  700. if (this->Internal->ColorWindow == colorWindow &&
  701. this->Internal->ColorLevel == colorLevel)
  702. {
  703. return;
  704. }
  705. vtkInternal::RenderWindowItemListIt it;
  706. for(it = this->Internal->RenderWindowItemList.begin();
  707. it != this->Internal->RenderWindowItemList.end();
  708. ++it)
  709. {
  710. (*it)->ImageMapper->SetColorWindow(colorWindow);
  711. (*it)->ImageMapper->SetColorLevel(colorLevel);
  712. }
  713. this->Internal->ColorWindow = colorWindow;
  714. this->Internal->ColorLevel = colorLevel;
  715. this->Modified();
  716. }