GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QCellPreprocess.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Author: $Author$ // Author of last commit
3  Version: $Rev$ // Revision of last commit
4  Date: $Date$ // Date of last commit
5 =========================================================================*/
6 
7 /*=========================================================================
8  Authors: The GoFigure Dev. Team.
9  at Megason Lab, Systems biology, Harvard Medical school, 2009
10 
11  Copyright (c) 2009, President and Fellows of Harvard College.
12  All rights reserved.
13 
14  Redistribution and use in source and binary forms, with or without
15  modificatio n, are permitted provided that the following conditions are met:
16 
17  Redistributions of source code must retain the above copyright notice,
18  this list of conditions and the following disclaimer.
19  Redistributions in binary form must reproduce the above copyright notice,
20  this list of conditions and the following disclaimer in the documentation
21  and/or other materials provided with the distribution.
22  Neither the name of the President and Fellows of Harvard College
23  nor the names of its contributors may be used to endorse or promote
24  products derived from this software without specific prior written
25  permission.
26 
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
31  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
33  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
36  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 =========================================================================*/
40 #include "QCellPreprocess.h"
41 
42 #include "vtkitkAdaptor.h"
43 
44 #include <iostream>
45 
46 //--------------------------------------------------------------------------
48 {
49  this->setupUi(this);
50  m_CellRadius = 4.0;
51  m_MembraneData = true;
52 
53  this->buttonGroup->setId(allChRadioButton, 0);
54  this->buttonGroup->setId(singleChRadioButton, 1);
55  this->ChannelComboBox->setEnabled(false);
56 }
57 
59 {
60  m_MembraneData = x;
61 }
62 
63 void QCellPreprocess::SetInput(std::vector< vtkImageData * > & iImg)
64 {
65  m_VTKInput = iImg;
66  m_VTKOutput.resize(m_VTKInput.size(), 0);
67 }
68 
69 std::vector< vtkImageData * > QCellPreprocess::GetOutput()
70 {
71  return m_VTKOutput;
72 }
73 
74 //--------------------------------------------------------------------------
76 { // Get the current snapshot of parameters
77  m_CellRadius = static_cast< double >( this->RadiusSpinBox->value() );
78 }
79 
80 //--------------------------------------------------------------------------
82 {
83  double t = this->RadiusSpinBox->value();
84  double max_spin = this->RadiusSpinBox->maximum();
85  double min_spin = this->RadiusSpinBox->minimum();
86 
87  int max_slider = this->RadiusSlider->maximum();
88  int min_slider = this->RadiusSlider->minimum();
89 
90  int out = static_cast< int >( min_slider
91  + ( max_slider - min_slider ) * ( t - min_spin ) / ( max_spin - min_spin ) );
92 
93  this->RadiusSlider->setValue(out);
94 }
95 
96 //--------------------------------------------------------------------------
98 {
99  int t = this->RadiusSlider->value();
100 
101  double max_spin = this->RadiusSpinBox->maximum();
102  double min_spin = this->RadiusSpinBox->minimum();
103 
104  int max_slider = this->RadiusSlider->maximum();
105  int min_slider = this->RadiusSlider->minimum();
106 
107  double out = static_cast< double >( min_spin
108  + ( max_spin - min_spin ) * ( t - min_slider ) / ( max_slider - min_slider ) );
109 
110  this->RadiusSpinBox->setValue(out);
111 }
112 
113 //--------------------------------------------------------------------------
115 {
116  this->ChannelComboBox->setEnabled(false);
117 }
118 
119 //--------------------------------------------------------------------------
121 {
122  this->ChannelComboBox->setEnabled(true);
123 }
124 
125 //--------------------------------------------------------------------------
127 {
128  this->m_CellRadius = 4.0;
129  this->RadiusSpinBox->setValue(this->m_CellRadius);
130 }
131 
132 //--------------------------------------------------------------------------
134 {
135  unsigned int option = static_cast< unsigned int >( this->buttonGroup->checkedId() );
136 
137  if ( !option )
138  {
139  Preprocess(0);
140 // Preprocess( 1 );
141 // Preprocess( 2 );
142  }
143  else
144  {
145  unsigned int channel = static_cast< unsigned int >( this->ChannelComboBox->currentIndex() );
146  Preprocess(channel);
147  }
148 
149  emit Done(m_VTKOutput);
150 }
151 
152 void QCellPreprocess::Preprocess(unsigned int i)
153 {
154  if ( m_VTKInput[i] )
155  {
156  // convert VTK image to ITK image
157  vtkImageExport *vtkExporter = vtkImageExport::New();
158  vtkExporter->SetInput(m_VTKInput[i]);
159 
160  ImageImportPointer itkImporter = ImageImportType::New();
161 
162  ConnectPipelines(vtkExporter, itkImporter);
163 
164  InputImagePointer m_ITKImage = itkImporter->GetOutput();
165 
166  PreprocessFilterPointer filter = PreprocessFilterType::New();
167  filter->SetInput (m_ITKImage);
168  filter->SetLargestCellRadius (m_CellRadius); // in real coordinates
169  filter->SetMembraneData(m_MembraneData);
170  filter->Update();
171 
172  InputImagePointer m_ITKOutputImage = filter->GetOutput();
173 
174  ImageExportType::Pointer itkExporter = ImageExportType::New();
175  itkExporter->SetInput(m_ITKOutputImage);
176 
177  vtkImageImport *vtkImporter = vtkImageImport::New();
178 
179  ConnectPipelines(itkExporter, vtkImporter);
180 
181  m_VTKOutput[i] = vtkImporter->GetOutput();
182 
183  vtkExporter->Delete();
184  vtkImporter->Delete();
185  }
186 }
PreprocessFilterType::Pointer PreprocessFilterPointer
void on_RadiusSlider_sliderReleased()
void setupUi(QWidget *widget)
void SetMembraneDataType(bool x)
std::vector< vtkImageData * > m_VTKOutput
void on_singleChRadioButton_clicked()
int x() const
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer *importer)
Definition: vtkitkAdaptor.h:44
std::vector< vtkImageData * > GetOutput()
void on_RadiusSpinBox_valueChanged()
void SetInput(std::vector< vtkImageData * > &iImg)
void Preprocess(unsigned int i)
std::vector< vtkImageData * > m_VTKInput
void on_GlobalResetButton_clicked()
void Done(std::vector< vtkImageData * >)
ImageImportType::Pointer ImageImportPointer
InputImageType::Pointer InputImagePointer
void on_allChRadioButton_clicked()
void on_GlobalApplyButton_clicked()
QCellPreprocess(QWidget *iParent=0)