//
//  subpixel_lsd.h
//  subpixel_lsd
//
//  Created by Mehdi Stapleton on 2015-05-18.
//
//

#ifndef __subpixel_lsd__
#define __subpixel_lsd__

#include "lsd.h"

//#define XCODE_COMPILATION
#ifndef XCODE_COMPILATION
#include "mex.h"
#endif

#include <sstream>
#include <string>
#include <cstdio>
#include <iostream>
#include <fstream>

#include <vector>
#include <cmath>

//---------------------------------------------------------------
//             GENERAL PREPROCESSOR DEFINITIONS
//---------------------------------------------------------------

#define BITS_PER_BYTE 8
//#define DEBUG_MODE

//---------------------------------------------------------------
//                      TYPE DEFINITIONS
//---------------------------------------------------------------

typedef double   matrix_t;
typedef double   pixel_t;
typedef uint32_t index_t;

//---------------------------------------------------------------
//                      GLOBAL CONSTANTS
//---------------------------------------------------------------

#ifdef XCODE_COMPILATION
static const std::string PROJECT_DIR_PATH = "../subpixel_lsd/";
#else
static const std::string PROJECT_DIR_PATH = "/Users/mehdistapleton/Documents/MATLAB/MASC/Image Processing Tools/Edge Detection/subpixel_lsd/";
#endif

template<typename T = char>
struct Image
{
	std::vector<T> pixels;
	size_t width, height;
    
    Image& operator=(const Image& img)
    {
        width  = img.width;
        height = img.height;
        
        for(index_t i=0; i<img.pixels.size(); ++i)
        {
            pixels.push_back(img.pixels[i]);
        }
        
        return *this;
    }
    
    void zero_fill(void)
    {
        size_t nPxls = width*height;
        pixels.resize(nPxls);
        std::fill(pixels.begin(), pixels.end(), 0);
    }
};

//---------------------------------------------------------------
//                      LOGGING FUNCTIONS
//---------------------------------------------------------------

#define LOG_DEBUG(txt) {std::ostringstream debug_oss; \
debug_oss <<"Debug:"<< txt << ";\n"; \
mexPrintf(debug_oss.str().c_str());}

#define LOG_PRINT(txt) {std::ostringstream debug_oss; \
debug_oss << txt << ";\n"; \
mexPrintf(debug_oss.str().c_str());}

#define LOG_WARNING(txt) {std::ostringstream debug_oss; \
debug_oss <<"Warning:"<< txt << ";\n"; \
mexPrintf(debug_oss.str().c_str());}

#define LOG_ERROR(txt) {std::ostringstream debug_oss; \
debug_oss <<"Error:"<< txt << ";\n"; \
mexPrintf(debug_oss.str().c_str());}

//---------------------------------------------------------------
//                      MACROS
//---------------------------------------------------------------

#define PROJECT_RELPATH(relpath) PROJECT_DIR_PATH + relpath

#define IS_REAL_3D_FULL_DOUBLE(P) (!mxIsComplex(P) && \
        mxGetNumberOfDimensions(P) == 3 && !mxIsSparse(P) && mxIsDouble(P))

#define IS_REAL_2D_FULL_DOUBLE(P) (!mxIsComplex(P) && \
        mxGetNumberOfDimensions(P) == 2 && !mxIsSparse(P) && mxIsDouble(P))

#define IS_REAL_SCALAR(P) (mxIsDouble(P) && !mxIsComplex(P) && mxGetNumberOfElements(P) == 1)

//---------------------------------------------------------------
//                      HELPER FUNCTIONS
//---------------------------------------------------------------


//---------------------------------------------------------------
//                 MAIN FUNCTION DECLARATIONS
//---------------------------------------------------------------


#endif /* defined(__subpixel_lsd__) */
