Skip to content

Commit da27569

Browse files
committed
Some pattern-related refactoring.
1 parent 4d21059 commit da27569

File tree

11 files changed

+427
-406
lines changed

11 files changed

+427
-406
lines changed

source/core/configcore.h

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,22 @@ namespace pov
165165
#define POV_BLEND_MAP_DEBUG POV_DEBUG
166166
#endif
167167

168-
/// @def POV_SHAPE_DEBUG
169-
/// Enable run-time sanity checks for geometric shapes.
168+
/// @def POV_PATTERN_DEBUG
169+
/// Enable run-time sanity checks for pattern handling.
170170
///
171171
/// Define as non-zero integer to enable, or zero to disable.
172172
///
173-
#ifndef POV_SHAPE_DEBUG
174-
#define POV_SHAPE_DEBUG POV_DEBUG
173+
#ifndef POV_PATTERN_DEBUG
174+
#define POV_PATTERN_DEBUG POV_DEBUG
175175
#endif
176176

177-
/// @def POV_PATTERN_DEBUG
178-
/// Enable run-time sanity checks for pattern handling.
177+
/// @def POV_PIGMENT_DEBUG
178+
/// Enable run-time sanity checks for pigment handling.
179179
///
180180
/// Define as non-zero integer to enable, or zero to disable.
181181
///
182-
#ifndef POV_PATTERN_DEBUG
183-
#define POV_PATTERN_DEBUG POV_DEBUG
182+
#ifndef POV_PIGMENT_DEBUG
183+
#define POV_PIGMENT_DEBUG POV_DEBUG
184184
#endif
185185

186186
/// @def POV_RADIOSITY_DEBUG
@@ -210,6 +210,15 @@ namespace pov
210210
#define POV_REFPOOL_DEBUG POV_DEBUG
211211
#endif
212212

213+
/// @def POV_SHAPE_DEBUG
214+
/// Enable run-time sanity checks for geometric shapes.
215+
///
216+
/// Define as non-zero integer to enable, or zero to disable.
217+
///
218+
#ifndef POV_SHAPE_DEBUG
219+
#define POV_SHAPE_DEBUG POV_DEBUG
220+
#endif
221+
213222
/// @def POV_SUBSURFACE_DEBUG
214223
/// Enable run-time sanity checks for subsurface light transport.
215224
///
@@ -236,18 +245,18 @@ namespace pov
236245
#define POV_BLEND_MAP_ASSERT(expr) POV_ASSERT_DISABLE(expr)
237246
#endif
238247

239-
#if POV_SHAPE_DEBUG
240-
#define POV_SHAPE_ASSERT(expr) POV_ASSERT_HARD(expr)
241-
#else
242-
#define POV_SHAPE_ASSERT(expr) POV_ASSERT_DISABLE(expr)
243-
#endif
244-
245248
#if POV_PATTERN_DEBUG
246249
#define POV_PATTERN_ASSERT(expr) POV_ASSERT_HARD(expr)
247250
#else
248251
#define POV_PATTERN_ASSERT(expr) POV_ASSERT_DISABLE(expr)
249252
#endif
250253

254+
#if POV_PIGMENT_DEBUG
255+
#define POV_PIGMENT_ASSERT(expr) POV_ASSERT_HARD(expr)
256+
#else
257+
#define POV_PIGMENT_ASSERT(expr) POV_ASSERT_DISABLE(expr)
258+
#endif
259+
251260
#if POV_RADIOSITY_DEBUG
252261
#define POV_RADIOSITY_ASSERT(expr) POV_ASSERT_HARD(expr)
253262
#else
@@ -266,6 +275,12 @@ namespace pov
266275
#define POV_REFPOOL_ASSERT(expr) POV_ASSERT_DISABLE(expr)
267276
#endif
268277

278+
#if POV_SHAPE_DEBUG
279+
#define POV_SHAPE_ASSERT(expr) POV_ASSERT_HARD(expr)
280+
#else
281+
#define POV_SHAPE_ASSERT(expr) POV_ASSERT_DISABLE(expr)
282+
#endif
283+
269284
#if POV_SUBSURFACE_DEBUG
270285
#define POV_SUBSURFACE_ASSERT(expr) POV_ASSERT_HARD(expr)
271286
#else

