Пример #1
0
static __inline__ void build_area_table(const BBOX_TREE *bbox_tree,
	Uint32 a, Uint32  b, float *areas)
{
	VECTOR3 bmin, bmax, len;
	int i, j;

	VFill(bmin, BOUND_HUGE);
	VFill(bmax, -BOUND_HUGE);

	if (a < b)
	{
		for (i = a, j = 0; i <= b; i++, j++)
		{
			VMin(bmin, bmin, bbox_tree->items[i].bbox.bbmin);
			VMax(bmax, bmax, bbox_tree->items[i].bbox.bbmax);
			VSub(len, bmax, bmin);

			areas[j] = len[X] * len[Y] * len[Z];
		}
	}
	else
	{
		for (i = a, j = a-b; i >= (int)b; i--, j--)
		{
			VMin(bmin, bmin, bbox_tree->items[i].bbox.bbmin);
			VMax(bmax, bmax, bbox_tree->items[i].bbox.bbmax);
			VSub(len, bmax, bmin);

			areas[j] = len[X] * len[Y] * len[Z];
		}
	}
}
Пример #2
0
template <class Type,class TypeB> void bench_r2d_assoc
    (
          const OperAssocMixte & op,
          Type *,
          TypeB *,
          Pt2di sz,
          INT   x0,
          INT   x1
    )
{
    Im2D<Type,TypeB> I(sz.x,sz.y,(Type)0);
    Im2D_REAL8       R1(sz.x,sz.y,0.0);
    Im2D_REAL8       R2(sz.x,sz.y,0.0);
    Im2D_REAL8       R3(sz.x,sz.y,0.0);

    ELISE_COPY(I.all_pts(),255*frandr(),I.out());

    ELISE_COPY
    (
         I.all_pts(),
         linear_red(op,I.in(),x0,x1),
         R1.out()
    );

    TypeB vdef;
    op.set_neutre(vdef);
    ELISE_COPY
    (
         I.all_pts(),
         rect_red(op,I.in(vdef),Box2di(Pt2di(x0,0),Pt2di(x1,0))),
         R2.out()
    );

    ELISE_COPY
    (
         I.lmr_all_pts(Pt2di(1,0)),
         linear_red(op,I.in(),x0,x1),
         R3.out()
    );

    REAL d12,d23;
    ELISE_COPY 
    (
         R1.all_pts(),
         Virgule(
              Abs(R1.in()-R2.in()),
              Abs(R2.in()-R3.in())
         ),
         Virgule(VMax(d12),VMax(d23))
    );
    BENCH_ASSERT((d12<epsilon)&&(d23<epsilon));
}
Пример #3
0
void bench_r2d_shading()
{
    Pt2di sz(120,50);

    Im2D_REAL8       MNT(sz.x,sz.y,0.0);
    Im2D_REAL8       SHAD1(sz.x,sz.y,0.0);
    Im2D_REAL8       SHAD2(sz.x,sz.y,0.0);


    ELISE_COPY(MNT.all_pts(),frandr(),MNT.out());

    ELISE_COPY
    (
        MNT.all_pts(),
        binary_shading(MNT.in(),1.0),
        SHAD1.out()
    );

    ELISE_COPY
    (
        MNT.lmr_all_pts(Pt2di(1,0)),
        binary_shading(MNT.in(),1.0),
        SHAD2.out()
    );

    REAL dif;

    ELISE_COPY (MNT.all_pts(),Abs(SHAD1.in()-SHAD2.in()),VMax(dif));
    BENCH_ASSERT(dif<epsilon);


    ELISE_COPY
    (
        MNT.all_pts(),
        gray_level_shading(MNT.in()),
        SHAD1.out()
    );

    ELISE_COPY
    (
        MNT.lmr_all_pts(Pt2di(1,0)),
        gray_level_shading(MNT.in()),
        SHAD2.out()
    );


    ELISE_COPY (MNT.all_pts(),Abs(SHAD1.in()-SHAD2.in()),VMax(dif));
    BENCH_ASSERT(dif<epsilon);
}
Пример #4
0
static __inline__ void calc_bbox_sub_nodes(BBOX_TREE* bbox_tree, Uint32 sub_node, Uint32 in_mask, AABBOX* bbox)
{
	Uint32 out_mask, result, idx;

	if (sub_node != NO_INDEX)
	{
		idx = bbox_tree->cur_intersect_type;
		result = check_aabb_in_frustum(bbox_tree->nodes[sub_node].bbox, bbox_tree->intersect[idx].frustum, in_mask, &out_mask);
		if (result == INSIDE)
		{
			VMin(bbox->bbmin, bbox->bbmin, bbox_tree->nodes[sub_node].bbox.bbmin);
			VMax(bbox->bbmax, bbox->bbmax, bbox_tree->nodes[sub_node].bbox.bbmax);
		}
		else
		{
			if (result == INTERSECT)
			{
				merge_dyn_items(bbox_tree, sub_node, out_mask, bbox);
				if (	(bbox_tree->nodes[sub_node].nodes[0] == NO_INDEX) &&
					(bbox_tree->nodes[sub_node].nodes[1] == NO_INDEX)) merge_items(bbox_tree, sub_node, out_mask, bbox);
				else
				{
					calc_bbox_sub_nodes(bbox_tree, bbox_tree->nodes[sub_node].nodes[0], out_mask, bbox);
					calc_bbox_sub_nodes(bbox_tree, bbox_tree->nodes[sub_node].nodes[1], out_mask, bbox);
				}
			}
		}
	}
}
Пример #5
0
static __inline__ void build_area_table(BBOX_TREE *bbox_tree, Uint32 a, Uint32  b, float *areas)
{
	int i, imin, dir;
	VECTOR3 bmin, bmax, len;

	if (a < b)
	{
		imin = a;
		dir =  1;
	}
	else
	{
		imin = b;
		dir = -1;
	}

	VFill(bmin, BOUND_HUGE);
	VFill(bmax, -BOUND_HUGE);

	for (i = a; i != (b + dir); i += dir)
	{
		VMin(bmin, bmin, bbox_tree->items[i].bbox.bbmin);
		VMax(bmax, bmax, bbox_tree->items[i].bbox.bbmax);
		VSub(len, bmax, bmin);

		areas[i - imin] = len[X] * len[Y] * len[Z];
	}
}
Пример #6
0
void bench_im_reech
     (
           Fonc_Num   Fonc,
           Pt2di      SzIm,
           Fonc_Num   reechantX,
           Fonc_Num   reechantY,
           INT        sz_grid,
           REAL       aMaxDif
    )
{
    Im2D_U_INT1 AnIm(SzIm.x,SzIm.y);

    ELISE_COPY(AnIm.all_pts(),Fonc,AnIm.out());
    REAL dif;

    ELISE_COPY
    (
        AnIm.interior(3),
        Abs
        (
             AnIm.ImGridReech (reechantX,reechantY,sz_grid,-100)
           - Fonc[Virgule(reechantX,reechantY)]
        ),
        VMax(dif)
    );

    BENCH_ASSERT(dif<aMaxDif);
}
Пример #7
0
static __inline__ void add_dynamic_item_to_node(BBOX_TREE *bbox_tree, Uint32 node, const AABBOX bbox, Uint32 ID, Uint32 type, Uint32 texture_id, Uint32 extra)
{	
	Uint32 index, size;

	if (node != NO_INDEX)
	{
		index = bbox_tree->nodes[node].dynamic_objects.index;
		size = bbox_tree->nodes[node].dynamic_objects.size;

		if (size <= index)
		{
			if (size < 4) size = 4;
			size *= 2;
			bbox_tree->nodes[node].dynamic_objects.items = (BBOX_ITEM*)realloc(bbox_tree->nodes[node].dynamic_objects.items, size*sizeof(BBOX_ITEM));
			bbox_tree->nodes[node].dynamic_objects.size = size;
		}

		bbox_tree->nodes[node].dynamic_objects.items[index].ID = ID;
		bbox_tree->nodes[node].dynamic_objects.items[index].extra = extra;
		bbox_tree->nodes[node].dynamic_objects.items[index].texture_id = texture_id;
		bbox_tree->nodes[node].dynamic_objects.items[index].type = type;
#ifdef CLUSTER_INSIDES
		bbox_tree->nodes[node].dynamic_objects.items[index].cluster = current_cluster;
#endif // CLUSTER_INSIDES
		VAssign(bbox_tree->nodes[node].dynamic_objects.items[index].bbox.bbmin, bbox.bbmin);
		VAssign(bbox_tree->nodes[node].dynamic_objects.items[index].bbox.bbmax, bbox.bbmax);
		bbox_tree->nodes[node].dynamic_objects.index = index + 1;
		VMin(bbox_tree->nodes[node].bbox.bbmin, bbox_tree->nodes[node].bbox.bbmin, bbox.bbmin);
		VMax(bbox_tree->nodes[node].bbox.bbmax, bbox_tree->nodes[node].bbox.bbmax, bbox.bbmax);
	}
}
Пример #8
0
static __inline__ void find_axis_and_bbox(const BBOX_TREE *bbox_tree,
	Uint32 first, Uint32 last, Uint32 *ret, AABBOX *bbox)
{
	Uint32 i, a1, a2, a3;
	VECTOR3 bmin, bmax;
	float d, e;

	VFill(bmin, BOUND_HUGE);
	VFill(bmax, -BOUND_HUGE);

	for (i = first; i < last; i++)
	{
		VMin(bmin, bmin, bbox_tree->items[i].bbox.bbmin);
		VMax(bmax, bmax, bbox_tree->items[i].bbox.bbmax);
	}

	VAssign(bbox->bbmin, bmin);
	VAssign(bbox->bbmax, bmax);

	a1 = 0;
	a2 = 1;
	a3 = 2;

	d = bmax[a1] - bmin[a1];
	e = bmax[a2] - bmin[a2];
	if (d < e)
	{
		i = a2;
		a2 = a1;
		a1 = i;
	}

	d = bmax[a1] - bmin[a1];
	e = bmax[a3] - bmin[a3];
	if (d < e)
	{
//		i = a2;
//		a2 = a1;
		i = a3;
		a3 = a1;
		a1 = i;
	}

	d = bmax[a2] - bmin[a2];
	e = bmax[a3] - bmin[a3];
	if (d < e)
	{
		i = a3;
		a3 = a2;
		a2 = i;
	}

	ret[0] = a1;
	ret[1] = a2;
	ret[2] = a3;
}
Пример #9
0
void ElImplemDequantifier::DoDequantif(Pt2di aSzIm,Fonc_Num f2Deq,bool aVerifI)
{

     SetSize(aSzIm);
     SetChamfer(Chamfer::d32);


     Symb_FNum aFC = Max(trans(Rconv(f2Deq),Pt2di(-1,-1)),eValOut+2);
     Symb_FNum aIFC = round_ni(aFC);
     double aDifI;
     ELISE_COPY
     (
          mImQuant.interior(1),
          Virgule(aIFC,Abs(aFC-aIFC)),
          // Max(trans(f2Deq,Pt2di(-1,-1)),eValOut+2),
          Virgule(mImQuant.out(),VMax(aDifI))
     );
     if (aVerifI)
     {
        ELISE_ASSERT(aDifI<1e-6,"Non int in ElImplemDequantifier::DoDequantif");
     }

     ELISE_COPY(mImQuant.border(1),eValOut, mImQuant.out());



     QuickSetDist(1);
   
     Symb_FNum  sM (mDistMoins.in()); 
     Symb_FNum  sP (mDistPlus.in()); 

/*
Pt2di P128(1565+2,1100+2);
Pt2di P126(1475+2,1085+2);

std::cout <<   "P128 : " 
          << int(mDistMoins.data()[P128.y][P128.x]) << " " 
          << int(mDistPlus.data()[P128.y][P128.x]) << "\n" ;
std::cout <<   "P126 : " 
          << int(mDistMoins.data()[P126.y][P126.x]) << " " 
          << int(mDistPlus.data()[P126.y][P126.x]) << "\n" ;


std::cout << "SZ IM " <<  aSzIm << "\n"; getchar();
*/


     ELISE_COPY
     (
         mImDeq.all_pts(),
         trans(mImQuant.in()+(sM/Rconv(sM+sP)-0.5),Pt2di(1,1)),
         mImDeq.out()
     );
}
Пример #10
0
template <class Type> void  Bench_PackB_IM<Type>::verif(Flux_Pts flx,INT def)
{
	INT dif;
	ELISE_COPY
	(
		flx,
 		Abs(im1.in(def)-pck.in(def)),
		VMax(dif)
	);
	BENCH_ASSERT(dif==0);
}
Пример #11
0
void dist_chamfer_cabl(Im2D<U_INT1,INT> I,INT v_max)
{
     Im2D<U_INT1,INT> I0(I.tx(),I.ty(),0);

     ELISE_COPY(I0.all_pts(),I.in(),I0.out());
     Chamfer::d32.im_dist(I);

     INT nb_dif;
     ELISE_COPY
     (
          I.all_pts(),
          I0.in()!=(I.in()!=0),
          sigma(nb_dif)
     );
     BENCH_ASSERT(nb_dif == 0);

     INT tx = I.tx();
     INT ty = I.ty();
     U_INT1 ** d = I.data();
     INT     vmax = I.vmax()-1;
     
     for (int x=1; x<tx-1 ; x++)
         for (int y=1; y<ty-1 ; y++)
         {
              
              INT v;
              if (d[y][x])
                 v  = std::min3 
                      (
                          std::min3(d[y+1][x-1]+3,d[y+1][x]+2,d[y+1][x+1]+3),
                          std::min3(d[y][x-1]+2,vmax,d[y][x+1]+2),
                          std::min3(d[y-1][x-1]+3,d[y-1][x]+2,d[y-1][x+1]+3)
                      );
              else
                 v = 0;

              BENCH_ASSERT(v == d[y][x]);
         }

      INT dif;
      ELISE_COPY 
      (
           I.all_pts(),
           Abs
           (
               Min(I.in(),v_max)
             - extinc_32(I0.in(0),v_max)
           ),
           VMax(dif)
      );

      BENCH_ASSERT(dif == 0);
}
Пример #12
0
void VisuParalx(Video_Win aW,Fonc_Num f,REAL & aV0,REAL & aV1,bool CalcV)
{
   if (CalcV)	
       ELISE_COPY ( aW.all_pts(),Rconv(f),VMin(aV0) | VMax(aV1));

   ELISE_COPY
   (
        aW.all_pts(),
        AUC(round_ni((f-aV0) * (255.0/(aV1-aV0)))),
       aW.ogray()
   );
}
Пример #13
0
template <class Type> void Bench_PackB_IM<Type>::TiffVerif()
{

   Pt2di SzDalle = Pt2di(mPer,64);

    Tiff_Im  aTifFile
    (
         ELISE_BFI_DATA_DIR "ex.tif",  
         sz,
         type_of_ptr((Type *)0),
         Tiff_Im::NoByte_PackBits_Compr,
         Tiff_Im::BlackIsZero,
            L_Arg_Opt_Tiff()
           +  Arg_Tiff(Tiff_Im::ATiles(SzDalle))
    );


    

    ELISE_COPY(aTifFile.all_pts(),pck.in(),aTifFile.out());
    INT VDIF;
    ELISE_COPY(aTifFile.all_pts(),Abs(pck.in()-aTifFile.in()),VMax(VDIF));

    BENCH_ASSERT(VDIF==0);

    if (type_of_ptr((Type *)0)==GenIm::u_int1)
    {
         PackB_IM<U_INT1> aPack2 = aTifFile.un_load_pack_bit_U_INT1();
         ELISE_COPY(aTifFile.all_pts(),Abs(pck.in()-aPack2.in()),VMax(VDIF));
         BENCH_ASSERT(VDIF==0);
    }
    if (type_of_ptr((Type *)0)==GenIm::u_int2)
    {
         PackB_IM<U_INT2> aPack2 = aTifFile.un_load_pack_bit_U_INT2();
         ELISE_COPY(aTifFile.all_pts(),Abs(pck.in()-aPack2.in()),VMax(VDIF));
         BENCH_ASSERT(VDIF==0);
    }
}
Пример #14
0
void ShowIm2(Im2D_INT2 aZ,Video_Win aW)
{
    INT zMax,zMin;

    ELISE_COPY(aZ.all_pts(),aZ.in(),VMax(zMax)|VMin(zMin));
    cout << "Z  = [" << zMin << " , " << zMax << "]\n";

    ELISE_COPY
    (
        aZ.all_pts(),
        Max(0,Min(255,aZ.in())), // (aZ.in()-zMin) * (255.0/(zMax-zMin)),
        aW.ogray()
    );
}
Пример #15
0
static __inline__ Uint32 delete_dynamic_aabb_from_node(BBOX_TREE *bbox_tree, Uint32 node, Uint32 ID, Uint32 type_mask)
{
	Uint32 i, result, idx1, idx2;
	AABBOX new_bbox;

	if (node != NO_INDEX)
	{		
		result = dynamic_aabb_is_in_node(bbox_tree, node, ID, type_mask);
		if (result != 0)
		{
			if ((bbox_tree->nodes[node].nodes[0] != NO_INDEX) && (bbox_tree->nodes[node].nodes[1] != NO_INDEX))
			{
				idx1 = bbox_tree->nodes[node].nodes[0];
				idx2 = bbox_tree->nodes[node].nodes[1];
				VMin(new_bbox.bbmin, bbox_tree->nodes[idx1].bbox.bbmin, bbox_tree->nodes[idx2].bbox.bbmin);
				VMax(new_bbox.bbmax, bbox_tree->nodes[idx1].bbox.bbmax, bbox_tree->nodes[idx2].bbox.bbmax);
			}
			else
			{
				VAssign(new_bbox.bbmin, bbox_tree->nodes[node].orig_bbox.bbmin);
				VAssign(new_bbox.bbmax, bbox_tree->nodes[node].orig_bbox.bbmax);
			}

			for (i = 0; i < bbox_tree->nodes[node].dynamic_objects.index; i++)
			{
				VMin(new_bbox.bbmin, new_bbox.bbmin, bbox_tree->nodes[node].dynamic_objects.items[i].bbox.bbmin);
				VMax(new_bbox.bbmax, new_bbox.bbmax, bbox_tree->nodes[node].dynamic_objects.items[i].bbox.bbmax);
			}

			VAssign(bbox_tree->nodes[node].bbox.bbmin, new_bbox.bbmin);
			VAssign(bbox_tree->nodes[node].bbox.bbmax, new_bbox.bbmax);

			return 1;
		}
	}
	return 0;
}
Пример #16
0
bool Triangle::TestInterval(const RayInterval &i) const {
	//TODO: wrong, backface culling still on
	//TODO: min/max origin
	float det =
		(plane.x < 0.0f? i.minDir.x : i.maxDir.x) * plane.x +
		(plane.y < 0.0f? i.minDir.y : i.maxDir.y) * plane.y +
		(plane.z < 0.0f? i.minDir.z : i.maxDir.z) * plane.z;
	if(det < 0.0f)
		return 1;

	enum { sharedOrigin = 1 };
	Vec3f c1a, c1b, c2a, c2b;
	if(sharedOrigin) {
		Vec3f tvec = i.minOrigin - a;
		Vec3f c1 = ba ^ tvec, c2 = tvec ^ ca;

		c1a = i.minDir * c1; c1b = i.maxDir * c1;
		c2a = i.minDir * c2; c2b = i.maxDir * c2;
	}
	else {
		Vec3f tvec1 = i.minOrigin - a, tvec2 = i.maxOrigin - a;

		{
			float xa1 = ba.y * tvec1.z, xb1 = ba.z * tvec1.y; float xa2 = ba.y * tvec2.z, xb2 = ba.z * tvec2.y;
			float ya1 = ba.z * tvec1.x, yb1 = ba.x * tvec1.z; float ya2 = ba.z * tvec2.x, yb2 = ba.x * tvec2.z;
			float za1 = ba.x * tvec1.y, zb1 = ba.y * tvec1.x; float za2 = ba.x * tvec2.y, zb2 = ba.y * tvec2.x;
			c1a.x = Min(xa1, xa2) - Max(xb1, xb2); c1b.x = Max(xa1, xa2) - Min(xb1, xb2);
			c1a.y = Min(ya1, ya2) - Max(yb1, yb2); c1b.y = Max(ya1, ya2) - Min(yb1, yb2);
			c1a.z = Min(za1, za2) - Max(zb1, zb2); c1b.z = Max(za1, za2) - Min(zb1, zb2);
		}
		{
			float xa1 = tvec1.y * ca.z, xb1 = tvec1.z * ca.y; float xa2 = tvec2.y * ca.z, xb2 = tvec2.z * ca.y;
			float ya1 = tvec1.z * ca.x, yb1 = tvec1.x * ca.z; float ya2 = tvec2.z * ca.x, yb2 = tvec2.x * ca.z;
			float za1 = tvec1.x * ca.y, zb1 = tvec1.y * ca.x; float za2 = tvec2.x * ca.y, zb2 = tvec2.y * ca.x;
			c2a.x = Min(xa1, xa2) - Max(xb1, xb2); c2b.x = Max(xa1, xa2) - Min(xb1, xb2);
			c2a.y = Min(ya1, ya2) - Max(yb1, yb2); c2b.y = Max(ya1, ya2) - Min(yb1, yb2);
			c2a.z = Min(za1, za2) - Max(zb1, zb2); c2b.z = Max(za1, za2) - Min(zb1, zb2);
		}
		Vec3f t1, t2, t3, t4;
		t1 = i.minDir * c1a; t2 = i.maxDir * c1b; 
		t3 = i.maxDir * c1a; t4 = i.minDir * c1b; 
		c1a = VMin(VMin(t1, t2), VMin(t3, t4)); c1b = VMax(VMax(t1, t2), VMax(t3, t4));
		t1 = i.minDir * c2a; t2 = i.maxDir * c2b;
		t3 = i.maxDir * c2a; t4 = i.minDir * c2b;
		c2a = VMin(VMin(t1, t2), VMin(t3, t4)); c2b = VMax(VMax(t1, t2), VMax(t3, t4));
	}

	float u[2] = {
		Min(c1a.x, c1b.x) + Min(c1a.y, c1b.y) + Min(c1a.z, c1b.z),
		Max(c1a.x, c1b.x) + Max(c1a.y, c1b.y) + Max(c1a.z, c1b.z) };
	float v[2] = {
		Min(c2a.x, c2b.x) + Min(c2a.y, c2b.y) + Min(c2a.z, c2b.z),
		Max(c2a.x, c2b.x) + Max(c2a.y, c2b.y) + Max(c2a.z, c2b.z) };
	
	return Min(u[1], v[1]) >= 0.0f && u[0] + v[0] <= det * t0;
}
Пример #17
0
void ObjectInstance::ComputeBBox() {
	BBox b = tree->GetBBox();
	floatq x0(b.min.x);
	floatq x1(b.max.x);
	floatq y(b.min.y, b.min.y, b.max.y, b.max.y);
	floatq z(b.min.z, b.max.z, b.min.z, b.max.z);
	Vec3q p0(	y * rotation[0].y + z * rotation[0].z,
				y * rotation[1].y + z * rotation[1].z,
				y * rotation[2].y + z * rotation[2].z);
	Vec3q p1(	x1 * rotation[0].x + p0.x,
				x1 * rotation[1].x + p0.y,
				x1 * rotation[2].x + p0.z);
	p0.x += x0 * rotation[0].x;
	p0.y += x0 * rotation[1].x;
	p0.z += x0 * rotation[2].x;
	bbox = BBox(Minimize(VMin(p0, p1)) + translation, Maximize(VMax(p0, p1)) + translation);
}
Пример #18
0
static __inline__ void calc_bbox(AABBOX *bbox, BBOX_TREE *bbox_tree, Uint32 first, Uint32 last)
{
	int i;
	VECTOR3 bmin, bmax;

	VFill(bmin, BOUND_HUGE);
	VFill(bmax, -BOUND_HUGE);

	for (i = first; i < last; i++)
	{
		VMin(bmin, bmin, bbox_tree->items[i].bbox.bbmin);
		VMax(bmax, bmax, bbox_tree->items[i].bbox.bbmax);
	}

	VAssign(bbox->bbmin, bmin);
	VAssign(bbox->bbmax, bmax);
}
Пример #19
0
static __inline__ Uint32 check_aabb_aabb(const AABBOX bbox, const AABBOX dyn_bbox, float grow)
{
	AABBOX new_bbox;
	VECTOR3 len;
	float old_v, new_v;

	VMin(new_bbox.bbmin, bbox.bbmin, dyn_bbox.bbmin);
	VMax(new_bbox.bbmax, bbox.bbmax, dyn_bbox.bbmax);

	VSub(len, bbox.bbmax, bbox.bbmin);
	old_v = len[X] * len[Y] * len[Z];
	VSub(len, new_bbox.bbmax, new_bbox.bbmin);
	new_v = len[X] * len[Y] * len[Z];

	if ((new_v / old_v) > grow) return 0;
	else return 1;
}
Пример #20
0
static __inline__ void merge_dyn_items(BBOX_TREE* bbox_tree, Uint32 sub_node, Uint32 in_mask, AABBOX* bbox)
{
	Uint32 idx, size, i;

	idx = bbox_tree->cur_intersect_type;
	size = bbox_tree->nodes[sub_node].dynamic_objects.index;

	for (i = 0; i < size; i++)
	{
		if (check_aabb_outside_frustum(bbox_tree->nodes[sub_node].dynamic_objects.items[i].bbox,
			bbox_tree->intersect[idx].frustum, in_mask) != OUTSIDE)
		{
			VMin(bbox->bbmin, bbox->bbmin, bbox_tree->nodes[sub_node].dynamic_objects.items[i].bbox.bbmin);
			VMax(bbox->bbmax, bbox->bbmax, bbox_tree->nodes[sub_node].dynamic_objects.items[i].bbox.bbmax);			
		}
	}
}
Пример #21
0
template <class Type,class TypeB> void bench_r2d_lin_cumul
    (
          const OperAssocMixte & op,
          Type *,
          TypeB *,
          Pt2di sz
    )
{
    Im2D<Type,TypeB> I(sz.x,sz.y,(Type)0);
    Im2D_REAL8       R1(sz.x,sz.y,(REAL8)0);
    Im2D_REAL8       R2(sz.x,sz.y,(REAL8)0);

    ELISE_COPY(I.all_pts(),255*frandr(),I.out());

    ELISE_COPY(I.all_pts(),lin_cumul_ass(op,I.in()),R1.out());
    ELISE_COPY(I.lmr_all_pts(Pt2di(1,0)),lin_cumul_ass(op,I.in()),R2.out());

    REAL dif;
    ELISE_COPY (R1.all_pts(),Abs(R1.in()-R2.in()),VMax(dif));
    BENCH_ASSERT(dif<epsilon);
}
Пример #22
0
void bench_opt_contrainte()
{ 
     INT NbVar = round_ni(1 + 10 * NRrandom3());
     L2SysSurResol aSys1(NbVar);
     L2SysSurResol aSys2(NbVar);

     INT NbContr = round_ni(NbVar*NRrandom3());
     INT NbEq =  round_ni(NbVar + 2 + 10 * NRrandom3());

     for (INT fois=0 ; fois < 3 ; fois++)
     {
         for (INT k=0 ;k<NbContr +NbEq ; k++)
         {
             Im1D_REAL8 C(NbVar);
	     ELISE_COPY(C.all_pts(), frandr(),C.out());
             REAL aVal = NRrandom3();
	     if (k<NbContr)
             {
	         aSys1.GSSR_AddContrainte(C.data(),aVal);
	         aSys2.GSSR_AddNewEquation(1e9,C.data(),aVal);
             }
	     else
             {
	         aSys1.GSSR_AddNewEquation(1,C.data(),aVal);
	         aSys2.GSSR_AddNewEquation(1,C.data(),aVal);
             }
         }

	 Im1D_REAL8 Sol1 = aSys1.GSSR_Solve(0);
	 Im1D_REAL8 Sol2 = aSys2.GSSR_Solve(0);

	 REAL Dif;
	 ELISE_COPY(Sol1.all_pts(),Abs(Sol1.in()-Sol2.in()),VMax(Dif));
         BENCH_ASSERT(Dif<GIGANTESQUE_epsilon);
         aSys1.GSSR_Reset();
         aSys2.GSSR_Reset();
     }
    
}
Пример #23
0
void FillStat(cXml_StatVino & aStat,Flux_Pts aFlux,Fonc_Num aFonc)
{
   aFonc = Rconv(aFonc);
   int aNbCh = aFonc.dimf_out();
   aStat.Soms().resize(aNbCh,0.0);
   aStat.Soms2().resize(aNbCh,0.0);
   aStat.ECT().resize(aNbCh,0.0);
   aStat.VMax().resize(aNbCh,0.0);
   aStat.VMin().resize(aNbCh,0.0);
   Symb_FNum aSF(aFonc);

   ELISE_COPY
   (
        aFlux,
        Virgule(1.0,aSF,Square(aSF)),
        Virgule
        (
            sigma(aStat.Nb()),
            sigma(VData(aStat.Soms()),aNbCh)  | VMin(VData(aStat.VMin()),aNbCh) | VMax(VData(aStat.VMax()),aNbCh),
            sigma(VData(aStat.Soms2()),aNbCh)
        )
   );

   double aNb = aStat.Nb();
   aStat.IntervDyn() = Pt2dr(0,0);

   for (int aK=0 ; aK<aNbCh ; aK++)
   {
       aStat.Soms()[aK] /= aNb;
       aStat.Soms2()[aK] /= aNb;
       aStat.ECT()[aK] = sqrt(ElMax(0.0,aStat.Soms2()[aK]-ElSquare(aStat.Soms()[aK])));
       aStat.IntervDyn().x += aStat.VMin()[aK];
       aStat.IntervDyn().y += aStat.VMax()[aK];
   }
    aStat.IntervDyn() = aStat.IntervDyn() / aNbCh;
}
Пример #24
0
int GrShade_main(int argc,char ** argv)
{
     std::string aNameIn;
     std::string aNameOut;
     std::string aNameCol="";
     Pt2di aP0Glob(0,0),aSzGlob(0,0);
     INT aNbDir = 20;
     REAL aFZ = 1.0;

     REAL aPdsAnis = 0.95;
     INT  aBrd = -1;
     std::string aTMNt = "real4";
     std::string aTShade = "real4";
     INT aDequant =0;
     INT aVisu = 0;
     REAL aHypsoDyn = -1.0;
     REAL aHypsoSat = 0.5;

     Pt2di aSzMaxDalles (3000,3000);
     INT aSzRecDalles = 300;
     std::string aModeOmbre="CielVu";
     std::string modeOmbre[] = {aModeOmbre,"IgnE","Local","Med","Mixte"};
     std::list<std::string> lModeOmbre(modeOmbre, modeOmbre + sizeof(modeOmbre) / sizeof(std::string) );
     std::string aFileMasq="";

     double  aDericheFact=2.0;
     int     aNbIterF = 4;
     double  aFactExp = 0.95;
     double aDyn = 1.0;
     int aNbMed = 100;
     int aNbIterMed = 1;

     Tiff_Im::SetDefTileFile(1<<15);

     std::vector<double> aVPdsFiltre;


     std::string aModeColor = "IntensShade";
     std::string modeColor[] = {aModeColor,"BackRGB","GrayBackRGB"};
     std::list<std::string> lModeColor(modeColor, modeColor + sizeof(modeColor) / sizeof(std::string) );

     double aTetaH = 25.0;
     double anAzimut = 0.0;
     double aDynMed = 1.0;

     ElInitArgMain
     (
           argc,argv,
           LArgMain() << EAMC(aNameIn, "File name", eSAM_IsExistFile) ,
           LArgMain() << EAM(aNameOut,"Out",true)
                      << EAM(aNameCol,"FileCol",true, "Color file", eSAM_IsExistFile)
                      << EAM(aVisu,"Visu",true)
                      << EAM(aP0Glob,"P0",true)
                      << EAM(aSzGlob,"Sz",true)
                      << EAM(aFZ,"FZ",true)
                      << EAM(aDynMed,"DynMed",true)
                      << EAM(aPdsAnis,"Anisotropie",true)
                      << EAM(aNbDir,"NbDir",true)
                      << EAM(aBrd,"Brd",true)
                      << EAM(aTMNt,"TypeMnt",true, "Type", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                      << EAM(aTShade,"TypeShade",true, "Type", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                      << EAM(aDequant,"Dequant",true)
                      << EAM(aHypsoDyn,"HypsoDyn",true)
                      << EAM(aHypsoSat,"HypsoSat",true)
              << EAM(aSzMaxDalles,"SzMaxDalles",true)
              << EAM(aSzRecDalles,"SzRecDalles",true)
              << EAM(aModeOmbre,"ModeOmbre",true,"in {CielVu,IgnE,Local,Med,Mixte}",eSAM_None,lModeOmbre)
              << EAM(aFileMasq,"Mask",true, "Mask file", eSAM_IsExistFile)
              << EAM(aDericheFact,"DericheFact",true)
              << EAM(aNbIterF,"NbIterF",true)
              << EAM(aFactExp,"FactExp",true)
              << EAM(aDyn,"Dyn",true)
                      << EAM(aVPdsFiltre,"PdsF",true,"[CielVu,Local,Grad,Med]", eSAM_NoInit)
                      << EAM(aModeColor,"ModeColor",true,"Color mode", eSAM_None, lModeColor)
                      << EAM(aNbMed,"NbMed",true)
                      << EAM(aNbIterMed,"NbIterMed",true)
                      << EAM(aTetaH,"TetaH",true)
                      << EAM(anAzimut,"Azimut",true)
    );

    if (!MMVisualMode)
    {

    double aPdsDef = aVPdsFiltre.size() ? 0 : 1;
    for (int aK=aVPdsFiltre.size() ; aK<4 ; aK++)
       aVPdsFiltre.push_back(aPdsDef);

    double aSPdsF = 0;
    for (int aK=0 ; aK<4 ; aK++)
       aSPdsF += aVPdsFiltre[aK];
    for (int aK=0 ; aK<4 ; aK++)
        aVPdsFiltre[aK] /= aSPdsF;


    std::string aDir,aNameFileIn;
    SplitDirAndFile(aDir,aNameFileIn,aNameIn);



     bool WithHypso = (aHypsoDyn>0) || (aNameCol != "");
     // bool WithCol =   (aNameCol != "");


    if (aNameOut=="")
       aNameOut = StdPrefix(aNameIn) +std::string("Shade.tif");

     Tiff_Im aFileIn = Tiff_Im::StdConvGen(aNameIn,1,true,false);
     if (aSzGlob== Pt2di(0,0))
        aSzGlob = aFileIn.sz() -aP0Glob;
     Fonc_Num aFIn = aFileIn.in_gen(Tiff_Im::eModeCoulGray,Tiff_Im::eModeNoProl);

    {
        Tiff_Im
        (
             aNameOut.c_str(),
             aSzGlob,
             GenIm::u_int1,
         Tiff_Im::No_Compr,
         WithHypso  ? Tiff_Im::RGB : Tiff_Im::BlackIsZero
        );
    }
    Tiff_Im aTifOut(aNameOut.c_str());

     if (aSzMaxDalles.x<0) aSzMaxDalles = aSzGlob;
     Pt2di aPRD(aSzRecDalles,aSzRecDalles);
     cDecoupageInterv2D aDecoup
                    (
                            Box2di(aP0Glob,aP0Glob+aSzGlob),
                aSzMaxDalles,
                Box2di(-aPRD,aPRD)
            );

     Im2DGen aMnt =    AllocImGen(aDecoup.SzMaxIn(),aTMNt);
     Im2DGen aShade =  AllocImGen(aDecoup.SzMaxIn(),aTShade);

     cout << "SZ Max In " << aDecoup.SzMaxIn() << endl;
     REAL aRatio = ElMin(800.0/aSzGlob.x,700.0/aSzGlob.y);
     Video_Win * pW  = aVisu                          ?
                       Video_Win::PtrWStd(Pt2di(Pt2dr(aSzGlob)*aRatio)) :
                       0                              ;

     aTetaH *= (2*PI)/360.0;
     anAzimut *= (2*PI)/360.0;

     for (int aKDec=0; aKDec<aDecoup.NbInterv() ; aKDec++)
     {

         Box2di aBoxIn = aDecoup.KthIntervIn(aKDec);
     Pt2di aSzIn = aBoxIn.sz();
     Pt2di aP0In = aBoxIn.P0();

     cout << "DEQ " << aDequant << "Sz In " << aSzIn <<endl;

         REAL aVMin;
         if (aDequant)
         {
             ElImplemDequantifier aDeq(aSzIn);
             aDeq.SetTraitSpecialCuv(true);
             aDeq.DoDequantif(aSzIn, trans(aFIn,aP0In),true);
         REAL aVMax;
             ELISE_COPY
             (
                  rectangle(Pt2di(0,0),aSzIn),
                  aDeq.ImDeqReelle() * aFZ,
                  aMnt.out() | VMax(aVMax) |VMin(aVMin)
             );

         }
         else
     {
             ELISE_COPY
             (
                  rectangle(Pt2di(0,0),aSzIn),
                  trans(aFIn,aP0In)*aFZ,
                  aMnt.out()|VMin(aVMin)
             );
     }
         Im2D_Bits<1> aIMasq(aSzIn.x,aSzIn.y,1);

     if (aFileMasq!="")
     {
             if (ELISE_fp::exist_file(aDir+aFileMasq))
                aFileMasq = aDir+aFileMasq;
         double aDif=100;
         Tiff_Im aFM = Tiff_Im::StdConvGen(aFileMasq,1,true,false);
             ELISE_COPY
             (
                  select(rectangle(Pt2di(0,0),aSzIn),trans(!aFM.in_proj(),aP0In)),
          aVMin-aDif,
                     aMnt.out()
                  |  (aIMasq.out() << 0)
             );
         aVMin-= aDif;
     }

         if (aBrd>0)
         {
            cout << "VMin = " << aVMin <<endl;
            ELISE_COPY(aMnt.border(aBrd),aVMin-1000,aMnt.out());
         }

     // Im2D_REAL4 aShade(aSzGlob.x,aSzGlob.y);
         ELISE_COPY(aShade.all_pts(),0,aShade.out());

         if (pW)
            pW = pW->PtrChc(Pt2dr(aP0Glob-aP0In),Pt2dr(aRatio,aRatio));

         REAL SPds = 0;
         REAL aSTot = 0;
         REAL Dyn = 1.0;
         if (aTShade != "u_int1")
            Dyn = 100;

         bool Done = false;
         if (   (aModeOmbre=="CielVu")
             || ((aModeOmbre=="Mixte") && (aVPdsFiltre[0] > 0.0))
            )
     {
            std::cout << "BEGIN CIEL" << endl;
            Done = true;
            for (int aK=0 ; aK< 2 ; aK++)
            {
               SPds = 0;
               for (int i=0; i<aNbDir; i++)
               {
                  REAL Teta  = (2*PI*i) / aNbDir ;
                  Pt2dr U(cos(Teta),sin(Teta));
                  Pt2di aDir = Pt2di(U * (aNbDir * 4));
                  REAL Pds = (1-aPdsAnis) + aPdsAnis *ElSquare(1.0 - euclid(U,Pt2dr(0,1))/2);
                  if (aK==1)
                     Pds = (Pds*Dyn) / (2*aSTot);
                  Symb_FNum Gr = (1-cos(PI/2-atan(gray_level_shading(aMnt.in()))))
                             *255.0;
                  cout << "Dir " << i << " Sur " << aNbDir <<  " P= " << Pds << endl;
                  SPds  += Pds;
                  if (aK==1)
                  {
                 ELISE_COPY
                 (
                     line_map_rect(aDir,Pt2di(0,0),aSzIn),
                     Min(255*Dyn,aShade.in()+Pds*Gr),
                       aShade.out()
                         // | (pW ? (pW->ogray()<<(aShade.in()/SPds)) : Output::onul())
                         | (pW ? (pW->ogray()<<(Gr)) : Output::onul())
                     );
                  }

               }
               aSTot  = SPds;
            }
            double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[0] : 1.0;
            ELISE_COPY(aShade.all_pts(),aShade.in()*(aMul/SPds),aShade.out());
            SPds = aMul;
            std::cout << "BEGIN CIEL" << endl;
     }
     if (
                      (aModeOmbre=="Local")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[1] > 0.0))
                 )
     {
               std::cout << "BEGIN LOCAL" << endl;
               Done = true;
               Fonc_Num aFonc = aMnt.in_proj();
               Fonc_Num aMoy = aFonc;
               for (int aK=0 ; aK<aNbIterF; aK++)
                   aMoy =    canny_exp_filt(aMoy*aIMasq.in_proj(),aFactExp,aFactExp)
                          /  Max(0.1,canny_exp_filt(aIMasq.in_proj(),aFactExp,aFactExp));

               double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[1] : 1.0;
               ELISE_COPY
               (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,Min(255, aShade.in() +(128+(aFonc-aMoy)*aDyn)* aMul)),
          aShade.out()
               );
               SPds += aMul;
               std::cout << "END LOCAL" << endl;
     }
     if (
                      (aModeOmbre=="Med")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[3] > 0.0))
                 )
     {
              std::cout << "BEGIN MED" << endl;

               Done = true;
               Fonc_Num aFonc = round_ni(aMnt.in_proj()*aDynMed);
               int aVMax,aVMin;

               ELISE_COPY
               (
                   rectangle(Pt2di(-1,-1),aSzIn+Pt2di(1,1)),
                   aFonc,
                   VMin(aVMin)|VMax(aVMax)
               );

               Fonc_Num aMoy = aFonc-aVMin;

               for (int aK=0 ; aK<aNbIterMed; aK++)
                   aMoy =    rect_median(aMoy,aNbMed,aVMax-aVMin+1);

               aMoy = aMoy + aVMin;

               double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[3] : 1.0;
               ELISE_COPY
               (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,Min(255, aShade.in() +(128+((aFonc-aMoy)*aDyn)/aDynMed)* aMul)),
          aShade.out()
               );
               SPds += aMul;
              std::cout << "END MED" << endl;
     }
     if (
                      (aModeOmbre=="IgnE")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[2] > 0.0))
                 )
     {
int aCpt=0; aCpt++;
std::cout << "IGN E " << aCpt << " " << aKDec << "\n";
             Done = true;
if (aCpt>0)
{
         Symb_FNum aGrad =  deriche(aMnt.in_proj(),aDericheFact);
             Symb_FNum aGx = (aGrad.v0());
             Symb_FNum aGy = (aGrad.v1());
         Symb_FNum aNG = sqrt(1+Square(aGx)+Square(aGy));

         Symb_FNum aNx (aGx/aNG);
         Symb_FNum aNy (aGy/aNG);
         Symb_FNum aNz (1/aNG);



         Pt2dr  aDirS = Pt2dr::FromPolar(1.0,anAzimut) * Pt2dr(1,0);

         double aSx = aDirS.x * sin(aTetaH);
         double aSy = aDirS.y * sin(aTetaH);
         double aSz = cos(aTetaH);

         Symb_FNum aScal(aNx*aSx+aNy*aSy+aNz*aSz);

std::cout << "AAAAAAAaa" << endl;
             double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[2] : 1.0;
             ELISE_COPY
             (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,aShade.in() + 255*aScal * aMul),
          aShade.out()
             );
             SPds += aMul;
std::cout << "BBBBbbb" << endl;
}
     }
     if (! Done)
     {
         ELISE_ASSERT(false,"Unknown ModeOmbre");
     }



        Fonc_Num aFoncRes = Max(0,Min(255,aShade.in()/SPds));
        if (WithHypso)
        {
            Fonc_Num  aFIntens = aFoncRes;
            Fonc_Num  aFTeinte = trans(aFIn,aP0In)*aHypsoDyn;
            Fonc_Num  aFSat = 255*aHypsoSat;

            if (aNameCol!="")
            {
                Tiff_Im aFileCol = Tiff_Im::StdConvGen(aDir+aNameCol,-1,true,false);
            Symb_FNum aFNC(trans(rgb_to_its(aFileCol.in()),aP0In));

                if (aModeColor == "IntensShade")
                {
                    aFIntens = aFoncRes;
                    aFTeinte = aFNC.v1();
                    aFSat = aFNC.v2();
                }
                else if (aModeColor == "BackRGB")
                {
                   aFIntens = aIMasq.in()*aFoncRes + (1- aIMasq.in()) * aFNC.v0();
                   aFTeinte = aFNC.v1();
                   aFSat = aFNC.v2() * (1- aIMasq.in());
                }
                else if (aModeColor == "GrayBackRGB")
                {
                   aFIntens = aIMasq.in()*aFoncRes + (1- aIMasq.in()) * aFNC.v0();
                   aFTeinte = aFNC.v1();
                   aFSat = aFNC.v2()*(1-aIMasq.in());
                }
                else
                {
                    ELISE_ASSERT(false,"Unknown mode color");
                }
            }
            aFoncRes = its_to_rgb(Virgule(aFIntens,aFTeinte,aFSat));
            //aFoncRes = its_to_rgb(Virgule(aFoncRes,trans(aFIn,aP0In)*aHypsoDyn,255*aHypsoSat));
        }
