コード例 #1
0
ファイル: demo.cpp プロジェクト: icharlie/glui-cs553
void
Arrow( float tail[3], float head[3] )
{
	float u[3], v[3], w[3];		// arrow coordinate system

	// set w direction in u-v-w coordinate system:

	w[0] = head[0] - tail[0];
	w[1] = head[1] - tail[1];
	w[2] = head[2] - tail[2];


	// determine major direction:

	int axis = X;
	float mag = fabs( w[0] );
	if(  fabs( w[1] )  > mag  )
	{
		axis = Y;
		mag = fabs( w[1] );
	}
	if(  fabs( w[2] )  > mag  )
	{
		axis = Z;
		mag = fabs( w[2] );
	}


	// set size of wings and turn w into a Unit vector:

	float d = WINGS * Unit( w, w );


	// draw the shaft of the arrow:

	glBegin( GL_LINE_STRIP );
		glVertex3fv( tail );
		glVertex3fv( head );
	glEnd( );

	// draw two sets of wings in the non-major directions:

	float x, y, z;

	if( axis != X )
	{
		Cross( w, axx, v );
		(void) Unit( v, v );
		Cross( v, w, u  );
		x = head[0] + d * ( u[0] - w[0] );
		y = head[1] + d * ( u[1] - w[1] );
		z = head[2] + d * ( u[2] - w[2] );
		glBegin( GL_LINE_STRIP );
			glVertex3fv( head );
			glVertex3f( x, y, z );
		glEnd( );
		x = head[0] + d * ( -u[0] - w[0] );
		y = head[1] + d * ( -u[1] - w[1] );
		z = head[2] + d * ( -u[2] - w[2] );
		glBegin( GL_LINE_STRIP );
			glVertex3fv( head );
			glVertex3f( x, y, z );
		glEnd( );
	}


	if( axis != Y )
	{
		Cross( w, ayy, v );
		(void) Unit( v, v );
		Cross( v, w, u  );
		x = head[0] + d * ( u[0] - w[0] );
		y = head[1] + d * ( u[1] - w[1] );
		z = head[2] + d * ( u[2] - w[2] );
		glBegin( GL_LINE_STRIP );
			glVertex3fv( head );
			glVertex3f( x, y, z );
		glEnd( );
		x = head[0] + d * ( -u[0] - w[0] );
		y = head[1] + d * ( -u[1] - w[1] );
		z = head[2] + d * ( -u[2] - w[2] );
		glBegin( GL_LINE_STRIP );
			glVertex3fv( head );
			glVertex3f( x, y, z );
		glEnd( );
	}



	if( axis != Z )
	{
		Cross( w, azz, v );
		(void) Unit( v, v );
		Cross( v, w, u  );
		x = head[0] + d * ( u[0] - w[0] );
		y = head[1] + d * ( u[1] - w[1] );
		z = head[2] + d * ( u[2] - w[2] );
		glBegin( GL_LINE_STRIP );
			glVertex3fv( head );
			glVertex3f( x, y, z );
		glEnd( );
		x = head[0] + d * ( -u[0] - w[0] );
		y = head[1] + d * ( -u[1] - w[1] );
		z = head[2] + d * ( -u[2] - w[2] );
		glBegin( GL_LINE_STRIP );
			glVertex3fv( head );
			glVertex3f( x, y, z );
		glEnd( );
	}
}
コード例 #2
0
 static const boost::units::quantity< Unit, Numeric > construct(T&& n) { return boost::units::quantity< Unit, Numeric >(boost::numeric_cast<Numeric>(geometrix::get(std::forward<T>(n))) * Unit()); }
