vtkLightBoxRendererManager.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. vtkWeakPointer<vtkImageData> ImageData;
  154. double ColorWindow;
  155. double ColorLevel;
  156. double RendererBackgroundColor[3];
  157. /// Collection of RenderWindowItem
  158. std::vector<RenderWindowItem* > RenderWindowItemList;
  159. /// .. and its associated convenient typedef
  160. typedef std::vector<RenderWindowItem*>::iterator RenderWindowItemListIt;
  161. /// Reference to the public interface
  162. vtkLightBoxRendererManager* External;
  163. };
  164. // --------------------------------------------------------------------------
  165. // vtkInternal methods
  166. // --------------------------------------------------------------------------
  167. vtkLightBoxRendererManager::vtkInternal::vtkInternal(vtkLightBoxRendererManager* external):
  168. External(external)
  169. {
  170. this->CornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
  171. this->RenderWindowRowCount = 0;
  172. this->RenderWindowColumnCount = 0;
  173. this->RenderWindowLayoutType = vtkLightBoxRendererManager::LeftRightTopBottom;
  174. this->ColorWindow = 255;
  175. this->ColorLevel = 127.5;
  176. this->RendererLayer = 0;
  177. // Default background color: black
  178. this->RendererBackgroundColor[0] = 0.0;
  179. this->RendererBackgroundColor[1] = 0.0;
  180. this->RendererBackgroundColor[2] = 0.0;
  181. // Default highlightedBox color: green
  182. this->HighlightedBoxColor[0] = 0.0;
  183. this->HighlightedBoxColor[1] = 1.0;
  184. this->HighlightedBoxColor[2] = 0.0;
  185. }
  186. // --------------------------------------------------------------------------
  187. vtkLightBoxRendererManager::vtkInternal::~vtkInternal()
  188. {
  189. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  190. it != this->RenderWindowItemList.end();
  191. ++it)
  192. {
  193. delete *it;
  194. }
  195. this->RenderWindowItemList.clear();
  196. }
  197. // --------------------------------------------------------------------------
  198. void vtkLightBoxRendererManager::vtkInternal::SetupCornerAnnotation()
  199. {
  200. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  201. it != this->RenderWindowItemList.end();
  202. ++it)
  203. {
  204. if (!(*it)->Renderer->HasViewProp(this->CornerAnnotation))
  205. {
  206. (*it)->Renderer->AddViewProp(this->CornerAnnotation);
  207. this->CornerAnnotation->SetMaximumLineHeight(0.07);
  208. vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
  209. tprop->ShadowOn();
  210. }
  211. this->CornerAnnotation->ClearAllTexts();
  212. }
  213. }
  214. //---------------------------------------------------------------------------
  215. void vtkLightBoxRendererManager::vtkInternal::setupRendering()
  216. {
  217. assert(this->RenderWindow);
  218. // Remove only renderers managed by this light box
  219. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  220. it != this->RenderWindowItemList.end();
  221. ++it)
  222. {
  223. this->RenderWindow->GetRenderers()->RemoveItem((*it)->Renderer);
  224. }
  225. // Compute the width and height of each RenderWindowItem
  226. double viewportWidth = 1.0 / static_cast<double>(this->RenderWindowColumnCount);
  227. double viewportHeight = 1.0 / static_cast<double>(this->RenderWindowRowCount);
  228. // Postion of the Top-Left corner of the RenderWindowItem
  229. float xMin, yMin;
  230. // Loop through RenderWindowItem
  231. for ( int rowId = 0; rowId < this->RenderWindowRowCount; ++rowId )
  232. {
  233. yMin = (this->RenderWindowRowCount - 1 - rowId) * viewportHeight;
  234. xMin = 0.0;
  235. for ( int columnId = 0; columnId < this->RenderWindowColumnCount; ++columnId )
  236. {
  237. // Get reference to the renderWindowItem
  238. RenderWindowItem * item =
  239. this->RenderWindowItemList.at(
  240. this->External->ComputeRenderWindowItemId(rowId, columnId));
  241. // Set viewport
  242. item->SetViewport(xMin, yMin, viewportWidth, viewportHeight);
  243. // Add to RenderWindow
  244. this->RenderWindow->AddRenderer(item->Renderer);
  245. xMin += viewportWidth;
  246. }
  247. }
  248. }
  249. // --------------------------------------------------------------------------
  250. void vtkLightBoxRendererManager::vtkInternal::updateRenderWindowItemsZIndex(int layoutType)
  251. {
  252. for (int rowId = 0; rowId < this->RenderWindowRowCount; ++rowId)
  253. {
  254. for (int columnId = 0; columnId < this->RenderWindowColumnCount; ++columnId)
  255. {
  256. int itemId = this->External->ComputeRenderWindowItemId(rowId, columnId);
  257. assert(itemId <= static_cast<int>(this->RenderWindowItemList.size()));
  258. RenderWindowItem * item = this->RenderWindowItemList.at(itemId);
  259. assert(item->ImageMapper->GetInput());
  260. // Default to ctkVTKSliceView::LeftRightTopBottom
  261. int zSliceIndex = rowId * this->RenderWindowColumnCount + columnId;
  262. if (layoutType == vtkLightBoxRendererManager::LeftRightBottomTop)
  263. {
  264. zSliceIndex = (this->RenderWindowRowCount - rowId - 1) *
  265. this->RenderWindowColumnCount + columnId;
  266. }
  267. item->ImageMapper->SetZSlice(zSliceIndex);
  268. }
  269. }
  270. }
  271. //---------------------------------------------------------------------------
  272. // vtkLightBoxRendererManager methods
  273. // --------------------------------------------------------------------------
  274. vtkLightBoxRendererManager::vtkLightBoxRendererManager() : Superclass()
  275. {
  276. this->Internal = new vtkInternal(this);
  277. }
  278. // --------------------------------------------------------------------------
  279. vtkLightBoxRendererManager::~vtkLightBoxRendererManager()
  280. {
  281. delete this->Internal;
  282. }
  283. //----------------------------------------------------------------------------
  284. void vtkLightBoxRendererManager::PrintSelf(ostream& os, vtkIndent indent)
  285. {
  286. this->Superclass::PrintSelf(os, indent);
  287. }
  288. //----------------------------------------------------------------------------
  289. void vtkLightBoxRendererManager::SetRendererLayer(int newLayer)
  290. {
  291. if (this->IsInitialized())
  292. {
  293. vtkErrorMacro(<< "SetRendererLayer failed - vtkLightBoxRendererManager is initialized");
  294. return;
  295. }
  296. if (newLayer == this->Internal->RendererLayer)
  297. {
  298. return;
  299. }
  300. this->Internal->RendererLayer = newLayer;
  301. this->Modified();
  302. }
  303. //----------------------------------------------------------------------------
  304. vtkRenderWindow* vtkLightBoxRendererManager::GetRenderWindow()
  305. {
  306. return this->Internal->RenderWindow;
  307. }
  308. //----------------------------------------------------------------------------
  309. void vtkLightBoxRendererManager::Initialize(vtkRenderWindow* renderWindow)
  310. {
  311. if (this->Internal->RenderWindow)
  312. {
  313. vtkWarningMacro( << "vtkLightBoxRendererManager has already been initialized");
  314. return;
  315. }
  316. if (!renderWindow)
  317. {
  318. vtkErrorMacro("Failed to initialize vtkLightBoxRendererManager with a NULL renderWindow");
  319. return;
  320. }
  321. this->Internal->RenderWindow = renderWindow;
  322. // Set default Layout
  323. this->SetRenderWindowLayout(1, 1); // Modified() is invoked by SetRenderWindowLayout
  324. }
  325. //----------------------------------------------------------------------------
  326. bool vtkLightBoxRendererManager::IsInitialized()
  327. {
  328. return this->Internal->RenderWindow;
  329. }
  330. //----------------------------------------------------------------------------
  331. void vtkLightBoxRendererManager::SetImageData(vtkImageData* newImageData)
  332. {
  333. if (!this->IsInitialized())
  334. {
  335. vtkErrorMacro(<< "SetImageData failed - vtkLightBoxRendererManager is NOT initialized");
  336. return;
  337. }
  338. vtkInternal::RenderWindowItemListIt it;
  339. for(it = this->Internal->RenderWindowItemList.begin();
  340. it != this->Internal->RenderWindowItemList.end();
  341. ++it)
  342. {
  343. (*it)->ImageMapper->SetInput(newImageData);
  344. }
  345. if (newImageData)
  346. {
  347. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  348. }
  349. this->Internal->ImageData = newImageData;
  350. this->Modified();
  351. }
  352. //----------------------------------------------------------------------------
  353. vtkCamera* vtkLightBoxRendererManager::GetActiveCamera()
  354. {
  355. if (this->Internal->RenderWindowItemList.size() == 0)
  356. {
  357. return 0;
  358. }
  359. // Obtain reference of the first renderer
  360. vtkRenderer * firstRenderer = this->Internal->RenderWindowItemList.at(0)->Renderer;
  361. if (firstRenderer->IsActiveCameraCreated())
  362. {
  363. return firstRenderer->GetActiveCamera();
  364. }
  365. else
  366. {
  367. return 0;
  368. }
  369. return 0;
  370. }
  371. //----------------------------------------------------------------------------
  372. void vtkLightBoxRendererManager::SetActiveCamera(vtkCamera* newActiveCamera)
  373. {
  374. if (!this->IsInitialized())
  375. {
  376. vtkErrorMacro(<< "SetActiveCamera failed - vtkLightBoxRendererManager is NOT initialized");
  377. return;
  378. }
  379. if (newActiveCamera == this->GetActiveCamera())
  380. {
  381. return;
  382. }
  383. newActiveCamera->ParallelProjectionOn();
  384. vtkInternal::RenderWindowItemListIt it;
  385. for(it = this->Internal->RenderWindowItemList.begin();
  386. it != this->Internal->RenderWindowItemList.end();
  387. ++it)
  388. {
  389. (*it)->Renderer->SetActiveCamera(newActiveCamera);
  390. }
  391. this->Modified();
  392. }
  393. //----------------------------------------------------------------------------
  394. void vtkLightBoxRendererManager::ResetCamera()
  395. {
  396. if (!this->IsInitialized())
  397. {
  398. vtkErrorMacro(<< "ResetCamera failed - vtkLightBoxRendererManager is NOT initialized");
  399. return;
  400. }
  401. vtkInternal::RenderWindowItemListIt it;
  402. for(it = this->Internal->RenderWindowItemList.begin();
  403. it != this->Internal->RenderWindowItemList.end();
  404. ++it)
  405. {
  406. (*it)->Renderer->ResetCamera();
  407. }
  408. this->Modified();
  409. }
  410. //----------------------------------------------------------------------------
  411. int vtkLightBoxRendererManager::GetRenderWindowItemCount()
  412. {
  413. return static_cast<int>(this->Internal->RenderWindowItemList.size());
  414. }
  415. //----------------------------------------------------------------------------
  416. vtkRenderer* vtkLightBoxRendererManager::GetRenderer(int id)
  417. {
  418. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  419. {
  420. return 0;
  421. }
  422. return this->Internal->RenderWindowItemList.at(id)->Renderer;
  423. }
  424. //----------------------------------------------------------------------------
  425. vtkRenderer* vtkLightBoxRendererManager::GetRenderer(int rowId, int columnId)
  426. {
  427. return this->GetRenderer(this->ComputeRenderWindowItemId(rowId, columnId));
  428. }
  429. //----------------------------------------------------------------------------
  430. void vtkLightBoxRendererManager::SetRenderWindowLayoutType(int layoutType)
  431. {
  432. if (this->Internal->RenderWindowLayoutType == layoutType)
  433. {
  434. return;
  435. }
  436. if (this->Internal->ImageData)
  437. {
  438. this->Internal->updateRenderWindowItemsZIndex(layoutType);
  439. }
  440. this->Internal->RenderWindowLayoutType = layoutType;
  441. this->Modified();
  442. }
  443. //----------------------------------------------------------------------------
  444. int vtkLightBoxRendererManager::GetRenderWindowLayoutType() const
  445. {
  446. return this->Internal->RenderWindowLayoutType;
  447. }
  448. //----------------------------------------------------------------------------
  449. void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnCount)
  450. {
  451. if (!this->IsInitialized())
  452. {
  453. vtkErrorMacro(<< "SetRenderWindowLayout failed - "
  454. "vtkLightBoxRendererManager is NOT initialized");
  455. return;
  456. }
  457. // Sanity checks
  458. assert(rowCount >= 0 && columnCount >= 0);
  459. if(!(rowCount >= 0 && columnCount >= 0))
  460. {
  461. return;
  462. }
  463. if (this->Internal->RenderWindowRowCount == rowCount &&
  464. this->Internal->RenderWindowColumnCount == columnCount)
  465. {
  466. return;
  467. }
  468. int extraItem = (rowCount * columnCount)
  469. - static_cast<int>(this->Internal->RenderWindowItemList.size());
  470. if (extraItem > 0)
  471. {
  472. //std::cout << "Creating " << extraItem << " RenderWindowItem";
  473. // Create extra RenderWindowItem(s)
  474. while(extraItem > 0)
  475. {
  476. RenderWindowItem * item =
  477. new RenderWindowItem(this->Internal->RendererBackgroundColor,
  478. this->Internal->HighlightedBoxColor,
  479. this->Internal->ColorWindow, this->Internal->ColorLevel);
  480. item->Renderer->SetLayer(this->Internal->RendererLayer);
  481. item->ImageMapper->SetInput(this->Internal->ImageData);
  482. this->Internal->RenderWindowItemList.push_back(item);
  483. --extraItem;
  484. }
  485. }
  486. else
  487. {
  488. //std::cout << "Removing " << extraItem << " RenderWindowItem";
  489. // Remove extra RenderWindowItem(s)
  490. extraItem = extraItem >= 0 ? extraItem : -extraItem; // Compute Abs
  491. while(extraItem > 0)
  492. {
  493. delete this->Internal->RenderWindowItemList.back();
  494. this->Internal->RenderWindowItemList.pop_back();
  495. --extraItem;
  496. }
  497. }
  498. this->Internal->RenderWindowRowCount = rowCount;
  499. this->Internal->RenderWindowColumnCount = columnCount;
  500. this->Internal->setupRendering();
  501. this->Internal->SetupCornerAnnotation();
  502. if (this->Internal->ImageData)
  503. {
  504. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  505. }
  506. this->Modified();
  507. }
  508. //----------------------------------------------------------------------------
  509. int vtkLightBoxRendererManager::GetRenderWindowRowCount()
  510. {
  511. return this->Internal->RenderWindowRowCount;
  512. }
  513. //----------------------------------------------------------------------------
  514. void vtkLightBoxRendererManager::SetRenderWindowRowCount(int newRowCount)
  515. {
  516. this->SetRenderWindowLayout(newRowCount, this->GetRenderWindowColumnCount());
  517. }
  518. //----------------------------------------------------------------------------
  519. int vtkLightBoxRendererManager::GetRenderWindowColumnCount()
  520. {
  521. return this->Internal->RenderWindowColumnCount;
  522. }
  523. //----------------------------------------------------------------------------
  524. void vtkLightBoxRendererManager::SetRenderWindowColumnCount(int newColumnCount)
  525. {
  526. this->SetRenderWindowLayout(this->GetRenderWindowRowCount(), newColumnCount);
  527. }
  528. //----------------------------------------------------------------------------
  529. bool vtkLightBoxRendererManager::GetHighlightedById(int id)
  530. {
  531. if (!this->IsInitialized())
  532. {
  533. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  534. return false;
  535. }
  536. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  537. {
  538. return false;
  539. }
  540. return this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->GetVisibility();
  541. }
  542. //----------------------------------------------------------------------------
  543. bool vtkLightBoxRendererManager::GetHighlighted(int rowId, int columnId)
  544. {
  545. return this->GetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId));
  546. }
  547. //----------------------------------------------------------------------------
  548. void vtkLightBoxRendererManager::SetHighlightedById(int id, bool highlighted)
  549. {
  550. if (!this->IsInitialized())
  551. {
  552. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  553. return;
  554. }
  555. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  556. {
  557. return;
  558. }
  559. this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->SetVisibility(highlighted);
  560. this->Modified();
  561. }
  562. //----------------------------------------------------------------------------
  563. void vtkLightBoxRendererManager::SetHighlighted(int rowId, int columnId, bool highlighted)
  564. {
  565. this->SetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId), highlighted);
  566. }
  567. //----------------------------------------------------------------------------
  568. void vtkLightBoxRendererManager::SetHighlightedBoxColor(double newHighlightedBoxColor[3])
  569. {
  570. if (!this->IsInitialized())
  571. {
  572. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  573. return;
  574. }
  575. if (this->Internal->HighlightedBoxColor[0] == newHighlightedBoxColor[0] &&
  576. this->Internal->HighlightedBoxColor[1] == newHighlightedBoxColor[1] &&
  577. this->Internal->HighlightedBoxColor[2] == newHighlightedBoxColor[2])
  578. {
  579. return;
  580. }
  581. this->Internal->HighlightedBoxColor[0] = newHighlightedBoxColor[0];
  582. this->Internal->HighlightedBoxColor[1] = newHighlightedBoxColor[1];
  583. this->Internal->HighlightedBoxColor[2] = newHighlightedBoxColor[2];
  584. vtkInternal::RenderWindowItemListIt it;
  585. for(it = this->Internal->RenderWindowItemList.begin();
  586. it != this->Internal->RenderWindowItemList.end();
  587. ++it)
  588. {
  589. (*it)->SetHighlightedBoxColor(newHighlightedBoxColor);
  590. }
  591. this->Modified();
  592. }
  593. //----------------------------------------------------------------------------
  594. double* vtkLightBoxRendererManager::GetHighlightedBoxColor() const
  595. {
  596. return this->Internal->HighlightedBoxColor;
  597. }
  598. //----------------------------------------------------------------------------
  599. int vtkLightBoxRendererManager::ComputeRenderWindowItemId(int rowId, int columnId)
  600. {
  601. return this->Internal->RenderWindowColumnCount * rowId + columnId;
  602. }
  603. //----------------------------------------------------------------------------
  604. void vtkLightBoxRendererManager::SetCornerAnnotationText(const std::string& text)
  605. {
  606. if (!this->IsInitialized())
  607. {
  608. vtkErrorMacro(<< "SetCornerAnnotationText failed - "
  609. "vtkLightBoxRendererManager is NOT initialized");
  610. return;
  611. }
  612. if (text.compare(this->Internal->CornerAnnotation->GetText(2)) == 0)
  613. {
  614. return;
  615. }
  616. this->Internal->CornerAnnotation->ClearAllTexts();
  617. this->Internal->CornerAnnotation->SetText(2, text.c_str());
  618. this->Modified();
  619. }
  620. //----------------------------------------------------------------------------
  621. const std::string vtkLightBoxRendererManager::GetCornerAnnotationText() const
  622. {
  623. const char * text = this->Internal->CornerAnnotation->GetText(2);
  624. return text ? text : "";
  625. }
  626. // --------------------------------------------------------------------------
  627. vtkCornerAnnotation * vtkLightBoxRendererManager::GetCornerAnnotation() const
  628. {
  629. return this->Internal->CornerAnnotation;
  630. }
  631. // --------------------------------------------------------------------------
  632. void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
  633. {
  634. if (!this->IsInitialized())
  635. {
  636. vtkErrorMacro(<< "SetBackgroundColor failed - vtkLightBoxRendererManager is NOT initialized");
  637. return;
  638. }
  639. vtkInternal::RenderWindowItemListIt it;
  640. for(it = this->Internal->RenderWindowItemList.begin();
  641. it != this->Internal->RenderWindowItemList.end();
  642. ++it)
  643. {
  644. (*it)->Renderer->SetBackground(newBackgroundColor[0],
  645. newBackgroundColor[1],
  646. newBackgroundColor[2]);
  647. }
  648. this->Internal->RendererBackgroundColor[0] = newBackgroundColor[0];
  649. this->Internal->RendererBackgroundColor[1] = newBackgroundColor[1];
  650. this->Internal->RendererBackgroundColor[2] = newBackgroundColor[2];
  651. this->Modified();
  652. }
  653. //----------------------------------------------------------------------------
  654. double* vtkLightBoxRendererManager::GetBackgroundColor()const
  655. {
  656. return this->Internal->RendererBackgroundColor;
  657. }
  658. //----------------------------------------------------------------------------
  659. void vtkLightBoxRendererManager::SetColorLevel(double colorLevel)
  660. {
  661. this->SetColorWindowAndLevel(this->Internal->ColorWindow, colorLevel);
  662. }
  663. //----------------------------------------------------------------------------
  664. double vtkLightBoxRendererManager::GetColorLevel()const
  665. {
  666. return this->Internal->ColorLevel;
  667. }
  668. //----------------------------------------------------------------------------
  669. void vtkLightBoxRendererManager::SetColorWindow(double colorWindow)
  670. {
  671. this->SetColorWindowAndLevel(colorWindow, this->Internal->ColorLevel);
  672. }
  673. //----------------------------------------------------------------------------
  674. double vtkLightBoxRendererManager::GetColorWindow()const
  675. {
  676. return this->Internal->ColorWindow;
  677. }
  678. //----------------------------------------------------------------------------
  679. void vtkLightBoxRendererManager::SetColorWindowAndLevel(double colorWindow, double colorLevel)
  680. {
  681. if (this->Internal->ColorWindow == colorWindow &&
  682. this->Internal->ColorLevel == colorLevel)
  683. {
  684. return;
  685. }
  686. vtkInternal::RenderWindowItemListIt it;
  687. for(it = this->Internal->RenderWindowItemList.begin();
  688. it != this->Internal->RenderWindowItemList.end();
  689. ++it)
  690. {
  691. (*it)->ImageMapper->SetColorWindow(colorWindow);
  692. (*it)->ImageMapper->SetColorLevel(colorLevel);
  693. }
  694. this->Internal->ColorWindow = colorWindow;
  695. this->Internal->ColorLevel = colorLevel;
  696. this->Modified();
  697. }