diff --git a/src/meshlabplugins/edit_ocme/edit_ocme.cpp b/src/meshlabplugins/edit_ocme/edit_ocme.cpp index 5b253e840..f621e8f57 100755 --- a/src/meshlabplugins/edit_ocme/edit_ocme.cpp +++ b/src/meshlabplugins/edit_ocme/edit_ocme.cpp @@ -105,6 +105,28 @@ vcg::Box3f GetViewVolumeBBox() } +void OcmeEditPlugin::DrawCellsToEdit( ){ + + // render all the cells only on the stencil buffer + glColorMask(false,false,false,false); + for(unsigned int i = 0; i < cells_to_edit.size(); ++i) + DrawCellSel(cells_to_edit[i]->key,1); + glColorMask(true,true,true,true); + + glDepthFunc(GL_EQUAL); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glDisable(GL_LIGHTING); + glColor4b(0,0,0,127); + for(unsigned int i = 0; i < cells_to_edit.size(); ++i) + DrawCellSel(cells_to_edit[i]->key,1); + + glEnable(GL_LIGHTING); + glDisable(GL_BLEND); + glDepthFunc(GL_LESS); + +} + void OcmeEditPlugin::Decorate(MeshModel &, GLArea * gla) { rendering.lock(); @@ -193,13 +215,15 @@ void OcmeEditPlugin::Decorate(MeshModel &, GLArea * gla) if ( vcg::Pick ( pickx, gla->height()-picky, all_keys,results, DrawCell /*DrawImpostor*/) ) { CellKey cellkey = *results[0]; - cells_to_edit.push_back(ocme->GetCell(cellkey)); + Cell *c = ocme->GetCell(cellkey,false); + cells_to_edit.push_back(c); } } - // draw the cells selected as sphere - for(unsigned int i = 0; i < cells_to_edit.size(); ++i) - DrawCellSel(cells_to_edit[i]->key,2); + DrawCellsToEdit(); +// // draw the cells selected as sphere +// for(unsigned int i = 0; i < cells_to_edit.size(); ++i) +// DrawCellSel(cells_to_edit[i]->key,1); if(isDragging) DrawXORRect(gla); @@ -243,6 +267,7 @@ void OcmeEditPlugin::updateButtonsState(){ odw->loadOcmPushButton->setEnabled(!ocme_loaded); odw->createOcmPushButton->setEnabled(!ocme_loaded); + //odw->markEditablePushButton->setEnabled(!mm->cm.face.empty()); } bool OcmeEditPlugin::StartEdit(MeshModel &/*m*/, GLArea *_gla ) @@ -265,6 +290,8 @@ bool OcmeEditPlugin::StartEdit(MeshModel &/*m*/, GLArea *_gla ) QObject::connect(odw->createOcmPushButton,SIGNAL(clicked()),this,SLOT(createOcm())); QObject::connect(odw->closeOcmPushButton,SIGNAL(clicked()),this,SLOT(closeOcm())); QObject::connect(odw->editPushButton,SIGNAL(clicked()),this,SLOT(edit())); + QObject::connect(odw->markEditablePushButton ,SIGNAL(clicked() ),this,SLOT( markEditable() )); + QObject::connect(odw->dropSelectionPushButton,SIGNAL(clicked()),this,SLOT(drop())); QObject::connect(odw->commitPushButton,SIGNAL(clicked()),this,SLOT(commit())); QObject::connect(odw->addPushButton,SIGNAL(clicked()),this,SLOT(add())); QObject::connect(odw->fillAttrMeshPushButton ,SIGNAL(clicked() ),this,SLOT( fillMeshAttribute())); @@ -472,6 +499,33 @@ void OcmeEditPlugin::createOcm(){ } } +void OcmeEditPlugin::drop(){ + ocme->renderCache.controller.pause(); + mm->cm.Clear(); + cells_to_edit.clear(); + ocme->DropEdited(); + ocme->renderCache.controller.resume(); +} + +void OcmeEditPlugin::markEditable(){ + CMeshO:: PerVertexAttributeHandle lockedV = + vcg::tri::Allocator:: GetPerVertexAttribute (mm->cm,"ocme_locked"); + + CMeshO:: PerFaceAttributeHandle lockedF = + vcg::tri::Allocator:: GetPerFaceAttribute (mm->cm,"ocme_locked"); + + for(CMeshO::VertexIterator vi = mm->cm.vert.begin(); vi != mm->cm.vert.end(); ++vi ) + if(!(*vi).IsD()) + if(!lockedV[*vi]) (*vi).SetS(); + + for(CMeshO::FaceIterator fi = mm->cm.face.begin(); fi != mm->cm.face.end(); ++fi ) + if(!(*fi).IsD()){ + bool ed = !lockedF[*fi]; + for(unsigned int i = 0; i < (*fi).VN() ; ++i) + ed = ed && !lockedV[(*fi).V(i)]; + if(ed) (*fi).SetS(); + } +} void OcmeEditPlugin::edit(){ @@ -513,29 +567,29 @@ void OcmeEditPlugin::edit(){ cells_to_edit.clear(); vcg::tri::UpdateNormals::PerVertexPerFace ( mm->cm ); - - CMeshO:: PerFaceAttributeHandle gposf = - vcg::tri::Allocator:: GetPerFaceAttribute (mm->cm,"ocme_gindex"); - - CMeshO:: PerVertexAttributeHandle lockedV = - vcg::tri::Allocator:: GetPerVertexAttribute (mm->cm,"ocme_locked"); - - CMeshO:: PerFaceAttributeHandle lockedF = - vcg::tri::Allocator:: GetPerFaceAttribute (mm->cm,"ocme_locked"); - - - for(unsigned int i = 0; i < mm->cm.face.size();++i) - if(!mm->cm.face[i].IsD()) - if( lockedF[i] ) { - for(unsigned int fi = 0; fi < 3; ++ fi ){ - lockedV[mm->cm.face[i].V(fi)] = 1; - mm->cm.face[i].V(fi)->SetS(); - } - mm->cm.face[i].SetS(); - } - - for(unsigned int i = 0; i < mm->cm.vert.size();++i) - if( lockedV[i] ) mm->cm.vert[i].SetS(); +// +// CMeshO:: PerFaceAttributeHandle gposf = +// vcg::tri::Allocator:: GetPerFaceAttribute (mm->cm,"ocme_gindex"); +// +// CMeshO:: PerVertexAttributeHandle lockedV = +// vcg::tri::Allocator:: GetPerVertexAttribute (mm->cm,"ocme_locked"); +// +// CMeshO:: PerFaceAttributeHandle lockedF = +// vcg::tri::Allocator:: GetPerFaceAttribute (mm->cm,"ocme_locked"); +// +// +// for(unsigned int i = 0; i < mm->cm.face.size();++i) +// if(!mm->cm.face[i].IsD()) +// if( lockedF[i] ) { +// for(unsigned int fi = 0; fi < 3; ++ fi ){ +// lockedV[mm->cm.face[i].V(fi)] = 1; +// mm->cm.face[i].V(fi)->SetS(); +// } +// mm->cm.face[i].SetS(); +// } +// +// for(unsigned int i = 0; i < mm->cm.vert.size();++i) +// if( lockedV[i] ) mm->cm.vert[i].SetS(); diff --git a/src/meshlabplugins/edit_ocme/edit_ocme.h b/src/meshlabplugins/edit_ocme/edit_ocme.h index b4c8ceec1..1e13377c3 100755 --- a/src/meshlabplugins/edit_ocme/edit_ocme.h +++ b/src/meshlabplugins/edit_ocme/edit_ocme.h @@ -48,6 +48,7 @@ public: virtual bool StartEdit(MeshModel &/*m*/, GLArea * /*parent*/); virtual void EndEdit(MeshModel &/*m*/, GLArea * /*parent*/); + virtual void Decorate(MeshModel &/*m*/, GLArea * /*parent*/); virtual void mousePressEvent(QMouseEvent *, MeshModel &, GLArea * ) ; virtual void mouseMoveEvent(QMouseEvent *, MeshModel &, GLArea * ) ; @@ -99,11 +100,14 @@ public: vcg::Trackball curr_track; void suspendEditMode(); +void DrawCellsToEdit(); public slots: void loadOcm(); // load an ocm database void closeOcm(); // close an ocm database void createOcm(); // create an ocm database void edit(); // edit current selection + void markEditable(); // mark as selected (flag S) the editable element on the editing mesh + void drop(); // drop current selection void commit(); // commit void add(); // add new mesh void addFromDisk(); // add from disk diff --git a/src/meshlabplugins/edit_ocme/ocme.ui b/src/meshlabplugins/edit_ocme/ocme.ui index dd74d6baf..555ab9625 100755 --- a/src/meshlabplugins/edit_ocme/ocme.ui +++ b/src/meshlabplugins/edit_ocme/ocme.ui @@ -10,7 +10,7 @@ 0 0 400 - 398 + 431 @@ -173,7 +173,7 @@ 250 - 340 + 380 131 27 @@ -186,7 +186,7 @@ 150 - 340 + 380 93 27 @@ -199,7 +199,7 @@ 0 - 340 + 380 151 27 @@ -214,7 +214,7 @@ 190 220 160 - 61 + 128 @@ -225,10 +225,24 @@ + + + + Drop ROI + + + - Edit Selected + Edit ROI + + + + + + + Select Editable diff --git a/src/meshlabplugins/edit_ocme/src/ocme/ocme.cpp b/src/meshlabplugins/edit_ocme/src/ocme/ocme.cpp index b8f1c693c..8f5ab0ca0 100755 --- a/src/meshlabplugins/edit_ocme/src/ocme/ocme.cpp +++ b/src/meshlabplugins/edit_ocme/src/ocme/ocme.cpp @@ -177,6 +177,9 @@ void OCME::MarkTouchedAdded(const CellKey & key ){ added_cells.push_back(key); } +void OCME::DropEdited( ){ + ++generic_bool; // mark cells taken for editing +} int OCME::ComputeLevel(const float & l){ return (int)( std::log(((float)this->params.side_factor) * float(l) ) / log(2.f)); } diff --git a/src/meshlabplugins/edit_ocme/src/ocme/ocme_definition.h b/src/meshlabplugins/edit_ocme/src/ocme/ocme_definition.h index bcf354932..99b54cae9 100755 --- a/src/meshlabplugins/edit_ocme/src/ocme/ocme_definition.h +++ b/src/meshlabplugins/edit_ocme/src/ocme/ocme_definition.h @@ -465,6 +465,8 @@ struct OCME{ template void Edit( std::vector & cells, MeshType & m, AttributeMapper attr_map = AttributeMapper()); + // Undo edit + void DropEdited(); // find the removed elements template diff --git a/src/meshlabplugins/edit_ocme/src/ocme/ocme_extract.h b/src/meshlabplugins/edit_ocme/src/ocme/ocme_extract.h index 7e4f5a861..f26f2a9f8 100755 --- a/src/meshlabplugins/edit_ocme/src/ocme/ocme_extract.h +++ b/src/meshlabplugins/edit_ocme/src/ocme/ocme_extract.h @@ -332,6 +332,7 @@ void OCME::Extract( std::vector & sel_cells, MeshType & m, AttributeMap } } + template void OCME::Edit( std::vector & sel_cells, MeshType & m, AttributeMapper attrMap){ std::vector dep_cells,to_add; diff --git a/src/meshlabplugins/edit_ocme/src/ocme/ocme_render.cpp b/src/meshlabplugins/edit_ocme/src/ocme/ocme_render.cpp index 829e17b85..de17fddf3 100755 --- a/src/meshlabplugins/edit_ocme/src/ocme/ocme_render.cpp +++ b/src/meshlabplugins/edit_ocme/src/ocme/ocme_render.cpp @@ -24,9 +24,14 @@ void DrawCellSel ( CellKey & ck, int mode = 0 ) ubox.min=vcg::Point3f ( -0.5,-0.5,-0.5 ); ubox.max=-ubox.min; + vcg::Color4b c; - c = c.Scatter ( 32,lev+16 ); - glColor ( c ); + if(mode=3) + c = vcg::Color4b(230,0,0,127); + else{ + c = c.Scatter ( 32,lev+16 ); + } + glColor( c ); glPushMatrix(); @@ -36,9 +41,10 @@ void DrawCellSel ( CellKey & ck, int mode = 0 ) glScalef ( stepf*0.1 ,stepf*0.1 ,stepf*0.1 ); vcg::glBoxFlat ( ubox ); break; - case 1: glTranslatef ( ( p[0]+ 0.5 ) *stepf, ( p[1]+ 0.5 ) *stepf, ( p[2]+ 0.5 ) *stepf ); + case 1:; + case 3: glTranslatef ( ( p[0]+ 0.5 ) *stepf, ( p[1]+ 0.5 ) *stepf, ( p[2]+ 0.5 ) *stepf ); glScalef ( stepf ,stepf ,stepf ); - vcg::glBoxWire ( ubox ); + vcg::glBoxFlat ( ubox ); break; case 2: glTranslatef ( ( p[0]+ 0.5 ) *stepf, ( p[1]+ 0.5 ) *stepf, ( p[2]+ 0.5 ) *stepf ); glScalef ( stepf*0.1 ,stepf*0.1 ,stepf*0.1 );