void shot_image_cross(sf_complex *wld_s,sf_complex *wld_r,float *image_z,int nx,int ny,struct shot_image_par_type image_par){ sf_complex ws,wr; int ihx,ihy,ix,iy,iihx,iihy,iohx,iohy; int shift_ix_s,shift_iy_s,shift_ix_r,shift_iy_r; int nimg[3]; d4(nx,image_par.nhy,image_par.nhx,nimg); iohy=(int)(image_par.ohy/image_par.dy); iohx=(int)(image_par.ohx/image_par.dx); for(iy=0;iy<ny;iy++){ for(ix=0;ix<nx;ix++){ for(ihy=0; ihy<image_par.nhy;ihy++){ //hy=ihy*image_par.dy+image_par.ohy; iihy=(int)(hy/image_par.dy); iihy=ihy+iohy; for(ihx=0;ihx<image_par.nhx;ihx++){ //hx=ihx*image_par.dx+image_par.ohx; iihx=(int)(hx/image_par.dx); iihx=ihx+iohx; shift_ix_s=ix-iihx; shift_iy_s=iy-iihy; shift_ix_r=ix+iihx; shift_iy_r=iy+iihy; if (shift_ix_s <0) shift_ix_s=0; if (shift_ix_s >=nx) shift_ix_s=nx-1; if (shift_ix_r <0) shift_ix_r=0; if (shift_ix_r >=nx) shift_ix_r=nx-1; if (shift_iy_s <0) shift_iy_s=0; if (shift_iy_s >=ny) shift_iy_s=ny-1; if (shift_iy_r <0) shift_iy_r=0; if (shift_iy_r >=ny) shift_iy_r=ny-1; ws=wld_s[i2(shift_iy_s,shift_ix_s,nx)]; wr=wld_r[i2(shift_iy_r,shift_ix_r,nx)]; image_z[i4(iy,ix,ihy,ihx,nimg)]+=crealf( conjf(ws)*wr); } } } } }
Base::Base(){ nombre_obj = "Base"; Tupla3f a(-1,0,1), b(-1,0,-1), c(1,0,-1), d(1,0,1), e(-1,0.5,1), f(-1,0.5,-1), g(1,0.5,-1), h(1,0.5,1); vertices.push_back(a); vertices.push_back(b); vertices.push_back(c); vertices.push_back(d); vertices.push_back(e); vertices.push_back(f); vertices.push_back(g); vertices.push_back(h); Tupla3i i1(0,7,4), i2(0,3,7), i3(3,6,7), i4(3,2,6), i5(2,5,6), i6(2,1,5), i7(1,4,5), i8(1,0,4), i9(4,6,7), i10(4,6,5), i11(0,2,1),i12(0,3,2); caras.push_back(i1); caras.push_back(i2); caras.push_back(i3); caras.push_back(i4); caras.push_back(i5); caras.push_back(i6); caras.push_back(i7); caras.push_back(i8); caras.push_back(i9); caras.push_back(i10); caras.push_back(i11); caras.push_back(i12); }
TEST(ArrayTest, getNumRows) { TwoDArray<int> i4(10, 5, 42); TwoDArray<double> d4(2, 9, 9.9); TwoDArray<std::string> s4(6, 8, "e"); EXPECT_EQ(10, i4.access(8,2)); EXPECT_EQ(2, d4.access(0,0)); EXPECT_EQ(6, s4.access(5,7)); }
int main () { i1(); i3(); i4(); i5(); e1(); e3(); e4(); e5(); }
void shot_image_stack(float *img,float mig_min_x,float mig_min_y,int mig_nx,int mig_ny,sf_file tag, struct shot_image_par_type image_par) /*< stack image >*/ { float *tmp_img; float img_min_x,img_max_x,img_min_y,img_max_y,img_dx,img_dy; float mig_max_x,rite_min_x,rite_max_x; int img_ny,img_nx,rite_nx; int n_hy_hx,img_nhx,img_nhy,nz; int ntmp_img[2],nimg[3]; int rite_ix_b,array_ix_b; int block_size,block_i; int iy,rite_iy,ix,i_hy_hx,iz; img_min_x=image_par.min_x; img_max_x=image_par.max_x; img_min_y=image_par.min_y; img_max_y=image_par.max_y; img_dx=image_par.dx; img_dy=image_par.dy; img_ny=image_par.ny; img_nx=image_par.nx; img_nhx=image_par.nhx; img_nhy=image_par.nhy; nz=image_par.nz; mig_max_x=((float)(mig_nx-1))*img_dx+mig_min_x; rite_min_x=SF_MAX(img_min_x,mig_min_x); rite_max_x=SF_MIN(img_max_x,mig_max_x); rite_nx=(rite_max_x-rite_min_x)/img_dx+1; n_hy_hx= img_nhy*img_nhx; d3(n_hy_hx,nz,ntmp_img); d4(mig_ny,mig_nx,n_hy_hx,nimg); if (rite_nx >=1){ rite_ix_b= (rite_min_x-img_min_x)/img_dx; array_ix_b=(rite_min_x-mig_min_x)/img_dx; tmp_img=sf_floatalloc(rite_nx*n_hy_hx*nz); block_size=4*n_hy_hx*nz; for(iy=0;iy<mig_ny;iy++){ vector_value_f(tmp_img,0.0,rite_nx*n_hy_hx*nz); rite_iy= iy+(mig_min_y-img_min_y)/img_dy; if (rite_iy < img_ny && rite_iy>= 0){ block_i=rite_iy*img_nx+rite_ix_b; sf_seek(tag,block_i*block_size,SEEK_SET); sf_floatread(tmp_img,rite_nx*n_hy_hx*nz,tag); for(ix=0;ix<rite_nx;ix++){ for(i_hy_hx=0;i_hy_hx<n_hy_hx;i_hy_hx++){ for(iz=0;iz<nz;iz++){ tmp_img[i3(ix,i_hy_hx,iz,ntmp_img)]+=img[i4(iz,iy,array_ix_b+ix,i_hy_hx,nimg)]; } } } sf_seek(tag,block_i*block_size,SEEK_SET); sf_floatwrite(tmp_img,rite_nx*n_hy_hx*nz,tag); } } free(tmp_img); } }
TEST( CFPP_String_Iterator, MCTOR ) { CF::String s( "hello" ); CF::String::Iterator i1; CF::String::Iterator i2( std::move( i1 ) ); CF::String::Iterator i3( s.begin() ); CF::String::Iterator i4( std::move( i3 ) ); ASSERT_EQ( *( i1 ), 0 ); ASSERT_EQ( *( i2 ), 0 ); ASSERT_EQ( *( i3 ), 0 ); ASSERT_EQ( *( i4 ), 'h' ); }
void shot_image_cross_tilt(sf_complex *wld_s,sf_complex *wld_r,float *image_z,int nx,int ny, struct shot_image_par_type image_par,int nx_iz) /*< cross correlation >*/ { sf_complex ws,wr; int ihx,ihy,ix,iy,iihx,iihy,iohx,iohy; int shift_ix_s,shift_iy_s,shift_ix_r,shift_iy_r; float eps; int nimg[3]; int nsmooth; nsmooth=200; eps=1200; d4(nx,image_par.nhy,image_par.nhx,nimg); iohy=(int)(image_par.ohy/image_par.dy); iohx=(int)(image_par.ohx/image_par.dx); for(iy=0;iy<ny;iy++){ for(ix=0;ix<nx_iz;ix++){ for(ihy=0; ihy<image_par.nhy;ihy++){ //hy=ihy*image_par.dy+image_par.ohy; iihy=(int)(hy/image_par.dy); iihy=ihy+iohy; for(ihx=0;ihx<image_par.nhx;ihx++){ //hx=ihx*image_par.dx+image_par.ohx; iihx=(int)(hx/image_par.dx); iihx=ihx+iohx; shift_ix_s=ix-iihx; shift_iy_s=iy-iihy; shift_ix_r=ix+iihx; shift_iy_r=iy+iihy; if (shift_ix_s <0) shift_ix_s=0; if (shift_ix_s >=nx_iz) shift_ix_s=nx_iz-1; if (shift_ix_r <0) shift_ix_r=0; if (shift_ix_r >=nx_iz) shift_ix_r=nx_iz-1; if (shift_iy_s <0) shift_iy_s=0; if (shift_iy_s >=ny) shift_iy_s=ny-1; if (shift_iy_r <0) shift_iy_r=0; if (shift_iy_r >=ny) shift_iy_r=ny-1; ws=wld_s[i2(shift_iy_s,shift_ix_s,nx)]; wr=wld_r[i2(shift_iy_r,shift_ix_r,nx)]; // wait for nx /* de=0.0; for (ismooth=1;ismooth<=nsmooth;ismooth++){ ixsmooth=shift_ix_s-nsmooth/2+ismooth; if (ixsmooth<0) ixsmooth=0; if (ixsmooth>=nx_iz) ixsmooth=nx_iz-1; de=de+wld_s[i2(shift_iy_s,ixsmooth,nx)]*conjg(wld_s[i2(shift_iy_s,ixsmooth,nx)]); } de=de/nsmooth; */ //image_z[i4(iy,ix,ihy,ihx,nimg)]+=real( conjg(ws)*wr/(conjg(ws)*ws+eps) ); //image_z[i4(iy,ix,ihy,ihx,nimg)]+=real( conjg(ws)*wr/(de) ); image_z[i4(iy,ix,ihy,ihx,nimg)]+=crealf( conjf(ws)*wr); //image_z[i4(iy,ix,ihy,ihx,nimg)]+=real( conjg(ws)*ws); } } } } }
static void TestInteger32() { // constructors SnmpInt32 i1; ACE_ASSERT(i1 == def); SnmpInt32 i2(l); ACE_ASSERT(i2 == l); SnmpInt32 i3(nl); ACE_ASSERT(i3 == nl); SnmpInt32 i4(ul); ACE_ASSERT(i4 == ul); SnmpInt32 i5(i); ACE_ASSERT(i5 == i); SnmpInt32 i6(ni); ACE_ASSERT(i6 == ni); SnmpInt32 i7(ui); ACE_ASSERT(i7 == ui); SnmpInt32 *i8 = new SnmpInt32(i5); ACE_ASSERT(i8 != 0); delete i8; ACE_DEBUG ((LM_DEBUG, "(%P|%t) i1(\"\") [%u]\n", (unsigned long)i1)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) i2(\"%u\") [%u]\n", l, (unsigned long)i2)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) i3(\"%u\") [%u]\n", nl, (unsigned long)i3)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) i4(\"%u\") [%u]\n", ul, (unsigned long)i4)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) i5(\"%u\") [%u]\n", i, (unsigned long)i5)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) i6(\"%u\") [%u]\n", ni, (unsigned long)i6)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) i7(\"%u\") [%u]\n", ui, (unsigned long)i7)); // assignent i1 = i2; // obj ACE_ASSERT(i1 == i2); i1 = i1; // self ACE_ASSERT(i1 == i1); i1 = def; // unsigned long ACE_ASSERT(i1 == def); i1 = us; // unsigned short ACE_ASSERT(i1 == us); i1 = si; // unsigned short ACE_ASSERT(i1 == si); }
int main(int argc, char * argv[]) { printf("hello\n"); Polygon p1; Polygon p2; Polygons ps1; Polygons ps2; IntPoint i1(0, 0); IntPoint i2(0, 100); IntPoint i3(100, 100); IntPoint i4(100, 0); IntPoint j1(0, 0); IntPoint j2(50, 200); IntPoint j3(100, 0); p1.push_back(i1); p1.push_back(i2); p1.push_back(i3); p1.push_back(i4); p2.push_back(j1); p2.push_back(j2); p2.push_back(j3); ps1.push_back(p1); ps2.push_back(p2); Clipper clipper; clipper.AddPolygons(ps1, ptSubject); clipper.AddPolygons(ps2, ptClip); Polygons soln; clipper.Execute(ctIntersection, soln); for(int i = 0; i < soln.size(); i++) { Polygon& p = soln[i]; for(int j = 0; j < p.size(); j++) { printf("Point:(%lld,%lld)\n", p[j].X, p[j].Y); } } printf("hehe\n"); return 0; }
void getpar (int i, int s, int k, int xi, int N, int ss, int nk, int cc0, int cc1, int fn, int bswitch, int gsb0[], double gsb0val[], int gsb1[], double gsb1val[], double *g0, double *sigma, double *z) { /* bswitch determines whether to use naive (0) or caught before (1) */ int wxi; int c; wxi = i4(i,s,k,xi,N,ss,nk); *z = 0; if (bswitch == 0) { c = gsb0[wxi]-1; *g0 = gsb0val[c]; *sigma = gsb0val[cc0 + c]; if (par3(fn)) *z = gsb0val[2* cc0 + c]; } else { c = gsb1[wxi]-1; *g0 = gsb1val[c]; *sigma = gsb1val[cc1 + c]; if (par3(fn)) *z = gsb1val[2* cc1 + c]; } }
void run () { testcase ("add/traverse"); beast::Journal const j; // debug journal tests::TestFamily f(j); // h3 and h4 differ only in the leaf, same terminal node (level 19) uint256 h1, h2, h3, h4, h5; h1.SetHex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); h2.SetHex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe"); h3.SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8"); h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); SHAMap sMap (SHAMapType::FREE, f); SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5)); unexpected (!sMap.addItem (i2, true, false), "no add"); unexpected (!sMap.addItem (i1, true, false), "no add"); auto i = sMap.begin(); auto e = sMap.end(); unexpected (i == e || (*i != i1), "bad traverse"); ++i; unexpected (i == e || (*i != i2), "bad traverse"); ++i; unexpected (i != e, "bad traverse"); sMap.addItem (i4, true, false); sMap.delItem (i2.key()); sMap.addItem (i3, true, false); i = sMap.begin(); e = sMap.end(); unexpected (i == e || (*i != i1), "bad traverse"); ++i; unexpected (i == e || (*i != i3), "bad traverse"); ++i; unexpected (i == e || (*i != i4), "bad traverse"); ++i; unexpected (i != e, "bad traverse"); testcase ("snapshot"); SHAMapHash mapHash = sMap.getHash (); std::shared_ptr<SHAMap> map2 = sMap.snapShot (false); unexpected (sMap.getHash () != mapHash, "bad snapshot"); unexpected (map2->getHash () != mapHash, "bad snapshot"); unexpected (!sMap.delItem (sMap.begin()->key()), "bad mod"); unexpected (sMap.getHash () == mapHash, "bad snapshot"); unexpected (map2->getHash () != mapHash, "bad snapshot"); testcase ("build/tear"); { std::vector<uint256> keys(8); keys[0].SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[1].SetHex ("b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[2].SetHex ("b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[3].SetHex ("b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[4].SetHex ("b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[5].SetHex ("b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[6].SetHex ("f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); keys[7].SetHex ("292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); std::vector<uint256> hashes(8); hashes[0].SetHex ("B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C64B6281F7F"); hashes[1].SetHex ("FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A8831845467FB2ECE266"); hashes[2].SetHex ("4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51AE756795B75"); hashes[3].SetHex ("7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC6C74F93E07"); hashes[4].SetHex ("395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596462B0E3A3E"); hashes[5].SetHex ("D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D98A84D9DDE4"); hashes[6].SetHex ("76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF94361143615"); hashes[7].SetHex ("DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA02BBE7230E5"); SHAMap map (SHAMapType::FREE, f); expect (map.getHash() == zero, "bad initial empty map hash"); for (int i = 0; i < keys.size(); ++i) { SHAMapItem item (keys[i], IntToVUC (i)); map.addItem (item, true, false); expect (map.getHash().as_uint256() == hashes[i], "bad buildup map hash"); } for (int i = keys.size() - 1; i >= 0; --i) { expect (map.getHash().as_uint256() == hashes[i], "bad teardown hash"); map.delItem (keys[i]); } expect (map.getHash() == zero, "bad final empty map hash"); } }
i4 IIgetfldio(i2 *ind, i4 variable, i4 type, i4 len, PTR data, char *name) { char *namestr; char fbuf[MAXFRSNAME+1]; DB_EMBEDDED_DATA edv; DB_DATA_VALUE *dbvptr; DB_DATA_VALUE oper_dbv; DB_DATA_VALUE dbvcop; i4 oper; ADF_CB *cb; bool errflag = FALSE; i4 getop = 0; i4 (*oldproc)(); bool disp_msgs = TRUE; /* Check field name for validity */ namestr = IIstrconv(II_CONV, name, fbuf, (i4)MAXFRSNAME); if (namestr == NULL) { IIFDerror(RTRFFL, 2, IIfrmio->fdfrmnm, ERx("")); return(FALSE); } /* Set up an EDV to describe the caller's parameters. */ edv.ed_type = type; edv.ed_length = len; edv.ed_data = (PTR) data; edv.ed_null = ind; cb = FEadfcb(); if (IIfrscb->frs_globs->enabled & GETMSGS_OFF) { disp_msgs = FALSE; oldproc = IIseterr(IIFRgmoGetmsgsOff); } /* ** If getting an 'oper', not a value, special processing required. ** Operators are not returned from FRAME as DBV's, so we must build ** one so we can follow the normal path and convert to the final EDV. */ getop = IIgetoper( (i4) 0 ); if ( getop ) { oper_dbv.db_datatype = DB_INT_TYPE; oper_dbv.db_length = sizeof(i4); oper_dbv.db_prec = 0; oper_dbv.db_data = (PTR) &oper; /* ** Make sure the frame is in Query mode, else return NOOP. */ if (IIfrmio->fdrunmd != fdrtQRY) oper = fdNOP; else FDqryop( IIfrmio->fdrunfrm, namestr, (i4 *) oper_dbv.db_data ); dbvptr = &oper_dbv; } else if (IIfrmio->fdrunmd == fdrtQRY) { /* ** If in query mode, we must use a different routine ** to retrieve the data portion of the field. This ** routine also strips off the operator. */ if (!FDqryfld(IIfrmio->fdrunfrm, namestr, &dbvptr)) errflag = TRUE; } else { IIfrscb->frs_event->eval_aggs = TRUE; /* ** Get data portion of the field */ if (!FDgetfld(IIfrmio->fdrunfrm, namestr, &dbvptr)) errflag = TRUE; IIfrscb->frs_event->eval_aggs = FALSE; } /* ** If "errflag" is set at this point, then it was not ** possible to get the DB_DATA_VALUE pointer for a field. ** ** Trim trailing blanks on character-type fields */ if ( errflag == FALSE && ( IIftrim( dbvptr, &dbvcop ) != OK ) ) errflag = TRUE; /* ** Convert the DBV containing the field's value to an EDV */ if ( errflag == FALSE && ( adh_dbcvtev( cb, &dbvcop, &edv ) != OK ) ) { if (cb->adf_errcb.ad_errcode == E_AD1012_NULL_TO_NONNULL) { IIFDerror(RTRNLNNL, 2, IIfrmio->fdfrmnm, namestr); } else { IIFDerror(RTGFERR, 2, IIfrmio->fdfrmnm, namestr); } errflag = TRUE; } if (!disp_msgs) _VOID_ IIseterr(oldproc); if ( errflag == TRUE ) return (FALSE); else return (TRUE); }
void MarchingCubeTriangulator::Triangulate(ScalarFieldBuilders::ScalarFieldCreator& inData,const SpatialDiscretization::weight_t& volId, progressOperation& mainProcess) { weigh_parameters_t weigh_parameters; weigh_parameters.volId=volId; BeginFeedingFaces(); ivec3 coordinates; long cellCount_m_one(inData.GetDomainSize()-1); ivec3 i1(1,0,0), i2(1,0,1), i3(0,0,1), i4(0,1,0), i5(1,1,0), i6(1,1,1), i7(0,1,1); PolygoniseAlgo::GRIDCELL grid; PolygoniseAlgo::TRIANGLE triList[5]; int nbtri; progressOperation thisProcess(&mainProcess, (unsigned int) (cellCount_m_one * cellCount_m_one)); for(coordinates.x=0;coordinates.x<cellCount_m_one;coordinates.x++) { for(coordinates.y=0;coordinates.y<cellCount_m_one;coordinates.y++) { progressOperation thisSubProcess(&thisProcess,1); if(VariationWithinFourZ(ivec2(coordinates.x,coordinates.y),inData)) { grid.p[3] = inData.GetCenterCellCoordinates(coordinates+i3); grid.p[2] = inData.GetCenterCellCoordinates(coordinates+i2); grid.p[7] = inData.GetCenterCellCoordinates(coordinates+i7); grid.p[6] = inData.GetCenterCellCoordinates(coordinates+i6); grid.val[3]=WeightEvaluation(inData.GetMatrixValue(coordinates),weigh_parameters); grid.val[2]=WeightEvaluation(inData.GetMatrixValue(coordinates+i1),weigh_parameters); grid.val[7]=WeightEvaluation(inData.GetMatrixValue(coordinates+i4),weigh_parameters); grid.val[6]=WeightEvaluation(inData.GetMatrixValue(coordinates+i5),weigh_parameters); for(coordinates.z=0;coordinates.z<cellCount_m_one;coordinates.z++) { //TODO Computation on x,y loop grid.p[0] = grid.p[3]; grid.p[1] = grid.p[2]; grid.p[4]= grid.p[7]; grid.p[5] = grid.p[6]; grid.p[2] = inData.GetCenterCellCoordinates(coordinates+i2); grid.p[3] = inData.GetCenterCellCoordinates(coordinates+i3); grid.p[6] = inData.GetCenterCellCoordinates(coordinates+i6); grid.p[7] = inData.GetCenterCellCoordinates(coordinates+i7); grid.val[0]=grid.val[3]; grid.val[1]=grid.val[2]; grid.val[4]=grid.val[7]; grid.val[5]=grid.val[6]; grid.val[2]=WeightEvaluation(inData.GetMatrixValue(coordinates+i2),weigh_parameters); grid.val[3]=WeightEvaluation(inData.GetMatrixValue(coordinates+i3),weigh_parameters); grid.val[6]=WeightEvaluation(inData.GetMatrixValue(coordinates+i6),weigh_parameters); grid.val[7]=WeightEvaluation(inData.GetMatrixValue(coordinates+i7),weigh_parameters); nbtri=PolygoniseAlgo::Polygonise(grid,0,triList); if(nbtri>0) { for(int idtri=0;idtri<nbtri;idtri++) { AddFace((const decimal *)&(triList[idtri].p[2]), (const decimal *)&(triList[idtri].p[1]), (const decimal *)&(triList[idtri].p[0])); } } } } } } FinishFeedingFaces(); }
void run () { testcase ("add/traverse"); beast::manual_clock <std::chrono::steady_clock> clock; // manual advance clock beast::journal const j; // debug journal fullbelowcache fullbelowcache ("test.full_below", clock); treenodecache treenodecache ("test.tree_node_cache", 65536, 60, clock, j); nodestore::dummyscheduler scheduler; auto db = nodestore::manager::instance().make_database ( "test", scheduler, j, 0, parsedelimitedkeyvaluestring("type=memory|path=shamap_test")); // h3 and h4 differ only in the leaf, same terminal node (level 19) uint256 h1, h2, h3, h4, h5; h1.sethex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); h2.sethex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe"); h3.sethex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8"); h4.sethex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8"); h5.sethex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); shamap smap (smtfree, fullbelowcache, treenodecache, *db, handler(), beast::journal()); shamapitem i1 (h1, inttovuc (1)), i2 (h2, inttovuc (2)), i3 (h3, inttovuc (3)), i4 (h4, inttovuc (4)), i5 (h5, inttovuc (5)); unexpected (!smap.additem (i2, true, false), "no add"); unexpected (!smap.additem (i1, true, false), "no add"); shamapitem::pointer i; i = smap.peekfirstitem (); unexpected (!i || (*i != i1), "bad traverse"); i = smap.peeknextitem (i->gettag ()); unexpected (!i || (*i != i2), "bad traverse"); i = smap.peeknextitem (i->gettag ()); unexpected (i, "bad traverse"); smap.additem (i4, true, false); smap.delitem (i2.gettag ()); smap.additem (i3, true, false); i = smap.peekfirstitem (); unexpected (!i || (*i != i1), "bad traverse"); i = smap.peeknextitem (i->gettag ()); unexpected (!i || (*i != i3), "bad traverse"); i = smap.peeknextitem (i->gettag ()); unexpected (!i || (*i != i4), "bad traverse"); i = smap.peeknextitem (i->gettag ()); unexpected (i, "bad traverse"); testcase ("snapshot"); uint256 maphash = smap.gethash (); shamap::pointer map2 = smap.snapshot (false); unexpected (smap.gethash () != maphash, "bad snapshot"); unexpected (map2->gethash () != maphash, "bad snapshot"); unexpected (!smap.delitem (smap.peekfirstitem ()->gettag ()), "bad mod"); unexpected (smap.gethash () == maphash, "bad snapshot"); unexpected (map2->gethash () != maphash, "bad snapshot"); }
//----------------------------------------------------------------------------- //! //----------------------------------------------------------------------------- tApTurnSelectWidgetAC1242AC7080::tApTurnSelectWidgetAC1242AC7080( tPilotController& pilotDevice, QWidget* parent ) : tApWidget( pilotDevice, parent ), m_RequestedTurn( tPilotCommandInterface::PILOT_MODE_STANDBY ) { m_pGridMenu = new tGridMenu( 3, 3, this, false ); m_pGridMenu->SetIndexing( true ); setFocusProxy( m_pGridMenu ); QFont f = font(); f.setPixelSize( style()->pixelMetric( NPM( tNOSStyle::NPM_FontSizeSmallest ) ) ); m_pGridMenu->setFont( f ); QAction* pUTurnAction = new QAction( this ); QIcon i( QPixmap( tPath::ResourceFile( "simrad/autopilot/uturn.png" ) ) ); pUTurnAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_U_TURN ) ); pUTurnAction->setIcon( i ); pUTurnAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_U_TURN ); m_pGridMenu->AddAction( pUTurnAction, true ); Connect( pUTurnAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QAction* pCTurnAction = new QAction( this ); QIcon i2( QPixmap( tPath::ResourceFile( "simrad/autopilot/cturn.png" ) ) ); pCTurnAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_C_TURN ) ); pCTurnAction->setIcon( i2 ); pCTurnAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_C_TURN ); m_pGridMenu->AddAction( pCTurnAction, true ); Connect( pCTurnAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QAction* pSpiralAction = new QAction( this ); QIcon i3( QPixmap( tPath::ResourceFile( "simrad/autopilot/spiral.png" ) ) ); pSpiralAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_SPIRAL ) ); pSpiralAction->setIcon( i3 ); pSpiralAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_SPIRAL ); m_pGridMenu->AddAction( pSpiralAction, true ); Connect( pSpiralAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QAction* pZigzagAction = new QAction( this ); QIcon i4( QPixmap( tPath::ResourceFile( "simrad/autopilot/zigzag.png" ) ) ); pZigzagAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_ZIGZAG ) ); pZigzagAction->setIcon( i4 ); pZigzagAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_ZIGZAG ); m_pGridMenu->AddAction( pZigzagAction, true ); Connect( pZigzagAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QAction* pSquareAction = new QAction( this ); QIcon i5( QPixmap( tPath::ResourceFile( "simrad/autopilot/square.png" ) ) ); pSquareAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_SQUARE ) ); pSquareAction->setIcon( i5 ); pSquareAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_SQUARE ); m_pGridMenu->AddAction( pSquareAction, true ); Connect( pSquareAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QAction* pLazySAction = new QAction( this ); QIcon i6( QPixmap( tPath::ResourceFile( "simrad/autopilot/lazys.png" ) ) ); pLazySAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_LAZY_S ) ); pLazySAction->setIcon( i6 ); pLazySAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_LAZY_S ); m_pGridMenu->AddAction( pLazySAction, true ); Connect( pLazySAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QAction* pDCTAction = new QAction( this ); QIcon i7( QPixmap( tPath::ResourceFile( "simrad/autopilot/depth.png" ) ) ); pDCTAction->setText( m_PilotDevice.GetCommandInterface()->ModeAbbreviation( tPilotCommandInterface::PILOT_MODE_DEPTH_CONTOUR ) ); pDCTAction->setIcon( i7 ); pDCTAction->setProperty( "turnID", (int)tPilotCommandInterface::PILOT_MODE_DEPTH_CONTOUR ); m_pGridMenu->InsertAction( pDCTAction, 2, 1, true ); Connect( pDCTAction, SIGNAL( triggered() ), this, SLOT( OnTurnAction() ) ); QVBoxLayout* pMainLayout = new QVBoxLayout(); pMainLayout->setContentsMargins( 5, 5, 5, 5 ); pMainLayout->setSpacing( 5 ); pMainLayout->addWidget( m_pGridMenu, 0 ); setLayout( pMainLayout ); m_pGridMenu->SetSelectedItem( 1, 1 ); ShowCloseButton(); }
void simdetect ( int *detect, /* detector -1 single, 0 multi, 1 proximity, 2 count,... */ double *gsb0val, /* Parameter values (matrix nr= comb of g0,sigma,b nc=3) [naive animal] */ double *gsb1val, /* Parameter values (matrix nr= comb of g0,sigma,b nc=3) [caught before] */ int *cc0, /* number of g0/sigma/b combinations for naive animals */ int *cc1, /* number of g0/sigma/b combinations for caught before */ int *gsb0, /* lookup which g0/sigma/b combination to use for given g, S, K [naive animal] */ int *gsb1, /* lookup which g0/sigma/b combination to use for given n, S, K [caught before] */ int *N, /* number of animals */ int *ss, /* number of occasions */ int *kk, /* number of traps */ int *nmix, /* number of classes */ int *knownclass, /* known membership of 'latent' classes */ double *animals, /* x,y points of animal range centres (first x, then y) */ double *traps, /* x,y locations of traps (first x, then y) */ double *dist2, /* distances squared (optional: -1 if unused) */ double *Tsk, /* ss x kk array of 0/1 usage codes or effort */ int *btype, /* code for behavioural response 0 none 1 individual 2 individual, trap-specific 3 trap-specific */ int *Markov, /* learned vs transient behavioural response 0 learned 1 Markov */ int *binomN, /* number of trials for 'count' detector modelled with binomial */ double *miscparm, /* detection threshold on transformed scale, etc. */ int *fn, /* code 0 = halfnormal, 1 = hazard, 2 = exponential, 3 = uniform */ int *maxperpoly, /* */ int *n, /* number of individuals caught */ int *caught, /* sequence number in session (0 if not caught) */ double *detectedXY, /* x,y locations of detections */ double *signal, /* vector of signal strengths, one per detection */ int *value, /* return value array of trap locations n x s */ int *resultcode ) { double d2val; double p; int i,j,k,l,s; int ik; int nc = 0; int nk = 0; /* number of detectors (polygons or transects when *detect==6,7) */ int count = 0; int *caughtbefore; int *x; /* mixture class of animal i */ double *pmix; double runif; int wxi = 0; int c = 0; int gpar = 2; double g0 = 0; double sigma = 0; double z = 0; double Tski = 1.0; double *work = NULL; double *noise = NULL; /* detectfn 12,13 only */ int *sortorder = NULL; double *sortkey = NULL; /* *detect may take values - -1 single-catch traps 0 multi-catch traps 1 binary proximity detectors 2 count proximity detectors 5 signal detectors 6 polygon detectors 7 transect detectors */ /*========================================================*/ /* 'single-catch only' declarations */ int tr_an_indx = 0; int nanimals; int ntraps; int *occupied = NULL; int *intrap = NULL; struct trap_animal *tran = NULL; double event_time; int anum = 0; int tnum = 0; int nextcombo; int finished; int OK; /*========================================================*/ /* 'multi-catch only' declarations */ double *h = NULL; /* multi-catch only */ double *hsum = NULL; /* multi-catch only */ double *cump = NULL; /* multi-catch only */ /*========================================================*/ /* 'polygon & transect only' declarations */ int nd = 0; int cumk[maxnpoly+1]; int sumk; /* total number of vertices */ int g=0; int *gotcha; double xy[2]; int n1,n2,t; double par[3]; int np = 1; /* n points each call of gxy */ double w, ws; int maxdet=1; double *cumd = NULL; struct rpoint *line = NULL; struct rpoint xyp; struct rpoint animal; double lx; double maxg = 0; double lambdak; /* temp value for Poisson rate */ double grx; /* temp value for integral gr */ double H; int J; int maybecaught; double dx,dy,d; double pks; double sumhaz; /*========================================================*/ /* 'signal-strength only' declarations */ double beta0; double beta1; double muS; double sdS; double muN = 0; double sdN = 1; double signalvalue; double noisevalue; double cut; double *ex; /*========================================================*/ /* MAIN LINE */ gotcha = &g; *resultcode = 1; caughtbefore = (int *) R_alloc(*N * *kk, sizeof(int)); x = (int *) R_alloc(*N, sizeof(int)); for (i=0; i<*N; i++) x[i] = 0; pmix = (double *) R_alloc(*nmix, sizeof(double)); /* ------------------------------------------------------ */ /* pre-compute distances */ if (dist2[0] < 0) { dist2 = (double *) S_alloc(*kk * *N, sizeof(double)); makedist2 (*kk, *N, traps, animals, dist2); } else { squaredist (*kk, *N, dist2); } /* ------------------------------------------------------ */ if ((*detect < -1) || (*detect > 7)) return; if (*detect == -1) { /* single-catch only */ occupied = (int*) R_alloc(*kk, sizeof(int)); intrap = (int*) R_alloc(*N, sizeof(int)); tran = (struct trap_animal *) R_alloc(*N * *kk, sizeof(struct trap_animal)); /* 2*sizeof(int) + sizeof(double)); */ } if (*detect == 0) { /* multi-catch only */ h = (double *) R_alloc(*N * *kk, sizeof(double)); hsum = (double *) R_alloc(*N, sizeof(double)); cump = (double *) R_alloc(*kk+1, sizeof(double)); cump[0] = 0; } if (*detect == 5) { /* signal only */ maxdet = *N * *ss * *kk; if (!((*fn == 10) || (*fn == 11))) error ("simsecr not implemented for this combination of detector & detectfn"); } if ((*detect == 3) || (*detect == 4) || (*detect == 6) || (*detect == 7)) { /* polygon or transect */ cumk[0] = 0; for (i=0; i<maxnpoly; i++) { /* maxnpoly much larger than npoly */ if (kk[i]<=0) break; cumk[i+1] = cumk[i] + kk[i]; nk++; } sumk = cumk[nk]; if ((*detect == 6) || (*detect == 7)) maxdet = *N * *ss * nk * *maxperpoly; else maxdet = *N * *ss; } else nk = *kk; if ((*detect == 4) || (*detect == 7)) { /* transect only */ line = (struct rpoint *) R_alloc(sumk, sizeof(struct rpoint)); cumd = (double *) R_alloc(sumk, sizeof(double)); /* coordinates of vertices */ for (i=0; i<sumk; i++) { line[i].x = traps[i]; line[i].y = traps[i+sumk]; } /* cumulative distance along line; all transects end on end */ for (k=0; k<nk; k++) { cumd[cumk[k]] = 0; for (i=cumk[k]; i<(cumk[k+1]-1); i++) { cumd[i+1] = cumd[i] + distance(line[i], line[i+1]); } } } if ((*detect==3) || (*detect==4) || (*detect==5) || (*detect==6) || (*detect==7)) { work = (double*) R_alloc(maxdet*2, sizeof(double)); /* twice size needed for signal */ sortorder = (int*) R_alloc(maxdet, sizeof(int)); sortkey = (double*) R_alloc(maxdet, sizeof(double)); } if ((*fn==12) || (*fn==13)) { noise = (double*) R_alloc(maxdet*2, sizeof(double)); /* twice size needed for signal */ } GetRNGstate(); gpar = 2; if ((*fn == 1) || (*fn == 3) || (*fn == 5)|| (*fn == 6) || (*fn == 7) || (*fn == 8) || (*fn == 10) || (*fn == 11)) gpar ++; /* ------------------------------------------------------------------------- */ /* mixture models */ /* may be better to pass pmix */ if (*nmix>1) { if (*nmix>2) error("simsecr nmix>2 not implemented"); gpar++; /* these models have one more detection parameter */ for (i=0; i<*nmix; i++) { wxi = i4(0,0,0,i,*N,*ss,nk); c = gsb0[wxi] - 1; pmix[i] = gsb0val[*cc0 * (gpar-1) + c]; /* assuming 4-column gsb */ } for (i=0; i<*N; i++) { if (knownclass[i] > 1) x[i] = knownclass[i] - 2; /* knownclass=2 maps to x=0 etc. */ else x[i] = rdiscrete(*nmix, pmix) - 1; } } /* ------------------------------------------------------------------------- */ /* zero caught status */ for (i=0; i<*N; i++) caught[i] = 0; for (i=0; i<*N; i++) for (k=0; k < nk; k++) caughtbefore[k * (*N-1) + i] = 0; /* ------------------------------------------------------------------------- */ /* MAIN LOOP */ for (s=0; s<*ss; s++) { /* ------------------ */ /* single-catch traps */ if (*detect == -1) { /* initialise day */ tr_an_indx = 0; nanimals = *N; ntraps = nk; for (i=0; i<*N; i++) intrap[i] = 0; for (k=0; k<nk; k++) occupied[k] = 0; nextcombo = 0; /* make tran */ for (i=0; i<*N; i++) { /* animals */ for (k=0; k<nk; k++) { /* traps */ Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, k, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); /* d2val = d2(i,k, animals, traps, *N, nk); */ d2val = d2L(k, i, dist2, nk); p = pfn(*fn, d2val, g0, sigma, z, miscparm, 1e20); /* effectively inf w2 */ if (fabs(Tski-1) > 1e-10) p = 1 - pow(1-p, Tski); event_time = randomtime(p); if (event_time <= 1) { tran[tr_an_indx].time = event_time; tran[tr_an_indx].animal = i; /* 0..*N-1 */ tran[tr_an_indx].trap = k; /* 0..nk-1 */ tr_an_indx++; } } } } /* end of make tran */ if (tr_an_indx > 1) probsort (tr_an_indx, tran); while ((nextcombo < tr_an_indx) && (nanimals>0) && (ntraps>0)) { finished = 0; OK = 0; while ((1-finished)*(1-OK) > 0) { /* until finished or OK */ if (nextcombo >= (tr_an_indx)) finished = 1; /* no more to process */ else { anum = tran[nextcombo].animal; tnum = tran[nextcombo].trap; OK = (1-occupied[tnum]) * (1-intrap[anum]); /* not occupied and not intrap */ nextcombo++; } } if (finished==0) { /* Record this capture */ occupied[tnum] = 1; intrap[anum] = tnum+1; /* trap = k+1 */ nanimals--; ntraps--; } } for (i=0; i<*N; i++) { if (intrap[i]>0) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; /* nc-th animal to be captured */ for (j=0; j<*ss; j++) value[*ss * (nc-1) + j] = 0; } value[*ss * (caught[i]-1) + s] = intrap[i]; /* trap = k+1 */ } } } /* -------------------------------------------------------------------------- */ /* multi-catch trap; only one site per occasion (drop last dimension of capt) */ else if (*detect == 0) { for (i=0; i<*N; i++) { hsum[i] = 0; for (k=0; k<nk; k++) { Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, k, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); /* d2val = d2(i,k, animals, traps, *N, nk); */ d2val = d2L(k, i, dist2, nk); p = pfn(*fn, d2val, g0, sigma, z, miscparm, 1e20); h[k * *N + i] = - Tski * log(1 - p); hsum[i] += h[k * *N + i]; } } for (k=0; k<nk; k++) { cump[k+1] = cump[k] + h[k * *N + i]/hsum[i]; } if (Random() < (1-exp(-hsum[i]))) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (j=0; j<*ss; j++) value[*ss * (nc-1) + j] = 0; } /* find trap with probability proportional to p searches cumulative distribution of p */ runif = Random(); k = 0; while ((runif > cump[k]) && (k<nk)) k++; value[*ss * (caught[i]-1) + s] = k; /* trap = k+1 */ } } } /* -------------------------------------------------------------------------------- */ /* the 'proximity' group of detectors 1:2 - proximity, count */ else if ((*detect >= 1) && (*detect <= 2)) { for (i=0; i<*N; i++) { for (k=0; k<nk; k++) { Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, k, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); /* d2val = d2(i,k, animals, traps, *N, nk); */ d2val = d2L(k, i, dist2, nk); p = pfn(*fn, d2val, g0, sigma, z, miscparm, 1e20); if (p < -0.1) { PutRNGstate(); return; } /* error */ if (p>0) { if (*detect == 1) { if (fabs(Tski-1) > 1e-10) p = 1 - pow(1-p, Tski); count = Random() < p; /* binary proximity */ } else if (*detect == 2) { /* count proximity */ if (*binomN == 1) count = rcount(round(Tski), p, 1); else count = rcount(*binomN, p, Tski); } if (count>0) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (j=0; j<*ss; j++) for (l=0; l<nk; l++) value[*ss * ((nc-1) * nk + l) + j] = 0; } value[*ss * ((caught[i]-1) * nk + k) + s] = count; } } } } } } /* -------------------------------------------------------------------------------- */ /* exclusive polygon detectors */ else if (*detect == 3) { /* find maximum distance between animal and detector vertex */ w = 0; J = cumk[nk]; for (i = 0; i< *N; i++) { for (j = 0; j < J; j++) { dx = animals[i] - traps[j]; dy = animals[*N + i] - traps[J + j]; d = sqrt(dx*dx + dy*dy); if (d > w) w = d; } } for (i=0; i<*N; i++) { /* this implementation assumes NO VARIATION AMONG DETECTORS */ getpar (i, s, 0, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, 0, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); maybecaught = Random() < g0; if (w > (10 * sigma)) ws = 10 * sigma; else ws = w; par[0] = 1; par[1] = sigma; par[2] = z; if (maybecaught) { gxy (&np, fn, par, &ws, xy); /* simulate location */ xy[0] = xy[0] + animals[i]; xy[1] = xy[1] + animals[*N + i]; for (k=0; k<nk; k++) { /* each polygon */ Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { n1 = cumk[k]; n2 = cumk[k+1]-1; inside(xy, &n1, &n2, &sumk, traps, gotcha); /* assume closed */ if (*gotcha > 0) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (t=0; t<*ss; t++) value[*ss * (nc-1) + t] = 0; } nd++; value[*ss * (caught[i]-1) + s] = k+1; work[(nd-1)*2] = xy[0]; work[(nd-1)*2+1] = xy[1]; sortkey[nd-1] = (double) (s * *N + caught[i]); break; /* no need to look at more poly */ } } } } } } /* -------------------------------------------------------------------------------- */ /* exclusive transect detectors */ else if (*detect == 4) { ex = (double *) R_alloc(10 + 2 * maxvertices, sizeof(double)); for (i=0; i<*N; i++) { /* each animal */ animal.x = animals[i]; animal.y = animals[i + *N]; sumhaz = 0; /* ------------------------------------ */ /* sum hazard */ for (k=0; k<nk; k++) { Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, k, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); par[0] = g0; par[1] = sigma; par[2] = z; n1 = cumk[k]; n2 = cumk[k+1]-1; H = hintegral1(*fn, par); sumhaz += -log(1 - par[0] * integral1D (*fn, i, 0, par, 1, traps, animals, n1, n2, sumk, *N, ex) / H); } } /* ------------------------------------ */ for (k=0; k<nk; k++) { /* each transect */ Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, k, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); par[0] = g0; par[1] = sigma; par[2] = z; n1 = cumk[k]; n2 = cumk[k+1]-1; H = hintegral1(*fn, par); lambdak = par[0] * integral1D (*fn, i, 0, par, 1, traps, animals, n1, n2, sumk, *N, ex) / H; pks = (1 - exp(-sumhaz)) * (-log(1-lambdak)) / sumhaz; count = Random() < pks; maxg = 0; if (count>0) { /* find maximum - approximate */ for (l=0; l<=100; l++) { lx = (cumd[n2] - cumd[n1]) * l/100; xyp = getxy (lx, cumd, line, sumk, n1); grx = gr (fn, par, xyp, animal); if (R_FINITE(grx)) maxg = fmax2(maxg, grx); } for (l=n1; l<=n2; l++) { xyp = line[l]; grx = gr (fn, par, xyp, animal); if (R_FINITE(grx)) maxg = fmax2(maxg, grx); } maxg= 1.2 * maxg; /* safety margin */ if (maxg<=0) Rprintf("maxg error in simsecr\n"); /* not found */ *gotcha = 0; l = 0; while (*gotcha == 0) { lx = Random() * (cumd[n2] - cumd[n1]); /* simulate location */ xyp = getxy (lx, cumd, line, sumk, n1); grx = gr (fn, par, xyp, animal); if (Random() < (grx/maxg)) /* rejection sampling */ *gotcha = 1; l++; if (l % 10000 == 0) R_CheckUserInterrupt(); if (l>1e8) *gotcha = 1; /* give up and accept anything!!!! */ } if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (t=0; t<*ss; t++) value[*ss * (nc-1) + t] = 0; } nd++; if (nd >= maxdet) { *resultcode = 2; /* error */ return; } value[*ss * (caught[i]-1) + s] = k+1; work[(nd-1)*2] = xyp.x; work[(nd-1)*2+1] = xyp.y; sortkey[nd-1] = (double) (s * *N + caught[i]); } if (count>0) break; /* no need to look further */ } } /* end loop over transects */ } /* end loop over animals */ } /* -------------------------------------------------------------------------------- */ /* polygon detectors */ else if (*detect == 6) { for (i=0; i<*N; i++) { /* this implementation assumes NO VARIATION AMONG DETECTORS */ getpar (i, s, 0, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, 0, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); count = rcount(*binomN, g0, Tski); w = 10 * sigma; par[0] = 1; par[1] = sigma; par[2] = z; for (j=0; j<count; j++) { gxy (&np, fn, par, &w, xy); /* simulate location */ xy[0] = xy[0] + animals[i]; xy[1] = xy[1] + animals[*N + i]; for (k=0; k<nk; k++) { /* each polygon */ Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { n1 = cumk[k]; n2 = cumk[k+1]-1; inside(xy, &n1, &n2, &sumk, traps, gotcha); /* assume closed */ if (*gotcha > 0) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (t=0; t<*ss; t++) for (l=0; l<nk; l++) value[*ss * ((nc-1) * nk + l) + t] = 0; } nd++; if (nd > maxdet) { *resultcode = 2; return; /* error */ } value[*ss * ((caught[i]-1) * nk + k) + s]++; work[(nd-1)*2] = xy[0]; work[(nd-1)*2+1] = xy[1]; sortkey[nd-1] = (double) (k * *N * *ss + s * *N + caught[i]); } } } } } } /* -------------------------------------------------------------------------------- */ /* transect detectors */ else if (*detect == 7) { ex = (double *) R_alloc(10 + 2 * maxvertices, sizeof(double)); for (i=0; i<*N; i++) { /* each animal */ animal.x = animals[i]; animal.y = animals[i + *N]; for (k=0; k<nk; k++) { /* each transect */ Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, bswitch (*btype, *N, i, k, caughtbefore), gsb0, gsb0val, gsb1, gsb1val, &g0, &sigma, &z); par[0] = g0; par[1] = sigma; par[2] = z; n1 = cumk[k]; n2 = cumk[k+1]-1; H = hintegral1(*fn, par); lambdak = par[0] * integral1D (*fn, i, 0, par, 1, traps, animals, n1, n2, sumk, *N, ex) / H; count = rcount(*binomN, lambdak, Tski); /* numb detections on transect */ maxg = 0; if (count>0) { /* find maximum - approximate */ for (l=0; l<=100; l++) { lx = (cumd[n2]-cumd[n1]) * l/100; xyp = getxy (lx, cumd, line, sumk, n1); grx = gr (fn, par, xyp, animal); if (R_FINITE(grx)) maxg = fmax2(maxg, grx); } for (l=n1; l<=n2; l++) { xyp = line[l]; grx = gr (fn, par, xyp, animal); if (R_FINITE(grx)) maxg = fmax2(maxg, grx); } maxg= 1.2 * maxg; /* safety margin */ if (maxg<=0) Rprintf("maxg error in simsecr\n"); /* not found */ } for (j=0; j<count; j++) { *gotcha = 0; l = 0; while (*gotcha == 0) { lx = Random() * (cumd[n2]-cumd[n1]); /* simulate location */ xyp = getxy (lx, cumd, line, sumk, n1); grx = gr (fn, par, xyp, animal); if (Random() < (grx/maxg)) /* rejection sampling */ *gotcha = 1; l++; if (l % 10000 == 0) R_CheckUserInterrupt(); if (l>1e8) *gotcha = 1; /* give up and accept anything!!!! */ } if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (t=0; t<*ss; t++) for (l=0; l<nk; l++) value[*ss * ((nc-1) * nk + l) + t] = 0; } nd++; if (nd >= maxdet) { *resultcode = 2; /* error */ return; } value[*ss * ((caught[i]-1) * nk + k) + s]++; work[(nd-1)*2] = xyp.x; work[(nd-1)*2+1] = xyp.y; sortkey[nd-1] = (double) (k * *N * *ss + s * *N + caught[i]); } } } /* end loop over transects */ } /* end loop over animals */ } /* ------------------------ */ /* signal strength detector */ else if (*detect == 5) { cut = miscparm[0]; if ((*fn == 12) || (*fn == 13)) { muN = miscparm[1]; sdN = miscparm[2]; } for (i=0; i<*N; i++) { for (k=0; k<nk; k++) { Tski = Tsk[s * nk + k]; if (fabs(Tski) > 1e-10) { /* sounds not recaptured */ getpar (i, s, k, x[i], *N, *ss, nk, *cc0, *cc1, *fn, 0, gsb0, gsb0val, gsb0, gsb0val, &beta0, &beta1, &sdS); /* if ((*fn == 10) || (*fn == 12)) muS = mufn (i, k, beta0, beta1, animals, traps, *N, nk, 0); else muS = mufn (i, k, beta0, beta1, animals, traps, *N, nk, 1); */ if ((*fn == 10) || (*fn == 12)) muS = mufnL (k, i, beta0, beta1, dist2, nk, 0); else muS = mufnL (k, i, beta0, beta1, dist2, nk, 1); signalvalue = norm_rand() * sdS + muS; if ((*fn == 10) || (*fn == 11)) { if (signalvalue > cut) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (j=0; j<*ss; j++) for (l=0; l<nk; l++) value[*ss * ((nc-1) * *kk + l) + j] = 0; } nd++; value[*ss * ((caught[i]-1) * *kk + k) + s] = 1; work[nd-1] = signalvalue; sortkey[nd-1] = (double) (k * *N * *ss + s * *N + caught[i]); } } else { noisevalue = norm_rand() * sdN + muN; if ((signalvalue - noisevalue) > cut) { if (caught[i]==0) { /* first capture of this animal */ nc++; caught[i] = nc; for (j=0; j<*ss; j++) for (l=0; l<nk; l++) value[*ss * ((nc-1) * *kk + l) + j] = 0; } nd++; value[*ss * ((caught[i]-1) * *kk + k) + s] = 1; work[nd-1] = signalvalue; noise[nd-1] = noisevalue; sortkey[nd-1] = (double) (k * *N * *ss + s * *N + caught[i]); } } } } } } if ((*btype > 0) && (s < (*ss-1))) { /* update record of 'previous-capture' status */ if (*btype == 1) { for (i=0; i<*N; i++) { if (*Markov) caughtbefore[i] = 0; for (k=0; k<nk; k++) caughtbefore[i] = imax2 (value[i3(s, k, i, *ss, nk)], caughtbefore[i]); } } else if (*btype == 2) { for (i=0; i<*N; i++) { for (k=0; k<nk; k++) { ik = k * (*N-1) + i; if (*Markov) caughtbefore[ik] = value[i3(s, k, i, *ss, nk)]; else caughtbefore[ik] = imax2 (value[i3(s, k, i, *ss, nk)], caughtbefore[ik]); } } } else { for (k=0;k<nk;k++) { if (*Markov) caughtbefore[k] = 0; for (i=0; i<*N; i++) caughtbefore[k] = imax2 (value[i3(s, k, i, *ss, nk)], caughtbefore[k]); } } } } /* loop over s */ if ((*detect==3) || (*detect==4) || (*detect==5) || (*detect==6) || (*detect==7)) { for (i=0; i<nd; i++) sortorder[i] = i; if (nd>0) rsort_with_index (sortkey, sortorder, nd); if (*detect==5) { for (i=0; i<nd; i++) signal[i] = work[sortorder[i]]; if ((*fn == 12) || (*fn == 13)) { for (i=0; i<nd; i++) signal[i+nd] = noise[sortorder[i]]; } } else { for (i=0; i<nd; i++) { detectedXY[i] = work[sortorder[i]*2]; detectedXY[i+nd] = work[sortorder[i]*2+1]; } } } *n = nc; PutRNGstate(); *resultcode = 0; }