vtkLightBoxRendererManager.cpp 25 KB

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