Esempio n. 1
0
cube* cubeDialog::callDialog(modeler *md)
{
	
		//cubeDialog = new QDialog;
	QString nm;
	QTextStream(&nm) << "cube" << md->numCube();
	this->setObjectName("Cube Dialog");
	LName = new QLabel("Name");
	LStartPoint = new QLabel("Start point");
	LEndPoint = new QLabel("End point");
	
	LEName = new QLineEdit;
	LEName->setText(nm);
	LEStartPoint = new QLineEdit;
	LEEndPoint = new QLineEdit;
	
	cubeLayout = new QGridLayout;
	
	PBOk = new QPushButton("OK");
	PBCancel = new QPushButton("Cancel");
	connect(PBOk, SIGNAL(clicked()), this, SLOT(Click_ok()));
	connect(PBCancel, SIGNAL(clicked()), this, SLOT(Click_cancel()));
	cubeLayout->addWidget(LMaterial, 0, 0);
	cubeLayout->addWidget(CBMaterial, 0, 1, 1, 2);
	cubeLayout->addWidget(LName, 1, 0);
	cubeLayout->addWidget(LEName, 1, 1, 1, 2);
	cubeLayout->addWidget(LStartPoint, 2, 0);
	cubeLayout->addWidget(LEStartPoint, 2, 1, 1, 2);
	cubeLayout->addWidget(LEndPoint, 3, 0);
	cubeLayout->addWidget(LEEndPoint, 3, 1, 1, 2);
	cubeLayout->addWidget(PBOk, 4, 0);
	cubeLayout->addWidget(PBCancel, 4, 1);
	this->setLayout(cubeLayout);
	
	this->exec();
	cube *c = NULL;
	if (isDialogOk)
	{
		c = md->makeCube(this->objectName(), tMaterial(CBMaterial->currentIndex()), ROLL_BOUNDARY);
		QStringList chList = LEStartPoint->text().split(" ");
		float minPoint[3] = { chList.at(0).toFloat(), chList.at(1).toFloat(), chList.at(2).toFloat() };
		chList = LEEndPoint->text().split(" ");
		float maxPoint[3] = { chList.at(0).toFloat(), chList.at(1).toFloat(), chList.at(2).toFloat() };
		c->define(VEC3F(minPoint), VEC3F(maxPoint));
	}

	return c;
}
Esempio n. 2
0
VEC3F rayColor(VEC3F* ray) {	
	VEC3F colorRGB;
	VEC3F c(0, 0, 1); // sphere center 
	VEC3F n; 		  // normal vector
	
	VEC3F cr(1.0f, 1.0f, 1.0f); // surface color 
	VEC3F cl(1.0f, 1.0f, 1.0f); // light color
	VEC3F light(1, 1, -1); 		// light location
	VEC3F l;					// light direction
	
	if(!intersectScene(ray[0])) {
		//return black
		colorRGB = VEC3F(0.f, 0.f, 0.f);
	} else {		
		// return color								
		n = ray[0]-c;	   // calculate normal vector, p - c
		l = light-ray[0];  // calculate l vector, light - p
		
		// normalize n and l
		n.normalize();	
		l.normalize();				
		
		VEC3F crcl(cr[0]*cl[0], cr[1]*cl[1], cr[2]*cl[2]);		
		float nlDotProd = n*l; 		
		colorRGB = crcl*(nlDotProd);					
	}
		
	return colorRGB; // return vector with rgb values
}
Esempio n. 3
0
void plane::updateMotion(float dt, tSolveDevice tsd)
{
	if (tsd == CPU){
		xw += dt * VEC3F(0.0f, 0.0f, 0.0f);	//plane motion setting, m/s, CPU code
		w2 += dt * VEC3F(0.0f, 0.0f, 0.0f);
		w3 += dt * VEC3F(0.0f, 0.0f, 0.0f);
		w4 += dt * VEC3F(0.0f, 0.0f, 0.0f);
	}
	else if(tsd == GPU){
		device_plane_info *h_dpi = new device_plane_info;
		checkCudaErrors(cudaMemcpy(h_dpi, dpi, sizeof(device_plane_info), cudaMemcpyDeviceToHost));
		// plane motion setting, m/s, GPU code, mde파일에서 plane 설정값중 마지막값 '1'로 바꾸기
		h_dpi->xw = make_float3(h_dpi->xw.x + dt * 0.0f, h_dpi->xw.y + dt *  0.2f, h_dpi->xw.z + dt *  0.0f);
		h_dpi->w2 = make_float3(h_dpi->w2.x + dt * 0.0f, h_dpi->w2.y + dt *  0.2f, h_dpi->w2.z + dt *  0.0f);
		h_dpi->w3 = make_float3(h_dpi->w3.x + dt * 0.0f, h_dpi->w3.y + dt *  0.2f, h_dpi->w3.z + dt *  0.0f);
		h_dpi->w4 = make_float3(h_dpi->w4.x + dt * 0.0f, h_dpi->w4.y + dt *  0.2f, h_dpi->w4.z + dt *  0.0f);
		checkCudaErrors(cudaMemcpy(dpi, h_dpi, sizeof(device_plane_info), cudaMemcpyHostToDevice));
		delete h_dpi;
	}
	
}
Esempio n. 4
0
// Ray Generation
VEC3F* generateRay(int i, int j, float left, float right, float bottom, float top, int nx, int ny, int eVar) {
	VEC3F dPersp;  		// d vector aka -w
	VEC3F oOrtho; 		// orthographic vector (image plane coords)	
	VEC3F e(0, 0, -1);
	double u, v, w, t;	
	
	// SPHERE
	VEC3F c(0, 0, 1); 	// sphere center
	float R = 0.25f;	// radius sphere		
	
	int mode = 1; // mode=0 (orthographic w/ flat image plane), 
				  // mode=1 (perspective w/ odd pixel "checker board" image plane)
	
	// calculate image plane coordinates for orthographic generation
	u = left + ((right-left)*(i + 0.5) / nx);   // image plane coordinate u
	v = bottom + ((top-bottom)*(j + 0.5) / ny); // image plane coordinate v					 			

	//     if(eVar*0.005 < 0.45) {
	// 	e[0] -= eVar*0.005; // change x coord to move left
	// } else {
	// 	e[0] += eVar*0.005; // change x coord to move right
	// }

//	std::cout << eVar*0.005 << std::endl;
//	e[2] += eVar*0.001; // change z coord eye location (if movie being made)

	 // change mode to set image plane coordinate w	
	// if(mode == 0) {	
	// 	w = 0.0; 
	// } else {
	// 	if(i%2 == 0 && j%2 == 0) {
	// 		w = -0.5;
	// 	} else {
	// 		w = 0.0;						 				
	// 	}		
	// }
	
	oOrtho = VEC3F(u, v, w); // ray origin
	dPersp = oOrtho - e; 	 // calculate dPerspective
		
	// calculate t
	t = calcT(e, dPersp, c, R);
			
	// return ray					
	return new VEC3F(e + t*dPersp);
}
Esempio n. 5
0
MATRIX3 diag(const VEC3F& v)
{
  return MATRIX3(VEC3F(v[0],0,0),  VEC3F(0,v[1],0),  VEC3F(0,0,v[2]));
}
Esempio n. 6
0
MATRIX3 MATRIX3::I() { return MATRIX3(VEC3F(1,0,0), VEC3F(0,1,0), VEC3F(0,0,1)); }
Esempio n. 7
0
MATRIX3 MATRIX3::crossProductMatrix( const VEC3F &w )
{
	return MATRIX3( VEC3F( 0.0, -w[2], w[1] ),
									VEC3F( w[2], 0.0, -w[0] ),
									VEC3F( -w[1], w[0], 0.0 ) );
}
Esempio n. 8
0
FLUID_3D_MIC::FLUID_3D_MIC(int xRes, int yRes, int zRes, int amplify, unsigned int* boundaries) :
	_xRes(xRes), _yRes(yRes), _zRes(zRes), _res(0.)
{
	// set simulation consts
  _dt = 0.10; 

  _iterations = 1000;
  _buoyancy = 0.1f;
  _heatDiffusion = 1e-3;
  _vorticityEps = 2.0;
	_totalTime = 0.0f;
	_totalSteps = 0;
	_res = VEC3I(_xRes,_yRes,_zRes);
	_maxRes = _res.maxElement();

  // scale the constants according to the refinement of the grid
	_dx = 1.0f / (Real)_maxRes;
	Real scaling = 64.0f / _maxRes;
	scaling = (scaling < 1.0f) ? 1.0f : scaling;
	_vorticityEps /= scaling;

  // precision of the CG solver
  _solverEps = 1e-10;

  _center = VEC3F(0,0,0);
  _lengths = VEC3F(_dx * _xRes, _dx * _yRes, _dx * _zRes);

  _density    = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _densityOld = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _heat    = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _heatOld = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _pressure = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _divergence = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _residual = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _direction = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _q = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);

  _dudt0 = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _dudt1 = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);

  _velocity = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _velocityOld = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);

  _force = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
  _vorticity = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);

	_precon = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_z      = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Adiag  = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Aplusi = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Aplusj = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Aplusk = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Aminui = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Aminuj = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	_Aminuk = FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	
	// allocate arrays
	_totalCells   = _xRes * _yRes * _zRes;
	_slabSize = _xRes * _yRes;
	_xs = 1; _ys = _xRes; _zs = _slabSize;
	_obstacles    = new unsigned char[_totalCells];
	_dirichletObstacleField = new bool[_totalCells];
	_neumannObstacleField = new bool[_totalCells];

  _neumannVelocityField = VECTOR3_FIELD_3D(_xRes, _yRes, _zRes, _center, _lengths);
	
	for (int x = 0; x < _totalCells; x++)
  {
		_obstacles[x]    = false;
    _dirichletObstacleField[x] = false;
    _neumannObstacleField[x] = false;
  }
  
  // set up the boundary conditions
  if (boundaries != NULL)
  {
    _domainBcFront  = boundaries[0];
    _domainBcBack   = boundaries[1];
    _domainBcLeft   = boundaries[2];
    _domainBcRight  = boundaries[3];
    _domainBcTop    = boundaries[4];
    _domainBcBottom = boundaries[5];
  }
  else
  {
    _domainBcFront  = 1; 
    _domainBcBack   = 1;
    _domainBcLeft   = 1;
    _domainBcRight  = 1;
    _domainBcTop    = 0;
    _domainBcBottom = 0;
  }

	// set side obstacles
  int index;
  for (int y = 0; y < _yRes; y++)
    for (int x = 0; x < _xRes; x++)
    {
      // front slab
      index = x + y * _xRes;
      if(_domainBcFront==1) _obstacles[index] = 1;

      // back slab
      index += _totalCells - _slabSize;
      if(_domainBcBack==1) _obstacles[index] = 1;
    }
  for (int z = 0; z < _zRes; z++)
    for (int x = 0; x < _xRes; x++)
    {
      // bottom slab
      index = x + z * _slabSize;
      if(_domainBcBottom==1) _obstacles[index] = 1;

      // top slab
      index += _slabSize - _xRes;
      if(_domainBcTop==1) _obstacles[index] = 1;
    }
  for (int z = 0; z < _zRes; z++)
    for (int y = 0; y < _yRes; y++)
    {
      // left slab
      index = y * _xRes + z * _slabSize;
      if(_domainBcLeft==1) _obstacles[index] = 1;

      // right slab
      index += _xRes - 1;
      if(_domainBcRight==1) _obstacles[index] = 1;
    }
}
Esempio n. 9
0
bool vcylinder::define()
{
	glList = glGenLists(1);
	glNewList(glList, GL_COMPILE);
	glShadeModel(GL_FLAT);
	float angle = (float)(15 * (M_PI / 180));
	int iter = (int)(360 / 15);

	float h_len = length * 0.5f;
	VEC3F to = VEC3F(pb[0] - origin[0], pb[1] - origin[1], pb[2] - origin[2]);
	VEC3F u = to / to.length();
	double th = M_PI * 0.5;
	double ap = acos(u.z);
	double xi = asin(-u.y);

	if (ap > M_PI)
		ap = ap - M_PI;

	ang[0] = 180 * xi / M_PI;
	ang[1] = 180 * th / M_PI;
	ang[2] = 180 * ap / M_PI;

	EPD ep;
	ep.setFromEuler(xi, th, ap);

	glPushMatrix();
	glBegin(GL_TRIANGLE_FAN);
	{
		VEC3D p = VEC3D( 0.f, length * 0.5f, 0.f );
		glColor3f(0.0f, 0.f, 1.f);
	//	VEC3F p2_ = ep.A() * VEC3F(p2[0], p2[1], p2[2]);
		//glVertex3f(p2[0], p2[1], p2[2]);
		//p = ep.A() * p;
		glVertex3f(p.x, p.y, p.z);
		for (int i = 0; i < iter + 1; i++){
			float rad = angle * i;
			glColor3f(i % 2, 0.f, i % 2 + 1.f);
			VEC3D q(sin(rad)*topRadius, length * 0.5, cos(rad) * topRadius);
			//q = ep.A() * q;
			glVertex3f(/*origin[0] + */(float)q.x, /*origin[1] + */(float)q.y, /*origin[2] + */(float)q.z);	
		}
	}
	glEnd();
	glPopMatrix();
	glBegin(GL_TRIANGLE_FAN);
	{
		VEC3D p = VEC3D(0.f, -length * 0.5f, 0.f);
		//float p[3] = { 0.f, -length * 0.5f, 0.f };
		glColor3f(0.f, 0.f, 1.f);
		//glVertex3f(p1[0], p1[1], p1[2]);
		//p = ep.A() * p;
		glVertex3f(p.x, p.y, p.z);
		//glVertex3f(p[0], p[1], p[2]);
		for (int i = 0; i < iter + 1; i++){
			float rad = angle * i;
			glColor3f(i % 2, 0.0f, i % 2 + 1.0f);
			VEC3D q(sin(-rad)*baseRadius, -length * 0.5, cos(-rad) * baseRadius);
			//q = ep.A() * q;
			glVertex3f(/*origin[0] + */q.x, /*origin[1] + */q.y, /*origin[2] +*/ q.z);
		}
	}
	glEnd();
	glBegin(GL_QUAD_STRIP);
	{
		for (int i = 0; i < iter + 1; i++){
			float rad = angle * i;
			VEC3D q1(sin(rad) * topRadius, length * 0.5, cos(rad) * topRadius);
			VEC3D q2(sin(rad) * baseRadius, -length * 0.5, cos(rad) * baseRadius);
			//q1 = ep.A() * q1;
			//q2 = ep.A() * q2;
			glVertex3f(/*origin[0] + */q2.x, /*origin[1] + */q2.y, /*origin[2] + */q2.z);
			glVertex3f(/*origin[0] + */q1.x, /*origin[1] + */q1.y, /*origin[2] + */q1.z);
		}
	}
	glEnd();
	glEndList();


	return true;
}