#ifndef __DefOrgViewerAdapterBase_h #define __DefOrgViewerAdapterBase_h #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkMeanImageFilter.h" #include "itkBinaryThresholdImageFilter.h" #include "itkCovariantVector.h" #include "vtkUnstructuredGrid.h" #include "vtkCellArray.h" #include "vtkProperty.h" #include "vtkTransform.h" #include #include #include #include "itkSceneSpatialObject.h" #include "itkImage.h" #include "itkImageFileReader.h" #include "vtkImageImport.h" #include "itkVTKImageExport.h" #include "DefOrgViewerAdapterBase.h" #include #include namespace mial{ #define N_DIMS 3 typedef itk::SceneSpatialObject::Pointer itkScenePointer; #define SetStringMacro(name) \ virtual void Set##name (const char* _arg) \ { \ if ( _arg && (_arg == this->m_##name) ) { return;} \ if (_arg) \ { \ this->m_##name = _arg;\ } \ else \ { \ this->m_##name = ""; \ } \ m_Initialized=false; \ } struct DefOrgLayerStruct{ const char* layerName; std::vector options; const char* chosenOption; }; /*! Structure for storing DefOrg numeric property. Define the range, default value and resolution for displaying the numeric property as a slicer in the GUI */ struct DefOrgPropertyStruct{ double lowerBound; double upperBound; double defaultValue; double currentValue; double resolution; std::string helpString; DefOrgPropertyStruct(double _lowerBound, double _upperBound, double _defaultValue, double _currentValue, double _resolution, std::string _helpString): lowerBound(_lowerBound), upperBound(_upperBound), defaultValue(_defaultValue), currentValue(_currentValue), resolution(_resolution), helpString(_helpString) {} DefOrgPropertyStruct(): lowerBound(0), upperBound(100), defaultValue(50), currentValue(50), resolution(1), helpString("Program Error: Incorrectly initialized.") {} }; /*!Structure for storing spatial object descriptions. Viewer assigns a ITKScene to be used by the adapter, the adapter populat the scene. Modified field must be set if the scene is changed. displayInSeparateFrame is currently ignored. */ struct SpatialObjectDescriptorStruct{ itkScenePointer theItkScene; bool isModified; bool displayInSeparateFrame; SpatialObjectDescriptorStruct(itkScenePointer _theItkScene, bool _displayInSeparateFrame, bool _isModified=true): theItkScene(_theItkScene), isModified(_isModified), displayInSeparateFrame(_displayInSeparateFrame) {} SpatialObjectDescriptorStruct(): theItkScene(NULL), isModified(false), displayInSeparateFrame(false) {} }; /*!Structure for storing output images descriptions. Viewer assigns a vtkImageImport to be used by the adapter, the adapter populat the scene. Modified field must be set if the scene is changed. displayInSeparateFrame is currently ignored. */ struct OutputImageDescriptorStruct{ vtkImageImport* theImageVolume; bool isModified; bool isInitialized; int dimension; std::string windowName; bool displayInSeparateFrame; OutputImageDescriptorStruct(vtkImageImport* _theImageVolume, bool _displayInSeparateFrame, int _D, bool _isModified=true): theImageVolume(_theImageVolume), isModified(_isModified), isInitialized(false), dimension(_D), windowName("Window"), displayInSeparateFrame(_displayInSeparateFrame) {} OutputImageDescriptorStruct(): theImageVolume(NULL), isModified(false), isInitialized(false), dimension(0), windowName(""), displayInSeparateFrame(false) {} }; /*! Abstract base class for DefOrgViewerAdapter. Do not inherit directly from this. Instead, inherit from DefOrgViewerAdapterBaseTemplate. This class is for internal use in DefOrgViewer. */ class DefOrgViewerAdapterBase{ public: //typedef void (* DEFORG_TEXTOUTPUT_CALLBACK_FUNCTION)(); DefOrgViewerAdapterBase(int maxNumImages):m_Initialized(false){ std::cout.rdbuf(theDefOrgTextOutput.rdbuf()); for(int i=0; i m_PropertyBag; std::vector< DefOrgLayerStruct > m_LayerBag; /*!Number of itkScenePointer will depend on MaxNumberOfOutputItkSpatialObjects(). The derived class would then populate the Scenes as it finds appropriate */ std::vector< SpatialObjectDescriptorStruct > m_OutputItkSpatialObjects; /*!Number of vtkImageImport* will depend on MaxNumberOfOutputImages(). The derived class would then populate the imageVolumes as it finds appropriate */ std::vector< OutputImageDescriptorStruct > m_OutputImages; /*!For viewer. Derived class should not call this method*/ virtual void AddOutputItkSpatialObjects(itkScenePointer itkScene){ m_OutputItkSpatialObjects.push_back(SpatialObjectDescriptorStruct(itkScene,false)); } /*!For viewer. Derived class should not call this method*/ virtual void AddOutputImages(vtkImageImport* vtkImporter,int Offset){ m_OutputImages[Offset].theImageVolume = vtkImporter; } /*!For viewer. Derived class should not access this variable. To produce text output to be displayed, use std::cout*/ std::ostringstream theDefOrgTextOutput; /*!Derived class can read from this stream for text input collected from the viewer*/ std::stringstream theDefOrgTextInput; //DEFORG_TEXTOUTPUT_CALLBACK_FUNCTION theDefOrgTextOutputCallBack; protected: bool m_Initialized; /*!Helper method to allow numeric properties to be added in derived adapter's constructor \param propertyName Name of the property \param lowerBound Lower bound of the numeric property \param upperBound Upper bound of the numeric property \param defaultValue Default Value of the numeric property \param resolution By what value will the current value be incremented when the slicer is adjusted \param helpString Optional help string describing this property*/ virtual void AddOrganismProperty(const char* propertyName, double lowerBound, double upperBound, double defaultValue, double resolution=1.0, const char* helpString=""){ m_PropertyBag[propertyName]=DefOrgPropertyStruct(lowerBound,upperBound,defaultValue,defaultValue,resolution,std::string(helpString)); } /*!Return the value of the property as obtained through the GUI \param propertyName Name of the property */ virtual double GetOrganismProperty(const char* propertyName){ std::map::iterator cur = m_PropertyBag.find(std::string(propertyName)); if ( m_PropertyBag.end()!= cur){ return (cur->second).currentValue; } return 0; } /*!Helper method to allow a combox to be displayed, allowing the user to choose which instance of a layer to attach*/ virtual void AddLayer(const char* layerName, const char** options, int numChoices); /*!Helper method to get the name of the layer assigned*/ virtual const char* GetLayer(const char* layerName); std::string m_ImageFileName; std::string m_ScheduleFileName; std::string m_MeshFileName; }; } #endif