ctkVTKPropertyWidget.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. // CTK includes
  17. #include "ctkVTKPropertyWidget.h"
  18. #include "ui_ctkVTKPropertyWidget.h"
  19. // VTK includes
  20. #include <vtkSmartPointer.h>
  21. #include <vtkProperty.h>
  22. //-----------------------------------------------------------------------------
  23. class ctkVTKPropertyWidgetPrivate: public Ui_ctkVTKPropertyWidget
  24. {
  25. Q_DECLARE_PUBLIC(ctkVTKPropertyWidget);
  26. protected:
  27. ctkVTKPropertyWidget* const q_ptr;
  28. public:
  29. ctkVTKPropertyWidgetPrivate(ctkVTKPropertyWidget& object);
  30. void setupUi(QWidget *widget);
  31. vtkSmartPointer<vtkProperty> Property;
  32. };
  33. //-----------------------------------------------------------------------------
  34. ctkVTKPropertyWidgetPrivate::ctkVTKPropertyWidgetPrivate(ctkVTKPropertyWidget& object)
  35. : q_ptr(&object)
  36. {
  37. }
  38. //-----------------------------------------------------------------------------
  39. void ctkVTKPropertyWidgetPrivate::setupUi(QWidget* widget)
  40. {
  41. Q_Q(ctkVTKPropertyWidget);
  42. this->Ui_ctkVTKPropertyWidget::setupUi(widget);
  43. q->connect(this->RepresentationComboBox, SIGNAL(currentIndexChanged(int)),
  44. q, SLOT(setRepresentation(int)));
  45. q->connect(this->PointSizeSliderWidget, SIGNAL(valueChanged(double)),
  46. q, SLOT(setPointSize(double)));
  47. q->connect(this->LineWidthSliderWidget, SIGNAL(valueChanged(double)),
  48. q, SLOT(setLineWidth(double)));
  49. q->connect(this->FrontfaceCullingCheckBox, SIGNAL(toggled(bool)),
  50. q, SLOT(setFrontfaceCulling(bool)));
  51. q->connect(this->BackfaceCullingCheckBox, SIGNAL(toggled(bool)),
  52. q, SLOT(setBackfaceCulling(bool)));
  53. q->connect(this->ColorPickerButton, SIGNAL(colorChanged(QColor)),
  54. q, SLOT(setColor(QColor)));
  55. q->connect(this->OpacitySliderWidget, SIGNAL(valueChanged(double)),
  56. q, SLOT(setOpacity(double)));
  57. q->connect(this->EdgeVisibilityCheckBox, SIGNAL(toggled(bool)),
  58. q, SLOT(setEdgeVisibility(bool)));
  59. q->connect(this->EdgeColorPickerButton, SIGNAL(colorChanged(QColor)),
  60. q, SLOT(setEdgeColor(QColor)));
  61. q->connect(this->LightingCheckBox, SIGNAL(toggled(bool)),
  62. q, SLOT(setLighting(bool)));
  63. q->connect(this->InterpolationComboBox, SIGNAL(currentIndexChanged(int)),
  64. q, SLOT(setInterpolation(int)));
  65. q->connect(this->ShadingCheckBox, SIGNAL(toggled(bool)),
  66. q, SLOT(setShading(bool)));
  67. }
  68. //-----------------------------------------------------------------------------
  69. ctkVTKPropertyWidget::~ctkVTKPropertyWidget()
  70. {
  71. }
  72. //-----------------------------------------------------------------------------
  73. ctkVTKPropertyWidget::ctkVTKPropertyWidget(QWidget* parentWidget)
  74. : Superclass(parentWidget)
  75. , d_ptr(new ctkVTKPropertyWidgetPrivate(*this))
  76. {
  77. Q_D(ctkVTKPropertyWidget);
  78. d->setupUi(this);
  79. vtkSmartPointer<vtkProperty> property = vtkSmartPointer<vtkProperty>::New();
  80. this->setProperty(property);
  81. }
  82. //-----------------------------------------------------------------------------
  83. ctkVTKPropertyWidget::ctkVTKPropertyWidget(vtkProperty* property, QWidget* parentWidget)
  84. : Superclass(parentWidget)
  85. , d_ptr(new ctkVTKPropertyWidgetPrivate(*this))
  86. {
  87. Q_D(ctkVTKPropertyWidget);
  88. d->setupUi(this);
  89. this->setProperty(property);
  90. }
  91. //-----------------------------------------------------------------------------
  92. void ctkVTKPropertyWidget::setProperty(vtkProperty* property)
  93. {
  94. Q_D(ctkVTKPropertyWidget);
  95. if (d->Property.GetPointer() == property)
  96. {
  97. return;
  98. }
  99. qvtkReconnect(d->Property, property, vtkCommand::ModifiedEvent,
  100. this, SLOT(updateWidgetFromProperty()));
  101. d->Property = property;
  102. d->MaterialPropertyWidget->setProperty(property);
  103. this->updateWidgetFromProperty();
  104. }
  105. //-----------------------------------------------------------------------------
  106. vtkProperty* ctkVTKPropertyWidget::property()const
  107. {
  108. Q_D(const ctkVTKPropertyWidget);
  109. return d->Property.GetPointer();
  110. }
  111. //-----------------------------------------------------------------------------
  112. ctkVTKPropertyWidget::GroupsState ctkVTKPropertyWidget::groupsState()const
  113. {
  114. Q_D(const ctkVTKPropertyWidget);
  115. ctkVTKPropertyWidget::GroupsState state = 0;
  116. ctkVTKPropertyWidget* constThis = const_cast<ctkVTKPropertyWidget*>(this);
  117. if (d->RepresentationCollapsibleGroupBox->isVisibleTo(constThis) )
  118. {
  119. state |= ctkVTKPropertyWidget::RepresentationVisible;
  120. }
  121. if (d->RepresentationCollapsibleGroupBox->collapsed())
  122. {
  123. state |= ctkVTKPropertyWidget::RepresentationCollapsed;
  124. }
  125. if (d->ColorCollapsibleGroupBox->isVisibleTo(constThis) )
  126. {
  127. state |= ctkVTKPropertyWidget::ColorVisible;
  128. }
  129. if (d->ColorCollapsibleGroupBox->collapsed())
  130. {
  131. state |= ctkVTKPropertyWidget::ColorCollapsed;
  132. }
  133. if (d->LightingCollapsibleGroupBox->isVisibleTo(constThis) )
  134. {
  135. state |= ctkVTKPropertyWidget::LightingVisible;
  136. }
  137. if (d->LightingCollapsibleGroupBox->collapsed())
  138. {
  139. state |= ctkVTKPropertyWidget::LightingCollapsed;
  140. }
  141. if (d->MaterialCollapsibleGroupBox->isVisibleTo(constThis) )
  142. {
  143. state |= ctkVTKPropertyWidget::MaterialVisible;
  144. }
  145. if (d->MaterialCollapsibleGroupBox->collapsed())
  146. {
  147. state |= ctkVTKPropertyWidget::MaterialCollapsed;
  148. }
  149. return state;
  150. }
  151. //-----------------------------------------------------------------------------
  152. void ctkVTKPropertyWidget::setGroupsState(ctkVTKPropertyWidget::GroupsState state)
  153. {
  154. Q_D(ctkVTKPropertyWidget);
  155. d->RepresentationCollapsibleGroupBox->setVisible(
  156. state & ctkVTKPropertyWidget::RepresentationVisible);
  157. d->RepresentationCollapsibleGroupBox->setCollapsed(
  158. state & ctkVTKPropertyWidget::RepresentationCollapsed);
  159. d->ColorCollapsibleGroupBox->setVisible(
  160. state & ctkVTKPropertyWidget::ColorVisible);
  161. d->ColorCollapsibleGroupBox->setCollapsed(
  162. state & ctkVTKPropertyWidget::ColorCollapsed);
  163. d->LightingCollapsibleGroupBox->setVisible(
  164. state & ctkVTKPropertyWidget::LightingVisible);
  165. d->LightingCollapsibleGroupBox->setCollapsed(
  166. state & ctkVTKPropertyWidget::LightingCollapsed);
  167. d->MaterialCollapsibleGroupBox->setVisible(
  168. state & ctkVTKPropertyWidget::MaterialVisible);
  169. d->MaterialCollapsibleGroupBox->setCollapsed(
  170. state & ctkVTKPropertyWidget::MaterialCollapsed);
  171. }
  172. //-----------------------------------------------------------------------------
  173. ctkColorPickerButton::ColorDialogOptions ctkVTKPropertyWidget
  174. ::colorDialogOptions()const
  175. {
  176. Q_D(const ctkVTKPropertyWidget);
  177. return d->ColorPickerButton->dialogOptions();
  178. }
  179. //-----------------------------------------------------------------------------
  180. void ctkVTKPropertyWidget
  181. ::setColorDialogOptions(ctkColorPickerButton::ColorDialogOptions options)
  182. {
  183. Q_D(ctkVTKPropertyWidget);
  184. d->ColorPickerButton->setDialogOptions(options);
  185. d->EdgeColorPickerButton->setDialogOptions(options);
  186. }
  187. //-----------------------------------------------------------------------------
  188. void ctkVTKPropertyWidget::updateWidgetFromProperty()
  189. {
  190. Q_D(ctkVTKPropertyWidget);
  191. this->setEnabled(d->Property.GetPointer() != 0);
  192. if (d->Property.GetPointer() == 0)
  193. {
  194. return;
  195. }
  196. // Warning: Valid as long as the representation matches the combobox indexes.
  197. d->RepresentationComboBox->setCurrentIndex( d->Property->GetRepresentation() );
  198. d->PointSizeSliderWidget->setValue( d->Property->GetPointSize() );
  199. d->LineWidthSliderWidget->setValue( d->Property->GetLineWidth() );
  200. d->FrontfaceCullingCheckBox->setChecked( d->Property->GetFrontfaceCulling() );
  201. d->BackfaceCullingCheckBox->setChecked( d->Property->GetBackfaceCulling() );
  202. double* c = d->Property->GetColor();
  203. d->ColorPickerButton->setColor(
  204. QColor::fromRgbF(qMin(c[0],1.), qMin(c[1], 1.), qMin(c[2],1.)));
  205. d->OpacitySliderWidget->setValue( d->Property->GetOpacity() );
  206. d->EdgeVisibilityCheckBox->setChecked( d->Property->GetEdgeVisibility() );
  207. double* ec = d->Property->GetEdgeColor();
  208. d->EdgeColorPickerButton->setColor(
  209. QColor::fromRgbF(qMin(ec[0],1.), qMin(ec[1], 1.), qMin(ec[2],1.)));
  210. d->LightingCheckBox->setChecked( d->Property->GetLighting() );
  211. d->InterpolationComboBox->setCurrentIndex( d->Property->GetInterpolation() );
  212. d->ShadingCheckBox->setChecked( d->Property->GetShading() );
  213. }
  214. // --------------------------------------------------------------------------
  215. int ctkVTKPropertyWidget::representation()const
  216. {
  217. Q_D(const ctkVTKPropertyWidget);
  218. return d->RepresentationComboBox->currentIndex();
  219. }
  220. // --------------------------------------------------------------------------
  221. double ctkVTKPropertyWidget::pointSize()const
  222. {
  223. Q_D(const ctkVTKPropertyWidget);
  224. return d->PointSizeSliderWidget->value();
  225. }
  226. // --------------------------------------------------------------------------
  227. double ctkVTKPropertyWidget::lineWidth()const
  228. {
  229. Q_D(const ctkVTKPropertyWidget);
  230. return d->LineWidthSliderWidget->value();
  231. }
  232. // --------------------------------------------------------------------------
  233. bool ctkVTKPropertyWidget::frontfaceCulling()const
  234. {
  235. Q_D(const ctkVTKPropertyWidget);
  236. return d->FrontfaceCullingCheckBox->isChecked();
  237. }
  238. // --------------------------------------------------------------------------
  239. bool ctkVTKPropertyWidget::backfaceCulling()const
  240. {
  241. Q_D(const ctkVTKPropertyWidget);
  242. return d->BackfaceCullingCheckBox->isChecked();
  243. }
  244. // --------------------------------------------------------------------------
  245. QColor ctkVTKPropertyWidget::color()const
  246. {
  247. Q_D(const ctkVTKPropertyWidget);
  248. return d->ColorPickerButton->color();
  249. }
  250. // --------------------------------------------------------------------------
  251. double ctkVTKPropertyWidget::opacity()const
  252. {
  253. Q_D(const ctkVTKPropertyWidget);
  254. return d->OpacitySliderWidget->value();
  255. }
  256. // --------------------------------------------------------------------------
  257. bool ctkVTKPropertyWidget::edgeVisibility()const
  258. {
  259. Q_D(const ctkVTKPropertyWidget);
  260. return d->EdgeVisibilityCheckBox->isChecked();
  261. }
  262. // --------------------------------------------------------------------------
  263. QColor ctkVTKPropertyWidget::edgeColor()const
  264. {
  265. Q_D(const ctkVTKPropertyWidget);
  266. return d->EdgeColorPickerButton->color();
  267. }
  268. // --------------------------------------------------------------------------
  269. bool ctkVTKPropertyWidget::lighting()const
  270. {
  271. Q_D(const ctkVTKPropertyWidget);
  272. return d->LightingCheckBox->isChecked();
  273. }
  274. // --------------------------------------------------------------------------
  275. int ctkVTKPropertyWidget::interpolation()const
  276. {
  277. Q_D(const ctkVTKPropertyWidget);
  278. return d->InterpolationComboBox->currentIndex();
  279. }
  280. // --------------------------------------------------------------------------
  281. bool ctkVTKPropertyWidget::shading()const
  282. {
  283. Q_D(const ctkVTKPropertyWidget);
  284. return d->ShadingCheckBox->isChecked();
  285. }
  286. // --------------------------------------------------------------------------
  287. void ctkVTKPropertyWidget::setRepresentation(int newRepresentation)
  288. {
  289. Q_D(ctkVTKPropertyWidget);
  290. if (d->Property.GetPointer() != 0)
  291. {
  292. d->Property->SetRepresentation(newRepresentation);
  293. }
  294. }
  295. // --------------------------------------------------------------------------
  296. void ctkVTKPropertyWidget::setPointSize(double newPointSize)
  297. {
  298. Q_D(ctkVTKPropertyWidget);
  299. if (d->Property.GetPointer() != 0)
  300. {
  301. d->Property->SetPointSize(newPointSize);
  302. }
  303. }
  304. // --------------------------------------------------------------------------
  305. void ctkVTKPropertyWidget::setLineWidth(double newLineWidth)
  306. {
  307. Q_D(ctkVTKPropertyWidget);
  308. if (d->Property.GetPointer() != 0)
  309. {
  310. d->Property->SetLineWidth(newLineWidth);
  311. }
  312. }
  313. // --------------------------------------------------------------------------
  314. void ctkVTKPropertyWidget::setFrontfaceCulling(bool newFrontfaceCulling)
  315. {
  316. Q_D(ctkVTKPropertyWidget);
  317. if (d->Property.GetPointer() != 0)
  318. {
  319. d->Property->SetFrontfaceCulling(newFrontfaceCulling);
  320. }
  321. }
  322. // --------------------------------------------------------------------------
  323. void ctkVTKPropertyWidget::setBackfaceCulling(bool newBackfaceCulling)
  324. {
  325. Q_D(ctkVTKPropertyWidget);
  326. if (d->Property.GetPointer() != 0)
  327. {
  328. d->Property->SetBackfaceCulling(newBackfaceCulling);
  329. }
  330. }
  331. // --------------------------------------------------------------------------
  332. void ctkVTKPropertyWidget::setColor(const QColor& newColor)
  333. {
  334. Q_D(ctkVTKPropertyWidget);
  335. d->MaterialPropertyWidget->setColor(newColor);
  336. }
  337. // --------------------------------------------------------------------------
  338. void ctkVTKPropertyWidget::setOpacity(double newOpacity)
  339. {
  340. Q_D(ctkVTKPropertyWidget);
  341. if (d->Property.GetPointer() != 0)
  342. {
  343. d->Property->SetOpacity(newOpacity);
  344. }
  345. }
  346. // --------------------------------------------------------------------------
  347. void ctkVTKPropertyWidget::setEdgeVisibility(bool newEdgeVisibility)
  348. {
  349. Q_D(ctkVTKPropertyWidget);
  350. if (d->Property.GetPointer() != 0)
  351. {
  352. d->Property->SetEdgeVisibility(newEdgeVisibility);
  353. }
  354. }
  355. // --------------------------------------------------------------------------
  356. void ctkVTKPropertyWidget::setEdgeColor(const QColor& newColor)
  357. {
  358. Q_D(ctkVTKPropertyWidget);
  359. if (d->Property.GetPointer() != 0)
  360. {
  361. d->Property->SetEdgeColor(
  362. newColor.redF(), newColor.greenF(), newColor.blueF());
  363. }
  364. }
  365. // --------------------------------------------------------------------------
  366. void ctkVTKPropertyWidget::setLighting(bool newLighting)
  367. {
  368. Q_D(ctkVTKPropertyWidget);
  369. if (d->Property.GetPointer() != 0)
  370. {
  371. d->Property->SetLighting(newLighting);
  372. }
  373. }
  374. // --------------------------------------------------------------------------
  375. void ctkVTKPropertyWidget::setInterpolation(int newInterpolation)
  376. {
  377. Q_D(ctkVTKPropertyWidget);
  378. if (d->Property.GetPointer() != 0)
  379. {
  380. d->Property->SetInterpolation(newInterpolation);
  381. }
  382. }
  383. // --------------------------------------------------------------------------
  384. void ctkVTKPropertyWidget::setShading(bool newShading)
  385. {
  386. Q_D(ctkVTKPropertyWidget);
  387. if (d->Property.GetPointer() != 0)
  388. {
  389. d->Property->SetShading(newShading);
  390. }
  391. }