Exemple #1
0
void esvg::Document::generateAnImage(ivec2 _size, draw::Image& _output)
{
	generateAnImage(_size.x(), _size.y());
	_output.resize(_size);
	draw::Color tmpp(0,0,0,0);
	_output.setFillColor(tmpp);
	_output.clear();
	if(NULL != m_renderedElement) {
		uint8_t* pointerOnData = m_renderedElement->getDataPointer();
		int32_t  sizeData = m_renderedElement->getDataSize();
		uint8_t* tmpOut = (uint8_t*)_output.getTextureDataPointer();
		memcpy(tmpOut, pointerOnData, sizeData);
	}
}
double BivariateDecomposition::debug(Vector * point, Vector * dp2prime, Vector * gradG2){


/////////////////////////////// ------------------- for debug only by Quan ----

	static int iii =1; 
	if (iii==1){
		iii++;
		ofstream file_coeff_2("Bivariate_surface_fitting_debug.out");

     	int numOfGridPlanes = numAxes*(numAxes-1)/2;

		for (int ii=0; ii<numOfGridPlanes; ii++) {

			file_coeff_2 <<"\n the "<<ii<<"  th plane: "<<endln;
			PrincipalAxis * axis_1 = theGridPlanes[ii]->getAxisPtr(1); // first axis
			PrincipalAxis * axis_2 = theGridPlanes[ii]->getAxisPtr(2);  // second axis

			 int m = axis_1->getExperimentalPointRule()->getNumberOfPoints();
			 int n = axis_2->getExperimentalPointRule()->getNumberOfPoints();




			Matrix * valueOnGrid = theGridPlanes[ii]->getGridValuesPtr();
			Matrix * valueG2OnGrid=0;
			
			if(isTimeVariant){
				valueG2OnGrid = theGridPlanes[ii]->getGridValuesG2Ptr();
			}

			double x_begin = axis_1->getExperimentalPointRule()->getBeginOfGrid();
			double x_end =   axis_1->getExperimentalPointRule()->getEndOfGrid();
			double x_interval = (x_end-x_begin)/(m-1);

			double y_begin=  axis_2->getExperimentalPointRule()->getBeginOfGrid();
			double y_end =   axis_2->getExperimentalPointRule()->getEndOfGrid();
			double y_interval = (y_end-y_begin)/(n-1);

			Vector * vector1 = axis_1->getAxisDirection();
			Vector * vector2 = axis_2->getAxisDirection();

			Vector tmpp(50); tmpp.Zero();
			file_coeff_2.precision(16);
			for( int pointX = 0; pointX < m; pointX++){
   

				for( int pointY = 0; pointY < n; pointY++){
					
					double x = x_begin + pointX*x_interval;
					double y = y_begin + pointY*y_interval;
					

					tmpp = x*(*vector1)/vector1->Norm()+y*(*vector2)/vector2->Norm();



					file_coeff_2<<"x:"<<x<<"y:"<<y<<endln;
					file_coeff_2<<"grid value G saved in the valueOnGrid is: "<<(*valueOnGrid)(pointX,pointY)<<endln;
					double gValue = this->getFunctionValue(&tmpp);
					file_coeff_2<<"grid value G computed by the response surface is: "<<gValue<<endln;

					file_coeff_2<<"grid value G2 saved in the valueOnGrid is: "<<(*valueG2OnGrid)(pointX,pointY)<<endln;
					double g2Value = this->getFunctionValue2(&tmpp,dp2prime,gradG2);
					file_coeff_2<<"grid value G2 computed by the response surface is: "<<g2Value<<endln;

	  			 

				} //pointY
			}//pointX
		} //ii =1:numOfGridPlanes
			
 
	//*/
		file_coeff_2.close();

	}// if iii==1     
////////////////////------ end debug -----------------
    return 0; 
 

};
SurfaceScalarJump<EvalT, Traits>::
SurfaceScalarJump(const Teuchos::ParameterList& p,
                  const Teuchos::RCP<Albany::Layouts>& dl) :
  cubature      (p.get<Teuchos::RCP<Intrepid2::Cubature<RealType, Intrepid2::FieldContainer_Kokkos<RealType, PHX::Layout,PHX::Device> >>>("Cubature")), 
  intrepidBasis (p.get<Teuchos::RCP<Intrepid2::Basis<RealType, Intrepid2::FieldContainer_Kokkos<RealType, PHX::Layout, PHX::Device>>>>("Intrepid2 Basis"))
