예제 #1
0
PtsKD AllocateurDInconnues::PInits()
{
   PtsKD aP((int) mAdrVar.size());
   for (INT aK=0; aK<INT(mAdrVar.size()) ; aK++)
       aP(aK) = *mAdrVar[aK];

   return aP;
}
예제 #2
0
std::vector<float> SimpleRayCaster::castRay(Eigen::Vector2f &p) {

    std::vector<float> zvalues;

    /* distort the point with the lens parameters */
    Eigen::Vector2f pDist = distortPoint(p);

    /* convert 2d coordinate (0.0-1.0) to proper image coordinate */
    Eigen::Vector3f aP(pDist[0]*_res_x, 
                       pDist[1]*_res_y, 
                       1.0); 

    /* project with inverse camera calibration matrix 
     * to 3d vector in camera space */
    cv::Mat ptMat = (cv::Mat_<float>(3,1) << aP[0], aP[1], aP[2]);
    cv::Mat vec3d = _inverseCamMat * ptMat; 
    Eigen::Vector3f pvec(vec3d.at<float>(0,0),
                         vec3d.at<float>(1,0),
                         vec3d.at<float>(2,0));

    std::vector<Eigen::Vector3f> isecs = intersectRay(pvec);
    for (auto isec : isecs) {
        zvalues.push_back(isec.norm());
    }

    return zvalues;
}
예제 #3
0
파일: CDS_YHay.cpp 프로젝트: jesushl/TUNAM
inline bool CDS_YHay<Tprec, Dim>::calcCoefficients2D () {
    prec_t dy_dx = Gamma * dy / dx;
    prec_t dx_dy = Gamma * dx / dy;
    prec_t dxy_dt = dx * dy / dt;
    prec_t RaGaVol = Rayleigh * Gamma * 0.5 * dx * dy;
    prec_t ce, cw;
    prec_t cn, cs;
    aE = 0.0; aW = 0.0; aN = 0.0; aS = 0.0; aP = 0.0; 
    sp = 0.0;
    
    for (int j = bj; j <= ej; ++j)
	for (int i =  bi; i <= ei; ++i)
	{
	    ce = ( u(i  ,j) + u(i  ,j+1) ) * 0.5 * dy;
	    cw = ( u(i-1,j) + u(i-1,j+1) ) * 0.5 * dy;
	    cn = ( v(i  ,j) + v(i  ,j+1) ) * 0.5 * dx;
	    cs = ( v(i  ,j) + v(i  ,j-1) ) * 0.5 * dx;

	    aE (i,j) = dy_dx - ce * 0.5;
	    aW (i,j) = dy_dx + cw * 0.5;
	    aN (i,j) = dx_dy - cn * 0.5;
	    aS (i,j) = dx_dy + cs * 0.5;
	    aP (i,j) = aE (i,j) + aW (i,j) + aN (i,j) + aS (i,j) + dxy_dt;
//		+ (ce - cw) + (cn - cs);
// Term (ce - cw) is part of discretizated continuity equation, and
// must be equal to zero when that equation is valid, so I can avoid
// this term for efficiency.
	    sp (i,j) = v(i,j) * dxy_dt - ( p(i,j+1) - p(i,j) ) * dx +
	      RaGaVol * ( T(i,j) + T(i,j+1) );
	}    
    calc_dv_2D();
    applyBoundaryConditions2D();
    return 0;  
}
         const Pack_Of_Pts *  RLEImGridReechComp<Type,TyBase>::values
                              (
                                   const class Pack_Of_Pts * aGenPack
                               )
{
     
      const RLE_Pack_Of_Pts *  aRle = aGenPack->rle_cast ();
      INT aNb = aRle->nb();
      _pack_out->set_nb(aNb);


      if (aNb)
      {
         REAL * coord = _pack_out->_pts[0];
         Pt2di aP0 (aRle->vx0(),aRle->y());

         mGrX.NewLine(aP0);
         mGrY.NewLine(aP0);

         for (INT k=0 ; k<aNb ; k++)
         {
               Pt2dr  aP(mGrX.GetVal(),mGrY.GetVal());
               tPt aPFix(aP);

 
               coord[k] = TImGet<Type,TyBase,NBB_RGRC>::getr(mTIm,aPFix,mDef);
               mGrX.IncrX();
               mGrY.IncrX();
         }
      }

      return _pack_out;

}
예제 #5
0
파일: b_0_38.cpp 프로젝트: jakexie/micmac
void BenchcDbleGrid
     (
         Pt2dr aP0In,Pt2dr aP1In,
         REAL               aStepDir,
         ElDistortion22_Gen & aDist
     )
{
     //cDbleGrid aDGr(aP0In,aP1In,aStepDir,aDist);
     Pt2dr stepDir2(aStepDir,aStepDir);                // __NEW
     cDbleGrid aDGr(false,aP0In,aP1In,stepDir2,aDist); // __NEW

     for (REAL aX = aP0In.x ; aX<aP1In.x ; aX += aStepDir)
         for (REAL aY = aP0In.y ; aY<aP1In.y ; aY += aStepDir)
         {
             REAL x = aX + NRrandom3() * aStepDir;
             SetInRange(aP0In.x,x,aP1In.x);
             REAL y = aY + NRrandom3() * aStepDir;
             SetInRange(aP0In.y,y,aP1In.y);

	     Pt2dr aP(x,y);
	     Pt2dr aQ0 = aDist.Direct(aP);
	     Pt2dr aQ1 = aDGr.Direct(aP);
	     Pt2dr aR0 = aDist.Inverse(aQ0);
	     Pt2dr aR1 = aDist.Inverse(aQ1);

	     REAL aDQ = euclid(aQ0,aQ1);
	     REAL aDR = euclid(aR0,aP) +  euclid(aR1,aP);
	     aDQ /= ElSquare(aStepDir);
	     aDR /= ElSquare(aStepDir);
	     BENCH_ASSERT(aDQ<0.1);
	     BENCH_ASSERT(aDR<0.1);
         }
}
예제 #6
0
inline bool Upwind_ZCoDiS<Tprec, Dim>::calcCoefficients3D () {
    prec_t dyz = dy * dz, dyz_dx = Gamma * dyz / dx;
    prec_t dxz = dx * dz, dxz_dy = Gamma * dxz / dy;
    prec_t dxy = dx * dy, dxy_dz = Gamma * dxy / dz;
    prec_t dxyz_dt = dx * dy * dz / dt;
    prec_t ce, cw;
    prec_t cn, cs;
    prec_t cf, cb;
    aE = 0.0; aW = 0.0; aN = 0.0; aS = 0.0; aF = 0.0; aB = 0.0; aP = 0.0; 
    sp = 0.0;

   for (int k = bk; k <= ek; ++k)
       for (int i =  bi; i <= ei; ++i)
	   for (int j = bj; j <= ej; ++j)
	   {
	       ce = ( u(i,j,k) + u(i,j+1,k) ) * 0.5 * dyz;
	       cw = ( u(i-1,j,k) + u(i-1,j+1,k) ) * 0.5 * dyz;
	       cn = ( v(i,j,k) + v(i+1,j,k) ) * 0.5 * dxz;
	       cs = ( v(i,j-1,k) + v(i+1,j-1,k) ) * 0.5 * dxz;
	       cf = ( w(i,j,k) + w(i,j,k+1) ) * 0.5 * dxy;
	       cb = ( w(i,j,k) + w(i,j,k-1) ) * 0.5 * dxy;

	       if ( ce > 0 ) ce = 0.0; 
	       else          ce = -ce;
//
// This statement:	    
	       if ( cw <= 0 ) cw = 0.0; 
//
// is more efficient than the next similar one:
//	    if ( cw > 0 ) cw = cw; 
//	    else          cw = 0.0;

	       if ( cn > 0 ) cn = 0.0;
	       else          cn = -cn;
	       if ( cs <= 0 ) cs = 0.0; 

	       if ( cf > 0 ) cf = 0.0;
	       else          cf = -cf;
	       if ( cb <= 0 ) cb = 0.0; 
	    
	       aE (i,j,k) = (dyz_dx + ce);
	       aW (i,j,k) = (dyz_dx + cw);
	       aN (i,j,k) = (dxz_dy + cn);
	       aS (i,j,k) = (dxz_dy + cs);
	       aF (i,j,k) = (dxy_dz + cf);
	       aB (i,j,k) = (dxy_dz + cb);
	       aP (i,j,k) = aE (i,j,k) + aW (i,j,k) + aN (i,j,k) + aS (i,j,k)
		   + aF (i,j,k) + aB (i,j,k) + dxyz_dt;
//		+ (ce - cw);	    
// Term (ce - cw) is part of discretizated continuity equation, and
// must be equal to zero when that equation is valid, so I can avoid
// this term for efficiency.

	       sp(i,j,k) = w(i,j,k) * dxyz_dt - 
		 ( p(i,j,k+1)- p(i,j,k) ) * dxy; 
	   }    
   calc_dw_3D();
   applyBoundaryConditions3D();
   return 0;   
}
예제 #7
0
void BiScroller::MasqMakeOneLine
     (
           U_INT1 * aDataImR,
           U_INT1 * aDataImG,
           U_INT1 * aDataImB,
           INT      aY,
           INT      anX0,
           INT      anX1,
           U_INT1 * aLine1,
           U_INT1 * aLine2
     )
{
   static U_INT1 * aLR=0;
   static U_INT1 * aLG=0;
   static U_INT1 * aLB=0;
   if (aLR==0)
   {
       aLR = new U_INT1 [256] ;
       aLG = new U_INT1 [256] ;
       aLB = new U_INT1 [256] ;

        // Pt3dr aP0(128,0,0);
        // Pt3dr aP1(255,128,255);
        // Pt3dr aP0(0,0,128);
        // Pt3dr aP1(255,128,255);
        Pt3dr aP0(0,80,0);
        Pt3dr aP1(255,255,128);

        for (int aK=0 ; aK< 256 ; aK++)
        {
          double aPds0 = 1- aK /255.0;
          double aPds1 = 1-aPds0;
          Pt3dr aCol = aP0 *aPds0 +  aP1*aPds1;
          aLR[aK] = round_ni(aCol.x);
          aLG[aK] = round_ni(aCol.y);
          aLB[aK] = round_ni(aCol.z);
        }
   }


   TIm2D<U_INT1,INT> aTM(mImMasq);
   Pt2di aP(anX0,aY);

   Pt2dr aQ0 = mScrGray->to_user(Pt2dr(aP));
   Pt2dr aQ1 = mScrGray->to_user(Pt2dr(aP)+Pt2dr(1,0));
   double aDx = aQ1.x -aQ0.x;
   double aXQ0 = aQ0.x;
   int aYQ0 = round_ni(aQ0.y);

   for (; aP.x<anX1 ; aP.x++)
   {
       bool inM = (aTM.get(Pt2di(round_ni(aXQ0),aYQ0),0)!=0);
       int aCoul = aLine1[aP.x];

       aDataImR[aP.x] = inM?aLR[aCoul]:aCoul ;
       aDataImG[aP.x] = inM?aLG[aCoul]:aCoul ;
       aDataImB[aP.x] = inM?aLB[aCoul]:aCoul ;
        aXQ0 +=aDx;
   }
}
예제 #8
0
파일: CDS_YLES.cpp 프로젝트: jesushl/TUNAM
inline
bool CDS_YLES<T_number, Dim>::calcCoefficients(const ScalarField &nut) { 
    T_number dyz = dy * dz, dxz = dx * dz, dxy = dx * dy;
    T_number dyz_dx = dyz / dx, dxz_dy = dxz / dy, dxy_dz = dxy / dz;
    T_number ce, cw, cn, cs, cf, cb;
    T_number nutinter;
    T_number dxyz_dt = dx * dy * dz / dt;
    T_number RaGaVol = Rayleigh * Gamma * 0.5 * dx * dy * dz;
   
    for (int i =  bi; i <= ei; ++i)
	for (int j = bj; j <= ej; ++j)
	    for (int k = bk; k <= ek; ++k)
	    {
		ce = ( u(i,j,k) + u(i,j+1,k) ) * 0.5 * dyz;
		cw = ( u(i-1,j,k) + u(i-1,j+1,k) ) * 0.5 * dyz;
		cn = ( v(i,j,k) + v(i,j+1,k) ) * 0.5 * dxz;
		cs = ( v(i,j,k) + v(i,j-1,k) ) * 0.5 * dxz;
		cf = ( w(i,j,k) + w(i,j,k+1) ) * 0.5 * dxy;
		cb = ( w(i-1,j,k) + w(i-1,j,k+1) ) * 0.5 * dxy;

//
// nut is calculated on center of volumes, therefore, nut
// must be staggered in y direction:	    
		nutinter = 0.5 * ( nut(i,j,k) + nut(i,j+1,k) );

		aE (i,j,k) = (Gamma + nutinter) * dyz_dx - ce * 0.5;
		aW (i,j,k) = (Gamma + nutinter) * dyz_dx + cw * 0.5;
		aN (i,j,k) = 2 * (Gamma + nutinter) * dxz_dy - cn * 0.5;
		aS (i,j,k) = 2 * (Gamma + nutinter) * dxz_dy + cs * 0.5;
		aF (i,j,k) = (Gamma + nutinter) * dxy_dz - cf * 0.5;
		aB (i,j,k) = (Gamma + nutinter) * dxy_dz + cb * 0.5;
		aP (i,j,k) = aE (i,j,k) + aW (i,j,k) +
		             aN (i,j,k) + aS (i,j,k) +
		             aF (i,j,k) + aB (i,j,k) +
		             dxyz_dt;	    
//		aP (i,j,k) /= alpha;  // under-relaxation
//		+ (ce - cw)  + (cn - cs) + (cf - cb);	    
// Term (ce - cw) is part of discretizated continuity equation, and
// must be equal to zero when that equation is valid, so I can avoid
// this term for efficiency.

		sp (i,j,k) = v(i,j,k) * dxyz_dt - 
		    ( p(i,j+1,k) - p(i,j,k) ) * dxz +
		    RaGaVol * ( T(i,j,k) + T(i,j+1,k) ) +
		    nutinter * ( (u(i,j+1,k) - u(i,j,k) - 
				  u(i-1,j+1,k) + u(i-1,j,k)) * dz +
				 (w(i,j+1,k) - w(i,j,k) - 
				  w(i,j+1,k-1) + w(i,j,k-1)) * dx );
		
//		    v(i,j,k) * (1-alpha) * aP(i,j,k)/alpha; // under-relaxation
	}    
    calc_dv_3D();
    applyBoundaryConditions3D();

    return 1;
}
예제 #9
0
inline bool Upwind_XCoDiS<Tprec, Dim>::calcCoefficients2D()
{
    prec_t dy_dx = Gamma * dy / dx;
    prec_t dx_dy = Gamma * dx / dy;
    prec_t dxy_dt = dx * dy / dt;
    prec_t ce, cw;
    prec_t cn, cs;
    aE = 0.0;
    aW = 0.0;
    aN = 0.0;
    aS = 0.0;
    aP = 0.0;
    sp = 0.0;

    for (int i =  bi; i <= ei; ++i)
        for (int j = bj; j <= ej; ++j)
        {
            ce = ( u(i+1, j) + u(i,j) ) * 0.5 * dy;
            cw = ( u(i-1, j) + u(i,j) ) * 0.5 * dy;
            cn = ( v(i,j) + v(i+1,j) ) * 0.5 * dx;
            cs = ( v(i,j-1) + v(i+1,j-1) ) * 0.5 * dx;

            if ( ce > 0 ) ce = 0.0;
            else          ce = -ce;
//
// This statement:
            if ( cw <= 0 ) cw = 0.0;
//
// is more efficient than the next similar one:
//	    if ( cw > 0 ) cw = cw;
//	    else          cw = 0.0;

            if ( cn > 0 ) cn = 0.0;
            else          cn = -cn;
            if ( cs <= 0 ) cs = 0.0;

            aE (i,j) = (dy_dx + ce);
            aW (i,j) = (dy_dx + cw);
            aN (i,j) = (dx_dy + cn);
            aS (i,j) = (dx_dy + cs);
            aP (i,j) = aE (i,j) + aW (i,j) + aN (i,j) + aS (i,j);
            //+ dxy_dt;
//		+ (ce - cw) + (cn - cs);
// Term (ce - cw) is part of discretizated continuity equation, and
// must be equal to zero when that equation is valid, so I can avoid
// this term for efficiency.
//	    sp (i,j) = u(i,j) * dxy_dt - ( p(i+1,j) - p(i,j) ) * dy;
            sp (i,j) = - ( p(i+1,j) - p(i,j) ) * dy;
        }
    calc_du_2D();
    applyBoundaryConditions2D();
    return 0;
}
예제 #10
0
int OCCEdge::createSpline(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points,
                           double tolerance)
{
    try {
        Standard_Boolean periodic = false;
        Standard_Real tol = tolerance;
        
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
        }
        
        int nbControlPoints = points.size();
        Handle(TColgp_HArray1OfPnt) ctrlPoints;
        ctrlPoints = new TColgp_HArray1OfPnt(1, nbControlPoints + vertices);
        
        int index = 1;
        
        if (vertices) {
            ctrlPoints->SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));  
        }
        
        for (int i = 0; i < nbControlPoints; i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints->SetValue(index++, aP);
        }
        
        if (vertices) {
            ctrlPoints->SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z()));
        }
        
        GeomAPI_Interpolate INT(ctrlPoints, periodic, tol);
        INT.Perform();
        
        Handle(Geom_BSplineCurve) curve = INT.Curve();
        if (vertices) {
            this->setShape(BRepBuilderAPI_MakeEdge(curve, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(curve));
        }
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create spline");
        }
        return 0;
    }
    return 1;
}
예제 #11
0
static Handle(Geom_Curve) mkBezierCurve(const Standard_Integer nPoles,
                                        const Standard_Real theCoords[][3],
                                        const Standard_Real aScale = 1,
                                        const gp_XYZ& aShift = gp_XYZ(0,0,0))
{
    TColgp_Array1OfPnt aPoles (1, nPoles);
    for (Standard_Integer i=0; i < nPoles; i++)
    {
        gp_XYZ aP (theCoords[i][0], theCoords[i][1], theCoords[i][2]);
        aPoles(i+1) = gp_Pnt (aP * aScale + aShift);
    }
    return new Geom_BezierCurve (aPoles);
}
예제 #12
0
static TopoDS_Wire mkPolygonWire(const Standard_Integer nPoints,
                                 const Standard_Real theCoords[][3],
                                 const Standard_Real aScale = 1,
                                 const gp_XYZ& aShift = gp_XYZ(0,0,0))
{
    BRepBuilderAPI_MakePolygon aPol;
    for (Standard_Integer i=0; i < nPoints; i++)
    {
        gp_XYZ aP(theCoords[i][0], theCoords[i][1], theCoords[i][2]);
        aPol.Add (gp_Pnt (aP * aScale + aShift));
    }
    return aPol.Wire();
}
예제 #13
0
int OCCEdge::createBezier(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points)
{
    try {
        int nbControlPoints = points.size();
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
        }
        
        TColgp_Array1OfPnt ctrlPoints(1, nbControlPoints + vertices);
        
        int index = 1;
        if (vertices) {
            ctrlPoints.SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));
        }
        
        for (int i = 0; i < nbControlPoints; i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints.SetValue(index++, aP);
        }
        
        if (vertices)
            ctrlPoints.SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z())); 
        
        Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(ctrlPoints);
        
        if (vertices) {
            this->setShape(BRepBuilderAPI_MakeEdge(bezier, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(bezier));
        }
        
        if (this->length() <= Precision::Confusion()) {
            StdFail_NotDone::Raise("bezier not valid");
        }
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create bezier");
        }
        return 0;
    }
    return 1;
}
예제 #14
0
void BiScroller::LutMakeOneLine
     (
           U_INT1 * aDataImR,
           U_INT1 * aDataImG,
           U_INT1 * aDataImB,
           INT      aY,
           INT      anX0,
           INT      anX1,
           U_INT1 * aLineGr,
           U_INT1 * aLineCol
     )
{
/*
    U_INT1 * aRGB;
    for (INT x= anX0; x<anX1 ; x++)
    {
        aRGB = RGBEntry(aLineGr[x],aLineCol[x]);
        aDataImR[x] = aRGB[eIndR];
        aDataImG[x] = aRGB[eIndG];
        aDataImB[x] = aRGB[eIndB];
    }
*/
   TIm2D<U_INT1,INT> aTM(mImMasq);
   Pt2di aP(anX0,aY);

   Pt2dr aQ0 = mScrGray->to_user(Pt2dr(aP));
   Pt2dr aQ1 = mScrGray->to_user(Pt2dr(aP)+Pt2dr(1,0));
   double aDx = aQ1.x -aQ0.x;
   double aXQ0 = aQ0.x;
   int aYQ0 = round_ni(aQ0.y);

   for (; aP.x<anX1 ; aP.x++)
   {
       int  indCoul  = aTM.get(Pt2di(round_ni(aXQ0),aYQ0),0);
       int aGray = aLineGr[aP.x];

       U_INT1 * aRGB = RGBEntry(aGray,indCoul);

        aDataImR[aP.x] = aRGB[eIndR];
        aDataImG[aP.x] = aRGB[eIndG];
        aDataImB[aP.x] = aRGB[eIndB];
       // aDataImR[aP.x] = inM?aLR[aCoul]:aCoul ;
       // aDataImG[aP.x] = inM?aLG[aCoul]:aCoul ;
       // aDataImB[aP.x] = inM?aLB[aCoul]:aCoul ;
        aXQ0 +=aDx;
   }
}
예제 #15
0
void   GenCodeSurf()
{
   if (1)
   {
        ElSeg3D aSeg(Pt3dr(0,0,0),Pt3dr(1,0,0));
        cCylindreRevolution aCyl(true,aSeg,Pt3dr(0,1,0));
        cSetEqFormelles  aSet;
        aSet.AllocCylindre(aCyl,true);
   }

   if (1) 
   {
        cSetEqFormelles  aSet; 
        Pt3dr aP(0,0,0);
        cSolBasculeRig aSBR(aP,aP,ElMatrix<double>::Rotation(0,0,0),1);
        aSet.NewEqObsBascult(aSBR,true);
   }
}
예제 #16
0
static Handle(Geom_Curve) mkPBSplineCurve(const Standard_Integer nPoles,
        const Standard_Real theCoords[][3],
        const Standard_Real aScale = 1,
        const gp_XYZ& aShift = gp_XYZ(0,0,0))
{
    TColgp_Array1OfPnt aPoles (1, nPoles);
    TColStd_Array1OfReal aKnots (1, nPoles+1);
    TColStd_Array1OfInteger aMults(1, nPoles+1);

    for (Standard_Integer i=0; i < nPoles; i++)
    {
        gp_XYZ aP (theCoords[i][0], theCoords[i][1], theCoords[i][2]);
        aPoles(i+1) = gp_Pnt (aP * aScale + aShift);
    }
    for (i=1; i <= nPoles+1; i++)
        aKnots(i) = Standard_Real(i-1);
    aMults.Init(1);

    return new Geom_BSplineCurve (aPoles, aKnots, aMults, 3, Standard_True);
}
예제 #17
0
cHomogFormelle::cHomogFormelle
(
     const cElHomographie & anHomog,
     cSetEqFormelles &         aSet,
     eModeContrHom                   aModeContr
)  :
     cElemEqFormelle(aSet,false),
     mHomInit     (anHomog),
     mCurHom      (anHomog),
     mCX          (mCurHom.HX(),aSet,false),
     mCY          (mCurHom.HY(),aSet,false),
     mCZ          (mCurHom.HZ(),aSet,true),
     mModeContr   (aModeContr),
     mHomFTol     (cContrainteEQF::theContrStricte)
{
   CloseEEF();

   for (int aK=0 ; aK<0 ; aK++)
   {
       cElComposHomographie aHX = mHomInit.HX();
       cElComposHomographie aHY = mHomInit.HY();
       cElComposHomographie aHZ = mHomInit.HZ();

        Pt2dr aP(NRrandom3()*100,NRrandom3()*100);
        Pt2dr aQ =  mHomInit.Direct(aP);

        Pt2dr aR = InvHom(
                         aHX.CoeffX(), aHX.CoeffY(), aHX.Coeff1(),
                         aHY.CoeffX(), aHY.CoeffY(), aHY.Coeff1(),
                         aHZ.CoeffX(), aHZ.CoeffY(),
                         aQ.x,aQ.y
                   );
        double aDist =  euclid(aP,aR);
        std::cout << "TESINV HOM " << aP << aR << aDist  << " B=" <<  aHX.CoeffY() << "\n";
        ELISE_ASSERT(aDist<1e-5,"TESINV HOM ");
   }

}
예제 #18
0
//-----------------------------------------------------------------------------
// Purpose: Export the specified bits of the maya scene into the specified file
// Input  : mArgDatabase	The command line arguments as passed
// Output : MS::kSuccess if ok, MS::kFailure otherwise
//-----------------------------------------------------------------------------
MStatus CVstSmdIOCmd::DoImport(
	const MArgDatabase &mArgDatabase )
{
	MString optFilename;
	if ( mArgDatabase.getFlagArgument( kOptFilename, 0, optFilename ) != MS::kSuccess || optFilename.length() == 0 )
	{
		MGlobal::displayError( "No filename specified for import" );
		return MS::kFailure;
	}

	MString optGame;
	if ( mArgDatabase.isFlagSet( kOptGame ) )
	{
		mArgDatabase.getFlagArgument( kOptGame, 0, optGame );
	}

	MString optTextureArchive;
	if ( mArgDatabase.isFlagSet( kOptTextureArchive ) )
	{
		mArgDatabase.getFlagArgument( kOptTextureArchive, 0, optTextureArchive );
	}

	CQcData qcData;
	char fullPath[ MAX_PATH ];
	if ( !_fullpath( fullPath, optFilename.asChar(), sizeof( fullPath ) ) )
	{
		strncpy( fullPath, optFilename.asChar(), sizeof( fullPath ) );
	}
	qcData.GetQcData( fullPath );

	if ( mArgDatabase.isFlagSet( kOptUpAxis ) )
	{
		MString upAxis;
		mArgDatabase.getFlagArgument( kOptUpAxis, 0, upAxis );
		switch ( *upAxis.asChar() )
		{
		case 'x':
		case 'X':
			qcData.m_upAxis = 0;
			break;
		case 'y':
		case 'Y':
			qcData.m_upAxis = 1;
			break;
		case 'z':
		case 'Z':
		default:
			qcData.m_upAxis = 2;
			break;
		}
	}

	CSmdImport smdImport( optGame.asChar(), optTextureArchive.asChar() );
	if ( mArgDatabase.isFlagSet( kOptImportSkeleton ) && !mArgDatabase.isFlagSet( kOptVmf ) )
	{
		mArgDatabase.getFlagArgument( kOptImportSkeleton, 0, smdImport.m_optImportSkeleton );
	}
	smdImport.SetNodeAddPrefix( GetNodeAddPrefix( mArgDatabase ) );
	smdImport.SetNodeDelPrefix( GetNodeDelPrefix( mArgDatabase ) );

	if ( mArgDatabase.isFlagSet( kOptImportType ) )
	{
		MString optImportType;
		if ( mArgDatabase.getFlagArgument( kOptImportType, 0, optImportType ) && (
			*optImportType.asChar() == 'a' || *optImportType.asChar() == 'A' ||
			*optImportType.asChar() == 's' || *optImportType.asChar() == 'S' ) )
		{
			MSelectionList mSelectionList;
			mArgDatabase.getObjects( mSelectionList );
			MDagPath rootDagPath;
			if ( mSelectionList.length() && mSelectionList.getDagPath( 0, rootDagPath ) )
			{
				return smdImport.ImportAnimation( optFilename.asChar(), rootDagPath, qcData, m_undo );
			}
			else
			{
				merr << "Cannot import animation without the root of the skeleton is selected or specified" << std::endl;
				return MS::kFailure;
			}
		}
	}

	MTransformationMatrix topLevel;

	if ( mArgDatabase.isFlagSet( kOptOrigin ) )
	{
		MVector o;
		mArgDatabase.getFlagArgument( kOptOrigin, 0, o.x );
		mArgDatabase.getFlagArgument( kOptOrigin, 1, o.y );
		mArgDatabase.getFlagArgument( kOptOrigin, 2, o.z );

		topLevel.setTranslation( o, MSpace::kObject );
	}

	if ( mArgDatabase.isFlagSet( kOptAngles ) )
	{
		MVector a;
		if ( mArgDatabase.isFlagSet( kOptVmf ) )
		{
			// The angles are specified in Yaw Pitch Roll order ( YZX )
			// but they're still an XYZ rotation
			mArgDatabase.getFlagArgument( kOptAngles, 0, a.y );
			mArgDatabase.getFlagArgument( kOptAngles, 1, a.z );
			mArgDatabase.getFlagArgument( kOptAngles, 2, a.x );
		}
		else
		{
			mArgDatabase.getFlagArgument( kOptAngles, 0, a.x );
			mArgDatabase.getFlagArgument( kOptAngles, 1, a.y );
			mArgDatabase.getFlagArgument( kOptAngles, 2, a.z );
		}

		const MEulerRotation e( a.x / 180.0 * M_PI, a.y / 180.0 * M_PI, a.z / 180.0 * M_PI, MEulerRotation::kXYZ );
		topLevel.rotateBy( e.asQuaternion(), MSpace::kObject );
	}

	if ( mArgDatabase.isFlagSet( kOptVmf ) )
	{
		if ( qcData.m_upAxis == 1U )
		{
			topLevel.rotateBy( MEulerRotation( 90.0 / 180.0 * M_PI, 0.0, 90.0 / 180.0 * M_PI ).asQuaternion(), MSpace::kObject );
		}
		else
		{
			topLevel.rotateBy( MEulerRotation( 0.0, 0.0, 90.0 / 180.0 * M_PI ).asQuaternion(), MSpace::kObject );
		}
	}
	else
	{
		switch ( qcData.m_upAxis )
		{
		case 0U:	// X Up
			if ( MGlobal::isYAxisUp() )
			{
				topLevel.rotateBy( MEulerRotation( -M_PI / 2.0, M_PI / 2.0, 0.0 ).asQuaternion(), MSpace::kObject );
			}
			else
			{
				topLevel.rotateBy( MEulerRotation( 0.0, M_PI / 2.0, 0.0 ).asQuaternion(), MSpace::kObject );
			}
			break;
		case 1U:	// Y Up
			if ( MGlobal::isZAxisUp() )
			{
				topLevel.rotateBy( MEulerRotation( M_PI / 2.0, 0.0, 0.0 ).asQuaternion(), MSpace::kObject );
			}
			break;
		default:
		case 2U:	// Z Up
			if ( MGlobal::isYAxisUp() )
			{
				topLevel.rotateBy( MEulerRotation( -M_PI / 2.0, 0.0, 0.0 ).asQuaternion(), MSpace::kObject );
			}
			break;
		}
	}

	MDagPath mDagPath( smdImport.DoIt( optFilename.asChar(), qcData, topLevel, m_undo ) );

	if ( mDagPath.isValid() && mDagPath.length() )
	{
		if ( mArgDatabase.isFlagSet( kOptVmf ) )
		{
			MFnNumericAttribute nFn;
			MObject aObj( nFn.create( "yUp", "yUp", MFnNumericData::kBoolean, false ) );
			MDagPath sDagPath( mDagPath );
			sDagPath.extendToShapeDirectlyBelow( 0 );
			m_undo.DagModifier().addAttribute( sDagPath.node(), aObj );
			m_undo.DagModifierDoIt();
			MPlug aP( sDagPath.node(), aObj );

			if ( qcData.m_upAxis == 1U )
			{
				aP.setValue( true );
			}
			else
			{
				aP.setValue( false );
			}
		}

		m_undo.SaveCurrentSelection();

		MGlobal::select( mDagPath, MObject::kNullObj, MGlobal::kReplaceList );
		setResult( mDagPath.partialPathName() );

		m_undo.SaveCurrentSelection();
		return MS::kSuccess;
	}

	m_undo.Undo();

	return MS::kFailure;
}
bool NameFilter(const std::string & aSubD,cInterfChantierNameManipulateur * aICNM,const cNameFilter & aFilter,const std::string & aName)
{
   std::string anEntete = aICNM->Dir()+ aSubD;
   std::string aFullName = anEntete + aName;

   int aSz = aFilter.SizeMinFile().Val();
   if (aSz>=0)
   {
      if (sizeofile(aFullName.c_str()) < aSz)
         return false;
   }

   if ((aFilter.Min().IsInit())&&(aFilter.Min().Val()>aName))
      return false;

   if ((aFilter.Max().IsInit())&&(aFilter.Max().Val()<aName))
      return false;


   const std::list<Pt2drSubst> & aLFoc = aFilter.FocMm();
   if (! aLFoc.empty())
   {
      
      if (!IsInIntervalle(aLFoc,GetFocalMmDefined(aFullName),true))
      {
            return false;
      }
   }
   


   for 
   (
        std::list<cKeyExistingFile>::const_iterator itKEF=aFilter.KeyExistingFile().begin();
        itKEF!=aFilter.KeyExistingFile().end();
        itKEF++
   )
   {
       bool OKGlob = itKEF->RequireForAll();
       for 
       (
            std::list<std::string>::const_iterator itKA=itKEF->KeyAssoc().begin();
            itKA!=itKEF->KeyAssoc().end();
            itKA++
       )
       {
          std::string aNameF = anEntete + aICNM->Assoc1To1(*itKA,aName,true);
          bool fExists = ELISE_fp::exist_file(aNameF);
// std::cout << "KEY-NF " << aNameF << "\n";
          bool Ok = itKEF->RequireExist() ? fExists : (!fExists);
          if (itKEF->RequireForAll())
             OKGlob = OKGlob && Ok;
          else
             OKGlob = OKGlob || Ok;
       }
   //std::cout << "KEY-NF " << aName << " " << OKGlob << "\n";
       if (!OKGlob) 
          return false;
   }


   if (aFilter.KeyLocalisation().IsInit())
   {
       const cFilterLocalisation & aKLoc = aFilter.KeyLocalisation().Val();
       std::string aNameCam = anEntete + aICNM->Assoc1To1(aKLoc.KeyAssocOrient(),aName,true);
       ElCamera * aCam = Cam_Gen_From_File(aNameCam,"OrientationConique",aICNM);
       Im2D_Bits<1> * aMasq = GetImRemanenteFromFile<Im2D_Bits<1> > (anEntete+ aKLoc.NameMasq());

       TIm2DBits<1> TM(*aMasq);

       cFileOriMnt * anOri = RemanentStdGetObjFromFile<cFileOriMnt>
                             (
                                anEntete+aKLoc.NameMTDMasq(),
                                StdGetFileXMLSpec("ParamChantierPhotogram.xml"),
                                "FileOriMnt",
                                "FileOriMnt"
                             );
       // std::cout << "ADR MASQ " << aMasq << " " << anOri << "\n";
        Pt3dr aPMnt = FromMnt(*anOri,aCam->OrigineProf());
        Pt2di aP(round_ni(aPMnt.x),round_ni(aPMnt.y));
        return ( TM.get(aP,0)==0 );
   }
   
   return true;
}
예제 #20
0
//=======================================================================
//function : Execute
//purpose  :
//======================================================================= 
Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const
{
  if (Label().IsNull()) return 0;
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  GEOMImpl_IScale aCI (aFunction);
  Standard_Integer aType = aFunction->GetType();

  TopoDS_Shape aShape;

  if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) {
    Handle(GEOM_Function) aRefShape = aCI.GetShape();
    TopoDS_Shape aShapeBase = aRefShape->GetValue();
    if (aShapeBase.IsNull()) return 0;

    gp_Pnt aP (0,0,0);
    Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
    if (!aRefPoint.IsNull()) {
      TopoDS_Shape aShapePnt = aRefPoint->GetValue();
      if (aShapePnt.IsNull()) return 0;
      if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0;
      aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
    }

    // Bug 6839: Check for standalone (not included in faces) degenerated edges
    TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
    TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap);
    Standard_Integer i, nbE = aEFMap.Extent();
    for (i = 1; i <= nbE; i++) {
      TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
      if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
        const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
        if (aFaces.IsEmpty())
          Standard_ConstructionError::Raise
            ("Scaling aborted : cannot scale standalone degenerated edge");
      }
    }

    // Perform Scaling
    gp_Trsf aTrsf;
    aTrsf.SetScale(aP, aCI.GetFactor());
    BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
	aShape = aBRepTrsf.Shape();
  }
  else if (aType == SCALE_SHAPE_AFFINE || aType == SCALE_SHAPE_AFFINE_COPY) {
	Handle(GEOM_Function) aRefShape = aCI.GetShape();
	Handle(GEOM_Function) aRefVector = aCI.GetVector();
	TopoDS_Shape aShapeBase = aRefShape->GetValue();
	TopoDS_Shape aShapeVector  = aRefVector->GetValue();
	if (aShapeBase.IsNull() || aShapeVector.IsNull()) return 0;
	if (aShapeVector.ShapeType() != TopAbs_EDGE) return 0;
	TopoDS_Edge anEdgeVector = TopoDS::Edge(aShapeVector);

	// Bug 6839: Check for standalone (not included in faces) degenerated edges
	TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
	TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap);
	Standard_Integer i, nbE = aEFMap.Extent();
	for (i = 1; i <= nbE; i++) {
	  TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
	  if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
		const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
		if (aFaces.IsEmpty())
		  Standard_ConstructionError::Raise
			("Scaling aborted : cannot scale standalone degenerated edge");
	  }
	}

	//Get axis
	gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdgeVector));
	gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdgeVector));
    gp_Dir aDir(gp_Vec(aP1, aP2));
	gp_Ax2 anAx2(aP1, aDir);

	// Perform Scaling
	gp_GTrsf aGTrsf;
	aGTrsf.SetAffinity(anAx2, aCI.GetFactor());
	BRepBuilderAPI_GTransform aBRepGTrsf(aShapeBase, aGTrsf, Standard_False);
	aShape = aBRepGTrsf.Shape();
  }
  else if (aType == SCALE_SHAPE_AXES || aType == SCALE_SHAPE_AXES_COPY) {
	Handle(GEOM_Function) aRefShape = aCI.GetShape();
    TopoDS_Shape aShapeBase = aRefShape->GetValue();
    if (aShapeBase.IsNull()) return 0;

    bool isP = false;
    gp_Pnt aP (0,0,0);
    Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
    if (!aRefPoint.IsNull()) {
      TopoDS_Shape aShapePnt = aRefPoint->GetValue();
      if (aShapePnt.IsNull()) return 0;
      if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0;
      aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
      isP = true;
    }

    // Bug 6839: Check for standalone (not included in faces) degenerated edges
    TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
    TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap);
    Standard_Integer i, nbE = aEFMap.Extent();
    for (i = 1; i <= nbE; i++) {
      TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
      if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
        const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
        if (aFaces.IsEmpty())
          Standard_ConstructionError::Raise
            ("Scaling aborted : cannot scale standalone degenerated edge");
      }
    }

    // Perform Scaling
    gp_GTrsf aGTrsf;
    gp_Mat rot (aCI.GetFactorX(), 0, 0,
                0, aCI.GetFactorY(), 0,
                0, 0, aCI.GetFactorZ());
    aGTrsf.SetVectorialPart(rot);

    if (isP) {
      gp_Pnt anO (0,0,0);
      if (anO.Distance(aP) > Precision::Confusion()) {
        gp_GTrsf aGTrsfP0;
        aGTrsfP0.SetTranslationPart(anO.XYZ() - aP.XYZ());
        gp_GTrsf aGTrsf0P;
        aGTrsf0P.SetTranslationPart(aP.XYZ());
        //aGTrsf = aGTrsf0P * aGTrsf * aGTrsfP0;
        aGTrsf = aGTrsf0P.Multiplied(aGTrsf);
        aGTrsf = aGTrsf.Multiplied(aGTrsfP0);
      }
    }

    BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False);
    if (!aBRepGTrsf.IsDone())
      Standard_ConstructionError::Raise("Scaling not done");
	aShape = aBRepGTrsf.Shape();
  } else {
  }

  if (aShape.IsNull()) return 0;

  // Check shape validity
  BRepCheck_Analyzer ana (aShape, false);
  if (!ana.IsValid()) {
    ShapeFix_ShapeTolerance aSFT;
    aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
    Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
    aSfs->SetPrecision(Precision::Confusion());
    aSfs->Perform();
    aShape = aSfs->Shape();

    ana.Init(aShape, Standard_False);
	if (!ana.IsValid()) {
	  Standard_CString anErrStr("Scaling aborted : non valid shape result");
	  #ifdef THROW_ON_INVALID_SH
		Standard_ConstructionError::Raise(anErrStr);
	  #else
	  MESSAGE(anErrStr);
	  //further processing can be performed here
		//...
	  //in case of failure of automatic treatment
	  //mark the corresponding GEOM_Object as problematic
	  TDF_Label aLabel = aFunction->GetOwnerEntry();
	  if (!aLabel.IsRoot()) {
		Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
		if (!aMainObj.IsNull())
		  aMainObj->SetDirty(Standard_True);
	  }
	  #endif
	}
  }

  aFunction->SetValue(aShape);

  log.SetTouched(Label()); 

  return 1;    
}
예제 #21
0
cElNuageLaser::cElNuageLaser
(
     const std::string & aNameFile,
     const char *  aNameOri,
     const char *  aNameGeomCible ,
     const char *  aNameGeomInit

)  :
   mVPts (),
   mQt   (0)
{
   std::string aNameBin = StdPrefix(aNameFile) + ".tif";
   if (! ELISE_fp::exist_file(aNameBin))
   {
       INT aNb = 3;
       FILE * aFP = ElFopen(aNameFile.c_str(),"r");
       ELISE_ASSERT(aFP!=0,"Cannot Open File for Laser Data");

       char Buf[10000];
       INT aCpt =0;
       while (aNb>=3)
       {
           aNb=0;
           char * got = fgets(Buf,10000,aFP);
           Pt3dr aP;
           if (got)
           {
              aNb = sscanf(Buf,"%lf %lf %lf",&aP.x,&aP.y,&aP.z);
           }
	   if (aNb>=3)
              mVPts.push_back(aP);
	   aCpt++;
       }

       INT aNbPts = (INT) mVPts.size();
       Im2D_REAL8 aImPts(aNbPts,3);
       REAL ** aData = aImPts.data();
       for (INT aK=0 ; aK<aNbPts ; aK++)
       {
	   Pt3dr aP = mVPts[aK];
           aData[0][aK] = aP.x;
           aData[1][aK] = aP.y;
           aData[2][aK] = aP.z;
       }

       Tiff_Im aFile
	       (
                  aNameBin.c_str(),
		  Pt2di(aNbPts,3),
		  GenIm::real8,
		  Tiff_Im::No_Compr,
		  Tiff_Im::BlackIsZero,
		     Tiff_Im::Empty_ARG
		  +  Arg_Tiff(Tiff_Im::ANoStrip())
               );
       ELISE_COPY(aImPts.all_pts(),aImPts.in(),aFile.out());
   }
   else
   {
       Tiff_Im aFile(aNameBin.c_str());
       Pt2di aSz = aFile.sz();
       Im2D_REAL8 aImPts(aSz.x,aSz.y);
       ELISE_COPY(aImPts.all_pts(),aFile.in(),aImPts.out());

       REAL ** aD = aImPts.data();
       mVPts.reserve(aSz.x);
       for (INT aK=0 ; aK<aSz.x ; aK++)
       {
           Pt3dr aP(aD[0][aK],aD[1][aK],aD[2][aK]);
           mVPts.push_back(aP);
       }
   }


   Ori3D_Std * aOri = 0;
   eModeConvGeom aMode = eConvId;

   if (aNameOri)
   {
       if (!strcmp(aNameGeomInit,"GeomCarto"))
       {
           if (!strcmp(aNameGeomCible,"GeomCarto"))
           {
               aMode = eConvId;
           }
           else if (!strcmp(aNameGeomCible,"GeomTerrain"))
           {
               aMode = eConvCarto2Terr;
           }
           else if (!strcmp(aNameGeomCible,"GeomTerIm1"))
           {
               aMode = eConvCarto2TerIm;
           }
           else
           {
              ELISE_ASSERT(false,"Bad GeomCible in cElNuageLaser::cElNuageLaser");
           }
       }
       else
       {
           ELISE_ASSERT(false,"Bad GeomInit in cElNuageLaser::cElNuageLaser");
       }
       if (aMode != eConvId)
          aOri = new Ori3D_Std (aNameOri) ;
   }

   for (INT aK=0 ; aK<INT( mVPts.size()); aK++)
   {
       Pt3dr aP = mVPts[aK];
       if (aOri)
       {
          if (aMode == eConvCarto2Terr)
             aP = aOri->carte_to_terr(aP);
          else if (aMode == eConvCarto2TerIm)
          {
             aP = aOri->carte_to_terr(aP);
             Pt2dr aP2 = aOri->to_photo(aP);
             aP.x = aP2.x;
             aP.y = aP2.y;
          }
          mVPts[aK] = aP;
       }

       REAL  aZ   =  aP.z;
       Pt2dr aP2 (aP.x,aP.y);
       if (aK==0)
       {
           mZMax = mZMin = aZ;
           mPInf =mPSup = aP2;
       }
       ElSetMin(mZMin,aZ);
       ElSetMax(mZMax,aZ);
       mPInf.SetInf(aP2);
       mPSup.SetSup(aP2);
   }
   delete aOri;
}
예제 #22
0
파일: b_0_48_2.cpp 프로젝트: jakexie/micmac
Im2D_INT2  TestCoxRoy
           (
                INT         aSzV,
                Im2D_U_INT1 imG1,
                Im2D_U_INT1 imG2,
                Pt2di       aP0,
                Pt2di       aP1,
                INT         aParMin,
                INT         aParMax
           )
{
   ElTimer  aRoyTimer;
   TheP0 = aP0;
   Pt2di aSz = aP1 -aP0;
   Im2D_INT2  aRes (aSz.x,aSz.y);

   TheCorr = new EliseCorrel2D
                 (
                     imG1.in(0),
                     imG2.in(0),
                     imG1.sz(),
                     aSzV,
                     false,
                     -1,
		     true,
		     true
                 );

   Im2D_INT2 aIZMin(aSz.x,aSz.y,(INT2)(aParMin));
   Im2D_INT2 aIZMax(aSz.x,aSz.y,(INT2)(aParMax));

   cInterfaceCoxRoyAlgo * TheCRA = cInterfaceCoxRoyAlgo::NewOne
                (
                      aSz.x,
                      aSz.y,
                      aIZMin.data(),
                      aIZMax.data(),
                      false,
                      false
                );
    InitCostCoxRoy(*TheCRA);





   INT MpdFlow=0;
   if (false)
   {
      cInterfaceCoxAlgo * pSCA =     cInterfaceCoxAlgo::StdNewOne
		                     (
			                 aSz,
			                 0,
			                 aParMax-aParMin,
			                 2,
			                 false
			              );
      for (INT anX=aP0.x ; anX<aP1.x ; anX++)
          for (INT anY=aP0.y ; anY<aP1.y ; anY++)
              for (INT aZ=0 ; aZ<(aParMax-aParMin) ; aZ++)
	      {
		  Pt2di aP(anX,anY);
                  REAL aC = TheCorr->Correl(aP,aP+Pt2di(aZ+aParMin,0));
		  pSCA->SetCost(Pt3di(anX-aP0.x,anY-aP0.y,aZ),MakeCapa(1-aC));
	      }
      MpdFlow =  pSCA->PccMaxFlow();
      Im2D_INT2 aSol = pSCA->Sol(0);   
      Video_Win aW =  Video_Win::WStd(aSol.sz(),1.0);
      aW.set_title("MPD");
      INT aV0,aV1;
      ELISE_COPY(aSol.all_pts(),aSol.in(),VMin(aV0)|VMax(aV1));
      ELISE_COPY(aSol.all_pts(),(aSol.in()-aV0)*(255.0/(aV1-aV0)),aW.ogray());
      delete pSCA;
   }
   cout << "MPD Flow " << MpdFlow << "\n";





    aRoyTimer.reinit();
    INT aFl1 = TheCRA->TopMaxFlowStd(aRes.data());
    cout << "Roy Time = " << aRoyTimer.uval() << "\n";


    ELISE_COPY(aRes.all_pts(),aRes.in(),aRes.out());


    {
        INT aV0,aV1;
        ELISE_COPY(aRes.all_pts(),aRes.in(),VMin(aV0)|VMax(aV1));
        cout << "Cox Roy Interv = " << aV0  << " --- " << aV1 << "\n";
    }

    delete TheCRA;

    INT ecartPlani = 2;
    INT ecartAlti = 5;

    ELISE_COPY
    (
          aIZMin.all_pts(),
          rect_min(aRes.in(aParMax),ecartPlani) -ecartAlti,
          aIZMin.out()
    );
    ELISE_COPY
    (
          aIZMax.all_pts(),
          rect_max(aRes.in(aParMin),ecartPlani) +ecartAlti,
          aIZMax.out()
    );


   Im2D_INT2  aRes2 (aSz.x,aSz.y);
   TheCRA = cInterfaceCoxRoyAlgo::NewOne
                (
                      aSz.x,
                      aSz.y,
                      aIZMin.data(),
                      aIZMax.data(),
                      false,
                      false
                );
    InitCostCoxRoy(*TheCRA);

    aRoyTimer.reinit();
    INT aFl2 = TheCRA->TopMaxFlowStd(aRes2.data());
    cout << "Roy Time 2 = " << aRoyTimer.uval() << "\n";

    INT aNbDif;
    ELISE_COPY
    (
         aRes.all_pts(), 
         aRes.in()!=aRes2.in(),
         sigma(aNbDif)
    );
    BENCH_ASSERT(aNbDif==0);

    cout << "FLOWS : " << aFl1 << " " << aFl2 << "\n";
    cout << "Nb Dif = " << aNbDif << "\n";




    delete TheCorr;
    return aRes;
}
예제 #23
0
inline bool Quick_ZHay<Tprec, Dim>::calcCoefficients3D () {
    prec_t dyz = dy * dz, dyz_dx = Gamma * dyz / dx;
    prec_t dxz = dx * dz, dxz_dy = Gamma * dxz / dy;
    prec_t dxy = dx * dy, dxy_dz = Gamma * dxy / dz;
    prec_t dxyz_dt = dx * dy * dz / dt;
    prec_t ce, cem, cep, cw, cwm, cwp, CE, CW;
    prec_t cn, cnm, cnp, cs, csm, csp, CN, CS;
    prec_t cf, cfm, cfp, cb, cbm, cbp, CF, CB;
    aE = 0.0; aW = 0.0; aN = 0.0; aS = 0.0; aF = 0.0; aB = 0.0; aP = 0.0; 
    sp = 0.0;
    
    for (int k = bk; k <= ek; ++k)
      for (int i =  bi; i <= ei; ++i)
	for (int j = bj; j <= ej; ++j)
	  {
	    CE = ce = ( u(i  ,j  ,k) + u(i  ,j+1,k  ) ) * 0.5 * dyz;
	    CW = cw = ( u(i-1,j  ,k) + u(i-1,j+1,k  ) ) * 0.5 * dyz;
	    CN = cn = ( v(i  ,j  ,k) + v(i+1,j  ,k  ) ) * 0.5 * dxz;
	    CS = cs = ( v(i  ,j-1,k) + v(i+1,j-1,k  ) ) * 0.5 * dxz;
	    CF = cf = ( w(i  ,j  ,k) + w(i  ,j  ,k+1) ) * 0.5 * dxy;
	    CB = cb = ( w(i  ,j  ,k) + w(i  ,j  ,k-1) ) * 0.5 * dxy;
	    cem = cep = 0.0;
	    cwm = cwp = 0.0;
	    cnm = cnp = 0.0;
	    csm = csp = 0.0;
	    cfm = cfp = 0.0;
	    cbm = cbp = 0.0;

	    // QUICK as presented in Hayase et al.
// ---- X
	    if ( ce > 0 ) { 
	      CE = 0;
	      if (i == bi) {
		cep = ce * (phi_0(i+1,j,k) - phi_0(i-1,j,k)) / 3.0;
	      } else {
		cep = ce * 0.125 * (-phi_0(i-1,j,k) - 2*phi_0(i,j,k) + 3*phi_0(i+1,j,k));
	      }
	    } else {
	      // The case i == ei is taken in to account in applyBoundaryConditions3D.
	      if (i == ei-1) {
		cem = ce * (phi_0(i+2,j,k) - phi_0(i,j,k)) / 3.0;
	      } else if (i < ei-1) {
		cem = ce * 0.125 * (-phi_0(i+2,j,k) - 2*phi_0(i+1,j,k) + 3*phi_0(i,j,k));
	      }
	    }
	    
	    if ( cw > 0 ) { 
	      // The case i == bi is taken in to account in applyBoundaryConditions3D.
	      if (i == bi+1) {
		cwp = cw * (phi_0(i,j,k) - phi_0(i-2,j,k)) / 3.0;
	      } else if (i > bi+1) {
		cwp = cw * 0.125 * (-phi_0(i-2,j,k) - 2*phi_0(i-1,j,k) + 3*phi_0(i,j,k));
	      }
	    } else {
	      CW = 0;
	      if (i == ei) {
		cwm = cw * (phi_0(i-1,j,k) - phi_0(i+1,j,k)) / 3.0;
	      } else {
		cwm = cw * 0.125 * (-phi_0(i+1,j,k) - 2*phi_0(i,j,k) + 3*phi_0(i-1,j,k));
	      }
	    }

// ---- Y
	    if ( cn > 0 ) { 
	      CN = 0;
	      if (j == bj) {
		cnp = cn * (phi_0(i,j+1,k) - phi_0(i,j-1,k)) / 3.0;
	      } else {
		cnp = cn * 0.125 * (-phi_0(i,j-1,k) - 2*phi_0(i,j,k) + 3*phi_0(i,j+1,k));
	      }
	    } else {
	      if (j == ej-1) {
		cnm = cn * (phi_0(i,j+2,k) - phi_0(i,j,k)) / 3.0;
	      } else if (i < ei-1) {
		cnm = cn * 0.125 * (-phi_0(i,j+2,k) - 2*phi_0(i,j+1,k) + 3*phi_0(i,j,k));
	      }
	    }
	    
	    if ( cs > 0 ) { 
	      if (j == bj+1) {
		csp = cs * (phi_0(i,j,k) - phi_0(i,j-2,k)) / 3.0;
	      } else if (j > bj+1) {
		csp = cs * 0.125 * (-phi_0(i,j-2,k) - 2*phi_0(i,j-1,k) + 3*phi_0(i,j,k));
	      }
	    } else {
	      CS = 0;
	      if (j == ej) {
		csm = cs * (phi_0(i,j-1,k) - phi_0(i,j+1,k)) / 3.0;
	      } else {
		csm = cs * 0.125 * (-phi_0(i,j+1,k) - 2*phi_0(i,j,k) + 3*phi_0(i,j-1,k));
	      }
	    }

// ---- Z
	    if ( cf > 0 ) { 
	      CF = 0;
	      cfp = cf * 0.125 * (-phi_0(i,j,k-1) - 2*phi_0(i,j,k) + 3*phi_0(i,j,k+1));
	    } else {
	      if (k == ek) {
		cfm = cf * 0.125 * (-5*phi_0(i,j,k+1) + 6*phi_0(i,j,k) - phi_0(i,j,k-1));
	      } else {
		cfm = cf * 0.125 * (-phi_0(i,j,k+2) - 2*phi_0(i,j,k+1) + 3*phi_0(i,j,k));
	      }
	    }
	    
	    if ( cb > 0 ) { 
	      if (k == bk) {
		cbp = cb * 0.125 * (-5*phi_0(i,j,k-1) + 6*phi_0(i,j,k) - phi_0(i,j,k+1));
	      } else {
		cbp = cb * 0.125 * (-phi_0(i,j,k-2) - 2*phi_0(i,j,k-1) + 3*phi_0(i,j,k));
	      }
	    } else {
	      CB = 0;
	      cbm = cb * 0.125 * (-phi_0(i,j,k+1) - 2*phi_0(i,j,k) + 3*phi_0(i,k,k-1));
	    }
	    
	    aE (i,j,k) = dyz_dx - CE;
	    aW (i,j,k) = dyz_dx + CW;
	    aN (i,j,k) = dxz_dy - CN;
	    aS (i,j,k) = dxz_dy + CS;
	    aF (i,j,k) = dxy_dz - CF;
	    aB (i,j,k) = dxy_dz + CB;
	    aP (i,j,k) = aE (i,j,k) + aW (i,j,k) + aN (i,j,k) + aS (i,j,k) 
	      + aF (i,j,k) + aB (i,j,k) + dxyz_dt
	      + (ce - cw) + (cn - cs) + (cf - cb);

	    sp(i,j,k) = w(i,j,k) * dxyz_dt - 
	      ( p(i,j,k+1)- p(i,j,k) ) * dxy
	      - (cep + cem - cwp - cwm + 
		 cnp + cnm - csp - csm +
		 cfp + cfm - cbp - cbm);    
	  }    
    calc_dw_3D();
    applyBoundaryConditions3D();
    return 0;     
}
예제 #24
0
파일: CDS_YHay.cpp 프로젝트: jesushl/TUNAM
inline bool CDS_YHay<Tprec, Dim>::calcCoefficients3D () 
{
    prec_t dyz = dy * dz, dyz_dx = Gamma * dyz / dx;
    prec_t dxz = dx * dz, dxz_dy = Gamma * dxz / dy;
    prec_t dxy = dx * dy, dxy_dz = Gamma * dxy / dz;
    prec_t dxyz_dt = dx * dy * dz / dt;
    prec_t ce, cep, cem, cw, cwp, cwm, CE, CW;
    prec_t cn, cnp, cnm, cs, csp, csm, CN, CS;
    prec_t cf, cfp, cfm, cb, cbp, cbm, CF, CB;
    prec_t RaGaVol = Rayleigh * Gamma * 0.5 * dx * dy * dz;
    aE = 0.0; aW = 0.0; aN = 0.0; aS = 0.0; aF = 0.0; aB = 0.0; aP = 0.0; 
    sp = 0.0;

    for (int k = bk; k <= ek; ++k)
      for (int i =  bi; i <= ei; ++i)
	for (int j = bj; j <= ej; ++j)
	  {
	    CE = ce = ( u(i  ,j,k) + u(i  ,j+1,k  ) ) * 0.5 * dyz;
	    CW = cw = ( u(i-1,j,k) + u(i-1,j+1,k  ) ) * 0.5 * dyz;
	    CN = cn = ( v(i  ,j,k) + v(i  ,j+1,k  ) ) * 0.5 * dxz;
	    CS = cs = ( v(i  ,j,k) + v(i  ,j-1,k  ) ) * 0.5 * dxz;
	    CF = cf = ( w(i  ,j,k) + w(i  ,j  ,k+1) ) * 0.5 * dxy;
	    CB = cb = ( w(i-1,j,k) + w(i-1,j  ,k+1) ) * 0.5 * dxy;
	    cem = cep = 0;
	    cwm = cwp = 0;
	    cnm = cnp = 0;
	    csm = csp = 0;
	    cfm = cfp = 0;
	    cbm = cbp = 0;

	    if ( ce > 0 ){
	      CE = 0;
	      cep = ce * 0.5 * (-phi_0(i,j,k) + phi_0(i+1,j,k));
	    } else {
	      cem = ce * 0.5 * (phi_0(i,j,k) - phi_0(i+1,j,k));
	    } 
	  
	    if ( cw > 0 ){
	      cwp = cw * 0.5 * (-phi_0(i-1,j,k) + phi_0(i,j,k));
	    } else {
	      CW = 0.0;
	      cwm = cw * 0.5 * (phi_0(i-1,j,k) - phi_0(i,j,k));
	    } 	    
	    
	    if ( cn > 0 ){
	      CN = 0;
	      cnp = cn * 0.5 * (-phi_0(i,j,k) + phi_0(i,j+1,k));
	    } else {
	      cnm = cn * 0.5 * (phi_0(i,j,k) - phi_0(i,j+1,k));
	    } 
	    
	    if ( cs > 0 ){
	      csp = cs * 0.5 * (-phi_0(i,j-1,k) + phi_0(i,j,k));
	    } else {
	      CS = 0.0;
	      csm = cs * 0.5 * (phi_0(i,j-1,k) - phi_0(i,j,k));
	    } 

	    if ( cf > 0 ){
	      CF = 0;
	      cfp = cf * 0.5 * (-phi_0(i,j,k) + phi_0(i,j,k+1));
	    } else {
	      cfm = cf * 0.5 * (phi_0(i,j,k) - phi_0(i,j,k+1));
	    } 
	    
	    if ( cb > 0 ){
	      cbp = cb * 0.5 * (-phi_0(i,j,k-1) + phi_0(i,j,k));
	    } else {
	      CB = 0.0;
	      cbm = cb * 0.5 * (phi_0(i,j,k-1) - phi_0(i,j,k));
	    } 
	
	    aE (i,j,k) = dyz_dx - CE;
	    aW (i,j,k) = dyz_dx + CW;
	    aN (i,j,k) = dxz_dy - CN;
	    aS (i,j,k) = dxz_dy + CS;
	    aF (i,j,k) = dxy_dz - CF;
	    aB (i,j,k) = dxy_dz + CB;
	    aP (i,j,k) = aE (i,j,k) + aW (i,j,k) + aN (i,j,k) + aS (i,j,k)
	      + aF (i,j,k) + aB (i,j,k) + dxyz_dt
	      + (ce - cw) + (cn - cs) + (cn - cs);
	    sp (i,j,k) += v(i,j,k) * dxyz_dt - 
	      ( p(i,j+1,k) - p(i,j,k) ) * dxz +
	      RaGaVol * ( T(i,j,k) + T(i,j+1,k) )
	      - (cep + cem - cwp - cwm + cnp + cnm - csp - csm + cfp + cfm - cbp - cbm); 
	  }    
    calc_dv_3D();
    applyBoundaryConditions3D();
    return 0;
}
예제 #25
0
void cParamIntrinsequeFormel::UpdateCamGrid( double aTol)
{
   if (UseAFocal()  &&  (! AFocalAcceptNoDist))
      return;
   bool aLastFiged = mFiged;
   mFiged = AllParamIsFiged() ;
   // Si rien n'a change
   if (aLastFiged == mFiged)
      return;

   // On passe de fige a mobile, donc plus de grille
   if (aLastFiged)
   {
        delete mCamGrid;
        mCamGrid =0;
        return;
   }

   //   On se fige
   //
 
      CamStenope * aCS = CurPIF();

      Pt2di aRab(20,20);
      Pt2di aStep(10,10);
      double aRabR = 0;
      Pt2di aSz = aCS->Sz();

      double aR = euclid(aSz)/2.0;
      if (aCS->HasRayonUtile())
         aR = aCS->RayonUtile();

// std::cout << "iuytml RAY = " << aR << " SZR " <<  euclid(aSz)/2.0 << "\n";

      mCamGrid = cCamStenopeGrid::Alloc(aR+aRabR,*aCS,Pt2dr(aStep),true,true);
      if (mCamGrid)
      {

          mRayonGrid = 1e20;

// std::cout << "iuytml END CGID  \n";

           double aEcMax =0;
           for (int aKx=100 ; aKx< aCS->Sz().x ; aKx += 200)
           {
               for (int aKy=100 ; aKy< aCS->Sz().y ; aKy += 200)
               {
                   Pt2dr aP(aKx,aKy);
                   // std::cout << "IZU " << mCamGrid->IsInZoneUtile(aP) << " " << aP << "\n";
                   if (mCamGrid->IsInZoneUtile(aP))
                   {
                      // UVGCC4.6 double aEps=1e-5;

                       Pt3dr aRay = aCS->F2toDirRayonL3(aP);
                       // UVGCC4.6 Pt3dr aRayG = mCamGrid->F2toDirRayonL3(aP);


                       // UVGCC4.6 Pt3dr  aRayX = aRay + Pt3dr(aEps,0,0);
                       // UVGCC4.6 Pt3dr  aRayY = aRay + Pt3dr(0,aEps,0);

                       Pt2dr aP1 = aCS->L3toF2(aRay);
                       Pt2dr aPG = mCamGrid->L3toF2(aRay);


                       // UVGCC4.6 Pt2dr aDx = (mCamGrid->L3toF2(aRayX)-aPG)/aEps;
                       // UVGCC4.6 Pt2dr aDy = (mCamGrid->L3toF2(aRayY)-aPG)/aEps;


                       Pt2dr aDGX,aDGY;
                       // UVGCC4.6 Pt2dr aPG2 = mCamGrid->L2toF2AndDer(Pt2dr(aRay.x,aRay.y),aDGX,aDGY);

                // std::cout << aPG << aDx << aDy << "\n";
                // std::cout <<  "    " << aPG2 << aDGX << aDGY << "\n";

                       double aDist = euclid(aP1,aPG);
                       if ( aDist >aTol)
                          mRayonGrid = ElMin(mRayonGrid,euclid(aP,aSz/2.0));
                       aEcMax = ElMax(aDist,aEcMax);
                    }
               }
           }
/*

        std::cout << "GetC ------------RTOl------------ " << mRayonGrid   << " -EcMax " << aEcMax << "\n"; 
         getchar();
*/

    }


}
예제 #26
0
int OCCEdge::createNURBS(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points,
                          DVec knots, DVec weights, IVec mult)
{
    try {
        Standard_Boolean periodic = false;
        
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
            periodic = true;
        }
        
        int nbControlPoints = points.size() + vertices;
        TColgp_Array1OfPnt  ctrlPoints(1, nbControlPoints);
        
        TColStd_Array1OfReal _knots(1, knots.size());
        TColStd_Array1OfReal _weights(1, weights.size());
        TColStd_Array1OfInteger  _mult(1, mult.size());
        
        for (unsigned i = 0; i < knots.size(); i++) {
            _knots.SetValue(i+1, knots[i]);
        }
        
        for (unsigned i = 0; i < weights.size(); i++) {
            _weights.SetValue(i+1, weights[i]);
        }
        
        int totKnots = 0;
        for (unsigned i = 0; i < mult.size(); i++) {
            _mult.SetValue(i+1, mult[i]);   
            totKnots += mult[i];
        }

        const int degree = totKnots - nbControlPoints - 1;

        int index = 1;
        
        if (!periodic) {
            ctrlPoints.SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));
        }
        
        for (unsigned i = 0; i < points.size(); i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints.SetValue(index++, aP);
        }
        
        if (!periodic) {
            ctrlPoints.SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z()));
        }
        
        Handle(Geom_BSplineCurve) NURBS = new Geom_BSplineCurve
        (ctrlPoints, _weights, _knots, _mult, degree, periodic);
        
        if (!periodic) {
            this->setShape(BRepBuilderAPI_MakeEdge(NURBS, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(NURBS));
        }
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create nurbs");
        }
        return 1;
    }
    return 0;
}
예제 #27
0
//TODO: range from edges, not center?
bool withinRange(Unit* a, int r, Unit* b)
{
    QPoint aP(a->x() + a->width()/2, a->y() + a->height()/2);
    QPoint bP(b->x() + b->width()/2, b->y() + b->height()/2);
    return (bP - aP).manhattanLength() <= r;
}