vtkLightBoxRendererManager.cpp 28 KB

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