mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.8k stars 429 forks source link

TypePack issue #346

Closed lucasamparo closed 1 year ago

lucasamparo commented 1 year ago

Hi.

I'm trying to create a new Shape (Based on This), but when I try to compile the code, the assert about TypePack is triggered.

src/pbrt/util/containers.h(37): error: static assertion failed with "Type not present in TypePack" static_assert(!std::is_same_v<T, T>, "Type not present in TypePack"); ^ detected during: instantiation of class "pbrt::IndexOf<T, Ts...> [with T=pbrt::DistanceEstimator, Ts=<pbrt::TypePack<>>]" at line 47 instantiation of class "pbrt::IndexOf<T, pbrt::TypePack<U, Ts...>> [with T=pbrt::DistanceEstimator, U=pbrt::Curve, Ts=<>]" at line 47 instantiation of class "pbrt::IndexOf<T, pbrt::TypePack<U, Ts...>> [with T=pbrt::DistanceEstimator, U=pbrt::BilinearPatch, Ts=]" at line 47 instantiation of class "pbrt::IndexOf<T, pbrt::TypePack<U, Ts...>> [with T=pbrt::DistanceEstimator, U=pbrt::Triangle, Ts=<pbrt::BilinearPatch, pbrt::Curve>]" at line 47 instantiation of class "pbrt::IndexOf<T, pbrt::TypePack<U, Ts...>> [with T=pbrt::DistanceEstimator, U=pbrt::Disk, Ts=<pbrt::Triangle, pbrt::BilinearPatch, pbrt::Curve>]" at line 47 instantiation of class "pbrt::IndexOf<T, pbrt::TypePack<U, Ts...>> [with T=pbrt::DistanceEstimator, U=pbrt::Cylinder, Ts=<pbrt::Disk, pbrt::Triangle, pbrt::BilinearPatch, pbrt::Curve>]" at line 47 instantiation of class "pbrt::IndexOf<T, pbrt::TypePack<U, Ts...>> [with T=pbrt::DistanceEstimator, U=pbrt::Sphere, Ts=<pbrt::Cylinder, pbrt::Disk, pbrt::Triangle, pbrt::BilinearPatch, pbrt::Curve>]" at line 768 of /media/lucas/9922d45a-445b-4429-b4aa-80f75e16a0111/doutorado/pbrt-v4/src/pbrt/util/taggedptr.h instantiation of "unsigned int pbrt::TaggedPointer::TypeIndex() [with Ts=<pbrt::Sphere, pbrt::Cylinder, pbrt::Disk, pbrt::Triangle, pbrt::BilinearPatch, pbrt::Curve>, T=pbrt::DistanceEstimator]" at line 747 of /media/lucas/9922d45a-445b-4429-b4aa-80f75e16a0111/doutorado/pbrt-v4/src/pbrt/util/taggedptr.h instantiation of "pbrt::TaggedPointer::TaggedPointer(T *) [with Ts=<pbrt::Sphere, pbrt::Cylinder, pbrt::Disk, pbrt::Triangle, pbrt::BilinearPatch, pbrt::Curve>, T=pbrt::DistanceEstimator]" at line 36 of /media/lucas/9922d45a-445b-4429-b4aa-80f75e16a0111/doutorado/pbrt-v4/src/pbrt/base/shape.h

How can I put my new class inside this "TypePack" list? (DistanceEstimator).

mmp commented 1 year ago

Those directions correspond to pbrt-v3 and things have changed a bit since then.. Add it in src/pbrt/base/shape.h, following how other shapes are included in the TaggedPointer that Shape inherits from and that error should go away.

lucasamparo commented 1 year ago

Thanks for the fast answer, Dr. Pharr. The problem goes away by adding the class in "Shape Declarations" (line 19) and TaggedPointer instantiation (line 34).

Thank you so much.

In time, incredible work. I'm trying to understand and use your library for my Ph.D. research.