zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
// Procedural textures generator.
 
#ifndef __ODGIPROCEDURALGENERATOR_H__
#define __ODGIPROCEDURALGENERATOR_H__
 
#include "RootExport.h"
#include "GiExport.h"
#include "CmColor.h"
#include "UInt32Array.h"
#include "GiImage.h"
#include "GiMaterial.h"
 
#include "RxObject.h"
 
#include "TD_PackPush.h"
 
/** \details
    Protocol extension for OdGiProceduralGenerator.
    Library: TD_Gi
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiProceduralGeneratorPE : public OdRxObject
{
  public:
    ODRX_DECLARE_MEMBERS(OdGiProceduralGeneratorPE);
 
    OdGiProceduralGeneratorPE();
 
    /** \details
      Generate procedural texture.
      Returns false if protocol extension not initialized or does not support current procedural texture type.
      \param pTexture [in]  Procedural texture pointer.
      \param image [out]  Output image.
      \param renderCoef [in]  Texture detail multiplier. 1.0 - is most standard device value, 10.0 - for normal rendering.
                     This value can be calculated from raster resolution.
    */
    virtual bool generateProceduralTexture(OdGiProceduralTexturePtr pTexture,
                                           OdGiImageBGRA32 &image, double renderCoef = 1.0) = 0;
};
 
/** \details
    This template class is a specialization of the OdSmartPtr class for OdGiProceduralGeneratorPE object pointers.
        
    <group Type Definitions>
*/
typedef OdSmartPtr<OdGiProceduralGeneratorPE> OdGiProceduralGeneratorPEPtr;
 
