//! file="amma/Surf3d/VoxSet/VoxSet.hh" //! lib=vox //! userlevel=Default //! author="Adrian Hilton" //! rcsid="$Id: VoxSet.hh,v 1.7 1999/03/29 11:17:38 ees1cg Exp $" //! date="04/02/97" //! docentry="default.Adrian Hilton" // ------------------------------------------------------- // // Name : VoxSet.hh // Library : // Description: Template Container Class for vodel data // Dependancies: // Modified : // Created : 8.96 // Author : Adrian Hilton // // // ------------------------------------------------------- #ifndef VOXSET_HH #define VOXSET_HH #include "amma/Vox.hh" #include "amma/BVoxSet.hh" // use buffer allocation //#define VOX_BUFFER //#define BUFFERSIZE 100 template class HVoxSetArrayC; // forward declaration //==================================================================== // Functions for VoxSetC dependent on DataC but not on storage scheme // DataC = VoxC or VoxNormalC or VoxPointNormalC template class VoxSetC: public BaseVoxSetC{ public: //--------------------------------- Constructors VoxSetC(); // empty VoxSetC(const Vector3dC xmin,const Vector3dC xmax, const RealT resolution,const RealT distance); // setup an empty volumetric frame // dimensions [xmin,xmax] // voxel 'resolution' // encode surface thickness +/- distance VoxSetC(const VoxSetC& vox); // copy //const VoxSetC void operator=(const VoxSetC& vox); // assignment //--------------------------------------------------- Operations BooleanT IsValid(const DataC v); // test if voxel is valid protected: // DataC invalid_voxel; // invalid voxel (index >2n^3+2n^2+2n) //--------------------------------------------------- Encoding virtual void EncodePoint(const TriC& tri, const Vector3dC v, const Vector3dC view_normal) =0; virtual void EncodePoint(const TriC& tri, const Vector3dC v, const Vector3dC view_normal, TriNearestPointC& np) =0; }; //============================================================ // Voxel Set stored as run-length encode array template class VoxSetArrayC: public BaseVoxSetC { //public VoxSetC { friend HVoxSetArrayC; public: //--------------------------------- Constructors VoxSetArrayC(); // empty VoxSetArrayC(const Vector3dC xmin,const Vector3dC xmax, const RealT resolution,const RealT distance); // setup an empty volumetric frame // dimensions [xmin,xmax] // voxel 'resolution' // encode surface thickness +/- distance VoxSetArrayC(const TriSetC triset); // voxel encode 'triset' // dimensions = limits of triset // resolution = average edge lenght of triset // surface thickness = 2*resolution // encode scheme = 2: vertex normal // fusion scheme = 0: nearest only // (weight scheme = 1: weighted ave) - not used for fusion VoxSetArrayC(const VoxSetArrayC& vox); // copy const VoxSetArrayC operator=(const VoxSetArrayC& vox); // assignment //--------------------------------- Operations DataC NearestPoint(const Vector3dC& v); // return voxel corresponding to nearest point on surface to 'v' DataC NearestPointRecursive(const Vector3dC& v); // recursive nearest point search // UNTESTED RealT SignedDistance(const Vector3dC v,BooleanT& valid); // return distance + validity // (valid if non-boundary voxel found) RealT SignedDistance(const Vector3dC v); // distance to surface in range [-dmax,dmax] // test if valid BooleanT IsValidSignedDistance(const RealT d); // inside range [-dmax,dmax] //---------------------------------- Public Operations DataC Get(const Index3dC i); // reference to voxel with index i // or invalid voxel if voxel does not exist DataC Get(const Vector3dC v); // reference to voxel with index of v // or invalid voxel if voxel does not exist IntT MemoryUsed(); // no. of bytes of mem used to store volumetric rep. IntT MemoryAllocated(); // no. of bytes of mem. used with buffer redundancy. private: //---------------------------------- Private Operations DataC GetRecursive(const Vector3dC v); // Recursive search for voxel with zero-set nearest to v DataC GetArrayRecursive(const Vector3dC v); // Resursive search based on 2d internal bucket encoding of 3D space void Put(const DataC vox); // put voxel data into structure //void Remove(const DataC vox); // not inculded for template instantiation // remove voxel data from structure private: //----------------------------------- Internal Data BucketArray3to2dC bucket; //---------------------------------- Encoding TriSetC in VoxSetArrayC void EncodeSetup(Vector3dC xmin, Vector3dC xmax, RealT resolution); // initialise internal volumetric representation void EncodePoint(const TriC& tri, const Vector3dC v, const Vector3dC view_normal); void EncodePoint(const TriC& tri, const Vector3dC v, const Vector3dC view_normal, TriNearestPointC& np); //------------------------------------------------- Access/Encode in RLE SArray1dC& GetString(const Index3dC& i); // Get the RLE char array corresponting to (i[0],i[1]) in bucket plane DataC StringGet(const Index3dC i); // Get voxel data DataC StringGet(const Vector3dC v); // Get voxel data DataC StringGet(SArray1dC& s,const IntT istart,const Index3dC i); // Get voxel data stored at s[istart] with index 'i' DataC StringGetNearest(SArray1dC& s, const Index3dC& i, const Vector3dC& v); // Get nearest voxel to 'v' in s // where (i[0],i[1]) is the index for s and i[2]=Index(v)[2] DataC StringGetNearestGuaranteed(SArray1dC& s, const Index3dC& i, const Vector3dC& v); // Nearest to all data in string DataC StringGetNearestApprox(SArray1dC& s, const Index3dC& i, const Vector3dC& v); // Nearest to data in string with same k value // or prev/next to k value void StringPut(const DataC vox); // Put voxel data IntT StringPut(SArray1dC& s,const IntT istart,const DataC vox); // Put voxel data IntT StringPut(SArray1dC& s,const IntT istart,const IntT nempty); // put empty space void StringSplit(SArray1dC& s,const IntT index,const IntT kprev, const IntT k,const DataC vox); void StringInit(SArray1dC& s,const DataC vox); IntT StringFind(SArray1dC& str,const IntT k); IntT StringFind(SArray1dC& str,const IntT k,IntT& kcount); // find array index for k^th item // kcount is the total k prior to this item // return -1 if item not found IntT StringFindPrevNext(SArray1dC& str,const IntT k, IntT& iprev,IntT& kprev, IntT& inext,IntT& knext); IntT StringFindPrevNext(SArray1dC& str, const IntT k, IntT& kcount, IntT& iprev,IntT& kprev, IntT& inext,IntT& knext); // find array index for k^th item // + iprev and inext array index for prev& next data items // which are kprev^th and knext^th items // return -1 for k^th item & iprev,inext if not found void StringCopy(SArray1dC& s, const IntT istart, const IntT iend, SArray1dC& snew, const IntT inew); void StringMerge(SArray1dC& s0,SArray1dC& s1); // merge s1 from external VoxSet into s0 from this VoxSet void StringCheck(SArray1dC& s); void StringPrint(SArray1dC& s); //------------------------------------------------- // functions for efficient string allocation SArray1dC StringNew(SArray1dC sold, const IntT size); IntT StringDataSize(SArray1dC s); void StringSetSize(SArray1dC s,const IntT size); IntT StringMaxDataSize(SArray1dC s); // void StringShift(SArray1dC s,IntT index,IntT shift); // removed for template instantiation // shift contents of string // shift >=0 //const IntT buffer_size(200); // length of string buffer blocks SArray1dC buffer; // handle to unused buffer string SArray1dC return_buffer; // handle to unused buffer string //------------------------------------------------- //friend ostream & operator<<(ostream & s, const VoxSetC & t); //friend ostream & operator<<(ostream & s,VoxSetC & t); }; //===================================================================== #include "amma/VoxSet.tcc" //============================================================ #endif