source/core/material/normal.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ void Perturb_Normal(Vector3d& Layer_Normal, const TNORMAL *Tnormal, const Vector
838838

839839
/* No normal_map. */
840840

841-
if (Tnormal->Type <= LAST_NORM_ONLY_PATTERN)
841+
if (Tnormal->Type <= LAST_SPECIAL_NORM_PATTERN)
842842
{
843843
Warp_Normal(Layer_Normal,Layer_Normal, Tnormal,
844844
Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
@@ -886,7 +886,6 @@ void Perturb_Normal(Vector3d& Layer_Normal, const TNORMAL *Tnormal, const Vector
886886

887887
UnWarp_Normal(Layer_Normal,Layer_Normal,Tnormal,
888888
Test_Flag(Tnormal,DONT_SCALE_BUMPS_FLAG));
889-
890889
}
891890

892891
if ( Intersection )
@@ -983,7 +982,7 @@ static DBL Hermite_Cubic(DBL T1, const Vector2d& UV1, const Vector2d& UV2)
983982
* DESCRIPTION
984983
*
985984
* CHANGES
986-
* Added intersectin parameter for UV mapping - NK 1998
985+
* Added intersection parameter for UV mapping - NK 1998
987986
*
988987
******************************************************************************/
989988

source/core/material/pattern.cpp

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,42 @@ ColourBlendMapConstPtr BasicPattern::GetDefaultBlendMap() const { return gpDefau
281281
bool BasicPattern::HasSpecialTurbulenceHandling() const { return false; }
282282

283283

284+
ImagePatternImpl::ImagePatternImpl() :
285+
pImage(NULL)
286+
{}
287+
288+
ImagePatternImpl::ImagePatternImpl(const ImagePatternImpl& obj) :
289+
pImage(obj.pImage ? Copy_Image(obj.pImage) : NULL)
290+
{}
291+
292+
ImagePatternImpl::~ImagePatternImpl()
293+
{
294+
if (pImage)
295+
Destroy_Image(pImage);
296+
}
297+
298+
299+
ColourPattern::ColourPattern() :
300+
BasicPattern()
301+
{}
302+
303+
ColourPattern::ColourPattern(const ColourPattern& obj) :
304+
BasicPattern(obj)
305+
{}
306+
307+
DBL ColourPattern::Evaluate(const Vector3d& EPoint, const Intersection *pIsection, const Ray *pRay, TraceThreadData *pThread) const
308+
{
309+
TransColour colour;
310+
if (Evaluate(colour, EPoint, pIsection, pRay, pThread))
311+
return colour.Greyscale();
312+
else
313+
return 0.0;
314+
}
315+
316+
unsigned int ColourPattern::NumDiscreteBlendMapEntries() const { return 0; }
317+
bool ColourPattern::CanMap() const { return false; }
318+
319+
284320
ContinuousPattern::ContinuousPattern() :
285321
BasicPattern(),
286322
waveType(kWaveType_Ramp),
@@ -338,10 +374,17 @@ DBL ContinuousPattern::Evaluate(const Vector3d& EPoint, const Intersection *pIse
338374
}
339375

340376
unsigned int ContinuousPattern::NumDiscreteBlendMapEntries() const { return 0; }
377+
bool ContinuousPattern::CanMap() const { return true; }
341378

379+
bool DiscretePattern::CanMap() const { return false; }
342380

343381
unsigned int PlainPattern::NumDiscreteBlendMapEntries() const { return 1; }
344382

383+
unsigned int AveragePattern::NumDiscreteBlendMapEntries() const { return 0; }
384+
bool AveragePattern::CanMap() const { return true; }
385+
DBL AveragePattern::Evaluate(const Vector3d& EPoint, const Intersection *pIsection, const Ray *pRay, TraceThreadData *pThread) const { return 0.0; }
386+
bool AveragePattern::HasSpecialTurbulenceHandling() const { return false; }
387+
345388

346389
ColourBlendMapConstPtr AgatePattern::GetDefaultBlendMap() const { return gpDefaultBlendMap_Agate; }
347390

@@ -357,6 +400,35 @@ ColourBlendMapConstPtr CubicPattern::GetDefaultBlendMap() const { return gpDefau
357400
unsigned int CubicPattern::NumDiscreteBlendMapEntries() const { return 6; }
358401

359402

403+
bool ColourImagePattern::Evaluate(TransColour& result, const Vector3d& EPoint, const Intersection *pIsection, const Ray *pRay, TraceThreadData *pThread) const
404+
{
405+
// TODO ALPHA - the caller does expect non-premultiplied data, but maybe he could profit from premultiplied data?
406+
407+
int reg_number;
408+
DBL xcoor = 0.0, ycoor = 0.0;
409+
410+
// If outside map coverage area, return clear
411+
412+
if (map_pos(EPoint, this, &xcoor, &ycoor))
413+
{
414+
result = ToTransColour(RGBFTColour(1.0, 1.0, 1.0, 0.0, 1.0));
415+
return false;
416+
}
417+
else
418+
{
419+
RGBFTColour rgbft;
420+
image_colour_at(pImage, xcoor, ycoor, rgbft, &reg_number, false);
421+
result = ToTransColour(rgbft);
422+
return true;
423+
}
424+
}
425+
426+
bool ColourImagePattern::HasTransparency() const
427+
{
428+
return (!pImage || pImage->Once_Flag || !is_image_opaque(pImage));
429+
}
430+
431+
360432
DensityFilePattern::DensityFilePattern() :
361433
densityFile(NULL)
362434
{}
@@ -402,24 +474,6 @@ ColourBlendMapConstPtr HexagonPattern::GetDefaultBlendMap() const { return gpDef
402474
unsigned int HexagonPattern::NumDiscreteBlendMapEntries() const { return 3; }
403475

404476

405-
ImagePattern::ImagePattern() :
406-
pImage(NULL)
407-
{}
408-
409-
ImagePattern::ImagePattern(const ImagePattern& obj) :
410-
ContinuousPattern(obj),
411-
pImage(NULL)
412-
{
413-
if (obj.pImage)
414-
pImage = Copy_Image(obj.pImage);
415-
}
416-
417-
ImagePattern::~ImagePattern()
418-
{
419-
if (pImage)
420-
Destroy_Image(pImage);
421-
}
422-
423477
DBL ImagePattern::EvaluateRaw(const Vector3d& EPoint, const Intersection *pIsection, const Ray *pRay, TraceThreadData *pThread) const
424478
{
425479
return image_pattern(EPoint, this);

0 commit comments

Comments
 (0)