Stimfit  0.13.15
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
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 
00097 wxString sectionToString(const Section& section);
00098  
00100 
00103 wxString CreatePreview(const wxString& fName);
00104  
00106 
00109 wxString noPath(const wxString& fName);
00110 
00112 typedef boost::function<Recording(const Recording&,const Vector_double&,std::map<std::string, double>&)> PluginFunc;
00113 
00115 
00117 class StfDll Table {
00118 public:
00120 
00123     Table(std::size_t nRows,std::size_t nCols);
00124 
00126 
00128     Table(const std::map< std::string, double >& map);
00129 
00131 
00135     double at(std::size_t row,std::size_t col) const;
00136 
00138 
00142     double& at(std::size_t row,std::size_t col);
00143     
00145 
00149     bool IsEmpty(std::size_t row,std::size_t col) const;
00150 
00152 
00156     void SetEmpty(std::size_t row,std::size_t col,bool value=true);
00157 
00159 
00162     void SetRowLabel(std::size_t row,const std::string& label);
00163 
00165 
00168     void SetColLabel(std::size_t col,const std::string& label);
00169 
00171 
00174     const std::string& GetRowLabel(std::size_t row) const;
00175 
00177 
00180     const std::string& GetColLabel(std::size_t col) const;
00181 
00183 
00185     std::size_t nRows() const { return rowLabels.size(); }
00186 
00188 
00190     std::size_t nCols() const { return colLabels.size(); }
00191     
00193 
00195     void AppendRows(std::size_t nRows);
00196 
00197 private:
00198     // row major order:
00199     std::vector< std::vector<double> > values;
00200     std::vector< std::deque< bool > > empty;
00201     std::vector< std::string > rowLabels;
00202     std::vector< std::string > colLabels;
00203 };
00204  
00206 struct UserInput {
00207     std::vector<std::string> labels; 
00208     Vector_double defaults; 
00209     std::string title;               
00211 
00212 
00216     UserInput(
00217             const std::vector<std::string>& labels_=std::vector<std::string>(0),
00218             const Vector_double& defaults_=Vector_double(0),
00219             std::string title_="\0"
00220     ) : labels(labels_),defaults(defaults_),title(title_)
00221     {
00222                 if (defaults.size()!=labels.size()) {
00223                     defaults.resize(labels.size());
00224                     std::fill(defaults.begin(), defaults.end(), 0.0);
00225                 }
00226     }
00227 };
00228 
00230 
00234 struct Plugin {
00236 
00240     Plugin(
00241             const wxString& menuEntry_,
00242             const PluginFunc& pluginFunc_,
00243             const UserInput& input_=UserInput()
00244     ) : menuEntry(menuEntry_),pluginFunc(pluginFunc_),input(input_)
00245     {
00246         id = n_plugins;
00247         n_plugins++;
00248     }
00249     
00251     ~Plugin() { }
00252 
00253     int id;                
00254     static int n_plugins;  
00255     wxString menuEntry;    
00256     PluginFunc pluginFunc; 
00257     UserInput input;       
00258 };
00259 
00261 
00265 struct Extension {
00267 
00272     Extension(const std::string& menuEntry_, void* pyFunc_,
00273               const std::string& description_, bool requiresFile_) :
00274         menuEntry(menuEntry_), pyFunc(pyFunc_),
00275         description(description_), requiresFile(requiresFile_)
00276     {
00277         id = n_extensions;
00278         n_extensions++;
00279     }
00280     
00282     ~Extension() { }
00283 
00284     int id;                
00285     static int n_extensions;  
00286     std::string menuEntry;    
00287     void* pyFunc;     
00288     std::string description;  
00289     bool requiresFile;     
00290 };
00291 
00293 struct ifstreamMan {
00294     
00296 
00297     ifstreamMan( const wxString& filename )
00298     : myStream( filename, wxT("r") ) 
00299     {}
00300     
00302     ~ifstreamMan() { myStream.Close(); }
00303     
00305     wxFFile myStream;
00306 };
00307 
00309 struct ofstreamMan {
00310 
00312 
00313     ofstreamMan( const wxString& filename )
00314     : myStream( filename, wxT("w") ) 
00315     {}
00316     
00318     ~ofstreamMan() { myStream.Close(); }
00319 
00321     wxFFile myStream;
00322 };
00323  
00325 class Event {
00326 public:
00328     explicit Event(std::size_t start, std::size_t peak, std::size_t size, bool discard_ = false) : 
00329         eventStartIndex(start), eventPeakIndex(peak), eventSize(size), discard(discard_) { }
00330     
00332     ~Event() {}
00333 
00335 
00336     std::size_t GetEventStartIndex() const { return eventStartIndex; }
00337 
00339 
00340     std::size_t GetEventPeakIndex() const { return eventPeakIndex; }
00341 
00343 
00344     std::size_t GetEventSize() const { return eventSize; }
00345 
00347 
00348     bool GetDiscard() const { return discard; }
00349 
00351 
00352     void SetEventStartIndex( std::size_t value ) { eventStartIndex = value; }
00353 
00355 
00356     void SetEventPeakIndex( std::size_t value ) { eventPeakIndex = value; }
00357 
00359 
00360     void SetEventSize( std::size_t value ) { eventSize = value; }
00361 
00363 
00364     void SetDiscard( bool value ) { discard = value; }
00365 
00367     void ToggleStatus() { discard = !discard; }
00368 
00369 private:
00370     std::size_t eventStartIndex;
00371     std::size_t eventPeakIndex;
00372     std::size_t eventSize;
00373     bool discard;
00374 };
00375 
00377 
00379 struct PyMarker {
00381 
00384     PyMarker( double xv, double yv ) : x(xv), y(yv) {} 
00385     double x; 
00386     double y; 
00387 };
00388 
00389 struct storedFunc;
00390  
00391 struct StfDll SectionAttributes {
00392     SectionAttributes();
00393     std::vector<stf::Event> eventList;
00394     std::vector<stf::PyMarker> pyMarkers;
00395     bool isFitted,isIntegrated;
00396     stf::storedFunc *fitFunc;
00397     Vector_double bestFitP;
00398     Vector_double quad_p;
00399     std::size_t storeFitBeg;
00400     std::size_t storeFitEnd;
00401     std::size_t storeIntBeg;
00402     std::size_t storeIntEnd;
00403     stf::Table bestFit;
00404 };
00405 
00406 struct SectionPointer {
00407     SectionPointer(Section* pSec=NULL, const SectionAttributes& sa=SectionAttributes());
00408     Section* pSection;
00409     SectionAttributes sec_attr;
00410 };
00411 
00413 const double PI=3.14159265358979323846;
00414 
00416 
00419 int round(double toRound);
00420 
00422 enum cursor_type {
00423     measure_cursor,  
00424     peak_cursor,     
00425     base_cursor,     
00426     decay_cursor,    
00427     latency_cursor,  
00428     zoom_cursor,     
00429     event_cursor,    
00430 #ifdef WITH_PSLOPE
00431     pslope_cursor,   
00432 #endif
00433     undefined_cursor 
00434 };
00435 
00436  
00437  
00439 enum direction {
00440     up,                 
00441     down,               
00442     both,               
00443     undefined_direction 
00444 };
00445  
00447 enum zoom_channels {
00448     zoomch1, 
00449     zoomch2, 
00450     zoomboth 
00451 };
00452 
00454 enum latency_mode {
00455     manualMode = 0, 
00456     peakMode = 1,   
00457     riseMode = 2,   
00458     halfMode = 3,   
00459     footMode = 4,    
00460     undefinedMode   
00461 };
00462 
00464 enum latency_window_mode {
00465     defaultMode = 0,  
00466     windowMode = 1  
00467 };
00468 
00469 #ifdef WITH_PSLOPE
00470 
00471 enum pslope_mode_beg {
00472     psBeg_manualMode =0,    /*< Set the start Slope cursor manually. */
00473     psBeg_footMode   =1,    /*< Set the start Slope cursor to the beginning of an event. */
00474     psBeg_thrMode    =2,    /*< Set the start Slope cursor to a threshold. */
00475     psBeg_t50Mode    =3,    /*< Set the start Slope cursor to the half-width of an event*/
00476     psBeg_undefined
00477 };
00478 
00480 enum pslope_mode_end {
00481     psEnd_manualMode =0,    /*< Set the end Slope cursor manually. */
00482     psEnd_t50Mode    =1,    /*< Set the Slope cursor to the half-width of an event. */
00483     psEnd_DeltaTMode =2,    /*< Set the Slope cursor to a given distance from the first cursor. */
00484     psEnd_peakMode   =3,    /*< Set the Slope cursor to the peak. */
00485     psEnd_undefined
00486 };
00487 
00488 #endif // WITH_PSLOPE
00489 
00491 enum extraction_mode {
00492     criterion,                 
00493     correlation,               
00494     deconvolution               
00495 };
00496 
00499 } // end of namespace
00500 
00501 inline int stf::round(double toRound) {
00502     return toRound <= 0.0 ? int(toRound-0.5) : int(toRound+0.5);
00503 }
00504 
00505 typedef std::vector< wxString >::iterator       wxs_it;      
00506 typedef std::vector< wxString >::const_iterator c_wxs_it;    
00507 typedef std::vector< stf::Event      >::iterator       event_it;    
00508 typedef std::vector< stf::Event      >::const_iterator c_event_it;  
00509 typedef std::vector< stf::PyMarker   >::iterator       marker_it;   
00510 typedef std::vector< stf::PyMarker   >::const_iterator c_marker_it; 
00512 // Doxygen-links to documentation of frequently used wxWidgets-classes
00513 
00587 
00588 
00610 
00611 #endif
00612 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines