// No scaling
void SpotLightParameterEstimationClass::WriteExponentValueToImage() {
    UtilityClass* util = new UtilityClass();
    Rgba* outputPixels = util->GetImagePixelsToWrite(_imageWidth,_imageHeight);
    
    for (int index = 0; index < exponentOfFallOffRegion.size(); ++index)
        outputPixels[exponentOfFallOffRegion[index].first].g = exponentOfFallOffRegion[index].second;
    WriteToImage(outputPixels,"ExponentValue1.exr");
    delete [] outputPixels;
    delete util;
}
// scaling
void SpotLightParameterEstimationClass::WriteExponentValueToImage(double maxExpValue, double minExpValue) {
    UtilityClass* util = new UtilityClass();
    Rgba* outputPixels = util->GetImagePixelsToWrite(_imageWidth,_imageHeight);
    
    // convert expoenentValues between 0 and 1
    std::vector<double>spotLightFallOffExponentVector = std::vector<double>(exponentOfFallOffRegion.size(),0);
    for (int index = 0; index < exponentOfFallOffRegion.size(); ++index) {
        spotLightFallOffExponentVector[index] = ((exponentOfFallOffRegion[index].second) - minExpValue)/(maxExpValue - minExpValue);
        outputPixels[exponentOfFallOffRegion[index].first].g = spotLightFallOffExponentVector[index];
    }
     WriteToImage(outputPixels,"ExponentScaled1.exr");
    delete[] outputPixels;
    delete util;
}
Beispiel #3
0
         void operator()( tBlob const& blob ) {
            if( bl.applyFilter( blob ) ) {
               WriteToImage( blob.streaks(), img, color, bordercolor );
            }

         }
void SpotLightParameterEstimationClass::CalculatePixelValue() {
    
    _inputSetter =  GetSpotLightExponentInputParameters();
    
    UtilityClass* util = new UtilityClass();
    Rgba* outputPixels = util->GetImagePixelsToWrite(_imageWidth, _imageHeight);
    
    std::ofstream outputPixelValue;
    outputPixelValue.open("../../Output/outputPixel-blend1.txt");
    
    std::ofstream outputOriginalPixelValue;
    outputOriginalPixelValue.open("../../Output/originalPixel-blend1.txt");
    
    
    for(int row = 0; row < _imageHeight; ++row) {
        for (int col = 0; col < _imageWidth; ++col) {
            Rgba p = (_imageSystem->GetCurrentImage().GetImage2DArrayPixels())[row][col];
            double averagePixelIntensityValue   =   (p.r + p.g + p.b)/3;
            
            outputOriginalPixelValue << row << "," << col << " = " << averagePixelIntensityValue << std::endl;
        }
    }
    
    std::vector<MapOFImageAndWorldPoints>reprojectedPoints = _inputSetter->reprojectedPoints;
    double cosOfInner_minus_OuterConeAngle  =   _inputSetter->cosOfInnerConeAngle - _inputSetter->cosOfOuterConeAngle;
    if(cosOfInner_minus_OuterConeAngle == 0)
        cosOfInner_minus_OuterConeAngle = EPSILON;
    double gamma = 1.0/_inputSetter->gammaCorrection;
    
    // Reprojected 3D points
    std::vector<Point2D<int>> spotLightCoreExponentVectorPosition;
    double r = _inputSetter->vnormal.dot(Eigen::Vector3d(-4,-4,2) - _inputSetter->lightPosition);
    
    for (int index = 0; index < reprojectedPoints.size(); ++index) {
        
        Eigen::Vector3d lightToPointDirectionVector =  reprojectedPoints[index]._worldPoint - _inputSetter->lightPosition;
        double distance = std::sqrt(lightToPointDirectionVector.dot(lightToPointDirectionVector));
        lightToPointDirectionVector.normalize();
        
        float lambertTerm = (-lightToPointDirectionVector).dot(_inputSetter->vnormal);
        // No light gets reflected from the surface at the particular point
        
        // Use it for attentuation factor
        double cosOfCurrAngle                   =   _inputSetter->lightDirection.dot(lightToPointDirectionVector);
        double IntensityFactorExponent =  std::pow((double)((cosOfCurrAngle - _inputSetter->cosOfOuterConeAngle) / (cosOfInner_minus_OuterConeAngle)), 4);
      
        Rgba pixelValue;
//        if(cosOfCurrAngle >= input->cosOfInnerConeAngle)
//        {
//            double v = lambertTerm * input->lightIntensity * input->materialAlbedo * attenuation;
//            pixelValue = Rgba(pow(v,gamma),pow(v,gamma),pow(v,gamma),1.0);
//                        
//        }
        if (cosOfCurrAngle > _inputSetter->cosOfOuterConeAngle)
        {
            //double attenuation = 1.0 / (1.0 + (2/r)* distance + (1/(r*r)) * pow(distance, 2));
            double attenuation = 1.0 / (r*r)*(distance*distance);
            if (lambertTerm > 0) {
                double v = (lambertTerm * _inputSetter->lightIntensity * _inputSetter->materialAlbedo * IntensityFactorExponent * attenuation);
                pixelValue = Rgba(pow(v,gamma),pow(v,gamma),pow(v,gamma),1.0);
            }
        }
        else
            pixelValue = Rgba(0,0,0,1);
        
        int i = reprojectedPoints[index]._imagepixel.y * _inputSetter->imageWidth + reprojectedPoints[index]._imagepixel.x;
        outputPixelValue << reprojectedPoints[index]._imagepixel.y << "," << reprojectedPoints[index]._imagepixel.x << " = " << pixelValue.r << std::endl;
        outputPixels[i] = pixelValue;
    }
    
    WriteToImage(outputPixels, "imagepixel-blend1.exr");
    outputPixelValue.close();
    outputOriginalPixelValue.close();
    delete [] outputPixels;
    
}