//  scalar        (p.get<std::string>("Nodal Scalar Name"),dl->node_scalar),
//  scalarJump    (p.get<std::string>("Scalar Jump Name"),dl->qp_scalar),
 // scalarAverage (p.get<std::string>("Scalar Average Name"),dl->qp_scalar)
{
 // this->addDependentField(scalar);

//  this->addEvaluatedField(scalarJump);
//  this->addEvaluatedField(scalarAverage);

  this->setName("Surface Scalar Jump"+PHX::typeAsString<EvalT>());

  haveTemperature = false;
  haveTransport = false;
  haveHydroStress = false;
  havePorePressure = false;

  if (p.isType<std::string>("Nodal Pore Pressure Name")) {
	havePorePressure = true;
    PHX::MDField<ScalarT,Cell,Vertex>
      tp(p.get<std::string>("Nodal Pore Pressure Name"), dl->node_scalar);
    nodalPorePressure = tp;
    this->addDependentField(nodalPorePressure);

    PHX::MDField<ScalarT,Cell,QuadPoint>
      tjp(p.get<std::string>("Jump of Pore Pressure Name"), dl->qp_scalar);
    jumpPorePressure = tjp;
    this->addEvaluatedField(jumpPorePressure);

    PHX::MDField<ScalarT,Cell,QuadPoint>
      tmpp(p.get<std::string>("MidPlane Pore Pressure Name"), dl->qp_scalar);
    midPlanePorePressure = tmpp;
    this->addEvaluatedField(midPlanePorePressure);
  }

  if (p.isType<std::string>("Nodal Temperature Name")) {
	haveTemperature = true;
    PHX::MDField<ScalarT,Cell,Vertex>
      tf(p.get<std::string>("Nodal Temperature Name"), dl->node_scalar);
    nodalTemperature = tf;
    this->addDependentField(nodalTemperature);

    PHX::MDField<ScalarT,Cell,QuadPoint>
      tt(p.get<std::string>("Jump of Temperature Name"), dl->qp_scalar);
    jumpTemperature = tt;
    this->addEvaluatedField(jumpTemperature);

    PHX::MDField<ScalarT,Cell,QuadPoint>
      tmt(p.get<std::string>("MidPlane Temperature Name"), dl->qp_scalar);
    midPlaneTemperature = tmt;
    this->addEvaluatedField(midPlaneTemperature);
  }

  if (p.isType<std::string>("Nodal Transport Name")) {
	haveTransport = true;
    PHX::MDField<ScalarT,Cell,Vertex>
      ttp(p.get<std::string>("Nodal Transport Name"), dl->node_scalar);
    nodalTransport = ttp;
    this->addDependentField(nodalTransport);

    PHX::MDField<ScalarT,Cell,QuadPoint>
    tjtp(p.get<std::string>("Jump of Transport Name"), dl->qp_scalar);
    jumpTransport= tjtp;
    this->addEvaluatedField(jumpTransport);

    PHX::MDField<ScalarT,Cell,QuadPoint>
    tjtm(p.get<std::string>("MidPlane Transport Name"), dl->qp_scalar);
    midPlaneTransport = tjtm;
    this->addEvaluatedField(midPlaneTransport);
  }

  if (p.isType<std::string>("Nodal HydroStress Name")) {

    haveHydroStress = true;
    PHX::MDField<ScalarT,Cell,Vertex>
      ths(p.get<std::string>("Nodal HydroStress Name"), dl->node_scalar);
    nodalHydroStress = ths;
    this->addDependentField(nodalHydroStress);

    PHX::MDField<ScalarT,Cell,QuadPoint>
    tjths(p.get<std::string>("Jump of HydroStress Name"), dl->qp_scalar);
    jumpHydroStress= tjths;
    this->addEvaluatedField(jumpHydroStress);

    PHX::MDField<ScalarT,Cell,QuadPoint>
    tmpths(p.get<std::string>("MidPlane HydroStress Name"), dl->qp_scalar);
    midPlaneHydroStress= tmpths;
    this->addEvaluatedField(midPlaneHydroStress);
  }

  std::vector<PHX::DataLayout::size_type> dims;
  dl->node_vector->dimensions(dims);
  worksetSize = dims[0];
  numNodes = dims[1];
  numDims = dims[2];

  numQPs = cubature->getNumPoints();

  numPlaneNodes = numNodes / 2;
  numPlaneDims = numDims - 1;

#ifdef ALBANY_VERBOSE
    std::cout << "in Surface Scalar Jump" << std::endl;
    std::cout << " numPlaneNodes: " << numPlaneNodes << std::endl;
    std::cout << " numPlaneDims: " << numPlaneDims << std::endl;
    std::cout << " numQPs: " << numQPs << std::endl;
    std::cout << " cubature->getNumPoints(): " << cubature->getNumPoints() << std::endl;
    std::cout << " cubature->getDimension(): " << cubature->getDimension() << std::endl;
#endif

  // Allocate Temporary FieldContainers
  refValues.resize(numPlaneNodes, numQPs);
  refGrads.resize(numPlaneNodes, numQPs, numPlaneDims);
  refPoints.resize(numQPs, numPlaneDims);
  refWeights.resize(numQPs);

  // Pre-Calculate reference element quantitites
  cubature->getCubature(refPoints, refWeights);
  intrepidBasis->getValues(refValues, refPoints, Intrepid2::OPERATOR_VALUE);
  intrepidBasis->getValues(refGrads, refPoints, Intrepid2::OPERATOR_GRAD);
}
Exemple #4
0
etk::Matrix2 etk::Matrix2::operator- (const etk::Matrix2& _obj) const {
	etk::Matrix2 tmpp(*this);
	tmpp += _obj;
	return tmpp;
}
Exemple #5
0
void KIconEditGrid::mouseMoveEvent( QMouseEvent *e )
{
  if(!e)
    return;

  int row = findRow( e->pos().y() );
  int col = findCol( e->pos().x() );
  int cell = row * numCols() + col;

  QPoint tmpp(col, row);
  if(tmpp == end)
    return;

  if(img->valid(col, row))
  {
    //debug("%d X %d", col, row);
    emit poschanged(col, row);
    emit xposchanged((col*scaling())+scaling()/2); // for the rulers
    emit yposchanged((row*scaling())+scaling()/2);
  }

  if(ispasting && !btndown && img->valid(col, row))
  {
    if( (col + cbsize.width()) > (numCols()-1) )
      insrect.setX(numCols()-insrect.width());
    else
      insrect.setX(col);
    if( (row + cbsize.height()) > (numRows()-1) )
      insrect.setY(numRows()-insrect.height());
    else
      insrect.setY(row);
    insrect.setSize(cbsize);
    //debug("Moving: %d x %d", insrect.width(), insrect.height());
    start = insrect.topLeft();
    end = insrect.bottomRight();
    drawRect(false);
    return;
  }

  if(!img->valid(col, row) || !btndown)
    return;

  end.setX(col);
  end.setY(row);

  if(isselecting)
  {
    if(tool == SelectRect)
      drawRect(false);
    else
      drawEllipse(false);
    return;
  }

  switch( tool )
  {
    case Eraser:
      currentcolor = TRANSPARENT;
    case Freehand:
    {
      setColor( cell, currentcolor );
  //img.setPixel(col, row, currentcolor.pixel());

      if ( selected != cell )
      {
        modified = true;
        int prevSel = selected;
        selected = cell;
        repaint((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize, false);
        repaint(col*cellsize,row*cellsize, cellsize, cellsize, false);
        //updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
        //updateCell( row, col, FALSE );
        *((uint*)img->scanLine(row) + col) = (colorAt(cell));
      }
      break;
    }
    case Find:
    {
      iconcolors.closestMatch(colorAt(cell));
      if ( selected != cell )
      {
        int prevSel = selected;
        selected = cell;
        repaint((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize, false);
        repaint(col*cellsize,row*cellsize, cellsize, cellsize, false);
        //updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
        //updateCell( row, col, FALSE );
      }
      break;
    }
    case Ellipse:
    case Circle:
    case FilledEllipse:
    case FilledCircle:
    {
      drawEllipse(false);
      break;
    }
    //case Select:
    case FilledRect:
    case Rect:
    {
      drawRect(false);
      break;
    }
    case Line:
    {
      drawLine(false);
      break;
    }
    case Spray:
    {
      drawSpray(QPoint(col, row));
      modified = true;
      break;
    }
    default:
      break;
  }

  p = *img;

  emit changed(QPixmap(p));
  //emit colorschanged(numColors(), data());
}
Exemple #6
0
int EMclustering::EM(int k, int *IDX, bool spatial, bool att)
{
	clusternum = k;
	MatrixXf x;
	/*if(spatial)
	{
		if(att)
		{
			x.resize(4,dataSize);
			for(int i=0;i<dataSize;i++)
			{
				x(0,i) = dataPos[i][0];
				x(1,i) = dataPos[i][1];
				x(2,i) = dataPos[i][2];
				x(3,i) = dataDen[i];
			}
		}
		else
		{
			x.resize(6,dataSize);
			for(int i=0;i<dataSize;i++)
			{
				x(0,i) = dataPos[i][0];
				x(1,i) = dataPos[i][1];
				x(2,i) = dataPos[i][2];
				x(3,i) = dataVel[i][0];
				x(4,i) = dataVel[i][1];
				x(5,i) = dataVel[i][2];
			}
		}
	}
	else
	{*/
		if(att)
		{
			x.resize(1,dataDen.size());
			for(int i=0;i<dataDen.size();i++)
			{
				x(0,i) = dataDen[i];
			}
			//cerr<<x;
			//cerr<<endl;
			if(k>dataDen.size())
				return -1;
		}
		else
		{
			x.resize(3,dataSize);
			for(int i=0;i<dataSize;i++)
			{
				x(0,i) = dataVel[i][0];//fabs(cos(-PI/4)*dataVel[i][0] - sin(-PI/4)*dataVel[i][1]);
				x(1,i) = dataVel[i][1];//fabs(sin(-PI/4)*dataVel[i][0] + cos(-PI/4)*dataVel[i][1]);
				x(2,i) = dataVel[i][2];
			}
			if(k>dataSize)
				return -1;
		}
	//}

	//cout<<"EM for Gaussian mixture: running ... "<<endl;
	//cerr<<x<<endl;
	MatrixXf r =initialization(x,k);// kmeans(x,k);//
	//cerr<<"Initialization is Done"<<endl;//cerr<<r<<endl;
	VectorXi label(r.rows());
	for(int i=0;i<r.rows();i++)
	{
		int index;
		float tmp1 = r.row(i).maxCoeff(&index);
		label(i) = index;
	}//cerr<<label<<endl;
	VectorXi tmpp(label.size()); 
	VectorXi tmp2 = unique(label,tmpp);
	int tmpd = tmp2.size();  //cerr<<tmpd<<endl;
	MatrixXf tmpr(r.rows(),tmpd);
	for(int i=0;i<tmpd;i++)
	{
		tmpr.col(i) = r.col(tmp2(i));
	}//cerr<<"done1"<<endl;
	r.resize(r.rows(),tmpd);
	r = tmpr;//cerr<<r.cols()<<endl;
	float tol = 1e-10;
	int max = 300;

	double llh = -9e+9;
	bool converged = false;
	int t = 1;
	//cerr<<"done1"<<endl;
	//gaussian_model model;

	int clusternum_error;

	MatrixXf tmpmodel;

	while(!converged&&t<max)
	{
		t = t + 1;
		gaussian_model model = maximization(x,r);//cerr<<t<<" "<<"max"<<endl;
		float tmpllh = llh;
		r = expectation(x,model,llh);//cerr<<t<<" "<<"exp"<<endl;
		for(int i=0;i<r.rows();i++)
		{
			int index;
			float tmp1 = r.row(i).maxCoeff(&index);
			label(i) = index;
		}
		
		VectorXi u = unique(label,tmpp);//cerr<<t<<" "<<u.size()<<" "<<r.cols()<<" "<<r.rows()<<endl;
		clusternum_error = clusternum - u.size();

		if(r.cols()!=u.size())
		{
		/*	tmpr.resize(r.rows(),u.size());
			for(int i=0;i<u.size();i++)
			{
				tmpr.col(i) = r.col(u(i));
			}
			r.resize(r.rows(),u.size());
			r = tmpr;//cerr<<"r"<<endl;*/
		}
		else
		{
			if((llh - tmpllh)<tol*abs(llh))
				converged = true;
			else
				converged = false;
		}
		//cerr<<"t"<<t<<endl;
		//return_model = model;

		tmpmodel.resize(model.mu.rows(),model.mu.cols());
		//return_model = model.mu;
		tmpmodel = model.mu;
		u.resize(0);
		//cerr<<tmpmodel<<endl;
	}
	/*ofstream off2("rr");
	off2<<r.row(0)<<endl;
	for(int i=1;i<r.rows();i++)
		if(r.row(i)!=r.row(i-1))
		{off2<<x.col(i)<<" ";
			off2<<r.row(i)<<endl;}
off2.close();*/
		cerr<<clusternum_error<<endl;
	return_model  = tmpmodel;
	//cerr<<label<<endl;
	if (converged)
    		cerr<<"Converged in "<<t-1<<endl;
	else
    		cerr<<max<<endl;
	//cerr<<t-1<<endl;

	
	for(int i=0;i<label.size();i++)
	{
		IDX[i] = label(i);
		//cerr<<IDX[i]<<" ";
	}//cerr<<endl;

	//cerr<<label.size()<<endl;

	x.resize(0,0);
	r.resize(0,0);
	tmpr.resize(0,0);
	tmpmodel.resize(0,0);
	label.resize(0);
	tmpp.resize(0);
	tmp2.resize(0);
	

	return clusternum_error;
}