bool ZernikeMom::CalculateOneFrame(int frame){ const double PI = 3.141592654; // cout << "ZernikeMom::CalculateOneFrame("<<frame<<")"<<endl; EnsureImage(); SegmentData()->setCurrentFrame(frame); TabulateFactorials(param.maxorder); FindSegmentNormalisations(); int nc=NumberOfCoefficients(param.maxorder); vector<double> zerovec(nc,0.0); vector<vector<double> > A_real(DataCount(),zerovec); vector<vector<double> > A_imag(DataCount(),zerovec); int width = Width(true), height = Height(true); int resind=0; for(int n=0;n<=param.maxorder;n++) for(int m=n&1;m<=n;m+=2){ for (int y=0; y<height; y++) for (int x=0; x<width; x++){ vector<int> svec = SegmentVector(frame, x, y); for (size_t j=0; j<svec.size(); j++) { int dataind = DataIndex(svec[j], true); if(dataind != -1){ int label=svec[j]; double xtilde=(x-XAvg(label))*Scaling(label); double ytilde=(y-YAvg(label))*Scaling(label); double roo=sqrt(xtilde*xtilde+ytilde*ytilde); double theta; if(ytilde || xtilde) theta=atan2(ytilde,xtilde); else theta=0; double r=R(n,m,roo); r *= Scaling(label)*Scaling(label)*(n+1)/PI; A_real[dataind][resind] += r*cos(m*theta); A_imag[dataind][resind] -= r*sin(m*theta); } } } resind++; } for(size_t i=0;i<A_real.size();i++){ ((ZernikeMomData*)GetData(i))->SetData(A_real[i],A_imag[i],param); } calculated = true; return true; }
bool ZernikeMom::CalculateOneLabel(int frame, int label) { const double PI = 3.141592654; EnsureImage(); SegmentData()->setCurrentFrame(frame); TabulateFactorials(param.maxorder); FindSegmentNormalisations(label); int nc=NumberOfCoefficients(param.maxorder); vector<double> A_real(nc,0.0); vector<double> A_imag(nc,0.0); int width = Width(true), height = Height(true); int resind=0; for(int n=0;n<=param.maxorder;n++) for(int m=n&1;m<=n;m+=2){ for (int y=0; y<height; y++) for (int x=0; x<width; x++){ vector<int> svec = SegmentVector(frame, x, y); for (size_t j=0; j<svec.size(); j++) { if(svec[j]==label){ double xtilde=(x-XAvg(label))*Scaling(label); double ytilde=(y-YAvg(label))*Scaling(label); double roo=sqrt(xtilde*xtilde+ytilde*ytilde); double theta; if(ytilde || xtilde) theta=atan2(ytilde,xtilde); else theta=0; double r=R(n,m,roo); r *= Scaling(label)*Scaling(label)*(n+1)/PI; A_real[resind] += r*cos(m*theta); A_imag[resind] -= r*sin(m*theta); } } } resind++; } int ind = DataIndex(label, true); if(ind==-1) return false; ((ZernikeMomData*)GetData(ind))->SetData(A_real,A_imag,param); calculated = true; return true; }
MutualInformation (const std::vector<std::vector<int> >& _data, const std::vector<double>& _weights) : m_features (_data) , m_weights (_weights) { if (m_features.empty ()) return; m_numFeatures = m_features.size (); std::vector<std::pair<int, int> > minMax; minMax.assign (m_numFeatures, std::make_pair(0,0)); std::vector<std::pair<int,int> >::iterator itMM = minMax.begin (); for (std::vector<std::vector<int> >::const_iterator it = m_features.begin (), itEnd = m_features.end (); it != itEnd; ++it, ++itMM) { const std::vector<int>& features = (*it); for (std::vector<int>::const_iterator it = features.begin (), itEnd = features.end (); it != itEnd; ++it) { const int& val = (*it); std::pair<int,int>& mm = (*itMM); mm.first = std::min (mm.first, val); mm.second = std::max (mm.second, val); } } int idx = 0; for (std::vector<std::pair<int,int> >::const_iterator it = minMax.begin (), itEnd = minMax.end (); it != itEnd; ++it) { m_dataIndices.push_back (DataIndex (idx, (*it).first, (*it).second - (*it).first+1)); ++idx; } m_Hx.assign (m_numFeatures, 0.0); m_H_joint_xy.assign (m_numFeatures*m_numFeatures, 0.0); m_H_joint_xyz.assign (m_numFeatures*m_numFeatures*m_numFeatures, 0.0); m_isHx.assign (m_numFeatures, false); m_isH_joint_xy.assign (m_numFeatures*m_numFeatures, false); m_isH_joint_xyz.assign (m_numFeatures*m_numFeatures*m_numFeatures, false); }
// new define void LevelFluxRegisterEdge::define( const DisjointBoxLayout& a_dbl, const DisjointBoxLayout& a_dblCoarse, const ProblemDomain& a_dProblem, int a_nRefine, int a_nComp) { m_isDefined = true; CH_assert(a_nRefine > 0); CH_assert(a_nComp > 0); CH_assert(!a_dProblem.isEmpty()); m_nComp = a_nComp; m_nRefine = a_nRefine; m_domainCoarse = coarsen(a_dProblem, a_nRefine); CH_assert (a_dblCoarse.checkPeriodic(m_domainCoarse)); // allocate copiers m_crseCopiers.resize(SpaceDim*2); SideIterator side; // create a Vector<Box> of the fine boxes which also includes periodic images, // since we don't really care about the processor layouts, etc Vector<Box> periodicFineBoxes; CFStencil::buildPeriodicVector(periodicFineBoxes, a_dProblem, a_dbl); // now coarsen these boxes... for (int i=0; i<periodicFineBoxes.size(); i++) { periodicFineBoxes[i].coarsen(m_nRefine); } for (int idir=0 ; idir<SpaceDim; ++idir) { for (side.begin(); side.ok(); ++side) { // step one, build fineBoxes, flux register boxes // indexed by the fine level but in the coarse index // space DisjointBoxLayout fineBoxes,tmp; // first create coarsened dbl, then compute flux register boxes // adjacent to coarsened fine boxes coarsen(tmp, a_dbl, m_nRefine); if (side() == Side::Lo) { adjCellLo(fineBoxes, tmp, idir,1); } else { adjCellHi(fineBoxes, tmp, idir,1); } // now define the FluxBoxes of fabFine on this DisjointBoxLayout m_fabFine[index(idir, side())].define(fineBoxes, a_nComp); LayoutData<Vector<Vector<IntVectSet> > >& ivsetsVect = m_refluxLocations[index(idir, side())]; ivsetsVect.define(a_dblCoarse); LayoutData<Vector<DataIndex> >& mapsV = m_coarToCoarMap[index(idir, side())]; mapsV.define(a_dblCoarse); DisjointBoxLayout coarseBoxes = a_dblCoarse; DataIterator dit = a_dblCoarse.dataIterator(); for (dit.begin(); dit.ok(); ++dit) { unsigned int thisproc = a_dblCoarse.procID(dit()); if (thisproc == procID()) { ivsetsVect[DataIndex(dit())].resize(SpaceDim); } const Box& coarseBox = a_dblCoarse[dit()]; int count = 0; for (int i=0; i<periodicFineBoxes.size(); i++) { Box regBox; if (side() == Side::Lo) { regBox = adjCellLo(periodicFineBoxes[i], idir, 1); } else { regBox = adjCellHi(periodicFineBoxes[i], idir, 1); } // do this little dance in order to ensure that // we catch corner cells which might be in different // boxes. Box testBox(regBox); testBox.grow(1); testBox.grow(idir,-1); if (testBox.intersectsNotEmpty(coarseBox)) { testBox &= coarseBox; ++count; unsigned int proc = a_dblCoarse.procID(dit()); const DataIndex index = DataIndex(dit()); if (proc == procID()) { mapsV[DataIndex(dit())].push_back(index); // loop over face directions here for (int faceDir=0; faceDir<SpaceDim; faceDir++) { // do nothing in normal direction if (faceDir != idir) { // this should give us the face indices for the // faceDir-centered faces adjacent to the coarse-fine // interface which are contained in the current // coarse box Box intersectBox(regBox); Box coarseEdgeBox(coarseBox); coarseEdgeBox.surroundingNodes(faceDir); intersectBox.surroundingNodes(faceDir); intersectBox &= coarseEdgeBox; intersectBox.shiftHalf(faceDir,1); IntVectSet localIV(intersectBox); ivsetsVect[DataIndex(dit())][faceDir].push_back(localIV); } } } } } // end loop over boxes on coarse level } m_regCoarse.define(coarseBoxes, a_nComp, IntVect::Unit); // last thing to do is to define copiers m_crseCopiers[index(idir, side())].define(fineBoxes, coarseBoxes, IntVect::Unit); } } }