From: Diane Trout Date: Sun, 5 Mar 2006 20:27:25 +0000 (+0000) Subject: record selected track X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=652d5805b67d4a32d9467e2b6f45f68ef4d3f334 record selected track Keep track of the lowest value selected track, so we know what to show when people try to bring up the sequence view. Also toss in some more Boost.Python code --- diff --git a/py/getm.py b/py/getm.py new file mode 100644 index 0000000..be5be65 --- /dev/null +++ b/py/getm.py @@ -0,0 +1,20 @@ +"""How many times does a large mussa analysis redraw the same line. +""" +import mussa +m = mussa.Mussa() +#m.load_mupa("examples/mck3test.mupa") +#m.analyze(0, 0, mussa.analysis_modes.TransitiveNway, 0) +m.load("../mussa_analyses/land/myogenin_w30_t21") +path = m.paths() + +count = 0 +tracks = {} +for rp in path.refinedPathz: + t0_id = rp.track_indexes[0] + t1_id = rp.track_indexes[1] + tid = (t0_id, t1_id) + tracks[tid] = tracks.setdefault(tid, 0) + 1 + count += 1 + +print "count", count +print "tracks", len(tracks.keys()) diff --git a/py/gl.py b/py/gl.py new file mode 100644 index 0000000..43d29f6 --- /dev/null +++ b/py/gl.py @@ -0,0 +1,18 @@ +"""Can we show a mussa gl object? +""" +from OpenGL.GLUT import * +from OpenGL.GL import * +import mussa + +def main(): + seq = mussa.Sequence() + s = "AAGGCCTTAAGGCCTT" + seq = mussa.Sequence(s) + assert s == seq.size() == len(seq) + glseq = mussa.GlSequence(seq) + + glutInit(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/py/glsequence.cxx b/py/glsequence.cxx new file mode 100644 index 0000000..3c9cd36 --- /dev/null +++ b/py/glsequence.cxx @@ -0,0 +1,18 @@ +#include +using namespace boost::python; + +#include "alg/glsequence.h" +#include "alg/sequence.hh" + +void export_glsequence() +{ + class_("GlSequence", init()) + .def(init()) + .def("draw", &GlSequence::draw) + .def("sequence", &GlSequence::sequence, + return_internal_reference<>()) + .add_property("x", &GlSequence::x, &GlSequence::setX) + .add_property("y", &GlSequence::y, &GlSequence::setY) + .add_property("width", &GlSequence::width, &GlSequence::setWidth) + ; +} diff --git a/py/module.cxx b/py/module.cxx index fbacede..1f6fd02 100644 --- a/py/module.cxx +++ b/py/module.cxx @@ -1,13 +1,17 @@ #include using namespace boost::python; +void export_conserved_path(); +void export_glsequence(); void export_mussa(); void export_nway_paths(); -void export_conserved_path(); +void export_sequence(); BOOST_PYTHON_MODULE(mussa) { + export_conserved_path(); + export_glsequence(); export_mussa(); export_nway_paths(); - export_conserved_path(); + export_sequence(); } diff --git a/py/module.mk b/py/module.mk index ba63363..b122d73 100644 --- a/py/module.mk +++ b/py/module.mk @@ -2,9 +2,10 @@ CURDIR := $(BASEDIR)py/ SOURCES.cxx := module.cxx \ conserved_path.cxx \ + glsequence.cxx \ mussa.cxx \ - nway_paths.cxx - + nway_paths.cxx \ + sequence.cxx MUSSA_PY_SRC := $(addprefix $(CURDIR), $(SOURCES.cxx)) MUSSA_PY_OBJ := $(MUSSA_PY_SRC:.cxx=$(OBJEXT)) @@ -15,5 +16,5 @@ CXXFLAGS += MUSSAPY := $(BASEDIR)/mussa.so TARGETBINS += $(MUSSAPY) -$(MUSSAPY): $(MUSSA_PY_OBJ) $(MUSSA_ALG_OBJ) - g++ -shared $(CXXFLAGS) -lpython2.3 -lboost_python -o $@ $^ +$(MUSSAPY): $(MUSSA_PY_OBJ) $(MUSSA_ALG_OBJ) $(MUSSA_ALG_GL_OBJ) + g++ -shared $(CXXFLAGS) -lGL -lpython2.3 -lboost_python -o $@ $^ diff --git a/py/sequence.cxx b/py/sequence.cxx new file mode 100644 index 0000000..39542fa --- /dev/null +++ b/py/sequence.cxx @@ -0,0 +1,16 @@ +#include +using namespace boost::python; + +#include +#include "alg/glsequence.h" + +void export_sequence() +{ + class_("Sequence") + .def(init()) + //.add_property("seq", &Sequence::get_seq, &Sequence::set_seq) + .def("size", &Sequence::size) + .def("__len__", &Sequence::size) + //.add_property("header", &Sequence::get_header) + ; +} diff --git a/qui/PathScene.cxx b/qui/PathScene.cxx index 3203e72..759014e 100644 --- a/qui/PathScene.cxx +++ b/qui/PathScene.cxx @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -23,7 +24,7 @@ PathScene::PathScene(Mussa* analysis, QWidget *parent) : zoom(0), maxOrtho2d(-50.0, -50, 3000000.0, 300.0), curOrtho2d(maxOrtho2d), - highlightMode(false), + selectedMode(false), rubberBand(0), drawingBand(false) { @@ -201,10 +202,11 @@ void PathScene::paintGL() mussaesque(); glEnable(GL_BLEND); glDepthMask(GL_FALSE); - if (highlightMode && !drawingBand) { + if (selectedMode && !drawingBand) { glColor4f(0.4, 0.4, 0.4, 0.9); glRectf(previousBand.x(), previousBand.y(), previousBand.right(), previousBand.bottom()); + cout << "x: " << previousBand.x() << " r:" << previousBand.right() << endl; } glDepthMask(GL_TRUE); glDisable(GL_BLEND); @@ -249,12 +251,15 @@ void PathScene::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize) GLuint objtype; GLuint objid; - highlightPaths.clear(); - highlightPaths.reserve(pathz_count); - highlightPaths.insert(highlightPaths.begin(), pathz_count, false); + selectedPaths.clear(); + selectedPaths.reserve(pathz_count); + selectedPaths.insert(selectedPaths.begin(), pathz_count, false); + selectedTrack = 0x7fffffff; std::cout << "hits = " << hits << " " << pathz_count << std::endl; ptr = (GLuint *) buffer; + if (hits > 0) + selectedMode = true; for (GLuint i=0; i < hits; ++i) { if ((i + 5) > bufsize) { @@ -265,8 +270,6 @@ void PathScene::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize) z2 = ((float)*ptr++)/0x7fffffff; objtype = *ptr++; objid = *ptr++; - //std::cout << " z1 is " << z1 << std::endl - // << " z2 is " << z2 << std::endl; if (names != 2) { std::clog << "wrong number of glNames, selection is having trouble "; std::clog << " got " << names << std::endl; @@ -277,16 +280,16 @@ void PathScene::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize) std::clog << endl; return; } - if (objtype == MussaPaths) { - highlightPaths[objid] = true; - // not sure i like this, but it means we'll only highlight if a - // selection was made - highlightMode = true; + switch (objtype) { + case MussaPaths: + selectedPaths[objid] = true; + break; + case MussaTracks: + if (objid < selectedTrack) { + selectedTrack = objid; + } + break; } - - //std::clog << ((objtype == MussaTracks) ? " track: " : " path: ") - // << objid - // << std::endl; } } } @@ -296,7 +299,7 @@ void PathScene::mousePressEvent( QMouseEvent *e) drawingBand = true; std::cout << "x=" << e->x() << " y=" << e->y() << std::endl; - highlightMode = false; + selectedMode = false; bandOrigin = e->pos(); if (!rubberBand) rubberBand = new QRubberBand(QRubberBand::Rectangle, this); @@ -434,7 +437,7 @@ void PathScene::draw_lines() const // the following boolean implements logical xor if ( (reversed || prevReversed) && (!reversed || !prevReversed)) { // we have a different orientation - if (not highlightMode or highlightPaths[objid] == true) { + if (not selectedMode or selectedPaths[objid] == true) { // if we have nothing selected, or we're the highlight, be bright glColor3f(0.0, 0.0, 1.0); } else { @@ -443,7 +446,7 @@ void PathScene::draw_lines() const } } else { // both current and previous path have the same orientation - if (not highlightMode or highlightPaths[objid] == true) { + if (not selectedMode or selectedPaths[objid] == true) { glColor3f(1.0, 0.0, 0.2); } else { glColor3f(1.0, 0.5, 0.5); diff --git a/qui/PathScene.h b/qui/PathScene.h index 64997d6..d836c19 100644 --- a/qui/PathScene.h +++ b/qui/PathScene.h @@ -49,8 +49,12 @@ protected: int zoom; QRectF maxOrtho2d; QRectF curOrtho2d; - bool highlightMode; - std::vector highlightPaths; + // true if we have a selection + bool selectedMode; + // indicate which paths are selected + std::vector selectedPaths; + // which track is selected (it only makes sense to have one track selected). + unsigned int selectedTrack; void initializeGL(); void resizeGL(int width, int height);