Fraxinus  17.12-rc1
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) 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 #include "vtkPolyDataNormals.h"
49 
50 #include "cxPatientModelService.h"
51 #include "cxLogger.h"
52 #include "cxProfile.h"
53 #include "cxVisServices.h"
55 #include "cxMeshGlyphsWidget.h"
56 #include "cxMeshPropertiesWidget.h"
57 #include "cxMeshTextureWidget.h"
58 
59 namespace cx
60 {
61 
63  BaseWidget(parent, "active_mesh_widget", "Mesh Properties")
64 {
65  this->setToolTip("Mesh properties");
66 
67  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), "mesh");
68  activeMeshProperty->setValueName("Active Mesh");
69 
70  QVBoxLayout* layout = new QVBoxLayout(this);
71  // layout->setMargin(0);
72  // layout->setSpacing(0);
73  layout->addWidget(new DataSelectWidget(services->view(), services->patient(), this, activeMeshProperty));
74  layout->addWidget(new AllMeshPropertiesWidget(activeMeshProperty, services, this));
75 }
76 
77 //---------------------------------------------------------
78 //---------------------------------------------------------
79 
81  TabbedWidget(parent, "all_mesh_tabs_widget", "Mesh Properties"),
82  mMeshSelector(mesh)
83 {
84  this->setToolTip("Mesh properties");
85 
86  this->addTab(new MeshInfoWidget(mesh, services->patient(), services->view(), this), "Info");
87  this->addTab(new MeshPropertiesWidget(mesh, services->patient(), services->view(), this), "Properties");
88  this->addTab(new MeshTextureWidget(mesh, services->patient(), services->view(), this), "Texture");
89  this->addTab(new SelectClippersForMeshWidget(services, this), "Clip");
90  this->addTab(new MeshGlyphsWidget(mesh, services->patient(), services->view(), this), "Glyph");
91 
92 }
93 
94 //---------------------------------------------------------
95 //---------------------------------------------------------
96 
97 MeshInfoWidget::MeshInfoWidget(SelectDataStringPropertyBasePtr meshSelector,
98  PatientModelServicePtr patientModelService,
99  ViewServicePtr viewService,
100  QWidget* parent) :
101  InfoWidget(parent, "mesh_info_widget", "Mesh Properties"),
102  mPatientModelService(patientModelService),
103  mViewService(viewService),
104  mMeshSelector(meshSelector)
105 {
106  connect(mMeshSelector.get(), &Property::changed, this, &MeshInfoWidget::meshSelectedSlot);
107  this->addWidgets();
108  this->meshSelectedSlot();
109 }
110 
112 {
113 }
114 
116 {
117  if (mMesh == mMeshSelector->getData())
118  return;
119 
120  if(mMesh)
121  {
122  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
123  }
124 
125  mMesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
126 
127  if (!mMesh)
128  {
129  mParentFrameAdapter->setData(mMesh);
130  mNameAdapter->setData(mMesh);
131  mUidAdapter->setData(mMesh);
132  return;
133  }
134 
135  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
136 
137  mParentFrameAdapter->setData(mMesh);
138  mNameAdapter->setData(mMesh);
139  mUidAdapter->setData(mMesh);
140 
141  std::map<std::string, std::string> info = getDisplayFriendlyInfo(mMesh);
142  this->populateTableWidget(info);
143 }
144 
146 {
147  if(!mMesh)
148  return;
149  DataPtr parent = mPatientModelService->getData(mMesh->getParentSpace());
150  if (!parent)
151  return;
152  mMesh->get_rMd_History()->setRegistration(parent->get_rMd());
153  report("Assigned rMd from volume [" + parent->getName() + "] to surface [" + mMesh->getName() + "]");
154 }
155 
157 {
158  if(!mMesh)
159  return;
160 
161  vtkPolyDataNormalsPtr normals = vtkPolyDataNormalsPtr::New();
162  normals->SetInputData(mMesh->getVtkPolyData());
163  normals->Update();
164  mMesh->setVtkPolyData(normals->GetOutput());
165 
166  QString outputBasePath = mPatientModelService->getActivePatientFolder();
167  mMesh->save(outputBasePath);
168 }
169 
171 {
172  if(!mMesh)
173  return;
174 }
175 
176 void MeshInfoWidget::showEvent(QShowEvent* event)
177 {
178  QWidget::showEvent(event);
179 }
180 
181 void MeshInfoWidget::hideEvent(QCloseEvent* event)
182 {
183  QWidget::closeEvent(event);
184 }
185 
186 void MeshInfoWidget::addWidgets()
187 {
188  MeshPtr mesh = boost::dynamic_pointer_cast<Mesh>(mMeshSelector->getData());
189 
190  QPushButton* importTransformButton = new QPushButton("Import Transform from Parent", this);
191  importTransformButton->setToolTip("Replace data transform with that of the parent data.");
192  connect(importTransformButton, SIGNAL(clicked()), this, SLOT(importTransformSlot()));
193 
194  QPushButton* addNormalsButton = new QPushButton("Generate Normals", this);
195  addNormalsButton->setToolTip("Generate surface normals and add to model.\nThis usually gives a smoother appearance.");
196  connect(addNormalsButton, SIGNAL(clicked()), this, SLOT(generateNormalsSlot()));
197 
198  mUidAdapter = StringPropertyDataUidEditable::New();
199  mNameAdapter = StringPropertyDataNameEditable::New();
200  mParentFrameAdapter = StringPropertyParentFrame::New(mPatientModelService);
201 
202  int row = 1;
203 
204  new LabeledLineEditWidget(this, mUidAdapter, gridLayout, row++);
205  new LabeledLineEditWidget(this, mNameAdapter, gridLayout, row++);
206  new LabeledComboBoxWidget(this, mParentFrameAdapter, gridLayout, row++);
207  gridLayout->addWidget(mTableWidget, row++, 0, 1, 2);
208  gridLayout->addWidget(importTransformButton, row++, 0, 1, 2);
209  gridLayout->addWidget(addNormalsButton, row++, 0, 1, 2);
210 
211  this->addStretch();
212 }
213 
214 
215 
216 }//end namespace cx
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:66
AllMeshPropertiesWidget(SelectDataStringPropertyBasePtr mesh, VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
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:68
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:109
void report(QString msg)
Definition: cxLogger.cpp:90
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.