/** \details
    Color gradient generator.
 
    \sa
    TD_Gi
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiGradientGenerator
{
  public:
    /** \details
        Type of color interpolation function (linear, exponential, inverted exponential, cosine).
    */
    enum InterpolationType
    {
      kLinearInterpolation = 0,
      kExpInterpolation,
      kInvExpInterpolation,
      kCosInterpolation
    };
    /** \details
        Color interval addressing mode.
        \remarks
        kClampMode Clamp color address coordinates to the [0.0, 1.0] range.
        kWrapMode Repeat color address on every integer junction.
    */
    enum AddressMode
    {
      kClampMode = 0,
      kWrapMode
    };
  protected:
    OdUInt32Array m_colorGradient;
    AddressMode m_addressMode;
  public:
    OdGiGradientGenerator();
    OdGiGradientGenerator(const OdGiGradientGenerator &other);
    ~OdGiGradientGenerator();
 
    /** \details
      Create gradient colors array, filled with black color.
      \param nColors [in]  Count of colors in gradient array.
    */
    void createColorArray(OdUInt32 nColors);
    /** \details
      Create gradient colors array, filled with specified color.
      \param color [in]  Color for all elements in array.
      \param nColors [in]  Count of colors in gradient array.
    */
    void createColorArrayFilled(ODCOLORREF color, OdUInt32 nColors);
    /** \details
      Create gradient colors array from other colors array.
      \param other [in]  Input colors array for copy from.
    */
    void copyGradient(const OdUInt32Array &other);
    /** \details
      Create gradient colors array from other colors array.
      \param colors [in]  Linear array of colors.
      \param nColors [in]  Count of colors in colors linear array.
    */
    void copyGradient(const ODCOLORREF *colors, OdUInt32 nColors);
    /** \details
      Create gradient from two input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl [in]  Interpolation function.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation);
    /** \details
      Create gradient from three input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param color3 [in]  Third color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl [in]  Interpolation function.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, ODCOLORREF color3, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation);
    /** \details
      Create gradient from three input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param color3 [in]  Third color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl1 [in]  Interpolation function for interval between color1 and color2.
      \param ipl2 [in]  Interpolation function for interval between color2 and color3.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, ODCOLORREF color3, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl1, OdGiGradientGenerator::InterpolationType ipl2);
    /** \details
      Create gradient from four input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param color3 [in]  Third color.
      \param color4 [in]  Four color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl [in]  Interpolation function.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, ODCOLORREF color3, ODCOLORREF color4, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation);
    /** \details
      Create gradient from four input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param color3 [in]  Third color.
      \param color4 [in]  Fourth color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl1 [in]  Interpolation function for interval between color1 and color2.
      \param ipl2 [in]  Interpolation function for interval between color2 and color3.
      \param ipl3 [in]  Interpolation function for interval between color3 and color4.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, ODCOLORREF color3, ODCOLORREF color4, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl1, OdGiGradientGenerator::InterpolationType ipl2,
                        OdGiGradientGenerator::InterpolationType ipl3);
    /** \details
      Create gradient from five input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param color3 [in]  Third color.
      \param color4 [in]  Fourth color.
      \param color5 [in]  Fifth color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl [in]  Interpolation function.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, ODCOLORREF color3, ODCOLORREF color4, ODCOLORREF color5, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation);
    /** \details
      Create gradient from five input colors.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param color3 [in]  Third color.
      \param color4 [in]  Fourth color.
      \param color5 [in]  Fifth color.
      \param nColors [in]  Number of color entries to be created in gradient colors array.
      \param ipl1 [in]  Interpolation function for interval between color1 and color2.
      \param ipl2 [in]  Interpolation function for interval between color2 and color3.
      \param ipl3 [in]  Interpolation function for interval between color3 and color4.
      \param ipl4 [in]  Interpolation function for interval between color4 and color5.
    */
    void createGradient(ODCOLORREF color1, ODCOLORREF color2, ODCOLORREF color3, ODCOLORREF color4, ODCOLORREF color5, OdUInt32 nColors,
                        OdGiGradientGenerator::InterpolationType ipl1, OdGiGradientGenerator::InterpolationType ipl2,
                        OdGiGradientGenerator::InterpolationType ipl3, OdGiGradientGenerator::InterpolationType ipl4);
 
    /** \details
      Fill gradient range between from and to.
      \param color [in]  Fill color.
      \param from [in]  Start of range for fill.
      \param to [in]  End of range for fill.
    */
    void fillInterval(ODCOLORREF color, double from = 0.0, double to = 1.0);
    /** \details
      Fill gradient range between from and to.
      \param color [in]  Fill color.
      \param from [in]  Start of range for fill.
      \param to [in]  End of range for fill.
    */
    void fillInterval(ODCOLORREF color, OdUInt32 from, OdUInt32 to);
    /** \details
      Fill range of gradient colors array with another gradient.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param from [in]  Start of range for fill.
      \param to [in]  End of range for fill.
      \param ipl [in]  Interpolation function.
    */
    void generateInterval(ODCOLORREF color1, ODCOLORREF color2, double from = 0.0, double to = 1.0,
                          OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation);
    /** \details
      Fill range of gradient colors array by another gradient.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param from [in]  Start of range for fill.
      \param to [in]  End of range for fill.
      \param ipl [in]  Interpolation function.
    */
    void generateInterval(ODCOLORREF color1, ODCOLORREF color2, OdUInt32 from, OdUInt32 to,
                          OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation);
 
    /** \details
      Get count of colors in gradient colors array.
    */
    OdUInt32 colorsCount() const;
    /** \details
      Get color from gradient colors array.
      \param nColor [in]  Index of color in array.
    */
    ODCOLORREF colorAt(OdUInt32 nColor) const;
    /** \details
      Get color from gradient colors array.
      \param at [in]  Color coordinate (0.0 equals 0 in array; 1.0 equals colorsCount() - 1 in array).
    */
    ODCOLORREF colorAt(double at) const;
    /** \details
      Test whether gradient is initialized.
    */
    bool isInitialized() const;
    /** \details
      Get reference to array of gradient colors.
    */
    const OdUInt32Array &asArray() const;
 
    /** \details
      Set addressing mode.
      \param mode [in]  New addressing mode.
    */
    void setAddressMode(OdGiGradientGenerator::AddressMode mode);
    /** \details
      Get addressing mode.
    */
    OdGiGradientGenerator::AddressMode addressMode() const;
 
    /** \details
      Interpolate color between color1 and color2.
      \param color1 [in]  First color.
      \param color2 [in]  Second color.
      \param at [in]  Interpolation coordinate (0.0 - 1.0 for range without additional addressing).
      \param to [in]  End of range for fill.
      \param ipl [in]  Interpolation function.
      \param mode [in]  Addressing mode.
    */
    static ODCOLORREF interpolateColor(ODCOLORREF color1, ODCOLORREF color2, double at,
                                       OdGiGradientGenerator::InterpolationType ipl = OdGiGradientGenerator::kLinearInterpolation,
                                       OdGiGradientGenerator::AddressMode mode = OdGiGradientGenerator::kWrapMode);
 
    const OdGiGradientGenerator &operator =(const OdGiGradientGenerator &other);
 
    static OdGiGradientGenerator createSpectrumGradient(OdUInt32 nColors, OdUInt8 alpha = 0);
 
    void appendGradient(const OdGiGradientGenerator &other);
    void operator +=(const OdGiGradientGenerator &other);
    friend OdGiGradientGenerator operator +(const OdGiGradientGenerator &g1, const OdGiGradientGenerator &g2);
  protected:
    /** \details
      inVal addressing.
    */
    OdUInt32 clampToRange(OdUInt32 inVal) const;
    /** \details
      inVal addressing.
    */
    OdUInt32 clampToRange(double inVal) const;
    /** \details
      Convert inVal to [0.0 - 1.0] range.
    */
    double toDoubleRange(OdUInt32 inVal) const;
 
    /** \details
      Linear interpolation function.
    */
    static double linterp(double a, double b, double t);
    /** \details
      Exponential interpolation function.
    */
    static double einterp(double a, double b, double t);
    /** \details
      Cosine interpolation function.
    */
    static double cinterp(double a, double b, double t);
    /** \details
      Inverted exponential interpolation function.
    */
    static double ieinterp(double a, double b, double t);
};
 
