C:/cmcintos/defOrgs/examples/DefOrgViewer/Source/DefOrgViewer.h

00001 #ifndef DefOrgViewer_h
00002 #define DefOrgViewer_h
00003 
00004 #include "DefOrgViewerGUI.h"
00005 
00006 
00007 //---------------------------------
00008 
00009 // ITK includes:
00010 #include "itkImage.h"
00011 #include "itkImageFileReader.h"
00012 #include "itkEllipseSpatialObject.h"
00013 #include "itkBlobSpatialObject.h"
00014 #include "itkSceneSpatialObject.h"
00015 #include "itkMeshSpatialObject.h"
00016 #include "itkGroupSpatialObject.h"
00017 #include "itkSpatialObjectReader.h"
00018 #include "itkImageSpatialObject.h"
00019 #include "itkMinimumMaximumImageFilter.h"
00020 #include "itkVTKImageExport.h"
00021 #include <itkCastImageFilter.h>
00022 
00023 #include <itkRegularSphereMeshSource.h> // TEMP DEBUG
00024 
00025 // std includes:
00026 #include <iostream>
00027 
00028 // VTK includes:
00029 #include <vtkPointPicker.h>
00030 #include "vtkRenderWindow.h"
00031 #include "vtkImageImport.h"
00032 #include "vtkImagePlaneWidget.h"
00033 #include "vtkImageActor.h"
00034 #include <vtkImageViewer.h>
00035 #include "vtkImplicitPlaneWidget.h" // DEBUG
00036 //#include "vtkJPEGReader.h" // DEBUG
00037 //#include "vtkJPEGWriter.h" // DEBUG
00038 #include "vtkVolumeMapper.h"
00039 #include <vtkMetaImageReader.h>
00040 //#include <vtkImageCast.h>
00041 // volume rendering stuff:
00042 #include <vtkPiecewiseFunction.h>
00043 #include "vtkColorTransferFunction.h"
00044 #include "vtkVolumeProperty.h"
00045 #include "vtkVolumeRayCastCompositeFunction.h"
00046 #include "vtkVolumeRayCastMIPFunction.h"
00047 #include "vtkVolumeRayCastMapper.h"
00048 #include "vtkVolume.h"
00049 #include "vtkCamera.h"
00050 #include "vtkLight.h"
00051 #include "vtkInteractorStyleTrackballActor.h"
00052 #include "vtkCubeAxesActor2D.h"
00053 #include "vtkProperty2D.h"
00054 
00055 #include "vtkRenderer.h"
00056 #include "vtkOpenGLRenderer.h"
00057 #include "vtkUnstructuredGrid.h"
00058 #include "vtkCellArray.h"
00059 #include "vtkProperty.h"
00060 #include "vtkDataSetMapper.h"
00061 #include "vtkImageData.h"
00062 #include "vtkDataSet.h"
00063 
00064 // other includes:
00065 //#include "vtk2itk.cxx" // TEMP DEBUG
00066 // vtkFlRenderWindowInteractor.h is included from DefOrgViewGUI.h
00067 #include <itkMetaImageIOFactory.h>
00068 #include "BYUToMeta.h"
00069 #include "itkImageFileReader.h"
00070 #include "itkImageFileWriter.h"
00071 #include "itkMeanImageFilter.h"
00072 #include "itkBinaryThresholdImageFilter.h"
00073 #include "itkCovariantVector.h"
00074 #include <iostream>
00075 #include "itkOrganism.h"
00076 #include "Phys_Euler.h"
00077 #include "Ctrl_ScheduleDriven.h"
00078 #include "Beh_TranslateAll.h"
00079 #include "Def_Translation.h"
00080 #include "Sense_Gradient.h"
00081 #include "Geom_MeshSpatialObject.h"
00082 #include "Phys_LevelSet.h"
00083 
00084 #define N_DIMS 3
00085 
00086 class VistVTKCellsClass; // predeclaration 
00087 
00088 class DefOrgViewer
00089         : public DefOrgViewerGUI
00090 {
00091 public:
00092         // typedefs for the defOrg:
00093         typedef float                                                                                   DataType;
00094         typedef unsigned char                                                                   PixelType;
00095         typedef itk::Image< PixelType, N_DIMS >                                 ImageType;
00096         typedef  Geom_MeshSpatialObject< DataType, N_DIMS >             GeometricType;
00097         typedef itk::CovariantVector< DataType, N_DIMS >                GradientPixelType;
00098         typedef itk::Image< GradientPixelType, N_DIMS >                 GradientImageType;
00099         typedef Phys_LevelSet< DataType, ImageType, N_DIMS >    LevelSetPhysicsType;
00100         typedef Phys_Euler< DataType, 
00101                 GradientImageType, N_DIMS >                                                     EulerPhysicsType;
00102         typedef Sense_Gradient< DataType, ImageType, 
00103                 GradientImageType, N_DIMS >                                                     GradientSensorType;
00104         typedef Ctrl_ScheduleDriven<DataType, N_DIMS>                   CognitiveType;
00105         typedef Beh_TranslateAll<DataType, N_DIMS>                              Beh_TranslateAllType;
00106         typedef Def_Translation<DataType, N_DIMS>                               Def_TranslateAllType;
00107 
00108         typedef itk::ItkOrganism < ImageType, ImageType,
00109                 GradientImageType, DataType, N_DIMS >                           OrganismType;
00110 
00111         typedef itk::DefaultDynamicMeshTraits<
00112                 DataType, N_DIMS, N_DIMS >                                                      MeshTrait;
00113         typedef  itk::Mesh< DataType, N_DIMS, MeshTrait >               MeshType;
00114         typedef  MeshType::Pointer                                                              MeshTypePointer;
00115         //typedef  itk::SpatialObject< N_DIMS >                         SpatialObjectType;
00116         //typedef  itk::MeshSpatialObject< MeshType >                   MeshSpatialObjectType;
00117         //typedef  itk::SceneSpatialObject< N_DIMS >                    SceneType;
00118         //typedef  SceneType::Pointer                                                   ScenePointer;
00119         //typedef  itk::GroupSpatialObject< N_DIMS >                    GroupType;
00120         //typedef  GroupType::Pointer                                                   GroupPointer;
00121 
00122         // typedefs for DefOrgViewer app:
00123         //typedef  vtkOpenGLRenderer                                                                    RendererType;
00124         typedef  vtkRenderer                                                                    RendererType;
00125         typedef  RendererType*                                                                  RendererPointer;
00126         typedef  itk::VTKImageExport< ImageType >                               itkImageExportType;
00127         typedef  vtkImageImport                                                                 vtkImageImportType;
00128 
00129         typedef itk::ImageFileReader< ImageType >                               ImageReaderType;
00130         ImageReaderType::Pointer                                                                imageReader;
00131         
00132         // typedefs for itk->vtk mesh conversion:
00133         typedef itk::CellInterfaceVisitorImplementation<
00134                 DataType, MeshType::CellTraits,
00135                 itk::TriangleCell< itk::CellInterface<MeshType::PixelType, MeshType::CellTraits > >, 
00136                 VistVTKCellsClass> TriangleVisitor;
00137 
00138         typedef itk::CellInterfaceVisitorImplementation<
00139                 DataType, MeshType::CellTraits,
00140                 itk::QuadrilateralCell< itk::CellInterface<MeshType::PixelType, MeshType::CellTraits > >, 
00141                 VistVTKCellsClass> QuadrilateralVisitor;
00142 
00143         // constructors:
00144         DefOrgViewer();                 
00145         DefOrgViewer( MeshTypePointer itkMesh );
00146 
00147         // overrides of FLUID-created functions in DefOrgViewerGUI:
00148         void Quit();
00149         void Show();
00150         void Update();
00151         void LoadImage();
00152         void LoadMeta();
00153         void TogglePlayPause();
00154         void ToggleVolumeRendering();
00155         void TransferSlider1();
00156         void TransferSlider2();
00157 
00158 
00159         // class utility functions:
00160         vtkUnstructuredGrid* MeshToUnstructuredGrid( MeshType::Pointer itkMesh );
00161         void ConnectPipelines( itkImageExportType::Pointer exporter, vtkImageImportType* importer);
00162         void SetupOrganism();
00163         void UpdateOrganism();
00164 
00165 private:
00166         // defOrg components:
00167         OrganismType::Pointer                   testOrg;
00168         LevelSetPhysicsType                             levelSetPhysLayer;
00169         EulerPhysicsType *                              eulerPhysLayerPointer;
00170         GradientSensorType::sensorIn    sensorInput;
00171         GradientSensorType                              gradientSensor;
00172         GeometricType*                                  geomLayerPointer;
00173         CognitiveType*                                  cognitiveLayerPointer;
00174         Beh_TranslateAllType                    * beh1;
00175         Def_TranslateAllType                    * def1;                                                         
00176 
00177         // DefOrgViewer components:
00178         vtkCubeAxesActor2D*                             axes;
00179         vtkLight*                                               light;
00180         vtkCamera*                                              camera;
00181         vtkImagePlaneWidget*                    planeX;
00182         ImageType::Pointer                              image;
00183         RendererPointer                                 renderer;
00184         vtkRenderWindow*                                renderWindow;
00185         itkImageExportType::Pointer             itkExporter;
00186         vtkImageImport*                                 vtkImporter;
00187 
00188         // volume rendering components:
00189         vtkPiecewiseFunction*                   opacityTransferFunction;
00190         vtkColorTransferFunction*               colorTransferFunction;
00191         vtkVolumeRayCastCompositeFunction* compositeFunction;
00192         vtkVolumeRayCastMIPFunction*    MIPFunction;
00193         vtkVolumeProperty*                              volumeProperty;
00194         vtkVolumeRayCastMapper*                 volumeMapper;
00195         vtkVolume*                                              volume;
00196         vtkDataSetMapper*                               meshMapper;
00197         vtkActor*                                               meshActor;
00198 
00199         //vtkInteractorStyleTrackballActor* trackBallInteractor;
00200 
00201         std::string                                             scheduleFileName;
00202         bool                                                    isVolumeRenderingOn;
00203         bool                                                    orgNotSet;
00204         
00205 };
00206 
00207 
00208 //**********************************************************************
00209 
00210 class VistVTKCellsClass
00211 {
00212         vtkCellArray* m_Cells;
00213         int* m_LastCell;
00214         int* m_TypeArray;
00215 public:
00216         // typedef the itk cells we are interested in
00217         typedef itk::CellInterface<
00218                 DefOrgViewer::MeshType::PixelType, 
00219                 DefOrgViewer::MeshType::CellTraits >  CellInterfaceType;
00220 
00221         typedef itk::TriangleCell<CellInterfaceType>      floatTriangleCell;
00222         typedef itk::QuadrilateralCell<CellInterfaceType> floatQuadrilateralCell;
00223 
00224         // Set the vtkCellArray that will be constructed
00225         void SetCellArray(vtkCellArray* a) 
00226         {
00227                 m_Cells = a;
00228         }
00229         // Set the cell counter pointer
00230         void SetCellCounter(int* i)
00231         {
00232                 m_LastCell = i;
00233         }
00234         // Set the type array for storing the vtk cell types
00235         void SetTypeArray(int* i)
00236         {
00237                 m_TypeArray = i;
00238         }
00239         // Visit a triangle and create the VTK_TRIANGLE cell 
00240         void Visit(unsigned long, floatTriangleCell* t)
00241         {
00242                 m_Cells->InsertNextCell(3,  (vtkIdType*)t->PointIdsBegin());
00243                 m_TypeArray[*m_LastCell] = VTK_TRIANGLE;
00244                 (*m_LastCell)++;
00245         }
00246         // Visit a triangle and create the VTK_QUAD cell 
00247         void Visit(unsigned long, floatQuadrilateralCell* t)
00248         {
00249                 m_Cells->InsertNextCell(4,  (vtkIdType*)t->PointIdsBegin());
00250                 m_TypeArray[*m_LastCell] = VTK_QUAD;
00251                 (*m_LastCell)++;
00252         }
00253 };
00254 
00255 //**********************************************************************
00256 
00257 #endif // DefOrgViewer defined

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