vtkImageGraph.h

Go to the documentation of this file.
00001 // .NAME vtkImageGraph - Abstract Filter used in slicer to plot graphs
00002 #ifndef __vtkImageGraph_h
00003 #define __vtkImageGraph_h
00004 
00005 #include "vtkImageSource.h"
00006 #include "vtkEMSegmentStep.h"
00007 
00008 
00009 // From vtkImagePlot
00010 #define SET_PIXEL(x,y,color){ ptr  =&outPtr[y*NumXScalar+x*3]; memcpy(ptr,color,3);}
00011 
00012 
00013 //BTX
00014 class   VTK_EMSEGMENT_EXPORT GraphList {
00015 public:
00016    vtkFloatingPointType* GetColor() {return this->Color;}
00017    void SetColor (vtkFloatingPointType value[3]) {memcpy(this->Color,value,sizeof(vtkFloatingPointType)*3);}
00018 
00019    void SetType(int val) {this->Type = val; }
00020    int GetType() {return this->Type; }
00021 
00022    int GetID() {return this->ID;}
00023 
00024   ~GraphList() {this->ID = -1;} 
00025    GraphList();
00026 
00027    vtkFloatingPointType Color[3];
00028    int ID;
00029    int Type;
00030 }; 
00031 
00032 // Description:
00033 // Type of curve:
00034 //  0 = curve representing contious data (e.g. /) 
00035 //  1 = curve representing discrete data (e.g. _|) 
00036 class  VTK_EMSEGMENT_EXPORT GraphEntryList : public GraphList {
00037 public:
00038    vtkImageData* GetGraphEntry() {return this->GraphEntry;} 
00039    void SetGraphEntry(vtkImageData* value) {this->GraphEntry = value;} 
00040 
00041    GraphEntryList* GetNext() {return this->Next;} 
00042 
00043    void SetIgnoreGraphMinGraphMax(bool flag) {this->IgnoreGraphMinGraphMax = flag;} 
00044    bool GetIgnoreGraphMinGraphMax() {return this->IgnoreGraphMinGraphMax;}
00045 
00046    int AddEntry(vtkImageData* plot, vtkFloatingPointType col[3],int type, bool ignore);  
00047    int DeleteEntry(int delID);
00048 
00049    GraphEntryList* MatchGraphEntry(vtkImageData* value);
00050 
00051    int GetNumFollowingEntries();
00052 
00053    GraphEntryList();
00054    ~GraphEntryList();
00055 
00056 protected:
00057 
00058    vtkImageData* GraphEntry;
00059    bool IgnoreGraphMinGraphMax;
00060    GraphEntryList* Next; 
00061 };
00062 //ETX
00063 class vtkScalarsToColors;
00064 class vtkIndirectLookupTable;
00065 class vtkLookupTable;
00066 
00067 class VTK_EMSEGMENT_EXPORT vtkImageGraph : public vtkImageSource
00068 {
00069 public:
00070   static vtkImageGraph *New();
00071   vtkTypeMacro(vtkImageGraph,vtkImageSource);
00072   void PrintSelf(ostream& os, vtkIndent indent);
00073 
00074   vtkSetMacro(Dimension, int);
00075   vtkGetMacro(Dimension, int);
00076 
00077   // Description:
00078   // Length of canvas/graph in X direction
00079   vtkSetMacro(Xlength, int);
00080   vtkGetMacro(Xlength, int);
00081 
00082   // Description:
00083   // Length of canvas/graph in Y direction
00084   vtkSetMacro(Ylength, int);
00085   vtkGetMacro(Ylength, int);
00086 
00087   // Description:
00088   // Global extrema over all the curves/regions 
00089   vtkGetMacro(GraphMax, vtkFloatingPointType);
00090   vtkGetMacro(GraphMin, vtkFloatingPointType);
00091 
00092   // Description:
00093   // Define the value range of the background (i.e. LookupTable)
00094   vtkSetVector2Macro(DataBackRange, int);
00095   vtkGetVector2Macro(DataBackRange, int);
00096 
00097   // Defines Background of Graph
00098   virtual void SetLookupTable(vtkScalarsToColors*);
00099   vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
00100    
00101   // Description:
00102   // Thickness for the curve 
00103   vtkSetMacro(CurveThickness, int);
00104   vtkGetMacro(CurveThickness, int);
00105 
00106   // Description: 
00107   // Ignore the GraphMin - GraphMax setting of the graph
00108   // This only makes sense in 1D when we plot two curves with independent output range
00109   // e.g. histogram and gaussian curve.
00110   void SetIgnoreGraphMinGraphMax(vtkImageData *plot, int flag);
00111   int GetIgnoreGraphMinGraphMax(vtkImageData *plot);
00112 
00113   // Description: 
00114   // Set the color of a curve 
00115   void SetColor(vtkImageData *plot, vtkFloatingPointType color0, vtkFloatingPointType color1,vtkFloatingPointType color2);
00116   vtkFloatingPointType* GetColor(vtkImageData *plot);
00117 
00118   GraphEntryList* GetGraphList() { return &this->GraphList;}
00119 
00120   // Description:
00121   // Add a curve or region to the graph. It returns the ID of the data entry back
00122   int AddCurveRegion(vtkImageData *plot,vtkFloatingPointType color0,vtkFloatingPointType color1,vtkFloatingPointType color2, int type, int ignore);
00123 
00124   // Description:
00125   // Delete a curve/region from the list -> if successfull returns 1 - otherwise 0; 
00126   int DeleteCurveRegion(int id);
00127 
00128   // Description:
00129   // Creates a Indirect Lookup Table just with white color => needed to genereate a simple background  
00130   vtkIndirectLookupTable* CreateUniformIndirectLookupTable();
00131 
00132   // Description:
00133   // Creates a Lookup Table - if you want to change the color of the IndirectLookupTable
00134   // you first have to delete the old LookupTable and than recreate it with this function
00135   // and assign it again to the IndirectLookupTable
00136   vtkLookupTable* CreateLookupTable(vtkFloatingPointType SatMin, vtkFloatingPointType SatMax, vtkFloatingPointType ValMin, vtkFloatingPointType ValMax, vtkFloatingPointType HueMin, vtkFloatingPointType HueMax); 
00137 
00138   // Description:
00139   // Change the color of the Indirect Table 
00140   void ChangeColorOfIndirectLookupTable(vtkIndirectLookupTable* Table, vtkFloatingPointType SatMin, vtkFloatingPointType SatMax, vtkFloatingPointType ValMin, vtkFloatingPointType ValMax, vtkFloatingPointType HueMin, vtkFloatingPointType HueMax);
00141 
00142   unsigned long GetMTime();
00143 protected:
00144   vtkImageGraph();
00145   void DeleteVariables();
00146   ~vtkImageGraph() {this->DeleteVariables();};
00147   virtual void ExecuteInformation();
00148   virtual void ExecuteData(vtkDataObject *data);
00149 
00150   void Draw1DGraph(vtkImageData *data);
00151   void Draw2DGraph(vtkImageData *data,int NumRegion, vtkFloatingPointType* CurveRegionMin, vtkFloatingPointType* CurveRegionMax);
00152   void CalculateGraphMinGraphMax (vtkFloatingPointType* CurveRegionMin, vtkFloatingPointType* CurveRegionMax);
00153   void DrawBackground(unsigned char *outPtr, int outIncY);
00154 
00155   int Dimension;
00156   int CurveThickness;
00157  
00158   int Xlength;
00159   int Ylength;
00160 
00161   vtkFloatingPointType GraphMin;
00162   vtkFloatingPointType GraphMax;
00163 
00164   GraphEntryList GraphList;
00165  
00166   vtkScalarsToColors *LookupTable;
00167   int DataBackRange[2];
00168 
00169 private:
00170   vtkImageGraph(const vtkImageGraph&);  // Not implemented.
00171   void operator=(const vtkImageGraph&);  // Not implemented.
00172 };
00173 
00174 //----------------------------------------------------------------------------
00175 // from vtkImagePlot
00176 inline void ConvertColor(vtkFloatingPointType *f, unsigned char *c)
00177 {
00178     c[0] = (int)(f[0] * 255.0);
00179     c[1] = (int)(f[1] * 255.0);
00180     c[2] = (int)(f[2] * 255.0);
00181 }
00182 
00183 //----------------------------------------------------------------------------
00184 inline void DrawThickPoint (int Xpos, int Ypos, unsigned char color[3], unsigned char *outPtr, 
00185                 int NumXScalar, int radius) {
00186   unsigned char *ptr;
00187   int x ,y;
00188   Xpos -= radius;
00189   for (x = -radius; x <= radius; x++) {
00190     for (y = -radius; y <= radius; y++) SET_PIXEL(Xpos, y+Ypos, color);
00191     Xpos ++;
00192   }
00193 }
00194 
00195 //----------------------------------------------------------------------------
00196 inline void DrawContinousLine(int xx1, int yy1, int xx2, int yy2, unsigned char color[3],
00197                               unsigned char *outPtr, int NumXScalar, int radius) {
00198   vtkFloatingPointType slope; 
00199   int Yold = yy1, Ynew, x,y;
00200 
00201   if (xx2 != xx1)  {
00202     slope = vtkFloatingPointType(yy2 - yy1)/vtkFloatingPointType(xx2 - xx1);
00203     DrawThickPoint(xx1, yy1, color, outPtr, NumXScalar, radius);
00204     for(x=xx1+1; x <=  xx2; x++) { 
00205       Ynew = (int) slope*(x - xx1) + yy1; 
00206       if (slope < 0) for (y = Yold; y >= Ynew; y --) DrawThickPoint(x, y, color, outPtr, NumXScalar, radius); 
00207       else  for (y = Yold; y <= Ynew; y ++)  DrawThickPoint(x, y, color, outPtr, NumXScalar, radius);
00208       Yold = Ynew; 
00209     } 
00210   } else {
00211     if (yy1 > yy2) { 
00212       for (y = yy2; y <= yy1; y++) DrawThickPoint(xx1, y, color, outPtr, NumXScalar, radius); 
00213     } else for (y = yy1; y <= yy2; y++) DrawThickPoint(xx1, y, color, outPtr, NumXScalar, radius); 
00214   }
00215 }
00216 #endif
00217 
00218   

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1