/** \details
    Procedural textures generator.
 
    \sa
    TD_Gi
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiProceduralGenerator : public OdRxObject
{
  public:
    ODRX_DECLARE_MEMBERS(OdGiProceduralGenerator);
 
    // High-level functions
 
    /** \details
      Generate procedural texture.
      Returns false if protocol extension not initialized or no support for current procedural texture type.
      \param pTexture [in]  Procedural texture pointer.
      \param image [out]  Output image.
      \param renderCoef [in]  Texture detail multiplier. 1.0 - most standard device value, 10.0 - normal rendering.
                     This value can be calculated from raster resolution.
    */
    virtual bool generateProceduralTexture(OdGiProceduralTexturePtr pTexture,
                                           OdGiImageBGRA32 &image, double renderCoef = 1.0) = 0;
 
    /** \details
      Generate procedural wood texture.
      \param color1 [in]  First wood texture color.
      \param color2 [in]  Second wood texture color.
      \param radialNoise [in]  Radial noise amount.
      \param axialNoise [in]  Axial noise amount.
      \param grainThickness [in]  Thickness of wood grains.
      \param image [out]  Output image.
      \param renderCoef [in]  Texture detail multiplier. 1.0 - most standard device value, 10.0 - normal rendering.
                     This value can be calculated from raster resolution.
    */
    virtual void generateProceduralWood(OdGiPixelBGRA32 color1, OdGiPixelBGRA32 color2, double radialNoise, double axialNoise, double grainThickness,
                                        OdGiImageBGRA32 &image, double renderCoef = 1.0) = 0;
    /** \details
      Generate procedural marble texture.
      \param veinColor [in]  Color of marble veins.
      \param veinSpacing [in]  Distance between veins multiplier.
      \param veinWidth [in]  Marble veins width multiplier.
      \param image [out]  Output image.
      \param renderCoef [in]  Texture detail multiplier. 1.0 - most standard device value, 10.0 - normal rendering.
                     This value can be calculated from raster resolution.
    */
    virtual void generateProceduralMarble(OdGiPixelBGRA32 stoneColor, OdGiPixelBGRA32 veinColor, double veinSpacing, double veinWidth,
                                          OdGiImageBGRA32 &image, double renderCoef = 1.0) = 0;
 
    // Low-level functions
 
    /** \details
      Set color gradient. 
      
      \remarks
      If gradient is not set up, it will be generated in generateProceduralXXX
      functions. This function may be called before a generateProceduralXXX call for changing palettes
      in procedural texture generation.
    */
    virtual void setColorGradient(const OdGiGradientGenerator &gradient) = 0;
    /** \details
      Get color gradient.
    */
    virtual const OdGiGradientGenerator &colorGradient() const = 0;
};
 
/** \details
    This template class is a specialization of the OdSmartPtr class for OdGiProceduralGenerator object pointers.
        
    <group Type Definitions>
*/
typedef OdSmartPtr<OdGiProceduralGenerator> OdGiProceduralGeneratorPtr;
 
#include "TD_PackPop.h"
 
#endif // __ODGIPROCEDURALGENERATOR_H__