Пример #1
0
inline Tv hermite(Tp f,
	const Tv& w, const Tv& x, const Tv& y, const Tv& z,
	Tp tension, Tp bias)
{
	tension = (Tp(1) - tension)*Tp(0.5);

	// compute endpoint tangents
	//Tv m0 = ((x-w)*(1+bias) + (y-x)*(1-bias))*tension;
	//Tv m1 = ((y-x)*(1+bias) + (z-y)*(1-bias))*tension;
	Tv m0 = ((x*Tv(2) - w - y)*bias + y - w)*tension;
	Tv m1 = ((y*Tv(2) - x - z)*bias + z - x)*tension;
	
//	x - w + x b - w b + y - x - y b + x b
//	-w + 2x b - w b + y - y b
//	b(2x - w - y) + y - w			
//	
//	y - x + y b - x b + z - y - z b + y b
//	-x + 2y b - x b + z - z b
//	b(2y - x - z) + z - x

	Tp f2 = f  * f;
	Tp f3 = f2 * f;

	// compute hermite basis functions
	Tp a3 = Tp(-2)*f3 + Tp(3)*f2;
	Tp a0 = Tp(1) - a3;
	Tp a2 = f3 - f2;
	Tp a1 = f3 - Tp(2)*f2 + f;

	return x*a0 + m0*a1 + m1*a2 + y*a3;
}
Пример #2
0
/*!
SLMesh::preShade calculates the rest of the intersection information 
after the final hit point is determined. Should be called just before the 
shading when the final intersection point of the closest triangle was found.
*/
void SLMesh::preShade(SLRay* ray)
{
   SLFace* hit = ray->hitTriangle;
   
   // calculate the hit point in world space
   ray->hitPoint.set(ray->origin + ray->length * ray->dir);
      
   // calculate the interpolated normal with vertex normals in object space
   ray->hitNormal.set(N[hit->iA] * (1-(ray->hitU+ray->hitV)) + 
                      N[hit->iB] * ray->hitU + 
                      N[hit->iC] * ray->hitV);
                      
   // transform normal back to world space
   ray->hitNormal.set(ray->hitShape->wmN() * ray->hitNormal);
                 
   // invert normal if the ray is inside a shape
   if (!ray->isOutside) ray->hitNormal *= -1;
   
   // for shading the normal is expected to be unit length
   ray->hitNormal.normalize();
   
   // calculate interpolated texture coordinates
   SLVGLTexture& textures = ray->hitMat->textures();
   if (textures.size() > 0)
   {  SLVec2f Tu(Tc[hit->iB] - Tc[hit->iA]);
      SLVec2f Tv(Tc[hit->iC] - Tc[hit->iA]);
      SLVec2f tc(Tc[hit->iA] + ray->hitU*Tu + ray->hitV*Tv);
      ray->hitTexCol.set(textures[0]->getTexelf(tc.x,tc.y));
      
      // bumpmapping
      if (textures.size() > 1)
      {  if (T)
         {  
            // calculate the interpolated tangent with vertex tangent in object space
            SLVec4f hitT(T[hit->iA] * (1-(ray->hitU+ray->hitV)) + 
                         T[hit->iB] * ray->hitU + 
                         T[hit->iC] * ray->hitV);
                         
            SLVec3f T3(hitT.x,hitT.y,hitT.z);         // tangent with 3 components
            T3.set(ray->hitShape->wmN() * T3);        // transform tangent back to world space
            SLVec2f d = textures[1]->dsdt(tc.x,tc.y);  // slope of bumpmap at tc
            SLVec3f N = ray->hitNormal;               // unperturbated normal
            SLVec3f B(N^T3);                          // binormal tangent B
            B *= T[hit->iA].w;                        // correct handedness
            SLVec3f D(d.x*T3 + d.y*B);                // perturbation vector D
            N+=D;
            N.normalize();
            ray->hitNormal.set(N);
         }
      }
   }
}
Пример #3
0
OclBM::OclBM(int width,int height,int numofdisps,int win){
	edge_method = HAS_EDGE;
	maxZ = 3.0;

	cv::Mat_<double> cameraMatrix1(3,3);
	cameraMatrix1<< 583.41225,  0.       ,  326.75770,
					0.       ,  589.27674,  209.41198,
					0.       ,  0.       ,  1.;

	cv::Mat_<double> disCoeff1(5,1);
	disCoeff1<<-0.00404,   -0.14885,   -0.00176,   0.00102,  0.00000;

	cv::Mat_<double> cameraMatrix2(3,3);
	cameraMatrix2<< 579.99012,  0.       ,  317.64133,
					0.       ,  585.44507,  219.48944,
					0.       ,  0.       ,  1.;

	cv::Mat_<double> disCoeff2(5,1);
	disCoeff2<<0.00698,   -0.16722,   -0.00279,   0.00162,  0.00000;

	cv::Mat_<double> rm(3,1);
	rm<<0.01857,   0.00525,  -0.03124;

	cv::Mat_<double> Rm(3,3);
	cv::Rodrigues(rm, Rm);
//	Rm<< 9.9949590888302986e-01,  3.0555658693688051e-02,  8.6185757455006194e-03,
//		-3.0365830270320297e-02,  9.9931064739905584e-01, -2.1357582889317616e-02,
//		-9.2652295211821528e-03,  2.1085106513243395e-02,  9.9973475172429860e-01;

	cv::Mat_<double> Tv(3,1);
	Tv<<-80.14897,   1.97999,  -1.23445;

	cv::Mat Rr1,Rr2,Pr1,Pr2;
	cv::Rect roi1,roi2;
	cv::stereoRectify(cameraMatrix1, disCoeff1, cameraMatrix2, disCoeff2, cv::Size(width,height), Rm, Tv, Rr1, Rr2, Pr1, Pr2, Qw);
	LOGI("Rr1: %f, %f, %f, %f, %f, %f, %f, %f, %f", Rr1.at<double>(0,0), Rr1.at<double>(0,1), Rr1.at<double>(0,2),
			Rr1.at<double>(1,0), Rr1.at<double>(1,1), Rr1.at<double>(1,2), Rr1.at<double>(2,0), Rr1.at<double>(2,1), Rr1.at<double>(2,2));
	LOGI("Rr2: %f, %f, %f, %f, %f, %f, %f, %f, %f", Rr2.at<double>(0,0), Rr2.at<double>(0,1), Rr2.at<double>(0,2),
			Rr2.at<double>(1,0), Rr2.at<double>(1,1), Rr2.at<double>(1,2), Rr2.at<double>(2,0), Rr2.at<double>(2,1), Rr2.at<double>(2,2));
	LOGI("Pr1: %f, %f, %f, %f, %f, %f, %f, %f, %f", Pr1.at<double>(0,0), Pr1.at<double>(0,1), Pr1.at<double>(0,2),
			Pr1.at<double>(1,0), Pr1.at<double>(1,1), Pr1.at<double>(1,2), Pr1.at<double>(2,0), Pr1.at<double>(2,1), Pr1.at<double>(2,2));
	LOGI("Pr2: %f, %f, %f, %f, %f, %f, %f, %f, %f", Pr2.at<double>(0,0), Pr2.at<double>(0,1), Pr2.at<double>(0,2),
			Pr2.at<double>(1,0), Pr2.at<double>(1,1), Rr2.at<double>(1,2), Pr2.at<double>(2,0), Pr2.at<double>(2,1), Pr2.at<double>(2,2));
	LOGI("Qw: \n%f, %f, %f, %f,\n%f, %f, %f, %f,\n%f, %f, %f, %f,\n%f, %f, %f, %f",
			Qw.at<double>(0,0), Qw.at<double>(0,1), Qw.at<double>(0,2), Qw.at<double>(0,3),
			Qw.at<double>(1,0), Qw.at<double>(1,1), Qw.at<double>(1,2), Qw.at<double>(1,3),
			Qw.at<double>(2,0), Qw.at<double>(2,1), Qw.at<double>(2,2), Qw.at<double>(2,3),
			Qw.at<double>(3,0), Qw.at<double>(3,1), Qw.at<double>(3,2), Qw.at<double>(3,3));
	LOGI("Center difference: %f", -Qw.at<double>(3,3)/Qw.at<double>(3,2));

	cv::initUndistortRectifyMap(cameraMatrix1, disCoeff1, Rr1, Pr1, cv::Size(width,height), CV_16SC2, mapx1, mapy1);
	cv::initUndistortRectifyMap(cameraMatrix2, disCoeff2, Rr2, Pr2, cv::Size(width,height), CV_16SC2, mapx2, mapy2);

	// create images for processing
	imgWidth=width;
	imgHeight=height;
	dispImg.create(height,2*width,CV_8UC4);
	depthMatrix.create(height,width,CV_32FC3);

	ndisp=numofdisps;
	winSize=win;

/*
	// output gpu device information
	cv::ocl::DevicesInfo devInfo;
	int res=cv::ocl::getOpenCLDevices(devInfo);
	if(res==0){
		LOGE("There is no OpenCL here!");
	}else{
		for(int i=0;i<devInfo.size();++i){
			LOGI("deviceProfile: %s",devInfo[i]->deviceProfile.c_str());
			LOGI("deviceVersion: %s",devInfo[i]->deviceVersion.c_str());
			LOGI("deviceName: %s",devInfo[i]->deviceName.c_str());
			LOGI("deviceVendor: %s",devInfo[i]->deviceVendor.c_str());
			LOGI("deviceDriverVersion: %s",devInfo[i]->deviceDriverVersion.c_str());
			LOGI("deviceExtensions: %s",devInfo[i]->deviceExtensions.c_str());
			LOGI("maxWorkGroupSize: %d",devInfo[i]->maxWorkGroupSize);
			LOGI("maxComputeUnits: %d",devInfo[i]->maxComputeUnits);
			LOGI("localMemorySize: %d",devInfo[i]->localMemorySize);
			LOGI("maxMemAllocSize: %d",devInfo[i]->maxMemAllocSize);
			LOGI("deviceVersionMajor: %d",devInfo[i]->deviceVersionMajor);
			LOGI("deviceVersionMinor: %d",devInfo[i]->deviceVersionMinor);
		}
	}
*/

#ifdef DUMP_DEPTH
	dumpCount = 0;
#endif
}