vtkLightBoxRendererManager.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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], double colorWindow, double colorLevel);
  39. void SetViewport(double xMin, double yMin, double viewportWidth, double viewportHeight);
  40. /// Create the actor supporing the image mapper
  41. void SetupImageMapperActor(double colorWindow, double colorLevel);
  42. /// Create a box around the renderer.
  43. void SetupHighlightBoxActor(bool visible = false);
  44. vtkSmartPointer<vtkRenderer> Renderer;
  45. vtkSmartPointer<vtkImageMapper> ImageMapper;
  46. vtkSmartPointer<vtkActor2D> HighlightBoxActor;
  47. };
  48. }
  49. // --------------------------------------------------------------------------
  50. // RenderWindowItem methods
  51. //-----------------------------------------------------------------------------
  52. RenderWindowItem::RenderWindowItem(const double rendererBackgroundColor[3],
  53. double colorWindow, double colorLevel)
  54. {
  55. // Instanciate a renderer
  56. this->Renderer = vtkSmartPointer<vtkRenderer>::New();
  57. this->Renderer->SetBackground(rendererBackgroundColor[0],
  58. rendererBackgroundColor[1],
  59. rendererBackgroundColor[2]);
  60. this->SetupImageMapperActor(colorWindow, colorLevel);
  61. this->SetupHighlightBoxActor();
  62. }
  63. //-----------------------------------------------------------------------------
  64. void RenderWindowItem::SetViewport(double xMin, double yMin,
  65. double viewportWidth, double viewportHeight)
  66. {
  67. assert(this->Renderer);
  68. this->Renderer->SetViewport( xMin, yMin, (xMin + viewportWidth), (yMin + viewportHeight));
  69. }
  70. //---------------------------------------------------------------------------
  71. void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLevel)
  72. {
  73. assert(this->Renderer);
  74. assert(!this->ImageMapper);
  75. // Instanciate an image mapper
  76. this->ImageMapper = vtkSmartPointer<vtkImageMapper>::New();
  77. this->ImageMapper->SetColorWindow(colorWindow);
  78. this->ImageMapper->SetColorLevel(colorLevel);
  79. // .. and its corresponding 2D actor
  80. VTK_CREATE(vtkActor2D, actor2D);
  81. actor2D->SetMapper(this->ImageMapper);
  82. actor2D->GetProperty()->SetDisplayLocationToBackground();
  83. // .. and add it to the renderer
  84. this->Renderer->AddActor2D(actor2D);
  85. }
  86. //---------------------------------------------------------------------------
  87. void RenderWindowItem::SetupHighlightBoxActor(bool visible)
  88. {
  89. assert(this->Renderer);
  90. assert(!this->HighlightBoxActor);
  91. // Create a highlight actor (2D box around viewport)
  92. VTK_CREATE(vtkPolyData, poly);
  93. VTK_CREATE(vtkPoints, points);
  94. double eps = 0.0;
  95. points->InsertNextPoint(eps, eps, 0);
  96. points->InsertNextPoint(1, eps, 0);
  97. points->InsertNextPoint(1, 1, 0);
  98. points->InsertNextPoint(eps, 1, 0);
  99. VTK_CREATE(vtkCellArray, cells);
  100. cells->InsertNextCell(5);
  101. cells->InsertCellPoint(0);
  102. cells->InsertCellPoint(1);
  103. cells->InsertCellPoint(2);
  104. cells->InsertCellPoint(3);
  105. cells->InsertCellPoint(0);
  106. poly->SetPoints(points);
  107. poly->SetLines(cells);
  108. VTK_CREATE(vtkCoordinate, coordinate);
  109. coordinate->SetCoordinateSystemToNormalizedViewport();
  110. coordinate->SetViewport(this->Renderer);
  111. VTK_CREATE(vtkPolyDataMapper2D, polyDataMapper);
  112. polyDataMapper->SetInput(poly);
  113. polyDataMapper->SetTransformCoordinate(coordinate);
  114. this->HighlightBoxActor = vtkSmartPointer<vtkActor2D>::New();
  115. this->HighlightBoxActor->SetMapper(polyDataMapper);
  116. this->HighlightBoxActor->GetProperty()->SetColor(1, 1, 0);
  117. this->HighlightBoxActor->GetProperty()->SetDisplayLocationToForeground();
  118. this->HighlightBoxActor->GetProperty()->SetLineWidth(3); // wide enough so not clipped
  119. this->HighlightBoxActor->SetVisibility(visible);
  120. this->Renderer->AddActor2D(this->HighlightBoxActor);
  121. }
  122. //-----------------------------------------------------------------------------
  123. // vtkInternal
  124. //-----------------------------------------------------------------------------
  125. class vtkLightBoxRendererManager::vtkInternal
  126. {
  127. public:
  128. vtkInternal(vtkLightBoxRendererManager* external);
  129. ~vtkInternal();
  130. /// Convenient setup methods
  131. void SetupCornerAnnotation();
  132. void setupRendering();
  133. /// Update render window ImageMapper Z slice according to \a layoutType
  134. void updateRenderWindowItemsZIndex(int layoutType);
  135. vtkSmartPointer<vtkRenderWindow> RenderWindow;
  136. int RenderWindowRowCount;
  137. int RenderWindowColumnCount;
  138. int RenderWindowLayoutType;
  139. vtkWeakPointer<vtkRenderWindowInteractor> CurrentInteractor;
  140. vtkSmartPointer<vtkCornerAnnotation> CornerAnnotation;
  141. vtkWeakPointer<vtkImageData> ImageData;
  142. double ColorWindow;
  143. double ColorLevel;
  144. double RendererBackgroundColor[3];
  145. /// Collection of RenderWindowItem
  146. std::vector<RenderWindowItem* > RenderWindowItemList;
  147. /// .. and its associated convenient typedef
  148. typedef std::vector<RenderWindowItem*>::iterator RenderWindowItemListIt;
  149. /// Reference to the public interface
  150. vtkLightBoxRendererManager* External;
  151. };
  152. // --------------------------------------------------------------------------
  153. // vtkInternal methods
  154. // --------------------------------------------------------------------------
  155. vtkLightBoxRendererManager::vtkInternal::vtkInternal(vtkLightBoxRendererManager* external):
  156. External(external)
  157. {
  158. this->CornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();
  159. this->RenderWindowRowCount = 0;
  160. this->RenderWindowColumnCount = 0;
  161. this->RenderWindowLayoutType = vtkLightBoxRendererManager::LeftRightTopBottom;
  162. this->ColorWindow = 255;
  163. this->ColorLevel = 127.5;
  164. // Default background color: black
  165. this->RendererBackgroundColor[0] = 0.0;
  166. this->RendererBackgroundColor[1] = 0.0;
  167. this->RendererBackgroundColor[2] = 0.0;
  168. }
  169. // --------------------------------------------------------------------------
  170. vtkLightBoxRendererManager::vtkInternal::~vtkInternal()
  171. {
  172. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  173. it != this->RenderWindowItemList.end();
  174. ++it)
  175. {
  176. delete *it;
  177. }
  178. this->RenderWindowItemList.clear();
  179. }
  180. // --------------------------------------------------------------------------
  181. void vtkLightBoxRendererManager::vtkInternal::SetupCornerAnnotation()
  182. {
  183. for(RenderWindowItemListIt it = this->RenderWindowItemList.begin();
  184. it != this->RenderWindowItemList.end();
  185. ++it)
  186. {
  187. if (!(*it)->Renderer->HasViewProp(this->CornerAnnotation))
  188. {
  189. (*it)->Renderer->AddViewProp(this->CornerAnnotation);
  190. this->CornerAnnotation->SetMaximumLineHeight(0.07);
  191. vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();
  192. tprop->ShadowOn();
  193. }
  194. this->CornerAnnotation->ClearAllTexts();
  195. }
  196. }
  197. //---------------------------------------------------------------------------
  198. void vtkLightBoxRendererManager::vtkInternal::setupRendering()
  199. {
  200. assert(this->RenderWindow);
  201. this->RenderWindow->GetRenderers()->RemoveAllItems();
  202. // Compute the width and height of each RenderWindowItem
  203. double viewportWidth = 1.0 / static_cast<double>(this->RenderWindowColumnCount);
  204. double viewportHeight = 1.0 / static_cast<double>(this->RenderWindowRowCount);
  205. // Postion of the Top-Left corner of the RenderWindowItem
  206. float xMin, yMin;
  207. // Loop through RenderWindowItem
  208. for ( int rowId = 0; rowId < this->RenderWindowRowCount; ++rowId )
  209. {
  210. yMin = (this->RenderWindowRowCount - 1 - rowId) * viewportHeight;
  211. xMin = 0.0;
  212. for ( int columnId = 0; columnId < this->RenderWindowColumnCount; ++columnId )
  213. {
  214. // Get reference to the renderWindowItem
  215. RenderWindowItem * item =
  216. this->RenderWindowItemList.at(
  217. this->External->ComputeRenderWindowItemId(rowId, columnId));
  218. // Set viewport
  219. item->SetViewport(xMin, yMin, viewportWidth, viewportHeight);
  220. // Add to RenderWindow
  221. this->RenderWindow->AddRenderer(item->Renderer);
  222. xMin += viewportWidth;
  223. }
  224. }
  225. }
  226. // --------------------------------------------------------------------------
  227. void vtkLightBoxRendererManager::vtkInternal::updateRenderWindowItemsZIndex(int layoutType)
  228. {
  229. for (int rowId = 0; rowId < this->RenderWindowRowCount; ++rowId)
  230. {
  231. for (int columnId = 0; columnId < this->RenderWindowColumnCount; ++columnId)
  232. {
  233. int itemId = this->External->ComputeRenderWindowItemId(rowId, columnId);
  234. assert(itemId <= static_cast<int>(this->RenderWindowItemList.size()));
  235. RenderWindowItem * item = this->RenderWindowItemList.at(itemId);
  236. assert(item->ImageMapper->GetInput());
  237. // Default to ctkVTKSliceView::LeftRightTopBottom
  238. int zSliceIndex = rowId * this->RenderWindowColumnCount + columnId;
  239. if (layoutType == vtkLightBoxRendererManager::LeftRightBottomTop)
  240. {
  241. zSliceIndex = (this->RenderWindowRowCount - rowId - 1) *
  242. this->RenderWindowColumnCount + columnId;
  243. }
  244. item->ImageMapper->SetZSlice(zSliceIndex);
  245. }
  246. }
  247. }
  248. //---------------------------------------------------------------------------
  249. // vtkLightBoxRendererManager methods
  250. // --------------------------------------------------------------------------
  251. vtkLightBoxRendererManager::vtkLightBoxRendererManager() : Superclass()
  252. {
  253. this->Internal = new vtkInternal(this);
  254. }
  255. // --------------------------------------------------------------------------
  256. vtkLightBoxRendererManager::~vtkLightBoxRendererManager()
  257. {
  258. delete this->Internal;
  259. }
  260. //----------------------------------------------------------------------------
  261. void vtkLightBoxRendererManager::PrintSelf(ostream& os, vtkIndent indent)
  262. {
  263. this->Superclass::PrintSelf(os, indent);
  264. }
  265. //----------------------------------------------------------------------------
  266. vtkRenderWindow* vtkLightBoxRendererManager::GetRenderWindow()
  267. {
  268. return this->Internal->RenderWindow;
  269. }
  270. //----------------------------------------------------------------------------
  271. void vtkLightBoxRendererManager::Initialize(vtkRenderWindow* renderWindow)
  272. {
  273. if (this->Internal->RenderWindow)
  274. {
  275. vtkWarningMacro( << "vtkLightBoxRendererManager has already been initialized");
  276. return;
  277. }
  278. if (!renderWindow)
  279. {
  280. vtkErrorMacro("Failed to initialize vtkLightBoxRendererManager with a NULL renderWindow");
  281. return;
  282. }
  283. this->Internal->RenderWindow = renderWindow;
  284. // Set default Layout
  285. this->SetRenderWindowLayout(1, 1); // Modified() is invoked by SetRenderWindowLayout
  286. }
  287. //----------------------------------------------------------------------------
  288. bool vtkLightBoxRendererManager::IsInitialized()
  289. {
  290. return this->Internal->RenderWindow;
  291. }
  292. //----------------------------------------------------------------------------
  293. void vtkLightBoxRendererManager::SetImageData(vtkImageData* newImageData)
  294. {
  295. if (!this->IsInitialized())
  296. {
  297. vtkErrorMacro(<< "SetImageData failed - vtkLightBoxRendererManager is NOT initialized");
  298. return;
  299. }
  300. vtkInternal::RenderWindowItemListIt it;
  301. for(it = this->Internal->RenderWindowItemList.begin();
  302. it != this->Internal->RenderWindowItemList.end();
  303. ++it)
  304. {
  305. (*it)->ImageMapper->SetInput(newImageData);
  306. }
  307. if (newImageData)
  308. {
  309. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  310. }
  311. this->Internal->ImageData = newImageData;
  312. this->Modified();
  313. }
  314. //----------------------------------------------------------------------------
  315. vtkCamera* vtkLightBoxRendererManager::GetActiveCamera()
  316. {
  317. if (this->Internal->RenderWindowItemList.size() == 0)
  318. {
  319. return 0;
  320. }
  321. // Obtain reference of the first renderer
  322. vtkRenderer * firstRenderer = this->Internal->RenderWindowItemList.at(0)->Renderer;
  323. if (firstRenderer->IsActiveCameraCreated())
  324. {
  325. return firstRenderer->GetActiveCamera();
  326. }
  327. else
  328. {
  329. return 0;
  330. }
  331. return 0;
  332. }
  333. //----------------------------------------------------------------------------
  334. void vtkLightBoxRendererManager::SetActiveCamera(vtkCamera* newActiveCamera)
  335. {
  336. if (!this->IsInitialized())
  337. {
  338. vtkErrorMacro(<< "SetActiveCamera failed - vtkLightBoxRendererManager is NOT initialized");
  339. return;
  340. }
  341. if (newActiveCamera == this->GetActiveCamera())
  342. {
  343. return;
  344. }
  345. newActiveCamera->ParallelProjectionOn();
  346. vtkInternal::RenderWindowItemListIt it;
  347. for(it = this->Internal->RenderWindowItemList.begin();
  348. it != this->Internal->RenderWindowItemList.end();
  349. ++it)
  350. {
  351. (*it)->Renderer->SetActiveCamera(newActiveCamera);
  352. }
  353. this->Modified();
  354. }
  355. //----------------------------------------------------------------------------
  356. void vtkLightBoxRendererManager::ResetCamera()
  357. {
  358. if (!this->IsInitialized())
  359. {
  360. vtkErrorMacro(<< "ResetCamera failed - vtkLightBoxRendererManager is NOT initialized");
  361. return;
  362. }
  363. vtkInternal::RenderWindowItemListIt it;
  364. for(it = this->Internal->RenderWindowItemList.begin();
  365. it != this->Internal->RenderWindowItemList.end();
  366. ++it)
  367. {
  368. (*it)->Renderer->ResetCamera();
  369. }
  370. this->Modified();
  371. }
  372. //----------------------------------------------------------------------------
  373. int vtkLightBoxRendererManager::GetRenderWindowItemCount()
  374. {
  375. return this->Internal->RenderWindowItemList.size();
  376. }
  377. //----------------------------------------------------------------------------
  378. vtkRenderer* vtkLightBoxRendererManager::GetRenderer(int id)
  379. {
  380. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  381. {
  382. return 0;
  383. }
  384. return this->Internal->RenderWindowItemList.at(id)->Renderer;
  385. }
  386. //----------------------------------------------------------------------------
  387. vtkRenderer* vtkLightBoxRendererManager::GetRenderer(int rowId, int columnId)
  388. {
  389. return this->GetRenderer(this->ComputeRenderWindowItemId(rowId, columnId));
  390. }
  391. //----------------------------------------------------------------------------
  392. void vtkLightBoxRendererManager::SetRenderWindowLayoutType(int layoutType)
  393. {
  394. if (this->Internal->RenderWindowLayoutType == layoutType)
  395. {
  396. return;
  397. }
  398. if (this->Internal->ImageData)
  399. {
  400. this->Internal->updateRenderWindowItemsZIndex(layoutType);
  401. }
  402. this->Internal->RenderWindowLayoutType = layoutType;
  403. this->Modified();
  404. }
  405. //----------------------------------------------------------------------------
  406. int vtkLightBoxRendererManager::GetRenderWindowLayoutType() const
  407. {
  408. return this->Internal->RenderWindowLayoutType;
  409. }
  410. //----------------------------------------------------------------------------
  411. void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnCount)
  412. {
  413. if (!this->IsInitialized())
  414. {
  415. vtkErrorMacro(<< "SetRenderWindowLayout failed - "
  416. "vtkLightBoxRendererManager is NOT initialized");
  417. return;
  418. }
  419. // Sanity checks
  420. assert(rowCount >= 0 && columnCount >= 0);
  421. if(!(rowCount >= 0 && columnCount >= 0))
  422. {
  423. return;
  424. }
  425. if (this->Internal->RenderWindowRowCount == rowCount &&
  426. this->Internal->RenderWindowColumnCount == columnCount)
  427. {
  428. return;
  429. }
  430. int extraItem = (rowCount * columnCount) - this->Internal->RenderWindowItemList.size();
  431. if (extraItem > 0)
  432. {
  433. //std::cout << "Creating " << extraItem << " RenderWindowItem";
  434. // Create extra RenderWindowItem(s)
  435. while(extraItem > 0)
  436. {
  437. RenderWindowItem * item =
  438. new RenderWindowItem(this->Internal->RendererBackgroundColor,
  439. this->Internal->ColorWindow, this->Internal->ColorLevel);
  440. item->ImageMapper->SetInput(this->Internal->ImageData);
  441. this->Internal->RenderWindowItemList.push_back(item);
  442. --extraItem;
  443. }
  444. }
  445. else
  446. {
  447. //std::cout << "Removing " << extraItem << " RenderWindowItem";
  448. // Remove extra RenderWindowItem(s)
  449. extraItem = extraItem >= 0 ? extraItem : -extraItem; // Compute Abs
  450. while(extraItem > 0)
  451. {
  452. delete this->Internal->RenderWindowItemList.back();
  453. this->Internal->RenderWindowItemList.pop_back();
  454. --extraItem;
  455. }
  456. }
  457. this->Internal->RenderWindowRowCount = rowCount;
  458. this->Internal->RenderWindowColumnCount = columnCount;
  459. this->Internal->setupRendering();
  460. this->Internal->SetupCornerAnnotation();
  461. if (this->Internal->ImageData)
  462. {
  463. this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
  464. }
  465. this->Modified();
  466. }
  467. //----------------------------------------------------------------------------
  468. void vtkLightBoxRendererManager::SetHighlightedById(int id, bool highlighted)
  469. {
  470. if (!this->IsInitialized())
  471. {
  472. vtkErrorMacro(<< "SetHighlightedById failed - vtkLightBoxRendererManager is NOT initialized");
  473. return;
  474. }
  475. if (id < 0 || id >= static_cast<int>(this->Internal->RenderWindowItemList.size()))
  476. {
  477. return;
  478. }
  479. this->Internal->RenderWindowItemList.at(id)->HighlightBoxActor->SetVisibility(highlighted);
  480. this->Modified();
  481. }
  482. //----------------------------------------------------------------------------
  483. void vtkLightBoxRendererManager::SetHighlighted(int rowId, int columnId, bool highlighted)
  484. {
  485. this->SetHighlightedById(this->ComputeRenderWindowItemId(rowId, columnId), highlighted);
  486. }
  487. //----------------------------------------------------------------------------
  488. int vtkLightBoxRendererManager::ComputeRenderWindowItemId(int rowId, int columnId)
  489. {
  490. return this->Internal->RenderWindowColumnCount * rowId + columnId;
  491. }
  492. //----------------------------------------------------------------------------
  493. void vtkLightBoxRendererManager::SetCornerAnnotationText(const std::string& text)
  494. {
  495. if (!this->IsInitialized())
  496. {
  497. vtkErrorMacro(<< "SetCornerAnnotationText failed - "
  498. "vtkLightBoxRendererManager is NOT initialized");
  499. return;
  500. }
  501. if (text.compare(this->Internal->CornerAnnotation->GetText(2)) == 0)
  502. {
  503. return;
  504. }
  505. this->Internal->CornerAnnotation->ClearAllTexts();
  506. this->Internal->CornerAnnotation->SetText(2, text.c_str());
  507. this->Modified();
  508. }
  509. //----------------------------------------------------------------------------
  510. const std::string vtkLightBoxRendererManager::GetCornerAnnotationText() const
  511. {
  512. const char * text = this->Internal->CornerAnnotation->GetText(2);
  513. return text ? text : "";
  514. }
  515. // --------------------------------------------------------------------------
  516. void vtkLightBoxRendererManager::SetBackgroundColor(const double newBackgroundColor[3])
  517. {
  518. if (!this->IsInitialized())
  519. {
  520. vtkErrorMacro(<< "SetBackgroundColor failed - vtkLightBoxRendererManager is NOT initialized");
  521. return;
  522. }
  523. vtkInternal::RenderWindowItemListIt it;
  524. for(it = this->Internal->RenderWindowItemList.begin();
  525. it != this->Internal->RenderWindowItemList.end();
  526. ++it)
  527. {
  528. (*it)->Renderer->SetBackground(newBackgroundColor[0],
  529. newBackgroundColor[1],
  530. newBackgroundColor[2]);
  531. }
  532. this->Internal->RendererBackgroundColor[0] = newBackgroundColor[0];
  533. this->Internal->RendererBackgroundColor[1] = newBackgroundColor[1];
  534. this->Internal->RendererBackgroundColor[2] = newBackgroundColor[2];
  535. this->Modified();
  536. }
  537. //----------------------------------------------------------------------------
  538. double* vtkLightBoxRendererManager::GetBackgroundColor()const
  539. {
  540. return this->Internal->RendererBackgroundColor;
  541. }
  542. //----------------------------------------------------------------------------
  543. void vtkLightBoxRendererManager::SetColorLevel(double colorLevel)
  544. {
  545. this->SetColorWindowAndLevel(this->Internal->ColorWindow, colorLevel);
  546. }
  547. //----------------------------------------------------------------------------
  548. double vtkLightBoxRendererManager::GetColorLevel()const
  549. {
  550. return this->Internal->ColorLevel;
  551. }
  552. //----------------------------------------------------------------------------
  553. void vtkLightBoxRendererManager::SetColorWindow(double colorWindow)
  554. {
  555. this->SetColorWindowAndLevel(colorWindow, this->Internal->ColorLevel);
  556. }
  557. //----------------------------------------------------------------------------
  558. double vtkLightBoxRendererManager::GetColorWindow()const
  559. {
  560. return this->Internal->ColorWindow;
  561. }
  562. //----------------------------------------------------------------------------
  563. void vtkLightBoxRendererManager::SetColorWindowAndLevel(double colorWindow, double colorLevel)
  564. {
  565. if (this->Internal->ColorWindow == colorWindow &&
  566. this->Internal->ColorLevel == colorLevel)
  567. {
  568. return;
  569. }
  570. vtkInternal::RenderWindowItemListIt it;
  571. for(it = this->Internal->RenderWindowItemList.begin();
  572. it != this->Internal->RenderWindowItemList.end();
  573. ++it)
  574. {
  575. (*it)->ImageMapper->SetColorWindow(colorWindow);
  576. (*it)->ImageMapper->SetColorLevel(colorLevel);
  577. }
  578. this->Internal->ColorWindow = colorWindow;
  579. this->Internal->ColorLevel = colorLevel;
  580. this->Modified();
  581. }