/*
    if (WithCol)
    {
            Tiff_Im aFileCol(aNameCol.c_str());
        Symb_FNum aFNC(trans(rgb_to_its(aFileCol.in()),aP0In));
        aFoncRes = its_to_rgb(Virgule(aFoncRes,aFNC.v1(),aFNC.v2()*aHypsoSat));
        // aFoncRes = aFileCol.in();
    }
*/

     // Tiff_Im::Create8BFromFonc(aNameOut,aShade.sz(),aShade.in()/SPds);


    cout << "WithHypso " << WithHypso << " DIM " << aFoncRes.dimf_out() <<  endl;
        Box2di aBoxOut = aDecoup.KthIntervOut(aKDec);
        ELISE_COPY
        (
            rectangle(aBoxOut.P0()-aP0Glob,aBoxOut.P1()-aP0Glob),
        trans(aFoncRes,aP0Glob-aP0In),
        aTifOut.out()
        );
     }

     return EXIT_SUCCESS;

    }
    else return EXIT_SUCCESS;
}
Пример #25
0
void bench_r2d_proj()
{
    Pt2di sz(120,50);

    Im2D_REAL8       MNT(sz.x,sz.y,0.0);
    Im2D_REAL8       X1(sz.x,sz.y,0.0);
    Im2D_REAL8       Y1(sz.x,sz.y,0.0);
    Im2D_REAL8       X2(sz.x,sz.y,0.0);
    Im2D_REAL8       Y2(sz.x,sz.y,0.0);


    ELISE_COPY(MNT.all_pts(),frandr(),MNT.out());

    ELISE_COPY
    (
        MNT.all_pts(),
        proj_cav(MNT.in(),0.5,2.0),
        Virgule(X1.out(),Y1.out())
    );

    ELISE_COPY
    (
        MNT.lmr_all_pts(Pt2di(1,0)),
        proj_cav(MNT.in(),0.5,2.0),
        Virgule(X2.out(),Y2.out())
    );

    REAL dif;

    ELISE_COPY 
    (
         MNT.all_pts(),
         Max(Abs(X1.in()-X2.in()),Abs(Y1.in()-Y2.in())),
         VMax(dif)
    );
    BENCH_ASSERT(dif<epsilon);


    ELISE_COPY
    (
        MNT.all_pts(),
        (2*PI)*phasis_auto_stereogramme(MNT.in(),10.5,2.0),
        X1.out()
    );

    ELISE_COPY
    (
        MNT.lmr_all_pts(Pt2di(1,0)),
        (2*PI)*phasis_auto_stereogramme(MNT.in(),10.5,2.0),
        X2.out()
    );

    ELISE_COPY 
    (
         MNT.all_pts(),
         Max
         (
              Abs(cos(X1.in())-cos(X2.in())),
              Abs(sin(X1.in())-sin(X2.in()))
         ),
         VMax(dif)
    );

    BENCH_ASSERT(dif<epsilon);
}
Пример #26
0
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;
}
Пример #27
0
void bench_im_rle(Pt2di sz,INT NbLabel,Pt2di SzBox,INT NbLissage)
{
    typedef EliseRle::tIm  tIm;
    bool  ModeV8 = NRrandom3() > 0.5;
    Im2D<tIm,INT> Im1(sz.x,sz.y);
    Im2D<tIm,INT> Im2(sz.x,sz.y);
    Im2D<tIm,INT> Im3(sz.x,sz.y);
    Im2D<tIm,INT> ImOri(sz.x,sz.y);

    Im2D<tIm,INT> ImBox1(sz.x,sz.y,0);
    Im2D<tIm,INT> ImBox2(sz.x,sz.y,0);

    Fonc_Num f = Iconv(frandr()*20*NbLabel)%NbLabel;
    for (INT k=0 ; k<NbLissage ; k++)
        f = label_maj(f,NbLabel,Pt2di(5,5));


    ELISE_COPY(Im1.all_pts() , f-2, Im1.out()|Im2.out()|Im3.out()|ImOri.out() );
    ELISE_COPY(Im1.border(1) , 0  , Im1.out()|Im2.out()|Im3.out()|ImOri.out() );


    tIm ** data1 = Im1.data();
    tIm ** data2 = Im2.data();


    Neighbourhood V8 = Neighbourhood::v8();     
    Neighbourhood V4 = Neighbourhood::v4();     

    U_INT1 ColBig = NbLabel * 2 +1;
    EliseRle::tContainer  Rles;

    INT cptSmall1 =0; 
    INT cptSmall2 =0; 
    INT cptBig1 =0; 
    INT cptBig2 =0; 
    ELISE_COPY(select(Im1.all_pts(),Im1.in()<0),0,Im1.out());

    BenchConc aBc(NbLabel,false);
    BenchConc * aBcPtr = &aBc;

    if (NRrandom3() >0.5)
        aBcPtr = new BenchConc(NbLabel,true);

    ELISE_COPY
    (
         Im3.all_pts(),
         BoxedConc(Im3.in(0),SzBox,ModeV8,aBcPtr,(INT)(9+SzBox.y*2.9*NRrandom3())),
         Im3.out()
    );


    for (INT y=0; y<sz.y ; y++)
    {
       for (INT x=0; x<sz.x ; x++)
       {
           tIm v1 = data1[y][x];
           Neighbourhood V = ModeV8 ? V8 : V4;
           Liste_Pts_INT2 l2(2);
           if ((v1 >0) && (v1<=NbLabel))
           {
               Pt2di p0,p1;
               ELISE_COPY
               (
                   conc
                   (
                      Pt2di(x,y),
                      Im1.neigh_test_and_set (V,v1,ColBig,ColBig+1)
                   ),
                   Virgule(FX,FY),
                   (l2|p0.VMin()|p1.VMax())
              );
              p1 += Pt2di(1,1);

              if ((p1.x-p0.x<=SzBox.x) && (p1.y-p0.y<=SzBox.y))
              {
                 cptSmall1++;
                 ELISE_COPY(l2.all_pts(),v1+NbLabel,Im1.out());
              }
              else
              {
                 cptBig1++;
              }
              ELISE_COPY(rectangle(p0,p1),(ImBox1.in()+v1)%256,ImBox1.out());
           }

           tIm v2 = data2[y][x];
           if ((v2 >0) && (v2<=NbLabel))
           {
                Box2di Box =  EliseRle::ConcIfInBox
                              (
                                   Pt2di(x,y),
                                   Rles,
                                   data2,
                                   v2,ColBig,
                                   ModeV8,
                                   SzBox
                              );
                if (! Rles.empty())
                {
                   cptSmall2++;
                   EliseRle::SetIm(Rles,data2, v2+NbLabel);
                }
                else
                {
                   cptBig2++;
                }
                ELISE_COPY
                (
                    rectangle(Box._p0,Box._p1),
                    (ImBox2.in()+v2)%256,
                    ImBox2.out()
                );
           }
       }
    }
    ELISE_COPY(select(Im1.all_pts(),ImOri.in()<0),ImOri.in(),Im1.out());

    BENCH_ASSERT(cptSmall2 == cptSmall1);
    BENCH_ASSERT(cptBig2 == cptBig1);
    INT Dif1;
    ELISE_COPY
    (
       Im1.all_pts(),
       Abs(Im1.in()-Im2.in()),
       VMax(Dif1)
    );
    BENCH_ASSERT(Dif1==0);
    ELISE_COPY
    (
       Im1.all_pts(),
       Abs(ImBox1.in()-ImBox2.in()),
       VMax(Dif1)
    );
    BENCH_ASSERT(Dif1==0);


    ELISE_COPY
    (
       Im1.all_pts(),
       Abs(Im1.in()-Im3.in()),
       VMax(Dif1)
    );
    
    BENCH_ASSERT(Dif1==0);
}
Пример #28
0
VImage VShearImageX (VImage src, VImage dest, VBand band, double shear)
{
  int src_nrows, src_ncols, src_nbands;
  int dest_nrows, dest_ncols, dest_nbands;
  VRepnKind src_repn, dest_repn;
  double skew, skewi, skewf, left, oleft;
  int x, y, b, src_curband, dest_curband;
  int extra_ncols, sdx, sdy, ddx, ddy;

  /* Read properties of "src": */
  src_nrows  = VImageNRows (src);
  src_ncols  = VImageNColumns (src);
  src_nbands = VImageNBands (src);
  src_repn   = VPixelRepn (src);

  /* Check to ensure that "band" exists: */
  if (band != VAllBands && (band < 0 || band >= src_nbands)) {
    VWarning ("VShearImageY: Band %d referenced in image of %d bands",
	      band, VImageNBands (src));
    return NULL;
  }
    
  /* Determine properties of "dest": */
  dest_nrows  = src_nrows;
  extra_ncols = (int) floor (shear * (src_nrows - 0.5));
  dest_ncols  = src_ncols + VMax (extra_ncols, -extra_ncols) + 1;
  dest_nbands = (band == VAllBands) ? src_nbands : 1;
  dest_repn   = src_repn;

  /* Calculate displacements in converting from xy-coord. to
     row/column-coord. : */
  sdx = 0;
  sdy = src_nrows - 1;
  ddx = (extra_ncols < 0) ? -extra_ncols : 0;
  ddy = dest_nrows - 1;
    
  /* Create dest image */
  dest = VSelectDestImage ("VShearImageX", dest,
			   dest_nbands, dest_nrows, dest_ncols, dest_repn);
    
  if (dest == NULL)
    return NULL;

  /* Set all dest pixels to zero: */
  VFillImage (dest, VAllBands, 0.0);
    
  /* Treat lower left-hand corner of image as origin, with
     y up and x to the right. */
    
  /*
   * Shear a row of an image of a particular type: 
   */
#define ShearRow(type)                                         \
    {                                                              \
	type pixel;                                                \
	for (x = 0; x < src_ncols; x++) {                          \
	    pixel = VPixel (src,                                   \
			    src_curband,                           \
			    XYToRow (x, y, sdx, sdy),              \
			    XYToCol (x, y, sdx, sdy),              \
			    type);                                 \
	    left = pixel * skewf;                                  \
	    pixel = pixel - left + oleft;                          \
	    VPixel (dest,                                          \
		    dest_curband,                                  \
		    XYToRow ((int) (x + skewi), y, ddx, ddy),      \
		    XYToCol ((int) (x + skewi), y, ddx, ddy),      \
		    type)                                          \
		= pixel;                                           \
	    oleft = left;                                          \
	}                                                          \
	VPixel (dest,                                              \
		dest_curband,                                      \
		XYToRow ((int) (src_ncols + skewi), y, ddx, ddy),  \
		XYToCol ((int) (src_ncols + skewi), y, ddx, ddy),  \
		type)                                              \
	    = (type) oleft;                                        \
    }

  /* For each band in the dest image do: */
  for (b = 0; b < dest_nbands; b++) {

    src_curband = (band == VAllBands) ? b : band;
    dest_curband = (band == VAllBands) ? b : 0;
	
    /* For each row in the source image do: */
    for (y = 0; y < src_nrows; y++) {
	    
      skew = shear * (y + 0.5);
      skewi = floor (skew);
      skewf = skew - skewi;

      oleft = 0.0;

      /* Shear a row according to pixel representation: */
      switch (src_repn) {
      case VBitRepn:      ShearRow (VBit);    break;
      case VUByteRepn:	ShearRow (VUByte);  break;
      case VSByteRepn:	ShearRow (VSByte);  break;
      case VShortRepn:	ShearRow (VShort);  break;
      case VLongRepn:	ShearRow (VLong);   break;
      case VFloatRepn:	ShearRow (VFloat);  break;
      case VDoubleRepn:	ShearRow (VDouble); break;
      default: break;
      }
    }
  }

  VCopyImageAttrs (src, dest);
  return dest;

#undef ShearRow
}
Пример #29
0
void  bench_algo_dist_32(Pt2di sz)
{
    Im2D_U_INT1  I0(sz.x,sz.y); 
    Im2D_U_INT1  Id_plus(sz.x,sz.y); 
    Im2D_U_INT1  Id_moins(sz.x,sz.y); 
    Im2D_INT1    Idneg1(sz.x,sz.y); 
    Im2D_INT1    Idneg2(sz.x,sz.y); 

    ELISE_COPY
    (
         I0.all_pts(),
         gauss_noise_1(10)>0.5,
         I0.out() 
    );
    ELISE_COPY(I0.border(2),0,I0.out());

    ELISE_COPY
    (
         I0.all_pts(),
         extinc_32(I0.in(0),255),
         Id_plus.out()
    );
    ELISE_COPY
    (
         I0.all_pts(),
         extinc_32(! I0.in(0),255),
         Id_moins.out()
    );

    ELISE_COPY
    (
        select(I0.all_pts(),I0.in()),
        Min(Id_plus.in()-1,127),
        Idneg1.out()
    );
    ELISE_COPY
    (
        select(I0.all_pts(),! I0.in()),
        Max(1-Id_moins.in(),-128),
        Idneg1.out()
    );

    ELISE_COPY(I0.all_pts(),I0.in(),Idneg2.out());
    TIm2D<INT1,INT> TIdneg2(Idneg2);
    TIdneg2.algo_dist_32_neg();


    INT dif;
    ELISE_COPY
    (
         I0.all_pts(),
         Abs(Idneg2.in()-Idneg1.in()),
         VMax(dif)
    );
    BENCH_ASSERT(dif==0);




    ELISE_COPY
    (
        Idneg1.all_pts(),
        Iconv((gauss_noise_1(10)-0.5)* 20),
        Idneg1.out() | Idneg2.out()
    );
    ELISE_COPY(Idneg1.border(2),-100, Idneg1.out() | Idneg2.out());
    ELISE_COPY
    (
        Idneg1.all_pts(),
        128-EnvKLipshcitz_32(128-Idneg1.in(-100),100),
        Idneg1.out()
    );
    TIdneg2.algo_dist_env_Klisp32_Sup();

    INT Max2 [2];
    INT Min2 [2];

    ELISE_COPY
    (
         I0.interior(1),
         Virgule(Idneg1.in(),Idneg2.in()),
         VMax(Max2,2) | VMin(Min2,2)
    );

    ELISE_COPY
    (
         I0.interior(1),
         Abs(Idneg2.in()-Idneg1.in()),
         VMax(dif)
    );

    BENCH_ASSERT(dif==0);
}
Пример #30
0
void BenchcSysQuadCreuse
     (
         INT aNbVar,
         INT aNbEq,
         cNameSpaceEqF::eTypeSysResol aType
      )
{
    bool isFixe = NRrandom3() < 0.5;
    //cFormQuadCreuse aSCr(aNbVar,isFixe);
    cFormQuadCreuse aSCr( aNbVar, cElMatCreuseGen::StdNewOne( aNbVar, aNbVar, isFixe ) ); // __NEW
    //aSCr.SetEpsB(1e-10);
    cGenSysSurResol & aS1 = aSCr;

    L2SysSurResol   aSPl(aNbVar);
    cGenSysSurResol & aS2 = aSPl;

    bool SysFix = (aType == cNameSpaceEqF::eSysCreuxFixe);
    cSetEqFormelles aSet2(aType); // ,1e-10);
    cEqFormelleLineaire * anEq2_1 = aSet2.NewEqLin(1,aNbVar);
    cEqFormelleLineaire * anEq2_3 = aSet2.NewEqLin(3,aNbVar);


    Im1D_REAL8   aIm2(aNbVar,0.0);
    for (INT aK=0; aK<aNbVar; aK++)
        aSet2.Alloc().NewInc(aIm2.data()+aK);
    aSet2.SetClosed();
    //if (aType !=  cNameSpaceEqF::eSysPlein)
    //   aSet2.FQC()->SetEpsB(1e-10);


    Im1D_REAL8 aF(aNbVar,0.0);

    for (INT aNbTest=0 ; aNbTest<3 ; aNbTest++)
    {
        for (INT aX =0 ; aX<aNbVar; aX++)
        {
	    std::vector<INT> V;
	    V.push_back(aX);

            REAL aPds = 0.5;
            double C1 = 1;
            aF.data()[aX] = C1;
            REAL aCste =  NRrandom3();
	    if (isFixe)
	    {
		if (aX==0)
	           aSCr.SetOffsets(V);
                //aS1.GSSR_AddNewEquation_Indexe(V,aPds,&C1,aCste);
                aS1.GSSR_AddNewEquation_Indexe(V,aPds,&C1,aCste);
	    }
	    else 
                aS1.GSSR_AddNewEquation(aPds,aF.data(),aCste);
            aS2.GSSR_AddNewEquation(aPds,aF.data(),aCste);

	     if ((NRrandom3() < 0.5) && (! SysFix))
                anEq2_1->AddEqNonIndexee(aCste,&C1,aPds,V);
	     else
	     {
                if (SysFix)
		   aSet2.FQC()->SetOffsets(V);
                anEq2_1->AddEqIndexee(aCste,&C1,aPds,V);
	     }

            aF.data()[aX] = 0;
        }

        for (INT aK =0 ; aK<aNbEq; aK++)
	{
	     std::vector<INT> aVInd;
	     REAL   aV3[3];

             static INT I1=0;
             static INT I2=0;
             static INT I3=0;
	     bool TransI =     (NRrandom3() <0.5)
		           &&  (aK != 0)
		           &&  (I1 < aNbVar-1)
		           &&  (I2 < aNbVar-1)
		           &&  (I3 < aNbVar-1); 
	     if (TransI)
	     {
		     I1++;
		     I2++;
		     I3++;
	     }
	     else
	     {
                I1 = std::min(aNbVar-1,INT(NRrandom3()*aNbVar));
                I2 = std::min(aNbVar-1,INT(NRrandom3()*aNbVar));
                I3 = std::min(aNbVar-1,INT(NRrandom3()*aNbVar));
	     }
             REAL aCste = NRrandom3();


	     aV3[0] = NRrandom3();
	     aV3[1] = NRrandom3();
	     aV3[2] = NRrandom3();

	     aF.data()[I1] += aV3[0];
             aF.data()[I2] += aV3[1];
             aF.data()[I3] += aV3[2];
	     aVInd.push_back(I1);
	     aVInd.push_back(I2);
	     aVInd.push_back(I3);

	     if ((NRrandom3() < 0.5) && (! SysFix))
                anEq2_3->AddEqNonIndexee(aCste,aV3,1,aVInd);
	     else
	     {
		if (SysFix)
		{
                   if (! TransI)
		      aSet2.FQC()->SetOffsets(aVInd);
		}
                anEq2_3->AddEqIndexee(aCste,aV3,1,aVInd);
	     }

	     if ((NRrandom3()<0.5) || isFixe)
	     {
	         if (isFixe) 
		 {
                     if (! TransI)
                        aSCr.SetOffsets(aVInd);
		 }
                 aS1.GSSR_AddNewEquation_Indexe(aVInd,1,aV3,aCste);
	     }
	     else
                 aS1.GSSR_AddNewEquation(1,aF.data(),aCste);

	     if (NRrandom3()<0.5)
                 aS2.GSSR_AddNewEquation_Indexe(aVInd,1,aV3,aCste);
	     else
                 aS2.GSSR_AddNewEquation(1,aF.data(),aCste);


             aF.data()[I1] = 0;
             aF.data()[I2] = 0;
             aF.data()[I3] = 0;
	}
        


	bool OK;
        Im1D_REAL8 Sol1 = aS1.GSSR_Solve(&OK);
        Im1D_REAL8 Sol2 = aS2.GSSR_Solve(&OK);
	REAL aDif;
	ELISE_COPY(Sol1.all_pts(),Abs(Sol1.in()-Sol2.in()),VMax(aDif));
	cout << "a Dif " << aDif << "\n";
	BENCH_ASSERT(aDif<1e-4);

	aSet2.SolveResetUpdate();
	ELISE_COPY(Sol1.all_pts(),Abs(aIm2.in()-Sol2.in()),VMax(aDif));
	cout << "a Dif " << aDif << "\n";
	BENCH_ASSERT(aDif<1e-4);



        aS1.GSSR_Reset();
        aS2.GSSR_Reset();
    }
}