Hello forum,
I believe that i have the design problem that i need to discuss about.
Intersectable is the super-class; Triangle and Sphere are the sub-classes of the Intersectable
i believe that you already realized class inheritance structure. I have the following pure virtual functions declared inside the INTERSECTABLE
virtual bool sampleDirection(const Intersection&,Vector3D&) = 0;
virtual float getPDF(const Intersection&,
const Intersection&) = 0;
Each of the sub-classes are defining the above functions.
There is another class called AreaLight that contains a std::vector as follows:
class LuminaireProbability
{
public:
LuminaireProbability() : mIntersectable(0),mMaterial(0),mLuminaireProbabilityValue(0.0f),
mCumulativeDistributionValue(0.0f)
{
}
~LuminaireProbability()
{
mIntersectable = 0;
mMaterial = 0;
}
//luminaire as an intersectable
Intersectable *mIntersectable;
//material of the intersectable
Material *mMaterial;
//probability of choosing the luminaire
float mLuminaireProbabilityValue;
//cumulative distribution value
float mCumulativeDistributionValue;
};
//the area light contains the reference
//to the geometric object to be the light source
//the geometric object in turn contains the emissive material
//thus providing the illumination
//in this way the type of geometric object automatically determines
//the type of light, in principle it allows any type of the geometric
//object to be a light source
//SOME OF THE ABOVE STATEMENTS DEMANS CHANGE
std::vector<LuminaireProbability*> mLightIntersectables;
//store the selected lumianire from the vector
LuminaireProbability *mSelectedLuminaire;
I have the std::vector populated with a pointer of intersectables of type triangle or sphere along with some other trivial information. Now i have the following function
//calcualate the world position based on the intersection point
bool AreaLight::calculateSampleDirection(const Intersection &intersection,Vector3D &sampleVector)
{
//choose the light intersectables based on the weight of the probaiblity
//that we have calculated in the prepare() function
float selectionProbability = 0.0f;
//create a random instance
RandomGenerator random = RandomGenerator::getRandomInstance();
//create a canonical random number between 0 and 1
selectionProbability = static_cast<float>(random.generateDouble(0,1));
CompareToCDF cdf;
//store the canonical random value
cdf.mRandomValue = selectionProbability;
// CompareAreaLight cmpAreaLight;
// //sort the light intersectables based on the luminaire probability value
// std::sort(mLightIntersectables.begin(),mLightIntersectables.end(),cmpAreaLight);
std::vector<LuminaireProbability*>::iterator it;
it = std::find_if(mLightIntersectables.begin(),mLightIntersectables.end(),cdf);
assert(it != mLightIntersectables.end());
//store the selected luminaire
mSelectedLuminaire = *it;
//I AM GETTING A SEGMENTATION FAULT IN THE FOLLOWING FUNCTION - !!!!!
mSelectedLuminaire->mIntersectable->sampleDirection(intersection,sampleVector);
return true;
}
As mentioned in the code i am getting the segmentation fault that the debugger is not even giving any hint of.
I hope you will be able to help me find out the issue here that i am missing.
Is there any logical mistake i am doing here?
I tried the following as follows , but till i am having the segmentation fault .
...................
if(mSelectedLuminaire != 0)
{
if(mSelectedLuminaire->mIntersectable != 0)
mSelectedLuminaire->mIntersectable->sampleDirection(intersection,sampleVector);
}
......................
Then i ran the GDB and it gave me the following information.
(gdb) backtrace
#0 0x2efd85ba in ?? ()
#1 0x0804e018 in AreaLight::calculateSampleDirection (this=0x80c4d60,
intersection=..., sampleVector=...) at arealight.cpp:151
#2 0x080556ed in Intersection::getShadowRay (this=0xbfffedfc, light=0x80c4d60)
at intersection.cpp:152
#3 0x08069787 in PathTracer::computeDirectIllumination (this=0xbffff220,
intersection=...) at pathtracer.cpp:179
#4 0x0806a3df in PathTracer::computeRadiance (this=0xbffff220,
intersection=..., depth=5) at pathtracer.cpp:141
#5 0x0806a63f in PathTracer::trace (this=0xbffff220, ray=..., E=1)
at pathtracer.cpp:127
#6 0x0806a8e0 in PathTracer::tracePixel (this=0xbffff220, x=0, y=1)
at pathtracer.cpp:95
#7 0x0806aa14 in PathTracer::computeImage() [clone ._omp_fn.0] ()
at pathtracer.cpp:53
#8 0x0806ac46 in PathTracer::computeImage (this=0xbffff220)
at pathtracer.cpp:47
#9 0x0804c397 in main (argc=1, argv=0xbffff304) at main.cpp:504
(gdb)
I hope some one in the forum wil be able to help me to debug this issue.
Where should i look into now?
Is there any more information you need please ask for it.
Regards
Sajjad