VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Rendering/Context2D/vtkContext2D.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkContext2D.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00032 #ifndef vtkContext2D_h
00033 #define vtkContext2D_h
00034 
00035 #include "vtkRenderingContext2DModule.h" // For export macro
00036 #include "vtkObject.h"
00037 
00038 class vtkWindow;
00039 
00040 class vtkContext3D;
00041 class vtkStdString;
00042 class vtkUnicodeString;
00043 class vtkTextProperty;
00044 
00045 class vtkPoints2D;
00046 class vtkVector2f;
00047 class vtkRectf;
00048 class vtkUnsignedCharArray;
00049 class vtkContextDevice2D;
00050 class vtkPen;
00051 class vtkBrush;
00052 class vtkImageData;
00053 class vtkTransform2D;
00054 class vtkAbstractContextBufferId;
00055 
00056 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
00057 {
00058 public:
00059   vtkTypeMacro(vtkContext2D, vtkObject);
00060   virtual void PrintSelf(ostream &os, vtkIndent indent);
00061 
00063   static vtkContext2D *New();
00064 
00065 //BTX
00069   bool Begin(vtkContextDevice2D *device);
00070 
00071   vtkGetObjectMacro(Device, vtkContextDevice2D);
00072 
00076   bool End();
00077 
00080   bool GetBufferIdMode() const;
00081 
00084   void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId);
00085 
00089   void BufferIdModeEnd();
00090 
00092   void DrawLine(float x1, float y1, float x2, float y2);
00093 
00095   void DrawLine(float p[4]);
00096 
00099   void DrawLine(vtkPoints2D *points);
00100 
00102   void DrawPoly(float *x, float *y, int n);
00103 
00106   void DrawPoly(vtkPoints2D *points);
00107 
00111   void DrawPoly(float *points, int n);
00112 
00114 
00119   void DrawPoly(float *points, int n,
00120                 unsigned char *colors, int nc_comps);
00122 
00124   void DrawPoint(float x, float y);
00125 
00127   void DrawPoints(float *x, float *y, int n);
00128 
00131   void DrawPoints(vtkPoints2D *points);
00132 
00136   void DrawPoints(float *points, int n);
00137 
00141   void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points);
00142 
00144 
00149   void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points,
00150                         vtkUnsignedCharArray *colors);
00151   void DrawPointSprites(vtkImageData *sprite, float *points, int n,
00152                         unsigned char *colors, int nc_comps);
00154 
00158   void DrawPointSprites(vtkImageData *sprite, float *points, int n);
00159 
00161 
00167   virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
00168                            unsigned char *colors, int nc_comps);
00169   virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
00170   virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
00171   virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
00172                            vtkUnsignedCharArray *colors);
00174 
00176   void DrawRect(float x, float y, float w, float h);
00177 
00179 
00181   void DrawQuad(float x1, float y1, float x2, float y2,
00182                 float x3, float y3, float x4, float y4);
00183   void DrawQuad(float *p);
00185 
00187 
00188   void DrawQuadStrip(vtkPoints2D *points);
00189   void DrawQuadStrip(float *p, int n);
00191 
00194   void DrawPolygon(float *x, float *y, int n);
00195 
00198   void DrawPolygon(vtkPoints2D *points);
00199 
00203   void DrawPolygon(float *points, int n);
00204 
00207   void DrawEllipse(float x, float y, float rx, float ry);
00208 
00210 
00215   void DrawWedge(float x, float y, float outRadius,
00216                  float inRadius,float startAngle,
00217                  float stopAngle);
00219 
00221 
00227   void DrawEllipseWedge(float x, float y, float outRx, float outRy,
00228                         float inRx, float inRy, float startAngle,
00229                         float stopAngle);
00231 
00232 
00234 
00237   void DrawArc(float x, float y, float r, float startAngle,
00238                float stopAngle);
00240 
00242 
00245   void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
00246                        float stopAngle);
00248 
00249 
00251   void DrawImage(float x, float y, vtkImageData *image);
00252 
00255   void DrawImage(float x, float y, float scale, vtkImageData *image);
00256 
00260   void DrawImage(const vtkRectf& pos, vtkImageData *image);
00261 
00263 
00266   void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
00267   void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
00268   void DrawStringRect(vtkPoints2D *rect, const char* string);
00270 
00272 
00273   void DrawString(vtkPoints2D *point, const vtkStdString &string);
00274   void DrawString(float x, float y, const vtkStdString &string);
00275   void DrawString(vtkPoints2D *point, const vtkUnicodeString &string);
00276   void DrawString(float x, float y, const vtkUnicodeString &string);
00277   void DrawString(vtkPoints2D *point, const char* string);
00278   void DrawString(float x, float y, const char* string);
00280 
00282 
00286   void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
00287   void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
00288   void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
00289   void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
00290   void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
00291   void ComputeStringBounds(const char* string, float bounds[4]);
00293 
00295 
00300   int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
00301                                       float height);
00303 
00305 
00311   void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string);
00312   void DrawMathTextString(float x, float y, const vtkStdString &string);
00313   void DrawMathTextString(vtkPoints2D *point, const char *string);
00314   void DrawMathTextString(float x, float y, const char *string);
00316 
00318 
00324   void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string,
00325                           const vtkStdString &fallback);
00326   void DrawMathTextString(float x, float y, const vtkStdString &string,
00327                           const vtkStdString &fallback);
00328   void DrawMathTextString(vtkPoints2D *point, const char *string,
00329                           const char *fallback);
00330   void DrawMathTextString(float x, float y, const char *string,
00331                           const char *fallback);
00333 
00334 
00336   bool MathTextIsSupported();
00337 
00342   void ApplyPen(vtkPen *pen);
00343 
00347   vtkPen* GetPen();
00348 
00353   void ApplyBrush(vtkBrush *brush);
00354 
00357   vtkBrush* GetBrush();
00358 
00362   void ApplyTextProp(vtkTextProperty *prop);
00363 
00365   vtkTextProperty* GetTextProp();
00366 
00370   void SetTransform(vtkTransform2D *transform);
00371 
00373   vtkTransform2D* GetTransform();
00374 
00379   void AppendTransform(vtkTransform2D *transform);
00380 
00382 
00384   void PushMatrix();
00385   void PopMatrix();
00387 
00389   void ApplyId(vtkIdType id);
00390 
00394   static int FloatToInt(float x);
00395 
00397 
00399   vtkGetObjectMacro(Context3D, vtkContext3D)
00400   virtual void SetContext3D(vtkContext3D *context);
00402 
00403 //BTX
00404 protected:
00405   vtkContext2D();
00406   ~vtkContext2D();
00407 
00408   vtkContextDevice2D *Device; // The underlying device
00409   vtkTransform2D *Transform;  // Current transform
00410 
00411   vtkAbstractContextBufferId *BufferId;
00412   vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
00413 
00414 private:
00415   vtkContext2D(const vtkContext2D &); // Not implemented.
00416   void operator=(const vtkContext2D &);   // Not implemented.
00417 
00419   vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
00420 
00421 //ETX
00422 };
00423 
00424 inline int vtkContext2D::FloatToInt(float x)
00425 {
00426   // Use a tolerance of 1/256 of a pixel when converting.
00427   // A float has only 24 bits of precision, so we cannot
00428   // make the tolerance too small.  For example, a tolerance
00429   // of 2^-8 means that the tolerance will be significant
00430   // for float values up to 2^16 or 65536.0.  But a
00431   // tolerance of 2^-16 would only be significant for
00432   // float values up to 2^8 or 256.0.  A small tolerance
00433   // disappears into insignificance when added to a large float.
00434   float tol = 0.00390625; // 1.0/256.0
00435   tol = (x >= 0 ? tol : -tol);
00436   return static_cast<int>(x + tol);
00437 }
00438 
00439 #endif //vtkContext2D_h