00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_STATCPTLEVELSET_H
00010 #define AMROC_STATCPTLEVELSET_H
00011
00019 #include "CPTLevelSet.h"
00020
00027 template <class DataType, int dim>
00028 class StatCPTLevelSet : public CPTLevelSet<DataType,dim> {
00029 typedef CPTLevelSet<DataType,dim> base;
00030
00031 public:
00032 typedef typename base::grid_fct_type grid_fct_type;
00033 typedef typename base::grid_data_type grid_data_type;
00034 typedef typename cpt::State<dim,DataType> cpt_type;
00035 typedef ads::FixedArray<dim,DataType> point_type;
00036 typedef ads::FixedArray<dim,int> multi_index_type;
00037
00038 StatCPTLevelSet() : base(), brep_filetype(0), vertices(0), connections(0) {
00039 base::_Stationary = 1;
00040 }
00041
00042 virtual ~StatCPTLevelSet() {
00043 if (vertices!=0) delete[] vertices;
00044 if (connections!=0) delete[] connections;
00045 }
00046
00047 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00048 base::LocCtrl = Ctrl.getSubDevice(prefix+"StatCPT");
00049 RegisterAt(base::LocCtrl,"Brep",brep_filename);
00050 RegisterAt(base::LocCtrl,"FileType",brep_filetype);
00051 RegisterAt(base::LocCtrl,"PlotPhi",base::_PlotPhi);
00052 RegisterAt(base::LocCtrl,"Inverse",base::inverse);
00053 RegisterAt(base::LocCtrl,"Unsigned",base::unsign);
00054 RegisterAt(base::LocCtrl,"FillWidth",base::_FillWidth);
00055 }
00056 virtual void register_at(ControlDevice& Ctrl) {
00057 register_at(Ctrl, "");
00058 }
00059
00060 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00061 base::SetupData(gh, ghosts);
00062
00063 std::ifstream brep_file( brep_filename.c_str() );
00064 if ( ! brep_file ) {
00065 std::cerr << "Could not read the b-rep file. Exiting...\n";
00066 std::exit( 1 );
00067 }
00068
00069 int num_vertices, num_connections;
00070
00071
00072 if (brep_filetype==1) {
00073 int fdim, mdim;
00074 brep_file >> fdim >> mdim;
00075 if ( fdim!=dim || mdim!=dim-1 ) {
00076 std::cerr << "Mesh in b-rep file has wrong dimension. Exiting...\n";
00077 std::exit( 1 );
00078 }
00079 brep_file >> num_vertices;
00080 vertices = new point_type[ num_vertices ];
00081 const point_type* point_iter_end = vertices + num_vertices;
00082 for ( point_type* piter = vertices; piter != point_iter_end; ++piter )
00083 brep_file >> *piter;
00084 brep_file >> num_connections;
00085 connections = new multi_index_type[ num_connections ];
00086 }
00087 else {
00088 brep_file >> num_vertices >> num_connections;
00089 vertices = new point_type[ num_vertices ];
00090 connections = new multi_index_type[ num_connections ];
00091 const point_type* point_iter_end = vertices + num_vertices;
00092 for ( point_type* piter = vertices; piter != point_iter_end; ++piter )
00093 brep_file >> *piter;
00094 }
00095
00096 const multi_index_type* connections_iter_end = connections + num_connections;
00097 for ( multi_index_type* eiter = connections; eiter != connections_iter_end; ++eiter )
00098 brep_file >> *eiter;
00099
00100 assert( brep_file.good() );
00101 brep_file.close();
00102
00103 base::SetBrep(num_vertices, reinterpret_cast<const DataType*>(vertices),
00104 num_connections, reinterpret_cast<const int*>(connections));
00105
00106 }
00107
00108 inline void SetFilename(const std::string filename) { brep_filename = filename; }
00109 inline std::string Filename() { return brep_filename; }
00110
00111 protected:
00112 std::string brep_filename;
00113 int brep_filetype;
00114 point_type* vertices;
00115 multi_index_type* connections;
00116 };
00117
00118
00119 #endif