Index: 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKFilterBaseImage.txx
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKFilterBaseImage.txx	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKFilterBaseImage.txx	(working copy)
@@ -208,10 +208,14 @@
     {
     outputImage.datatype = V3D_UINT8;
     }
-  else if ( typeid(OutputPixelType) == typeid( unsigned short int ) )
+  else if ( typeid(OutputPixelType) == typeid( uint16 ) )
     {
     outputImage.datatype = V3D_UINT16;
     }
+  else if ( typeid(OutputPixelType) == typeid( uint32 ) )
+    {
+    outputImage.datatype = V3D_UINT32;
+    }
   else if ( typeid(OutputPixelType) == typeid( float ) )
     {
     outputImage.datatype = V3D_FLOAT32;
Index: 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKFilterBaseImage.h
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKFilterBaseImage.h	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKFilterBaseImage.h	(working copy)
@@ -16,6 +16,7 @@
       {  \
       EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_UINT8, unsigned char );  \
       EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_UINT16, unsigned short int );  \
+      EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_UINT32, unsigned int );  \
       EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_FLOAT32, float );  \
       case V3D_UNKNOWN:  \
         {  \
@@ -28,6 +29,7 @@
       {  \
       EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_UINT8, unsigned char );  \
       EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_UINT16, unsigned short int );  \
+      EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( V3D_UINT32, unsigned int );  \
       case V3D_FLOAT32:  \
       case V3D_UNKNOWN:  \
         {  \
@@ -45,6 +47,7 @@
           {  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT8, V3D_UINT8, unsigned char, unsigned char );  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT8, V3D_UINT16, unsigned char, unsigned short int );  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT8, V3D_UINT32, unsigned char, unsigned int );  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT8, V3D_FLOAT32, unsigned char, float );  \
           case V3D_UNKNOWN:  \
             {  \
@@ -55,16 +58,29 @@
           {  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT16, V3D_UINT8, unsigned short int, unsigned char );  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT16, V3D_UINT16, unsigned short int, unsigned short int );  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT16, V3D_UINT32, unsigned short int, unsigned int );  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT16, V3D_FLOAT32, unsigned short int, float );  \
           case V3D_UNKNOWN:  \
             {  \
             }  \
           } \
+      case V3D_UINT32: \
+        switch( outputPixelType )  \
+          {  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT32, V3D_UINT8, unsigned int, unsigned char );  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT32, V3D_UINT16, unsigned int, unsigned short int );  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT32, V3D_UINT32, unsigned int, unsigned int );  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_UINT32, V3D_FLOAT32, unsigned int, float );  \
+          case V3D_UNKNOWN:  \
+            {  \
+            }  \
+          } \
       case V3D_FLOAT32: \
         switch( outputPixelType )  \
           {  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_FLOAT32, V3D_UINT8, float, unsigned char );  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_FLOAT32, V3D_UINT16, float, unsigned short int );  \
