| 1 | /**************************************************************************** |
| 2 | * VCGLib o o * |
| 3 | * Visual and Computer Graphics Library o o * |
| 4 | * _ O _ * |
| 5 | * Copyright(C) 2004 \/)\/ * |
| 6 | * Visual Computing Lab /\/| * |
| 7 | * ISTI - Italian National Research Council | * |
| 8 | * \ * |
| 9 | * All rights reserved. * |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | * This program is distributed in the hope that it will be useful, * |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 19 | * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * |
| 20 | * for more details. * |
| 21 | * * |
| 22 | ****************************************************************************/ |
| 23 | /**************************************************************************** |
| 24 | History |
| 25 | |
| 26 | $Log: bmt.h,v $ |
| 27 | Revision 1.1 2004/04/07 12:46:30 ponchio |
| 28 | Backup (working on it). |
| 29 | |
| 30 | |
| 31 | ****************************************************************************/ |
| 32 | |
| 33 | #ifndef VCG_BMT_H |
| 34 | #define VCG_BMT_H |
| 35 | |
| 36 | #include <string> |
| 37 | #include <vector> |
| 38 | |
| 39 | #include <vcg/space/sphere3.h> |
| 40 | #include <wrap/mt/mt.h> |
| 41 | |
| 42 | namespace vcg { |
| 43 | |
| 44 | /** \addtogroup bmt */ |
| 45 | /*@{*/ |
| 46 | /** |
| 47 | The class for representing a batched mt structure. |
| 48 | See bmt.cpp for details on the structure of the file. |
| 49 | */ |
| 50 | |
| 51 | class Bmt { |
| 52 | public: |
| 53 | ///Cell structure for the mt representation |
| 54 | class Cell { |
| 55 | public: |
| 56 | //this effectively limits databases to 4Gb in size. |
| 57 | unsigned int offset; |
| 58 | float error; |
| 59 | Sphere3f sphere; |
| 60 | float Error() { return error; } |
| 61 | }; |
| 62 | |
| 63 | ///tells what is inside each cell. |
| 64 | unsigned int signature; |
| 65 | ///Bounding sphere |
| 66 | Sphere3f sphere; |
| 67 | |
| 68 | std::vector<Cell> index; |
| 69 | std::vector< MT<Bmt::Cell>::Update > history; |
| 70 | |
| 71 | |
| 72 | |
| 73 | Bmt(); |
| 74 | ~Bmt(); |
| 75 | bool Load(const std::string &filename); |
| 76 | char *GetData(unsigned int &size, unsigned int offset); |
| 77 | |
| 78 | private: |
| 79 | FILE *fp; |
| 80 | unsigned int index_offset; |
| 81 | unsigned int index_size; |
| 82 | unsigned int history_offset; |
| 83 | unsigned int history_size; |
| 84 | }; |
| 85 | |
| 86 | class BmtBuilder { |
| 87 | public: |
| 88 | BmtBuilder(); |
| 89 | ~BmtBuilder(); |
| 90 | |
| 91 | ///tells what is inside each cell. |
| 92 | unsigned int signature; |
| 93 | ///Bounding sphere |
| 94 | Sphere3f sphere; |
| 95 | std::vector<Bmt::Cell> index; |
| 96 | std::vector<std::vector<unsigned int > > creation; |
| 97 | std::vector<std::vector<unsigned int > > deletion; |
| 98 | |
| 99 | bool Create(unsigned int signature); |
| 100 | |
| 101 | unsigned int AddCell(Bmt::Cell cell, unsigned int size, char *data); |
| 102 | void AddUpdate(std::vector<unsigned int> &created, std::vector<unsigned int> &erased); |
| 103 | |
| 104 | bool Save(const std::string &filename); |
| 105 | private: |
| 106 | FILE *ftmp; |
| 107 | FILE *fout; |
| 108 | }; |
| 109 | |
| 110 | float Distance(Bmt::Cell &cell, Point3f &p); |
| 111 | |
| 112 | }//end namespace |
| 113 | |
| 114 | #endif |