コード例 #3
0
Color basic_shader::Shade( const Scene &scene, const HitInfo &hit ) const
    {
    Ray ray;
	Ray reflectionRay;
	Ray refractedRay;
	Ray secondaryRefractedRay;

    HitInfo otherhit;
	HitInfo refractionHit;
    static const double epsilon = 1.0E-6;
    if( Emitter( hit.object ) ) return hit.object->material->emission;

    Material *mat   = hit.object->material;
    Color  diffuse  = mat->diffuse;
    Color  specular = mat->specular;
    Color  color    = mat->ambient * diffuse;
    Vec3   O = hit.ray.origin;
    Vec3   P = hit.point;
    Vec3   N = hit.normal;
    Vec3   E = Unit( O - P );
    Vec3   R = Unit( ( 2.0 * ( E * N ) ) * N - E );
    Color  r = mat->reflectivity;
    double e = mat->Phong_exp;
    double k = mat->ref_index;
	Color t = mat->translucency;

	if(hit.object->Inside(P)){
		P = P + epsilon*N;
	}

    if( E * N < 0.0 ) N = -N;  // Flip the normal if necessary.

	//get the attentuation
	
	double attenuation;
	double lightDistance;
	Vec3 lightVector;
	double diffuseFactor;
	double specularFactor;
	Color diffuseColor = Color();
	Color specularColor = Color();
	Color finalColor;
	Color colorWithLighting;
	Color reflectedColor;
	Color refractedColor;
	Vec3 currentR;
	double shadowFactor = 0;
	bool objectWasHit = false;

	int numGridVals = 30;
	float numSamples = 5;
	int totalNumGridVals = numGridVals*numGridVals*numSamples;
	int totalArrayValues = totalNumGridVals*2;
	float totalGridVals = numGridVals;
	float currentXvalue;
	float currentYvalue;
	float interval = 2.0f/totalGridVals;
	float currentDist;
	bool posZinHemisphere,negZinHemisphere;
	int currentInd1,currentInd2;
	float randomX,randomY;
	float currentPosZvalue,currentNegZvalue;
	//Vec3 currentNormal = Vec3(0.0f,0.0f,1.0f);
	Vec3 currentNormal = N;
	float dotProdPosZ,dotProdNegZ,dotProdXYpart;
	Vec3 positiveZvector;
	Vec3 negativeZvector;
	int numLightsHit = 0;
	
	/*
	Surface Area of sphere from each patch P is approximately area(P)*(1/z') where z' is taken at the center
	This comes from the fact that the surface area is integral_P (1/z)
	*/
	float minZvalue=sqrt(interval)*sqrt(2-interval);;
	
	//used to calculate surface area
	float centerXvalue,centerYvalue,centerZvalue,approxSurfaceArea;

	//temp variable. default emission of the light blocks
	Color defaultEmission = Color(1.0,1.0,1.0);
	double emissionFactor = 30.0;

	Color posZpatchValue = Color();
	Color negZpatchValue = Color();
	Color posZpatchSpecValue = Color();
	Color negZpatchSpecValue = Color();
	double radius,patchFormFactor;
	Vec3 otherNormal;
	float currentEnergy = 0;

	for(int xInd = 0; xInd < numGridVals; xInd++){
		for(int yInd = 0; yInd < numGridVals; yInd++){

			centerXvalue = -1 + interval*xInd + interval*0.5;
			centerYvalue = -1 + interval*yInd + interval*0.5;
			currentDist = centerXvalue*centerXvalue + centerYvalue*centerYvalue;
			centerZvalue = sqrt(1-currentDist);

			
			if(centerZvalue < minZvalue){
				centerZvalue = minZvalue;
			}

			approxSurfaceArea = interval*interval*(1.0f/centerZvalue);	
			

			posZpatchValue = Color();
			negZpatchValue = Color();

			for(int sampleInd = 0; sampleInd < numSamples; sampleInd++){

				randomX = (double)rand() / RAND_MAX;
				randomY = (double)rand() / RAND_MAX;

				currentXvalue = -1+interval*xInd + interval*randomX;
				currentYvalue = -1+interval*yInd + interval*randomY;
				
				currentDist = currentXvalue*currentXvalue + currentYvalue*currentYvalue;

				posZinHemisphere = false;
				negZinHemisphere = false;

				currentInd1 = (xInd*numGridVals + yInd)*numSamples + sampleInd;
				currentInd2 = currentInd1 + totalNumGridVals;

				//makes sure it is inside the unit disk
				if(currentDist <= 1){

					currentPosZvalue = sqrt(1-currentDist);
					currentNegZvalue = -currentPosZvalue;

					dotProdXYpart = currentNormal.x*currentXvalue + currentNormal.y*currentYvalue;
					dotProdPosZ = currentNormal.z*currentPosZvalue + dotProdXYpart;
					dotProdNegZ = currentNormal.z*currentNegZvalue + dotProdXYpart;

					posZinHemisphere = (dotProdPosZ >=0);
					negZinHemisphere = (dotProdNegZ >=0);

				}


				if(posZinHemisphere){

					positiveZvector = Vec3(currentXvalue,currentYvalue,currentPosZvalue);

					//light ray to case to determine occulsion
					ray.origin = P;
					ray.direction = positiveZvector;
					HitInfo objectHit;
					objectHit.distance = Infinity;

					shadowFactor = 1;
					if(scene.Cast(ray,objectHit) ){
						if(objectHit.object != NULL){
							Vec3 LightPos = objectHit.point;
							
							if(LightPos.z > 12.0){
								lightVector = LightPos - P;
								numLightsHit = numLightsHit + 1;
								radius = Length(lightVector);
								otherNormal = Unit(objectHit.normal);
								lightVector = Unit(lightVector);

								//this is the current patches approximation of F_ij
								//patchFormFactor = ((abs(lightVector*currentNormal))*(abs(-1*lightVector*otherNormal)))/(Pi*radius*radius);
								patchFormFactor = ((lightVector*currentNormal)*(-1*lightVector*otherNormal))/(Pi*radius*radius);
								patchFormFactor = max(0,patchFormFactor);
								//printf("radius: %f\n",radius);
								currentEnergy = currentEnergy + emissionFactor*patchFormFactor;
								diffuseColor = diffuseColor + GetDiffuseColor(lightVector,N,defaultEmission,diffuse);
							}
						}
					}

				}

				if(negZinHemisphere){
					negativeZvector = Vec3(currentXvalue,currentYvalue,currentNegZvalue);
					//printf("(x,y,z)=(%f,%f,%f)\n",gridXvalues[currentInd2],gridYvalues[currentInd2],gridZvalues[currentInd2]);

					//light ray to case to determine occulsion
					ray.origin = P;
					ray.direction = negativeZvector;
					HitInfo objectHit;
					objectHit.distance = Infinity;

					shadowFactor = 1;
					if(scene.Cast(ray,objectHit) ){
						if(objectHit.object != NULL){
							Vec3 LightPos = objectHit.point;
							
							if(LightPos.z > 12.0){
								lightVector = LightPos - P;
								numLightsHit = numLightsHit + 1;
								radius = Length(lightVector);
								
								otherNormal = Unit(objectHit.normal);
								lightVector = Unit(lightVector);

								//this is the current patches approximation of F_ij
								//patchFormFactor = ((abs(lightVector*currentNormal))*(abs(-1*lightVector*otherNormal)))/(Pi*radius*radius);
								patchFormFactor = ((lightVector*currentNormal)*(-1*lightVector*otherNormal))/(Pi*radius*radius);
								patchFormFactor = max(0,patchFormFactor);
								currentEnergy = currentEnergy + emissionFactor*patchFormFactor;
								diffuseColor = diffuseColor + GetDiffuseColor(lightVector,N,defaultEmission,diffuse);
								//negZpatchValue = negZpatchValue + GetDiffuseColor(lightVector,N,defaultEmission,diffuse);
							}
						}
					}
				}

			}

			//diffuseColor = diffuseColor + (posZpatchValue/numSamples)*approxSurfaceArea;
			//diffuseColor = diffuseColor + (negZpatchValue/numSamples)*approxSurfaceArea;
			//printf("Approx Surface Area:%f\n",approxSurfaceArea);

			//diffuseColor = diffuseColor + posZpatchValue;
			//diffuseColor = diffuseColor + negZpatchValue;

			if(diffuseColor.blue > 0.5 || diffuseColor.green > 0.5 || diffuseColor.red > 0.5){
				//printf("Current Diffuse Color: (%f,%f,%f)\n",diffuseColor.blue,diffuseColor.green,diffuseColor.red);
			}
			
			
		}
	}
	
	//makes sure to include the light vectors in the calculations
	for( unsigned i = 0; i < scene.NumLights(); i++ )
        {
        const Object *light = scene.GetLight(i);
        Color emission = light->material->emission;
        AABB box = GetBox( *light );
        Vec3 LightPos( Center( box ) ); 

		//gets the light Vector
		lightVector = LightPos - P;
		lightDistance = Length(lightVector);
		Vec3 unitLightVector = Unit(lightVector);
		
		//gets the attenuation factor
		attenuation = 1/(attenuation_a + attenuation_b*lightDistance + attenuation_c*lightDistance*lightDistance);

		float dotProd = currentNormal.x*unitLightVector.x + currentNormal.y*unitLightVector.y + currentNormal.z*unitLightVector.z;

		//light vector in unit hemipshere
		if(dotProd >= 0){

			//light ray to case to determine occulsion
			ray.origin = P;
			ray.direction = unitLightVector;
			HitInfo objectHit;
			objectHit.distance = Infinity;

			if(scene.Cast(ray,objectHit) ){
				if(objectHit.object != NULL){
					Vec3 LightPos = objectHit.point;
							
					if(LightPos.z > 12.0){
						numLightsHit = numLightsHit + 1;
						lightVector = LightPos - P;
						//diffuseColor = diffuseColor + GetDiffuseColor(lightVector,N,defaultEmission,diffuse);

						radius = Length(lightVector);
								
						otherNormal = Unit(objectHit.normal);
						lightVector = Unit(lightVector);

						//this is the current patches approximation of F_ij
						//patchFormFactor = ((abs(lightVector*currentNormal))*(abs(-1*lightVector*otherNormal)))/(Pi*radius*radius);
						patchFormFactor = ((lightVector*currentNormal)*(-1*lightVector*otherNormal))/(Pi*radius*radius);
						patchFormFactor = max(0,patchFormFactor);
						currentEnergy = currentEnergy + emissionFactor*patchFormFactor;
						diffuseColor = diffuseColor + GetDiffuseColor(lightVector,N,defaultEmission,diffuse);
					}
				}
			}

		}

		

		
    }

	diffuseColor = currentEnergy*defaultEmission;

	//diffuseColor = diffuseColor/12.0;

	float numLights = numLightsHit;
	//diffuseColor = diffuseColor/(numLights*Pi);
	if(numLightsHit > 1){
		//printf("Number of Lights Hit:%d\n",numLightsHit);
		//printf("Original Color: (%f,%f,%f)\n",diffuse.blue,diffuse.green,diffuse.red);
		//printf("Diffuse Color: (%f,%f,%f)\n\n",diffuseColor.blue,diffuseColor.green,diffuseColor.red);

	}

	//colorWithLighting = color + diffuseColor*diffuse + specularColor*specular;
	//colorWithLighting = diffuseColor*diffuse;
	colorWithLighting = diffuseColor*diffuse + diffuse*0.4;

	//set variables for reflection
	reflectionRay.origin = P;
	reflectionRay.direction = R;
	reflectionRay.generation = hit.ray.generation + 1;
	reflectedColor = Color();

	//set variables for refraction

	refractedRay.origin = P-epsilon*N;

	Vec3 refractionDir = RefractionDirection(1.0,k,E,N);
	refractedRay.direction = refractionDir; //for refraction
	refractedRay.generation = hit.ray.generation + 1;
	refractedColor = Color();
 	refractionHit.distance = Infinity;

	//only do refraction if the transluency is greater than zero
	//	this is an optimization so unnecessary refractions are not calculated
	if( (t.red + t.green + t.blue) > epsilon){
		if(scene.Cast(refractedRay,refractionHit)){

			bool insideMaterial = false;
			Vec3 currentNormal;
			Vec3 previousRefractedDirection;

			do{
				currentNormal = Unit(refractionHit.normal);
				previousRefractedDirection = refractedRay.direction;
				refractedRay.direction = RefractionDirection(k,1.0,-1*refractedRay.direction,-1*currentNormal);

				if(Length(refractedRay.direction) < epsilon){
					insideMaterial = true;
					refractionHit.distance = Infinity;
					refractedRay.origin = refractionHit.point - epsilon*currentNormal;
					refractedRay.direction = Unit( ( 2.0 * ( previousRefractedDirection * currentNormal ) ) * (-1*currentNormal) + previousRefractedDirection );


					if(!scene.Cast(refractedRay,refractionHit)){
						insideMaterial = false;
					}
				}else{

					refractedRay.origin = refractionHit.point + epsilon*currentNormal;
					insideMaterial = false;

				}

				

			}while(insideMaterial);

			refractedRay.generation = hit.ray.generation + 1;

			//now do refraction
			refractedColor = scene.Trace(refractedRay);

		}
	}


	//do the reflection
	//only do reflection if the reflectance is greater than zero
	//	this is an optimization so unnecessary reflections are not calculated
	if( (r.red + r.green + r.blue) > epsilon){
		reflectedColor = scene.Trace(reflectionRay);
	}
	
	//printf("diffuseColor: (%f,%f,%f)\n",colorWithLighting.red,colorWithLighting.green,colorWithLighting.blue);

	//now combine calculated color with reflected color
	//finalColor = (-1*t + Color(1.0,1.0,1.0))*(colorWithLighting + r*reflectedColor) + t*refractedColor;

	return colorWithLighting;
	//return finalColor; 
    }
