Skip to content

Commit

Permalink
Reduced memory footprint of sphere primitive.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
c-lipka committed Aug 7, 2016
1 parent 8e965a9 commit 53f0ebd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 55 deletions.
2 changes: 1 addition & 1 deletion source/base/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define OFFICIAL_VERSION_STRING "3.7.1"
#define OFFICIAL_VERSION_NUMBER 371

#define POV_RAY_PRERELEASE "alpha.8704732"
#define POV_RAY_PRERELEASE "alpha.8730959"

#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
#ifdef POV_RAY_PRERELEASE
Expand Down
75 changes: 24 additions & 51 deletions source/core/shape/sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,6 @@ ObjectPtr Sphere::Copy()
*New = *this;
New->Trans = Copy_Transform(Trans);

New->UV_Trans = Copy_Transform(UV_Trans);

return(New);
}

Expand Down Expand Up @@ -409,20 +407,16 @@ ObjectPtr Sphere::Copy()

void Sphere::Translate(const Vector3d& Vector, const TRANSFORM *tr)
{
if(Trans == NULL)
if(!Do_Ellipsoid)
{
if(UV_Trans == NULL)
UV_Trans = Create_Transform();
Compose_Transforms(UV_Trans, tr);

Center += Vector;

Compute_BBox();
}
else
{
Transform(tr);
Compose_Transforms(Trans, tr);
}

Compute_BBox();
}


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

void Sphere::Rotate(const Vector3d&, const TRANSFORM *tr)
{
if(Trans == NULL)
{
if (UV_Trans == NULL)
UV_Trans = Create_Transform();
Compose_Transforms(UV_Trans, tr);
if (Trans == NULL)
Trans = Create_Transform();
Compose_Transforms(Trans, tr);

if(!Do_Ellipsoid)
MTransPoint(Center, Center, tr);

Compute_BBox();
}
else
{
Transform(tr);
}
Compute_BBox();
}


Expand Down Expand Up @@ -503,30 +491,26 @@ void Sphere::Scale(const Vector3d& Vector, const TRANSFORM *tr)
{
if ((Vector[X] != Vector[Y]) || (Vector[X] != Vector[Z]))
{
if (Trans == NULL)
if (!Do_Ellipsoid)
{
// treat sphere as ellipsoid as it's unevenly scaled
Do_Ellipsoid = true; // FIXME - parser needs to select sphere or ellipsoid
Trans = Create_Transform();
Do_Ellipsoid = true;
if (Trans == NULL)
Trans = Create_Transform();
}
}

if (Trans == NULL)
if (!Do_Ellipsoid)
{
if (UV_Trans == NULL)
UV_Trans = Create_Transform();
Compose_Transforms(UV_Trans, tr);

Center *= Vector[X];

Radius *= fabs(Vector[X]);

Compute_BBox();
}
else
{
Transform(tr);
Compose_Transforms(Trans, tr);
}

Compute_BBox();
}


Expand Down Expand Up @@ -561,7 +545,6 @@ Sphere::Sphere() :
ObjectBase(SPHERE_OBJECT),
Center(0.0, 0.0, 0.0),
Radius(1.0),
UV_Trans(NULL),
Do_Ellipsoid(false) // FIXME
{}

Expand Down Expand Up @@ -593,16 +576,10 @@ Sphere::Sphere() :

void Sphere::Transform(const TRANSFORM *tr)
{
if (UV_Trans == NULL)
UV_Trans = Create_Transform();
Compose_Transforms(UV_Trans, tr);
Do_Ellipsoid = true;

if(Trans == NULL)
{
Do_Ellipsoid = true;
Trans = Create_Transform();
}

Compose_Transforms(Trans, tr);

Compute_BBox();
Expand Down Expand Up @@ -648,8 +625,6 @@ Sphere::~Sphere()
Debug_Info("\t%f // Radius\n", (DBL)Radius);
Debug_Info("}\n");
#endif

Destroy_Transform(UV_Trans);
}


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

if(Trans != NULL)
if(Do_Ellipsoid)
{
Recompute_BBox(&BBox, Trans);
}
Expand Down Expand Up @@ -729,17 +704,15 @@ void Sphere::UVCoord(Vector2d& Result, const Intersection *Inter, TraceThreadDat
Vector3d New_Point, New_Center;

/* Transform the point into the sphere's space */
if (UV_Trans != NULL)
if (Trans != NULL)
{

MInvTransPoint(New_Point, Inter->IPoint, UV_Trans);
MInvTransPoint(New_Point, Inter->IPoint, Trans);

if (Trans != NULL)
MTransPoint(New_Center, Center, Trans);
else
if (Do_Ellipsoid)
New_Center = Center;

MInvTransPoint(New_Center, New_Center, UV_Trans);
else
MInvTransPoint(New_Center, Center, Trans);
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions source/core/shape/sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class Sphere : public ObjectBase

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

}
Expand Down
2 changes: 1 addition & 1 deletion unix/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1-alpha.8704732
3.7.1-alpha.8730959

0 comments on commit 53f0ebd

Please sign in to comment.