vtkTextureText.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: vtkTextureText.h,v $
00010   Date:      $Date: 2006/05/26 19:59:45 $
00011   Version:   $Revision: 1.3 $
00012 
00013 =========================================================================auto=*/
00014 /*===========================================================
00015 
00016 Authors: Michael McKenna, David Small, Steve Pieper.
00017     Small Design Firm, Inc.,
00018     in association with Isomics, Inc.,
00019     and Partners Health Care.  MA, USA.
00020     June, 2004
00021 
00022 ===========================================================*/
00023 
00024 
00025 #ifndef __vtkTextureText_h
00026 #define __vtkTextureText_h
00027 
00028 #include "vtkObject.h"
00029 #include "vtkFreetypeRasterizer.h"
00030 #include "vtkTextureFont.h"
00031 #include <vtkQueryAtlasConfigure.h>
00032 #include <vtkFollower.h>
00033 
00034 #include "vtkTextureTextPolys.h"
00035 #include "vtkFontParameters.h"
00036 
00037 #include <vector>
00038 #include <vector>
00039 
00040 
00041 class vtkRenderer;
00042 
00043 
00044 // Alignment - must be one of the following 
00045 #define VTK_TEXT_ALIGNMENT_FLUSH_LEFT       (0)
00046 #define VTK_TEXT_ALIGNMENT_FLUSH_RIGHT      (1)
00047 #define VTK_TEXT_ALIGNMENT_JUSTIFIED        (2)
00048 #define VTK_TEXT_ALIGNMENT_CENTERED         (3)
00049 #define VTK_TEXT_ALIGNMENT_MONOSPACE        (4)
00050 
00051 #define VTK_TEXT_NLCHAR      'n'
00052 #define VTK_TEXT_SPACECHAR   'i'
00053 
00054 #define VTK_TEXT_BOTTOM_LEFT   (0)
00055 #define VTK_TEXT_BOTTOM_RIGHT  (1)
00056 #define VTK_TEXT_TOP_RIGHT     (2)
00057 #define VTK_TEXT_TOP_LEFT      (3)
00058 
00059 // characterPosition - small utility storage class
00060 
00061 //BTX
00062 class characterPosition
00063 {
00064 public:
00065     characterPosition(unsigned char c);
00066     ~characterPosition() {};
00067 
00068     // lower left x, y, z of the mbox
00069     Vector3D<vtkFloatingPointType> mbox_pos;
00070     char character;
00071 };
00072 //ETX
00073 
00074 
00075 class VTK_QUERYATLAS_EXPORT vtkTextureText : public vtkObject
00076 {
00077 public:
00078      void PrintSelf(ostream& os, vtkIndent indent);
00079     vtkTypeRevisionMacro(vtkTextureText,vtkObject);
00080 
00081     static vtkTextureText *New();
00082 
00083     int CreateTextureText();
00084 
00085     int mCharCount;
00086 
00087 //BTX
00088     Vector3D<vtkFloatingPointType> *mCharGsetCoords;
00089     Vector2D<vtkFloatingPointType> *mTexCoords;
00090 
00091     vtkFloatingPointType* (*baselineFunc) (vtkFloatingPointType *vec, void *args);
00092     void *baselineArgs;
00093 
00094     std::vector<characterPosition *>mCharacterPositions;
00095 //ETX
00096 
00097     void buildQuads();
00098     void UpdateTexture();
00099 
00100     vtkGetObjectMacro(Texture, vtkTexture);
00101     vtkGetObjectMacro(Follower, vtkFollower);
00102 
00103     vtkGetObjectMacro(TextureTextPolys, vtkTextureTextPolys);
00104     // this method also returns TextureTextPolys, but using more standard VTK naming
00105     vtkTextureTextPolys *GetPolyDataSource();
00106 
00107     vtkGetObjectMacro(TextureFont, vtkTextureFont);
00108     vtkSetObjectMacro(TextureFont, vtkTextureFont);
00109 
00110     vtkGetObjectMacro(FontParameters, vtkFontParameters);
00111 
00112     vtkGetStringMacro(CharacterArray);
00113 
00114 
00115     // dimensions for wrapped text    
00116     // The text goes to the next line when the x position of the next word goes outside the 
00117     // box width. When the height is exceeded, the text moves to new column.
00118     vtkGetMacro(BoxWidth, vtkFloatingPointType);
00119     vtkSetMacro(BoxWidth, vtkFloatingPointType);
00120     vtkGetMacro(BoxHeight, vtkFloatingPointType);
00121     vtkSetMacro(BoxHeight, vtkFloatingPointType);
00122 
00123     void SetBoxSize(vtkFloatingPointType w, vtkFloatingPointType h);
00124 
00125     void SetWrapped(bool wrpd);
00126     
00127     vtkGetMacro(Wrapped, bool);
00128     
00129     void WrappedOn();
00130     void WrappedOff();
00131 
00132     vtkGetMacro(Leading, vtkFloatingPointType);
00133     vtkSetMacro(Leading, vtkFloatingPointType);
00134 
00135     vtkGetMacro(Indent, vtkFloatingPointType);
00136     vtkSetMacro(Indent, vtkFloatingPointType);
00137 
00138     vtkGetMacro(CharacterSpace, vtkFloatingPointType);
00139     vtkSetMacro(CharacterSpace, vtkFloatingPointType);
00140 
00141     vtkGetMacro(Alignment, short);
00142     vtkSetMacro(Alignment, short);
00143 
00144     // set/replace an existing string with <string> 
00145     void SetText(char *string);
00146     vtkGetStringMacro(Text);
00147 
00148     void SetDefaultAlignment(short alignment);
00149     short GetDefaultAlignment();
00150 
00151     vtkGetMacro(Initialized, int);
00152     vtkGetMacro(Error, int);
00153 
00154 //BTX
00155     void SetBaselineFunction(vtkFloatingPointType* (*f) (vtkFloatingPointType *vec, void *args), void *args);
00156     void UpdateBaseline();
00157     void ApplyBaselineFunction();
00158 
00159     void CalculateRangeBox(Vector3D<vtkFloatingPointType> *min, Vector3D<vtkFloatingPointType> *max, int start, int end);
00160 //ETX
00161 
00162     //static vtkFloatingPointType CalculateLineLength(char *string, char *fontname);
00163 
00164     // v12 - this doesn't seem to be used internally, but can be a useful utility...
00165     static vtkFloatingPointType GetAdvanceWidth(char *string, char *fontname, bool space);
00166     int CalculateNumberLines();
00167 
00168     void AddPositionOffset(vtkFloatingPointType pos[3]);
00169     void AddPositionOffset(vtkFloatingPointType x, vtkFloatingPointType y, vtkFloatingPointType z);
00170 
00171     void SetPositionOffset(vtkFloatingPointType pos[3]);
00172     void SetPositionOffset(vtkFloatingPointType x, vtkFloatingPointType y, vtkFloatingPointType z);
00173     void GetPositionOffset(vtkFloatingPointType pos[3]);
00174 
00175     void DoPositionOffset();
00176 
00177     void Modified();
00178 
00179     void SetDim(int d);
00180     
00181 
00182 protected:
00183     vtkTextureText();
00184     ~vtkTextureText(); 
00185 
00186     int Initialized;
00187     int Error;
00188 
00189 
00190     // space between lines
00191     vtkFloatingPointType                   Leading;
00192     vtkFloatingPointType                    Indent;
00193     int                     mLineCount;
00194     // extra space between characters
00195     vtkFloatingPointType                   CharacterSpace;
00196 
00197     bool                    Wrapped;
00198     vtkFloatingPointType                   BoxWidth;
00199     vtkFloatingPointType                   BoxHeight;
00200 
00201     // TODO MED - v12 - Alignment isn't working right for every line, 
00202     //   w/ VTK_TEXT_ALIGNMENT_JUSTIFIED, RIGHT, CENTERED
00203     //  Right, Centered seem to work when charSpace and indent are off.  Justified is still a bit off.
00204     // VTK_TEXT_ALIGNMENT_MONOSPACE - seems to correctly monospace, but too spread out, and w/ multiple columns, they're overlapping w/o wrapping soon enough
00205     //   especially messed up if SetCharacterSpace() if used - also when indent used
00206     // Centered needs a linefeed at the end of the text to work right.
00207     short                   Alignment;
00208     static short            sDefaultTextAlignment;
00209     vtkFloatingPointType                   word_space_when_justified;
00210 
00211     char                    *CharacterArray;
00212     char *Text;
00213 //BTX
00214     Vector3D<vtkFloatingPointType> PositionOffset;
00215 //ETX
00216     vtkFontParameters *FontParameters;
00217     vtkTexture *Texture;
00218     vtkFollower *Follower;
00219     vtkTextureFont *TextureFont;
00220     vtkTextureTextPolys *TextureTextPolys;
00221 
00222     vtkFloatingPointType TextOpacity;
00223     int Dim;
00224 
00225     void deleteAllChars();
00226 
00227     // low level
00228     vtkFloatingPointType getLinePos(unsigned int _start);
00229     vtkFloatingPointType getLineLength(unsigned int _start);
00230     int getCharLine(unsigned int _start);
00231     vtkFloatingPointType getLineWordCount(unsigned int _start, vtkFloatingPointType ind = 0);
00232 
00233 //BTX
00234     void  setCharCoords(Vector3D<vtkFloatingPointType> *char_gset_coords, Vector2D<vtkFloatingPointType> *tex_coords, 
00235         vtkTextureFont *textureFont, int the_char, Vector3D<vtkFloatingPointType> text_pos);
00236 //ETX
00237 
00238 };
00239 
00240 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1