Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxMeshInfoWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 #include "cxMeshInfoWidget.h"
33 
34 #include <QVBoxLayout>
35 #include "cxImage.h"
36 
37 #include "cxDoubleProperty.h"
41 #include "cxMeshHelpers.h"
42 #include "cxHelperWidgets.h"
43 #include "cxColorProperty.h"
44 #include "cxDataLocations.h"
45 #include "cxDataInterface.h"
46 #include "cxDataSelectWidget.h"
48 
49 #include "cxPatientModelService.h"
50 #include "cxLogger.h"
51 #include "cxProfile.h"
52 #include "cxVisServices.h"
54 
55 namespace cx
56 {
58  TabbedWidget(parent, "MeshInfoWidget", "Mesh Properties")
59 {
60  this->setToolTip("Mesh properties");
61 
62  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), "mesh");
63  activeMeshProperty->setValueName("Active Mesh");
64 
65  this->insertWidgetAtTop(new DataSelectWidget(services->view(), services->patient(), this, activeMeshProperty));
66 
67  this->addTab(new MeshInfoWidget(activeMeshProperty, services->patient(), services->view(), this), "Info");
68  this->addTab(new SelectClippersForMeshWidget(services, this), "Clip");
69 }
70 
71 //<<<<<<< HEAD
72 //SelectedMeshInfoWidget::SelectedMeshInfoWidget(PatientModelServicePtr patientModelService, ViewServicePtr viewService, QWidget* parent) :
73 // BaseWidget(parent, "MeshInfoWidget", "Mesh Properties")
74 //{
75 // StringPropertySelectMeshPtr meshSelector = StringPropertySelectMesh::New(patientModelService);
76 // meshSelector->setValueName("Surface: ");
77 
78 // QVBoxLayout* layout = new QVBoxLayout(this);
79 // layout->setMargin(0);
80 // layout->addWidget(new DataSelectWidget(viewService, patientModelService, this, meshSelector));
81 
82 // MeshInfoWidget* info = new MeshInfoWidget(meshSelector, patientModelService, viewService, this);
83 // info->layout()->setMargin(0);
84 // layout->addWidget(info);
85 //}
86 
87 //SelectedMeshInfoWidget::~SelectedMeshInfoWidget()
88 //{
89 //}
90 
91 
92 
93 
94 
95 
96 
97 //---------------------------------------------------------
98 //---------------------------------------------------------
99 
100 MeshInfoWidget::MeshInfoWidget(SelectDataStringPropertyBasePtr meshSelector,
101  PatientModelServicePtr patientModelService,
103  QWidget* parent) :
104  InfoWidget(parent, "MeshCoreInfoWidget", "Mesh Properties"),
105  mPatientModelService(patientModelService),
106  mViewService(viewService),
107  mMeshSelector(meshSelector)
108 {
109  this->addWidgets();
110  this->meshSelectedSlot();
111 }
112 
114 {
115 }
116 
118 {
119  if(!mMesh)
120  return;
121  // Implement like TransferFunctionColorWidget::setColorSlot()
122  // to prevent crash problems
123  QTimer::singleShot(1, this, SLOT(setColorSlotDelayed()));
124 }
125 
127 {
128  if(!mMesh)
129  return;
130  mMesh->setColor(mColorAdapter->getValue());
131 }
132 
134 {
135  if (mMesh == mMeshSelector->getData())
136  return;
137 
138  if(mMesh)
139  {
140  mMesh->setVisSize((double) mVisSizeWidget->getValue());
141 // disconnect(mBackfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setBackfaceCullingSlot(bool)));
142 // disconnect(mFrontfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setFrontfaceCullingSlot(bool)));
143  disconnect(mGlyphVisualizationCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setShowGlyph(bool)));
144  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
145  }
146 
147  mMesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
148 
149  if (!mMesh)
150  {
151  mParentFrameAdapter->setData(mMesh);
152  mNameAdapter->setData(mMesh);
153  mUidAdapter->setData(mMesh);
154  mGlyphOrientationArrayAdapter->setData(mMesh);
155  mGlyphColorArrayAdapter->setData(mMesh);
156  mGlyphColorLUTAdapter->setData(mMesh);
157 
158  return;
159  }
160 
161 // mBackfaceCullingCheckBox->setChecked(mMesh->getBackfaceCulling());
162 // mFrontfaceCullingCheckBox->setChecked(mMesh->getFrontfaceCulling());
163  mGlyphVisualizationCheckBox->setChecked(mMesh->showGlyph());
164  mGlyphVisualizationCheckBox->setEnabled(mMesh->hasGlyph());
165  mVisSizeWidget->setValue(mMesh->getVisSize());
166 
167 // connect(mBackfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setBackfaceCullingSlot(bool)));
168 // connect(mFrontfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setFrontfaceCullingSlot(bool)));
169  connect(mGlyphVisualizationCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setShowGlyph(bool)));
170 
171  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
172 
173 
174  mParentFrameAdapter->setData(mMesh);
175  mNameAdapter->setData(mMesh);
176  mUidAdapter->setData(mMesh);
177  mColorAdapter->setValue(mMesh->getColor());
178  mGlyphOrientationArrayAdapter->setData(mMesh);
179  mGlyphColorArrayAdapter->setData(mMesh);
180  mGlyphColorLUTAdapter->setData(mMesh);
181 
182  std::map<std::string, std::string> info = getDisplayFriendlyInfo(mMesh);
183  this->populateTableWidget(info);
184 }
185 
187 {
188  if(!mMesh)
189  return;
190  DataPtr parent = mPatientModelService->getData(mMesh->getParentSpace());
191  if (!parent)
192  return;
193  mMesh->get_rMd_History()->setRegistration(parent->get_rMd());
194  report("Assigned rMd from volume [" + parent->getName() + "] to surface [" + mMesh->getName() + "]");
195 }
196 
198 {
199  if(!mMesh)
200  return;
201  mBackfaceCullingCheckBox->setChecked(mMesh->getBackfaceCulling());
202  mFrontfaceCullingCheckBox->setChecked(mMesh->getFrontfaceCulling());
203  mGlyphVisualizationCheckBox->setChecked(mMesh->showGlyph());
204  mGlyphVisualizationCheckBox->setEnabled(mMesh->hasGlyph());
205  mColorAdapter->setValue(mMesh->getColor());
206  mMesh->setVisSize((double) mVisSizeWidget->getValue());
207 }
208 
209 void MeshInfoWidget::showEvent(QShowEvent* event)
210 {
211  QWidget::showEvent(event);
212 }
213 
214 void MeshInfoWidget::hideEvent(QCloseEvent* event)
215 {
216  QWidget::closeEvent(event);
217 }
218 
219 void MeshInfoWidget::addWidgets()
220 {
221  connect(mMeshSelector.get(), &Property::changed, this, &MeshInfoWidget::meshSelectedSlot);
222 
223  XmlOptionFile options = profile()->getXmlSettings().descend("MeshInfoWidget");
224  QString uid("Color");
225  QString name("");
226  QString help("Color of the mesh.");
227  QColor color("red");
228 
229  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
230 
231  if(mesh)
232  color = mesh->getColor();
233 
234  mColorAdapter = ColorProperty::initialize(uid, name, help, color, options.getElement());
235  connect(mColorAdapter.get(), SIGNAL(changed()), this, SLOT(setColorSlot()));
236 
237  QPushButton* importTransformButton = new QPushButton("Import Transform from Parent", this);
238  importTransformButton->setToolTip("Replace data transform with that of the parent data.");
239  connect(importTransformButton, SIGNAL(clicked()), this, SLOT(importTransformSlot()));
240 
241  mUidAdapter = StringPropertyDataUidEditable::New();
242  mNameAdapter = StringPropertyDataNameEditable::New();
243  mParentFrameAdapter = StringPropertyParentFrame::New(mPatientModelService);
244  mGlyphOrientationArrayAdapter = StringPropertyGlyphOrientationArray::New(mPatientModelService);
245  mGlyphColorArrayAdapter = StringPropertyGlyphColorArray::New(mPatientModelService);
246  mGlyphColorLUTAdapter = StringPropertyGlyphLUT::New(mPatientModelService);
247 
248  QWidget* optionsWidget = new QWidget(this);
249  QHBoxLayout* optionsLayout = new QHBoxLayout(optionsWidget);
250  optionsLayout->setMargin(0);
251  mBackfaceCullingCheckBox = new QCheckBox("Backface culling");
252  mBackfaceCullingCheckBox->setToolTip("Set backface culling on. This makes transparent meshes work, but only draws outside mesh walls (eg. navigating inside meshes will not work).");
253  optionsLayout->addWidget(mBackfaceCullingCheckBox);
254  mFrontfaceCullingCheckBox = new QCheckBox("Frontface culling");
255  mFrontfaceCullingCheckBox->setToolTip("Set frontface culling on. Can be used to make transparent meshes work from inside the meshes.");
256  optionsLayout->addWidget(mFrontfaceCullingCheckBox);
257  optionsLayout->addWidget(sscCreateDataWidget(this, mColorAdapter));
258 
259  optionsLayout->addStretch(1);
260 
261  mVisSizeWidget= DoubleProperty::initialize("visSize", " ", "Visualization size",1, DoubleRange(1, 20, 1), 0);
262  mVisSizeWidget->setGuiRepresentation(DoublePropertyBase::grSLIDER);
263  connect(mVisSizeWidget.get(), &Property::changed, this, &MeshInfoWidget::meshChangedSlot);
264 
265  int gridGlyphLayoutRow = 1;
266  QWidget* glyphWidget = new QWidget(this);
267  QGridLayout* glyphLayout = new QGridLayout(glyphWidget);
268  glyphLayout->setMargin(0);
269  mGlyphVisualizationCheckBox = new QCheckBox("Enable glyph visualization");
270  mGlyphVisualizationCheckBox->setToolTip("Enable glyph visualization");
271  glyphLayout->addWidget(mGlyphVisualizationCheckBox, gridGlyphLayoutRow++,0);
272  new LabeledComboBoxWidget(this, mGlyphOrientationArrayAdapter,glyphLayout, gridGlyphLayoutRow++);
273  new LabeledComboBoxWidget(this, mGlyphColorArrayAdapter,glyphLayout, gridGlyphLayoutRow++);
274  new LabeledComboBoxWidget(this, mGlyphColorLUTAdapter,glyphLayout, gridGlyphLayoutRow++);
275 
276  int gridLayoutRow = 1;
277 
278  new LabeledLineEditWidget(this, mUidAdapter, gridLayout, gridLayoutRow++);
279  new LabeledLineEditWidget(this, mNameAdapter, gridLayout, gridLayoutRow++);
280  new LabeledComboBoxWidget(this, mParentFrameAdapter, gridLayout, gridLayoutRow++);
281 
282  gridLayout->addWidget(optionsWidget, gridLayoutRow++, 0, 1, 2);
283  gridLayout->addWidget(new QLabel("Visualization size:", this), gridLayoutRow, 0);
284  gridLayout->addWidget(createDataWidget(mViewService, mPatientModelService, this, mVisSizeWidget),gridLayoutRow++,1);
285  gridLayout->addWidget(glyphWidget, gridLayoutRow++, 0, 1, 2);
286  gridLayout->addWidget(mTableWidget, gridLayoutRow++, 0, 1, 2);
287  gridLayout->addWidget(importTransformButton, gridLayoutRow++, 0, 1, 2);
288 
289  this->addStretch();
290 }
291 
292 
293 
294 }//end namespace cx
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:176
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
static StringPropertyParentFramePtr New(PatientModelServicePtr patientModelService)
QTableWidget * mTableWidget
Definition: cxInfoWidget.h:69
A mesh data set.
Definition: cxMesh.h:61
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
ActiveMeshPropertiesWidget(VisServicesPtr services, QWidget *parent)
virtual void hideEvent(QCloseEvent *event)
disconnects stuff
void populateTableWidget(std::map< std::string, std::string > &info)
static StringPropertyGlyphLUTPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ViewService > ViewServicePtr
void insertWidgetAtTop(QWidget *newWidget)
Composite widget for string selection.
static StringPropertyGlyphColorArrayPtr New(PatientModelServicePtr patientModelService)
static StringPropertyDataUidEditablePtr New()
QGridLayout * gridLayout
Definition: cxInfoWidget.h:68
Composite widget for string edit.
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
void addTab(BaseWidget *newTab, QString newTabName)
static StringPropertyDataNameEditablePtr New()
Interface for making widgets with a hierarchy of tabs.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static StringPropertyGlyphOrientationArrayPtr New(PatientModelServicePtr patientModelService)
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
cxLogicManager_EXPORT ViewServicePtr viewService()
void report(QString msg)
Definition: cxLogger.cpp:90
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr
Helper class for xml files used to store ssc/cx data.
QColor getColor()
Get the color of the mesh (Values are range 0 - 255)
Definition: cxMesh.cpp:243