SMILX  1.01
milxQtFiniteTransformPlugin.cpp
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 #include "milxQtFiniteTransformPlugin.h"
19 
20 #include <qplugin.h>
21 //#include <cstdio>
22 
23 //FTL
24 extern "C"
25 {
26  #include <nttw/global.h>
27  #include <nttw/image.h>
28 }
29 
31 {
33  //~ MainWindow = qobject_cast<milxQtMain *>(theParent);
34 
35  threaded = false;
36  dockable = false;
37  consoleWindow = false;
38  extension = false;
39  pluginName = "FiniteTransform";
40  //~ dataName = "";
41 
42  //~ createConnections();
43 }
44 
45 milxQtFiniteTransformPlugin::~milxQtFiniteTransformPlugin()
46 {
47  if(isRunning() && threaded)
48  quit();
49  images.clear();
50  cout << "FiniteTransform Plugin Destroyed." << endl;
51 }
52 
54 {
55  return pluginName;
56 }
57 
59 {
60  QString openExt = "Portable Graymap Files (*.pgm)";
61 
62  return openExt;
63 }
64 
66 {
67  QStringList exts;
68 
69  exts.append(".pgm");
70 
71  return exts;
72 }
73 
75 {
76  QStringList exts;
77 
78  exts.append(".pgm");
79 
80  return exts;
81 }
82 
84 {
85  QString savePythonExt = "Portable Graymap Files (*.pgm)";
86 
87  return savePythonExt;
88 }
89 
90 void milxQtFiniteTransformPlugin::SetInputCollection(vtkPolyDataCollection* collection, QStringList &filenames)
91 {
92 
93 }
94 
95 void milxQtFiniteTransformPlugin::open(QString filename)
96 {
97  nttw_integer *image;
98  int rows, cols;
99  size_t n;
100  cout << "NTTW Library (nttw_integer) Type Size: " << sizeof(nttw_integer) << ", Alignment: " << ALIGNOF(nttw_integer) << " bytes" << endl;
101 
102  //Check if binary
103  int binaryInFile = isBinaryPGM(filename.toStdString().c_str());
104  //load
105  if(!readPGM(&image,&rows,&cols,filename.toStdString().c_str(),binaryInFile))
106  {
107  cerr << "Error Opening File: " << filename.toStdString() << endl;
108  return;
109  }
110  cout << "Opened " << filename.toStdString() << " as FTL image" << endl;
111  cout << "Image of size " << rows << "x" << cols << endl;
112 
113  //Convert to VNL
114  n = static_cast<unsigned>(rows)*static_cast<unsigned>(cols);
115  vnl_vector<nttw_integer> imgData(image, n);
116  vnl_vector<float> imgFloatData(n);
117 
118  for(size_t j = 0; j < imgData.size(); j ++)
119  imgFloatData[j] = static_cast<float>(imgData[j]);
120 
121  typedef floatImageType::SizeType SizeType;
122  SizeType newSize;
123  newSize[0] = static_cast<unsigned>(cols);
124  newSize[1] = static_cast<unsigned>(rows);
125  newSize[2] = 1;
126 
127  cout << "Converting to ITK Image" << endl;
128  floatImageType::Pointer tmpImageImage = milx::Image<floatImageType>::ImportVectorToImage<float>(imgFloatData, newSize);
129  floatImageType::Pointer Image = milx::Image<floatImageType>::DuplicateImage(tmpImageImage);
130 
131  QPointer<milxQtImage> img = new milxQtImage;
132  img->setName(filename);
133  img->setData(Image);
134  img->generateImage();
135 
136  images.append(img);
137 }
138 
139 void milxQtFiniteTransformPlugin::save(QString filename)
140 {
141  typedef floatImageType::SizeType SizeType;
142  SizeType newSize = images.last()->GetFloatImage()->GetLargestPossibleRegion().GetSize();
143  const size_t n = static_cast<unsigned>(newSize[1])*static_cast<unsigned>(newSize[0]);
144  vnl_vector<nttw_integer> imgData(n);
145 
146  for(size_t j = 0; j < imgData.size(); j ++)
147  imgData[j] = static_cast<nttw_integer>(images.last()->GetFloatImage()->GetBufferPointer()[j]);
148 
149  int binaryFile = FALSE;
150  writePGM(imgData.data_block(),newSize[1],newSize[0],255,filename.toStdString().c_str(),binaryFile);
151 }
152 
154 {
155  return NULL;
156 } //No image result
157 
159 {
160  //~ denoiseModel = new milxQtFiniteTransformModel;
161 
162  return NULL;
163  //~ return denoiseModel;
164 } //No image result
165 
167 {
168  images.last()->generateImage();
169 
170  return images.last();
171 } //image result
172 
174 {
175  return NULL;
176 } //No Dock result
177 
179 {
180  //~ if(pluginWindow(window) == 0)
181  return false;
182  //~ else
183  //~ return true;
184 }
185 
186 //~ milxQtDeNoiseModel* milxQtDeNoisePlugin::pluginWindow(QWidget *window)
187 //~ {
188  //~ if(window)
189  //~ return qobject_cast<milxQtDeNoiseModel *>(window);
190  //~ return 0;
191 //~ }
192 
194 {
195  //~ if(!MainWindow->isActiveModel())
196  //~ return;
197 
198  //~ milxQtModel *currentWin = MainWindow->activeModel();
199  //~ milxQtDeNoiseModel *denoiseModel = new milxQtDeNoiseModel(MainWindow); //hierarchical deletion
200  //~ denoiseModel->setName(currentWin->getName());
201  //~ denoiseModel->SetInput(currentWin->GetOutput());
202  //~ denoiseModel->generateModel();
203 
204  //~ MainWindow->display(denoiseModel);
205 }
206 
207 //void milxQtFiniteTransformPlugin::run()
208 //{
209  //~ QMutexLocker locker(&mutex); //Lock memory
210 
211  //~ ///Execute own thread work here
212 
213  //~ //exec();
214 //}
215 
217 {
218 
219 }
220 
222 {
223 
224 }
225 
226 //~ void milxQtFiniteTransformPlugin::createConnections()
227 //~ {
228  //~ //QObject::connect(denoiseAct, SIGNAL(triggered(bool)), denoiseModel, SLOT(denoise()));
229 //~ }
230 
231 Q_EXPORT_PLUGIN2(_MYPLUGINCLASS_, milxQtFiniteTransformPluginFactory);
bool threaded
Threaded plugin?
virtual milxQtRenderWindow * genericResult()
Get the generic result, which is a milxQtRenderWindow. The result can then be displayed in milxQtMain...
virtual void preStartTasks()
Tasks to complete before running or starting the thread. [Implement this].
virtual milxQtModel * modelResult()
Get the model result. The result can then be displayed in milxQtMain etc. [Implement this in your plu...
void setName(const QString filename)
Set the name of the data.
virtual bool isPluginWindow(QWidget *window)
Is the window provided a plugin generated window? In this case a milxQtShapeModel window...
This class represents the MILX Qt Render Window Display object using QVTK.
virtual void loadExtension()
Load the extension. [Implement this in your plugin].
bool consoleWindow
console window?
virtual void save(QString filename)
Save the result as a file using the plugin. [Implement this in your plugin].
This class represents the MILX Qt Image Display object using VTK.
Definition: milxQtImage.h:118
bool extension
Extension rather than a plugin?
virtual QStringList openExtensions()
Get a list of supported file format extensions. [Implement this in your plugin].
virtual QString name()
Get the Name of the plugin. [Implement this in your plugin].
This class represents the MILX Qt Model/Mesh Display object using VTK.
Definition: milxQtModel.h:115
virtual void postStartTasks()
Tasks to complete after running or starting the thread. [Implement this].
bool dockable
Dockable plugin?
virtual QDockWidget * dockWidget()
Return the dock widget (if one is provided by plugin). [Implement this in your plugin].
Represents an image (i.e. an regular rectangular array with scalar values) and their common operation...
Definition: milxImage.h:174
virtual void SetInputCollection(vtkPolyDataCollection *collection, QStringList &filenames)
Pass a collection to internal plugin class. [Implement this in your plugin].
The interface for any plugins that can be made for milxQtMain.
virtual QString openFileSupport()
Get the file support string for opening (extension wildcard list). [Implement this in your plugin]...
milxQtFiniteTransformPlugin(QObject *theParent=0)
Default destructor.
virtual void open(QString filename)
Open the file using the plugin. [Implement this in your plugin].
static itk::SmartPointer< TImage > DuplicateImage(itk::SmartPointer< TImage > img)
Duplicates the image into a new image.
Definition: milxImage.h:1152
virtual milxQtImage * imageResult()
Get the image result. The result can then be displayed in milxQtMain etc.[Implement this in your plug...
virtual QString saveFileSupport()
Get the file support string for saving (extension wildcard list). [Implement this in your plugin]...
virtual QStringList saveExtensions()
Get a list of supported file format extensions. [Implement this in your plugin].