Browse Source

Former-commit-id: 3186d8832ebe66f5a924b43a69dc6950b3bab733

dpanozzo 13 years ago
parent
commit
32c51f33fa
3 changed files with 147 additions and 5 deletions
  1. 120 0
      Timer.h
  2. 4 4
      adjacency_list.h
  3. 23 1
      plot_vector.h

+ 120 - 0
Timer.h

@@ -0,0 +1,120 @@
+//////////////////////////////////////////////////////////////////////////////
+// Timer.h
+// =======
+// High Resolution Timer.
+// This timer is able to measure the elapsed time with 1 micro-second accuracy
+// in both Windows, Linux and Unix system 
+//
+//  AUTHOR: Song Ho Ahn (song.ahn@gmail.com)
+// CREATED: 2003-01-13
+// UPDATED: 2006-01-13
+//
+// Copyright (c) 2003 Song Ho Ahn
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef TIMER_H_DEF
+#define TIMER_H_DEF
+
+#ifdef WIN32   // Windows system specific
+#include <windows.h>
+#else          // Unix based system specific
+#include <sys/time.h>
+#endif
+
+namespace igl
+{
+  class Timer
+  {
+  public:
+    Timer()                                     // default constructor
+    {
+#ifdef WIN32
+      QueryPerformanceFrequency(&frequency);
+      startCount.QuadPart = 0;
+      endCount.QuadPart = 0;
+#else
+      startCount.tv_sec = startCount.tv_usec = 0;
+      endCount.tv_sec = endCount.tv_usec = 0;
+#endif
+      
+      stopped = 0;
+      startTimeInMicroSec = 0;
+      endTimeInMicroSec = 0;
+    }
+    ~Timer()                                   // default destructor
+    {
+      
+    }
+    void   start()                             // start timer
+    {
+      stopped = 0; // reset stop flag
+#ifdef WIN32
+      QueryPerformanceCounter(&startCount);
+#else
+      gettimeofday(&startCount, NULL);
+#endif
+      
+    }
+    
+    void   stop()                              // stop the timer
+    {
+      stopped = 1; // set timer stopped flag
+      
+#ifdef WIN32
+      QueryPerformanceCounter(&endCount);
+#else
+      gettimeofday(&endCount, NULL);
+#endif
+      
+    }
+    double getElapsedTime()                    // get elapsed time in second
+    {
+      return this->getElapsedTimeInSec();
+    }
+    double getElapsedTimeInSec()               // get elapsed time in second (same as getElapsedTime)
+    {
+      return this->getElapsedTimeInMicroSec() * 0.000001;
+    }
+    
+    double getElapsedTimeInMilliSec()          // get elapsed time in milli-second
+    {
+      return this->getElapsedTimeInMicroSec() * 0.001;
+    }
+    double getElapsedTimeInMicroSec()          // get elapsed time in micro-second
+    {
+#ifdef WIN32
+      if(!stopped)
+        QueryPerformanceCounter(&endCount);
+      
+      startTimeInMicroSec = startCount.QuadPart * (1000000.0 / frequency.QuadPart);
+      endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart);
+#else
+      if(!stopped)
+        gettimeofday(&endCount, NULL);
+      
+      startTimeInMicroSec = (startCount.tv_sec * 1000000.0) + startCount.tv_usec;
+      endTimeInMicroSec = (endCount.tv_sec * 1000000.0) + endCount.tv_usec;
+#endif
+      
+      return endTimeInMicroSec - startTimeInMicroSec;
+    }
+    
+    
+  protected:
+    
+    
+  private:
+    double startTimeInMicroSec;                 // starting time in micro-second
+    double endTimeInMicroSec;                   // ending time in micro-second
+    int    stopped;                             // stop flag 
+#ifdef WIN32
+    LARGE_INTEGER frequency;                    // ticks per second
+    LARGE_INTEGER startCount;                   //
+    LARGE_INTEGER endCount;                     //
+#else
+    timeval startCount;                         //
+    timeval endCount;                           //
+#endif
+  };
+}
+#endif // TIMER_H_DEF

+ 4 - 4
adjacency_list.h

@@ -22,9 +22,9 @@ namespace igl
   //   adjacency_list(F,A);
   //
   // See also: edges, cotmatrix, diag
-  template <typename T>
+  template <typename T, typename M>
   inline void adjacency_list(
-                             const Eigen::MatrixXi & F, 
+                             const M & F, 
                              std::vector<std::vector<T> >& A,
                              bool sorted = false
                              );
@@ -33,9 +33,9 @@ namespace igl
 // Implementation
 #include "verbose.h"
 
-template <typename T>
+template <typename T, typename M>
 inline void igl::adjacency_list(
-                                const Eigen::MatrixXi & F, 
+                                const M & F, 
                                 std::vector<std::vector<T> >& A,
                                 bool sorted 
                                 )

+ 23 - 1
plot_vector.h

@@ -11,18 +11,40 @@ namespace igl
       std::cerr << v[i] << " ";
     std::cerr << std::endl;
   }
-
+  
   template <typename T>
   inline void plot_vector( std::vector< std::vector<T> >& v)
   {
     for (int i=0; i<v.size(); ++i)
     {
+      std::cerr << i << ": ";
       for (int j=0; j<v[i].size(); ++j)
         std::cerr << v[i][j] << " ";
       std::cerr << std::endl;
     }
   }
+  
+  
+  template <typename T>
+  inline void plot_vector( std::vector< std::vector< std::vector<T> > >& v)
+  {
+    for (int m=0; m<v.size(); ++m)
+    {
+      std::cerr << "Matrix " << m << std::endl;
 
+      for (int i=0; i<v[m].size(); ++i)
+      {
+        std::cerr << i << ": ";
+        for (int j=0; j<v[m][i].size(); ++j)
+          std::cerr << v[m][i][j] << " ";
+        std::cerr << std::endl;
+      }
+      
+      std::cerr << "---- end " << m << std::endl;
+
+    }
+  }
+  
 }
 
 #endif