00001 #ifndef _LEGEND_VALUE_H_
00002 #define _LEGEND_VALUE_H_
00003
00004 #include <iostream>
00005 #include <sstream>
00006 #include <string>
00007 #include <string.h>
00008
00009 #include "Color.h"
00010
00011 namespace FemViewer {
00012
00013
00014 enum LegendValueType
00015 {
00016 NON = 0,
00017 BORDER = 1,
00018 INSIDE = 2,
00019 OUTSIDE = 4,
00020
00021 START = 8,
00022 END = 16,
00023
00024 LVT_COLOR = 32
00025
00026 };
00027
00028
00029 typedef struct colormap_value {
00030
00031 double value;
00032
00033 RGBColor rgb;
00034
00035 int type;
00039 explicit colormap_value(void) { this->clear(); };
00040 colormap_value(const colormap_value& ref)
00041 : value(ref.value)
00042 , rgb(ref.rgb)
00043 , type(ref.type)
00044 {}
00045 void operator=(const colormap_value& rhs) {
00046 value = rhs.value;
00047 rgb.r = rhs.rgb.r;
00048 rgb.g = rhs.rgb.g;
00049 rgb.b = rhs.rgb.b;
00050 type = rhs.type;
00051 }
00052 void clear(void) {
00053
00054
00055
00056
00057
00058 memset(this,0,sizeof(*this));
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 unsigned char RedAsUChar(void){return static_cast<unsigned char>(rgb.r*255.99);};
00068 unsigned char GreenAsUChar(void){return static_cast<unsigned char>(this->rgb.g*255.99);};
00069 unsigned char BlueAsUChar(void){return static_cast<unsigned char>(this->rgb.b*255.99);};
00070
00072 ColorRGB GetColor(void) const
00073 {
00074 return ColorRGB(rgb.r, rgb.g, rgb.b);
00075 };
00076
00078 void SetColor( const ColorRGB & c )
00079 {
00080 rgb.r = c.R;
00081 rgb.g = c.G;
00082 rgb.b = c.B;
00083 };
00084
00092 std::string TypeAsString(void)
00093 {
00094 std::stringstream oss;
00095
00096 if ( this->type == NON)
00097 oss << "NON ";
00098
00099 if ( this->type & BORDER)
00100 oss << "BORDER ";
00101
00102 if ( this->type & INSIDE)
00103 oss << "INSIDE ";
00104
00105 if ( this->type & OUTSIDE)
00106 oss << "OUTSIDE ";
00107
00108 if ( this->type & LVT_COLOR)
00109 oss << "COLOR ";
00110
00111 if ( this->type & START)
00112 oss << "START ";
00113
00114 if ( this->type & END)
00115 oss << "END ";
00116
00117 return oss.str();
00118 };
00119
00121 std::string AsString(void)
00122 {
00123 std::stringstream oss;
00124
00125 oss << "war: " << value << " r: " << (int)RedAsUChar() << " g: " << (int)GreenAsUChar() << " b: "<< (int)BlueAsUChar() << " t: " << TypeAsString();
00126
00127 return oss.str();
00128 };
00129 } colormap_value;
00130
00131
00132
00133
00134
00135
00136 }
00137 #endif
00138