コード例 #4
0
ファイル: Raytracer.cpp プロジェクト: mashirito/gfx
// Shade assigns a color to a point on a surface, as it is seen
// from another point.  The coordinates of these points, the normal
// of the surface, and the surface material are all recorded in the
// HitInfo structure.  The shader will typically make calls to Trace
// to handle shadows and reflections.
Color Raytracer::Shade(const HitInfo &hit, const Scene &scene, int max_tree_depth)
{
	Color color = { 0.0f, 0.0f, 0.0f };
	Vec3 point = hit.geom.point + hit.geom.normal*Epsilon;
	HitInfo hitObstacle = hit;
	Ray ray, ray2;
	Color diffuse = Color(0,0,0), specular = Color(0,0,0);
	Color direct = Color(0,0,0), indirect = Color(0,0,0);
	Sample lightPoint;

	Vec3 V;
	Color irradiant = Color(0,0,0);
	int espec = 0;
	Color indirect_hemisphere = Color(0, 0, 0), indirect_lobe = Color(0, 0, 0);

	//if (max_tree_depth >= 0) {

		if (hit.material.Emitter()) {
			return hit.material.m_Diffuse;
		}else{
			for (Object *object = scene.first; object != NULL; object = object->next)
			{

				if (object->material.Emitter() == true)
				{
					lightPoint = object->GetSample(hit.geom.point, hit.geom.normal);
					ray.origin = hit.geom.point;

					//lightPoint.P = lightPoint.P + hit.geom.normal*Epsilon;
					ray.direction = Unit(lightPoint.P - hit.geom.point);
					hitObstacle.geom.distance = Length(lightPoint.P - point);

					V = Unit(hit.geom.origin - hit.geom.point);
						Vec3 N = (hit.geom.normal);
						Vec3 H = Unit(V + ray.direction);
						//V = Unit(hit.geom.origin - hit.geom.point);
						Vec3 L = (-ray.direction);// Unit(point - lightPoint.P);
						Vec3 R = Unit(Reflection(-L, N));//Unit((2*N*(N*L))-L);

					espec = hit.material.m_Phong_exp;

					double c = (L*H);
					double g = sqrt((pow(1.4 / 1, 2.0))+ pow(c,2)-1);
					Color f0 = hit.material.m_Specular;


					double F = (f0.red + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.green + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.blue+(1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)));
					//double F = (1 / 2)*((pow(g - c, 2))/(pow(g + c, 2)))*(1+pow((c*(g+c)-1),2)/ (1 + pow((c*(g - c) + 1), 2)));
					double D = ((espec + 2) / (2 * Pi))*(pow((H*N), espec));
					//double D = 1/(sqrt(2*Pi))
					double G = min(min(1.0, (2 * (N*H)*(N*V)) / (V*H)), (2 * (N*H)*(N*L)) / (L*H));
					if (G < 0) G = 0;
					if (D < 0) D = 0;
					if (F < 0) F = 0;

					if (!Cast(ray, scene, hitObstacle)) {
						

						if (N * L > 0) {
							diffuse = (N*L)*hit.material.m_Diffuse/Pi;
						}
						else {
							diffuse = Color(0.0, 0.0, 0.0);
						}

						irradiant = object->material.m_Emission*(lightPoint.w);
						
						if ((R*V) > 0 && hit.material.m_Phong_exp > 0) {
							specular = /*(espec + 2)/(2*Pi) * pow((R*V), espec)*/(F*D*G / (4 * (N*L)*(N*V)))*hit.material.m_Specular;
						}
						else {
							specular = Color(0.0, 0.0, 0.0);
						}
						direct += (diffuse + specular)*irradiant;
					}
				}
			}
			if (hit.material.m_Phong_exp > 0) {
				Vec3 N = (hit.geom.normal);
				Vec3 L = Unit(-ray.direction);
				V = -Unit(hit.geom.point - hit.geom.origin);
				Vec3 R = Unit(Reflection(-V, N));
				Vec3 H = Unit(V + ray.direction);
				double c = (L*H);
				double g = sqrt((pow(1.4 / 1, 2.0)) + pow(c, 2) - 1);
				Color f0 = hit.material.m_Specular;

				double F = (f0.red + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.green + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.blue + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)));
				//double F = (1 / 2)*((pow(g - c, 2))/(pow(g + c, 2)))*(1+pow((c*(g+c)-1),2)/ (1 + pow((c*(g - c) + 1), 2)));
				double D = ((espec + 2) / (2 * Pi))*(pow((H*N), espec));
				double G = min(min(1.0, (2 * (N*H)*(N*V)) / (V*H)), (2 * (N*H)*(N*L)) / (L*H));
				if (G < 0) G = 0;
				if (D < 0) D = 0;
				if (F < 0) F = 0;


				float phong_exp = hit.material.m_Phong_exp;
				ray2.origin = point;

				Sample sample_hemisphere = SampleProjectedHemisphere(N);
				ray2.direction = Unit(sample_hemisphere.P);
				//ray2.no_emitters = true;
				indirect_hemisphere = Trace(ray2, scene, max_tree_depth-1)*  hit.material.m_Diffuse;

				Sample specular_sample = SampleSpecularLobe(R, phong_exp);
				ray2.direction = Unit(specular_sample.P);
				indirect_lobe = Trace(ray2, scene, max_tree_depth - 1)*F*D*G / (4 * (N*L)*(N*V));// *hit.material.m_Specular;

				indirect = indirect_hemisphere + indirect_lobe;// *(F*D*G / (4 * (N*L)*(N*V)));
			}
			
			return (direct) + indirect;
		}
	//}
}
コード例 #5
0
void IngredientMatcherDialog::addIngredient()
{
	QList<Q3ListViewItem *> items = allIngListView->listView()->selectedItems();
	if ( !items.isEmpty() ) {
		for (int i = 0; i < items.size(); ++i) {
			bool dup = false;
			for ( Q3ListViewItem *exists_it = ingListView->listView()->firstChild(); exists_it; exists_it = exists_it->nextSibling() ) {
				if ( exists_it->text( 0 ) == items[i]->text( 0 ) ) {
					dup = true;
					break;
				}
			}

			if ( !dup ) {
				Q3ListViewItem * new_item = new Q3CheckListItem( ingListView->listView(), items[i]->text( 0 ), Q3CheckListItem::CheckBox );

				ingListView->listView() ->setSelected( new_item, true );
				ingListView->listView() ->ensureItemVisible( new_item );
				allIngListView->listView() ->setSelected( items[i], false );

				IngredientList::iterator it = m_ingredientList.append( Ingredient( items[i]->text( 0 ), 0, Unit(), -1, items[i]->text( 1 ).toInt() ) );
				m_item_ing_map.insert( new_item, it );
			}
		}
	}
}
コード例 #6
0
boost::optional<Unit> ScheduleTypeLimits::units(std::string unitType, bool returnIP) {
  boost::to_lower(unitType);
  OptionalUnit result;

  if (unitType.empty() ||
      (unitType == "dimensionless") ||
      (unitType == "availability") ||
      (unitType == "controlmode"))
  {
    if (returnIP) {
      result = IPUnit();
    }
    else {
      result = SIUnit();
    }
    return result;
  }

  char firstLetter = unitType[0];
  switch (firstLetter) {
  case 'a' :
    {
      if (unitType == "activitylevel") {
        result = (createSIPower() / createSIPeople());
      }
      else if (unitType == "angle") {
        result = createIPAngle();
      }
      break;
    }
  case 'c' :
    {
      if (unitType == "capacity") {
        if (returnIP) {
          result = BTUUnit(BTUExpnt(1,0,-1));
        }
        else {
          result = createSIPower();
        }
      }
      else if (unitType == "clothinginsulation") {
        result = Unit();
        result->setBaseUnitExponent("clo",1);
      }
      else if (unitType == "convectioncoefficient") {
        if (returnIP) {
          result = BTUUnit(BTUExpnt(1,-2,-1,-1));
        }
        else {
          result = createSIThermalConductance();
        }
      }
      break;
    }
  case 'd' :
    {
      if (unitType == "deltatemperature") {
        if (returnIP) {
          result = createFahrenheitTemperature();
          result->cast<TemperatureUnit>().setAsRelative();
        }
        else {
          result = createCelsiusTemperature();
          result->cast<TemperatureUnit>().setAsRelative();
        }
      }
      break;
    }
  case 'l' :
    {
      if (unitType == "linearpowerdensity") {
        if (returnIP) {
          result = (createIPPower() / createIPLength());
        }
        else {
          result = (createSIPower() / createSILength());
        }
      }
      break;
    }
  case 'm' :
    {
      if (unitType == "massflowrate") {
        if (returnIP) {
          result = IPUnit(IPExpnt(1,0,-1));
        }
        else {
          result = SIUnit(SIExpnt(1,0,-1));
        }
      }
      break;
    }
  case 'p' :
    {
      if (unitType == "percent") {
        result = Unit();
        result->setBaseUnitExponent("%",1);
      }
      else if (unitType == "power") {
        result = createSIPower();
      }
      else if (unitType == "precipitationrate") {
        if (returnIP) {
          result = BTUUnit(BTUExpnt(0,1,-1));
        }
        else {
          result = WhUnit(WhExpnt(0,-1,1));
        }
      }
      else if (unitType == "pressure") {
        if (returnIP) {
          result = createIPPressure();
        }
        else {
          result = createSIPressure();
        }
      }
      break;
    }
  case 'r' :
    {
      if (unitType == "rotationsperminute") {
        result = createCFMFrequency();
      }
      break;
    }
  case 's' :
    {
      if (unitType == "solarenergy") {
        result = WhUnit(WhExpnt(1,1,-2));
      }
      break;
    }
  case 't' :
    {
      if (unitType == "temperature") {
        if (returnIP) {
          result = createFahrenheitTemperature();
        }
        else {
          result = createCelsiusTemperature();
        }
      }
      break;
    }
  case 'v' :
    {
      if (unitType == "velocity") {
        if (returnIP) {
          result = CFMUnit(CFMExpnt(1,-1));
        }
        else {
          result = SIUnit(SIExpnt(0,1,-1));
        }
      }
      if (unitType == "volumetricflowrate") {
        if (returnIP) {
          result = IPUnit(IPExpnt(0,3,-1));
        }
        else {
          result = SIUnit(SIExpnt(0,3,-1));
        }
      }
      break;
    }
  }

  return result;
}
コード例 #7
0
ファイル: fp3.cpp プロジェクト: AbdelghaniDr/mirror
Pointf3 Orthonormal(Pointf3 v, Pointf3 against)
{
	return Unit(Orthogonal(v, against));
}
コード例 #8
0
ファイル: Bush.cpp プロジェクト: Crazyrobot6/PlantGame
Bush::Bush()
{
	Unit();
	classID = BUSH;
}
コード例 #9
0
DRTTransferSession::~DRTTransferSession()
{
    DelObserver(this);
    Unit();
}
コード例 #10
0
CValidatedUnit CEvaluationNodeFunction::getUnit(const CMathContainer & /* container */,
        const std::vector< CValidatedUnit > & units) const
{
    CValidatedUnit Unit(CBaseUnit::dimensionless, false);

    switch ((SubType)this->subType())
    {
    case S_LOG:
    case S_LOG10:
    case S_EXP:
    case S_SIN:
    case S_COS:
    case S_TAN:
    case S_SEC:
    case S_CSC:
    case S_COT:
    case S_SINH:
    case S_COSH:
    case S_TANH:
    case S_SECH:
    case S_CSCH:
    case S_COTH:
    case S_ARCSIN:
    case S_ARCCOS:
    case S_ARCTAN:
    case S_ARCSEC:
    case S_ARCCSC:
    case S_ARCCOT:
    case S_ARCSINH:
    case S_ARCCOSH:
    case S_ARCTANH:
    case S_ARCSECH:
    case S_ARCCSCH:
    case S_ARCCOTH:
    case S_FACTORIAL:
    case S_NOT:
        Unit = CValidatedUnit::merge(Unit, units[0]);
        break;

    case S_MAX:
    case S_MIN:
    case S_RUNIFORM:
    case S_RNORMAL:
        Unit = CValidatedUnit::merge(units[0], units[1]);
        break;

    case S_MINUS:
    case S_PLUS:
    case S_FLOOR:
    case S_CEIL:
    case S_ABS:
    case S_RPOISSON:
        Unit = units[0];

        break;

    case S_RGAMMA:
        // The unit of the gamma distribution is the inverse of the scale parameter (units[1])
        Unit = units[1].exponentiate(-1);

        // The shape parameter must be dimensionless
        if (!Unit.conflict())
        {
            Unit.setConflict(!(units[0] == CUnit(CBaseUnit::dimensionless)));
        }

        break;

    case S_SQRT:
    {
        // Exponentiate to 1/2.
        // Test if each component's exponent
        // is an integer. (don't want fractional exponents) by . . .
        // modf(exp, NULL) =< std::numeric_limits::epsilon
        Unit = units[0].exponentiate(1.0 / 2.0);

        std::set< CUnitComponent >::const_iterator  it = Unit.getComponents().begin();
        std::set< CUnitComponent >::const_iterator end = Unit.getComponents().end();

        for (; it != end; it++)
        {
            if (!(remainder((*it).getExponent(), 1.0) <= 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon()))
            {
                Unit = CValidatedUnit(CBaseUnit::undefined, true);

                break;
            }
        }

        break;
    }

    default:
        Unit.setConflict(true);
        break;
    }

    return Unit;
}