ctkVTKDiscretizableColorTransferWidget.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #include "ctkVTKDiscretizableColorTransferWidget.h"
  15. // CTK includes
  16. #include "ctkColorPickerButton.h"
  17. #include "ctkCompilerDetections_p.h" // For CTK_NULLPTR
  18. #include "ctkDoubleSlider.h"
  19. #include "ctkVTKScalarsToColorsComboBox.h"
  20. #include "ctkVTKScalarsToColorsUtils.h"
  21. #include "ui_ctkVTKDiscretizableColorTransferWidget.h"
  22. #include "vtkScalarsToColorsContextItem.h"
  23. // Qt includes
  24. #include <QColorDialog>
  25. #include <QCheckBox>
  26. #include <QDoubleValidator>
  27. #include <QHBoxLayout>
  28. #include <QIcon>
  29. #include <QLineEdit>
  30. #include <QLabel>
  31. #include <QMenu>
  32. #include <QPushButton>
  33. #include <QSpinBox>
  34. #include <QTimer>
  35. #include <QToolButton>
  36. #include <QVBoxLayout>
  37. #include <QWidgetAction>
  38. // VTK includes
  39. #if CTK_USE_QVTKOPENGLWIDGET
  40. #include <QVTKOpenGLWidget.h>
  41. #else
  42. #include <QVTKWidget.h>
  43. #endif
  44. #include <vtkCallbackCommand.h>
  45. #include <vtkContextScene.h>
  46. #include <vtkContextView.h>
  47. #include <vtkControlPointsItem.h>
  48. #include <vtkDiscretizableColorTransferFunction.h>
  49. #include <vtkDoubleArray.h>
  50. #include <vtkEventQtSlotConnect.h>
  51. #include <vtkIntArray.h>
  52. #include <vtkImageAccumulate.h>
  53. #include <vtkImageData.h>
  54. #include <vtkPiecewiseFunction.h>
  55. #include <vtkRenderer.h>
  56. #include <vtkRenderWindow.h>
  57. #include <vtkScalarsToColors.h>
  58. #include <vtkTable.h>
  59. // ----------------------------------------------------------------------------
  60. class ctkVTKDiscretizableColorTransferWidgetPrivate :
  61. public Ui_ctkVTKDiscretizableColorTransferWidget
  62. {
  63. Q_DECLARE_PUBLIC(ctkVTKDiscretizableColorTransferWidget);
  64. protected:
  65. ctkVTKDiscretizableColorTransferWidget* const q_ptr;
  66. public:
  67. ctkVTKDiscretizableColorTransferWidgetPrivate(
  68. ctkVTKDiscretizableColorTransferWidget& object);
  69. void setupUi(QWidget* widget);
  70. #if CTK_USE_QVTKOPENGLWIDGET
  71. QVTKOpenGLWidget* ScalarsToColorsView;
  72. #else
  73. QVTKWidget* ScalarsToColorsView;
  74. #endif
  75. vtkSmartPointer<vtkScalarsToColorsContextItem> scalarsToColorsContextItem;
  76. vtkSmartPointer<vtkContextView> scalarsToColorsContextView;
  77. vtkSmartPointer<vtkEventQtSlotConnect> eventLink;
  78. ///Option part
  79. ctkColorPickerButton* nanButton;
  80. QCheckBox* discretizeCheckBox;
  81. QSpinBox* nbOfDiscreteValuesSpinBox;
  82. /// Stores the range of the data.
  83. /// Extracted from the histogram
  84. double dataRange[2];
  85. double dataMean;
  86. double previousOpacityValue;
  87. vtkSmartPointer<vtkCallbackCommand> colorTransferFunctionModified;
  88. static void colorTransferFunctionModifiedCallback(vtkObject *caller,
  89. unsigned long eid, void *clientdata, void *calldata);
  90. };
  91. // ----------------------------------------------------------------------------
  92. ctkVTKDiscretizableColorTransferWidgetPrivate
  93. ::ctkVTKDiscretizableColorTransferWidgetPrivate(
  94. ctkVTKDiscretizableColorTransferWidget& object)
  95. : q_ptr(&object)
  96. {
  97. this->scalarsToColorsSelector = CTK_NULLPTR;
  98. // Option menu
  99. this->nanButton = CTK_NULLPTR;
  100. this->discretizeCheckBox = CTK_NULLPTR;
  101. this->nbOfDiscreteValuesSpinBox = CTK_NULLPTR;
  102. this->dataRange[0] = VTK_DOUBLE_MAX;
  103. this->dataRange[1] = VTK_DOUBLE_MIN;
  104. this->dataMean = 0.;
  105. this->previousOpacityValue = 0.;
  106. this->colorTransferFunctionModified =
  107. vtkSmartPointer<vtkCallbackCommand>::New();
  108. this->colorTransferFunctionModified->SetClientData(this);
  109. this->colorTransferFunctionModified->SetCallback(
  110. this->colorTransferFunctionModifiedCallback);
  111. }
  112. //-----------------------------------------------------------------------------
  113. void ctkVTKDiscretizableColorTransferWidgetPrivate::setupUi(QWidget* widget)
  114. {
  115. Q_Q(ctkVTKDiscretizableColorTransferWidget);
  116. this->Ui_ctkVTKDiscretizableColorTransferWidget::setupUi(widget);
  117. #if CTK_USE_QVTKOPENGLWIDGET
  118. this->ScalarsToColorsView = new QVTKOpenGLWidget;
  119. #else
  120. this->ScalarsToColorsView = new QVTKWidget;
  121. #endif
  122. this->gridLayout->addWidget(this->ScalarsToColorsView, 3, 2, 7, 1);
  123. this->scalarsToColorsContextItem =
  124. vtkSmartPointer<vtkScalarsToColorsContextItem>::New();
  125. this->scalarsToColorsContextView = vtkSmartPointer<vtkContextView> ::New();
  126. this->scalarsToColorsContextView->GetScene()->AddItem(
  127. this->scalarsToColorsContextItem.Get());
  128. this->scalarsToColorsContextView->SetInteractor(
  129. this->ScalarsToColorsView->GetInteractor());
  130. this->ScalarsToColorsView->SetRenderWindow(
  131. this->scalarsToColorsContextView->GetRenderWindow());
  132. q->setViewBackgroundColor(QColor(49, 54, 59));
  133. this->previousOpacityValue = opacitySlider->value();
  134. this->scalarsToColorsSelector->addScalarsToColors(CTK_NULLPTR, q->tr("Reset"));
  135. this->scalarsToColorsSelector->setCurrentIndex(-1);
  136. this->eventLink = vtkSmartPointer<vtkEventQtSlotConnect>::New();
  137. this->eventLink->Connect(scalarsToColorsContextItem.Get(),
  138. vtkControlPointsItem::CurrentPointEditEvent,
  139. q, SLOT(onCurrentPointEdit()));
  140. this->scalarsToColorsContextItem->AddObserver(vtkCommand::EndEvent,
  141. this->colorTransferFunctionModified);
  142. QObject::connect(this->scalarsToColorsSelector,
  143. SIGNAL(currentScalarsToColorsChanged(vtkScalarsToColors*)),
  144. q, SLOT(onPaletteIndexChanged(vtkScalarsToColors*)));
  145. QObject::connect(opacitySlider, SIGNAL(valueChanged(double)),
  146. q, SLOT(setGlobalOpacity(double)));
  147. QObject::connect(resetRangeButton, SIGNAL(clicked()),
  148. q, SLOT(resetColorTransferFunctionRange()));
  149. QObject::connect(centerRangeButton, SIGNAL(clicked()),
  150. q, SLOT(centerColorTransferFunctionRange()));
  151. QObject::connect(invertColorTransferFunctionButton, SIGNAL(clicked()),
  152. q, SLOT(invertColorTransferFunction()));
  153. QObject::connect(rangeSlider, SIGNAL(valuesChanged(double, double)),
  154. q, SLOT(setColorTransferFunctionRange(double, double)));
  155. /// Option panel menu
  156. QWidget* nanColorWidget = new QWidget(optionButton);
  157. QHBoxLayout* nanColorLayout = new QHBoxLayout(nanColorWidget);
  158. QWidget* discretizeWidget = new QWidget(optionButton);
  159. QHBoxLayout* discretizeLayout = new QHBoxLayout(discretizeWidget);
  160. nanColorLayout->setContentsMargins(0, 0, 0, 0);
  161. discretizeLayout->setContentsMargins(0, 0, 0, 0);
  162. optionButton->setIcon(q->style()->standardIcon(
  163. QStyle::SP_FileDialogDetailedView, CTK_NULLPTR, optionButton));
  164. QLabel* nanLabel = new QLabel(q->tr("NaN values"));
  165. nanButton = new ctkColorPickerButton;
  166. nanButton->setToolTip(q->tr("NaN color"));
  167. nanColorLayout->addWidget(nanButton);
  168. nanColorLayout->addWidget(nanLabel);
  169. discretizeCheckBox = new QCheckBox;
  170. discretizeCheckBox->setText(q->tr("Discretize"));
  171. discretizeCheckBox->setToolTip(q->tr("Discretize color transfer function"));
  172. nbOfDiscreteValuesSpinBox = new QSpinBox;
  173. nbOfDiscreteValuesSpinBox->setMinimum(1);
  174. nbOfDiscreteValuesSpinBox->setMaximum(255);
  175. nbOfDiscreteValuesSpinBox->setToolTip(q->tr("Number of discrete values"));
  176. nbOfDiscreteValuesSpinBox->setEnabled(discretizeCheckBox->isChecked());
  177. discretizeLayout->addWidget(discretizeCheckBox);
  178. discretizeLayout->addWidget(nbOfDiscreteValuesSpinBox);
  179. QMenu* optionMenu = new QMenu(optionButton);
  180. QWidgetAction* nanColorAction = new QWidgetAction(optionButton);
  181. nanColorAction->setDefaultWidget(nanColorWidget);
  182. QWidgetAction* discretizeAction = new QWidgetAction(optionButton);
  183. discretizeAction->setDefaultWidget(discretizeWidget);
  184. optionMenu->addAction(nanColorAction);
  185. optionMenu->addSeparator();
  186. optionMenu->addAction(discretizeAction);
  187. optionButton->setMenu(optionMenu);
  188. optionButton->setPopupMode(QToolButton::InstantPopup);
  189. QObject::connect(nanButton, SIGNAL(clicked()), q, SLOT(setNaNColor()));
  190. QObject::connect(discretizeCheckBox, SIGNAL(toggled(bool)),
  191. q, SLOT(setDiscretize(bool)));
  192. QObject::connect(nbOfDiscreteValuesSpinBox, SIGNAL(valueChanged(int)),
  193. q, SLOT(setNumberOfDiscreteValues(int)));
  194. ///Enable nbOfValuesSpinBox only if we use discretize
  195. QObject::connect(discretizeCheckBox, SIGNAL(toggled(bool)),
  196. nbOfDiscreteValuesSpinBox, SLOT(setEnabled(bool)));
  197. }
  198. // ----------------------------------------------------------------------------
  199. void
  200. ctkVTKDiscretizableColorTransferWidgetPrivate::colorTransferFunctionModifiedCallback(
  201. vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
  202. {
  203. ctkVTKDiscretizableColorTransferWidgetPrivate* self =
  204. reinterpret_cast<ctkVTKDiscretizableColorTransferWidgetPrivate*>(
  205. clientdata);
  206. vtkSmartPointer<vtkDiscretizableColorTransferFunction> dctf =
  207. self->scalarsToColorsContextItem->GetDiscretizableColorTransferFunction();
  208. if (dctf == CTK_NULLPTR)
  209. {
  210. return;
  211. }
  212. if (self->scalarsToColorsContextItem->IsProcessingColorTransferFunction())
  213. {
  214. return;
  215. }
  216. if (dctf->GetDiscretize())
  217. {
  218. dctf->Build();
  219. }
  220. self->discretizeCheckBox->setChecked(dctf->GetDiscretize());
  221. if (dctf->GetDiscretize())
  222. {
  223. self->nbOfDiscreteValuesSpinBox->setValue(dctf->GetNumberOfValues());
  224. }
  225. double* newRange = self->scalarsToColorsContextItem->GetCurrentRange();
  226. self->rangeSlider->setValues(newRange[0], newRange[1]);
  227. double r, g, b;
  228. self->scalarsToColorsContextItem->GetDiscretizableColorTransferFunction()->
  229. GetNanColor(r, g, b);
  230. QColor selected = QColor::fromRgbF(r, g, b);
  231. self->nanButton->setColor(selected);
  232. self->ScalarsToColorsView->GetInteractor()->Render();
  233. }
  234. // ----------------------------------------------------------------------------
  235. ctkVTKDiscretizableColorTransferWidget::ctkVTKDiscretizableColorTransferWidget(
  236. QWidget* parent)
  237. : QWidget(parent)
  238. , d_ptr(new ctkVTKDiscretizableColorTransferWidgetPrivate(*this))
  239. {
  240. Q_D(ctkVTKDiscretizableColorTransferWidget);
  241. d->setupUi(this);
  242. }
  243. // ----------------------------------------------------------------------------
  244. ctkVTKDiscretizableColorTransferWidget::~ctkVTKDiscretizableColorTransferWidget()
  245. {
  246. }
  247. // ----------------------------------------------------------------------------
  248. void ctkVTKDiscretizableColorTransferWidget::setColorTransferFunction(
  249. vtkScalarsToColors* ctf)
  250. {
  251. Q_D(ctkVTKDiscretizableColorTransferWidget);
  252. vtkScalarsToColors* oldCtf =
  253. d->scalarsToColorsContextItem->GetDiscretizableColorTransferFunction();
  254. if (oldCtf != CTK_NULLPTR)
  255. {
  256. oldCtf->RemoveObserver(d->colorTransferFunctionModified);
  257. }
  258. ///Setting the transfer function to the scalarsToColorsContextItem convert
  259. /// it to a vtkDiscretizableTransferFunction
  260. d->scalarsToColorsContextItem->SetColorTransferFunction(ctf);
  261. ctf = d->scalarsToColorsContextItem->GetColorTransferFunction();
  262. emit(currentScalarsToColorsChanged(ctf));
  263. if (ctf == CTK_NULLPTR)
  264. {
  265. d->rangeSlider->setRange(0., 255.);
  266. d->rangeSlider->setValues(0., 1.);
  267. d->rangeSlider->setEnabled(false);
  268. d->previousOpacityValue = 0.0;
  269. d->opacitySlider->setValue(d->previousOpacityValue);
  270. d->opacitySlider->setEnabled(false);
  271. d->optionButton->setEnabled(false);
  272. d->resetRangeButton->setEnabled(false);
  273. d->centerRangeButton->setEnabled(false);
  274. d->invertColorTransferFunctionButton->setEnabled(false);
  275. return;
  276. }
  277. // Set sliders values depending on the new color transfer function
  278. d->rangeSlider->setEnabled(true);
  279. d->opacitySlider->setEnabled(true);
  280. d->optionButton->setEnabled(true);
  281. d->resetRangeButton->setEnabled(true);
  282. d->centerRangeButton->setEnabled(true);
  283. d->invertColorTransferFunctionButton->setEnabled(true);
  284. double* newRange = d->scalarsToColorsContextItem->
  285. GetDiscretizableColorTransferFunction()->GetRange();
  286. d->rangeSlider->setRange(newRange[0], newRange[1]);
  287. d->previousOpacityValue = 1.0;
  288. d->opacitySlider->setValue(d->previousOpacityValue);
  289. ctf->AddObserver(
  290. vtkCommand::ModifiedEvent, d->colorTransferFunctionModified);
  291. d->colorTransferFunctionModified->Execute(ctf, vtkCommand::ModifiedEvent,
  292. this);
  293. }
  294. // ----------------------------------------------------------------------------
  295. vtkScalarsToColors*
  296. ctkVTKDiscretizableColorTransferWidget::colorTransferFunction() const
  297. {
  298. Q_D(const ctkVTKDiscretizableColorTransferWidget);
  299. return d->scalarsToColorsContextItem->GetColorTransferFunction();
  300. }
  301. // ----------------------------------------------------------------------------
  302. void ctkVTKDiscretizableColorTransferWidget::setHistogram(
  303. vtkImageAccumulate* histogram)
  304. {
  305. Q_D(ctkVTKDiscretizableColorTransferWidget);
  306. histogram->Update();
  307. d->dataRange[0] = histogram->GetMin()[0];
  308. d->dataRange[1] = histogram->GetMax()[0];
  309. d->dataMean = histogram->GetMean()[0];
  310. int* output = static_cast<int*>(histogram->GetOutput()->GetScalarPointer());
  311. double spacing = histogram->GetComponentSpacing()[0];
  312. double bin = histogram->GetComponentOrigin()[0];
  313. vtkSmartPointer<vtkDoubleArray> bins =
  314. vtkSmartPointer<vtkDoubleArray>::New();
  315. bins->SetNumberOfComponents(1);
  316. bins->SetNumberOfTuples(255);
  317. bins->SetName("image_extents");
  318. vtkSmartPointer<vtkIntArray> frequencies =
  319. vtkSmartPointer<vtkIntArray>::New();
  320. frequencies->SetNumberOfComponents(1);
  321. frequencies->SetNumberOfTuples(255);
  322. frequencies->SetName("Frequency");
  323. for (unsigned int j = 0; j < 255; ++j)
  324. {
  325. bins->SetTuple1(j, bin);
  326. bin += spacing;
  327. frequencies->SetTuple1(j, *output++);
  328. }
  329. vtkNew<vtkTable> table;
  330. table->AddColumn(bins);
  331. table->AddColumn(frequencies);
  332. d->scalarsToColorsContextItem->SetHistogramTable(table.Get(),
  333. "image_extents", "Frequency");
  334. d->scalarsToColorsContextItem->SetDataRange(d->dataRange[0], d->dataRange[1]);
  335. d->ScalarsToColorsView->GetInteractor()->Render();
  336. }
  337. // ----------------------------------------------------------------------------
  338. void ctkVTKDiscretizableColorTransferWidget::onPaletteIndexChanged(
  339. vtkScalarsToColors* ctf)
  340. {
  341. Q_D(ctkVTKDiscretizableColorTransferWidget);
  342. if (ctf == CTK_NULLPTR)
  343. {
  344. this->setColorTransferFunction(ctf);
  345. return;
  346. }
  347. if (ctf->IsA("vtkDiscretizableColorTransferFunction"))
  348. {
  349. vtkNew<vtkDiscretizableColorTransferFunction> newCtf;
  350. vtkNew<vtkPiecewiseFunction> newPf;
  351. newCtf->DeepCopy(vtkDiscretizableColorTransferFunction::SafeDownCast(ctf));
  352. newPf->DeepCopy(vtkDiscretizableColorTransferFunction::SafeDownCast(ctf)->GetScalarOpacityFunction());
  353. newCtf->SetScalarOpacityFunction(newPf.Get());
  354. newCtf->EnableOpacityMappingOn();
  355. this->setColorTransferFunction(newCtf.Get());
  356. }
  357. else if (ctf->IsA("vtkColorTransferFunction"))
  358. {
  359. vtkNew<vtkColorTransferFunction> newCtf;
  360. newCtf->DeepCopy(vtkColorTransferFunction::SafeDownCast(ctf));
  361. this->setColorTransferFunction(newCtf.Get());
  362. }
  363. }
  364. // ----------------------------------------------------------------------------
  365. void ctkVTKDiscretizableColorTransferWidget::setGlobalOpacity(double value)
  366. {
  367. Q_D(ctkVTKDiscretizableColorTransferWidget);
  368. d->scalarsToColorsContextItem->SetGlobalOpacity(
  369. value / d->previousOpacityValue);
  370. d->previousOpacityValue = value;
  371. }
  372. // ----------------------------------------------------------------------------
  373. void ctkVTKDiscretizableColorTransferWidget::setNaNColor()
  374. {
  375. Q_D(ctkVTKDiscretizableColorTransferWidget);
  376. QColor selected = d->nanButton->color();
  377. d->scalarsToColorsContextItem->GetDiscretizableColorTransferFunction()->
  378. SetNanColor(selected.redF(), selected.greenF(), selected.blueF());
  379. }
  380. // ----------------------------------------------------------------------------
  381. void ctkVTKDiscretizableColorTransferWidget::setDiscretize(bool checked)
  382. {
  383. Q_D(ctkVTKDiscretizableColorTransferWidget);
  384. d->scalarsToColorsContextItem->GetDiscretizableColorTransferFunction()->
  385. SetDiscretize(checked);
  386. }
  387. // ----------------------------------------------------------------------------
  388. void ctkVTKDiscretizableColorTransferWidget::setNumberOfDiscreteValues(
  389. int value)
  390. {
  391. Q_D(ctkVTKDiscretizableColorTransferWidget);
  392. d->scalarsToColorsContextItem->GetDiscretizableColorTransferFunction()
  393. ->SetNumberOfValues(value);
  394. }
  395. // ----------------------------------------------------------------------------
  396. void ctkVTKDiscretizableColorTransferWidget::setColorTransferFunctionRange(
  397. double minValue, double maxValue)
  398. {
  399. Q_D(ctkVTKDiscretizableColorTransferWidget);
  400. d->scalarsToColorsContextItem->SetCurrentRange(minValue, maxValue);
  401. }
  402. // ----------------------------------------------------------------------------
  403. void ctkVTKDiscretizableColorTransferWidget::onCurrentPointEdit()
  404. {
  405. Q_D(ctkVTKDiscretizableColorTransferWidget);
  406. double rgb[3];
  407. if (d->scalarsToColorsContextItem->GetCurrentControlPointColor(rgb))
  408. {
  409. QColor color = QColorDialog::getColor(
  410. QColor::fromRgbF(rgb[0], rgb[1], rgb[2]), this, "Select color at point",
  411. QColorDialog::DontUseNativeDialog);
  412. if (color.isValid())
  413. {
  414. rgb[0] = color.redF();
  415. rgb[1] = color.greenF();
  416. rgb[2] = color.blueF();
  417. d->scalarsToColorsContextItem->SetCurrentControlPointColor(rgb);
  418. }
  419. }
  420. }
  421. // ----------------------------------------------------------------------------
  422. void ctkVTKDiscretizableColorTransferWidget::resetColorTransferFunctionRange()
  423. {
  424. Q_D(ctkVTKDiscretizableColorTransferWidget);
  425. if (d->dataRange[0] <= d->dataRange[1])
  426. {
  427. d->scalarsToColorsContextItem->SetCurrentRange(
  428. d->dataRange[0], d->dataRange[1]);
  429. }
  430. }
  431. // ----------------------------------------------------------------------------
  432. void ctkVTKDiscretizableColorTransferWidget::centerColorTransferFunctionRange()
  433. {
  434. Q_D(ctkVTKDiscretizableColorTransferWidget);
  435. d->scalarsToColorsContextItem->CenterRange(d->dataMean);
  436. }
  437. // ----------------------------------------------------------------------------
  438. void ctkVTKDiscretizableColorTransferWidget::invertColorTransferFunction()
  439. {
  440. Q_D(ctkVTKDiscretizableColorTransferWidget);
  441. d->scalarsToColorsContextItem->InvertColorTransferFunction();
  442. }
  443. // ----------------------------------------------------------------------------
  444. void ctkVTKDiscretizableColorTransferWidget::setViewBackgroundColor(
  445. const QColor& i_color)
  446. {
  447. Q_D(ctkVTKDiscretizableColorTransferWidget);
  448. d->scalarsToColorsContextView->GetRenderer()->SetBackground(
  449. i_color.redF(), i_color.greenF(), i_color.blueF());
  450. }
  451. // ----------------------------------------------------------------------------
  452. QColor ctkVTKDiscretizableColorTransferWidget::viewBackgroundColor() const
  453. {
  454. Q_D(const ctkVTKDiscretizableColorTransferWidget);
  455. double rgb[3];
  456. d->scalarsToColorsContextView->GetRenderer()->GetBackground(rgb);
  457. return QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
  458. }
  459. // ----------------------------------------------------------------------------
  460. ctkVTKScalarsToColorsComboBox*
  461. ctkVTKDiscretizableColorTransferWidget::scalarsToColorsSelector() const
  462. {
  463. Q_D(const ctkVTKDiscretizableColorTransferWidget);
  464. return d->scalarsToColorsSelector;
  465. }