Exemplo n.º 1
0
inline void test_interpolate_1d() {
	Grid_<Float, Float, 2> g(2, 0, 1, //
			2, 0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	adp.adapt_full();
	// new value on leaf
	NewCenterDataOnLeaf(g, 2);
	// set value on leaf
	SetScalarOnCenterLeaf(g, 0, _set);
	//
	//stencil
	Grid_<Float, Float, 2>::iterator_leaf il = g.begin_leaf();
	++il;
	++il;
	++il;
	st idx = 0;
	Float res;
	il->show();
	InterpolateOnFace_1Order(il.get_pointer(), _XM_, idx, res);
	std::cout << "pnode c  : " << il->cd(0) << std::endl;
	std::cout << "res      : " << res << std::endl;
	// show
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga_leaf, ga_stencil;
	GnuplotActor_LeafNodesContours(ga_leaf, g, 0);
	lga.push_back(ga_leaf);
	GnuplotShow(lga);
}
Exemplo n.º 2
0
void test_stencil_2D() { //jan 13, 2016
	std::cout << "test stencil 2D   ================\n";
	Grid_<Float, Float, 2> g(2, 0.0, 1, //
			2, 0.0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	//adp.adapt_full();
	// shape
	Shape2D cir;
	CreatCircle(cir, 0.0, 0.0, 1.0, 359);
	adp.adapt_inner_solid(cir);
	//stencil ==============================
	Float x = 1.51;
	Float y = 1.51;
	Float z = 0.0;
	Grid_<Float, Float, 2>::pNode pn = nullptr;
	pn = g.get_pnode(x, y, z);
	Stencil_2D2 st(pn, _X_, 3, 3, _Y_, 3, 3);
	st.show();
	std::cout << "Stencil \n";

	// show ================================
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga;
	GnuplotActor_LeafNodes(ga, g);
	lga.push_back(ga);
	GnuplotActor_Shape2D(ga, cir);
	lga.push_back(ga);
	GnuplotActor_Stencil(ga, st);
	lga.push_back(ga);
	GnuplotShow(lga);
}
Exemplo n.º 3
0
inline void test_stencil_1d() {
	Grid_<Float, Float, 2> g(2, 0, 1, //
			2, 0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	adp.adapt_full();
	//stencil
	Grid_<Float, Float, 2>::iterator_leaf il = g.begin_leaf();
	++il;
	++il;
	++il;
	Stencil_2D1 st(il.get_pointer(), _Y_, 2, 1);
	st.show();
	std::cout << "Stencil \n";

	//GnuplotShow_LeafNodes(g);
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga_leaf, ga_stencil;
	GnuplotActor_LeafNodes(ga_leaf, g);
	GnuplotActor_Stencil(ga_stencil, st);
	lga.push_back(ga_leaf);
	lga.push_back(ga_stencil);
	GnuplotShow(lga);
	// test iterator
}
Exemplo n.º 4
0
void test_adapt_vof() { //jan 13, 2016
	std::cout << "test adapt initial vof  ================\n";
	Grid_<Float, Float, 2> g(4, -2.0, 1, //
			4, -2.0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	//adp.adapt_full();
	// shape
	Shape2D cir;
	CreatCircle(cir, 0.0, 0.0, 1.0, 359);
	adp.adapt_inner_solid(cir);
	// ==============================
	// shape for vof
	Shape2D cir2;
	CreatCircle(cir2, 0.7, 0.0, 1.5, 359);
	adp.adapt_vof(cir2);
	g.new_data_on_leaf(1, 0, 0, 1);
	Vof_<Float, Float, 2> vof(&g, 0, 0);
	vof.set_color(cir2);
	//stencil ==============================
	Float x = 1.0;
	Float y = 1.48;
	Float z = 0.0;
	Grid_<Float, Float, 2>::pNode pn = nullptr;
	pn = g.get_pnode(x, y, z);
	Stencil_2D2 st(pn, _X_, 1, 1, _Y_, 1, 1);
	typename Vof_<Float, Float, 2>::Matrix3_3 mat;
	vof.get_matrix(mat, st);
	Float mx = 0;
	Float my = 0;
	vof.cal_norm_Young(mat, mx, my);
	mat.show();
	std::cout << "vector x = " << mx << " y = " << my << std::endl;
	vof.construct_segments();

	// show ================================
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga;
	//GnuplotActor_LeafNodesContours(ga, g, 0);
	//lga.push_back(ga);
	GnuplotActor_LeafNodes(ga, g);
	lga.push_back(ga);
	//GnuplotActor_Shape2D(ga, cir);
	//lga.push_back(ga);
	//GnuplotActor_Shape2D(ga, cir2);
	//lga.push_back(ga);
	GnuplotActor_Stencil(ga, st);
	lga.push_back(ga);
	GnuplotActor_StencilContour(ga, st, 0);
	lga.push_back(ga);
	GnuplotActor_Vof2D(ga, vof);
	lga.push_back(ga);
	Gnuplot gp;
	gp.set_equal_ratio();
	gp.set_xrange(-1.5, 0);
	gp.set_yrange(0, 1.5);
	gp.plot(lga);
}
Exemplo n.º 5
0
int main( int hola, char** file_name)
{
  CvRect rect;
  rect.x=121;rect.y=110;rect.width=814;rect.height=223;
  erCerc cerc(135,293,25);
  erEqualP equ(0);
  erSmootP p1(BLUR,7),p2(MEDIAN,5);
  erCannyP cann(355,355);
  erAdThrP adp(THRESH_BINARY,AM_MEAN,49,119,255); //** < */
  erMacroDropAnalysis mda("hump");
  mda.defineParameters(rect,cerc,p1,p2,cann,adp,equ);
  mda.doIt("hump_1.bmp");
  return(0);
};
Exemplo n.º 6
0
void test_adp_boundary() {
	std::cout << "test adapt initial vof  ================\n";
	Grid_<Float, Float, 2> g(4, -2.0, 1, //
			4, -2.0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	//adp.adapt_full();
    //g.show_info();
	// shape
	Shape2D cir;
	CreatCircle(cir, 0.0, 0.0, 1.0, 359);
	adp.adapt_inner_solid(cir);
	// ==============================
	// shape for vof
	Shape2D cir2;
	CreatCircle(cir2, 0.0, 0.0, 1.5, 359);
	adp.adapt_vof(cir2);
	g.new_data_on_leaf(1, 0, 0, 1);
	Vof_<Float, Float, 2> vof(&g, 0, 0);
	vof.set_color(cir2);
	g.connect_nodes();
	// boundary ====
	Ghost_<Float, Float, 2> ghost(&g);

	// show ================================
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga;
	//GnuplotActor_LeafNodesContours(ga, g, 0);
	//lga.push_back(ga);
	GnuplotActor_LeafNodes(ga, g);
	lga.push_back(ga);
	//GnuplotActor_Shape2D(ga, cir);
	//lga.push_back(ga);
	//GnuplotActor_Shape2D(ga, cir2);
	//lga.push_back(ga);
	//GnuplotActor_Vof2D(ga, vof);
	//lga.push_back(ga);
	Gnuplot gp;
	gp.set_equal_ratio();
	//gp.set_xrange(-1.5, 0);
	//gp.set_yrange(0, 1.5);
	gp.plot(lga);
}
Exemplo n.º 7
0
        /*! the function to be bound to the future */
        int bond (void)
        {
            saga::impl::task_base::state_setter setter (*this);
            int return_code = 1;

            try {
                TR1::shared_ptr<Base> adp(
                    TR1::static_pointer_cast<Base>(this->cpi_instance_));
                                  
                (adp.get()->*exec_)(saga::detail::any_cast<RetVal&>(this->retval_), 
                    BOOST_PP_REPEAT(L, GETARG, _), this->get_uuid());

            // set state to finished
                setter.state_ = saga::task::Done;
                return_code = 0;
            }
            catch ( saga::exception const& e ) {
                mutex_type::scoped_lock l(this->saga::impl::object::mtx_);
                this->found_saga_exception_ = true;
                this->saved_exception_object_ = e.get_object();
                this->saved_exception_list_ = e.get_all_exceptions();
                this->saved_exception_error_ = e.get_error();
            }
            catch ( std::exception const& e ) {
                mutex_type::scoped_lock l(this->saga::impl::object::mtx_);
                this->found_exception_ = true;
                this->saved_exception_ = e;
            }
            catch ( ... ) {
                mutex_type::scoped_lock l(this->saga::impl::object::mtx_);

                TR1::shared_ptr<saga::impl::object> impl(
                    TR1::static_pointer_cast<saga::impl::object>(
                        TR1::const_pointer_cast<saga::impl::proxy>(
                            this->cpi_instance_->get_proxy()->shared_from_this())));

                this->found_saga_exception_ = true;
                this->saved_exception_object_ = runtime::get_object(impl);
                this->saved_exception_list_.clear();
                this->saved_exception_message_ = "Unspecified error caught";
                this->saved_exception_error_ = (saga::error)saga::adaptors::Unexpected;
            }
            return return_code;
        }
Exemplo n.º 8
0
void test_adapt_solid() {
	Grid_<Float, Float, 2> g(2, 0.0, 1, //
			2, 0.0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 7);
	//adp.adapt_full();
	// shape
	Shape2D cir;
	CreatCircle(cir, 0.0, 0.0, 1.0, 359);
	adp.adapt_inner_solid(cir);
	// show
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga;
	GnuplotActor_LeafNodes(ga, g);
	lga.push_back(ga);
	GnuplotActor_Shape2D(ga, cir);
	lga.push_back(ga);
	GnuplotShow(lga);
}
Exemplo n.º 9
0
inline void test_grid_2d() {
	Grid_<Float, Float, 2> g(2, 0, 1, //
			2, 0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	adp.adapt_full();

	//GnuplotShow_RootNodes(g);
	// test iterator
	int i = 0;
	Grid_2D::iterator_leaf iter = g.begin_leaf();
	for (; iter != g.end_leaf(); ++iter) {
		i++;
	}
	std::cout << "all     : " << g(0, 0)->count_all() << std::endl;
	std::cout << "leaf    : " << g(0, 0)->count_leaf() << std::endl;
	std::cout << "level 1 : " << g(0, 0)->count_level(1) << std::endl;
	std::cout << "level 2 : " << g(0, 0)->count_level(2) << std::endl;
}
Exemplo n.º 10
0
void test_stream_adaptor_perormance(void)
{
    uint32 loops=10485760;
#ifdef LINUX
    struct timeval tv1,tv2;
#elif defined(WIN32)
    long tc1;
#endif
    int8 i8='K';
    int16 i16=1024;
    int32 i32=1048576;
    char str_hello[33];
    memset(str_hello,'K',32);
    uint32 len_str=32;
    str_hello[32]=0;

    printf("********benchmark base overhead**********\n");
#ifdef LINUX
    gettimeofday(&tv1,0);
#elif defined(WIN32)
    tc1= ::GetTickCount();
#endif
    for(uint32 i=0; i<loops; i++) {}
#ifdef LINUX
    gettimeofday(&tv2,0);
    int32 tc=timeval_util_t::diff_of_timeval_tc(tv1,tv2);
#elif defined(WIN32)
    int32 tc=::GetTickCount() - tc1;
#endif
    //test results:2006-7-25
    //loops=10485760,tc=21
    printf("benchmark base overhead,loops=%d,tc=%d\n",
           loops,tc);
    //*************memory_stream_t performance*************
    {
        sp_mstream_t sp_stm=memory_stream_t::s_create();
#ifdef LINUX
        gettimeofday(&tv1,0);
#elif defined(WIN32)
        tc1=::GetTickCount();
#endif
        for(uint32 i=0; i<loops; i++)
        {
            //write int8
            if(sp_stm->write(&i8,sizeof(int8))!= sizeof(int8))
            {
                printf("write int8 failure\n");
                break;
            }
            /*
                            //write int32
                            if(sp_stm->write((int8*)&i32,sizeof(int32)) != sizeof(int32))
                            {
                                    printf("write int32 failure\n");
                                    break;
                            }

                            //write string
                            if(sp_stm->write((int8*)&len_str,sizeof(uint32)) != sizeof(uint32))
                            {
                                    printf("write uint32 failure\n");
                                    break;
                            }
                            if(sp_stm->write((int8*)str_hello,len_str) != len_str)
                            {
                                    printf("write string failure\n");
                                    break;
                            }
            */
        }
#ifdef LINUX
        gettimeofday(&tv2,0);
        int32 tc=timeval_util_t::diff_of_timeval_tc(tv1,tv2);
#elif defined(WIN32)
        int32 tc = ::GetTickCount() - tc1;
#endif
        uint32 wrote_len=sp_stm->seek(STM_SEEK_END,0);
        //test results:2006-7-25
        //i8:989,986,995,994,avg=991,net=991-21=970
        //i32:1057,1060,1060,1062,avg=1060,net=1060-21=1039
        //str(len=32):2809,2806,2802,2803,avg=2805,net=2805-21=2784
        //****test for revision,2008-3-25*****
        //i8:987,987,1004,989,avg=992,net=avg-24=968
        //i32:1064,1063,1061,1065,avg=1063,net=avg-24=1039
        //str(len=32):2831,2830,2831,2830,avg=2831,net=avg-24=2807
        printf("write to memory stream directly,len=%d,loops=%d,tc=%d\n",
               wrote_len,loops,tc);
    }

    //***************stream_adaptor_t performance***************
    {
        sp_mstream_t sp_stm=memory_stream_t::s_create();
        stream_adaptor_t adp((stream_it *)(memory_stream_t*)sp_stm,STM_ADP_OPT_STANDALONE);
        //adp.set_nbo();
        //adp.set_byte_order(BO_UNKNOWN);//BO_LITTLE_ENDIAN);
#ifdef LINUX
        gettimeofday(&tv1,0);
#elif defined(WIN32)
        tc1=::GetTickCount();
#endif
        for(uint32 i=0; i<loops; i++)
        {
            adp<<i8;
            //adp<<i32;
            //adp<<str_hello;
        }
#ifdef LINUX
        gettimeofday(&tv2,0);
        int32 tc=timeval_util_t::diff_of_timeval_tc(tv1,tv2);
#elif defined(WIN32)
        int32 tc=::GetTickCount() - tc1;
#endif
        uint32 wrote_len=sp_stm->seek(STM_SEEK_END,0);
        //test results:2006-7-25
        //i8:1093,1097,1096,1093,avg=1095,net=1095-21=1074,pdp(performance decrease percentage=(1074-970)/970=0.107,bw=74MB
        //i32:1156,1158,1155,1156,avg=1156,net=1156-21=1135,pdp=(1135-1039)/1039=0.092,bw=282MB
        //str(len=32):3194,3195,3191,3191,avg=3193,net=3193-21=3172,pdp=(3172-2784)/2784=0.139
        //===add network byte order feature====
        //disable nbo flag: about 1% performance descrease than adaptor without this feature,this descrease can be ignored
        //--2006-7-25
        //i32:1169,1167,1167,1168,avg=1168,net=1168-21=1147,pdp=(1147-1039)/1039=0.104
        //enabled nbo flag:incomparison with host byte order,pc of network byte order stream i/o is just 0.765,isn't good enough
        //,except for necessary,host byte order is preferred--2006-7-25
        //i32:1506,1502,1502,1504,avg=1504,net=1504-21=1483,pc=1135/1483=0.765//note,here is pc,but not pdp
        //****test for revision,2008-3-25*****
        //i8:1133,1140,1127,1168,avg=1142,net=avg-24=1118,pc=(1118-970)/970=0.152
        //i32:1356,1493,1374,1345,avg=1392,net=avg-24=1368,pdp=(1368-1039)/1039=0.317
        //str(len=32):3426,3437,3422,3437,avg=3427,net=avg-24=3403,pc=(3403-2807)/2807=0.212
        printf("write to stream by adaptor,len=%d,loops=%d,tc=%d\n",
               wrote_len,loops,tc);

    }
}
Exemplo n.º 11
0
void test_stream_adaptor()
{
    sp_mstream_t sp_stm=memory_stream_t::s_create();
    //pass test,2006-7-24
    //->
    printf("just created,sp_stm->get_ref_cnt:%d\n",sp_stm->get_ref_cnt());
    stream_adaptor_t adp((stream_it *)(memory_stream_t*)sp_stm,STM_ADP_OPT_STANDALONE);
    printf("after attach to adaptor,sp_stm->get_ref_cnt:%d\n",sp_stm->get_ref_cnt());
    //adp.attach((stream_it*)0);
    printf("after clear adaptor,sp_stm->get_ref_cnt:%d\n",sp_stm->get_ref_cnt());

    adp.set_nbo();
    //adp.set_byte_order(BO_UNKNOWN);

    adp<<(int8)(-8)<<(uint8)(8);
    adp<<(int16)(-32767)<<(uint16)(32767);
    adp<<(int32)(-1048576)<<(uint32)(1048576);
    adp<<"hello every one!!!";
    char ca[]= {'A','B','C'};
    adp<<stream_adaptor_t::raw_buf_t(ca,3);

    char cb[]="morining from bb_t!!!";
    bb_t bb;
    bb.fill_from(cb,sizeof(cb),0);
    adp<<bb;

    int8 i8=0;
    uint8 ui8=0;
    int16 i16=0;
    uint16 ui16=0;
    int32 i32=0;
    uint32 ui32=0;
    int8 str[32];
    stream_adaptor_t::raw_str_t raw_str(str,32,true); //len: control if the tail will be truncated
    stream_adaptor_t::raw_buf_t raw_buf(str,32);

    sp_stm->seek(STM_SEEK_BEGIN,0);
    adp>>i8>>ui8;
    printf("read from stream:i8=%d,ui8=%d\n",i8,ui8);

    adp>>i16>>ui16;
    printf("read from stream:i16=%d,ui16=%d\n",i16,ui16);

    adp>>i32>>ui32;
    printf("read from stream:i32=%d,ui32=%d\n",i32,ui32);


    adp>>raw_str;
    printf("read from stream:string=%s\n",str);

    char szTmp[4]= {0};
    stream_adaptor_t::raw_buf_t raw_buf_tmp(szTmp,4);
    adp>>raw_buf_tmp;
    for(int i=0; i<raw_buf_tmp.get_data_size(); ++i) printf("char in szTmp[%d]=%c\n",i,szTmp[i]);

    bb_t bbo;
    adp>>bbo;
    printf("read bb_t from stream:%s,size=%d\n",(int8*)bbo,bbo.get_filled_len());

    //test network byte order--pass test,2006-7-25
    printf("********read from a network byte order with/without transfer to host byte order********\n");
    sp_stm->seek(STM_SEEK_BEGIN,0);
    stream_adaptor_t adp1((stream_it*)(memory_stream_t*)sp_stm,STM_ADP_OPT_STANDALONE);
    adp1.set_nbo();

    adp1>>i8>>ui8;
    printf("read from stream:i8=%d,ui8=%d\n",i8,ui8);

    adp1>>i16>>ui16;
    printf("read from stream:i16=%d,ui16=%d\n",i16,ui16);

    adp1>>i32>>ui32;
    printf("read from stream:i32=%d,ui32=%d\n",i32,ui32);
    //<-
}