SmallChange  1.0.0
A collection of extensions to Coin3D
Loading...
Searching...
No Matches
LegendKit.h
1#ifndef SMALLCHANGE_LEGENDKIT_H
2#define SMALLCHANGE_LEGENDKIT_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/nodekits/SoSubKit.h>
37#include <Inventor/nodekits/SoBaseKit.h>
38#include <Inventor/fields/SoSFEnum.h>
39#include <Inventor/fields/SoSFBool.h>
40#include <Inventor/fields/SoSFVec2f.h>
41#include <Inventor/fields/SoSFFloat.h>
42#include <Inventor/fields/SoSFString.h>
43#include <Inventor/fields/SoMFString.h>
44
45#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
46#include <SoWinLeaveScope.h>
47#endif // win
48
49#include <SmallChange/basic.h>
50
51class SbViewport;
52class SoState;
53class SbColor;
54class SbVec2s;
55
56
57class SMALLCHANGE_DLL_API LegendKit : public SoBaseKit {
58 typedef SoBaseKit inherited;
59
60 SO_KIT_HEADER(LegendKit);
61
62 SO_KIT_CATALOG_ENTRY_HEADER(topSeparator);
63 SO_KIT_CATALOG_ENTRY_HEADER(viewport);
64 SO_KIT_CATALOG_ENTRY_HEADER(resetTransform);
65 SO_KIT_CATALOG_ENTRY_HEADER(position);
66 SO_KIT_CATALOG_ENTRY_HEADER(depthBuffer);
67 SO_KIT_CATALOG_ENTRY_HEADER(lightModel);
68 SO_KIT_CATALOG_ENTRY_HEADER(camera);
69 SO_KIT_CATALOG_ENTRY_HEADER(texture);
70 SO_KIT_CATALOG_ENTRY_HEADER(shapeHints);
71 SO_KIT_CATALOG_ENTRY_HEADER(pickStyle);
72 SO_KIT_CATALOG_ENTRY_HEADER(backgroundMaterial);
73 SO_KIT_CATALOG_ENTRY_HEADER(backgroundShape);
74 SO_KIT_CATALOG_ENTRY_HEADER(imageSeparator);
75 SO_KIT_CATALOG_ENTRY_HEADER(imageTransform);
76 SO_KIT_CATALOG_ENTRY_HEADER(imageMaterial);
77 SO_KIT_CATALOG_ENTRY_HEADER(imageSwitch);
78 SO_KIT_CATALOG_ENTRY_HEADER(imageGroup);
79 SO_KIT_CATALOG_ENTRY_HEADER(imageTranslation);
80 SO_KIT_CATALOG_ENTRY_HEADER(image);
81 SO_KIT_CATALOG_ENTRY_HEADER(textureGroup);
82 SO_KIT_CATALOG_ENTRY_HEADER(textureQuality);
83 SO_KIT_CATALOG_ENTRY_HEADER(textureImage);
84 SO_KIT_CATALOG_ENTRY_HEADER(textureShape);
85 SO_KIT_CATALOG_ENTRY_HEADER(tickMaterial);
86 SO_KIT_CATALOG_ENTRY_HEADER(renderCallbackLines);
87 SO_KIT_CATALOG_ENTRY_HEADER(textMaterial);
88 SO_KIT_CATALOG_ENTRY_HEADER(renderCallbackText);
89 SO_KIT_CATALOG_ENTRY_HEADER(extraNodes);
90
91public:
92 LegendKit(void);
93
94 static void initClass(void);
95
96public:
97
98 SoSFBool on;
99 SoSFFloat imageWidth;
100 SoSFFloat space;
101 SoSFFloat bigTickSize;
102 SoSFFloat smallTickSize;
103 SoSFString tickValueFormat;
105 SoMFString description;
108 SoSFFloat topSpace;
110 SoSFBool threadSafe;
111
112 void preRender(SoAction * action);
113
114 void setImageTransparency(const float transparency = 0.0f);
115 void useTextureNotImage(const SbBool onoff);
116 void setColorCB(uint32_t (*colorCB)(double, void*), void * userdata = NULL);
117 void setColorCB(uint32_t (*colorCB)(double));
118
119 void clearTicks(void);
120 void addSmallTick(double nval);
121 void addBigTick(double nval, double tickvalue, const SbString * discretestring = NULL);
122 void addBigTick(double nval, const SbString & string, const SbString * discretestring = NULL);
123
124 void setDiscreteMode(const SbBool onoff);
125 void addDiscreteColor(double uppernval, uint32_t color);
126 void addDiscreteColor(double uppernval);
127
128 void clearData(void);
129 void enableImage(const SbBool onoff);
130
131 float getLegendWidth(void) const;
132
133 typedef SbString SoNumberFormatCB(const double number, void * closure);
134 void setNumberFormatCallback(SoNumberFormatCB * cb, void * closure);
135
136public:
137 // convenience methods for setting part attributes
138 void setTickAndLinesColor(const SbColor & color, const float transparency = 0.0f);
139 void setTextColor(const SbColor & color, const float transparency = 0.0f);
140 void setPosition(const SbVec2s & pos);
141 void setBackgroundColor(const SbColor & color, const float transparency = 0.0f);
142 void enableBackground(const SbBool onoff);
143
144
145protected:
146 virtual void GLRender(SoGLRenderAction * action);
147 virtual void getBoundingBox(SoGetBoundingBoxAction * action);
148 virtual void handleEvent(SoHandleEventAction * action);
149 virtual void search(SoSearchAction * action);
150 virtual void callback(SoCallbackAction * action);
151 virtual void getMatrix(SoGetMatrixAction * action);
152 virtual void pick(SoPickAction * action);
153 virtual void rayPick(SoRayPickAction * action);
154 virtual void audioRender(SoAudioRenderAction * action);
155 virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
156
157 virtual SbBool affectsState(void) const;
158
159 virtual ~LegendKit();
160 virtual void notify(SoNotList * list);
161
162private:
163
164 void recalcSize(SoState * state);
165 void initBackground(const SbBool force = FALSE);
166 void initTextureImage(void);
167 void initImage(void);
168 void reallyInitImage(unsigned char * data, unsigned char * rowdata = NULL);
169 void fillImageAlpha(void);
170 static void renderCBlines(void * userdata, SoAction * action);
171 static void renderCBtext(void * userdata, SoAction * action);
172 void render(SoGLRenderAction * action, const SbBool lines);
173 void renderLines(SoGLRenderAction * action);
174 void renderText(SoGLRenderAction * action);
175 void renderString(const char * str, int xpos, int ypos);
176
177 void setSwitchValue(const char * part, const int value);
178
179 class LegendKitP * pimpl;
180 friend class LegendKitP;
181};
182
183#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
184#include <SoWinEnterScope.h>
185#endif // win
186
187#endif // !SMALLCHANGE_LEGENDKIT_H
The LegendKit class is used to draw a simple colormap legend.
Definition LegendKit.h:57
SoSFBool on
Definition LegendKit.h:98
SoSFFloat smallTickSize
Definition LegendKit.h:102
SoSFFloat imageWidth
Definition LegendKit.h:99
SoSFBool descriptionOnTop
Definition LegendKit.h:106
SoSFFloat topSpace
Definition LegendKit.h:108
SoMFString description
Definition LegendKit.h:105
SoSFFloat bigTickSize
Definition LegendKit.h:101
SoSFFloat tickValueOffset
Definition LegendKit.h:104
SoSFFloat space
Definition LegendKit.h:100
SoSFBool discreteUseLower
Definition LegendKit.h:109
SoSFString tickValueFormat
Definition LegendKit.h:103
SoSFBool delayedRender
Definition LegendKit.h:107