NorMIT-nav  22.09
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxMeshInfoWidget.h"
12 
13 #include <QVBoxLayout>
14 #include "cxImage.h"
15 
16 #include "cxDoubleProperty.h"
20 #include "cxMeshHelpers.h"
21 #include "cxHelperWidgets.h"
22 #include "cxColorProperty.h"
23 #include "cxDataLocations.h"
24 #include "cxDataInterface.h"
25 #include "cxDataSelectWidget.h"
27 #include "vtkPolyDataNormals.h"
28 
29 #include "cxPatientModelService.h"
30 #include "cxLogger.h"
31 #include "cxProfile.h"
32 #include "cxVisServices.h"
34 #include "cxMeshGlyphsWidget.h"
35 #include "cxMeshPropertiesWidget.h"
36 #include "cxMeshTextureWidget.h"
37 
38 namespace cx
39 {
40 
42  BaseWidget(parent, "active_mesh_widget", "Mesh Properties")
43 {
44  this->setToolTip("Mesh properties");
45 
46  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), Mesh::getTypeName());
47  activeMeshProperty->setValueName("Active Mesh");
48 
49  QVBoxLayout* layout = new QVBoxLayout(this);
50  // layout->setMargin(0);
51  // layout->setSpacing(0);
52  layout->addWidget(new DataSelectWidget(services->view(), services->patient(), this, activeMeshProperty));
53  layout->addWidget(new AllMeshPropertiesWidget(activeMeshProperty, services, this));
54 }
55 
56 //---------------------------------------------------------
57 //---------------------------------------------------------
58 
60  TabbedWidget(parent, "all_mesh_tabs_widget", "Mesh Properties"),
61  mMeshSelector(mesh)
62 {
63  this->setToolTip("Mesh properties");
64 
65  this->addTab(new MeshInfoWidget(mesh, services->patient(), services->view(), services->file(), this), "Info");
66  this->addTab(new MeshPropertiesWidget(mesh, services->patient(), services->view(), this), "Properties");
67  this->addTab(new MeshTextureWidget(mesh, services->patient(), services->view(), this), "Texture");
68  this->addTab(new SelectClippersForMeshWidget(services, this), "Clip");
69  this->addTab(new MeshGlyphsWidget(mesh, services->patient(), services->view(), this), "Glyph");
70 
71 }
72 
73 //---------------------------------------------------------
74 //---------------------------------------------------------
75 
76 MeshInfoWidget::MeshInfoWidget(SelectDataStringPropertyBasePtr meshSelector,
77  PatientModelServicePtr patientModelService,
78  ViewServicePtr viewService,
79  FileManagerServicePtr fileManager,
80  QWidget* parent) :
81  InfoWidget(parent, "mesh_info_widget", "Mesh Properties"),
82  mPatientModelService(patientModelService),
83  mViewService(viewService),
84  mFileManagerService(fileManager),
85  mMeshSelector(meshSelector)
86 {
87  connect(mMeshSelector.get(), &Property::changed, this, &MeshInfoWidget::meshSelectedSlot);
88  this->addWidgets();
89  this->meshSelectedSlot();
90 }
91 
93 {
94 }
95 
97 {
98  if (mMesh == mMeshSelector->getData())
99  return;
100 
101  if(mMesh)
102  {
103  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
104  }
105 
106  mMesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
107 
108  if (!mMesh)
109  {
110  mParentFrameAdapter->setData(mMesh);
111  mNameAdapter->setData(mMesh);
112  mUidAdapter->setData(mMesh);
113  return;
114  }
115 
116  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
117 
118  mParentFrameAdapter->setData(mMesh);
119  mNameAdapter->setData(mMesh);
120  mUidAdapter->setData(mMesh);
121 
122  std::map<std::string, std::string> info = getDisplayFriendlyInfo(mMesh);
123  this->populateTableWidget(info);
124 }
125 
127 {
128  if(!mMesh)
129  return;
130  DataPtr parent = mPatientModelService->getData(mMesh->getParentSpace());
131  if (!parent)
132  return;
133  mMesh->get_rMd_History()->setRegistration(parent->get_rMd());
134  report("Assigned rMd from volume [" + parent->getName() + "] to surface [" + mMesh->getName() + "]");
135 }
136 
138 {
139  if(!mMesh)
140  return;
141 
142  vtkPolyDataNormalsPtr normals = vtkPolyDataNormalsPtr::New();
143  normals->SetInputData(mMesh->getVtkPolyData());
144  normals->Update();
145  mMesh->setVtkPolyData(normals->GetOutput());
146 
147  QString outputBasePath = mPatientModelService->getActivePatientFolder();
148  mMesh->save(outputBasePath, mFileManagerService);
149 }
150 
152 {
153  if(!mMesh)
154  return;
155 }
156 
157 void MeshInfoWidget::showEvent(QShowEvent* event)
158 {
159  QWidget::showEvent(event);
160 }
161 
162 void MeshInfoWidget::hideEvent(QCloseEvent* event)
163 {
164  QWidget::closeEvent(event);
165 }
166 
167 void MeshInfoWidget::addWidgets()
168 {
169  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
170 
171  QPushButton* importTransformButton = new QPushButton("Import Transform from Parent", this);
172  importTransformButton->setToolTip("Replace data transform with that of the parent data.");
173  connect(importTransformButton, SIGNAL(clicked()), this, SLOT(importTransformSlot()));
174 
175  QPushButton* addNormalsButton = new QPushButton("Generate Normals", this);
176  addNormalsButton->setToolTip("Generate surface normals and add to model.\nThis usually gives a smoother appearance.");
177  connect(addNormalsButton, SIGNAL(clicked()), this, SLOT(generateNormalsSlot()));
178 
179  mUidAdapter = StringPropertyDataUidEditable::New();
180  mNameAdapter = StringPropertyDataNameEditable::New();
181  mParentFrameAdapter = StringPropertyParentFrame::New(mPatientModelService);
182 
183  int row = 1;
184 
185  new LabeledLineEditWidget(this, mUidAdapter, gridLayout, row++);
186  new LabeledLineEditWidget(this, mNameAdapter, gridLayout, row++);
187  new LabeledComboBoxWidget(this, mParentFrameAdapter, gridLayout, row++);
188  gridLayout->addWidget(mTableWidget, row++, 0, 1, 2);
189  gridLayout->addWidget(importTransformButton, row++, 0, 1, 2);
190  gridLayout->addWidget(addNormalsButton, row++, 0, 1, 2);
191 
192  this->addStretch();
193 }
194 
195 
196 
197 }//end namespace cx
cx::LabeledComboBoxWidget
Composite widget for string selection.
Definition: cxLabeledComboBoxWidget.h:36
cx::MeshTextureWidget
Definition: cxMeshTextureWidget.h:21
vtkPolyDataNormalsPtr
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
Definition: vtkForwardDeclarations.h:113
cxLogger.h
cxMeshGlyphsWidget.h
cx::InfoWidget::mTableWidget
QTableWidget * mTableWidget
Definition: cxInfoWidget.h:48
cx::TabbedWidget::addTab
void addTab(BaseWidget *newTab, QString newTabName)
Definition: cxTabbedWidget.cpp:37
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::InfoWidget::populateTableWidget
void populateTableWidget(std::map< std::string, std::string > &info)
Definition: cxInfoWidget.cpp:40
cx::StringPropertyActiveData::New
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Definition: cxSelectDataStringProperty.h:28
cx::getDisplayFriendlyInfo
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
Definition: cxMeshHelpers.cpp:72
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cxImage.h
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::MeshInfoWidget
Widget for displaying information about meshes.
Definition: cxMeshInfoWidget.h:62
cx::report
void report(QString msg)
Definition: cxLogger.cpp:69
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cxLabeledComboBoxWidget.h
cx::StringPropertyActiveDataPtr
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr
Definition: cxSelectDataStringProperty.h:18
cx::StringPropertyParentFrame::New
static StringPropertyParentFramePtr New(PatientModelServicePtr patientModelService)
Definition: cxDataInterface.h:149
cxDoubleProperty.h
cx::MeshGlyphsWidget
Widget for displaying glyps information about meshes.
Definition: cxMeshGlyphsWidget.h:37
cx::FileManagerServicePtr
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
Definition: cxLogicManager.h:31
cxHelperWidgets.h
cx::TabbedWidget
Interface for making widgets with a hierarchy of tabs.
Definition: cxTabbedWidget.h:34
cx::MeshInfoWidget::showEvent
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
Definition: cxMeshInfoWidget.cpp:157
cx::AllMeshPropertiesWidget
Definition: cxMeshInfoWidget.h:38
cxMeshInfoWidget.h
cx::Mesh::getTypeName
static QString getTypeName()
Definition: cxMesh.h:67
cx::SelectClippersForMeshWidget
Definition: cxSelectClippersForDataWidget.h:67
cxDataInterface.h
cx::StringPropertyDataNameEditable::New
static StringPropertyDataNameEditablePtr New()
Definition: cxDataInterface.h:199
cx::MeshPtr
boost::shared_ptr< class Mesh > MeshPtr
Definition: cxForwardDeclarations.h:48
cxProfile.h
cx::MeshInfoWidget::importTransformSlot
void importTransformSlot()
Definition: cxMeshInfoWidget.cpp:126
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::MeshPropertiesWidget
Widget for displaying glyps information about meshes.
Definition: cxMeshPropertiesWidget.h:38
cx::ViewServicePtr
boost::shared_ptr< class ViewService > ViewServicePtr
Definition: cxLogicManager.h:28
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cxPatientModelService.h
cx::ActiveMeshPropertiesWidget::ActiveMeshPropertiesWidget
ActiveMeshPropertiesWidget(VisServicesPtr services, QWidget *parent)
Definition: cxMeshInfoWidget.cpp:41
cx::InfoWidget::gridLayout
QGridLayout * gridLayout
Definition: cxInfoWidget.h:47
cx::LabeledLineEditWidget
Composite widget for string edit.
Definition: cxLabeledLineEditWidget.h:35
cx::MeshInfoWidget::meshSelectedSlot
void meshSelectedSlot()
Definition: cxMeshInfoWidget.cpp:96
cxRegistrationTransform.h
cx::InfoWidget
Definition: cxInfoWidget.h:34
cxMeshTextureWidget.h
cx::StringPropertyDataUidEditable::New
static StringPropertyDataUidEditablePtr New()
Definition: cxDataInterface.h:226
cxMeshHelpers.h
cx::InfoWidget::addStretch
void addStretch()
Definition: cxInfoWidget.cpp:35
cxDataLocations.h
cxDataSelectWidget.h
cxSelectClippersForDataWidget.h
cx::MeshInfoWidget::generateNormalsSlot
void generateNormalsSlot()
Definition: cxMeshInfoWidget.cpp:137
cxLabeledLineEditWidget.h
cxMeshPropertiesWidget.h
cxSelectDataStringProperty.h
cx::DataSelectWidget
Definition: cxDataSelectWidget.h:38
cx::AllMeshPropertiesWidget::AllMeshPropertiesWidget
AllMeshPropertiesWidget(SelectDataStringPropertyBasePtr mesh, VisServicesPtr services, QWidget *parent)
Definition: cxMeshInfoWidget.cpp:59
cx::MeshInfoWidget::~MeshInfoWidget
virtual ~MeshInfoWidget()
Definition: cxMeshInfoWidget.cpp:92
cxColorProperty.h
cx::MeshInfoWidget::meshChangedSlot
void meshChangedSlot()
Definition: cxMeshInfoWidget.cpp:151
cx::SelectDataStringPropertyBasePtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
Definition: cxMeshGlyphsWidget.h:26
cx::MeshInfoWidget::hideEvent
virtual void hideEvent(QCloseEvent *event)
disconnects stuff
Definition: cxMeshInfoWidget.cpp:162
cxVisServices.h