void LinearLaRank::eval(Sample& sample, Result& result) { // Evaluate the sample if (m_sampleCount) { // Convert the Sample to LaRank form SVector laX; for (int nFeat = 0; nFeat < sample.x.rows(); nFeat++) { laX.set(nFeat, sample.x(nFeat)); } m_svm->predict_with_scores(laX, result); // Convert the scores to probabilities double totalProb = 0.0; for (int nClass = 0; nClass < *m_numClasses; nClass++) { result.confidence[nClass] = exp(result.confidence[nClass]); totalProb += result.confidence[nClass]; } for (int nClass = 0; nClass < *m_numClasses; nClass++) { result.confidence[nClass] /= (totalProb + 1e-16); } } else { for (int nClass = 0; nClass < *m_numClasses; nClass++) { result.confidence[nClass] = 1.0 / *m_numClasses; } result.prediction = 0; } }
void saveSvmLight(const char *fname, docs_t &docs, intvector_t &ids) { cerr << "# Writing " << fname << "." << endl; ogzstream f; f.open(fname); if (! f.good()) { cerr << "ERROR: cannot open " << fname << " for writing." << endl; ::exit(10); } for(int i=0; i<(int)ids.size(); i++) { int id = ids[i]; bool y = classes[id]; SVector s = docs[id]; int p = s.npairs(); if (p <= 0) { cerr << "ERROR: empty vector " << id << "." << endl; ::exit(10); } f << ((y) ? +1 : -1); f << s; if (! f.good()) { cerr << "ERROR: writing " << fname << " for writing." << endl; ::exit(10); } } cerr << "# Done. Wrote " << ids.size() << " examples." << endl; }
static void loadmult_datafile_sub(istream &f, bool binary, const char *fname, xvec_t &xp, yvec_t &yp, int &maxdim, int maxrows) { cout << "# Reading file " << fname << endl; if (! f.good()) assertfail("Cannot open " << fname); int pcount = 0; while (f.good() && maxrows--) { double y; SVector x; y = (f.get()); x.load(f); if (f.good()) { xp.push_back(x); yp.push_back(y); pcount += 1; if (x.size() > maxdim) maxdim = x.size(); } } cout << "# Read " << pcount << " examples." << endl; }
void load(const char *fname, xvec_t &xp, yvec_t &yp) { cout << "Loading " << fname << "." << endl; igzstream f; f.open(fname); if (! f.good()) { cerr << "ERROR: cannot open " << fname << "." << endl; exit(10); } int pcount = 0; int ncount = 0; bool binary; string suffix = fname; if (suffix.size() >= 7) suffix = suffix.substr(suffix.size() - 7); if (suffix == ".dat.gz") binary = false; else if (suffix == ".bin.gz") binary = true; else { cerr << "ERROR: filename should end with .bin.gz or .dat.gz" << endl; exit(10); } while (f.good()) { SVector x; double y; if (binary) { y = (f.get()) ? +1 : -1; x.load(f); } else { f >> y >> x; } if (f.good()) { assert(y == +1 || y == -1); xp.push_back(x); yp.push_back(y); if (y > 0) pcount += 1; else ncount += 1; if (x.size() > dim) dim = x.size(); } if (trainsize > 0 && xp.size() > (unsigned int)trainsize) break; } cout << "Read " << pcount << "+" << ncount << "=" << pcount + ncount << " examples." << endl; }
bool DDynamicActor::Collision_IntersectCheck( int ) { DLogWriteSystem(" Collision_IntersectCheck : %p", this ); SVector Location = m_Locus.Location; SVector Start = Physics::g_vStart; if( m_dwColFlag & CF_COLLIDEDBY_ROOT_INTERNAL ) { Location = GMath.ZeroVector; SMatrix Matrix = (this->m_matRootMatrixForCollision * m_Locus.LocalToWorld).Inverse(); Start = Matrix.TransformVector( Physics::g_vStart ); } SVector vExtent = Physics::g_vExtent + this->m_vExtent; SVector Delta = Start - Location; if( Abs(Delta.Y) >= vExtent.Y ) return false; float DeltaSquared2D = Delta.SizeSquared2D(); float RadiusSquared = Square(vExtent.X); if( DeltaSquared2D >= RadiusSquared ) return false; float Overlap = appSqrt( RadiusSquared ) - appSqrt( DeltaSquared2D ); if( Overlap <= Physics::g_SingleResult.m_fTime ) return false; Physics::g_SingleResult.m_nActorIndex = m_dwID; Physics::g_SingleResult.m_nMeshIndex = -1; Physics::g_SingleResult.m_fTime = Overlap; Delta.Y = 0.f; Physics::g_SingleResult.m_vNormal = Delta.SafeNormal(); Physics::g_SingleResult.m_vContactPoint= m_Locus.Location + this->m_vExtent.X * Physics::g_SingleResult.m_vNormal; Physics::g_SingleResult.m_ActorType = this->m_ActorType; return true; }
SValue For::Evaluate(const sptr<BShell>& parent, const sptr<ICommand>& shell, bool* outExit) { SVector<SValue> args; for (size_t i = 0 ; i < m_words.CountItems(); i++) { bool insert_args = false; //bout << "WORDS [" << i << "] " << m_words[i] << endl; SValue expanded = Expand(shell, m_words.ItemAt(i), &insert_args); if (insert_args) { collect_arguments(expanded.AsString(), &args); } else { //bout << "adding expanded " << expanded << endl; args.AddItem(expanded); } } *outExit = false; SValue returned = SValue::Status(B_OK); for (size_t i = 0 ; i < args.CountItems() && !*outExit; i++) { //bout << "setting m_condition to be " << args.ItemAt(i) << endl; shell->SetProperty(SValue::String(m_condition), args.ItemAt(i)); returned = m_dolist->Evaluate(parent, shell, outExit); } return returned; }
Real Vector::operator*(const SVector& v) const { assert(dim() >= v.dim()); int i; Real x = 0; for (i = v.size(); i-- > 0;) x += val[v.index(i)] * v.value(i); return x; }
void load_classes(const char *fname, int &nclass) { string filename = fname; ifstream f; SVector x; f.open(fname); x.load(f); nclass = x.size(); }
void SH::generateBasisFuncVisualizationPoints( int numPoints, int l, int m, const Vector& center ) { for( int i = 0 ; i < numPoints ; i++ ) { SVector sv = SVector::random( 1 ) ; // get SH value for band. real value = Y( l, m, sv.tElevation, sv.pAzimuth ) ; window->addDebugPoint( sv.toCartesian() + center, Vector::toRGB( 180*(value+1), 1, 1 ) ) ; // coloration by mag of point } }
void LinearLaRank::update(Sample& sample) { // Convert the Sample to LaRank form SVector laX; for (int nFeat = 0; nFeat < sample.x.rows(); nFeat++) { laX.set(nFeat, sample.x(nFeat)); } // Add the sample to svm m_sampleCount++; m_svm->add(laX, sample.y, m_sampleCount, sample.w); }
void rem_binder_cleanup_func(binder_cleanup_func func) { SAutolock _l(g_cleanupLock.Lock()); size_t N = g_cleanupFuncs.CountItems(); for (size_t i=0; i<N; i++) { if (g_cleanupFuncs[i] == func) { g_cleanupFuncs.RemoveItemsAt(i); i--; N--; } } }
void call_binder_cleanup_funcs() { SVector<binder_cleanup_func> funcs; { SAutolock _l(g_cleanupLock.Lock()); funcs = g_cleanupFuncs; g_cleanupFuncs.MakeEmpty(); } size_t N = funcs.CountItems(); while (N-- > 0) { funcs[N](); } }
void CollectParents(InterfaceRec* rec, const SVector<InterfaceRec*>& classes, SVector<InterfaceRec*>* out) { SVector<SString> parents = rec->Parents(); const size_t N = parents.CountItems(); for (size_t i=0; i<N; i++) { const size_t Nc = classes.CountItems(); for (size_t c=0; c<Nc; c++) { if (parents[i] == classes[c]->ID() || parents[i] == classes[c]->FullInterfaceName()) { out->AddItem(classes[c]); } } } out->AddItem(rec); }
void saveBinary(const char *fname, docs_t &docs, intvector_t &ids) { cerr << "# Writing " << fname << "." << endl; ogzstream f; f.open(fname); if (! f.good()) { cerr << "ERROR: cannot open " << fname << " for writing." << endl; ::exit(10); } int pcount = 0; int ncount = 0; int npairs = 0; for(int i=0; i<(int)ids.size(); i++) { int id = ids[i]; bool y = classes[id]; if (y) pcount += 1; else ncount += 1; SVector s = docs[id]; int p = s.npairs(); npairs += p; if (p <= 0) { cerr << "ERROR: empty vector " << id << "." << endl; ::exit(10); } f.put( y ? 1 : 0); s.save(f); if (! f.good()) { cerr << "ERROR: writing " << fname << " for writing." << endl; ::exit(10); } } cerr << "# Done. Wrote " << ids.size() << " examples." << endl; cerr << "# with " << npairs << " pairs, " << pcount << " positives, and " << ncount << " negatives." << endl; }
void GSphere::ExpandBoundBySphere( const GSphere &Src ) { // Method 1 = 대상구와의 거리 + 반지름을 한 길이가 더 길면, 그만큼 반지름을 확장한다. // Method 2 = Method-1의 체크가 TRUE이면, 두 구의 중심을 잇는 선의 중점에서 두 구와의 거리의 반을 반지름으로 하는 // 구를 만들면 최적화된 구가 나온다. // 여기서는 Method-2를 쓴다. SVector vSub; vSub = Src.vecCenter - vecCenter; float fDistCenter = vSub.Size(); if( fDistCenter+Src.fRadius > fRadius ) { vecCenter = vecCenter + vSub/2.0f; fRadius = fDistCenter/2.0f; } }
// Organizing the cache of an output void load_output (LaFVector nbeta, int nl, SVector & rtoi) { beta = nbeta; l = nl; for (int r = 0; r < l; r++) larank_kcache_swap_ri (kernel, r, (int) rtoi.get (r)); }
DSVector::DSVector(const SVector& old) : theelem( 0 ) { allocMem(old.size() + 1); SVector::operator= ( old ); assert(DSVector::isConsistent()); }
void CCamera::Update(float ftDelta) { SRotator Rot = this->Location().Rotation; if(m_bImpact) { if(m_ftElapsedTime < m_ftImpactTime/2.0f) { m_vctTargetEye = m_vctTargetEye*m_ftElapsedTime + m_vctCurrentEye*(m_ftImpactTime/2.0f-m_ftElapsedTime); m_vctTargetEye *= m_ftImpactTime/2.0f; } else { m_vctTargetEye = m_vctTargetEye*(m_ftElapsedTime-m_ftImpactTime/2.0f) + m_vctCurrentEye*(m_ftImpactTime-m_ftElapsedTime); m_vctTargetEye *= m_ftImpactTime/2.0f; } } float ftVelocityEye = 10.0f; SVector vctDelta = m_vctTargetEye - m_vctCurrentEye; if(vctDelta.Size2D() < ftDelta * ftVelocityEye) { m_vctCurrentEye = m_vctTargetEye; } else { vctDelta.Normalize(); m_vctCurrentEye = m_vctCurrentEye + vctDelta * ftDelta * ftVelocityEye; } m_vctCurrentEye = m_vctTargetEye; if(m_bJerk) { // if(((int)(m_fFlashTime * 5.0f)) % 2 == 0) SVector vctDelta = m_vctCurrentEye - m_vctCurrentAt; m_vctCurrentAt.Y += float(rand()%10-5)/10.0f * m_ftJerk * vctDelta.Size() / 20.0f; } CreateLookAt(m_vctCurrentEye, m_vctCurrentAt, SVector(0.0f, 1.0f, 0.0f)); }
void GSphere::SetSphere( const GBoxAA *pBox, bool bYIgnore ) { if( !pBox ) { Init(); return; } vecCenter = pBox->vecCenter; if( bYIgnore ) { fRadius = appSqrt( appSquare(pBox->vecSize.X/2.0f) + appSquare(pBox->vecSize.Z/2.0f) ); } else { SVector v = pBox->vecCenter - pBox->vecMax; fRadius = v.Size(); } if( fRadius < pBox->vecSize.X/2.0f ) fRadius = pBox->vecSize.X/2.0f; if( !bYIgnore && fRadius < pBox->vecSize.Y/2.0f ) fRadius = pBox->vecSize.Y/2.0f; if( fRadius < pBox->vecSize.Z/2.0f ) fRadius = pBox->vecSize.Z/2.0f; fRadiusSq = appSquare(fRadius); }
void DComputeBoundingSphere( SVector& vCenterOut, float& fRadiusOut, const SVector *pVertices, dword dwNumVertices ) { if( dwNumVertices==0 ) return; vCenterOut.X = vCenterOut.Y = vCenterOut.Z = 0.0; for( dword nVert=0; nVert<dwNumVertices; ++nVert ) { vCenterOut += pVertices[nVert]; } vCenterOut /= (float)dwNumVertices; SVector vSub; float fTest; for(int nVert=0; nVert<dwNumVertices; ++nVert ) { vSub = vCenterOut - pVertices[nVert]; fTest = vSub.SizeSquared(); if( fTest>fRadiusOut ) { fRadiusOut = fTest; } } fRadiusOut = appSqrt(fRadiusOut); }
status_t IDLStruct::SetInterfaces(SVector<InterfaceRec> interfaces) { p_interfaces=interfaces; #ifdef STRUCTDEBUG bout << "<----- idlstruct.cpp -----> there are now " << p_interfaces.CountItems() << " interfaces in IDLStruct\n"; for (size_t index=0 ; index<interfaces.CountItems() ; index++ ) { bout << "<----- idlstruct.cpp -----> " <<p_interfaces.ItemAt(index).ID() << " added\n"; } #endif return B_OK; }
void SVSet::xtend(SVector& svec, int newmax) { if (svec.max() < newmax) { if (possiblyUnusedMem * memFactor > memSize()) memPack(); assert(has(&svec)); DLPSV* ps = static_cast<DLPSV*>( & svec ); if (ps == list.last()) { int sz = ps->size(); ensureMem (newmax - ps->max() + 1); insert(memSize(), newmax - ps->max()); ps->setMem (newmax + 1, ps->mem()); ps->set_size( sz ); } else { ensureMem(newmax + 1); SVector newps(newmax + 1, &last() + 1); int sz = ps->size(); insert(memSize(), newmax + 1); newps = svec; if (ps != list.first()) { SVector* prev = ps->prev(); int prevsz = prev->size(); prev->setMem (prev->max() + ps->max() + 2, prev->mem()); prev->set_size(prevsz); possiblyUnusedMem += ps->max(); } list.remove(ps); list.append(ps); ps->setMem(newmax + 1, newps.mem()); ps->set_size(sz); } } }
void computeNormalizedTfIdf() { cerr << "# Computing document frequencies" << endl; int terms = dico.size(); vector<double> nt(terms+1); double nd = trainid.size(); for(int i=0; i<terms+1; i++) nt[i] = 0; for(int i=0; i<(int)trainid.size(); i++) { int id = trainid[i]; SVector s = train[id]; for (const SVector::Pair *p = s; p->i >= 0; p++) if (p->v > 0) nt[p->i] += 1; } cerr << "# Computing TF/IDF for training set" << endl; for(int i=0; i<(int)trainid.size(); i++) { int id = trainid[i]; SVector s = train[id]; SVector v; for (const SVector::Pair *p = s; p->i >= 0; p++) if (nt[p->i] > 0) v.set(p->i, (1.0 + log(p->v)) * log(nd/nt[p->i])); double norm = dot(v,v); v.scale(1.0 / sqrt(norm)); train[id] = v; } cerr << "# Computing TF/IDF for testing set" << endl; for(int i=0; i<(int)testid.size(); i++) { int id = testid[i]; SVector s = test[id]; SVector v; for (const SVector::Pair *p = s; p->i >= 0; p++) if (nt[p->i] > 0) v.set(p->i, (1.0 + log(p->v)) * log(nd/nt[p->i])); double norm = dot(v,v); v.scale(1.0 / sqrt(norm)); test[id] = v; } cerr << "# Done." << endl; }
void SVSet::add2(SVector &svec, int n, const int idx[], const Real val[]) { xtend(svec, svec.size() + n); svec.add(n, idx, val); }
SValue SimpleCommand::Evaluate(const sptr<BShell>& parent, const sptr<ICommand>& shell, bool* outExit) { // bout << "SimpleCommand::Evaluate: " << m_command << endl; sptr<ICommand> command = NULL; bool doExit = false; *outExit = false; if (m_command != "" && m_command != "exit" && m_command != "return" && m_command != "cd" && m_command != "." && m_command != "source") { SValue cmdName = Expand(shell, m_command); // If the command is actually an ICommand object, // run it in-place. // XXX This isn't quite right -- we really want // to spawn a copy, in which we can set our own // environment. command = ICommand::AsInterface(cmdName); // Not an object, try to execute by name. if (command == NULL) { command = shell->Spawn(cmdName.AsString()); } if (command == NULL) { parent->TextError() << "bsh: " << m_command << ": command not found" << endl; return SValue::Status(B_NAME_NOT_FOUND); } } else command = shell; SValue result; if (m_prefix != NULL) result = m_prefix->Evaluate(parent, command, &doExit); if (m_suffix != NULL) m_suffix->Evaluate(parent, command, &doExit); SVector<SString> words; if (m_suffix != NULL) words = m_suffix->GetWords(); // set redirects // build argument list ICommand::ArgList args; args.AddItem(SValue::String(m_command)); for (size_t index = 0 ; index < words.CountItems(); index++) { bool expand = false; //bout << "WORDS [" << index << "] " << words[index] << endl; SValue expanded = Expand(shell, words.ItemAt(index), &expand); //bout << "WORDS [" << index << "] expaned to " << expanded << endl; if (expand) { collect_arguments(expanded.AsString(), &args); } else { args.AddItem(expanded); } } // only run this if we are a newly spawned command! if (command != shell) { result = command->Run(args); // This command may be a function, that could call "exit". *outExit = parent->ExitRequested(); } else if (m_command == "exit" || m_command == "return") { result = args.CountItems() > 1 ? args[1] : SValue::Status(B_OK); *outExit = true; if (m_command == "exit") { parent->RequestExit(); } } else if (m_command == "cd") { SString path; if (args.CountItems() > 1) { path = args[1].AsString(); } if (path != "") { SString cd=shell->GetProperty(SValue::String("PWD")).AsString(); cd.PathAppend(path, true); SNode node(parent->Context().Root()); SValue dir(node.Walk(cd, (uint32_t)0)); if (interface_cast<INode>(dir) != NULL) { shell->SetProperty(SValue::String("PWD"), SValue::String(cd)); result = SValue::Status(B_OK); } else { parent->TextError() << "cd: '" << path << "' is not a directory." << endl; result = SValue::Status(B_BAD_VALUE); } } else { parent->TextError() << "cd: no directory specified." << endl; result = SValue::Status(B_BAD_VALUE); } } else if (m_command == "." || m_command == "source") { if (args.CountItems() > 1) { sptr<ITextInput> input; SString path; find_some_input(args[1], parent, &input, &path); if (input != NULL) { SValue oldFile = parent->GetProperty(kBSH_SCRIPT_FILE); SValue oldDir = parent->GetProperty(kBSH_SCRIPT_DIR); args.RemoveItemsAt(0, 2); args.AddItemAt(SValue::String(path), 0); parent->SetLastResult(SValue::String(path)); parent->SetProperty(kBSH_SCRIPT_FILE, SValue::String(path)); SString parentDir; path.PathGetParent(&parentDir); parent->SetProperty(kBSH_SCRIPT_DIR, SValue::String(parentDir)); FunctionCommand::ArgumentHandler argHandler; argHandler.ApplyArgs(parent, args, true); sptr<Lexer> lexer = new Lexer(parent, input, parent->TextOutput(), false); SValue result; if (lexer != NULL) { Parser parser(parent); SValue result = parser.Parse(lexer); } else { parent->TextError() << m_command << ": out of memory." << endl; result = SValue::Status(B_NO_MEMORY); } argHandler.RestoreArgs(parent); parent->SetProperty(kBSH_SCRIPT_FILE, oldFile); parent->SetProperty(kBSH_SCRIPT_DIR, oldDir); return result; } else { parent->TextError() << m_command << ": '" << args[1] << "' is not a file." << endl; result = SValue::Status(B_BAD_VALUE); } } else { parent->TextError() << m_command << ": no file specified." << endl; result = SValue::Status(B_BAD_VALUE); } *outExit = parent->ExitRequested(); } return result; }
void NamespaceGenerator::EnterNamespace(const sptr<ITextOutput> stream, const SString& newNS, const SVector<SString>& newUsing) { SString ns, nspart; int32_t pos, oldpos; size_t i; bool diff = prevNamespace != newNS; for (i=0; !diff && i<newUsing.CountItems(); i++) { diff = prevUsing.IndexOf(newUsing[i]) < 0; } if (!diff) return; bool haveNamespaces = false; if (prevNamespace != newNS) { if (prevNamespace.Length() > 0) { stream << endl; if (!haveNamespaces) { haveNamespaces = true; stream << "#if _SUPPORTS_NAMESPACE" << endl; } for (i=0; i<namespaceDepth; i++) stream << "} "; namespaceDepth = 0; stream << "// namespace " << prevNamespace << endl; stream << endl; } prevNamespace = newNS; prevUsing.MakeEmpty(); if (prevNamespace.Length() > 0) { ns = newNS; oldpos = 0; while ((pos = ns.FindFirst("::", oldpos)) > 0) { nspart.SetTo(ns.String()+oldpos, pos-oldpos); if (!haveNamespaces) { haveNamespaces = true; stream << "#if _SUPPORTS_NAMESPACE" << endl; } stream << "namespace " << nspart << " {" << endl; oldpos = pos + 2; namespaceDepth++; } namespaceDepth++; nspart.SetTo(ns.String()+oldpos); if (!haveNamespaces) { haveNamespaces = true; stream << "#if _SUPPORTS_NAMESPACE" << endl; } stream << "namespace " << nspart << " {" << endl; } else { namespaceDepth = 0; } } if (newNS != "palmos::support" && prevUsing.IndexOf(SString("palmos::support")) < 0) { if (!haveNamespaces) { stream << "#if _SUPPORTS_NAMESPACE" << endl; } haveNamespaces = true; stream << "using namespace palmos::support;" << endl; prevUsing.AddItem(SString("palmos::support")); } for (i=0; i<newUsing.CountItems(); i++) { const SString& n = newUsing[i]; if (newNS != n && prevUsing.IndexOf(n) < 0) { if (!haveNamespaces) { stream << "#if _SUPPORTS_NAMESPACE" << endl; } haveNamespaces = true; stream << "using namespace " << n << ";" << endl; prevUsing.AddItem(n); } } if (haveNamespaces) { stream << "#endif /* _SUPPORTS_NAMESPACE */" << endl; stream << endl; } }
void readDocs(const char *fname, docs_t &docs, bool freezedico=false) { cerr << "# Reading " << fname << endl; igzstream f; f.open(fname); if (! f.good()) { cerr << "ERROR: cannot open file " << fname << endl; ::exit(10); } string token; f >> token; if (token != ".I") { cerr << "ERROR: Cannot read initial .I in " << fname << endl; ::exit(10); } int id = 0; int count = 0; while(f.good()) { f >> id >> token; count += 1; if (! f.good() || token != ".W") { cerr << "ERROR (" << id << "): " << "Cannot read \"<id> .W\"." << endl; ::exit(10); } int wid = -1; string otoken; SVector s; for(;;) { f >> token; if (!f.good() || token == ".I") break; if (token != otoken) { dico_t::iterator it = dico.find(token); if (it != dico.end()) wid = it->second; else if (freezedico) continue; else { wid = dico.size() + 1; dico[token] = wid; } otoken = token; } s.set(wid, s.get(wid)+1.0); } if (s.npairs() <= 0) { cerr << "ERROR (" << id << "): " << "Empty vector " << id << "?" << endl; ::exit(10); } docs[id] = s; } if (!f.eof()) { cerr << "ERROR (" << id << "): " << "Failed reading words" << endl; ::exit(10); } cerr << "# Done reading " << count << " documents." << endl; }
//switch(comp) //{ // case GRAY: // channelIndex = 1; // break; // case RED: // channelIndex = 2; // break; // case GREEN: // channelIndex = 1; // break; // case BLUE: // channelIndex = 0; // break; //} //if( (height-1-i) < (Rhistogram.datos[j]) ) //{ // matrix[i][j] = 255.0; //}else //{ // matrix[i][j] = 0.0; //} IplImage* ImageCreater::histogram_image_by_opencv(Image *myImg) { int height = 200; int width = 256; //IPL_DEPTH_32F register int index = 0; double max=0.0; int pix = 0; unsigned char RMatrix[200][256], GMatrix[200][256], BMatrix[200][256],VMatrix[200][256]; ulint N = (ulint)myImg->get_rows()*myImg->get_cols(); SVector Rhistogram = myImg->histogram_vector(RED,0,false); SVector Ghistogram = myImg->histogram_vector(GREEN,0,false); SVector Bhistogram = myImg->histogram_vector(BLUE,0,false); myImg->to_grayscale(); SVector Vhistogram = myImg->histogram_vector(GRAY,0,true); IplImage* img = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U ,3); Rhistogram.normalized((double)N); Ghistogram.normalized((double)N); Bhistogram.normalized((double)N); Vhistogram.normalized((double)N); max = Rhistogram.get_max(); cout << " \nRMax:" << max; max = Ghistogram.get_max(); cout << " \nGMax:" << max; max = Bhistogram.get_max(); cout << " \nBMax:" << max; cout << endl << " RHist[0] = " << Rhistogram.datos[0] << " RHist[255] = " << Rhistogram.datos[255]; cout << endl << " GHist[0] = " << Ghistogram.datos[0] << " GHist[255] = " << Ghistogram.datos[255]; cout << endl << " BHist[0] = " << Bhistogram.datos[0] << " BHist[255] = " << Bhistogram.datos[255]; max = Vhistogram.get_max(); //cout << " \nVMax:" << max; max = Util::max( Util::max(Rhistogram.get_max(), Ghistogram.get_max()), Util::max(Bhistogram.get_max(),Vhistogram.get_max())); //Util::max(Bhistogram.get_max(),Vhistogram.get_max()) ); //max = max/2; cout << " \nMax:" << max; cout << " "; for(register int i=0; i< height; i++) for(register int j=0; j< width; j++) { RMatrix[i][j] = 0; GMatrix[i][j] = 0; BMatrix[i][j] = 0; VMatrix[i][j] = 0; } for(int j=0; j<width ; j++) { pix = (int)((double)(height-1)*( (double)(Rhistogram.datos[j]) / (max) )); pix = height - pix - 1; RMatrix[pix][j]=255; pix = (int)((double)(height-1)*( (double)(Ghistogram.datos[j]) / (max) )); pix = height - pix - 1; GMatrix[pix][j]=200; pix = (int)((double)(height-1)*( (double)(Bhistogram.datos[j]) / (max) )); pix = height - pix - 1; BMatrix[pix][j]=240; pix = (int)((double)(height-1)*( (double)(Vhistogram.datos[j]) / (max) )); pix = height - pix - 1; VMatrix[pix][j]=240; } for(int i=0;i<height; i++) { uchar* ptr = (uchar*) ( img->imageData + i * img->widthStep ); for(int j=0; j<width; j++) { //index = i*3*width +3*j; index = 3*j; ptr[index+0] = 250; ptr[index+1] = 250; ptr[index+2] = 250; if(RMatrix[i][j] > 0 || GMatrix[i][j] > 0 || BMatrix[i][j] > 0) { ptr[index+2] = 0; ptr[index+1] = 0; ptr[index+0] = 0; } if(RMatrix[i][j] > 0) ptr[index+2] = RMatrix[i][j]; if(GMatrix[i][j] > 0){ //ptr[index+2] = GMatrix[i][j]; ptr[index+1] = GMatrix[i][j]; //ptr[index+0] = GMatrix[i][j]; } if(BMatrix[i][j] > 0) ptr[index+0] = BMatrix[i][j]; if(VMatrix[i][j] > 0){ ptr[index+2] = 0; ptr[index+1] = 0; ptr[index+0] = 0; } } } return img; }
void SVSet::add2(SVector &svec, int idx, Real val) { xtend(svec, svec.size() + 1); svec.add(idx, val); }
void SVSet::deleteVec(DLPSV* ps) { /* delete last entries, in an SVECTOR and also in an DLPSV there is always the position -1 used for memorizing * the size; this is the reason why we need to delete max()+1 entries */ if (list.last() == ps) removeLast(ps->max() + 1); /* merge space of predecessor with position which will be deleted, therefore we do not need to delete any * memory or do an expensive memmove * * @note an SVECTOR and also in an DLPSV memorize the size always on position -1; this is the reason why we * need to set the new mem size to the old combined size + 2 */ else if (list.first() != ps) { SVector* prev = ps->prev(); int sz = prev->size(); prev->setMem(prev->max() + ps->max() + 2, prev->mem()); prev->set_size(sz); } /* delete the front entries of the first list entry and correct the memory pointers in the vectors */ /* @note we do this by merging the first both vectors, move the entries from the second vector up front, and * correct the size */ else { SVector* next = ps->next(); int sz = next->size(); int bothmax = next->max() + ps->max(); int offset = 0; /* the first element does not need to start at the beginning of the data array; why ??? */ while( &(this->SVSetBase::operator[](offset)) != ps->mem() ) { ++offset; assert(offset < size()); } /* move all entries of the second vector to the front */ for(int j = 0; j <= sz; ++j) { this->SVSetBase::operator[](offset + j) = next->mem()[j]; } /* correct the data memmory pointer and the maximal space */ next->setMem(bothmax + 2, ps->mem()); /* correct size */ next->set_size(sz); } list.remove(ps); }