+          EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_FLOAT32, V3D_UINT32, float, unsigned int );  \
           EXECUTE_PLUGIN_FOR_INPUT_AND_OUTPUT_IMAGE_TYPE( V3D_FLOAT32, V3D_FLOAT32, float, float );  \
           case V3D_UNKNOWN:  \
             {  \
Index: 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKPluginBaseSingleImage.h
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKPluginBaseSingleImage.h	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/Common/V3DITKPluginBaseSingleImage.h	(working copy)
@@ -27,6 +27,7 @@
       {  \
       V3DITK_PLUGIN_EXECUTE( PluginName, V3D_UINT8, unsigned char );  \
       V3DITK_PLUGIN_EXECUTE( PluginName, V3D_UINT16, unsigned short int );  \
+      V3DITK_PLUGIN_EXECUTE( PluginName, V3D_UINT32, unsigned int );  \
       V3DITK_PLUGIN_EXECUTE( PluginName, V3D_FLOAT32, float );  \
       case V3D_UNKNOWN:  \
         {  \
Index: 2010_hackathon/ITK-V3D-Plugins/Source/ImageObjects/ConnectedComponents.cxx
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/ImageObjects/ConnectedComponents.cxx	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/ImageObjects/ConnectedComponents.cxx	(working copy)
@@ -86,7 +86,7 @@
 #define EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( v3d_pixel_type, c_pixel_type ) \
   case v3d_pixel_type: \
     { \
-    PluginSpecialized< c_pixel_type, unsigned short int > runner( &callback ); \
+    PluginSpecialized< c_pixel_type, uint32 > runner( &callback ); \
     runner.Execute( menu_name, parent ); \
     break; \
     }
Index: 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MeanFilter.cxx
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MeanFilter.cxx	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MeanFilter.cxx	(working copy)
@@ -26,7 +26,7 @@
 }
 
 template<typename TPixelType>
-class ITKMeanFilterSpecializaed
+class PluginSpecialized
 {
 public:
 	void Execute(const QString &menu_name, V3DPluginCallback &callback, QWidget *parent)
@@ -174,27 +174,14 @@
 
 };
 
-#define EXECUTE( v3d_pixel_type, c_pixel_type ) \
+#define EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( v3d_pixel_type, c_pixel_type ) \
   case v3d_pixel_type: \
     { \
-	ITKMeanFilterSpecializaed< c_pixel_type > runner; \
+	PluginSpecialized< c_pixel_type > runner; \
     runner.Execute(  menu_name, callback, parent ); \
     break; \
-    } 
+    }
 
-#define EXECUTE_ALL_PIXEL_TYPES \
-	Image4DSimple *p4DImage = callback.getImage(curwin); \
-    if (! p4DImage) return; \
-    ImagePixelType pixelType = p4DImage->getDatatype(); \
-    switch( pixelType )  \
-      {  \
-      EXECUTE( V3D_UINT8, unsigned char );  \
-      EXECUTE( V3D_UINT16, unsigned short int );  \
-      EXECUTE( V3D_FLOAT32, float );  \
-      case V3D_UNKNOWN:  \
-        {  \
-        }  \
-      }  
 
 void ITKMeanFilterPlugin::domenu(const QString & menu_name, V3DPluginCallback & callback, QWidget * parent)
 {
@@ -205,5 +192,12 @@
 		return;
     }
 
-  EXECUTE_ALL_PIXEL_TYPES;
+  Image4DSimple *p4DImage = callback.getImage(curwin);
+  if (! p4DImage)
+    {
+    v3d_msg(tr("The input image is null."));
+    return;
+    }
+
+  EXECUTE_PLUGIN_FOR_ALL_PIXEL_TYPES;
 }
Index: 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MedianFilter.h
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MedianFilter.h	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MedianFilter.h	(working copy)
@@ -1,69 +1,13 @@
-/* MedianFilter.h
- * 2010-06-03: create this program by Lei Qu
- */
+#ifndef __Median_H__
+#define __Median_H__
 
-#ifndef __MEDIANFILTER_H__
-#define __MEDIANFILTER_H__
+#include "V3DITKPluginDefaultHeader.h"
 
-#include <QtGui>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <v3d_interface.h>
-
-class ITKMedianFilterPlugin: public QObject, public V3DPluginInterface
+class MedianPlugin : public QObject, public V3DPluginInterface
 {
-	Q_OBJECT
-	Q_INTERFACES(V3DPluginInterface)
-
-public:
-	QStringList menulist() const;
-	void domenu(const QString &menu_name, V3DPluginCallback &callback, QWidget *parent);
-
-	QStringList funclist() const {return QStringList();}
-	void dofunc(const QString &func_name, const V3DPluginArgList &input, V3DPluginArgList &output, QWidget *parent) {}
-
+  Q_OBJECT
+  Q_INTERFACES(V3DPluginInterface)
+  V3DITKPLUGIN_DEFAULT_CLASS_DECLARATION_BODY(Median);
 };
 
-class ITKMedianFilterDialog: public QDialog
-{
-Q_OBJECT
-
-public:
-	ITKMedianFilterDialog(Image4DSimple *p4DImage, QWidget *parent)
-	{
-		if (!p4DImage)
-			return;
-
-		printf("Passing data to data1d\n");
-
-		ok = new QPushButton("OK");
-		cancel = new QPushButton("Cancel");
-
-		gridLayout = new QGridLayout();
-
-		gridLayout->addWidget(cancel, 0, 0);
-		gridLayout->addWidget(ok, 0, 1);
-		setLayout( gridLayout);
-		setWindowTitle(QString("Mean Filter"));
-
-		connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
-		connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
-	}
-
-	~ITKMedianFilterDialog()
-	{
-	}
-
-public slots:
-
-public:
-	QGridLayout *gridLayout;
-
-	QPushButton* ok;
-	QPushButton* cancel;
-};
-
 #endif
-
Index: 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MedianFilter.cxx
===================================================================
--- 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MedianFilter.cxx	(revision 157)
+++ 2010_hackathon/ITK-V3D-Plugins/Source/Smoothing/MedianFilter.cxx	(working copy)
@@ -1,209 +1,135 @@
-/* MedianFilter.cpp
- * 2010-06-03: create this program by Lei Qu
- */
-
 #include <QtGui>
 
 #include <math.h>
 #include <stdlib.h>
 
-#include "MedianFilter.h"
+#include "Median.h"
+#include "V3DITKFilterSingleImage.h"
 
 // ITK Header Files
-#include "itkImage.h"
-#include "itkImportImageFilter.h"
 #include "itkMedianImageFilter.h"
-#include "itkImageFileWriter.h"
 
+
 // Q_EXPORT_PLUGIN2 ( PluginName, ClassName )
 // The value of PluginName should correspond to the TARGET specified in the
 // plugin's project file.
-Q_EXPORT_PLUGIN2(MedianFilter, ITKMedianFilterPlugin)
+Q_EXPORT_PLUGIN2(Median, MedianPlugin)
 
-QStringList ITKMedianFilterPlugin::menulist() const
+
+QStringList MedianPlugin::menulist() const
 {
-	return QStringList() << QObject::tr("ITK Median Filter ...");
+    return QStringList() << QObject::tr("ITK Median")
+            << QObject::tr("about this plugin");
 }
 
