CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GiPalette.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef __ODGIPALETTE_H__
25#define __ODGIPALETTE_H__
26
27#include "TD_PackPush.h"
28
29#include "GiExport.h"
30#include "OdArray.h"
31#include "StaticRxObject.h"
32
39{
41
43 : r(_r), g(_g), b(_b)
44 { }
47 {
48 setColor(cref);
49 }
50
54 OdInt32 red() const { return r; }
58 OdInt32 green() const { return g; }
62 OdInt32 blue() const { return b; }
63
68 void setRed(OdInt32 _r) { r = _r; }
73 void setGreen(OdInt32 _g) { g = _g; }
78 void setBlue(OdInt32 _b) { b = _b; }
85 void setRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b) { r = _r; g = _g; b = _b; }
86
92 {
94 }
99 {
100 return ODRGB(r, g, b);
101 }
102};
103
110{
111 protected:
118 protected:
119 virtual bool isDynamic() const { return false; }
120 public:
121 OdGiColorCube(OdGiIntRGB nGridDivs = OdGiIntRGB(2, 2, 2), float fIntensity = 1.0f, OdInt32 nBaseOffset = 0)
122 : m_nBaseOffset(nBaseOffset)
123 , m_nGridDivs(nGridDivs)
124 , m_fIntensity(fIntensity)
125 {
126 validate();
127 }
128 static OdSmartPtr<OdGiColorCube> createDynamic(OdGiIntRGB nGridDivs = OdGiIntRGB(2, 2, 2), float fIntensity = 1.0f, OdInt32 nBaseOffset = 0);
129
130 virtual OdRxObjectPtr clone() const;
131 OdSmartPtr<OdGiColorCube> cloneIfNeed() const { if (!isDynamic()) return clone(); return this; }
132
136 OdInt32 baseOffset() const { return m_nBaseOffset; }
140 const OdGiIntRGB &gridDivisions() const { return m_nGridDivs; }
144 float intensity() const { return m_fIntensity; }
148 OdInt32 gridSize() const { return m_nGridSize; }
152 const OdGiIntRGB &offsets() const { return m_nOffsets; }
156 const OdGiIntRGB &dimensions() const { return m_nDims; }
157
162 ODCOLORREF color(OdInt32 nColor) const;
163
169
171 {
172 OdInt32 m_fitColors[4];
173 OdInt32 m_pattern[4];
174 };
175
184 protected:
185 void validate();
186};
187
192
198class ODGI_EXPORT OdGiGrayRamp : public OdStaticRxObject<OdRxObject>
199{
200 protected:
205 protected:
206 virtual bool isDynamic() const { return false; }
207 public:
208 OdGiGrayRamp(OdInt32 nGridDivs = 2, float fIntensity = 1.0f, OdInt32 nBaseOffset = 0)
209 : m_nBaseOffset(nBaseOffset)
210 , m_nGridDivs(nGridDivs)
211 , m_fIntensity(fIntensity)
212 {
213 validate();
214 }
215 static OdSmartPtr<OdGiGrayRamp> createDynamic(OdInt32 nGridDivs = 2, float fIntensity = 1.0f, OdInt32 nBaseOffset = 0);
216
217 virtual OdRxObjectPtr clone() const;
218 OdSmartPtr<OdGiGrayRamp> cloneIfNeed() const { if (!isDynamic()) return clone(); return this; }
219
223 OdInt32 baseOffset() const { return m_nBaseOffset; }
227 OdInt32 gridDivisions() const { return m_nGridDivs; }
231 float intensity() const { return m_fIntensity; }
235 OdInt32 dimension() const { return m_nDim; }
236
241 ODCOLORREF color(OdInt32 nColor) const;
242
248 protected:
249 void validate();
250};
251
256
262class ODGI_EXPORT OdGiPalette : public OdStaticRxObject<OdRxObject>
263{
264 protected:
265 ODCOLORREF m_colors[256];
266 OdUInt64 m_activities[4];
269 public:
271 {
275 Addressation(OdInt32 nFrom = 0, OdInt32 nTo = 0, OdInt32 nNum = 256)
276 : m_nSrcFrom(nFrom), m_nDstTo(nTo), m_nNumColors(nNum)
277 {}
278 bool validate() const { return ((m_nSrcFrom + m_nNumColors) <= 256) && ((m_nDstTo + m_nNumColors) <= 256); }
279 bool fullRange() const { return (m_nSrcFrom == 0) && (m_nDstTo == 0) && (m_nNumColors == 256); }
280 };
281 protected:
282 virtual bool isDynamic() const { return false; }
283 public:
285 {
286 initPalette();
287 }
290
291 OdGiPalette& operator= (const OdGiPalette & obj);
292
293 virtual OdRxObjectPtr clone() const;
294 OdSmartPtr<OdGiPalette> cloneIfNeed() const { if (!isDynamic()) return clone(); return this; }
295
301 {
302 return m_colors[nColor];
303 }
308 bool entryActivity(OdInt32 nColor) const
309 {
310 return GETBIT(m_activities[nColor >> 6], 1ULL << (OdUInt64(nColor) & 63));
311 }
312
318 void setColor(OdInt32 nColor, ODCOLORREF color)
319 {
320 m_colors[nColor] = color;
321 }
327 void setEntryActivity(OdInt32 nColor, bool bActivity)
328 {
329 SETBIT(m_activities[nColor >> 6], 1ULL << (OdUInt64(nColor) & 63), bActivity);
330 }
331
335 const ODCOLORREF *asArray() const
336 {
337 return m_colors;
338 }
339
344 {
345 return m_pColorCube.get();
346 }
350 void setColorCube(const OdGiColorCube *pColorCube)
351 {
352 resetColorCube(pColorCube);
353 }
358 {
359 resetColorCube(NULL);
360 }
361
365 const OdGiGrayRamp *grayRamp() const
366 {
367 return m_pGrayRamp.get();
368 }
372 void setGrayRamp(const OdGiGrayRamp *pGrayRamp)
373 {
374 resetGrayRamp(pGrayRamp);
375 }
380 {
381 resetGrayRamp(NULL);
382 }
383
389 bool install(const OdGiColorCube *pColorCube, bool bForceUpdate = false);
395 bool install(const OdGiGrayRamp *pGrayRamp, bool bForceUpdate = false);
401 bool install(const OdGiPalette *pPalette, bool bForceUpdate = false, const Addressation &address = Addressation());
408 bool install(ODCOLORREF const *const pColors, bool bForceUpdate = false, const Addressation &address = Addressation());
409
415 OdInt32 closestMatch(ODCOLORREF cref, bool bThroughPal = false) const;
416
422
428 bool isEqualTo(const OdGiPalette *pPalette, const Addressation &address = Addressation()) const;
434 bool remove(const OdGiPalette *pPalette, bool bForceUpdate = false, const Addressation &address = Addressation());
435
439 void clear();
440 protected:
442
443 void resetColorCube(const OdGiColorCube *pColorCube);
444 void resetGrayRamp(const OdGiGrayRamp *pGrayRamp);
445
446 void setColorImpl(OdInt32 nColor, ODCOLORREF color)
447 {
448 m_colors[nColor] = color;
449 setEntryActivity(nColor, true);
450 }
451};
452
457
458// Forward declaration
460
470{
471 protected:
473 public:
474 OdGiPaletteOverrideHelper() : m_pTraits(NULL) {}
475 OdGiPaletteOverrideHelper(OdGiSubEntityTraits &pTraits, const OdGiPalette &pOverride) : m_pTraits(NULL)
476 { setPaletteOverride(pTraits, pOverride); }
478 void setPaletteOverride(OdGiSubEntityTraits &pTraits, const OdGiPalette &pOverride);
479};
480
481#include "TD_PackPop.h"
482
483#endif //#ifndef __ODGIPALETTE_H__
#define ODGI_EXPORT
Definition: GiExport.h:35
OdSmartPtr< OdGiColorCube > OdGiColorCubePtr
Definition: GiPalette.h:191
OdSmartPtr< OdGiPalette > OdGiPalettePtr
Definition: GiPalette.h:456
OdSmartPtr< OdGiGrayRamp > OdGiGrayRampPtr
Definition: GiPalette.h:255
#define ODGETBLUE(rgb)
Definition: OdPlatform.h:939
#define ODRGB(r, g, b)
Definition: OdPlatform.h:934
#define ODCOLORREF
Definition: OdPlatform.h:933
#define ODGETGREEN(rgb)
Definition: OdPlatform.h:938
#define ODGETRED(rgb)
Definition: OdPlatform.h:937
int OdInt32
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
float intensity() const
Definition: GiPalette.h:144
OdSmartPtr< OdGiColorCube > cloneIfNeed() const
Definition: GiPalette.h:131
float m_fIntensity
Definition: GiPalette.h:114
OdInt32 baseOffset() const
Definition: GiPalette.h:136
OdInt32 m_nGridSize
Definition: GiPalette.h:115
OdGiIntRGB m_nDims
Definition: GiPalette.h:117
static OdSmartPtr< OdGiColorCube > createDynamic(OdGiIntRGB nGridDivs=OdGiIntRGB(2, 2, 2), float fIntensity=1.0f, OdInt32 nBaseOffset=0)
OdGiIntRGB m_nOffsets
Definition: GiPalette.h:116
virtual bool isDynamic() const
Definition: GiPalette.h:119
ODCOLORREF color(OdInt32 nColor) const
OdInt32 closestMatch(ODCOLORREF cref) const
const OdGiIntRGB & offsets() const
Definition: GiPalette.h:152
OdGiColorCube(OdGiIntRGB nGridDivs=OdGiIntRGB(2, 2, 2), float fIntensity=1.0f, OdInt32 nBaseOffset=0)
Definition: GiPalette.h:121
const OdGiIntRGB & dimensions() const
Definition: GiPalette.h:156
virtual OdRxObjectPtr clone() const
OdGiIntRGB m_nGridDivs
Definition: GiPalette.h:113
OdInt32 ditheredMatch(ODCOLORREF cref, DtMatchResult &results) const
const OdGiIntRGB & gridDivisions() const
Definition: GiPalette.h:140
OdInt32 gridSize() const
Definition: GiPalette.h:148
OdInt32 m_nBaseOffset
Definition: GiPalette.h:112
float m_fIntensity
Definition: GiPalette.h:203
float intensity() const
Definition: GiPalette.h:231
OdInt32 m_nBaseOffset
Definition: GiPalette.h:201
OdInt32 m_nDim
Definition: GiPalette.h:204
void validate()
virtual OdRxObjectPtr clone() const
OdGiGrayRamp(OdInt32 nGridDivs=2, float fIntensity=1.0f, OdInt32 nBaseOffset=0)
Definition: GiPalette.h:208
static OdSmartPtr< OdGiGrayRamp > createDynamic(OdInt32 nGridDivs=2, float fIntensity=1.0f, OdInt32 nBaseOffset=0)
OdInt32 dimension() const
Definition: GiPalette.h:235
OdSmartPtr< OdGiGrayRamp > cloneIfNeed() const
Definition: GiPalette.h:218
OdInt32 m_nGridDivs
Definition: GiPalette.h:202
OdInt32 gridDivisions() const
Definition: GiPalette.h:227
ODCOLORREF color(OdInt32 nColor) const
OdInt32 closestMatch(ODCOLORREF cref) const
virtual bool isDynamic() const
Definition: GiPalette.h:206
OdInt32 baseOffset() const
Definition: GiPalette.h:223
void setColorCube(const OdGiColorCube *pColorCube)
Definition: GiPalette.h:350
bool install(ODCOLORREF const *const pColors, bool bForceUpdate=false, const Addressation &address=Addressation())
void setColor(OdInt32 nColor, ODCOLORREF color)
Definition: GiPalette.h:318
void setColorImpl(OdInt32 nColor, ODCOLORREF color)
Definition: GiPalette.h:446
void setGrayRamp(const OdGiGrayRamp *pGrayRamp)
Definition: GiPalette.h:372
const OdGiGrayRamp * grayRamp() const
Definition: GiPalette.h:365
OdInt32 firstAvailableBlock(OdInt32 blockSize) const
virtual bool isDynamic() const
Definition: GiPalette.h:282
const OdGiColorCube * colorCube() const
Definition: GiPalette.h:343
static OdSmartPtr< OdGiPalette > createDynamic()
bool entryActivity(OdInt32 nColor) const
Definition: GiPalette.h:308
OdGiPalette(const OdGiPalette &obj)
void clear()
OdSmartPtr< OdGiPalette > cloneIfNeed() const
Definition: GiPalette.h:294
void setEntryActivity(OdInt32 nColor, bool bActivity)
Definition: GiPalette.h:327
bool install(const OdGiPalette *pPalette, bool bForceUpdate=false, const Addressation &address=Addressation())
void initPalette()
void resetGrayRamp(const OdGiGrayRamp *pGrayRamp)
void resetColorCube()
Definition: GiPalette.h:357
OdGiColorCubePtr m_pColorCube
Definition: GiPalette.h:267
OdGiGrayRampPtr m_pGrayRamp
Definition: GiPalette.h:268
OdInt32 closestMatch(ODCOLORREF cref, bool bThroughPal=false) const
ODCOLORREF color(OdInt32 nColor) const
Definition: GiPalette.h:300
bool install(const OdGiColorCube *pColorCube, bool bForceUpdate=false)
bool remove(const OdGiPalette *pPalette, bool bForceUpdate=false, const Addressation &address=Addressation())
void resetGrayRamp()
Definition: GiPalette.h:379
const ODCOLORREF * asArray() const
Definition: GiPalette.h:335
void resetColorCube(const OdGiColorCube *pColorCube)
virtual OdRxObjectPtr clone() const
bool install(const OdGiGrayRamp *pGrayRamp, bool bForceUpdate=false)
bool isEqualTo(const OdGiPalette *pPalette, const Addressation &address=Addressation()) const
OdGiSubEntityTraits * m_pTraits
Definition: GiPalette.h:472
OdGiPaletteOverrideHelper(OdGiSubEntityTraits &pTraits, const OdGiPalette &pOverride)
Definition: GiPalette.h:475
void setPaletteOverride(OdGiSubEntityTraits &pTraits, const OdGiPalette &pOverride)
const T * get() const
Definition: SmartPtr.h:339
ODCOLORREF color() const
Definition: GiPalette.h:98
void setRed(OdInt32 _r)
Definition: GiPalette.h:68
OdGiIntRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b)
Definition: GiPalette.h:42
OdInt32 b
Definition: GiPalette.h:40
void setColor(ODCOLORREF cref)
Definition: GiPalette.h:91
OdInt32 blue() const
Definition: GiPalette.h:62
void setGreen(OdInt32 _g)
Definition: GiPalette.h:73
OdGiIntRGB(ODCOLORREF cref)
Definition: GiPalette.h:46
OdInt32 r
Definition: GiPalette.h:40
OdInt32 green() const
Definition: GiPalette.h:58
void setBlue(OdInt32 _b)
Definition: GiPalette.h:78
OdGiIntRGB()
Definition: GiPalette.h:45
OdInt32 red() const
Definition: GiPalette.h:54
OdInt32 g
Definition: GiPalette.h:40
void setRGB(OdInt32 _r, OdInt32 _g, OdInt32 _b)
Definition: GiPalette.h:85
bool fullRange() const
Definition: GiPalette.h:279
Addressation(OdInt32 nFrom=0, OdInt32 nTo=0, OdInt32 nNum=256)
Definition: GiPalette.h:275