diff --git a/ld2dap/AttributeProfiles.py b/ld2dap/AttributeProfiles.py new file mode 100644 index 0000000..c8551cf --- /dev/null +++ b/ld2dap/AttributeProfiles.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file AttributeProfiles.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 04 avril 2018 +# +# TODO details + +from core import Filter + +## TODO: dep +import sys +sys.path.append('../triskele/python') +import triskele + +class AttributeProfiles(Filter): + def __init__(self, area=None, sd=None, moi=None): + super().__init__(self.__class__.__name__) + self.area = area + self.sd = sd + self.moi = moi + + def _process(self, data, metadata): + t = triskele.Triskele(data, verbose=False) + att_min = t.filter(tree='min-tree', area=self.area, + standard_deviation=self.sd, + moment_of_inertia=self.moi) + att_max = t.filter(tree='max-tree', area=self.area, + standard_deviation=self.sd, + moment_of_inertia=self.moi) + + return att, None diff --git a/ld2dap/LoadTIFF.py b/ld2dap/LoadTIFF.py new file mode 100644 index 0000000..e63830b --- /dev/null +++ b/ld2dap/LoadTIFF.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file LoadTIFF.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 04 avril 2018 +# +# TODO details + +from core import Input +import numpy as np + +## TODO: dep +import sys +sys.path.append('../triskele/python') +import triskele + +class LoadTIFF(Input): + def __init__(self, tiffFiles): + super().__init__(self.__class__.__name__) + self.files = tiffFiles + + def _process(self, data, metadata): + layers = list() + + for file in self.files: + print('Loading {}'.format(file)) + layers.append(triskele.read(file)) + + return np.stack(layers, axis=2), self.files + diff --git a/ld2dap/core/Filter.py b/ld2dap/core/Filter.py new file mode 100644 index 0000000..d67334d --- /dev/null +++ b/ld2dap/core/Filter.py @@ -0,0 +1,17 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file Filter.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 03 avril 2018 +# +# TODO details + +from .Input import Input +from .Output import Output + +class Filter(Output, Input): + """Output should be first""" + def __init__(self, name='__CHILD__'): + super().__init__('Filter:{}'.format(name)) diff --git a/ld2dap/core/Input.py b/ld2dap/core/Input.py new file mode 100644 index 0000000..0cda81d --- /dev/null +++ b/ld2dap/core/Input.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file Input.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 03 avril 2018 +# +# TODO details + +from .Node import Node + +class Input(Node): + def __init__(self, name='__CHILD__'): + super().__init__('Input:{}'.format(name)) + self.outputs = list() + + def register(self, output): + self.outputs.append(output) + + def process(self, data, metadata=None): + """Override abstract method""" + data, meta = self._process(data, metadata) + for output in self.outputs: + output.process(data, meta) + + def _run(self): + self.process(None, None) diff --git a/ld2dap/core/Node.py b/ld2dap/core/Node.py new file mode 100644 index 0000000..1a6ca27 --- /dev/null +++ b/ld2dap/core/Node.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file Node.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 03 avril 2018 +# +# TODO details + + +class Node(object): + def __init__(self, name='A NODE HAS NO NAME'): + self.name = name + + def __str__(self): + return ("Node:{}".format(self.name)) + + def process(self, data, metadata=None): + self._process(data) + + def _process(self, data, metadata=None): + raise NotImplementedError( + '{} should override _process(self, data, metadata)'.format(self)) + + def _run(self): + raise NotImplementedError('{} should override _run()'.format(self)) + + def run(self): + return self._run() diff --git a/ld2dap/core/Output.py b/ld2dap/core/Output.py new file mode 100644 index 0000000..c2abe02 --- /dev/null +++ b/ld2dap/core/Output.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file Output.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 03 avril 2018 +# +# TODO details + +#from . import Node, Input +from .Node import Node +from .Input import Input + +class Output(Node): + def __init__(self, name='__CHILD__'): + super().__init__('Output:{}'.format(name)) + self.__dict__['input'] = None + + def __setattr__(self, name, value): + if name == 'input': + self._input(value) + else: + self.__dict__[name] = value + + def _input(self, inode): + if not isinstance(inode, (Input)): + raise NotImplementedError('{} is not an Input'.format(inode)) + self.__dict__['input'] = inode + inode.register(self) + + def _run(self): + if self.input is None: + raise RuntimeError('{} do not have an input'.format(self)) + return self.input.run() diff --git a/ld2dap/core/__init__.py b/ld2dap/core/__init__.py new file mode 100644 index 0000000..ac7bdea --- /dev/null +++ b/ld2dap/core/__init__.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file %filename%.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 04 avril 2018 +# +# TODO details + +from .Output import Output +from .Input import Input +from .Filter import Filter diff --git a/ld2dap/test.py b/ld2dap/test.py new file mode 100644 index 0000000..1e3fbed --- /dev/null +++ b/ld2dap/test.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# \file test.py +# \brief TODO +# \author Florent Guiotte +# \version 0.1 +# \date 03 avril 2018 +# +# TODO details + +from core import Input, Output, Filter +from LoadTIFF import LoadTIFF +from AttributeProfiles import AttributeProfiles as APs + +def main(): + i = LoadTIFF(['../Data/test.tiff']) + ap = APs() + o = Output('o') + + ap.input = i + o.input = i + + o.run() + +if __name__ == '__main__': + main()