ctkVTKScalarsToColorsWidget.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. // Qt includes
  15. #include <QDebug>
  16. #include <QTimer>
  17. // CTK includes
  18. #include "ctkLogger.h"
  19. #include "ctkUtils.h"
  20. #include "ctkVTKScalarsToColorsView.h"
  21. #include "ctkVTKScalarsToColorsWidget.h"
  22. #include "ui_ctkVTKScalarsToColorsWidget.h"
  23. // VTK includes
  24. #include <vtkAxis.h>
  25. #include <vtkChartXY.h>
  26. #include <vtkColorTransferControlPointsItem.h>
  27. #include <vtkColorTransferFunction.h>
  28. #include <vtkColorTransferFunctionItem.h>
  29. #include <vtkCompositeControlPointsItem.h>
  30. #include <vtkCompositeTransferFunctionItem.h>
  31. #include <vtkContextScene.h>
  32. #include <vtkLookupTable.h>
  33. #include <vtkLookupTableItem.h>
  34. #include <vtkPiecewiseControlPointsItem.h>
  35. #include <vtkPiecewiseFunction.h>
  36. #include <vtkPiecewiseFunctionItem.h>
  37. //----------------------------------------------------------------------------
  38. static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKScalarsToColorsWidget");
  39. //----------------------------------------------------------------------------
  40. class ctkVTKScalarsToColorsWidgetPrivate:
  41. public Ui_ctkVTKScalarsToColorsWidget
  42. {
  43. Q_DECLARE_PUBLIC(ctkVTKScalarsToColorsWidget);
  44. protected:
  45. ctkVTKScalarsToColorsWidget* const q_ptr;
  46. public:
  47. ctkVTKScalarsToColorsWidgetPrivate(ctkVTKScalarsToColorsWidget& object);
  48. void setupUi(QWidget* widget);
  49. bool blockSignals(bool);
  50. bool checkXRange(double x, int pointId);
  51. vtkControlPointsItem* CurrentControlPointsItem;
  52. bool EditColors;
  53. };
  54. // ----------------------------------------------------------------------------
  55. // ctkVTKScalarsToColorsWidgetPrivate methods
  56. // ----------------------------------------------------------------------------
  57. ctkVTKScalarsToColorsWidgetPrivate::ctkVTKScalarsToColorsWidgetPrivate(
  58. ctkVTKScalarsToColorsWidget& object)
  59. : q_ptr(&object)
  60. {
  61. this->CurrentControlPointsItem = 0;
  62. this->EditColors = true;
  63. }
  64. // ----------------------------------------------------------------------------
  65. void ctkVTKScalarsToColorsWidgetPrivate::setupUi(QWidget* widget)
  66. {
  67. Q_Q(ctkVTKScalarsToColorsWidget);
  68. this->Ui_ctkVTKScalarsToColorsWidget::setupUi(widget);
  69. QObject::connect(this->View, SIGNAL(plotAdded(vtkPlot*)),
  70. q, SLOT(onPlotAdded(vtkPlot*)));
  71. QObject::connect(this->View, SIGNAL(boundsChanged()),
  72. q, SLOT(onBoundsChanged()));
  73. this->PointIdSpinBox->setSpecialValueText("None");
  74. QObject::connect(this->PointIdSpinBox, SIGNAL(valueChanged(int)),
  75. q, SLOT(onCurrentPointChanged(int)));
  76. this->PointIdSpinBox->setValue(-1);
  77. QObject::connect(this->ColorPickerButton, SIGNAL(colorChanged(QColor)),
  78. q, SLOT(onColorChanged(QColor)));
  79. QObject::connect(this->XSpinBox, SIGNAL(valueChanged(double)),
  80. q, SLOT(onXChanged(double)));
  81. QObject::connect(this->OpacitySpinBox, SIGNAL(valueChanged(double)),
  82. q, SLOT(onOpacityChanged(double)));
  83. QObject::connect(this->MidPointSpinBox, SIGNAL(valueChanged(double)),
  84. q, SLOT(onMidPointChanged(double)));
  85. QObject::connect(this->SharpnessSpinBox, SIGNAL(valueChanged(double)),
  86. q, SLOT(onSharpnessChanged(double)));
  87. this->ColorPickerButton->setVisible(false);
  88. this->XLabel->setVisible(false);
  89. this->XSpinBox->setVisible(false);
  90. this->OpacityLabel->setVisible(false);
  91. this->OpacitySpinBox->setVisible(false);
  92. QObject::connect(this->XRangeSlider, SIGNAL(valuesChanged(double,double)),
  93. q, SLOT(setXRange(double,double)));
  94. QObject::connect(this->YRangeSlider, SIGNAL(valuesChanged(double,double)),
  95. q, SLOT(setYRange(double,double)));
  96. QObject::connect(this->XRangeSlider, SIGNAL(valuesChanged(double,double)),
  97. q, SIGNAL(axesModified()));
  98. QObject::connect(this->YRangeSlider, SIGNAL(valuesChanged(double,double)),
  99. q, SIGNAL(axesModified()));
  100. q->qvtkConnect(this->View->chart()->GetAxis(0),vtkCommand::ModifiedEvent,
  101. q, SLOT(onAxesModified()));
  102. q->qvtkConnect(this->View->chart()->GetAxis(1),vtkCommand::ModifiedEvent,
  103. q, SLOT(onAxesModified()));
  104. }
  105. // ----------------------------------------------------------------------------
  106. bool ctkVTKScalarsToColorsWidgetPrivate::blockSignals(bool block)
  107. {
  108. this->ColorPickerButton->blockSignals(block);
  109. this->XSpinBox->blockSignals(block);
  110. this->OpacitySpinBox->blockSignals(block);
  111. this->MidPointSpinBox->blockSignals(block);
  112. return this->SharpnessSpinBox->blockSignals(block);
  113. }
  114. // ----------------------------------------------------------------------------
  115. bool ctkVTKScalarsToColorsWidgetPrivate::checkXRange(double x, int pointId)
  116. {
  117. Q_Q(ctkVTKScalarsToColorsWidget);
  118. QPalette wrongPalette = q->palette();
  119. wrongPalette.setColor(QPalette::Highlight, Qt::red);
  120. if (pointId > 0)
  121. {
  122. double previous[4];
  123. this->CurrentControlPointsItem->GetControlPoint(pointId - 1, previous);
  124. if (x < previous[0])
  125. {
  126. this->XSpinBox->setPalette(wrongPalette);
  127. this->XSpinBox->selectAll();
  128. QTimer::singleShot(2000, q, SLOT(restorePalette()));
  129. this->XSpinBox->setValue(previous[0]);
  130. return false;
  131. }
  132. }
  133. if (pointId < this->PointIdSpinBox->maximum() - 1)
  134. {
  135. double next[4];
  136. this->CurrentControlPointsItem->GetControlPoint(pointId + 1, next);
  137. if (x > next[0])
  138. {
  139. this->XSpinBox->setPalette(wrongPalette);
  140. this->XSpinBox->selectAll();
  141. QTimer::singleShot(2000, q, SLOT(restorePalette()));
  142. this->XSpinBox->setValue(next[0]);
  143. return false;
  144. }
  145. }
  146. return true;
  147. }
  148. // ----------------------------------------------------------------------------
  149. // ctkVTKScalarsToColorsWidget methods
  150. // ----------------------------------------------------------------------------
  151. ctkVTKScalarsToColorsWidget::ctkVTKScalarsToColorsWidget(QWidget* parentWidget)
  152. :QWidget(parentWidget)
  153. , d_ptr(new ctkVTKScalarsToColorsWidgetPrivate(*this))
  154. {
  155. Q_D(ctkVTKScalarsToColorsWidget);
  156. d->setupUi(this);
  157. }
  158. // ----------------------------------------------------------------------------
  159. ctkVTKScalarsToColorsWidget::~ctkVTKScalarsToColorsWidget()
  160. {
  161. }
  162. // ----------------------------------------------------------------------------
  163. ctkVTKScalarsToColorsView* ctkVTKScalarsToColorsWidget::view()const
  164. {
  165. Q_D(const ctkVTKScalarsToColorsWidget);
  166. return d->View;
  167. }
  168. // ----------------------------------------------------------------------------
  169. bool ctkVTKScalarsToColorsWidget::isHorizontalSliderVisible()const
  170. {
  171. Q_D(const ctkVTKScalarsToColorsWidget);
  172. return d->XRangeSlider->isVisibleTo(
  173. const_cast<ctkVTKScalarsToColorsWidget*>(this));
  174. }
  175. // ----------------------------------------------------------------------------
  176. void ctkVTKScalarsToColorsWidget::setHorizontalSliderVisible(bool visible)
  177. {
  178. Q_D(ctkVTKScalarsToColorsWidget);
  179. d->XRangeSlider->setVisible(visible);
  180. }
  181. // ----------------------------------------------------------------------------
  182. bool ctkVTKScalarsToColorsWidget::isVerticalSliderVisible()const
  183. {
  184. Q_D(const ctkVTKScalarsToColorsWidget);
  185. return d->YRangeSlider->isVisibleTo(
  186. const_cast<ctkVTKScalarsToColorsWidget*>(this));
  187. }
  188. // ----------------------------------------------------------------------------
  189. void ctkVTKScalarsToColorsWidget::setVerticalSliderVisible(bool visible)
  190. {
  191. Q_D(ctkVTKScalarsToColorsWidget);
  192. d->YRangeSlider->setVisible(visible);
  193. }
  194. // ----------------------------------------------------------------------------
  195. bool ctkVTKScalarsToColorsWidget::editColors()const
  196. {
  197. Q_D(const ctkVTKScalarsToColorsWidget);
  198. return d->EditColors;
  199. }
  200. // ----------------------------------------------------------------------------
  201. void ctkVTKScalarsToColorsWidget::setEditColors(bool edit)
  202. {
  203. Q_D(ctkVTKScalarsToColorsWidget);
  204. d->EditColors = edit;
  205. }
  206. // ----------------------------------------------------------------------------
  207. void ctkVTKScalarsToColorsWidget::onPlotAdded(vtkPlot* plot)
  208. {
  209. if (vtkControlPointsItem::SafeDownCast(plot))
  210. {
  211. this->qvtkConnect(plot, vtkControlPointsItem::CurrentPointChangedEvent,
  212. this, SLOT(setCurrentPoint(vtkObject*,void*)));
  213. }
  214. }
  215. // ----------------------------------------------------------------------------
  216. void ctkVTKScalarsToColorsWidget::onBoundsChanged()
  217. {
  218. this->onAxesModified();
  219. }
  220. // ----------------------------------------------------------------------------
  221. void ctkVTKScalarsToColorsWidget::setCurrentPoint(vtkObject* caller, void* callData)
  222. {
  223. vtkControlPointsItem* controlPoints = reinterpret_cast<vtkControlPointsItem*>(caller);
  224. long newPoint = reinterpret_cast<long>(callData);
  225. if (!controlPoints || newPoint < -1)
  226. {
  227. return;
  228. }
  229. this->setCurrentControlPointsItem(controlPoints);
  230. this->setCurrentPoint(newPoint);
  231. }
  232. // ----------------------------------------------------------------------------
  233. void ctkVTKScalarsToColorsWidget::setCurrentPoint(int newPoint)
  234. {
  235. Q_D(ctkVTKScalarsToColorsWidget);
  236. d->PointIdSpinBox->setValue(newPoint);
  237. Q_ASSERT( newPoint == d->PointIdSpinBox->value());
  238. }
  239. // ----------------------------------------------------------------------------
  240. void ctkVTKScalarsToColorsWidget::setCurrentControlPointsItem(vtkControlPointsItem* item)
  241. {
  242. Q_D(ctkVTKScalarsToColorsWidget);
  243. if (d->CurrentControlPointsItem == item)
  244. {
  245. return;
  246. }
  247. this->qvtkReconnect(d->CurrentControlPointsItem, item, vtkCommand::ModifiedEvent,
  248. this, SLOT(updateCurrentPoint()));
  249. this->qvtkReconnect(d->CurrentControlPointsItem ?
  250. d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(0),
  251. item ? item->GetXAxis() : d->View->chart()->GetAxis(0),
  252. vtkCommand::ModifiedEvent,
  253. this, SLOT(onAxesModified()));
  254. this->qvtkReconnect(d->CurrentControlPointsItem ?
  255. d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(1),
  256. item ? item->GetYAxis() : d->View->chart()->GetAxis(1),
  257. vtkCommand::ModifiedEvent,
  258. this, SLOT(onAxesModified()));
  259. d->CurrentControlPointsItem = item;
  260. if (item)
  261. {
  262. d->ColorPickerButton->setVisible( d->EditColors &&
  263. (vtkColorTransferControlPointsItem::SafeDownCast(item) != 0 ||
  264. vtkCompositeControlPointsItem::SafeDownCast(item) != 0));
  265. d->XLabel->setVisible(true);
  266. d->XSpinBox->setVisible(true);
  267. d->OpacityLabel->setVisible(vtkPiecewiseControlPointsItem::SafeDownCast(item) != 0 ||
  268. vtkCompositeControlPointsItem::SafeDownCast(item) != 0);
  269. d->OpacitySpinBox->setVisible(vtkPiecewiseControlPointsItem::SafeDownCast(item) != 0 ||
  270. vtkCompositeControlPointsItem::SafeDownCast(item) != 0);
  271. this->onAxesModified();
  272. }
  273. d->PointIdSpinBox->setEnabled(item != 0);
  274. d->PointIdSpinBox->setMaximum((item ? item->GetNumberOfPoints() : 0) - 1);
  275. d->PointIdSpinBox->setValue(item ? item->GetCurrentPoint() : -1);
  276. this->updateCurrentPoint();
  277. }
  278. // ----------------------------------------------------------------------------
  279. vtkControlPointsItem* ctkVTKScalarsToColorsWidget::currentControlPointsItem()const
  280. {
  281. Q_D(const ctkVTKScalarsToColorsWidget);
  282. return d->CurrentControlPointsItem;
  283. }
  284. // ----------------------------------------------------------------------------
  285. void ctkVTKScalarsToColorsWidget::onCurrentPointChanged(int currentPoint)
  286. {
  287. Q_D(ctkVTKScalarsToColorsWidget);
  288. if (d->CurrentControlPointsItem)
  289. {
  290. d->CurrentControlPointsItem->SetCurrentPoint(currentPoint);
  291. }
  292. d->ColorPickerButton->setEnabled(currentPoint != -1);
  293. d->XSpinBox->setEnabled(currentPoint != -1);
  294. d->OpacitySpinBox->setEnabled(currentPoint != -1);
  295. d->MidPointSpinBox->setEnabled(currentPoint != -1);
  296. d->SharpnessSpinBox->setEnabled(currentPoint != -1);
  297. if (d->CurrentControlPointsItem)
  298. {
  299. this->updateCurrentPoint();
  300. }
  301. }
  302. // ----------------------------------------------------------------------------
  303. void ctkVTKScalarsToColorsWidget::updateCurrentPoint()
  304. {
  305. Q_D(ctkVTKScalarsToColorsWidget);
  306. Q_ASSERT(d->CurrentControlPointsItem);
  307. Q_ASSERT(d->PointIdSpinBox->value() == d->CurrentControlPointsItem->GetCurrentPoint());
  308. d->PointIdSpinBox->setMaximum((d->CurrentControlPointsItem ?
  309. d->CurrentControlPointsItem->GetNumberOfPoints() : 0) - 1);
  310. int pointId = d->PointIdSpinBox->value();
  311. if (pointId == -1)
  312. {
  313. return;
  314. }
  315. double point[4];
  316. d->CurrentControlPointsItem->GetControlPoint(pointId, point);
  317. bool oldBlock = d->blockSignals(true);
  318. d->XSpinBox->setValue(point[0]);
  319. d->OpacitySpinBox->setValue(point[1]);
  320. d->MidPointSpinBox->setValue(point[2]);
  321. d->SharpnessSpinBox->setValue(point[3]);
  322. vtkColorTransferControlPointsItem* colorControlPoints =
  323. vtkColorTransferControlPointsItem::SafeDownCast(d->CurrentControlPointsItem);
  324. vtkCompositeControlPointsItem* compositeControlPoints =
  325. vtkCompositeControlPointsItem::SafeDownCast(d->CurrentControlPointsItem);
  326. if (colorControlPoints &&
  327. (!compositeControlPoints ||
  328. compositeControlPoints->GetPointsFunction() == vtkCompositeControlPointsItem::ColorPointsFunction ||
  329. compositeControlPoints->GetPointsFunction() == vtkCompositeControlPointsItem::ColorAndOpacityPointsFunction))
  330. {
  331. vtkColorTransferFunction* colorTF =
  332. colorControlPoints->GetColorTransferFunction();
  333. double xrgbms[6];
  334. colorTF->GetNodeValue(d->PointIdSpinBox->value(), xrgbms);
  335. QColor color = QColor::fromRgbF(xrgbms[1], xrgbms[2], xrgbms[3]);
  336. d->ColorPickerButton->setColor(color);
  337. }
  338. d->blockSignals(oldBlock);
  339. }
  340. // ----------------------------------------------------------------------------
  341. void ctkVTKScalarsToColorsWidget::onColorChanged(const QColor& color)
  342. {
  343. Q_D(ctkVTKScalarsToColorsWidget);
  344. if (!color.isValid())
  345. {
  346. return;
  347. }
  348. Q_ASSERT(d->CurrentControlPointsItem);
  349. Q_ASSERT(d->PointIdSpinBox->value() != -1);
  350. Q_ASSERT(d->PointIdSpinBox->value() == d->CurrentControlPointsItem->GetCurrentPoint());
  351. vtkColorTransferControlPointsItem* colorControlPoints =
  352. vtkColorTransferControlPointsItem::SafeDownCast(d->CurrentControlPointsItem);
  353. if (colorControlPoints)
  354. {
  355. vtkColorTransferFunction* colorTF =
  356. colorControlPoints->GetColorTransferFunction();
  357. double point[6];
  358. colorTF->GetNodeValue(d->PointIdSpinBox->value(), point);
  359. point[1] = color.redF();
  360. point[2] = color.greenF();
  361. point[3] = color.blueF();
  362. colorTF->SetNodeValue(d->PointIdSpinBox->value(), point);
  363. }
  364. }
  365. // ----------------------------------------------------------------------------
  366. void ctkVTKScalarsToColorsWidget::onXChanged(double x)
  367. {
  368. Q_D(ctkVTKScalarsToColorsWidget);
  369. Q_ASSERT(d->CurrentControlPointsItem);
  370. bool validRange = d->checkXRange(x, d->PointIdSpinBox->value());
  371. if (!validRange)
  372. {
  373. return;
  374. }
  375. double point[4];
  376. d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
  377. point[0] = x;
  378. d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
  379. }
  380. // ----------------------------------------------------------------------------
  381. void ctkVTKScalarsToColorsWidget::onOpacityChanged(double opacity)
  382. {
  383. Q_D(ctkVTKScalarsToColorsWidget);
  384. Q_ASSERT(d->CurrentControlPointsItem);
  385. double point[4];
  386. d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
  387. point[1] = opacity;
  388. d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
  389. }
  390. // ----------------------------------------------------------------------------
  391. void ctkVTKScalarsToColorsWidget::onMidPointChanged(double midPoint)
  392. {
  393. Q_D(ctkVTKScalarsToColorsWidget);
  394. Q_ASSERT(d->CurrentControlPointsItem);
  395. double point[4];
  396. d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
  397. point[2] = midPoint;
  398. d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
  399. }
  400. // ----------------------------------------------------------------------------
  401. void ctkVTKScalarsToColorsWidget::onSharpnessChanged(double sharpness)
  402. {
  403. Q_D(ctkVTKScalarsToColorsWidget);
  404. Q_ASSERT(d->CurrentControlPointsItem);
  405. double point[4];
  406. d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
  407. point[3] = sharpness;
  408. d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
  409. }
  410. // ----------------------------------------------------------------------------
  411. void ctkVTKScalarsToColorsWidget::xRange(double* range)const
  412. {
  413. Q_D(const ctkVTKScalarsToColorsWidget);
  414. vtkAxis* xAxis = d->CurrentControlPointsItem ?
  415. d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
  416. Q_ASSERT(xAxis);
  417. range[0] = xAxis->GetMinimum();
  418. range[1] = xAxis->GetMaximum();
  419. }
  420. // ----------------------------------------------------------------------------
  421. void ctkVTKScalarsToColorsWidget::setXRange(double min, double max)
  422. {
  423. Q_D(ctkVTKScalarsToColorsWidget);
  424. vtkAxis* xAxis = d->CurrentControlPointsItem ?
  425. d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
  426. Q_ASSERT(xAxis);
  427. if (xAxis->GetMinimum() != min || xAxis->GetMaximum() != max)
  428. {
  429. xAxis->SetRange(min, max);
  430. // Repaint the scene
  431. d->View->scene()->SetDirty(true);
  432. }
  433. }
  434. // ----------------------------------------------------------------------------
  435. void ctkVTKScalarsToColorsWidget::yRange(double* range)const
  436. {
  437. Q_D(const ctkVTKScalarsToColorsWidget);
  438. vtkAxis* yAxis = d->CurrentControlPointsItem ?
  439. d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
  440. Q_ASSERT(yAxis);
  441. range[0] = yAxis->GetMinimum();
  442. range[1] = yAxis->GetMaximum();
  443. }
  444. // ----------------------------------------------------------------------------
  445. void ctkVTKScalarsToColorsWidget::setYRange(double min, double max)
  446. {
  447. Q_D(ctkVTKScalarsToColorsWidget);
  448. vtkAxis* yAxis = d->CurrentControlPointsItem ?
  449. d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
  450. Q_ASSERT(yAxis);
  451. if (yAxis->GetMinimum() != min || yAxis->GetMaximum() != max)
  452. {
  453. yAxis->SetRange(min, max);
  454. // Repaint the scene
  455. d->View->scene()->SetDirty(true);
  456. }
  457. }
  458. // ----------------------------------------------------------------------------
  459. void ctkVTKScalarsToColorsWidget::onAxesModified()
  460. {
  461. Q_D(ctkVTKScalarsToColorsWidget);
  462. vtkAxis* xAxis = d->CurrentControlPointsItem ?
  463. d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
  464. Q_ASSERT(xAxis);
  465. bool wasBlocking = d->XRangeSlider->blockSignals(true);
  466. d->XRangeSlider->setRange(xAxis->GetMinimumLimit(), xAxis->GetMaximumLimit());
  467. d->XRangeSlider->setValues(xAxis->GetMinimum(), xAxis->GetMaximum());
  468. d->XSpinBox->setRange(xAxis->GetMinimumLimit(), xAxis->GetMaximumLimit());
  469. d->XSpinBox->setSingleStep(
  470. ctk::closestPowerOfTen(xAxis->GetMaximumLimit() - xAxis->GetMinimumLimit()) / 100);
  471. d->XRangeSlider->blockSignals(wasBlocking);
  472. vtkAxis* yAxis = d->CurrentControlPointsItem ?
  473. d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
  474. Q_ASSERT(yAxis);
  475. wasBlocking = d->YRangeSlider->blockSignals(true);
  476. d->YRangeSlider->setRange(yAxis->GetMinimumLimit(), yAxis->GetMaximumLimit());
  477. d->YRangeSlider->setValues(yAxis->GetMinimum(), yAxis->GetMaximum());
  478. d->YRangeSlider->blockSignals(wasBlocking);
  479. }
  480. // ----------------------------------------------------------------------------
  481. void ctkVTKScalarsToColorsWidget::restorePalette()
  482. {
  483. Q_D(ctkVTKScalarsToColorsWidget);
  484. d->XSpinBox->setPalette(this->palette());
  485. }