void QHeader::mousePressEvent( QMouseEvent *m ) { if ( m->button() != LeftButton ) return; handleIdx = 0; int c = orient == Horizontal ? m->pos().x() : m->pos().y(); int i = 0; while ( i < (int) count() ) { if ( pPos(i+1) - MINSIZE/2 < c && c < pPos(i+1) + MINSIZE/2 ) { handleIdx = i+1; oldHIdxSize = cellSize( i ); if ( data->resize.testBit(i) ) state = Sliding; else state = Blocked; break; } else if ( pPos(i) < c && c < pPos( i+1 ) ) { handleIdx = i; moveToIdx = -1; if ( data->clicks.testBit(i) ) state = Pressed; else state = Blocked; clickPos = c; repaint(sRect( handleIdx )); break; } i++; } }
bool VarData::WriteXvt(char *OutFile){ VarMessage("Write"); FILE *FileToWrite = NULL; char Line2Put[512]; FileToWrite = fopen(OutFile,"w"); SigErr(FileToWrite==NULL,"The output file %s could not be opened\n",OutFile); fprintf(FileToWrite,"# L=%lf %lf %lf t=%lf blocks=%d\n",Gen->Edge[0],Gen->Edge[1],Gen->Edge[2],pTime(),Gen->NBlock); HeaderInteraction(FileToWrite); HeaderNano(FileToWrite); for(int b=0,cOff=0,pCurr=0;b<Gen->NBlock;b++,cOff+=Block[b].NChain){ if(Block[b].NChain == 0) continue; fprintf(FileToWrite,"# n=%d N=%d name=%s\n",Block[b].NChain,Block[b].NPCh,Block[b].Name); for(int c=cOff;c<Block[b].NChain+cOff;c++){ for(int p=0;p<Block[b].NPCh;p++,pCurr++){ // if(p > 0){ // for(int d=0;d<3;d++){ // if(Pm[pCurr].Pos[d] - Pm[pCurr-1].Pos[d] > .5*pEdge(d)) // Pm[pCurr].Pos[d] -= pEdge(d); // else if(Pm[pCurr].Pos[d] - Pm[pCurr-1].Pos[d] < -.5*pEdge(d)) // Pm[pCurr].Pos[d] += pEdge(d); // } // } fprintf(FileToWrite,"%lf %lf %lf ", pPos(pCurr,0),pPos(pCurr,1),pPos(pCurr,2)); fprintf(FileToWrite,"%lf %lf %lf ", Pm[pCurr].Vel[0],Pm[pCurr].Vel[1],Pm[pCurr].Vel[2]); fprintf(FileToWrite," %d ", Pm[pCurr].Typ); fprintf(FileToWrite,"\n"); } } } fclose(FileToWrite); return 0; }
void ElPoly::IsoLine(int NSample,double *IsoLevel,int NIso,int How){ int NPairF = 1;//NFile[1]-NFile[0]; double OldPos[3] = {pNanoPos(0,0),pNanoPos(0,1),pNanoPos(0,2)}; double DensEl = SQR(NSample)/(pVol()*NPairF); double Dens = 13.3; //IsoLevel *= NPairF; for(int ff=NFile[0];ff<NFile[1];ff+=NPairF){ double *Plot = (double *)calloc(SQR(NSample),sizeof(double)); double Min = 0.; double Max = 0.; double Pos[3]; for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_PART))return; for(int b=0;b<pNBlock();b++){ for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){ if(pType(p) != 0)continue; for(int d=0;d<3;d++){ Pos[d] = pPos(p,d) - (pNanoPos(0,d)-.5*pEdge(d)); Pos[d] -= floor(Pos[d]*pInvEdge(d))*pEdge(d); } int sx = (int)(Pos[CLat1]*pInvEdge(CLat1)*NSample); int sy = (int)(Pos[CLat2]*pInvEdge(CLat2)*NSample); int sTot = sx*NSample+sy; if(How==0)//particle file Plot[sTot] += DensEl; else Plot[sTot] += pPos(p,CNorm); if(Max < Plot[sTot]) Max = Plot[sTot]; if(Min > Plot[sTot]) Min = Plot[sTot]; } } printf("Min %lf Max %lf DensEl %lf\n",Min,Max,DensEl); } Matrice Mask(5,5); Mask.FillGaussian(.5,3.); Mask.Print(); int NDim = 2; int IfMinImConv = 1; Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); char FString[60]; sprintf(FString,"IsoSurf%05d.dat",ff); FILE *F2Write = fopen(FString,"w"); fprintf(F2Write,"#l(%lf %lf %lf) v[%d] d[part]\n",pEdge(0),pEdge(1),pEdge(2),NSample); HeaderNano(F2Write); IsoLine(F2Write,Plot,NSample,IsoLevel,NIso); free(Plot); fclose(F2Write); } }
/*! Tries to find a line that is not a neighbour of \c handleIdx. */ int QHeader::findLine( int c ) { int i = cellAt( c ); if ( i == -1 ) return handleIdx; //####### frustrating, but safe behaviour. if ( i == handleIdx ) return i; if ( i == handleIdx - 1 && pPos( handleIdx ) - c > MARKSIZE/2 ) return i; if ( i == handleIdx + 1 && c - pPos( i ) > MARKSIZE/2 ) return i + 1; if ( c - pPos( i ) > pSize( i ) / 2 ) return i + 1; else return i; }
int QHeader::cellPos( int i ) const { /* cvs conflict here */ int r = pPos( i ); return r + offset(); }
/*! Marks the division line at \a idx. */ void QHeader::markLine( int idx ) { QPainter paint( this ); paint.setPen( QPen( black, 1, DotLine ) ); int p = pPos( idx ); int x = p - MARKSIZE/2; int y = 2; int x2 = p + MARKSIZE/2; int y2 = height() - 3; if ( orient == Vertical ) { int t = x; x = y; y = t; t = x2; x2 = y2; y2 = t; } paint.drawLine( x, y, x2, y ); paint.drawLine( x, y+1, x2, y+1 ); paint.drawLine( x, y2, x2, y2 ); paint.drawLine( x, y2-1, x2, y2-1 ); paint.drawLine( x, y, x, y2 ); paint.drawLine( x+1, y, x+1, y2 ); paint.drawLine( x2, y, x2, y2 ); paint.drawLine( x2-1, y, x2-1, y2 ); }
int ElPoly::From2To1d(int Coord){ if(Coord != 0 && Coord != 1){ printf("Coordinate accepted are 0 or 1 not %d\n",Coord); return 1; } int SecCoord = (Coord+1)%2; double *Line = (double *) calloc(3*NEdge,sizeof(double)); double *Count = (double *) calloc(3*NEdge,sizeof(double)); for(int p=0;p<pNPart();p++){ int vz = (int)((pPos(p,Coord)+0.001)*pInvEdge(Coord)*NEdge); if(vz < 0 || vz >= NEdge) continue; for(int d=0;d<3;d++){ Line[vz*3+d] += pVel(p,d); Count[vz*3+d] += 1.; } } for(int vz=0;vz<NEdge;vz++){ for(int d=0;d<3;d++){ double Norm = Count[vz*3+d] > 0. ? Count[vz*3+d] : 1.; //Line[vz*3+d] /= Norm; Line[vz*3+d] *= pEdge(SecCoord)/(double)NEdge; } } FILE *FLine = fopen("ProjOnLine.dat","w"); for(int v=0;v<NEdge;v++){ fprintf(FLine,"%lf %lf %lf %lf\n",v*pEdge(Coord)/(double)NEdge,Line[v*3+0],Line[v*3+1],Line[v*3+2]); } fclose(FLine); free(Line); free(Count); }
int main() { std::shared_ptr<Pos> pPos(new Pos(7, 8)); std::shared_ptr<Pos> pPos2(pPos); pPos->print(); pPos2->print(); return 0; }
void ElPoly::AvSnap(){ int NPairF = 10; double InvAv = 1./(double)NPairF; double Norm = 1./(double)(NFile[1]-NFile[0]); char FName[256]; // for(int ff=NFile[0];ff<NFile[1];ff+=NPairF){ PART *Pn = (PART *)calloc(pNPart(),sizeof(PART)); //for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_NO))return; for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ Pn[p].Pos[d] += pPos(p,d); } } } for(int p=0;p<pNPart();p++){ double Pos[3] = {Pn[p].Pos[0]*Norm,Pn[p].Pos[1]*Norm,Pn[p].Pos[2]*Norm}; SetPos(p,Pos); } printf("\n"); free(Pn); sprintf(FName,"Av%s",cFile[NFile[0]]); Write(FName); }
void Forces::ReOpen(char *FName,int Bf){ double Edge[3] = {pEdge(0),pEdge(1),pEdge(2)}; Pc->Erase(); delete Pc; Open(FName,Bf); Pc = new DomDec(Edge,pNPart(),sqrt(Kf.CutOff2)); double Pos[3]; for(int p=0;p<pNPart();p++){pPos(p,Pos);Pc->AddPart(p,Pos);} PrepareSys(); }
void Forces::Info(){ printf("-----INFO-------\n"); if(VAR_IF_TYPE(SysShape,SYS_MC)){ // Pc->Erase(); // ClearDens(); // for(int p=0;p<pNPart();p++) // Pc->AddPart(p,Pm[p].Pos); // AddDens(0,pNPart()); printf("Energy: Sys %lf Ch Part \n",OldNrgSys); // CalcTotNrgCh(); // for(int c=0;c<pNChain();c++) // printf("%d %lf %lf %lf\n",c,OldNrgCh[c*3],OldNrgCh[c*3+1],OldNrgCh[c*3+2]); } else if(VAR_IF_TYPE(SysShape,SYS_MD)){ for(int p=0;p<pNPart();p++){ if(p == Bead2Move) printf("p "); printf("%d) (%lf,%lf,%lf) (%lf %lf %lf) %lf-%lf-%lf\n",p,pPos(p,0),pPos(p,1),pPos(p,2),pVel(p,0),pVel(p,1),pVel(p,2),Fm[p].Dir[2],Fm[p].Dir[2],Fm[p].Dir[2]); } } printf("------------\n"); }
void Forces::CalcDens(){ // 3d if(VAR_IF_TYPE(Tens.CalcMode,CALC_3d)){ double PosRel[3]; for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ PosRel[d] = pPos(p,d) - (pEdge(d)*.5 - Tens.RefPos[d]); PosRel[d] -= floor(PosRel[d]*pInvEdge(d))*pEdge(d); } int sx = (int)(PosRel[0]*pInvEdge(0)*Tens.NSlab); int sy = (int)(PosRel[1]*pInvEdge(1)*Tens.NSlab); int sz = (int)(PosRel[2]*pInvEdge(2)*Tens.NSlab); int v = (sx*Tens.NSlab+sy)*Tens.NSlab+sz; int t = pType(p); if(t > 1) continue; Tens.Dens[t][v] += 1.; } } // 2d else if(VAR_IF_TYPE(Tens.CalcMode,CALC_2d)){ double PosRel[3]; for(int p=0;p<pNPart();p++){ PosRel[CLat1] = pPos(p,CLat1) - Tens.RefPos[CLat1]; PosRel[CLat2] = pPos(p,CLat2) - Tens.RefPos[CLat2]; PosRel[CNorm] = pPos(p,CNorm) + (pEdge(CNorm)*.5 - Tens.RefPos[CNorm]); for(int d=0;d<3;d++){ PosRel[d] -= floor(PosRel[d]*pInvEdge(d))*pEdge(d); } int sr = (int)(hypot(PosRel[CLat1],PosRel[CLat2])*Tens.EdgeInv[0]*Tens.NSlab); int sz = (int)(PosRel[CNorm]*pInvEdge(CNorm)*Tens.NSlab); if(sr < 0 || sr >= Tens.NSlab) continue; if(sz < 0 || sz >= Tens.NSlab) continue; int v = (sr*Tens.NSlab+sz); int t = pType(p); if(t > 1) continue; Tens.Dens[t][v] += 1.; //printf("%d %d %d %lf\n",sr,sz,v,Tens.Dens[t][v]); } } }
/*! Tries to find a line that is not a neighbor of \c handleIdx. */ int QHeader::findLine( int c ) { int lastpos = d->positions[d->count-1] + d->sizes[d->i2s[d->count-1]]; int i = 0; if ( c > lastpos ) { return d->count; } else { int section = sectionAt( c ); if ( section < 0 ) return handleIdx; i = d->s2i[section]; } if ( i == handleIdx ) return i; if ( i == handleIdx - 1 && pPos( handleIdx ) - c > MARKSIZE/2 ) return i; if ( i == handleIdx + 1 && c - pPos( i ) > MARKSIZE/2 ) return i + 1; if ( c - pPos( i ) > pSize( i ) / 2 ) return i + 1; else return i; }
/*! Removes the mark at the division line at \a idx. */ void QHeader::unMarkLine( int idx ) { if ( idx < 0 ) return; int p = pPos( idx ); int x = p - MARKSIZE/2; int y = 2; int x2 = p + MARKSIZE/2; int y2 = height() - 3; if ( orient == Vertical ) { int t = x; x = y; y = t; t = x2; x2 = y2; y2 = t; } repaint( x, y, x2-x+1, y2-y+1 ); }
int ElPoly::From3To2d(int NSample,double Param){ char FName[120]; for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_NANO)); sprintf(FName,"ProjOnSurf%05d.dat",f); FILE *FLine = fopen(FName,"w"); fprintf(FLine,"# l(%lf %lf %lf) d[part]\n",1.,pEdge(CLat2)*pInvEdge(CLat1),.5); for(int p=0;p<pNPart();p++){ if(pType(p) != 0) continue; fprintf(FLine,"{x(%lf %lf %lf) v(%lf %lf %lf)}\n",pPos(p,CLat1)*pInvEdge(CLat1),pPos(p,CLat2)*pInvEdge(CLat1),.5,pVel(p,0),pVel(p,1),pVel(p,2)); } fclose(FLine); } printf("\n"); }
void QHeader::mouseMoveEvent( QMouseEvent *m ) { int s = orient == Horizontal ? m->pos().x() : m->pos().y(); if ( state == Idle ) { bool hit = FALSE; int i = 0; while ( i <= (int) count() ) { if ( i && pPos(i) - MINSIZE/2 < s && s < pPos(i) + MINSIZE/2 && data->resize.testBit(i-1) ) { hit = TRUE; if ( orient == Horizontal ) setCursor( *hSplitCur ); else setCursor( *vSplitCur ); break; } i++; } if ( !hit ) setCursor( arrowCursor ); } else { switch ( state ) { case Idle: debug( "QHeader::mouseMoveEvent() (%s) Idle state", name( "unnamed" ) ); break; case Pressed: case Blocked: if ( QABS( s - clickPos ) > 4 && data->move ) { state = Moving; moveToIdx = -1; if ( orient == Horizontal ) setCursor( sizeHorCursor ); else setCursor( sizeVerCursor ); } break; case Sliding: handleColumnResize( handleIdx, s, FALSE ); break; case Moving: { int newPos = findLine( s ); if ( newPos != moveToIdx ) { if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 ) repaint( sRect(handleIdx) ); else unMarkLine( moveToIdx ); moveToIdx = newPos; if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 ) paintRect( pPos( handleIdx ), pSize( handleIdx ) ); else markLine( moveToIdx ); } break; } default: warning( "QHeader::mouseMoveEvent: (%s) unknown state", name( "unnamed" ) ); break; } } }
else markLine( moveToIdx ); } break; } default: warning( "QHeader::mouseMoveEvent: (%s) unknown state", name( "unnamed" ) ); break; } } } void QHeader::handleColumnResize( int index, int s, bool final ) { int lim = pPos(index-1) + MINSIZE; if ( s == lim ) return; if ( s < lim ) s = lim; int oldPos = pPos( index ); int delta = s - oldPos; int lIdx = mapToLogical(index - 1); int oldSize = data->sizes[lIdx]; int newSize = data->sizes[lIdx] = oldSize + delta; int repaintPos = QMIN( oldPos, s ); if ( orient == Horizontal ) repaint(repaintPos-2, 0, width(), height()); else repaint(0, repaintPos-oldSize+2, width(), height()); if ( tracking() && oldSize != newSize ) emit sizeChange( lIdx, oldSize, newSize ); else if ( final && oldHIdxSize != newSize )
/*! \reimp */ void QHeader::mouseMoveEvent( QMouseEvent *e ) { int section; bool hit; int c = orient == Horizontal ? e->pos().x() : e->pos().y(); c += offset(); switch( state ) { case Idle: hit = FALSE; if ( (section = sectionAt( c )) >= 0 ) { int index = d->s2i[section]; if ( (index > 0 && c < d->positions[index] + GRIPMARGIN) || (c > d->positions[index] + d->sizes[section] - GRIPMARGIN) ) { if ( index > 0 && c < d->positions[index] + GRIPMARGIN ) section = d->i2s[--index]; if ( d->resize.testBit(section) ) { hit = TRUE; #ifndef QT_NO_CURSOR if ( orient == Horizontal ) setCursor( splitHCursor ); else setCursor( splitVCursor ); #endif } } } #ifndef QT_NO_CURSOR if ( !hit ) unsetCursor(); #endif break; case Blocked: break; case Pressed: if ( QABS( c - clickPos ) > 4 && d->move ) { state = Moving; moveToIdx = -1; #ifndef QT_NO_CURSOR if ( orient == Horizontal ) setCursor( sizeHorCursor ); else setCursor( sizeVerCursor ); #endif } break; case Sliding: handleColumnResize( handleIdx, c, FALSE ); break; case Moving: { int newPos = findLine( c ); if ( newPos != moveToIdx ) { if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 ) repaint( sRect(handleIdx) ); else unMarkLine( moveToIdx ); moveToIdx = newPos; if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 ) paintRect( pPos( handleIdx ), pSize( handleIdx ) ); else markLine( moveToIdx ); } break; } default: qWarning( "QHeader::mouseMoveEvent: (%s) unknown state", name() ); break; } }
int ElPoly::ProjectionF(int NBin,int Coord){ if(Coord > 4 || Coord <0) return 1; int NType = 5; double *Plot = (double *)calloc(NBin*NBin*NType,sizeof(double)); double InvNBin = 1./(double)NBin; double RefPos[3] = {0.,0.,0.}; for(int d=0;d<3;d++){ RefPos[d] = Nano->Pos[d]-.5*pEdge(d); } if(Coord == 3){ RefPos[0]=pCm(0);RefPos[1]=pCm(1);RefPos[2]=pCm(2); } SetEdge(.5*MIN(pEdge(CLat1),pEdge(CLat2)),3); for(int f=NFile[0];f<NFile[1];f++){ Processing(f); OpenRisk(cFile[f],BF_PART); ShiftSys(SHIFT_CM); int NPlot = 0; //---Projects-against-one-coordinate-- if(Coord < 3){ int coord1 = (Coord+1)%3; int coord2 = (Coord+2)%3; for(int p=0;p<pNPart();p++){ double x = pPos(p,coord1) - RefPos[coord1]; x -= floor(x*pInvEdge(coord1))*pEdge(coord1); double y = pPos(p,coord2) - RefPos[coord2]; y -= floor(y*pInvEdge(coord2))*pEdge(coord2); int v = (int)(NBin*x*pInvEdge(coord1)); if( v < 0 || v >= NBin) continue; int vv = (int)(NBin*y*pInvEdge(coord2)); if( vv < 0 || vv >= NBin) continue; int t = pType(p); if( t < 0 || t > 3) continue; if( CHAIN_IF_TYPE(Ch[pChain(p)].Type,CHAIN_ADDED) ) Plot[(v*NBin+vv)*NType+3] += 1.; Plot[(v*NBin+vv)*NType+t] += 1.; if(p<pNPart()-1) if(pType(p+1) == 1 && pType(p) == 0) Plot[(v*NBin+vv)*NType+4] += 1.; } } //---Projects-against-the-radial-coordinate-- else if(Coord == 3){ SetEdge(.5*MAX((pEdge(CLat1)),(pEdge(CLat2))),3); for(int p=0;p<pNPart();p++){ double x = pPos(p,CLat1) - RefPos[CLat1]; x -= floor(x*pInvEdge(CLat1))*pEdge(CLat1); double y = pPos(p,CLat2) - RefPos[CLat2]; y -= floor(y*pInvEdge(CLat2))*pEdge(CLat2); double z = pPos(p,CNorm) - RefPos[CNorm]; z -= floor(z*pInvEdge(CNorm))*pEdge(CNorm); double r = sqrt(SQR(x)+SQR(y)); int v = (int)(NBin*r*pInvEdge(3)); if( v < 0 || v >= NBin) continue; int vv = (int)(NBin*pPos(p,CNorm)/pEdge(CNorm)); if( vv < 0 || vv >= NBin) continue; int t = pType(p); if( t < 0 || t > 3) continue; if( CHAIN_IF_TYPE(Ch[pChain(p)].Type,CHAIN_ADDED) ) Plot[(v*NBin+vv)*NType+3] += 1.; Plot[(v*NBin+vv)*NType+t] += 1.; if(p<pNPart()-1) if(pType(p+1) == 1 && pType(p) == 0) Plot[(v*NBin+vv)*NType+4] += 1.; } } } printf("\n"); //-----writes-the-output-file------------------- FILE *FileToWrite = NULL; FileToWrite = fopen("Projection.xyd","w"); fprintf(FileToWrite,"#l(%lf %lf %lf) v[%d] d[%s]\n",pEdge(CLat1),pEdge(CLat2),pEdge(CNorm),NBin,ChooseDraw(EL_QUAD1)); int coord1 = (Coord+1)%3; int coord2 = (Coord+2)%3; if(Coord == 3){ coord1 = 3; coord2 = CNorm; } double Max[NType]; for(int t=0;t<NType;t++){ Max[t] = Plot[t]; for(int v=0;v<NBin;v++) for(int vv=0;vv<NBin;vv++) if(Max[t] < Plot[(v*NBin+vv)*NType+t]) Max[t] = Plot[(v*NBin+vv)*NType+t]; Max[t] = Max[t] <= 0. ? 1. : Max[t]; } //for(int t=0;t<NType-1;t++){ for(int t=0;t<1;t++){ for(int v=0;v<NBin;v++){ for(int vv=0;vv<NBin;vv++){ int p = (v*NBin+vv)*NType+t; int c = 0; if(Plot[p] < .1) continue; double x = (v)*InvNBin*pEdge(CLat1); double y = (vv)*InvNBin*pEdge(CLat2); double dens = Plot[p]/Max[t]*5.+.5*pEdge(CNorm); double NanoAdded = 0.;//Plot[p]/Max[t]+Plot[((v*NBin+vv)*NType+3]/Max[3]; double Phob = t == 0 ? Plot[(v*NBin+vv)*NType+0]/Max[0] : 0.; double Phil = t == 1 ? Plot[(v*NBin+vv)*NType+1]/Max[1] : 0.; fprintf(FileToWrite,"{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf)}\n",p,c,t,x,y,dens,NanoAdded,Phob,Phil); } } } free(Plot); fclose(FileToWrite); return 0; }
void Forces::AllocMethod(){ Shout("Allocation"); StatFile1 = fopen("StatDyn1.dat","w"); StatFile2 = fopen("StatDyn2.dat","w"); ChooseCalcMode(CalcMode); ChoosePot(CalcMode); ChooseThermostat(ThermMode); double Edge[3] = {pEdge(0),pEdge(1),pEdge(2)}; double Pos[3]; //Pc->PrintCells(); //CheckPairList(); SetDeltat(Deltat); if(VAR_IF_TYPE(SysShape,SYS_MD)){ Shout("Allocating/md: forces, domain decomposition"); Fm = (FORCES *)calloc(pNAllocP(),sizeof(FORCES)); VAR_ADD_TYPE(SysAlloc,ALL_MD); VAR_ADD_TYPE(SysAlloc,ALL_FORCES); Pc = new DomDec(Edge,pNPart(),sqrt(Kf.CutOff2)); for(int p=0;p<pNPart();p++){pPos(p,Pos);Pc->AddPart(p,Pos);} } if(VAR_IF_TYPE(SysShape,SYS_ROD)){ Shout("Allocating/rod: forces"); Fm = (FORCES *)calloc(pNAllocP(),sizeof(FORCES)); VAR_ADD_TYPE(SysAlloc,ALL_FORCES); } else if(VAR_IF_TYPE(SysShape,SYS_MC)){ Shout("Allocating/mc: domain decomposition old chain positions, old energies for particles and chains, first bead distribution, bias (cumulative probabilities and bead positions)"); Pc = new DomDec(Edge,pNPart(),sqrt(Kf.CutOff2)); double Pos[3]; for(int p=0;p<pNPart();p++){pPos(p,Pos);Pc->AddPart(p,Pos);} //Pc->PrintCells(); if(VAR_IF_TYPE(CalcMode,CALC_NVT)){ OldNrgBead = new double[3*pNAllocP()]; if(!OldNrgBead){ printf("Could not allocate OldNrgPm \n"); exit(1); } } OldNrgCh = new double[3*pNAllocC()]; FirstBeadDistr = new double[NBin]; if(!OldNrgCh){ printf("Could not allocate OldNrgCh\n"); exit(1); } OldPos = (double **)calloc(pNPCh(),sizeof(double)); if( !OldPos){ printf("Could not allocate OldPos\n"); exit(1); } for(int p=0;p<pNPCh();p++){ OldPos[p] = (double *)calloc(3,sizeof(double)); } CumProbBias = new double[NTrialBias]; BondPosBias = new double*[NTrialBias]; for(int t=0;t<NTrialBias;t++){ BondPosBias[t] = new double[3]; } VAR_ADD_TYPE(SysAlloc,ALL_MC); VAR_ADD_TYPE(SysAlloc,ALL_BIAS); GaussVar = sqrt(pReOverCutOff()/(3.*(pNPCh()-1)))/2.; GaussVar = sqrt(1./pkSpr()); } else if(VAR_IF_TYPE(SysShape,SYS_ELECTRO)){ Shout("Allocating/mc: domain decomposition old chain positions, old energies for particles and chains, first bead distribution, bias (cumulative probabilities and bead positions)"); Pc = new DomDec(Edge,pNPart(),sqrt(Kf.CutOff2)); double Pos[3]; for(int p=0;p<pNPart();p++){pPos(p,Pos);Pc->AddPart(p,Pos);} //Pc->PrintCells(); if(VAR_IF_TYPE(CalcMode,CALC_NVT)){ OldNrgBead = new double[3*pNAllocP()]; if(!OldNrgBead){ printf("Could not allocate OldNrgPm \n"); exit(1); } } OldNrgCh = new double[3*pNAllocC()]; FirstBeadDistr = new double[NBin]; if(!OldNrgCh){ printf("Could not allocate OldNrgCh\n"); exit(1); } OldPos = (double **)calloc(pNPCh(),sizeof(double)); if( !OldPos){ printf("Could not allocate OldPos\n"); exit(1); } for(int p=0;p<pNPCh();p++){ OldPos[p] = (double *)calloc(3,sizeof(double)); } CumProbBias = new double[NTrialBias]; BondPosBias = new double*[NTrialBias]; for(int t=0;t<NTrialBias;t++){ BondPosBias[t] = new double[3]; } VAR_ADD_TYPE(SysAlloc,ALL_MC); VAR_ADD_TYPE(SysAlloc,ALL_BIAS); } if(VAR_IF_TYPE(SysShape,SYS_1D) || VAR_IF_TYPE(SysShape,SYS_TRIAL)){ Shout("Allocating/splines"); Pl = (PART *)calloc(NSpline,sizeof(PART)); VAR_ADD_TYPE(SysAlloc,ALL_SPLINE); } if(VAR_IF_TYPE(CalcMode,CALC_DENS)){ Shout("Allocating/particle densities, sum of local densities"); LocDens2 = (double *)calloc(pNPCh()*pNType(),sizeof(double)); LocDens3 = (double *)calloc(pNPCh()*pNType(),sizeof(double)); Dens2 = (double *)calloc(pNAllocP()*pNType(),sizeof(double)); Dens3 = (double *)calloc(pNAllocP()*pNType(),sizeof(double)); if( !Dens2 || !Dens3){ printf("Could not allocate Dens2 Dens3\n"); exit(1); } VAR_ADD_TYPE(SysAlloc,ALL_DENS); } #ifdef __glut_h__ Cylinder = (GLuint *)calloc(pNNano(),sizeof(GLuint)); #endif ChemPotId = log(NChemPotId/pVol()); }
int main(int argc, char *argv[]) { srand(argc * 17); if (/*argc != 3 &&*/ argc != 4) { // TODO: non-implemented case printUsage(argv[0]); exit(EXIT_FAILURE); } else { const char *sampleDirectory = strdup(argv[1]); const char *resultFile = strdup(argv[2]); const char *modelFile = ""; if (argc == 4) { modelFile = strdup(argv[3]); } try { ImageSet images(sampleDirectory); PatchPositions result(resultFile); std::vector <std::string> names = images.getNames(); std::vector <std::vector <double> > descriptorSet; std::vector <int> answerSet; std::cerr << names.size() << " files are found." << std::endl; int progress = 0; for (std::vector <std::string>::iterator imageName = names.begin(); imageName != names.end(); ++imageName) { progress += 1; Sample sample(images.getImage(*imageName)); std::vector <Rectangle> pRects = result.getPositions(*imageName); std::vector <int> pPos(pRects.size()); for (int i = 0; i < (int)pRects.size(); i++) { pPos[i] = pRects[i].left(); } std::sort(pPos.begin(), pPos.end()); // Pedestrian patches std::cerr << "\b\b\b\b\b" << 100 * progress / names.size() << " %"; for (std::vector <int>::iterator pos = pPos.begin(); pos != pPos.end(); ++pos) { descriptorSet.push_back(sample.getDescriptor(*pos)); answerSet.push_back(ANSWER_PEDESTRIAN); } // Background patches std::vector <bool> isAllowed(sample.maximalShift(), true); for (std::vector <int>::iterator pos = pPos.begin(); pos != pPos.end(); ++pos) { int start = std::max(0, *pos - PATCH_WIDTH / 2); int end = std::min(*pos + PATCH_WIDTH / 2, (int)isAllowed.size()); for (int i = start; i < end; i++) { isAllowed[i] = false; } } int bgCount = 0; for (int i = 0; i < (int)isAllowed.size(); i++) { if (isAllowed[i]) { bgCount += 1; } } if (bgCount != 0) { for (int bgNum = 0; bgNum < BACKGROUND_PER_SAMPLE; bgNum++) { int number = rand() % bgCount + 1; int x = -1; do { x += 1; while (!isAllowed[x]) { x += 1; } number -= 1; } while (number > 0); descriptorSet.push_back(sample.getDescriptor(x)); answerSet.push_back(ANSWER_BACKGROUND); } } } std::cerr << "\b\b\b\b\b"; std::cerr << "There are " << descriptorSet.size() << " pathces." << std::endl; LinearSVM(descriptorSet, answerSet, 1.0).save(modelFile); } catch (const char *e) { std::cerr << "Error: " << e << std::endl; exit(EXIT_FAILURE); } } return 0; }
// int ElPoly::LateralDistr(int NBin){ // } int ElPoly::Surface(int NBin,int Threshold){ double *PlotAv = (double *)calloc(NBin*NBin,sizeof(double)); int NPoint=0; double AreaAv = 0.,SurfAv = 0.; double Max=0.; printf("Edge %lf Threshold %d\n",pEdge(3),Threshold); for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_PART))return 1; double Surf=0.,Area =0.; double *Plot = (double *)calloc(NBin*NBin,sizeof(double)); for(int p=0;p<pNPart();p++){ int v = (int)(pPos(p,CLat1)/pEdge(CLat1)*NBin); if( v < 0 || v > NBin){ printf("Oi 0 < %d < %d\n",v,NBin);return 1;} int vv = (int)(pPos(p,CLat2)/pEdge(CLat2)*NBin); if( vv < 0 || vv > NBin){ printf("Oi 0 < %d < %d\n",vv,NBin);return 1;} Plot[v*NBin+vv] += 1.; } for(int v=0;v<NBin;v++) for(int vv=0,n=0;vv<NBin;vv++) PlotAv[v*NBin+vv] += Plot[v*NBin+vv]; for(int v=1;v<NBin-1;v++){ for(int vv=1,n=0;vv<NBin-1;vv++){ if(Plot[v*NBin+vv] > Threshold){ NPoint++; //printf("(%d %d) %d %d %d %d\n",v,vv,Plot[v-1][vv],Plot[v+1][vv],Plot[v][vv-1],Plot[v][vv+1]); if(Plot[(v-1)*NBin+vv] > Threshold && v > 0) n++; if(Plot[(v+1)*NBin+vv] > Threshold && v < NBin -1) n++; if(Plot[v*NBin+vv-1] > Threshold && vv > 0) n++; if(Plot[v*NBin+vv+1] > Threshold && vv < NBin -1) n++; if(n == 4){ Area += 1.; } else if(n < 4 && n != 0){ if(n == 3){ Surf += 1.; Area += 1.; } else if(n == 2){ Surf += 2; } else if(n == 1){ Surf += sqrt(2); } } n = 0; } } } AreaAv += Area; SurfAv += Surf; free(Plot); } printf("\n"); //-----------normalize------------------- for(int v=0;v<NBin;v++) for(int vv=0,n=0;vv<NBin;vv++) if(PlotAv[v*NBin+vv] > Max) Max = PlotAv[v*NBin+vv]; //------------write-output----------------- FILE *FileToWrite = NULL; FileToWrite = fopen("Surface.xyz","w"); double FNorma = 1./(double)(NFile[1] - NFile[0]); double LengthConv = pEdge(0)*pEdge(1)/(double)(NBin*NBin); fprintf(FileToWrite,"#AreaTot %lf Area %lf Surf %lf Threshold %d NChain %d NBin %d\n",pEdge(CLat1)*pEdge(CLat2),AreaAv*FNorma*LengthConv,SurfAv*FNorma*LengthConv,Threshold,pNChain(),NBin); for(int v=0;v<NBin;v++) for(int vv=0,n=0;vv<NBin;vv++) if(PlotAv[v*NBin+vv] > 0.) fprintf(FileToWrite,"%lf %lf %lf\n",(double)v/NBin*pEdge(CLat1),(double)vv/NBin*pEdge(CLat2),PlotAv[v*NBin+vv]/Max); fclose(FileToWrite); free(PlotAv); return 0; }
void Forces::CalcTens(){ if(!VAR_IF_TYPE(SysAlloc,ALL_FORCES)){ printf("Forces not allocated\n"); return; } ClearDens(); AddDens(0,pNPart()); SumDens(0,pNPart()); double Dist = 0.; double DistRelBA[4]; for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ Fm[p].Dir[d] = 0.; } } // non bonded double Pos[3]; for(int p1=0;p1<pNPart();p1++){ for(Pc->SetCurr(p1);Pc->IfCurr();Pc->NextCurr()){ int p2 = Pc->p2Curr; if(p2 <= p1) continue; Pc->Dist2Curr(DistRelBA); if(DistRelBA[3] > Kf.CutOff2) continue; double Dist = sqrt(DistRelBA[3]); double Force = 0.; for(int t=0;t<pNType();t++){ Force += MInt->Coeff(pType(p1),pType(p2),t)*(Dens3[p1*pNType()+t]+Dens3[p2*pNType()+t]); } Force *= DerWei3(Dist,pWei3Par())*2./3.; Force += DerWei2(Dist,pWei2Par())*MInt->Coeff(pType(p1),pType(p2)); SumTens(p1,p2,Force,DistRelBA); Force /= -Dist; SigErr(Force > 5000.,"Forces over the limit %lf\n",Force); for(int d=0;d<3;d++){ Fm[p1].Dir[d] += Force*DistRelBA[d]; Fm[p2].Dir[d] -= Force*DistRelBA[d]; } } } // bonded double DistRelBC[4]; double Pre[12]; for(int b=0;b<pNBlock();b++){ for(int c=0;c<pNChain(b);c++){ for(int p=c*pNPCh(b);p<(c+1)*pNPCh(b)-1;p++){ TwoPartDist(p+1,p,DistRelBA); double ForceSp = pkSpr()*(1. - pSprRest()/DistRelBA[3]); SumTens(p,p+1,ForceSp,DistRelBA); for(int d=0;d<3;d++){ Fm[p].Dir[d] += ForceSp*DistRelBA[d]; Fm[p+1].Dir[d] -= ForceSp*DistRelBA[d]; } if(p < (c+1)*pNPCh(b)-2){ TwoPartDist(p+2,p+1,DistRelBC); double CosAngle = 0.; for(int d=0;d<3;d++){ DistRelBA[d] /= DistRelBA[3]; DistRelBC[d] /= DistRelBC[3]; CosAngle += DistRelBA[d]*DistRelBC[d]; } double PreFactBA = pkBen()/DistRelBA[3]; double PreFactBC = pkBen()/DistRelBC[3]; for(int d=0;d<3;d++){ Fm[p+0].Dir[d] += PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle); Fm[p+1].Dir[d] -= PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle); Fm[p+1].Dir[d] += PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle); Fm[p+2].Dir[d] -= PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle); Pre[d ] = DistRelBA[d]*pkBen()*(DistRelBC[d]-DistRelBA[d]*CosAngle); Pre[d+6] = DistRelBC[d]*pkBen()*(DistRelBA[d]-DistRelBC[d]*CosAngle); } Pre[ 3] = DistRelBA[0]*pkBen()*(DistRelBC[1]-DistRelBA[1]*CosAngle); Pre[ 4] = DistRelBA[0]*pkBen()*(DistRelBC[2]-DistRelBA[2]*CosAngle); Pre[ 5] = DistRelBA[1]*pkBen()*(DistRelBC[2]-DistRelBA[2]*CosAngle); Pre[ 9] = DistRelBC[0]*pkBen()*(DistRelBA[1]-DistRelBC[1]*CosAngle); Pre[10] = DistRelBC[0]*pkBen()*(DistRelBA[2]-DistRelBC[2]*CosAngle); Pre[11] = DistRelBC[1]*pkBen()*(DistRelBA[2]-DistRelBC[2]*CosAngle); SumTens(p,p+1,Pre); SumTens(p+1,p+2,Pre+6); } } } } return; //external double Pot[3]; double PosBf[3]; double dr[4]; double NPos[3]; for(int n=0;n<pNNano();n++){ Point2Shape(Nano[n].Shape); for(int p=0;p<pNPart();p++){ pPos(p,Pos); double Dr2 = NanoDist2(Pos,n); double InvDist = 1./Dr2; double Cons = Potential(Dr2,0,pType(p),Pot); for(int d=0;d<3;d++){ dr[d] = Nano[n].Pos[d] - pPos(p,d); if(dr[d] > .5*pInvEdge(d)) dr[d] -= pEdge(d); if(dr[d] < -.5*pInvEdge(d)) dr[d] += pEdge(d); } double Norm = SQR(Nano[n].Rad)/(SQR(dr[0]) + SQR(dr[1]) + SQR(dr[2])); Norm = sqrt(Norm); for(int d=0;d<3;d++){ NPos[d] = NPos[d] + dr[d]*Norm; Fm[p].Dir[d] += Cons*dr[d]*InvDist; Pre[d ] = Cons*dr[d]*dr[d]*InvDist; } Pre[3] = Cons*dr[0]*dr[1]*InvDist; Pre[4] = Cons*dr[0]*dr[2]*InvDist; Pre[5] = Cons*dr[1]*dr[2]*InvDist; SumTens(NPos,Pos,Pre); } } }
void ElPoly::IsoSurf(int NSample,double *IsoLevel,int NIso){ int NPairF = NFile[1]-NFile[0]; double OldPos[3] = {pNanoPos(0,0),pNanoPos(0,1),pNanoPos(0,2)}; double DensEl = CUB(NSample)/(pVol()*NPairF); double Dens = 13.3; FILE *FNano = fopen("NanoPos.txt","w"); //IsoLevel *= NPairF; for(int ff=NFile[0];ff<NFile[1];ff+=NPairF){ double *Plot = (double *)calloc(CUBE(NSample),sizeof(double)); double Min = 0.; double Max = 0.; VAR_TRIANGLE *Triang = NULL; double Pos[3]; for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_PART))return; for(int b=0;b<pNBlock();b++){ for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){ if(pType(p) != 0)continue; for(int d=0;d<3;d++){ Pos[d] = pPos(p,d) - (pNanoPos(0,d)-.5*pEdge(d)); Pos[d] -= floor(Pos[d]*pInvEdge(d))*pEdge(d); } int sx = (int)(Pos[0]*pInvEdge(0)*NSample); int sy = (int)(Pos[1]*pInvEdge(1)*NSample); int sz = (int)(Pos[2]*pInvEdge(2)*NSample); int sTot = (sx*NSample+sy)*NSample+sz; Plot[sTot] += DensEl; if(Max < Plot[sTot]) Max = Plot[sTot]; if(Min > Plot[sTot]) Min = Plot[sTot]; } } } Matrice Mask(3,3,3); Mask.FillGaussian(.5,3.); Mask.Print(); int NDim = 3; int IfMinImConv = 1; Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); // ConvoluteMatrix(Plot,NSample,&Mask,3); // ConvoluteMatrix(Plot,NSample,&Mask,3); char FString[256]; sprintf(FString,"IsoSurf%05d.dat",ff); FILE *F2Write = fopen(FString,"w"); fprintf(F2Write,"#l(%lf %lf %lf) v[%d] d[polygon]\n",pEdge(0),pEdge(1),pEdge(2),NSample); HeaderNano(F2Write); int NTri = 0; for(int i=0;i<NIso;i++){ printf("Min %lf Max %lf IsoLevel %lf DensEl %lf\n",Min,Max,IsoLevel[i],DensEl); Triang = MarchingCubes(Plot,NSample,IsoLevel[i],&NTri); for(int t=0;t<NTri;t++){ for(int i=0;i<3;i++){ int l1 = t*3 + (i+1)%3; int l2 = t*3 + (i+2)%3; for(int d=0;d<3;d++) Pos[d] = Triang[t].p[i].x[d]; int sx = (int)(Pos[0]*pInvEdge(0)*NSample); int sy = (int)(Pos[1]*pInvEdge(1)*NSample); int sz = (int)(Pos[2]*pInvEdge(2)*NSample); int sTot = (sx*NSample+sy)*NSample+sz; fprintf(F2Write,"{t[%d %d %d] ",sTot,t,0); fprintf(F2Write,"x(%lf %lf %lf) ",Pos[0],Pos[1],Pos[2]); fprintf(F2Write,"v(%lf %lf %lf) ",Triang[t].n[i].x[0],Triang[t].n[i].x[1],Triang[t].n[i].x[2]); fprintf(F2Write,"l[%d] l[%d]}\n",l1,l2); } } } fclose(F2Write); free(Plot); free(Triang);continue; int NVertex = CUBE(2*NSample-1); double *WeightL = (double *) calloc(NVertex,sizeof(double)); NormalWeight(Triang,WeightL,NSample,NTri); double CmStalk[3] = {0.,0.,0.};//OldPos[0],OldPos[1],OldPos[2]}; double CountStalk = 0.; for(int t=0;t<NTri;t++){ for(int v=0;v<3;v++){ int vRef = Triang[t].v[v]; for(int d=0;d<3;d++){ CmStalk[d] = Triang[t].p[v].x[d]*WeightL[vRef]; } CountStalk += WeightL[vRef]; } } free(WeightL); free(Triang); if(CountStalk <= 0.) CountStalk = 1.; for(int d=0;d<3;d++){ CmStalk[d] /= CountStalk; } pPos(CmStalk); SetNNano(1); for(int d=0;d<3;d++){ Nano->Pos[d] = CmStalk[d]; OldPos[d] = Nano->Pos[d]; } SetNanoBkf(0); Nano->Axis[0] = 0.; Nano->Axis[1] = 0.; Nano->Axis[2] = 1.; Nano->Rad = .5; Nano->Height = 4.; Nano->Hamaker = 1.; Nano->OffSet = 1.; Nano->Shape = SHAPE_STALK; for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ char String[120]; StringNano(String,0); fprintf(FNano,"sed '/Rigid/c\\%s' %s > Ciccia.dat\n",String,cFile[f]); fprintf(FNano,"mv Ciccia.dat %s\n",cFile[f]); //command("chmod u+x %s\n","NanoPos.txt"); //SubNanoHeader(cFile[f]); } printf("\n"); } fclose(FNano); }
int ElPoly::RadialShell(int NBin){ double Volume=0;//Global constant double Area=0.; double Norm=0.; double **Plot; double Ypsilon = 0.; double InvNFile = 1./(double)(NFile[1]-NFile[0]); Plot = (double **)calloc(NBin,sizeof(double)); for(int i=0;i<NBin;i++){ *(Plot+i) = (double *)calloc(NBin,sizeof(double)); } for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_PART))return 0; SetEdge(MIN((pEdge(CLat1)*.5),(pEdge(CLat2)*.5)),3); for(int p=0;p<pNPart();p++){ double Rad = sqrt(SQR((pPos(p,CLat1)-pCm(CLat1))) + SQR((pPos(p,CLat2)-pCm(CLat2))) ); int vr = (int)(NBin*Rad*pInvEdge(3)); int vz = (int)(NBin*pPos(p,CNorm)*pInvEdge(CNorm)); //printf("%lf %lf %d %d \n",Rad,pPos(p,CNorm),v,vv); if( vr < 0 || vr >= NBin) continue; if( vz < 0 || vz >= NBin) continue; Plot[vr][vz] += InvNFile; } Ypsilon += pEdge(2)-pCm(2)-1.; } printf("\n"); FILE *FileToWrite = fopen("RadialShell.xye","w"); //fprintf(FileToWrite,"# l(%.2f %.2f %.2f) v[60] d[chain]\n",Gen->Edge[0],Gen->Edge[1],Gen->Edge[2]); fprintf(FileToWrite,"%lf %lf %lf\n",0.,0.,0.); fprintf(FileToWrite,"%lf %lf %lf\n",pEdge(0),pEdge(1),1.); double Max=0.; for(int i=0;i<NBin;i++){ for(int j=0;j<NBin;j++){ if(Plot[i][j] > Max) Max = Plot[i][j]; } } int th=0; for(int vz=0;vz<NBin;vz++){ //for(int vr=NBin-1;vr>=0;vr--){ for(int vr=0;vr<NBin;vr++){ if(Plot[vr][vz] > 0.){ fprintf(FileToWrite,"%lf %lf %lf\n",(double)vr/NBin*pEdge(3),(double)vz/NBin*pEdge(2),Plot[vr][vz]/Max); Norm += Plot[vr][vz]; th++; if(th > 4){ th = 0; break; } } } } fclose(FileToWrite); return 0; Mat->Ypsilon = Ypsilon*InvNFile; double Vol = 1.;//pNPart()/(Gen->rho/(double)pNPCh()*CUB(5.)); Mat->PreFact = 3./8.*pow((3.*Vol)/DUE_PI,1./3.); Mat->Func = &Matematica::ContactAngle; int NRadici = 4; printf("Volume %lf Cm %lf Area %lf # to Invert %lf\n",(double)pNPart()/10.,pCm(2),Area,pow(DUE_PI/(2.*pNPart()/10.),.25)); double *Radici; Radici = (double *)malloc(NRadici*sizeof(double)); int NZeri = Mat->Zeri(0.,DUE_PI/2.,Radici,NRadici); for(int i=0;i<NZeri;i++){ Radici[i] *= 360./DUE_PI; printf("Angle %lf\n",Radici[i]); } if(NZeri == 0){ printf("The function has no real roots\n"); } free(Plot); return 0; }
void ElPoly::DefineSkin(int NSample){ std::list<Weighted_point> l; FT shrinkfactor = 0.5; double *Plot = new double[pNType()*CUBE(NSample)]; double *Count = new double[CUBE(NSample)]; double Thre = 10.; double Radius = pEdge(0)/(double)NSample; for(int p=0;p<pNPart();p++){ int t = pType(p); int vx = (int)(pPos(p,0)/pEdge(0)*NSample); int vy = (int)(pPos(p,1)/pEdge(1)*NSample); int vz = (int)(pPos(p,2)/pEdge(2)*NSample); int vTot = (vz*NSample+vy)*NSample+vx; Plot[vTot*pNType()+t] += 1.; } double *Norm = (double *)calloc(pNType(),sizeof(double)); for(int t=0;t<pNType();t++){ for(int v=0;v<CUBE(NSample);v++){ if(Norm[t] < Plot[v*pNType()+t]) Norm[t] = Plot[v*pNType()+t]; } Norm[t] = Norm[t] <= 0. ? 1. : Norm[t]; } for(int vx=0;vx<NSample;vx++){ double x = vx*pEdge(0)/(double)NSample; for(int vy=0;vy<NSample;vy++){ double y = vy*pEdge(1)/(double)NSample; for(int vz=0;vz<NSample;vz++){ double z = vz*pEdge(2)/(double)NSample; int vTot = (vz*NSample+vy)*NSample+vx; if(Plot[vTot*pNType()] > Thre){ l.push_front(Weighted_point(Bare_point(x,y,z),Radius)); } } } } Polyhedron Polyhe; Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); CGAL::mesh_skin_surface_3(skin_surface, Polyhe); // CGAL::subdivide_skin_surface_mesh_3(skin_surface, Polyhe); // std::ofstream out("mesh.off"); // out << Polyhe; glDeleteLists(Dr->Particles,1); Dr->Particles = glGenLists(1); glNewList(Dr->Particles,GL_COMPILE); // Polyhedron::Facet_iterator fcUp = Polyhe.facets_begin(); // for(;fcUp != Polyhe.facets_end(); ++fcUp){ // Polyhedron::Supports_facet_halfedge = fcUp.halfedge(); // //Halfedge_around_facet_circulator heUp = fcUp.halfedge(); // } // for (Vertex_iterator vit = Polyhe.vertices_begin();vit != Polyhe.vertices_end(); vit++){ // // Vector n = policy.normal(vit); // // n = n/sqrt(n*n); // cout << vit->point() << std::endl; // Halfedge_iterator heUp = Polyhe.halfedges_begin(); // for(;heUp != Polyhe.halfedges_end(); ++heUp){ // //Polyhedron::Halfedge_handle Half = *heUp; // Vertex_handle veUp = heUp->vertex(); // K::Point_3 pf1 = vit->point(); // } // } CGAL::Inverse_index<Vertex_handle> index(Polyhe.vertices_begin(), Polyhe.vertices_end()); for(Facet_iterator fi = Polyhe.facets_begin();fi != Polyhe.facets_end(); ++fi) { HFC hc = fi->facet_begin(); HFC hc_end = hc; Polyhedron::Vertex_handle vf1 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf2 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf3 = (*hc).vertex(); hc++; K::Point_3 pf1 = vf1->point(); K::Point_3 pf2 = vf2->point(); K::Point_3 pf3 = vf3->point(); Vettore v1(pf1.x(),pf1.y(),pf1.z()); Vettore v2(pf2.x(),pf2.y(),pf2.z()); Vettore v3(pf3.x(),pf3.y(),pf3.z()); Vettore vN(3); v1.Mult(InvScaleUn); v2.Mult(InvScaleUn); v3.Mult(InvScaleUn); vN = (v1-v2) ^ (v3-v2); //if(vN.Norm() > 2.*AreaMean) continue; double Sfumatura = .3*Mat->Casuale(); glColor4f(0.1,.4+Sfumatura,0.2,1.); //glColor4f(HueUp[p].r,HueUp[p].g,HueUp[p].b,HueUp[p].a); DrTria(&v1,&v2,&v3,&vN); glColor4f(1.,.0,0.,1.); DrTriaContour(&v1,&v2,&v3); // glPushMatrix();//Particle // glBegin(GL_LINES); // do { // Polyhedron::Vertex_handle vh = (*hc).vertex(); // K::Point_3 pf1 = vh->point(); // glVertex3d(pf1.x(),pf1.y(),pf1.z()); // } while (++hc != hc_end); // glEnd(); // glPopMatrix();//Particle } glEndList(); // Tr tr; // 3D-Delaunay triangulation // C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // Surface_3 surface(sphere_function,Sphere_3(CGAL::ORIGIN, 2.)); // Surface_mesh_default_criteria_3<Tr> criteria(30., 0.1,0.1); // // meshing surface // make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); // std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; // DT dt; // for(int c=0;c<Gen->NChain;c++){ // if(CHAIN_IF_TYPE(Ch[c].Type,CHAIN_UP) )continue; // Point_3<K> ChPos(pPos(c,CLat1),pPos(c,CLat2),pPos(c,CNorm)); // dt.insert(ChPos); // } // Face_iterator fcTr = dt.finite_faces_begin(); // glDeleteLists(Dr->Particles,1); // Dr->Particles = glGenLists(1); // glNewList(Dr->Particles,GL_COMPILE); // for(;fcTr != dt.faces_end(); ++fcTr){ // Vertex_handle vf1 = fcTr->vertex(0), // vf2 = fcTr->vertex(1),vf3 = fcTr->vertex(2); // Point pf1 = vf1->point(); // Point pf2 = vf2->point(); // Point pf3 = vf3->point(); // Vettore v1(pf1.x() - pf2.x(),pf1.y() - pf2.y(),pf1.z()-pf2.z()); // Vettore v2(pf3.x() - pf2.x(),pf3.y() - pf2.y(),pf1.z()-pf2.z()); // Vettore vN(3); // vN = v1 ^ v2; // DrTira(v1,v2,v3,vN); // } // glEndList(); }
void CHandBookHeroLayer::addTableCell( unsigned int uIdx, CTableViewCell * pCell ) { //先克隆外框条 CLayout *pLay = UICloneMgr::cloneLayout(m_pCellBlank); //对应数据 AtlasIns *pAtlasIns = m_AtlasResponse.mutable_atlas_list()->Mutable(uIdx); //赋值 for (unsigned int i=1; i<=10; i++) { CCNode *child = pLay->getChildByTag(i); pLay->removeChild(child); child->setTag(i); pCell->addChild(child); pCell->setTag(uIdx); } //1-活动底板 { CImageView* pBoard = dynamic_cast<CImageView*>(pCell->getChildByTag(1)); pBoard->setTouchEnabled(true); pBoard->setOnClickListener(this, ccw_click_selector(CHandBookHeroLayer::onClickBlank)); if ( uIdx==m_iSelectIndex ) { pBoard->setTexture(CCTextureCache::sharedTextureCache()->addImage("handBook/bookbg_2.png")); } else { pBoard->setTexture(CCTextureCache::sharedTextureCache()->addImage("handBook/bookbg_1.png")); } } //2-组合名字 { CLabel* pLabel = dynamic_cast<CLabel*>(pCell->getChildByTag(2)); } //3-//组合描述 { CLabel* pLabel = dynamic_cast<CLabel*>(pCell->getChildByTag(3)); } //4-礼品背景 //5-礼品 //10-文字 { CImageView* pGiftBg = dynamic_cast<CImageView*>(pCell->getChildByTag(4)); CImageView* pGift = dynamic_cast<CImageView*>(pCell->getChildByTag(5)); CLabel* pLabel = dynamic_cast<CLabel*>(pCell->getChildByTag(10)); pLabel->setVisible(false); pGift->stopAllActions(); //奖励领取标志 0未领取(不可领取),1未领取(可领取状态),2 已领取 switch (pAtlasIns->get_prize()) { case 0: { pGiftBg->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone)); pGift->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone)); }break; case 1: { pGiftBg->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderDefault)); pGift->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderDefault)); ResetAnchorPointAndKeepSamePos(pGift, CCPointCenter); pGift->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleTo::create(0.3f, 0.75f), CCScaleTo::create(0.3f, 0.7f)))); }break; case 2: { pGiftBg->setVisible(false); pGift->setVisible(false); pLabel->setVisible(true); }break; default: break; } } //7-进度条 //8-进度数字 //9-进度图标 { CProgressBar* pProgress = dynamic_cast<CProgressBar*>(pCell->getChildByTag(7)); CLabel* pLabel = dynamic_cast<CLabel*>(pCell->getChildByTag(8)); pLabel->setTouchEnabled(true); pLabel->setOnClickListener(this, ccw_click_selector(CHandBookHeroLayer::onClickScoreIcon)); CImageView* pIcon = dynamic_cast<CImageView*>(pCell->getChildByTag(9)); pIcon->setTouchEnabled(true); pIcon->setOnClickListener(this, ccw_click_selector(CHandBookHeroLayer::onClickScoreIcon)); } //收集列表 CCPoint pPos(80, 54); int iGapX = 94; initListCellIcon( pAtlasIns, pPos, iGapX, pCell ); }
/** Simple Monte Carlo to find the best position and radius of the osculating torus. The area and position of the torus are hence redifined counting how many hydrophilic beads are inside the torus. */ void ElPoly::StalkArea(){ FILE *FNano = fopen("NanoPosA.sh","w"); FILE *StalkArea = fopen("StalkArea.dat","w"); FILE *AreaS = fopen("AreaS.dat","w"); double OldPos[5] = {pNanoPos(0,0),pNanoPos(0,1),pNanoPos(0,2),Nano->Rad,Nano->Height}; int NBin = 36; double *Count = (double *)calloc(NBin*NBin,sizeof(double)); double RadTorus = 1.;//Nano->Rad; //fprintf(AreaS,"#l(%lf %lf %lf) \n",2.*Nano->Height,2.*Nano->Height,10.); fprintf(AreaS,"#l(%lf %lf %lf) \n",pEdge(0),pEdge(1),pEdge(2)); HeaderNano(AreaS); char FName[60]; for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_NO)) return; SetNNano(1); if(StalkPos(OldPos)) continue; //Nano->Pos[CNorm] = pCm(CNorm); //Nano->Pos[CNorm] -= floor(Nano->Pos[CNorm]*pInvEdge(CNorm))*pEdge(CNorm); double Cm[3] = {0.,0.,0.}; double CountCm = 0; int nPart = 0; double Pos[3]; //counts the particles inside the torus for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ Pos[d] = pPos(p,d) - Nano->Pos[d]; Pos[d] -= floor(pPos(p,d)*pInvEdge(d))*pEdge(d); } double Rad = hypot(Pos[CLat1],Pos[CLat2]); if(Rad > Nano->Height) continue; if(fabs(Pos[CNorm]) > RadTorus) continue; // fprintf(AreaS,"{t[%d 0 %d] x(%lf %lf %lf)",nPart++,pType(p),pPos(p,0),pPos(p,1),pPos(p,2)); // if(Ln[p].NLink > 0) fprintf(AreaS,"l[%d]",p-Ln[p].Link[0]+nPart+1); // fprintf(AreaS,"}\n"); if(pType(p) == 1) continue; for(int d=0;d<3;d++){ Cm[d] += pPos(p,d); } CountCm += 1.; int vx = (int)(Pos[CLat1]/(2.*Nano->Height)*NBin); vx += NBin/2; if(vx < 0 || vx >= NBin) continue; int vy = (int)(Pos[CLat2]/(2.*Nano->Height)*NBin); vy += NBin/2; if(vy < 0 || vy >= NBin) continue; Count[vx*NBin+vy] += 1.; } double Area = 0.; double Norm = 0.; for(int vx=0;vx<NBin;vx++){ for(int vy=0;vy<NBin;vy++){ if(Count[vx*NBin+vy] < 1.) continue; // double x = vx*Nano->Height*2./(double)NBin; // double y = vy*Nano->Height*2./(double)NBin; // fprintf(AreaS,"{t[%d 0 2] x(%lf %lf %lf)}\n",nPart++,x+pNanoPos(0,0)-Nano->Height,y+pNanoPos(0,1)-Nano->Height,pNanoPos(0,2)); Area += 1.; } } if(CountCm <= 0.){ printf("No particles in the torus %s\n",cFile[f]); return; } Nano->Area = SQR(2.*Nano->Height)*Area/(double)(SQR(NBin)); for(int d=0;d<3;d++){ Cm[d] /= CountCm; } Cm[CNorm] = pCm(CNorm); //fprintf(AreaS,"%lf %lf %lf\n",Cm[0]-Nano->Pos[0],Cm[1]-Nano->Pos[1],Cm[2]-Nano->Pos[2]); for(int d=0;d<3;d++){ Nano->Pos[d] = Cm[d] - floor(Cm[d]*pInvEdge(d))*pEdge(d); fprintf(StalkArea,"%lf %lf\n",pTime(),Nano->Area); } SetNanoBkf(0); Nano->Height = Nano->Rad + sqrt(Nano->Area/DUE_PI); char String[120]; StringNano(String,0); fprintf(StalkArea,"%lf %lf\n",pTime(),Nano->Area); fprintf(FNano,"sed '/Rigid/c\\%s' %s > Ciccia.dat\n",String,cFile[f]); fprintf(FNano,"mv Ciccia.dat %s\n",cFile[f]); sprintf(FName,"Centered%05d.dat",f); //Write(FName); //HeaderNano(AreaS); } fclose(AreaS); fclose(StalkArea); fclose(FNano); free(Count); printf("\n"); }