vtkLightBoxRendererManager.cpp 26 KB

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