added selection of editable region

This commit is contained in:
Fabio Ganovelli ganovelli 2010-07-23 14:49:28 +00:00
parent fcef4c55dd
commit cece2d2e3e
7 changed files with 121 additions and 37 deletions

View File

@ -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<unsigned char> lockedV =
vcg::tri::Allocator<CMeshO>:: GetPerVertexAttribute<unsigned char> (mm->cm,"ocme_locked");
CMeshO:: PerFaceAttributeHandle<unsigned char> lockedF =
vcg::tri::Allocator<CMeshO>:: GetPerFaceAttribute<unsigned char> (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<CMeshO>::PerVertexPerFace ( mm->cm );
CMeshO:: PerFaceAttributeHandle<GIndex> gposf =
vcg::tri::Allocator<CMeshO>:: GetPerFaceAttribute<GIndex> (mm->cm,"ocme_gindex");
CMeshO:: PerVertexAttributeHandle<unsigned char> lockedV =
vcg::tri::Allocator<CMeshO>:: GetPerVertexAttribute<unsigned char> (mm->cm,"ocme_locked");
CMeshO:: PerFaceAttributeHandle<unsigned char> lockedF =
vcg::tri::Allocator<CMeshO>:: GetPerFaceAttribute<unsigned char> (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<GIndex> gposf =
// vcg::tri::Allocator<CMeshO>:: GetPerFaceAttribute<GIndex> (mm->cm,"ocme_gindex");
//
// CMeshO:: PerVertexAttributeHandle<unsigned char> lockedV =
// vcg::tri::Allocator<CMeshO>:: GetPerVertexAttribute<unsigned char> (mm->cm,"ocme_locked");
//
// CMeshO:: PerFaceAttributeHandle<unsigned char> lockedF =
// vcg::tri::Allocator<CMeshO>:: GetPerFaceAttribute<unsigned char> (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();

View File

@ -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

View File

@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>398</height>
<height>431</height>
</rect>
</property>
<property name="sizePolicy">
@ -173,7 +173,7 @@
<property name="geometry">
<rect>
<x>250</x>
<y>340</y>
<y>380</y>
<width>131</width>
<height>27</height>
</rect>
@ -186,7 +186,7 @@
<property name="geometry">
<rect>
<x>150</x>
<y>340</y>
<y>380</y>
<width>93</width>
<height>27</height>
</rect>
@ -199,7 +199,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>340</y>
<y>380</y>
<width>151</width>
<height>27</height>
</rect>
@ -214,7 +214,7 @@
<x>190</x>
<y>220</y>
<width>160</width>
<height>61</height>
<height>128</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -225,10 +225,24 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dropSelectionPushButton">
<property name="text">
<string>Drop ROI</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editPushButton">
<property name="text">
<string>Edit Selected</string>
<string>Edit ROI</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="markEditablePushButton">
<property name="text">
<string>Select Editable</string>
</property>
</widget>
</item>

View File

@ -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));
}

View File

@ -465,6 +465,8 @@ struct OCME{
template <class MeshType>
void Edit( std::vector<Cell*> & cells, MeshType & m, AttributeMapper attr_map = AttributeMapper());
// Undo edit
void DropEdited();
// find the removed elements
template <class MeshType>

View File

@ -332,6 +332,7 @@ void OCME::Extract( std::vector<Cell*> & sel_cells, MeshType & m, AttributeMap
}
}
template <class MeshType>
void OCME::Edit( std::vector<Cell*> & sel_cells, MeshType & m, AttributeMapper attrMap){
std::vector<Cell*> dep_cells,to_add;

View File

@ -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 );