From 7bfab225b6bfcab9aa14a74d6e3a9ddb80a0c5b4 Mon Sep 17 00:00:00 2001 From: Edward Vigmond <edward.vigmond@u-bordeaux.fr> Date: Thu, 29 Oct 2020 14:41:06 +0100 Subject: [PATCH] Fixed output of visible points --- src/DrawingObjects.h | 13 +++++------ src/Point.cc | 13 +++-------- src/TBmeshWin.cc | 52 ++++++++++++++++++++------------------------ src/TBmeshWin.h | 3 +-- src/trimesh.fl | 11 ++++++---- 5 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/DrawingObjects.h b/src/DrawingObjects.h index 87844bc..b2b33c7 100644 --- a/src/DrawingObjects.h +++ b/src/DrawingObjects.h @@ -74,11 +74,11 @@ class PPoint: public DrawingObj #endif const GLfloat* pt( int p=0 ){ return _pts+p*3; } const GLfloat* pt( int p ) const { return _pts+p*3; } - void setVis( bool v ){ if (v) _visible=&_allvis; } - void setVis( vector<bool>* v ){ _visible=v; } - bool vis( int n ) const { return (*_visible)[n]; } - void vis( int n, bool b ) const { (*_visible)[n]=b; } - const vector<bool>* vis() const { return _visible; } + void setVis( bool v ){ _visible.assign(_visible.size(), v ); } + void setVis( vector<bool>& v ){ _visible=v; } + bool vis( int n ) const { return _visible[n]; } + void vis( int n, bool b ) { _visible[n]=b; } + const vector<bool>* vis() const { return &_visible; } const GLfloat* offset() const { return _offset; } void offset( const GLfloat*o ) { memcpy(_offset,o,sizeof(GLfloat)*3); } void base1(bool b){ _base1 = b; } @@ -93,10 +93,9 @@ class PPoint: public DrawingObj void clear(){_n=0;free(_pts);_pts=NULL;} private: GLfloat* _pts=NULL; //!< point list - vector<bool>*_visible=NULL; //!< points which get drawn + vector<bool>_visible; //!< points which get drawn GLfloat _offset[3]; //!< centering offset bool _base1=false; //!< true for base 1 - vector<bool>_allvis; //!< all true int _maxtm; //!< maximum time int _tm=-1; //!< current time GLfloat _min[3]={0,0,0}, diff --git a/src/Point.cc b/src/Point.cc index 1a869e2..53f798d 100644 --- a/src/Point.cc +++ b/src/Point.cc @@ -25,13 +25,13 @@ PPoint::buffer( RenderSpheres &rd, int p0, int p1, const GLfloat *defcol, Colour if ( p0>=_n || p1>=_n ) return 0; int nvis=0; - for( int i=p0; i<=p1; i++ ) if( (*_visible)[i] ) nvis++; + for( int i=p0; i<=p1; i++ ) if( _visible[i] ) nvis++; GLfloat *buff = rd.buff_append( nvis ); int current=0; #pragma omp parallel for for ( int i=p0; i<=p1; i+=stride ) - if ( (*_visible)[i] ) { + if ( _visible[i] ) { int buffent; #pragma omp critical buffent = current++; @@ -105,9 +105,6 @@ bool PPoint :: read( const char *fname ) gzclose(in); #endif - _allvis.resize( _n ); - _allvis.assign( _n, true ); - return true; } @@ -133,8 +130,6 @@ bool PPoint :: read(hid_t hdf_file) } for (int i = 0; i < 3; i++) _offset[i] = (_min[i]+_max[i])/2; - _allvis.resize(info.count); - _allvis.assign(info.count, true ); return true; } @@ -162,9 +157,7 @@ PPoint :: add( const GLfloat *p, int n ) } for (int i = 0; i < 3; i++) _offset[i] = (_min[i]+_max[i])/2; - _allvis.resize( _n ); - _allvis.assign( _n, true ); - _visible = &_allvis; + _visible.resize(_n); setVis( true ); } diff --git a/src/TBmeshWin.cc b/src/TBmeshWin.cc index 9fff441..83ec769 100644 --- a/src/TBmeshWin.cc +++ b/src/TBmeshWin.cc @@ -276,7 +276,7 @@ void TBmeshWin :: draw() RRegion *reg = model->region(revDrawOrder ? model->_numReg-s-1 : s); - model->pt.setVis(®->pt_membership()); + model->pt.setVis(reg->pt_membership()); if ( reg->show(Cnnx) && model->_cnnx->num() ) draw_cnnx(reg); @@ -328,7 +328,7 @@ TBmeshWin::draw_vol_mesh() for ( int r=0; r<model->_numReg; r++ ) { if ( !model->region(r)->visible() ) continue; - model->pt.setVis(&model->region(r)->pt_membership()); + model->pt.setVis(model->region(r)->pt_membership()); #pragma omp parallel for for( int i=0; i<model->numVol(); i++ ) { @@ -578,7 +578,7 @@ void TBmeshWin::draw_vertices(RRegion* reg, bool last ) bool update = _rd_pt.setup_render_data(context()) || REDRAW(VBO_Pt_Color|VBO_Position|VBO_Visible) || REDRAW(VBO_Colour) && datadst&Vertex_flg || - REDRAW(VBO_Pt)&&threeD(Vertex) ; + REDRAW(VBO_Pt) ; if( last ) { if( !first && _rd_pt.num() && update ){ @@ -661,7 +661,7 @@ TBmeshWin:: trim_vertices( vector<bool>& visvert, bool draw_cnnx ) for( auto sn : snodes ) visvert[sn] = model->pt.vis(sn); } - model->pt.setVis( &visvert ); + model->pt.setVis( visvert ); } @@ -981,8 +981,6 @@ int TBmeshWin::handle( int event ) */ void TBmeshWin::set_windows( Fl_Window *flwindow, const char *modname ) { - ptDrawn.resize(model->pt.num()); - flwin = flwindow; flwintitle = modname; flwin->label( flwintitle.c_str() ); @@ -1551,7 +1549,6 @@ int TBmeshWin::max_time( GridType ignore ) void TBmeshWin:: select_vertex() { - ptDrawn.assign(model->pt.num(),false); // clear list of drawn vertices renderMode = GL_SELECT; } @@ -1600,28 +1597,30 @@ TBmeshWin::process_hits( Frame &frame ) * . \n * visible_node? */ -void TBmeshWin::dump_vertices() +void TBmeshWin::dump_vertices(const char *fname) { + vector<bool> ptDrawn(model->pt.num(), false ); - ptDrawn.assign(model->pt.num(),false); // clear list of drawn vertices - for( int i=0; i<model->_numReg; i++ ) { - RRegion *r = model->region(i); - if( !r->visible() ) continue; - for( int p=0; p<model->pt.num(); p++ ) - if( r->pt_member(p) ) ptDrawn[p] = true; - } + for ( int s=0; s<model->_numReg; s++ ) { + + RRegion *reg = model->region(s); + if( !reg->show(Vertex) || !reg->visible()) return; - for( int p=0; p<model->pt.num(); p++ ) - if( ptDrawn[p] ) - for( int i=0; i<NUM_CP; i++ ) - if( clipping(i) ) - if( dot(CLIP_EQN[i], model->pt[p])-CLIP_EQN[i][3]<0 ){ - ptDrawn[p] = false; + model->pt.setVis(reg->pt_membership()); + vector<bool> draw_vert; + if( !_draw_all_vert ) trim_vertices( draw_vert, reg->show(Cnnx) ); + + for( int p=0; p<model->pt.num(); p++ ) + if( model->pt.vis(p) ) { + for( int i=0; i<NUM_CP; i++ ) + if( clipping(i) && dot(CLIP_EQN[i],model->pt[p])+CLIP_EQN[i][3]<0 ){ + model->pt.vis(p, false); break; } + ptDrawn[p] = ptDrawn[p] || model->pt.vis(p); + } + } - char *fname=fl_file_chooser( "Choose vertex file", "*", "vertices.dat" ); - if ( fname == NULL ) return; ofstream of( fname ); //output the clipping planes @@ -1643,12 +1642,9 @@ void TBmeshWin::dump_vertices() } // output the vertices - int vtx_on=0; - for ( int i=0; i<model->pt.num(); i++ ) - if ( ptDrawn[i] ) - vtx_on++; + int vtx_on=count( ptDrawn.begin(), ptDrawn.end(), true ); of << vtx_on << endl; - for ( int i=0; i<model->pt.num(); i++ ) if ( ptDrawn[i] ) of<< i << endl; + for ( int i=0; i<model->pt.num(); i++ ) if ( ptDrawn[i] ) of << i << endl; of.close(); } diff --git a/src/TBmeshWin.h b/src/TBmeshWin.h index 60d0616..ff66fb7 100644 --- a/src/TBmeshWin.h +++ b/src/TBmeshWin.h @@ -119,7 +119,7 @@ class TBmeshWin:public Fl_Gl_Tb_Window void timeplot(); bool recording = false; // true if recording events void record_events( char * ); // output the frame buffer after each change - void dump_vertices(); + void dump_vertices(const char *); void compute_normals(); void region_vis( int *, int, bool *); friend class Sequence; @@ -221,7 +221,6 @@ class TBmeshWin:public Fl_Gl_Tb_Window bool translucency( Object_t, GLfloat *, bool=false ); GLenum renderMode = GL_RENDER;// mode for drawing - vector<bool> ptDrawn; // was a point drawn vector<bool> ptVisible; // is a point is a visible region? void register_vertex( int i ); // for picking vector<GLuint> hitbuffer; diff --git a/src/trimesh.fl b/src/trimesh.fl index 2ae4b57..11c85cf 100644 --- a/src/trimesh.fl +++ b/src/trimesh.fl @@ -14,7 +14,7 @@ decl {\#include<list>} {public global decl {\#include <algorithm>} {private local } -decl {\#include<memory>} {private local +decl {\#include<memory>} {selected private local } decl {class TBmeshWin;} {public local @@ -119,7 +119,7 @@ class Controls {open } { Fl_Window window { label {Meshalyzer Controls} open - xywh {1323 82 350 705} type Double box UP_BOX + xywh {731 112 350 705} type Double box UP_BOX code0 {\#include <FL/Fl_Color_Chooser.H>} code1 {\#include "VecData.h"} visible } { @@ -704,7 +704,10 @@ mwtb->cs->output_png(fn);} } MenuItem {} { label {Visible vertices} - callback {mwtb->dump_vertices();} + callback {char *fname=fl_file_chooser( "Choose vertex file", "*", "vertices.dat" ); +if ( fname == NULL ) return; + +mwtb->dump_vertices(fname);} tooltip {output the indices of the visible vertices} xywh {0 0 100 20} } Submenu recordmenu { @@ -850,7 +853,7 @@ mwtb->showobj(Vertex,selreg.get(),static_cast<bool>(o->value())); if(o->value()) pickvert->activate(); else - pickvert->deactivate();} selected + pickvert->deactivate();} xywh {160 145 75 25} when 1 } Fl_Light_Button cnnxbut { -- GitLab