vtkLightBoxRendererManager.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. // Instanciate 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. // Instanciate 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 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) - this->Internal->RenderWindowItemList.size();
  446. if (extraItem > 0)
  447. {
  448. //std::cout << "Creating " << extraItem << " RenderWindowItem";
  449. // Create extra RenderWindowItem(s)
  450. while(extraItem > 0)
  451. {
  452. RenderWindowItem * item =
  453. new RenderWindowItem(this->Internal->RendererBackgroundColor,
  454. this->Internal->HighlightedBoxColor,
  455. this->Internal->ColorWindow, this->Internal->ColorLevel);
  456. item->ImageMapper->SetInput(this->Internal->ImageData);
  457. this->Internal->RenderWindowItemList.push_back(item);
  458. --extraItem;
  459. }
  460. }
  461. else
  462. {
  463. //std::cout << "Removing " << extraItem << " RenderWindowItem";
  464. // Remove extra RenderWindowItem(s)
  465. extraItem = extraItem >= 0 ? extraItem : -extraItem; // Compute Abs
  466. while(extraItem > 0)
  467. {
  468. delete this->Internal->RenderWindowItemList.back();
  469. this->Internal->RenderWindowItemList.pop_back();
  470. --extraItem;
  471. }
  472. }
  473. this->Internal->RenderWindowRowCount = rowCount;
  474. this->Internal->RenderWindowColumnCount = columnCount;
  475. this->Internal->setupRendering();
  476. this->Internal->SetupCornerAnnotation();
  477. if (this->Internal->ImageData)
  478. {
  479. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  480. }
  481. this->Modified();
  482. }
  483. //----------------------------------------------------------------------------
  484. int vtkLightBoxRendererManager::GetRenderWindowRowCount()
  485. {
  486. return this->Internal->RenderWindowRowCount;
  487. }
  488. //----------------------------------------------------------------------------
  489. void vtkLightBoxRendererManager::SetRenderWindowRowCount(int newRowCount)
  490. {
  491. this->SetRenderWindowLayout(newRowCount, this->GetRenderWindowColumnCount());
  492. }
  493. //----------------------------------------------------------------------------
  494. int vtkLightBoxRendererManager::GetRenderWindowColumnCount()
  495. {
  496. return this->Internal->RenderWindowColumnCount;
  497. }
  498. //----------------------------------------------------------------------------
  499. void vtkLightBoxRendererManager::SetRenderWindowColumnCount(int newColumnCount)
  500. {
  501. this->SetRenderWindowLayout(this->GetRenderWindowRowCount(), newColumnCount);
  502. }
  503. //----------------------------------------------------------------------------
  504. bool vtkLightBoxRendererManager::GetHighlightedById(int id)
  505. {
  506. if (!this->IsInitialized())
  507. {
  508. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  509. return false;
  510. }
  511. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  512. {
  513. return false;
  514. }
  515. return this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->GetVisibility();
  516. }
  517. //----------------------------------------------------------------------------
  518. bool vtkLightBoxRendererManager::GetHighlighted(int rowId, int columnId)
  519. {
  520. return this->GetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId));
  521. }
  522. //----------------------------------------------------------------------------
  523. void vtkLightBoxRendererManager::SetHighlightedById(int id, bool highlighted)
  524. {
  525. if (!this->IsInitialized())
  526. {
  527. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  528. return;
  529. }
  530. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  531. {
  532. return;
  533. }
  534. this->Internal->RenderWindowItemList.at(id)->HighlightedBoxActor->SetVisibility(highlighted);
  535. this->Modified();
  536. }
  537. //----------------------------------------------------------------------------
  538. void vtkLightBoxRendererManager::SetHighlighted(int rowId, int columnId, bool highlighted)
  539. {
  540. this->SetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId), highlighted);
  541. }
  542. //----------------------------------------------------------------------------
  543. void vtkLightBoxRendererManager::SetHighlightedBoxColor(double newHighlightedBoxColor[3])
  544. {
  545. if (!this->IsInitialized())
  546. {
  547. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  548. return;
  549. }
  550. if (this->Internal->HighlightedBoxColor[0] == newHighlightedBoxColor[0] &&
  551. this->Internal->HighlightedBoxColor[1] == newHighlightedBoxColor[1] &&
  552. this->Internal->HighlightedBoxColor[2] == newHighlightedBoxColor[2])
  553. {
  554. return;
  555. }
  556. this->Internal->HighlightedBoxColor[0] = newHighlightedBoxColor[0];
  557. this->Internal->HighlightedBoxColor[1] = newHighlightedBoxColor[1];
  558. this->Internal->HighlightedBoxColor[2] = newHighlightedBoxColor[2];
  559. vtkInternal::RenderWindowItemListIt it;
  560. for(it = this->Internal->RenderWindowItemList.begin();
  561. it != this->Internal->RenderWindowItemList.end();
  562. ++it)
  563. {
  564. (*it)->SetHighlightedBoxColor(newHighlightedBoxColor);
  565. }
  566. this->Modified();
  567. }
  568. //----------------------------------------------------------------------------
  569. double* vtkLightBoxRendererManager::GetHighlightedBoxColor() const
  570. {
  571. return this->Internal->HighlightedBoxColor;
  572. }
  573. //----------------------------------------------------------------------------
  574. int vtkLightBoxRendererManager::ComputeRenderWindowItemId(int rowId, int columnId)
  575. {
  576. return this->Internal->RenderWindowColumnCount * rowId + columnId;
  577. }
  578. //----------------------------------------------------------------------------
  579. void vtkLightBoxRendererManager::SetCornerAnnotationText(const std::string& text)
  580. {
  581. if (!this->IsInitialized())
  582. {
  583. vtkErrorMacro(<< "SetCornerAnnotationText failed - "
  584. "vtkLightBoxRendererManager is NOT initialized");
  585. return;
  586. }
  587. if (text.compare(this->Internal->CornerAnnotation->GetText(2)) == 0)
  588. {
  589. return;
  590. }
  591. this->Internal->CornerAnnotation->ClearAllTexts();
  592. this->Internal->CornerAnnotation->SetText(2, text.c_str());
  593. this->Modified();
  594. }
  595. //----------------------------------------------------------------------------
  596. const std::string vtkLightBoxRendererManager::GetCornerAnnotationText() const
  597. {
  598. const char * text = this->Internal->CornerAnnotation->GetText(2);
  599. return text ? text : "";
  600. }
  601. // --------------------------------------------------------------------------
  602. void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
  603. {
  604. if (!this->IsInitialized())
  605. {
  606. vtkErrorMacro(<< "SetBackgroundColor failed - vtkLightBoxRendererManager is NOT initialized");
  607. return;
  608. }
  609. vtkInternal::RenderWindowItemListIt it;
  610. for(it = this->Internal->RenderWindowItemList.begin();
  611. it != this->Internal->RenderWindowItemList.end();
  612. ++it)
  613. {
  614. (*it)->Renderer->SetBackground(newBackgroundColor[0],
  615. newBackgroundColor[1],
  616. newBackgroundColor[2]);
  617. }
  618. this->Internal->RendererBackgroundColor[0] = newBackgroundColor[0];
  619. this->Internal->RendererBackgroundColor[1] = newBackgroundColor[1];
  620. this->Internal->RendererBackgroundColor[2] = newBackgroundColor[2];
  621. this->Modified();
  622. }
  623. //----------------------------------------------------------------------------
  624. double* vtkLightBoxRendererManager::GetBackgroundColor()const
  625. {
  626. return this->Internal->RendererBackgroundColor;
  627. }
  628. //----------------------------------------------------------------------------
  629. void vtkLightBoxRendererManager::SetColorLevel(double colorLevel)
  630. {
  631. this->SetColorWindowAndLevel(this->Internal->ColorWindow, colorLevel);
  632. }
  633. //----------------------------------------------------------------------------
  634. double vtkLightBoxRendererManager::GetColorLevel()const
  635. {
  636. return this->Internal->ColorLevel;
  637. }
  638. //----------------------------------------------------------------------------
  639. void vtkLightBoxRendererManager::SetColorWindow(double colorWindow)
  640. {
  641. this->SetColorWindowAndLevel(colorWindow, this->Internal->ColorLevel);
  642. }
  643. //----------------------------------------------------------------------------
  644. double vtkLightBoxRendererManager::GetColorWindow()const
  645. {
  646. return this->Internal->ColorWindow;
  647. }
  648. //----------------------------------------------------------------------------
  649. void vtkLightBoxRendererManager::SetColorWindowAndLevel(double colorWindow, double colorLevel)
  650. {
  651. if (this->Internal->ColorWindow == colorWindow &&
  652. this->Internal->ColorLevel == colorLevel)
  653. {
  654. return;
  655. }
  656. vtkInternal::RenderWindowItemListIt it;
  657. for(it = this->Internal->RenderWindowItemList.begin();
  658. it != this->Internal->RenderWindowItemList.end();
  659. ++it)
  660. {
  661. (*it)->ImageMapper->SetColorWindow(colorWindow);
  662. (*it)->ImageMapper->SetColorLevel(colorLevel);
  663. }
  664. this->Internal->ColorWindow = colorWindow;
  665. this->Internal->ColorLevel = colorLevel;
  666. this->Modified();
  667. }