📄 tvbranch.c
字号:
/* COPYRIGHT NOTICE This material was developed by Christos Faloutsos and King-Ip Linat the University of Maryland, College Park, Department of Computer Science.Permission is granted to copy this software, to redistribute iton a nonprofit basis, and to use it for any purpose, subject tothe following restrictions and understandings. 1. Any copy made of this software must include this copyright noticein full. 2. All materials developed as a consequence of the use of thissoftware shall duly acknowledge such use, in accordance with the usualstandards of acknowledging credit in academic research. 3. The authors have made no warranty or representation that theoperation of this software will be error-free or suitable for anyapplication, and they are under under no obligation to provide anyservices, by way of maintenance, update, or otherwise. The softwareis an experimental prototype offered on an as-is basis. 4. Redistribution for profit requires the express, written permissionof the authors. */// Author : $Author$// Date : $Date$// Id : $Id$// $Id: branch.C,v 1.2 1996/04/18 21:50:24 kilin Exp kilin $// Please change sig_dim to active_dim#include <iostream.h>#include <assert.h>#include <stdlib.h>#include <fstream.h>#include "TVdefine.h"#include "TVconstants.h"#include "TVvector.h"#include "TVrectangle.h"#include "TVelement.h"#include "TVsimbuf.h"#include "TVnode.h"#include "TVutil.h"// For branchesTVBranch::TVBranch(){ child.setnull();}TVBranch::TVBranch(const TVRectangle &d, TVNode* l) : bound(d), child(l){}TVBranch:: TVBranch(const TVBranch& b){ bound = b.bound; child = b.child;}TVBranch::~TVBranch(){}TVBranch& TVBranch::operator=(const TVBranch& b){ bound = b.bound; child = b.child; return *this;}TVBranch& TVBranch::operator=(const TVRectangle& d){ bound = d; return *this;}int TVBranch::Size() const{ return bound.Size() + child.bytes();}void TVBranch::ConnectChild(const TVNodehandle& n){ child = n;}void TVBranch::DisconnectChild(){ child.setnull();}TVRectangle TVBranch::GetBound() const{ return bound;}TVector TVBranch::GetCenter() const{ return bound.GetCenter();}float TVBranch::GetRadius() const{ return bound.GetRadius();}TVNode* TVBranch::FetchChild(){ /* Increment stat for fetching */// if (fetchfrom == FROM_DISK); return child.fetch();}TVNodehandle TVBranch::GetHandle() const{ return child;}TVBranch& TVBranch::UpdateBound(const TVector& v, int sig_dim){ bound = bound.InsertTVector(v, sig_dim) ; return *this;}TVBranch& TVBranch::UpdateBound(const TVRectangle& d, int sig_dim){ bound = bound.Combine(d, sig_dim) ; return *this;}TVBranch& TVBranch::SetBound(const TVRectangle& d){ bound = d; return *this;}void TVBranch::WriteChild(){ child.write();}ostream& operator<< (ostream& os, const TVBranch& b){ os << "Bounding rectangle : " << b.bound; return os;}ostream& operator<< (ostream& os, const TVBranch*& b){ os << "Bounding rectangle : " << b->bound; return os;}// TVNodeEntry, to handle fetchingTVNodeEntry::TVNodeEntry(){ ftype = not_defined;}TVNodeEntry::TVNodeEntry(TVBranch& b){ u.b = &b; ftype = is_branch;// cout << "TVNodeEntry TVBranch " << u.b;}TVNodeEntry::TVNodeEntry(Leaf_Element& e){ u.e = &e; ftype = is_leafele;}TVNodeEntry::TVNodeEntry(const TVNodeEntry& f){ ftype = f.ftype; if (f.ftype == is_branch) u.b = f.u.b; else if (f.ftype == is_leafele) u.e = f.u.e;}TVNodeEntry& TVNodeEntry::operator=(const TVNodeEntry& f){ ftype = f.ftype; if (f.ftype == is_branch) u.b = f.u.b; else if (f.ftype == is_leafele) u.e = f.u.e; return *this;}TVNodeEntry& TVNodeEntry::Put(TVBranch& b){ u.b = &b; ftype = is_branch; return *this;}TVNodeEntry& TVNodeEntry::Put(Leaf_Element& e){ u.e = &e; ftype = is_leafele; return *this;}int TVNodeEntry::Defined(){ return ftype != not_defined;}FRType TVNodeEntry::Type() const{ return ftype;}// If branch, return the bounding rectangle;// If element, return a 0 radius rectangle with the // already extracted feature vector as centerTVRectangle TVNodeEntry::GetTVRectangle(){ if (ftype != is_branch) { if (ftype == is_leafele) { TVRectangle result(u.e->GetTVector(), 0.0, u.e->GetTVector().GetDim()); return result; } else assert(0); } return u.b->GetBound();}// If branch, return the center vector// If element, return the vector with the given dimension// (extracting new features if necessary)TVector TVNodeEntry::GetTVector(int dim, VCOM_TYPE (*gfeat)(int, char*)){ if (ftype != is_branch) { if (ftype == is_leafele) return u.e->GetTVector(dim, gfeat); else assert(0); } return u.b->GetBound().GetCenter();}int TVNodeEntry::Size(){ if (ftype == is_branch) return u.b->Size(); else if (ftype == is_leafele) return u.e->Size(); else assert(0); return 0;}ostream& operator<< (ostream& os, TVNodeEntry& ne){ if (ne.ftype == is_branch) os << "Type is branch : " << ne.u.b; else if (ne.ftype == is_leafele) os << "Type is element : " << ne.u.e; else assert(0); return os;}ostream& operator<< (ostream& os, TVNodeEntry*& ne){ if (ne->ftype == is_branch) os << "Type is branch : " << ne->u.b; else if (ne->ftype == is_leafele) os << "Type is element : " << ne->u.e; else assert(0); return os;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -