00001
00002 #ifndef __vtkImageGraph_h
00003 #define __vtkImageGraph_h
00004
00005 #include "vtkImageSource.h"
00006 #include "vtkEMSegmentStep.h"
00007
00008
00009
00010 #define SET_PIXEL(x,y,color){ ptr =&outPtr[y*NumXScalar+x*3]; memcpy(ptr,color,3);}
00011
00012
00013
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
00033
00034
00035
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
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
00078
00079 vtkSetMacro(Xlength, int);
00080 vtkGetMacro(Xlength, int);
00081
00082
00083
00084 vtkSetMacro(Ylength, int);
00085 vtkGetMacro(Ylength, int);
00086
00087
00088
00089 vtkGetMacro(GraphMax, vtkFloatingPointType);
00090 vtkGetMacro(GraphMin, vtkFloatingPointType);
00091
00092
00093
00094 vtkSetVector2Macro(DataBackRange, int);
00095 vtkGetVector2Macro(DataBackRange, int);
00096
00097
00098 virtual void SetLookupTable(vtkScalarsToColors*);
00099 vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
00100
00101
00102
00103 vtkSetMacro(CurveThickness, int);
00104 vtkGetMacro(CurveThickness, int);
00105
00106
00107
00108
00109
00110 void SetIgnoreGraphMinGraphMax(vtkImageData *plot, int flag);
00111 int GetIgnoreGraphMinGraphMax(vtkImageData *plot);
00112
00113
00114
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
00121
00122 int AddCurveRegion(vtkImageData *plot,vtkFloatingPointType color0,vtkFloatingPointType color1,vtkFloatingPointType color2, int type, int ignore);
00123
00124
00125
00126 int DeleteCurveRegion(int id);
00127
00128
00129
00130 vtkIndirectLookupTable* CreateUniformIndirectLookupTable();
00131
00132
00133
00134
00135
00136 vtkLookupTable* CreateLookupTable(vtkFloatingPointType SatMin, vtkFloatingPointType SatMax, vtkFloatingPointType ValMin, vtkFloatingPointType ValMax, vtkFloatingPointType HueMin, vtkFloatingPointType HueMax);
00137
00138
00139
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&);
00171 void operator=(const vtkImageGraph&);
00172 };
00173
00174
00175
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