C:/cmcintos/defOrgs/examples/DefOrgViewerWithKW/Source/DefOrgViewerAdapterBase.h

00001 #ifndef __DefOrgViewerAdapterBase_h
00002 #define __DefOrgViewerAdapterBase_h
00003 
00004 #include "itkImageFileReader.h"
00005 #include "itkImageFileWriter.h"
00006 #include "itkMeanImageFilter.h"
00007 #include "itkBinaryThresholdImageFilter.h"
00008 #include "itkCovariantVector.h"
00009 
00010 #include "vtkUnstructuredGrid.h"
00011 #include "vtkCellArray.h"
00012 #include "vtkProperty.h"
00013 #include "vtkTransform.h"
00014 
00015 #include <iostream>
00016 #include <map>
00017 #include <vector>
00018 #include "itkSceneSpatialObject.h"
00019 #include "itkImage.h"
00020 #include "itkImageFileReader.h"
00021 #include "vtkImageImport.h"
00022 #include "itkVTKImageExport.h"
00023 #include "DefOrgViewerAdapterBase.h"
00024 
00025 #include <vtksys/SystemTools.hxx>
00026 #include <vtksys/CommandLineArguments.hxx>
00027 
00028 namespace mial{
00029 #define N_DIMS 3
00030 typedef itk::SceneSpatialObject<N_DIMS>::Pointer                itkScenePointer;
00031 
00032 #define SetStringMacro(name) \
00033   virtual void Set##name (const char* _arg) \
00034   { \
00035     if ( _arg && (_arg == this->m_##name) ) { return;} \
00036     if (_arg) \
00037       { \
00038       this->m_##name = _arg;\
00039       } \
00040      else \
00041       { \
00042       this->m_##name = ""; \
00043       } \
00044     m_Initialized=false; \
00045   } 
00046 
00047 struct DefOrgLayerStruct{
00048         const char* layerName;
00049         std::vector<const char*> options;
00050         const char* chosenOption;       
00051 };
00052 
00053 
00058 struct DefOrgPropertyStruct{
00059         double lowerBound;
00060         double upperBound;
00061         double defaultValue;
00062         double currentValue;
00063         double resolution;
00064         std::string helpString;
00065         DefOrgPropertyStruct(double _lowerBound, double _upperBound, double _defaultValue, double _currentValue, double _resolution, std::string _helpString):
00066                 lowerBound(_lowerBound),
00067                 upperBound(_upperBound),
00068                 defaultValue(_defaultValue),
00069                 currentValue(_currentValue),
00070                 resolution(_resolution),
00071                 helpString(_helpString)
00072         {}
00073         DefOrgPropertyStruct():
00074                 lowerBound(0),
00075                 upperBound(100),
00076                 defaultValue(50),
00077                 currentValue(50),
00078                 resolution(1),
00079                 helpString("Program Error: Incorrectly initialized.")           
00080         {}
00081 };
00082 
00088 struct SpatialObjectDescriptorStruct{
00089         itkScenePointer theItkScene;
00090         bool isModified;
00091         bool displayInSeparateFrame;
00092         SpatialObjectDescriptorStruct(itkScenePointer _theItkScene, bool _displayInSeparateFrame, bool _isModified=true):
00093                 theItkScene(_theItkScene),
00094                 isModified(_isModified),
00095                 displayInSeparateFrame(_displayInSeparateFrame)
00096         {}
00097         SpatialObjectDescriptorStruct():
00098                 theItkScene(NULL),
00099                 isModified(false),
00100                 displayInSeparateFrame(false)
00101         {}
00102 };
00103 
00109 struct OutputImageDescriptorStruct{
00110         vtkImageImport* theImageVolume;
00111         bool isModified;
00112         bool isInitialized;
00113         int      dimension;
00114         std::string windowName;
00115         bool displayInSeparateFrame;
00116         OutputImageDescriptorStruct(vtkImageImport* _theImageVolume, bool _displayInSeparateFrame, int _D, bool _isModified=true):
00117                 theImageVolume(_theImageVolume),
00118                 isModified(_isModified),
00119                 isInitialized(false),
00120                 dimension(_D),
00121                 windowName("Window"),
00122                 displayInSeparateFrame(_displayInSeparateFrame)
00123         {}
00124         OutputImageDescriptorStruct():
00125                 theImageVolume(NULL),
00126                 isModified(false),
00127                 isInitialized(false),
00128                 dimension(0),
00129                 windowName(""),
00130                 displayInSeparateFrame(false)
00131         {}
00132 };
00133 
00137 class DefOrgViewerAdapterBase{
00138 public:
00139         //typedef void (* DEFORG_TEXTOUTPUT_CALLBACK_FUNCTION)();
00140         DefOrgViewerAdapterBase(int maxNumImages):m_Initialized(false){
00141                 std::cout.rdbuf(theDefOrgTextOutput.rdbuf());
00142                 for(int i=0; i<maxNumImages;i++)
00143                         m_OutputImages.push_back(OutputImageDescriptorStruct(NULL,false,0));
00144         }
00145         SetStringMacro(ScheduleFileName);
00146         SetStringMacro(MeshFileName);
00147         SetStringMacro(ImageFileName);
00148 
00151         virtual bool IsAllInputFilesSet(){
00152                 return 
00153                 (vtksys::SystemTools::FileExists(m_ImageFileName.c_str()) &&
00154                 vtksys::SystemTools::FileExists(m_ScheduleFileName.c_str()) &&
00155                 vtksys::SystemTools::FileExists(m_MeshFileName.c_str()) 
00156                 );
00157         }       
00158         /*
00159         virtual bool IsInitialized(){
00160                 return m_Initialized;
00161         }*/
00162 
00165         virtual void SetupOrganism()=0;
00168         virtual void UpdateOrganism()=0;
00170         virtual void PopulateVtkImage()=0;
00172         virtual void PopulateVtkUnstructuredGrid(vtkUnstructuredGrid* vtkGrid /*in/out*/)=0;
00174         virtual void PopulateItkScene()=0;
00175 
00177         virtual void HandleUserMouseInteraction(vtkTransform* userTransformation)=0;
00178 
00180         virtual int MaxNumberOfOutputItkSpatialObjects()=0;
00182         virtual unsigned int MaxNumberOfOutputImages()=0;
00183 
00185         std::map<std::string,DefOrgPropertyStruct> m_PropertyBag;
00186 
00187         std::vector< DefOrgLayerStruct > m_LayerBag;
00191         std::vector< SpatialObjectDescriptorStruct > m_OutputItkSpatialObjects;
00195         std::vector< OutputImageDescriptorStruct > m_OutputImages;
00196 
00198         virtual void AddOutputItkSpatialObjects(itkScenePointer itkScene){
00199                 m_OutputItkSpatialObjects.push_back(SpatialObjectDescriptorStruct(itkScene,false));
00200         }
00201         
00203         virtual void AddOutputImages(vtkImageImport* vtkImporter,int Offset){
00204                 m_OutputImages[Offset].theImageVolume = vtkImporter;
00205         }
00206 
00209         std::ostringstream theDefOrgTextOutput;
00211         std::stringstream theDefOrgTextInput;
00212         //DEFORG_TEXTOUTPUT_CALLBACK_FUNCTION theDefOrgTextOutputCallBack;
00213 
00214 protected:      
00215         bool m_Initialized;
00223         virtual void AddOrganismProperty(const char* propertyName, double lowerBound,   double upperBound, double defaultValue, double resolution=1.0, const char* helpString=""){
00224                 m_PropertyBag[propertyName]=DefOrgPropertyStruct(lowerBound,upperBound,defaultValue,defaultValue,resolution,std::string(helpString));
00225         }
00229         virtual double GetOrganismProperty(const char* propertyName){
00230                 std::map<std::string,DefOrgPropertyStruct>::iterator cur = m_PropertyBag.find(std::string(propertyName));
00231                 if ( m_PropertyBag.end()!= cur){
00232                         return (cur->second).currentValue;
00233                 }
00234                 return 0;
00235         }
00236 
00239         virtual void AddLayer(const char* layerName, const char** options, int numChoices);
00240 
00242         virtual const char* GetLayer(const char* layerName);
00243 
00244         std::string m_ImageFileName;
00245         std::string m_ScheduleFileName;
00246         std::string m_MeshFileName;             
00247         
00248         
00249 };
00250 }
00251 #endif

Generated on Wed Jul 19 13:05:16 2006 for IDO by  doxygen 1.4.7