Commit 72bb7dd0 authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

Recreated.

parents
export NUMPY_INCLUDE=/usr/lib64/python2.7/site-packages/numpy/core/include/numpy
export PYTHON_INCLUDE=/usr/include/python2.7
export PYTHON_LIB=python2.7
export PYTHON_LIB_PATH=/usr/lib64
export PYTHON_LD_EXT=so
export PYTHON_LD_INSTALLDIR=/home/raffaele/Chaines/sitsproc/sitsproc_c_modules
export PYTHON_CPY_LINKERFLAGS=
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include src/subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: obiatools.$(PYTHON_LD_EXT)
# Tool invocations
obiatools.$(PYTHON_LD_EXT): $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: MinGW C++ Linker'
g++ -o"obiatools.$(PYTHON_LD_EXT)" $(OBJS) $(USER_OBJS) $(LIBS) -L$(PYTHON_LIB_PATH) $(PYTHON_CPY_LINKERFLAGS) -l$(PYTHON_LIB) -shared
@echo 'Finished building target: $@'
@echo ' '
$(MAKE) --no-print-directory post-build
# Other Targets
clean:
-$(RM) $(LIBRARIES)$(CC_DEPS)$(C++_DEPS)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(CPP_DEPS)$(C_DEPS) obiatools.$(PYTHON_LD_EXT)
-@echo ' '
post-build:
-cp obiatools.$(PYTHON_LD_EXT) $(PYTHON_LD_INSTALLDIR)
-@echo ' '
.PHONY: all clean dependents
.SECONDARY: post-build
-include ../makefile.targets
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS :=
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
C_UPPER_SRCS :=
CXX_SRCS :=
C++_SRCS :=
OBJ_SRCS :=
CC_SRCS :=
ASM_SRCS :=
CPP_SRCS :=
C_SRCS :=
S_UPPER_SRCS :=
O_SRCS :=
LIBRARIES :=
CC_DEPS :=
C++_DEPS :=
OBJS :=
C_UPPER_DEPS :=
CXX_DEPS :=
CPP_DEPS :=
C_DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
src \
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../src/labelmap.cpp \
../src/labelmap1d.cpp \
../src/main.cpp \
../src/rasterdata.cpp \
../src/rasterdata1d.cpp \
../src/rasterstats.cpp \
../src/rasterstats1d.cpp
OBJS += \
./src/labelmap.o \
./src/labelmap1d.o \
./src/main.o \
./src/rasterdata.o \
./src/rasterdata1d.o \
./src/rasterstats.o \
./src/rasterstats1d.o
CPP_DEPS += \
./src/labelmap.d \
./src/labelmap1d.d \
./src/main.d \
./src/rasterdata.d \
./src/rasterdata1d.d \
./src/rasterstats.d \
./src/rasterstats1d.d
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
g++ -DMS_WIN64 -I$(PYTHON_INCLUDE) -I$(NUMPY_INCLUDE) -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
/*
* dataconverter.h
*
* Created on: 21 sept. 2015
* Author: gaetano
*/
#ifndef DATACONVERTER_H_
#define DATACONVERTER_H_
template <typename T, typename TI>
T** array_1to2d(T* x, TI* dims) {
TI i,j,c;
c = 0;
T** y = new T*[dims[0]];
for (i=0;i<dims[0];i++) {
y[i] = new T[dims[1]];
for (j=0;j<dims[1];j++) {
y[i][j] = x[c++];
}
}
return y;
}
template <typename T, typename TI>
T* array_2to1d(T** x, TI* dims) {
TI i,j,c;
c = 0;
T* y = new T[dims[0]*dims[1]];
for (i=0;i<dims[0];i++) {
for (j=0;j<dims[1];j++) {
y[c++] = x[i][j];
}
}
return y;
}
template <typename T, typename TI>
T*** array_1to3d(T* x, TI* dims) {
TI i,j,k,c;
c = 0;
T*** y = new T**[dims[0]];
for (k=0;k<dims[0];k++) {
y[k] = new T*[dims[1]];
for (i=0;i<dims[1];i++) {
y[k][i] = new T[dims[2]];
for (j=0;j<dims[2];j++) {
y[k][i][j] = x[c++];
}
}
}
return y;
}
template <typename T, typename TI>
T* array_3to1d(T*** x, TI* dims) {
TI i,j,k,c;
c = 0;
T* y = new T[dims[0]*dims[1]*dims[2]];
for (k=0;k<dims[0];k++) {
for (i=0;i<dims[1];i++) {
for (j=0;j<dims[2];j++) {
y[c++] = x[k][i][j];
}
}
}
return y;
}
template <typename T, typename TI>
void del_array_3d(T*** x, TI* dims) {
TI i,k;
for (k=0;k<dims[0];k++) {
for (i=0;i<dims[1];i++) {
delete [] x[k][i];
}
delete [] x[k];
}
delete [] x;
}
template <typename T, typename TI>
void del_array_2d(T** x, TI* dims) {
TI i;
for (i=0;i<dims[0];i++) {
delete [] x[i];
}
delete [] x;
}
#endif /* DATACONVERTER_H_ */
/*
* labelmap.cpp
*
* Created on: 13 juil. 2016
* Author: gaetano
*/
#include "labelmap.h"
LabelMap::LabelMap(Label** in, int r, int c, Label bg) {
int i,j,cnt;
rows = r;
cols = c;
background = bg;
cnt = 0;
pair<map<Label,int>::iterator,bool> ret;
lmap = new Label*[rows];
for (i=0;i<rows;i++) {
lmap[i] = new Label[cols];
for (j=0;j<cols;j++) {
lmap[i][j] = in[i][j];
if (lmap[i][j] != background) {
ret = rLabels.insert(pair<Label,int>(lmap[i][j],cnt));
if (ret.second)
labels.insert(pair<int,Label>(cnt++,lmap[i][j]));
}
}
}
nObjects = (Label)labels.size();
}
LabelMap::~LabelMap() {
int i;
for (i=0;i<rows;i++) {
delete [] lmap[i];
}
delete [] lmap;
}
/*
* labelmap.h
*
* Created on: 13 juil. 2016
* Author: gaetano
*/
#ifndef LABELMAP_H_
#define LABELMAP_H_
#include "obiatools.h"
#include <map>
using namespace std;
class LabelMap {
private:
Label** lmap;
public:
int rows,cols;
Label background;
map<int, Label> labels;
map<Label,int> rLabels;
Label nObjects;
LabelMap(Label** in, int r, int c, Label bg = 0);
~LabelMap();
inline Label& operator()(int i, int j) {
return lmap[i][j];
}
};
#endif /* LABELMAP_H_ */
/*
* labelmap.cpp
*
* Created on: 13 juil. 2016
* Author: gaetano
*/
#include "labelmap1d.h"
LabelMap1D::LabelMap1D(Label* in, int r, int c, Label bg) {
int i,j,cnt;
Label tmp;
rows = r;
cols = c;
background = bg;
cnt = 0;
pair<map<Label,int>::iterator,bool> ret;
lmap = in;
for (i=0;i<rows;i++) {
for (j=0;j<cols;j++) {
tmp = lmap[i*cols+j];
if (tmp != background) {
ret = rLabels.insert(pair<Label,int>(tmp,cnt));
if (ret.second)
labels.insert(pair<int,Label>(cnt++,tmp));
}
}
}
nObjects = (Label)labels.size();
}
LabelMap1D::~LabelMap1D() {
}
/*
* labelmap.h
*
* Created on: 13 juil. 2016
* Author: gaetano
*/
#ifndef LABELMAP1D_H_
#define LABELMAP1D_H_
#include "obiatools.h"
#include <map>
using namespace std;
class LabelMap1D {
private:
Label* lmap;
public:
int rows,cols;
Label background;
map<int, Label> labels;
map<Label,int> rLabels;
Label nObjects;
LabelMap1D(Label* in, int r, int c, Label bg = 0);
~LabelMap1D();
inline Label& operator()(int i, int j) {
return lmap[i*cols+j];
}
};
#endif /* LABELMAP_H_ */
/*
* main.cpp
*
* Created on: 13 juil. 2016
* Author: gaetano
*/
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <Python.h>
#include <arrayobject.h>
#include "dataconverter.h"
#include "rasterstats.h"
#include "rasterstats1d.h"
using namespace std;
static PyObject *
obiatools_version(PyObject *self, PyObject *args) {
PySys_WriteStdout("Hello from OBIATOOLS! Version 0.0.1a");
return Py_None;
}
/*
* TO DELETE!
static PyObject *
obiatools_test(PyObject *self, PyObject *args) {
int b,iR,iC,oR,oC;
PyArrayObject *img;
PyArrayObject *ol;
PyObject *w = 0;
PyArg_ParseTuple(args,"O!O!|O", &PyArray_Type, &img, &PyArray_Type, &ol, &w);
npy_intp *iDims = PyArray_DIMS(img);
b = iDims[0]; iR = iDims[1]; iC = iDims[2];
npy_intp *oDims = PyArray_DIMS(ol);
oR = oDims[0]; oC = oDims[1];
Data* img_vec = (Data*)PyArray_DATA(img);
Data*** image = array_1to3d<Data,npy_intp>(img_vec,iDims);
Label* ol_vec = (Label*)PyArray_DATA(ol);
Label** objlayer = array_1to2d<Label,npy_intp>(ol_vec,oDims);
float **wg;
float *w_vec;
if (!w || w == Py_None) {
wg = 0;
} else {
PyArray_Descr* dtype;
int _ndims;
npy_intp _dims;
PyArrayObject* _w;
PyArray_GetArrayParamsFromObject(w,NULL,1,&dtype,&_ndims,&_dims,&_w,NULL);
w_vec = (float*)PyArray_DATA(_w);
wg = array_1to2d<float,npy_intp>(w_vec,&iDims[1]);
}
RasterStats rs(objlayer,oR,oC);
rs.addRaster(image,b,iR,iC,wg);
rs.computeStatistics(0,OSTAT_MIN);
rs.computeStatistics(0,OSTAT_MAX);
rs.computeStatistics(0,OSTAT_RANGE);
map<Label,float> feat = rs.getStat(0,0,OSTAT_MIN);
PySys_WriteStdout("Min:\n");
map<Label,float>::iterator it;
for (it=feat.begin();it!=feat.end();it++)
PySys_WriteStdout("%d --> %10.5f\n",it->first,it->second);
PySys_WriteStdout("\nMax:\n");
feat = rs.getStat(0,0,OSTAT_MAX);
for (it=feat.begin();it!=feat.end();it++)
PySys_WriteStdout("%d --> %10.5f\n",it->first,it->second);
PySys_WriteStdout("\nRange:\n");
feat = rs.getStat(0,0,OSTAT_RANGE);
for (it=feat.begin();it!=feat.end();it++)
PySys_WriteStdout("%d --> %10.5f\n",it->first,it->second);
rs.computeStatistics(0,OSTAT_MEDIAN);
map<Label,float> feat = rs.getStat(0,3,OSTAT_MEDIAN);
PySys_WriteStdout("\nMedian:\n");
map<Label,float>::iterator it;
for (it=feat.begin();it!=feat.end();it++)
PySys_WriteStdout("%d --> %10.5f\n",it->first,it->second);
PySys_WriteStdout("\n ==> OK from inside! \n\n");
return Py_None;
}
*/
/*
static PyObject *
obiatools_zonalstats(PyObject *self, PyObject *args) {
int t,k,s;
int B,R,C,oR,oC,nStats,nObj;
PyArrayObject *ol, *ras, *ridx, *cidx, *stats;
PyObject *w = 0;
PyArg_ParseTuple(args,"O!O!O!O!O!|O", &PyArray_Type, &ol, &PyArray_Type, &ras, &PyArray_Type, &ridx, &PyArray_Type, &cidx, &PyArray_Type, &stats, &w);
npy_intp nRasDims = PyArray_NDIM(ras);
npy_intp *rasDims = PyArray_DIMS(ras);
if (nRasDims == 2) {
B = 1; R = rasDims[0]; C = rasDims[1];
} else {
B = rasDims[0]; R = rasDims[1]; C = rasDims[2];
}
npy_intp *olDims = PyArray_DIMS(ol);
oR = olDims[0]; oC = olDims[1];
Data* ras_vec = (Data*)PyArray_DATA(ras);
Data*** ras_arr = array_1to3d<Data,npy_intp>(ras_vec,rasDims);
Label* ol_vec = (Label*)PyArray_DATA(ol);
Label** ol_arr = array_1to2d<Label,npy_intp>(ol_vec,olDims);
int* row_idx = (int*)PyArray_DATA(ridx);
int* col_idx = (int*)PyArray_DATA(cidx);
npy_intp *statsDims = PyArray_DIMS(stats);
int* stats_vec = (int*)PyArray_DATA(stats);
nStats = (int)statsDims[0];
float **wg;
float *w_vec;
if (!w || w == Py_None) {
wg = 0;
} else {
PyArray_Descr* dtype;
int _ndims;
npy_intp _dims;
PyArrayObject* _w;
PyArray_GetArrayParamsFromObject(w,NULL,1,&dtype,&_ndims,&_dims,&_w,NULL);
w_vec = (float*)PyArray_DATA(_w);
wg = array_1to2d<float,npy_intp>(w_vec,&rasDims[1]);
}
RasterStats rs(ol_arr,oR,oC);
rs.addRaster(ras_arr,B,R,C,row_idx,col_idx,wg);
nObj = rs.getNObjects();
int *cstats = new int[nStats];
int tot_stats = 0;
for (s=0; s<nStats; s++) {
cstats[s] = rs.computeStatistics(0,stats_vec[s]);
tot_stats += cstats[s];
}
float **zstats = new float*[nObj];
for (t=0; t<nObj; t++) zstats[t] = new float[tot_stats+1];
map<Label,float> tmp;
map<Label,float>::iterator it;
int cnt = 0;
for (s=0; s<nStats; s++) {
for (k=0; k<cstats[s]; k++) {
tmp.clear();
tmp = rs.getStat(0,k,stats_vec[s]);
if (k==0 && s==0) {
t = 0;
for (it=tmp.begin();it!=tmp.end();it++) zstats[t++][cnt] = it->first;
cnt++;
}
t = 0;
for (it=tmp.begin();it!=tmp.end();it++) zstats[t++][cnt] = it->second;
cnt++;
}
}
npy_intp featDims = (npy_intp)tot_stats;
PyObject *out_dict = PyDict_New();
PyObject *key,*val;
for (t=0;t<nObj;t++) {
key = PyInt_FromLong((long)round(zstats[t][0]));
val = PyArray_SimpleNewFromData(1,&featDims,NPY_FLOAT32,&zstats[t][1]);
PyDict_SetItem(out_dict,key,val);
}
npy_intp py_nStats = (npy_intp)nStats;
PyObject *out_cstats = PyArray_SimpleNewFromData(1,&py_nStats,NPY_INT32,cstats);
del_array_3d<Data,npy_intp>(ras_arr,rasDims);
del_array_2d<Label,npy_intp>(ol_arr,olDims);
if (w && w != Py_None) del_array_2d<float,npy_intp>(wg,&rasDims[1]);