KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWColorPresetMenu.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWColorPresetMenu - a color preset selector. 00015 // .SECTION Description 00016 // This class displays a color preset selector as an option menu. 00017 // Different type of presets can be enabled/disabled. 00018 // .SECTION See Also 00019 // vtkKWMenuButton 00020 00021 #ifndef __vtkKWColorPresetMenu_h 00022 #define __vtkKWColorPresetMenu_h 00023 00024 #include "vtkKWMenuButtonWithLabel.h" 00025 00026 class vtkColorTransferFunction; 00027 class vtkKWColorPresetMenuInternals; 00028 00029 class KWWidgets_EXPORT vtkKWColorPresetMenu : public vtkKWMenuButtonWithLabel 00030 { 00031 public: 00032 static vtkKWColorPresetMenu* New(); 00033 vtkTypeRevisionMacro(vtkKWColorPresetMenu,vtkKWMenuButtonWithLabel); 00034 void PrintSelf(ostream& os, vtkIndent indent); 00035 00036 // Description: 00037 // Set/Get the color transfer function the preset will be applied to. 00038 // Note that a color transfer function is created by default. 00039 virtual void SetColorTransferFunction(vtkColorTransferFunction *p); 00040 vtkGetObjectMacro(ColorTransferFunction,vtkColorTransferFunction); 00041 00042 // Description: 00043 // Set/Get the scalar range along which the preset will be applied. 00044 // Solid color presets will be created using two entries, one at each 00045 // end of the range. 00046 // Gradient, or custom presets will be scaled appropriately along 00047 // the range. 00048 // If ApplyPresetBetweenEndPoint is true, the preset is applied 00049 // given the scalar range defined between the two end-points (if any) 00050 vtkGetVector2Macro(ScalarRange, double); 00051 vtkSetVector2Macro(ScalarRange, double); 00052 vtkGetMacro(ApplyPresetBetweenEndPoints, int); 00053 vtkSetMacro(ApplyPresetBetweenEndPoints, int); 00054 vtkBooleanMacro(ApplyPresetBetweenEndPoints, int); 00055 00056 // Description: 00057 // Add a color preset. 00058 // A name is required, as well as a color transfer function and a range. 00059 // The range specifies the scalar range of the color tfunc, and is used 00060 // to store a normalized version of the color transfer function so that 00061 // it can be applied to the ColorTransferFunction ivar according to the 00062 // ScalarRange ivar. The color transfer function passed as parameter 00063 // is not Register()'ed. 00064 // Return 1 on success, 0 otherwise 00065 virtual int AddPreset( 00066 const char *name, vtkColorTransferFunction *func, double range[2]); 00067 00068 // Description: 00069 // Remove one (or all) color preset(s). 00070 // Return 1 on success, 0 otherwise 00071 virtual int RemovePreset(const char *name); 00072 virtual int RemoveAllPresets(); 00073 00074 // Description: 00075 // Add a color preset. 00076 // Add a preset given a solid color, in RGB or HSV format. 00077 virtual int AddSolidRGBPreset(const char *name, double rgb[3]); 00078 virtual int AddSolidRGBPreset(const char *name, double r,double g, double b); 00079 virtual int AddSolidHSVPreset(const char *name, double hsv[3]); 00080 virtual int AddSolidHSVPreset(const char *name, double h,double s, double v); 00081 00082 // Description: 00083 // Add a color preset. 00084 // Add a gradient preset given the endpoints of the gradient, in RGB or HSV 00085 // format. 00086 virtual int AddGradientRGBPreset( 00087 const char *name, double rgb1[3], double rgb2[3]); 00088 virtual int AddGradientRGBPreset( 00089 const char *name, 00090 double r1, double g1, double b1, 00091 double r2, double g2, double b2); 00092 virtual int AddGradientHSVPreset( 00093 const char *name, double hsv1[3], double hsv2[3]); 00094 virtual int AddGradientHSVPreset( 00095 const char *name, 00096 double h1, double s1, double v1, 00097 double h2, double s2, double v2); 00098 00099 // Description: 00100 // Add a color preset. 00101 // Add a "flag" preset given the number of colors in the flag, a pointer 00102 // to those colors, and the number of time the flag should be repeated in 00103 // the scalar range. 00104 virtual int AddFlagRGBPreset( 00105 const char *name, int nb_colors, double **rgb, int repeat); 00106 00107 // Description: 00108 // Set/Get the preview size. Each entry in the menu also displays a 00109 // preview of the preset. 00110 vtkGetMacro(PreviewSize, int); 00111 virtual void SetPreviewSize(int); 00112 00113 // Description: 00114 // Set/Get visibility of solid color presets in menu. 00115 vtkGetMacro(SolidColorPresetsVisibility, int); 00116 vtkBooleanMacro(SolidColorPresetsVisibility, int); 00117 virtual void SetSolidColorPresetsVisibility(int); 00118 00119 // Description: 00120 // Set/Get visibility of gradient presets in menu. 00121 vtkGetMacro(GradientPresetsVisibility, int); 00122 vtkBooleanMacro(GradientPresetsVisibility, int); 00123 virtual void SetGradientPresetsVisibility(int); 00124 00125 // Description: 00126 // Set/Get the preset name visibility in the menu. 00127 vtkGetMacro(PresetNameVisibility, int); 00128 vtkBooleanMacro(PresetNameVisibility, int); 00129 virtual void SetPresetNameVisibility(int); 00130 00131 // Description: 00132 // Specifies a command to associate with the widget. This command is 00133 // invoked when a preset is selected. 00134 // The 'object' argument is the object that will have the method called on 00135 // it. The 'method' argument is the name of the method to be called and any 00136 // arguments in string form. If the object is NULL, the method is still 00137 // evaluated as a simple command. 00138 // The following parameters are also passed to the command: 00139 // - name of the selected preset: const char* 00140 virtual void SetPresetSelectedCommand(vtkObject *object, const char *method); 00141 00142 // Description: 00143 // Callbacks. Internal, do not use. 00144 virtual void PresetSelectedCallback(const char *name); 00145 00146 protected: 00147 vtkKWColorPresetMenu(); 00148 ~vtkKWColorPresetMenu(); 00149 00150 // Description: 00151 // Create the widget. 00152 virtual void CreateWidget(); 00153 00154 double ScalarRange[2]; 00155 vtkColorTransferFunction *ColorTransferFunction; 00156 int PreviewSize; 00157 int SolidColorPresetsVisibility; 00158 int GradientPresetsVisibility; 00159 int ApplyPresetBetweenEndPoints; 00160 int PresetNameVisibility; 00161 00162 char *PresetSelectedCommand; 00163 virtual void InvokePresetSelectedCommand(const char *name); 00164 00165 // PIMPL Encapsulation for STL containers 00166 00167 vtkKWColorPresetMenuInternals *Internals; 00168 00169 // Description: 00170 // Query if there is a preset with a given name, create a preset 00171 // with a given name 00172 // Return 1 on success, 0 otherwise 00173 virtual int HasPreset(const char *name); 00174 virtual int AllocatePreset(const char *name); 00175 00176 // Description: 00177 // Get a preset color transfer function. 00178 // Return the func on success, NULL otherwise 00179 virtual vtkColorTransferFunction* GetPresetColorTransferFunction( 00180 const char *name); 00181 00182 // Description: 00183 // Create the default presets 00184 virtual void CreateDefaultPresets(); 00185 00186 // Description: 00187 // Map one transfer function to another 00188 // Return 1 on success, 0 otherwise 00189 virtual int MapColorTransferFunction( 00190 vtkColorTransferFunction *source, double source_range[2], 00191 vtkColorTransferFunction *target, double target_range[2]); 00192 00193 // Description: 00194 // Create preview (icon/image) for a preset 00195 virtual int CreateColorTransferFunctionPreview( 00196 vtkColorTransferFunction *func, const char *img_name); 00197 00198 // Description: 00199 // Populate the preset menu 00200 virtual void PopulatePresetMenu(); 00201 00202 private: 00203 vtkKWColorPresetMenu(const vtkKWColorPresetMenu&); // Not implemented 00204 void operator=(const vtkKWColorPresetMenu&); // Not Implemented 00205 }; 00206 00207 #endif 00208