Skip to content

Commit bc9d776

Browse files
committed
Custom segmentation
1 parent dc3c234 commit bc9d776

File tree

13 files changed

+268
-38
lines changed

13 files changed

+268
-38
lines changed

SEPythonModule/SEPythonModule/PipelineReceiver.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@ namespace SourceXPy {
3131
using SourceReceiverIfce = SourceXtractor::PipelineReceiver<SourceXtractor::SourceInterface>;
3232
using GroupReceiverIfce = SourceXtractor::PipelineReceiver<SourceXtractor::SourceGroupInterface>;
3333

34-
class ProcessSourcesEvent {
35-
public:
36-
SourceXtractor::ProcessSourcesEvent m_event;
37-
38-
std::string repr() const;
39-
};
34+
std::string ProcessSourcesEventRepr(const SourceXtractor::ProcessSourcesEvent&);
4035

4136
class AllFramesDone : public SourceXtractor::SelectionCriteria {
4237
public:
4338
bool mustBeProcessed(const SourceXtractor::SourceInterface& source) const override;
39+
40+
static SourceXtractor::ProcessSourcesEvent create();
4441
};
4542

4643
class PipelineSourceReceiver : public SourceReceiverIfce {
@@ -62,7 +59,7 @@ class PipelineSourceReceiver : public SourceReceiverIfce {
6259
void receiveProcessSignal(const SourceXtractor::ProcessSourcesEvent& event) override {
6360
Pyston::GILLocker gil;
6461
try {
65-
m_callback(ProcessSourcesEvent{event});
62+
m_callback(event);
6663
} catch (const boost::python::error_already_set&) {
6764
throw Pyston::Exception();
6865
}
@@ -92,7 +89,7 @@ class PipelineGroupReceiver : public GroupReceiverIfce {
9289
void receiveProcessSignal(const SourceXtractor::ProcessSourcesEvent& event) override {
9390
Pyston::GILLocker gil;
9491
try {
95-
m_callback(ProcessSourcesEvent{event});
92+
m_callback(event);
9693
} catch (const boost::python::error_already_set&) {
9794
throw Pyston::Exception();
9895
}

SEPythonModule/SEPythonModule/SourceInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
#include "SEFramework/Source/SourceGroupInterface.h"
2323
#include "SEFramework/Source/SourceInterface.h"
24+
#include "SEImplementation/Property/PixelCoordinateList.h"
2425
#include "SEPythonModule/Context.h"
26+
#include <boost/python/dict.hpp>
2527
#include <boost/python/object.hpp>
2628
#include <memory>
2729
#include <string>
@@ -54,6 +56,9 @@ struct OwnedSource : public AttachedSource {
5456
std::string repr() const;
5557

5658
std::unique_ptr<SourceXtractor::SourceInterface> m_owned_source;
59+
60+
static std::shared_ptr<OwnedSource> create(const std::shared_ptr<Context>& context, int detection_frame_idx,
61+
int detection_id, const boost::python::tuple& pixels);
5762
};
5863

5964
struct EntangledSource : public AttachedSource {

SEPythonModule/src/lib/Deblending.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <boost/python/extract.hpp>
2424

2525
namespace py = boost::python;
26+
namespace se = SourceXtractor;
2627

2728
namespace SourceXPy {
2829

@@ -56,9 +57,9 @@ void Deblending::call(const py::object& obj) const {
5657
m_deblending->receiveSource(std::move(cloned_group_ptr));
5758
return;
5859
}
59-
py::extract<ProcessSourcesEvent> event_wrapper(obj);
60+
py::extract<se::ProcessSourcesEvent> event_wrapper(obj);
6061
if (event_wrapper.check()) {
61-
const auto& event = event_wrapper().m_event;
62+
const auto& event = event_wrapper();
6263
Pyston::SaveThread save_thread;
6364
m_deblending->receiveProcessSignal(event);
6465
return;

SEPythonModule/src/lib/FitsOutput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <boost/python/extract.hpp>
2424

2525
namespace py = boost::python;
26+
namespace se = SourceXtractor;
2627

2728
namespace SourceXPy {
2829

@@ -58,9 +59,9 @@ void FitsOutput::call(const boost::python::object& obj) {
5859
m_output->receiveSource(std::move(cloned_group_ptr));
5960
return;
6061
}
61-
py::extract<ProcessSourcesEvent> event_wrapper(obj);
62+
py::extract<se::ProcessSourcesEvent> event_wrapper(obj);
6263
if (event_wrapper.check()) {
63-
const auto& event = event_wrapper().m_event;
64+
const auto& event = event_wrapper();
6465
Pyston::SaveThread save_thread;
6566
m_output->receiveProcessSignal(event);
6667
return;

SEPythonModule/src/lib/Grouping.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <boost/python/extract.hpp>
2323

2424
namespace py = boost::python;
25+
namespace se = SourceXtractor;
2526

2627
namespace SourceXPy {
2728

@@ -58,9 +59,9 @@ void Grouping::call(const py::object& obj) const {
5859
m_grouping->receiveSource(source_ptr->clone());
5960
return;
6061
}
61-
py::extract<ProcessSourcesEvent> event_wrapper(obj);
62+
py::extract<se::ProcessSourcesEvent> event_wrapper(obj);
6263
if (event_wrapper.check()) {
63-
const auto& event = event_wrapper().m_event;
64+
const auto& event = event_wrapper();
6465
Pyston::SaveThread save_thread;
6566
m_grouping->receiveProcessSignal(event);
6667
return;

SEPythonModule/src/lib/Measurement.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <boost/python/extract.hpp>
2323

2424
namespace py = boost::python;
25+
namespace se = SourceXtractor;
2526

2627
namespace SourceXPy {
2728

@@ -70,9 +71,9 @@ void Measurement::call(const py::object& obj) {
7071
m_measurement->receiveSource(std::move(cloned_group_ptr));
7172
return;
7273
}
73-
py::extract<ProcessSourcesEvent> event_wrapper(obj);
74+
py::extract<se::ProcessSourcesEvent> event_wrapper(obj);
7475
if (event_wrapper.check()) {
75-
const auto& event = event_wrapper().m_event;
76+
const auto& event = event_wrapper();
7677
Pyston::SaveThread save_thread;
7778
m_measurement->receiveProcessSignal(event);
7879
return;

SEPythonModule/src/lib/NumpyOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void NumpyOutput::call(const py::object& obj) {
6161
boost::transform(*group_ptr, std::back_inserter(m_rows), m_source_to_row);
6262
return;
6363
}
64-
py::extract<ProcessSourcesEvent> event_wrapper(obj);
64+
py::extract<se::ProcessSourcesEvent> event_wrapper(obj);
6565
if (!event_wrapper.check()) {
6666
PyErr_SetString(PyExc_TypeError, "NumpyOutput: Unexpected python object received");
6767
py::throw_error_already_set();

SEPythonModule/src/lib/Partition.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <boost/python/extract.hpp>
2323

2424
namespace py = boost::python;
25+
namespace se = SourceXtractor;
2526

2627
namespace SourceXPy {
2728

@@ -58,9 +59,9 @@ void Partition::call(const py::object& obj) const {
5859
m_partition->receiveSource(source_ptr->clone());
5960
return;
6061
}
61-
py::extract<ProcessSourcesEvent> event_wrapper(obj);
62+
py::extract<se::ProcessSourcesEvent> event_wrapper(obj);
6263
if (event_wrapper.check()) {
63-
const auto& event = event_wrapper().m_event;
64+
const auto& event = event_wrapper();
6465
Pyston::SaveThread save_thread;
6566
m_partition->receiveProcessSignal(event);
6667
return;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright © 2022 Université de Genève, LMU Munich - Faculty of Physics, IAP-CNRS/Sorbonne Université
3+
*
4+
* This library is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU Lesser General Public License as published by the Free
6+
* Software Foundation; either version 3.0 of the License, or (at your option)
7+
* any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12+
* details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this library; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "SEPythonModule/PipelineReceiver.h"
20+
21+
namespace se = SourceXtractor;
22+
23+
namespace SourceXPy {
24+
25+
std::string ProcessSourcesEventRepr(const se::ProcessSourcesEvent& event) {
26+
auto& ptr = event.m_selection_criteria;
27+
if (std::dynamic_pointer_cast<se::SelectAllCriteria>(ptr)) {
28+
return "SelectAllCriteria";
29+
} else if (std::dynamic_pointer_cast<AllFramesDone>(ptr)) {
30+
return "AllFramesDone";
31+
}
32+
return "LineSelectionCriteria";
33+
}
34+
35+
bool AllFramesDone::mustBeProcessed(const se::SourceInterface&) const {
36+
return true;
37+
}
38+
39+
se::ProcessSourcesEvent AllFramesDone::create() {
40+
return se::ProcessSourcesEvent{std::make_shared<AllFramesDone>()};
41+
}
42+
43+
} // namespace SourceXPy

SEPythonModule/src/lib/SePyMain.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
using namespace SourceXPy;
3838
namespace py = boost::python;
3939
namespace np = boost::python::numpy;
40+
namespace se = SourceXtractor;
4041

4142
namespace {
4243

@@ -129,7 +130,9 @@ BOOST_PYTHON_MODULE(_SEPythonModule) {
129130

130131
py::class_<AttachedSource, boost::noncopyable>("Source", py::no_init)
131132
.def("__getattr__", &AttachedSource::attribute)
132-
.def("detach", &AttachedSource::detach);
133+
.def("detach", &AttachedSource::detach)
134+
.def("create", &OwnedSource::create, py::args("context", "detection_frame", "detection_id", "pixel_coordinates"))
135+
.staticmethod("create");
133136
py::register_ptr_to_python<std::shared_ptr<AttachedSource>>();
134137

135138
py::class_<OwnedSource, py::bases<AttachedSource>, boost::noncopyable>("OwnedSource", py::no_init)
@@ -150,7 +153,7 @@ BOOST_PYTHON_MODULE(_SEPythonModule) {
150153
.def("__iter__", &SourceGroup::iter);
151154
py::register_ptr_to_python<std::shared_ptr<SourceGroup>>();
152155

153-
py::class_<ProcessSourcesEvent>("ProcessSourcesEvent", py::no_init).def("__repr__", &ProcessSourcesEvent::repr);
156+
py::class_<se::ProcessSourcesEvent>("ProcessSourcesEvent", py::no_init).def("__repr__", &ProcessSourcesEventRepr);
154157

155158
py::class_<SourceReceiverIfce, boost::noncopyable>("SourceReceiver", py::no_init);
156159
py::class_<GroupReceiverIfce, boost::noncopyable>("GroupReceiverIfce", py::no_init);
@@ -196,6 +199,10 @@ BOOST_PYTHON_MODULE(_SEPythonModule) {
196199
.def("__call__", &FitsOutput::call)
197200
.def("get", &FitsOutput::get, (py::arg("timeout") = std::chrono::microseconds::max()));
198201

202+
// For custom segmentation
203+
py::def("AllFramesDone", &AllFramesDone::create);
204+
205+
// Import pyston into the interpreter so it is importable without tweaking PYTHONPATH
199206
#if PY_MAJOR_VERSION >= 3
200207
PyObject* pyston = PyInit_pyston();
201208
#else

0 commit comments

Comments
 (0)