Fraxinus  2023.01.05-dev+develop.0da12
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
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
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
static QString getTypeName()
Definition: cxMesh.h:67
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.