Fraxinus  18.10
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");
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(), 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  QWidget* parent) :
80  InfoWidget(parent, "mesh_info_widget", "Mesh Properties"),
81  mPatientModelService(patientModelService),
82  mViewService(viewService),
83  mMeshSelector(meshSelector)
84 {
85  connect(mMeshSelector.get(), &Property::changed, this, &MeshInfoWidget::meshSelectedSlot);
86  this->addWidgets();
87  this->meshSelectedSlot();
88 }
89 
91 {
92 }
93 
95 {
96  if (mMesh == mMeshSelector->getData())
97  return;
98 
99  if(mMesh)
100  {
101  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
102  }
103 
104  mMesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
105 
106  if (!mMesh)
107  {
108  mParentFrameAdapter->setData(mMesh);
109  mNameAdapter->setData(mMesh);
110  mUidAdapter->setData(mMesh);
111  return;
112  }
113 
114  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
115 
116  mParentFrameAdapter->setData(mMesh);
117  mNameAdapter->setData(mMesh);
118  mUidAdapter->setData(mMesh);
119 
120  std::map<std::string, std::string> info = getDisplayFriendlyInfo(mMesh);
121  this->populateTableWidget(info);
122 }
123 
125 {
126  if(!mMesh)
127  return;
128  DataPtr parent = mPatientModelService->getData(mMesh->getParentSpace());
129  if (!parent)
130  return;
131  mMesh->get_rMd_History()->setRegistration(parent->get_rMd());
132  report("Assigned rMd from volume [" + parent->getName() + "] to surface [" + mMesh->getName() + "]");
133 }
134 
136 {
137  if(!mMesh)
138  return;
139 
140  vtkPolyDataNormalsPtr normals = vtkPolyDataNormalsPtr::New();
141  normals->SetInputData(mMesh->getVtkPolyData());
142  normals->Update();
143  mMesh->setVtkPolyData(normals->GetOutput());
144 
145  QString outputBasePath = mPatientModelService->getActivePatientFolder();
146  mMesh->save(outputBasePath);
147 }
148 
150 {
151  if(!mMesh)
152  return;
153 }
154 
155 void MeshInfoWidget::showEvent(QShowEvent* event)
156 {
157  QWidget::showEvent(event);
158 }
159 
160 void MeshInfoWidget::hideEvent(QCloseEvent* event)
161 {
162  QWidget::closeEvent(event);
163 }
164 
165 void MeshInfoWidget::addWidgets()
166 {
167  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
168 
169  QPushButton* importTransformButton = new QPushButton("Import Transform from Parent", this);
170  importTransformButton->setToolTip("Replace data transform with that of the parent data.");
171  connect(importTransformButton, SIGNAL(clicked()), this, SLOT(importTransformSlot()));
172 
173  QPushButton* addNormalsButton = new QPushButton("Generate Normals", this);
174  addNormalsButton->setToolTip("Generate surface normals and add to model.\nThis usually gives a smoother appearance.");
175  connect(addNormalsButton, SIGNAL(clicked()), this, SLOT(generateNormalsSlot()));
176 
177  mUidAdapter = StringPropertyDataUidEditable::New();
178  mNameAdapter = StringPropertyDataNameEditable::New();
179  mParentFrameAdapter = StringPropertyParentFrame::New(mPatientModelService);
180 
181  int row = 1;
182 
183  new LabeledLineEditWidget(this, mUidAdapter, gridLayout, row++);
184  new LabeledLineEditWidget(this, mNameAdapter, gridLayout, row++);
185  new LabeledComboBoxWidget(this, mParentFrameAdapter, gridLayout, row++);
186  gridLayout->addWidget(mTableWidget, row++, 0, 1, 2);
187  gridLayout->addWidget(importTransformButton, row++, 0, 1, 2);
188  gridLayout->addWidget(addNormalsButton, row++, 0, 1, 2);
189 
190  this->addStretch();
191 }
192 
193 
194 
195 }//end namespace cx
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
static StringPropertyParentFramePtr New(PatientModelServicePtr patientModelService)
QTableWidget * mTableWidget
Definition: cxInfoWidget.h:48
A mesh data set.
Definition: cxMesh.h:45
AllMeshPropertiesWidget(SelectDataStringPropertyBasePtr mesh, VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
ActiveMeshPropertiesWidget(VisServicesPtr services, QWidget *parent)
virtual void hideEvent(QCloseEvent *event)
disconnects stuff
void populateTableWidget(std::map< std::string, std::string > &info)
Widget for displaying glyps information about meshes.
boost::shared_ptr< class ViewService > ViewServicePtr
Composite widget for string selection.
static StringPropertyDataUidEditablePtr New()
QGridLayout * gridLayout
Definition: cxInfoWidget.h:47
Composite widget for string edit.
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.
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
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
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
void report(QString msg)
Definition: cxLogger.cpp:69
Widget for displaying glyps information about meshes.
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr
Namespace for all CustusX production code.