-template<typename TPixelType>
-class ITKMedianFilterSpecializaed
+QStringList MedianPlugin::funclist() const
 {
-public:
-	void Execute(const QString &menu_name, V3DPluginCallback &callback, QWidget *parent)
-	{
-		v3dhandle oldwin = callback.currentImageWindow();
-		Image4DSimple* p4DImage = callback.getImage(oldwin);
-		V3D_GlobalSetting globalSetting = callback.getGlobalSetting();
+    return QStringList();
+}
 
-		const unsigned int Dimension = 3;
-	    int channelToFilter = globalSetting.iChannel_for_plugin;
-	    if( channelToFilter >= p4DImage->getCDim() )
-	      {
-	      v3d_msg(QObject::tr("You are selecting a channel that doesn't exist in this image."));
-	      return;
-	      }
 
-		//------------------------------------------------------------------
-		//import image from V3D
-		typedef TPixelType PixelType;
-		typedef itk::Image< PixelType,  Dimension > ImageType_input;
-		typedef itk::ImportImageFilter<PixelType, Dimension> ImportFilterType;
+template <typename TPixelType>
+class PluginSpecialized : public V3DITKFilterSingleImage< TPixelType, TPixelType >
+{
+  typedef V3DITKFilterSingleImage< TPixelType, TPixelType >   Superclass;
+  typedef typename Superclass::Input3DImageType               ImageType;
 
-		typename ImportFilterType::Pointer importFilter = ImportFilterType::New();
+  typedef itk::MedianImageFilter< ImageType, ImageType > FilterType;
 
-		//set ROI region
-		typename ImportFilterType::RegionType region;
-		typename ImportFilterType::IndexType start;
-		start.Fill(0);
-		typename ImportFilterType::SizeType size;
-		size[0] = p4DImage->getXDim();
-		size[1] = p4DImage->getYDim();
-		size[2] = p4DImage->getZDim();
-		region.SetIndex(start);
-		region.SetSize(size);
-		importFilter->SetRegion(region);
+public:
 
-		//set image Origin
-		typename ImageType_input::PointType origin;
-		origin.Fill(0.0);
-		importFilter->SetOrigin(origin);
-		//set spacing
-		typename ImportFilterType::SpacingType spacing;
-		spacing.Fill(1.0);
-		importFilter->SetSpacing(spacing);
+  PluginSpecialized( V3DPluginCallback * callback ): Superclass(callback)
+    {
+    this->m_Filter = FilterType::New();
+    this->RegisterInternalFilter( this->m_Filter, 1.0 );
+    }
 
-		//set import image pointer
-		PixelType * data1d = reinterpret_cast<PixelType *> (p4DImage->getRawData());
-		unsigned long int numberOfPixels = p4DImage->getTotalBytes();
-		const bool importImageFilterWillOwnTheBuffer = false;
-		importFilter->SetImportPointer(data1d, numberOfPixels,importImageFilterWillOwnTheBuffer);
+  virtual ~PluginSpecialized() {};
 
-		//------------------------------------------------------------------
-		//setup filter: Mean Filter
-		typedef itk::MedianImageFilter<ImageType_input,ImageType_input> FilterType;
-		typename FilterType::Pointer filter = FilterType::New();
 
-		//set paras
-		typename ImageType_input::SizeType indexRadius;
-		indexRadius[0] = 1; // radius along x
-		indexRadius[1] = 1; // radius along y
-		indexRadius[2] = 1; // radius along y
-		filter->SetRadius( indexRadius );
+  void Execute(const QString &menu_name, QWidget *parent)
+    {
+    V3DITKGenericDialog dialog("Median");
 
-		//------------------------------------------------------------------
-		//setup filter: write processed image to disk
-		typedef itk::ImageFileWriter< ImageType_input >  WriterType;
-		typename WriterType::Pointer writer = WriterType::New();
-		writer->SetFileName("output.tif");
+    dialog.AddDialogElement("Radius X",1.0, 0.0, 10.0);
+    dialog.AddDialogElement("Radius Y",1.0, 0.0, 10.0);
+    dialog.AddDialogElement("Radius Z",1.0, 0.0, 10.0);
 
-		//------------------------------------------------------------------
-		//build pipeline
-		filter->SetInput(importFilter->GetOutput());
-		writer->SetInput(filter->GetOutput());
+    if( dialog.exec() == QDialog::Accepted )
+      {
 
-		//------------------------------------------------------------------
-		//update the pixel value
-		if (menu_name == QObject::tr("ITK Median Filter ..."))
-		{
-			ITKMedianFilterDialog d(p4DImage, parent);
+      typename ImageType_input::SizeType indexRadius;
+      indexRadius[0] = dialog.GetValue("Radius X");
+      indexRadius[1] = dialog.GetValue("Radius Y");
+      indexRadius[2] = dialog.GetValue("Radius Z");
 
-			if (d.exec() != QDialog::Accepted)
-			{
-				return;
-			}
-			else
-			{
-				try
-				{
-					writer->Update();
-				}
-				catch(itk::ExceptionObject &excp)
-				{
-					std::cerr<<excp<<std::endl;
-					return;
-				}
-			}
+      this->m_Filter->SetRadius( indexRadius );
 
-		}
-		else
-		{
-			return;
-		}
+      this->Compute();
+      }
+    }
 
-		//------------------------------------------------------------------
-		typedef itk::ImageRegionConstIterator<ImageType_input> IteratorType;
-		IteratorType it(filter->GetOutput(), filter->GetOutput()->GetRequestedRegion());
-		it.GoToBegin();
+  virtual void ComputeOneRegion()
+    {
 
-		if(!globalSetting.b_plugin_dispResInNewWindow)
-		{
-			printf("display results in a new window\n");
-			//copy data back to V3D
-			while(!it.IsAtEnd())
-			{
-				*data1d=it.Get();
-				++it;
-				++data1d;
-			}
+    this->m_Filter->SetInput( this->GetInput3DImage() );
 
-			callback.setImageName(oldwin, callback.getImageName(oldwin)+"_new");
-			callback.updateImageWindow(oldwin);
-		}
-		else
-		{
-			printf("display results in current window\n");
-			long N = p4DImage->getTotalBytes();
-			unsigned char* newdata1d = new unsigned char[N];
-			Image4DSimple tmp;
-			tmp.setData(newdata1d, p4DImage );
+    if( !this->ShouldGenerateNewWindow() )
+      {
+      this->m_Filter->InPlaceOn();
+      }
 
-			//copy data back to the new image
-			while(!it.IsAtEnd())
-			{
-				*newdata1d=it.Get();
-				++it;
-				++newdata1d;
-			}
+    this->m_Filter->Update();
 
-			v3dhandle newwin = callback.newImageWindow();
-			callback.setImage(newwin, &tmp);
-			callback.setImageName(newwin, callback.getImageName(oldwin)+"_new");
-		    callback.updateImageWindow(newwin);
-		}
-	}
+    this->SetOutputImage( this->m_Filter->GetOutput() );
+    }
 
+
+private:
+
+    typename FilterType::Pointer   m_Filter;
+
 };
 
