vtkSlicerSliceLogic.h

Go to the documentation of this file.
00001 /*=auto=========================================================================
00002 
00003   Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
00004 
00005   See Doc/copyright/copyright.txt
00006   or http://www.slicer.org/copyright/copyright.txt for details.
00007 
00008   Program:   3D Slicer
00009   Module:    $RCSfile: vtkSlicerSliceLogic.h,v $
00010   Date:      $Date: 2011-01-31 20:37:43 -0500 (Mon, 31 Jan 2011) $
00011   Version:   $Revision: 15879 $
00012 
00013 =========================================================================auto=*/
00014 
00022 //
00027 
00028 
00029 #ifndef __vtkSlicerSliceLogic_h
00030 #define __vtkSlicerSliceLogic_h
00031 
00032 #include <stdlib.h>
00033 
00034 #include "vtkSlicerBaseLogic.h"
00035 #include "vtkSlicerLogic.h"
00036 
00037 #include "vtkMRML.h"
00038 #include "vtkMRMLSliceNode.h"
00039 #include "vtkMRMLSliceCompositeNode.h"
00040 #include "vtkSlicerSliceLayerLogic.h"
00041 #include "vtkMRMLModelNode.h"
00042 
00043 #include "vtkImageBlend.h"
00044 #include "vtkCollection.h"
00045 #include "vtkPolyDataCollection.h"
00046 
00047 class vtkImageData;
00048 class vtkMRMLModelDisplayNode;
00049 class vtkMRMLLinearTransformNode;
00050 class vtkImageReslice;
00051 class vtkPolyDataCollection;
00052 class vtkCollection;
00053 
00054 class VTK_SLICER_BASE_LOGIC_EXPORT vtkSlicerSliceLogic : public vtkSlicerLogic 
00055 {
00056   public:
00057   
00059   static vtkSlicerSliceLogic *New();
00060   vtkTypeRevisionMacro(vtkSlicerSliceLogic,vtkSlicerLogic);
00061   void PrintSelf(ostream& os, vtkIndent indent);
00062 
00065   vtkGetObjectMacro (SliceNode, vtkMRMLSliceNode);
00066   void SetSliceNode (vtkMRMLSliceNode *SliceNode);
00067 
00070   vtkGetObjectMacro (SliceCompositeNode, vtkMRMLSliceCompositeNode);
00071   void SetSliceCompositeNode (vtkMRMLSliceCompositeNode *SliceCompositeNode);
00072 
00076   vtkGetObjectMacro (BackgroundLayer, vtkSlicerSliceLayerLogic);
00077   void SetBackgroundLayer (vtkSlicerSliceLayerLogic *BackgroundLayer);
00078 
00082   vtkGetObjectMacro (ForegroundLayer, vtkSlicerSliceLayerLogic);
00083   void SetForegroundLayer (vtkSlicerSliceLayerLogic *ForegroundLayer);
00084 
00088   vtkGetObjectMacro (LabelLayer, vtkSlicerSliceLayerLogic);
00089   void SetLabelLayer (vtkSlicerSliceLayerLogic *LabelLayer);
00090 
00095   vtkGetMacro (ForegroundOpacity, double);
00096   void SetForegroundOpacity (double ForegroundOpacity);
00097 
00102   vtkGetMacro (LabelOpacity, double);
00103   void SetLabelOpacity (double LabelOpacity);
00104 
00107   vtkGetObjectMacro (SliceModelNode, vtkMRMLModelNode);
00108 
00111   vtkGetObjectMacro (SliceModelDisplayNode, vtkMRMLModelDisplayNode);
00112 
00115   vtkGetObjectMacro (SliceModelTransformNode, vtkMRMLLinearTransformNode);
00116 
00120   vtkGetObjectMacro (Blend, vtkImageBlend);
00121 
00124   vtkGetObjectMacro (PolyDataCollection, vtkPolyDataCollection);
00125 
00128   vtkGetObjectMacro (LookupTableCollection, vtkCollection);
00129 
00133   vtkGetObjectMacro (ExtractModelTexture, vtkImageReslice);
00134 
00138   vtkImageData *GetImageData () { 
00139      if ( (this->GetBackgroundLayer() != NULL && this->GetBackgroundLayer()->GetImageData() != NULL) ||
00140          (this->GetForegroundLayer() != NULL && this->GetForegroundLayer()->GetImageData() != NULL) ||
00141          (this->GetLabelLayer() != NULL && this->GetLabelLayer()->GetImageData() != NULL) ) 
00142       {     
00143       return this->ImageData;
00144       }
00145      else
00146       {
00147       return NULL;
00148       }
00149   };
00150 
00151   void UpdateImageData () { 
00152     if ( (this->GetBackgroundLayer() != NULL && this->GetBackgroundLayer()->GetImageData() != NULL) ||
00153          (this->GetForegroundLayer() != NULL && this->GetForegroundLayer()->GetImageData() != NULL) ||
00154          (this->GetLabelLayer() != NULL && this->GetLabelLayer()->GetImageData() != NULL) ) 
00155       {     
00156       if ( this->Blend->GetInput(0) != NULL ) 
00157         {
00158         this->Blend->Update(); 
00159         }
00160       //this->ImageData = this->Blend->GetOutput();
00161       if (this->ImageData== NULL || this->Blend->GetOutput()->GetMTime() > this->ImageData->GetMTime())
00162         {
00163         if (this->ImageData== NULL)
00164           {
00165           this->ImageData = vtkImageData::New();
00166           }
00167         this->ImageData->DeepCopy( this->Blend->GetOutput()); 
00168         this->ExtractModelTexture->SetInput( this->ImageData );
00169         vtkTransform *activeSliceTransform = vtkTransform::New();
00170         activeSliceTransform->Identity();
00171         activeSliceTransform->Translate(0, 0, this->SliceNode->GetActiveSlice() );
00172         this->ExtractModelTexture->SetResliceTransform( activeSliceTransform );
00173         activeSliceTransform->Delete();
00174         }
00175       }
00176     else 
00177       {
00178       if (this->ImageData)
00179         {
00180         this->ImageData->Delete();
00181         }
00182       this->ImageData=NULL;
00183       this->ExtractModelTexture->SetInput( this->ImageData );
00184       }
00185   };
00186 
00189   void UpdatePipeline ();
00190 
00195   virtual void ProcessMRMLEvents ( vtkObject * /*caller*/, 
00196                                   unsigned long /*event*/, 
00197                                   void * /*callData*/ );
00198   virtual void ProcessMRMLEvents () { this->ProcessMRMLEvents( NULL, vtkCommand::NoEvent, NULL ); };
00199 
00202   virtual void ProcessLogicEvents ( vtkObject * /*caller*/, 
00203                                   unsigned long /*event*/, 
00204                                   void * /*callData*/ ) {this->ProcessLogicEvents();};
00205   void ProcessLogicEvents(); 
00206 
00209   void UpdateSliceNode();
00210 
00213   void UpdateSliceNodeFromLayout();
00214 
00217   void UpdateSliceCompositeNode();
00218 
00222   vtkMRMLVolumeNode *GetLayerVolumeNode(int layer);
00223 
00226   static void GetVolumeRASBox(vtkMRMLVolumeNode *volumeNode, double rasDimensions[3], double rasCenter[3]);
00227 
00230   void GetVolumeSliceDimensions(vtkMRMLVolumeNode *volumeNode, double sliceDimensions[3], double sliceCenter[3]);
00231 
00236   double *GetVolumeSliceSpacing(vtkMRMLVolumeNode *volumeNode);
00237 
00242   void GetVolumeSliceBounds(vtkMRMLVolumeNode *volumeNode, double sliceBounds[6]);
00243 
00246   void FitSliceToVolume(vtkMRMLVolumeNode *volumeNode, int width, int height);
00247 
00250   void GetBackgroundRASBox(double rasDimensions[3], double rasCenter[3]);
00251 
00254   void GetBackgroundSliceDimensions(double sliceDimensions[3], double sliceCenter[3]);
00255 
00260   double *GetBackgroundSliceSpacing();
00261 
00266   void GetBackgroundSliceBounds(double sliceBounds[6]);
00267 
00270   void FitSliceToBackground(int width, int height);
00271 
00275   void FitSliceToAll(int width, int height);
00276 
00279   vtkMRMLVolumeNode *GetLowestVolumeNode();
00280 
00286   double *GetLowestVolumeSliceSpacing();
00287 
00293   void GetLowestVolumeSliceBounds(double sliceBounds[6]);
00294 
00297   double GetSliceOffset();
00298   void SetSliceOffset(double offset);
00299 
00305   void CalculateSliceOffset(double offset, double oldOffsetVector[4], double newOffsetVector[4]);
00306 
00310   void SnapSliceOffsetToIJK();
00311 
00312   static const int SLICE_INDEX_ROTATED;
00313   static const int SLICE_INDEX_OUT_OF_VOLUME;
00314   static const int SLICE_INDEX_NO_VOLUME;
00315 
00322   int GetSliceIndexFromOffset(double sliceOffset, vtkMRMLVolumeNode *volumeNode);
00323 
00333   int GetSliceIndexFromOffset(double sliceOffset);
00334 
00337   void CreateSliceModel();
00338   void DeleteSliceModel();
00339   
00342   void GetPolyDataAndLookUpTableCollections(vtkPolyDataCollection *PolyDataCollection,
00343                                             vtkCollection *LookupTableCollection);
00344 //BTX                                            
00347   std::vector< vtkMRMLDisplayNode*> GetPolyDataDisplayNodes();
00348 //ETX
00349 
00350 protected:
00351   vtkSlicerSliceLogic();
00352   ~vtkSlicerSliceLogic();
00353   vtkSlicerSliceLogic(const vtkSlicerSliceLogic&);
00354   void operator=(const vtkSlicerSliceLogic&);
00355 
00357   //
00358   vtkMRMLSliceNode *SliceNode;
00359   vtkMRMLSliceCompositeNode *SliceCompositeNode;
00360   vtkSlicerSliceLayerLogic *BackgroundLayer;
00361   vtkSlicerSliceLayerLogic *ForegroundLayer;
00362   vtkSlicerSliceLayerLogic *LabelLayer;
00363 
00364   double ForegroundOpacity;
00365   double LabelOpacity;
00366   vtkImageBlend *Blend;
00367   vtkImageData *ImageData;
00368   vtkImageReslice *ExtractModelTexture;
00369 
00370   vtkPolyDataCollection *PolyDataCollection;
00371   vtkCollection *LookupTableCollection;
00372 
00373   vtkMRMLModelNode *SliceModelNode;
00374   vtkMRMLModelDisplayNode *SliceModelDisplayNode;
00375   vtkMRMLLinearTransformNode *SliceModelTransformNode;
00376   double SliceSpacing[3];
00377   
00378   void AddSliceGlyphs(vtkSlicerSliceLayerLogic *layerLogic);
00379 
00380 };
00381 
00382 #endif
00383 

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1