Stimfit 0.12.7
src/stimfit/stf.h
00001 // This program is free software; you can redistribute it and/or
00002 // modify it under the terms of the GNU General Public License
00003 // as published by the Free Software Foundation; either version 2
00004 // of the License, or (at your option) any later version.
00005 
00006 // This program is distributed in the hope that it will be useful,
00007 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00008 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009 // GNU General Public License for more details.
00010 
00011 // You should have received a copy of the GNU General Public License
00012 // along with this program; if not, write to the Free Software
00013 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00014 
00024 #ifndef _STF_H_
00025 #define _STF_H_
00026 
00027 #include <boost/function.hpp>
00028 #include <vector>
00029 #include <map>
00030 #include <string>
00031 
00032 #include "./gui/zoom.h"
00033 
00034 #ifdef _MSC_VER
00035 #pragma warning( disable : 4251 )  // Disable warning messages
00036 #pragma warning( disable : 4996 )  // Disable warning messages
00037 #endif
00038 
00040 #if defined(_WINDOWS) && !defined(__MINGW32__)
00041     #ifdef STFDLL
00042         #define StfDll __declspec( dllexport )
00043     #else
00044         #define StfDll __declspec( dllimport )
00045     #endif
00046 #else
00047     #define StfDll
00048 #endif
00049 
00050 #ifndef MODULE_ONLY
00051     #include <wx/wxprec.h>
00052     #ifdef __BORLANDC__
00053         #pragma hdrstop
00054     #endif
00055 
00056     #ifndef WX_PRECOMP
00057         #include <wx/wx.h>
00058     #endif
00059 
00060     #include <wx/wfstream.h>
00061     #include <wx/progdlg.h>
00062 #else
00063     typedef std::string wxString;
00064     typedef int wxWindow;
00065     #define wxT(x)  x
00066     #define wxCHECK_VERSION(major,minor,release) 0
00067 #endif
00068 
00069 #include "../libstfio/stfio.h"
00070 
00072 
00075 namespace stf {
00076 
00081 
00082 class wxProgressInfo : public stfio::ProgressInfo {
00083 public:
00084     wxProgressInfo(const std::string& title, const std::string& message, int maximum, bool verbose=true);
00085     bool Update(int value, const std::string& newmsg="", bool* skip=NULL);
00086 private:
00087     wxProgressDialog pd;
00088 };
00089 
00090 std::string wx2std(const wxString& wxs);
00091 wxString std2wx(const std::string& sst);
00092 
00094 typedef boost::function<Recording(const Recording&,const Vector_double&,std::map<std::string, double>&)> PluginFunc;
00095 
00097 
00099 class StfDll Table {
00100 public:
00102 
00105     Table(std::size_t nRows,std::size_t nCols);
00106 
00108 
00110     Table(const std::map< std::string, double >& map);
00111 
00113 
00117     double at(std::size_t row,std::size_t col) const;
00118 
00120 
00124     double& at(std::size_t row,std::size_t col);
00125     
00127 
00131     bool IsEmpty(std::size_t row,std::size_t col) const;
00132 
00134 
00138     void SetEmpty(std::size_t row,std::size_t col,bool value=true);
00139 
00141 
00144     void SetRowLabel(std::size_t row,const std::string& label);
00145 
00147 
00150     void SetColLabel(std::size_t col,const std::string& label);
00151 
00153 
00156     const std::string& GetRowLabel(std::size_t row) const;
00157 
00159 
00162     const std::string& GetColLabel(std::size_t col) const;
00163 
00165 
00167     std::size_t nRows() const { return rowLabels.size(); }
00168 
00170 
00172     std::size_t nCols() const { return colLabels.size(); }
00173     
00175 
00177     void AppendRows(std::size_t nRows);
00178 
00179 private:
00180     // row major order:
00181     std::vector< std::vector<double> > values;
00182     std::vector< std::deque< bool > > empty;
00183     std::vector< std::string > rowLabels;
00184     std::vector< std::string > colLabels;
00185 };
00186  
00188 struct UserInput {
00189     std::vector<std::string> labels; 
00190     Vector_double defaults; 
00191     std::string title;               
00193 
00194 
00198     UserInput(
00199             const std::vector<std::string>& labels_=std::vector<std::string>(0),
00200             const Vector_double& defaults_=Vector_double(0),
00201             std::string title_="\0"
00202     ) : labels(labels_),defaults(defaults_),title(title_)
00203     {
00204                 if (defaults.size()!=labels.size()) {
00205                     defaults.resize(labels.size());
00206                     std::fill(defaults.begin(), defaults.end(), 0.0);
00207                 }
00208     }
00209 };
00210 
00212 
00216 struct Plugin {
00218 
00222     Plugin(
00223             const wxString& menuEntry_,
00224             const PluginFunc& pluginFunc_,
00225             const UserInput& input_=UserInput()
00226     ) : menuEntry(menuEntry_),pluginFunc(pluginFunc_),input(input_)
00227     {
00228         id = n_plugins;
00229         n_plugins++;
00230     }
00231     
00233     ~Plugin() { }
00234 
00235     int id;                
00236     static int n_plugins;  
00237     wxString menuEntry;    
00238     PluginFunc pluginFunc; 
00239     UserInput input;       
00240 };
00241 
00243 
00247 struct Extension {
00249 
00254     Extension(const std::string& menuEntry_, void* pyFunc_,
00255               const std::string& description_, bool requiresFile_) :
00256         menuEntry(menuEntry_), pyFunc(pyFunc_),
00257         description(description_), requiresFile(requiresFile_)
00258     {
00259         id = n_extensions;
00260         n_extensions++;
00261     }
00262     
00264     ~Extension() { }
00265 
00266     int id;                
00267     static int n_extensions;  
00268     std::string menuEntry;    
00269     void* pyFunc;     
00270     std::string description;  
00271     bool requiresFile;     
00272 };
00273 
00275 struct ifstreamMan {
00276     
00278 
00279     ifstreamMan( const wxString& filename )
00280     : myStream( filename, wxT("r") ) 
00281     {}
00282     
00284     ~ifstreamMan() { myStream.Close(); }
00285     
00287     wxFFile myStream;
00288 };
00289 
00291 struct ofstreamMan {
00292 
00294 
00295     ofstreamMan( const wxString& filename )
00296     : myStream( filename, wxT("w") ) 
00297     {}
00298     
00300     ~ofstreamMan() { myStream.Close(); }
00301 
00303     wxFFile myStream;
00304 };
00305  
00307 class Event {
00308 public:
00310     explicit Event(std::size_t start, std::size_t peak, std::size_t size, bool discard_ = false) : 
00311         eventStartIndex(start), eventPeakIndex(peak), eventSize(size), discard(discard_) { }
00312     
00314     ~Event() {}
00315 
00317 
00318     std::size_t GetEventStartIndex() const { return eventStartIndex; }
00319 
00321 
00322     std::size_t GetEventPeakIndex() const { return eventPeakIndex; }
00323 
00325 
00326     std::size_t GetEventSize() const { return eventSize; }
00327 
00329 
00330     bool GetDiscard() const { return discard; }
00331 
00333 
00334     void SetEventStartIndex( std::size_t value ) { eventStartIndex = value; }
00335 
00337 
00338     void SetEventPeakIndex( std::size_t value ) { eventPeakIndex = value; }
00339 
00341 
00342     void SetEventSize( std::size_t value ) { eventSize = value; }
00343 
00345 
00346     void SetDiscard( bool value ) { discard = value; }
00347 
00349     void ToggleStatus() { discard = !discard; }
00350 
00351 private:
00352     std::size_t eventStartIndex;
00353     std::size_t eventPeakIndex;
00354     std::size_t eventSize;
00355     bool discard;
00356 };
00357 
00359 
00361 struct PyMarker {
00363 
00366     PyMarker( double xv, double yv ) : x(xv), y(yv) {} 
00367     double x; 
00368     double y; 
00369 };
00370 
00371 struct storedFunc;
00372  
00373 struct StfDll SectionAttributes {
00374     SectionAttributes();
00375     std::vector<stf::Event> eventList;
00376     std::vector<stf::PyMarker> pyMarkers;
00377     bool isFitted,isIntegrated;
00378     stf::storedFunc *fitFunc;
00379     Vector_double bestFitP;
00380     Vector_double quad_p;
00381     std::size_t storeFitBeg;
00382     std::size_t storeFitEnd;
00383     std::size_t storeIntBeg;
00384     std::size_t storeIntEnd;
00385     stf::Table bestFit;
00386 };
00387 
00388 struct SectionPointer {
00389     SectionPointer(Section* pSec=NULL, const SectionAttributes& sa=SectionAttributes());
00390     Section* pSection;
00391     SectionAttributes sec_attr;
00392 };
00393 
00395 const double PI=3.14159265358979323846;
00396 
00398 
00401 int round(double toRound);
00402 
00404 enum cursor_type {
00405     measure_cursor,  
00406     peak_cursor,     
00407     base_cursor,     
00408     decay_cursor,    
00409     latency_cursor,  
00410     zoom_cursor,     
00411     event_cursor,    
00412 #ifdef WITH_PSLOPE
00413     pslope_cursor,   
00414 #endif
00415     undefined_cursor 
00416 };
00417 
00418  
00419  
00421 enum direction {
00422     up,                 
00423     down,               
00424     both,               
00425     undefined_direction 
00426 };
00427  
00429 enum zoom_channels {
00430     zoomch1, 
00431     zoomch2, 
00432     zoomboth 
00433 };
00434 
00436 enum latency_mode {
00437     manualMode = 0, 
00438     peakMode = 1,   
00439     riseMode = 2,   
00440     halfMode = 3,   
00441     footMode = 4,    
00442     undefinedMode   
00443 };
00444 
00446 enum latency_window_mode {
00447     defaultMode = 0,  
00448     windowMode = 1  
00449 };
00450 
00451 #ifdef WITH_PSLOPE
00452 
00453 enum pslope_mode_beg {
00454     psBeg_manualMode, /*< Set the start Slope cursor manually. */
00455     psBeg_footMode,   /*< Set the start Slope cursor to the beginning of an event. */
00456     psBeg_thrMode,    /*< Set the start Slope cursor to a threshold. */
00457     psBeg_t50Mode,    /*< Set the start Slope cursor to the half-width of an event*/
00458     psBeg_undefined
00459 };
00460 
00462 enum pslope_mode_end {
00463     psEnd_manualMode, /*< Set the end Slope cursor manually. */
00464     psEnd_t50Mode,   /*< Set the Slope cursor to the half-width of an event. */
00465     psEnd_DeltaTMode,  /*< Set the Slope cursor to a given distance from the first cursor. */
00466     psEnd_peakMode,    /*< Set the Slope cursor to the peak. */
00467     psEnd_undefined
00468 };
00469 
00470 #endif // WITH_PSLOPE
00471 
00473 enum extraction_mode {
00474     criterion,                 
00475     correlation,               
00476     deconvolution               
00477 };
00478 
00481 } // end of namespace
00482 
00483 inline int stf::round(double toRound) {
00484     return toRound <= 0.0 ? int(toRound-0.5) : int(toRound+0.5);
00485 }
00486 
00487 typedef std::vector< wxString >::iterator       wxs_it;      
00488 typedef std::vector< wxString >::const_iterator c_wxs_it;    
00489 typedef std::vector< stf::Event      >::iterator       event_it;    
00490 typedef std::vector< stf::Event      >::const_iterator c_event_it;  
00491 typedef std::vector< stf::PyMarker   >::iterator       marker_it;   
00492 typedef std::vector< stf::PyMarker   >::const_iterator c_marker_it; 
00494 // Doxygen-links to documentation of frequently used wxWidgets-classes
00495 
00569 
00570 
00592 
00593 #endif
00594