Commits

Jean-Philippe Grimaldi committed 6c68e54

Strongly type DifferentialGeometry::handle and ihandle to prevent wild casts and reduce error probabilities.

Jeanphi

Comments (0)

Files changed (4)

core/geometry/raydifferential.cpp

 DifferentialGeometry::DifferentialGeometry(const Point &P,
 		const Vector &DPDU, const Vector &DPDV,
 		const Normal &DNDU, const Normal &DNDV,
-		float uu, float vv, const void *pr)
+		float uu, float vv, const Primitive *pr)
 	: PartialDifferentialGeometry(P, DPDU, DPDV), dndu(DNDU), dndv(DNDV),
 	  tangent(DPDU), bitangent(DPDV), btsign(1.f) {
 	// Initialize _DifferentialGeometry_ from parameters
 		const Normal &NN,
 		const Vector &DPDU, const Vector &DPDV,
 		const Normal &DNDU, const Normal &DNDV,
-		float uu, float vv, const void *pr)
+		float uu, float vv, const Primitive *pr)
 	: PartialDifferentialGeometry(P, NN, DPDU, DPDV), dndu(DNDU), dndv(DNDV),
 	  tangent(DPDU), bitangent(DPDV), btsign(1.f) {
 	// Initialize _DifferentialGeometry_ from parameters
 		const Vector &DPDU, const Vector &DPDV,
 		const Normal &DNDU, const Normal &DNDV,
 		const Vector &T, const Vector &BiT, float BiTsign,
-		float uu, float vv, const void *pr)
+		float uu, float vv, const Primitive *pr)
 	: PartialDifferentialGeometry(P, NN, DPDU, DPDV), dndu(DNDU), dndv(DNDV),
 	  tangent(T), bitangent(BiT), btsign(BiTsign) {
 	// Initialize _DifferentialGeometry_ from parameters

core/geometry/raydifferential.h

 namespace lux
 {
 
+class Primitive;
+
 class PartialDifferentialGeometry
 {
 public:
 			const Vector &DPDU,	const Vector &DPDV,
 			const Normal &DNDU, const Normal &DNDV,
 			float uu, float vv,
-			const void *pr);
+			const Primitive *pr);
 	DifferentialGeometry(
 			const Point &P, const Normal &NN,
 			const Vector &DPDU,	const Vector &DPDV,
 			const Normal &DNDU, const Normal &DNDV,
 			float uu, float vv,
-			const void *pr);
+			const Primitive *pr);
 	DifferentialGeometry(
 			const Point &P, const Normal &NN,
 			const Vector &DPDU,	const Vector &DPDV,
 			const Normal &DNDU, const Normal &DNDV,
 			const Vector &T, const Vector &BiT, float BiTsign,
 			float uu, float vv,
-			const void *pr);
+			const Primitive *pr);
 	void AdjustNormal(bool ro, bool swapsHandedness) {
 		// Adjust normal based on orientation and handedness
 		if (ro ^ swapsHandedness)
 	Vector tangent, bitangent; // surface tangents, may be different to dpdu,dpdv but in same plane, not normalized
 	float btsign; // sign of the bitangent, actual bitangent is "bitangent * (btsign > 0.f ? 1.f : -1.f)"
 	float u, v;
-	const void* handle;
-	const void* ihandle; // handle to intersected primitive, used with instances
+	const Primitive *handle;
+	const Primitive *ihandle; // handle to intersected primitive, used with instances
 
 	// Dade - shape specific data, useful to "transport" informatin between
 	// shape intersection method and GetShadingGeometry()
 Point LocalMapping3D::Map(const DifferentialGeometry &dg) const
 {
 	const Transform W2T(WorldToTexture *
-		static_cast<const Primitive *>(dg.handle)->GetWorldToLocal(dg.time));
+		dg.handle->GetWorldToLocal(dg.time));
 	return W2T(dg.p);
 }
 Point LocalMapping3D::MapDuv(const DifferentialGeometry &dg,
 	Vector *dpdu, Vector *dpdv) const
 {
 	const Transform W2T(WorldToTexture *
-		static_cast<const Primitive *>(dg.handle)->GetWorldToLocal(dg.time));
+		dg.handle->GetWorldToLocal(dg.time));
 	*dpdu = W2T(dg.dpdu);
 	*dpdv = W2T(dg.dpdv);
 	return W2T(dg.p);
 Point LocalNormalMapping3D::Map(const DifferentialGeometry &dg) const
 {
 	const Transform W2T(WorldToTexture *
-		static_cast<const Primitive *>(dg.handle)->GetWorldToLocal(dg.time));
+		dg.handle->GetWorldToLocal(dg.time));
 	const Normal n(W2T(dg.nn));
 	return Point(n.x, n.y, n.z);
 }
 	Vector *dpdu, Vector *dpdv) const
 {
 	const Transform W2T(WorldToTexture *
-		static_cast<const Primitive *>(dg.handle)->GetWorldToLocal(dg.time));
+		dg.handle->GetWorldToLocal(dg.time));
 	*dpdu = Vector(W2T(dg.dndu));
 	*dpdv = Vector(W2T(dg.dndv));
 	const Normal n(W2T(dg.nn));

shapes/loopsubdiv.cpp

 				SDVertex *vv = face->v[face->vnum(v->P)];
 				DifferentialGeometry dg(v->P, v->n, dpdu, dpdv,
 					Normal(0, 0, 0), Normal(0, 0, 0),
-					vv->u, vv->v, this);
+					vv->u, vv->v, NULL);
 
 				dl += displacementMap->Evaluate(swl, dg);
 				++nf;
 				SDVertex *vv = face->v[face->vnum(v->P)];
 				DifferentialGeometry dg(v->P, v->n, dpdu, dpdv,
 					Normal(0, 0, 0), Normal(0, 0, 0),
-					vv->u, vv->v, this);
+					vv->u, vv->v, NULL);
 
 				dl += displacementMap->Evaluate(swl, dg);
 				++nf;
 				SDVertex *vv = face->v[face->vnum(v->P)];
 				DifferentialGeometry dg(v->P, v->n, dpdu, dpdv,
 					Normal(0, 0, 0), Normal(0, 0, 0),
-					vv->u, vv->v, this);
+					vv->u, vv->v, NULL);
 
 				dl += displacementMap->Evaluate(swl, dg);
 				++nf;