Skip to content

Commit 53f0ebd

Browse files
committed
Reduced memory footprint of sphere primitive.
Until now, spheres subject to transformation (translation, rotation, scaling etc.) required an extra data block of 256 bytes. This data block has been eliminated, along with a corresponding pointer in the sphere's basic data block.
1 parent 8e965a9 commit 53f0ebd

File tree

4 files changed

+27
-55
lines changed

4 files changed

+27
-55
lines changed

source/base/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define OFFICIAL_VERSION_STRING "3.7.1"
4646
#define OFFICIAL_VERSION_NUMBER 371
4747

48-
#define POV_RAY_PRERELEASE "alpha.8704732"
48+
#define POV_RAY_PRERELEASE "alpha.8730959"
4949

5050
#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
5151
#ifdef POV_RAY_PRERELEASE

source/core/shape/sphere.cpp

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ ObjectPtr Sphere::Copy()
375375
*New = *this;
376376
New->Trans = Copy_Transform(Trans);
377377

378-
New->UV_Trans = Copy_Transform(UV_Trans);
379-
380378
return(New);
381379
}
382380

@@ -409,20 +407,16 @@ ObjectPtr Sphere::Copy()
409407

410408
void Sphere::Translate(const Vector3d& Vector, const TRANSFORM *tr)
411409
{
412-
if(Trans == NULL)
410+
if(!Do_Ellipsoid)
413411
{
414-
if(UV_Trans == NULL)
415-
UV_Trans = Create_Transform();
416-
Compose_Transforms(UV_Trans, tr);
417-
418412
Center += Vector;
419-
420-
Compute_BBox();
421413
}
422414
else
423415
{
424-
Transform(tr);
416+
Compose_Transforms(Trans, tr);
425417
}
418+
419+
Compute_BBox();
426420
}
427421

428422

@@ -455,20 +449,14 @@ void Sphere::Translate(const Vector3d& Vector, const TRANSFORM *tr)
455449

456450
void Sphere::Rotate(const Vector3d&, const TRANSFORM *tr)
457451
{
458-
if(Trans == NULL)
459-
{
460-
if (UV_Trans == NULL)
461-
UV_Trans = Create_Transform();
462-
Compose_Transforms(UV_Trans, tr);
452+
if (Trans == NULL)
453+
Trans = Create_Transform();
454+
Compose_Transforms(Trans, tr);
463455

456+
if(!Do_Ellipsoid)
464457
MTransPoint(Center, Center, tr);
465458

466-
Compute_BBox();
467-
}
468-
else
469-
{
470-
Transform(tr);
471-
}
459+
Compute_BBox();
472460
}
473461

474462

@@ -503,30 +491,26 @@ void Sphere::Scale(const Vector3d& Vector, const TRANSFORM *tr)
503491
{
504492
if ((Vector[X] != Vector[Y]) || (Vector[X] != Vector[Z]))
505493
{
506-
if (Trans == NULL)
494+
if (!Do_Ellipsoid)
507495
{
508496
// treat sphere as ellipsoid as it's unevenly scaled
509-
Do_Ellipsoid = true; // FIXME - parser needs to select sphere or ellipsoid
510-
Trans = Create_Transform();
497+
Do_Ellipsoid = true;
498+
if (Trans == NULL)
499+
Trans = Create_Transform();
511500
}
512501
}
513502

514-
if (Trans == NULL)
503+
if (!Do_Ellipsoid)
515504
{
516-
if (UV_Trans == NULL)
517-
UV_Trans = Create_Transform();
518-
Compose_Transforms(UV_Trans, tr);
519-
520505
Center *= Vector[X];
521-
522506
Radius *= fabs(Vector[X]);
523-
524-
Compute_BBox();
525507
}
526508
else
527509
{
528-
Transform(tr);
510+
Compose_Transforms(Trans, tr);
529511
}
512+
513+
Compute_BBox();
530514
}
531515

532516

@@ -561,7 +545,6 @@ Sphere::Sphere() :
561545
ObjectBase(SPHERE_OBJECT),
562546
Center(0.0, 0.0, 0.0),
563547
Radius(1.0),
564-
UV_Trans(NULL),
565548
Do_Ellipsoid(false) // FIXME
566549
{}
567550

@@ -593,16 +576,10 @@ Sphere::Sphere() :
593576

594577
void Sphere::Transform(const TRANSFORM *tr)
595578
{
596-
if (UV_Trans == NULL)
597-
UV_Trans = Create_Transform();
598-
Compose_Transforms(UV_Trans, tr);
579+
Do_Ellipsoid = true;
599580

600581
if(Trans == NULL)
601-
{
602-
Do_Ellipsoid = true;
603582
Trans = Create_Transform();
604-
}
605-
606583
Compose_Transforms(Trans, tr);
607584

608585
Compute_BBox();
@@ -648,8 +625,6 @@ Sphere::~Sphere()
648625
Debug_Info("\t%f // Radius\n", (DBL)Radius);
649626
Debug_Info("}\n");
650627
#endif
651-
652-
Destroy_Transform(UV_Trans);
653628
}
654629

655630

@@ -688,7 +663,7 @@ void Sphere::Compute_BBox()
688663
{
689664
Make_BBox(BBox, Center[X] - Radius, Center[Y] - Radius, Center[Z] - Radius, 2.0 * Radius, 2.0 * Radius, 2.0 * Radius);
690665

691-
if(Trans != NULL)
666+
if(Do_Ellipsoid)
692667
{
693668
Recompute_BBox(&BBox, Trans);
694669
}
@@ -729,17 +704,15 @@ void Sphere::UVCoord(Vector2d& Result, const Intersection *Inter, TraceThreadDat
729704
Vector3d New_Point, New_Center;
730705

731706
/* Transform the point into the sphere's space */
732-
if (UV_Trans != NULL)
707+
if (Trans != NULL)
733708
{
734709

735-
MInvTransPoint(New_Point, Inter->IPoint, UV_Trans);
710+
MInvTransPoint(New_Point, Inter->IPoint, Trans);
736711

737-
if (Trans != NULL)
738-
MTransPoint(New_Center, Center, Trans);
739-
else
712+
if (Do_Ellipsoid)
740713
New_Center = Center;
741-
742-
MInvTransPoint(New_Center, New_Center, UV_Trans);
714+
else
715+
MInvTransPoint(New_Center, Center, Trans);
743716
}
744717
else
745718
{

source/core/shape/sphere.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class Sphere : public ObjectBase
7979

8080
static bool Intersect(const BasicRay& ray, const Vector3d& Center, DBL Radius2, DBL *Depth1, DBL *Depth2);
8181
private:
82-
bool Do_Ellipsoid; // TODO - parser needs to take care of this
83-
TRANSFORM *UV_Trans;
82+
bool Do_Ellipsoid;
8483
};
8584

8685
}

unix/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.1-alpha.8704732
1+
3.7.1-alpha.8730959

0 commit comments

Comments
 (0)