ctkVTKDiscretizableColorTransferWidget.cpp 20 KB

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