-#define EXECUTE( v3d_pixel_type, c_pixel_type ) \
+
+#define EXECUTE_PLUGIN_FOR_ONE_IMAGE_TYPE( v3d_pixel_type, c_pixel_type ) \
   case v3d_pixel_type: \
     { \
-	ITKMedianFilterSpecializaed< c_pixel_type > runner; \
-    runner.Execute(  menu_name, callback, parent ); \
+    PluginSpecialized< c_pixel_type > runner( &callback ); \
+    runner.Execute( menu_name, parent ); \
     break; \
-    } 
+    }
 
-#define EXECUTE_ALL_PIXEL_TYPES \
-	Image4DSimple *p4DImage = callback.getImage(curwin); \
-    if (! p4DImage) return; \
-    ImagePixelType pixelType = p4DImage->getDatatype(); \
-    switch( pixelType )  \
-      {  \
-      EXECUTE( V3D_UINT8, unsigned char );  \
-      EXECUTE( V3D_UINT16, unsigned short int );  \
-      EXECUTE( V3D_FLOAT32, float );  \
-      case V3D_UNKNOWN:  \
-        {  \
-        }  \
-      }  
 
-void ITKMedianFilterPlugin::domenu(const QString & menu_name, V3DPluginCallback & callback, QWidget * parent)
+void MedianPlugin::dofunc(const QString & func_name,
+    const V3DPluginArgList & input, V3DPluginArgList & output, QWidget * parent)
 {
-	v3dhandle curwin = callback.currentImageWindow();
-	if (!curwin)
+  // empty by now
+}
+
+
+void MedianPlugin::domenu(const QString & menu_name, V3DPluginCallback & callback, QWidget * parent)
+{
+  if (menu_name == QObject::tr("about this plugin"))
     {
-		v3d_msg(tr("You don't have any image open in the main window."));
-		return;
+    QMessageBox::information(parent, "Version info", "ITK Median 1.0 (2010-Jun-21): this plugin is developed by Luis Ibanez.");
+    return;
     }
 
-  EXECUTE_ALL_PIXEL_TYPES;
+  v3dhandle curwin = callback.currentImageWindow();
+  if (!curwin)
+    {
+    v3d_msg(tr("You don't have any image open in the main window."));
+    return;
+    }
+
+  Image4DSimple *p4DImage = callback.getImage(curwin);
+  if (! p4DImage)
+    {
+    v3d_msg(tr("The input image is null."));
+    return;
+    }
+
+  EXECUTE_PLUGIN_FOR_ALL_PIXEL_TYPES;
 }
+
