1 #ifndef __BLOCKMODEL_H__
2 #define __BLOCKMODEL_H__
14 #include "svnversion.h"
17 #include "../../utils/ccols.h"
33 typedef unsigned long BlockIndexType;
35 typedef unsigned int BlockIndexType;
77 BlockModel(
const delphos::BlockIndexType & num_blocks);
80 BlockModel(
const unsigned int & num_blocks,
const bool& is_regular,
const bool& without_coordinates);
117 BlockModel(
const char* file_name,
const double& ang);
146 const delphos::BlockIndexType & index,
147 const string & column)
const;
163 const delphos::BlockIndexType & index,
164 const unsigned int & columnpos)
const;
175 const delphos::BlockIndexType & index,
176 const string & column,
177 const double & value);
188 const delphos::BlockIndexType & index,
189 const unsigned int & columnpos,
190 const double & value);
204 void AddColumn(
const string & column,
const double & default_value);
220 void AddColumn(
const string & column, delphos::BlockFunctionPtr fp);
238 void AddColumn(
const string & column,
const string & formula);
249 bool RemoveColumn(
const string &column);
258 virtual const delphos::BlockIndexType Size()
const;
264 virtual const delphos::BlockIndexType GetSize()
const;
273 const unsigned int NumColumns()
const;
279 const unsigned int GetNumColumns()
const;
292 string ColumnName(
const unsigned int & column_index)
const;
303 string GetColumnName(
const unsigned int & column_index)
const;
314 vector<string> GetColumnNames()
const;
328 const delphos::BlockIndexType ColumnPos(
const string & column)
const;
339 const delphos::BlockIndexType GetColumnPos(
const string & column)
const;
349 virtual void SetCoordinates(
const delphos::BlockIndexType & index,
const delphos::Coordinates & c);
419 virtual delphos::BlockIndexType BlockIndex(
const double & x,
const double & y,
const double & z)
const;
431 virtual delphos::BlockIndexType GetBlockIndex(
const double & x,
const double & y,
const double & z)
const;
434 virtual delphos::BlockIndexType UnsafeBlockIndex(
const double & x,
const double & y,
const double & z)
const;
450 virtual delphos::BlockIndexType BlockIndex(
const delphos::BlockIndexType& idx,
const delphos::BlockIndexType& idy,
const delphos::BlockIndexType& idz)
const;
464 virtual delphos::BlockIndexType GetBlockIndex(
const delphos::BlockIndexType& idx,
const delphos::BlockIndexType& idy,
const delphos::BlockIndexType& idz)
const;
480 virtual delphos::BlockIndexType UnsafeBlockIndex(
const BlockIndexType& idx,
const BlockIndexType& idy,
const BlockIndexType& idz)
const;
495 double X(
const delphos::BlockIndexType index)
const;
509 double Y(
const delphos::BlockIndexType index)
const;
523 double Z(
const delphos::BlockIndexType index)
const;
534 double GetX(
const delphos::BlockIndexType index)
const;
545 double GetY(
const delphos::BlockIndexType index)
const;
556 double GetZ(
const delphos::BlockIndexType index)
const;
578 bool SaveToTextFile(
const char * bm_file_name,
const unsigned int& precision = 4);
597 bool SaveToTextFile(
const char * bm_file_name,
const vector<string> & columns,
const unsigned int& precision=4,
const string& delim=
"");
618 bool SaveToVtkFile(
const char * vtk_file_name,
const vector<string> & columns,
const unsigned int& precision=4);
643 bool SaveToVtkFile(
const char * vtk_file_name,
const string& filtercolumn,
const float& li,
const float& ls,
const string& column,
const unsigned int& precision=4);
671 vector<double>* SaveToVtkScalarsArray(
const string& filtercolumn,
const float& li,
const float& ls,
const string& column,
int& DIMX,
int& DIMY,
int& DIMZ,
int& THRESOLD,
int& BMXINF,
int& BMYINF,
int& BMZINF,
int& BMXSUP,
int& BMYSUP,
int& BMZSUP,
const unsigned int& precision=4);
693 virtual bool SaveToVtkFileUGridView(
const char * vtk_file_name,
const string& filtercolumn,
const float& li,
const float& ls,
const vector<string> & columns,
const unsigned int& precision=4);
716 bool SaveToModFile(
const char * mod_file_name,
const string tonCol,
const unsigned int& precision=4);
739 bool SaveToModFile(
const char * mod_file_name,
const string tonCol,
740 const string mcafCol,
const string pcafCol,
const unsigned int& precision=4);
751 virtual delphos::Block GetBlock(
const delphos::BlockIndexType & index);
776 virtual delphos::Block GetBlock(
const double & x,
const double & y,
const double & z);
791 virtual delphos::Block GetBlock(
const delphos::BlockIndexType& index_x,
const delphos::BlockIndexType& index_y,
const delphos::BlockIndexType& index_z);
820 delphos::BlockModel* SubBlockModel(
const string& filtercolumn,
const float& li=0.9,
const float& ls=1.1);
837 delphos::BlockModel* SubBlockModel(
const string& column,
const string& filtercolumn,
const float& li=0.9,
const float& ls=1.1);
869 bool IsRegular()
const ;
881 bool Contains(
const delphos::BlockIndexType& idx,
const delphos::BlockIndexType& idy,
const delphos::BlockIndexType& idz)
const;
901 bool ContainsXYZ(
const double & x,
const double & y,
const double & z)
const;
920 const Coordinates& GetReferenceBlockCoordinates()
const;
929 const double& GetDZ()
const;
938 const double& GetDY()
const;
947 const double& GetDX()
const;
957 const BlockIndexType& GetZCount()
const;
966 const BlockIndexType& GetYCount()
const;
975 const BlockIndexType& GetXCount()
const;
991 const BlockIndexType& GetXMinIndex(
const unsigned int& level)
const;
1007 const BlockIndexType& GetXMaxIndex(
const unsigned int& level)
const;
1023 const BlockIndexType& GetYMinIndex(
const unsigned int& level)
const;
1039 const BlockIndexType& GetYMaxIndex(
const unsigned int& level)
const;
1070 bool UnRegularize();
1108 double GetMinZ(
const delphos::BlockIndexType& idx,
const delphos::BlockIndexType& idy,
const delphos::BlockFilter& bf,
const double& z,
const delphos::BlockIndexType& idz=2);
1111 double GetMinZ(
const delphos::BlockIndexType& idx,
const delphos::BlockIndexType& idy,
const delphos::BlockFilter& bf);
1150 double GetMaxAttr(
const string& column);
1161 double GetMinAttr(
const string& column);
1172 double GetAvgAttr(
const string& column);
1183 double GetMaxAttr(
const unsigned int& column_index);
1194 double GetMinAttr(
const unsigned int& column_index);
1205 double GetAvgAttr(
const unsigned int& column_index);
1217 bool IsComputed(
const string & column);
1229 bool IsComputed(
const unsigned int & index);
1246 bool SaveMetaData(
const string & filename,
const string & bm_filename);
1261 bool LoadMetaData(
const string & filename);
1264 string GetMD5(
const string & file);
1269 typedef struct data{
1276 typedef struct poly{
1281 BlockIndexType bindex;
1286 vector<string>* _columns;
1287 vector<double*>* _values;
1288 Coordinates* _coords;
1289 map<string,BlockIndexType> * _coord_map;
1292 BlockIndexType*** _indexes;
1293 BlockIndexType* _height_min_indexes;
1294 BlockIndexType* _height_max_indexes;
1295 BlockIndexType* _width_min_indexes;
1296 BlockIndexType* _width_max_indexes;
1297 Coordinates _coord_b0;
1301 BlockIndexType _height_index;
1302 BlockIndexType _width_index;
1303 BlockIndexType _depth_index;
1304 BlockIndexType* _index_to_coord;
1306 vector <double> _max_values;
1307 vector <double> _min_values;
1308 vector <double> _avg_values;
1318 vector <bool> _flag_stat_attr;
1319 bool _flag_stat_coord;
1320 void ComputeCoordStats();
1321 void ComputeAttrStats(
const unsigned int& column_index);
1324 map<string,Ccol> _ccols;
1325 vector< vector<string> > _cols_dep;
1330 void DeleteCoords();
1338 bool IsFull()
const;
1341 BlockModel(
const unsigned long & num_blocks,
const bool is_regular);
1343 BlockModel(
const unsigned int & num_blocks,
const bool is_regular);
1346 friend class BlockSelection;
1427 double GetX()
const;
1432 double GetY()
const;
1437 double GetZ()
const;
1449 double GetValue(
const string & column)
const;
1459 void SetValue(
const string & column,
const double & value);
1477 double operator [] (
const string & column)
const;
1487 delphos::BlockIndexType Index()
const;
1494 delphos::BlockIndexType GetIndex()
const;
1499 const BlockIndexType _index;
1525 std::stringstream ss;
1526 std::stringstream sf;
1529 time_t now = time(0);
1532 tstruct = *localtime(&now);
1533 strftime(buf,
sizeof(buf),
"%Y-%m-%d.%X", &tstruct);
1535 char const *folder = getenv(
"TMPDIR");
1536 if (folder == 0) folder = getenv(
"TMP");
1537 if (folder == 0) folder = getenv(
"TEMP");
1538 if (folder == 0) folder = getenv(
"TEMPDIR");
1539 if (folder == 0) folder =
"/tmp";
1545 sf <<folder<<sep<<
"MineLink.log";
1548 myfile.open (sf.str().c_str(), ios::out);
1549 myfile << buf <<
" : "<<what <<
" -> in file: " << file <<
" in function: " <<
function <<
" at line: " << line <<endl;
1558 virtual const char * what()
const throw()
1560 return _msg.c_str();
1570 static string GetVersion(){
1571 std::stringstream ss;
1594 static string GetRevision(){
1595 std::stringstream ss;
MineLinkException(const std::string &what, string file, string function, int line)
Throws a MineLink exception.
Definition: blockmodel.h:1523
Abstracts a set of blocks (subset of a blockmodel).
Definition: blocksel.h:33
An utility class to abstract coordinates so they can be used as map and set keys by means of string c...
Definition: coords.h:20
A utility class to access blocks individually.
Definition: blockmodel.h:1390
virtual ~MineLinkException()
The destructor.
Definition: blockmodel.h:1555
MineLinkException(const std::string &what)
Throws a MineLink exception.
Definition: blockmodel.h:1515
Abstracts a container of blocks as a table with arbitrary number of attributes that can be accessed b...
Definition: blockmodel.h:62
Abstracts Exceptions for MineLink library. In Windows, Log File MineLink.log is gererally for a user_...
Definition: blockmodel.h:1509
static const vector< string > EMPTY_STRING_VECT
Empty string vector.
Definition: blockmodel.h:128
A base class for object associated to a given block model.
Definition: blockmodel.h:1356
Abstracts functions to do block selection.
Definition: filters.h:15
static const delphos::BlockIndexType NO_INDEX
Index of nonexistent Block.
Definition: blockmodel.h:123