Commit ebd6ef21 authored by Mike Kremer's avatar Mike Kremer
Browse files

Updated handling of whether to load mesh as poly or trimesh.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8007 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9d2d6f0d
......@@ -92,138 +92,84 @@ DataType FileOMPlugin::supportedType() {
int FileOMPlugin::loadObject(QString _filename) {
int id = -1;
emit addEmptyObject(DATA_POLY_MESH, id);
int triMeshControl = 0; // 0 == Auto-Detect
PolyMeshObject* object(0);
if(PluginFunctions::getObject( id, object)) {
if (PluginFunctions::objectCount() == 1 )
object->target(true);
object->setFromFileName(_filename);
// call the local function to update names
QFileInfo f(_filename);
object->setName( f.fileName() );
std::string filename = std::string( _filename.toUtf8() );
//set options
OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
if ( !OpenFlipper::Options::loadingSettings() &&
!OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
if (loadVertexNormal_->isChecked())
opt += OpenMesh::IO::Options::VertexNormal;
if (loadVertexTexCoord_->isChecked())
opt += OpenMesh::IO::Options::VertexTexCoord;
if (loadVertexColor_->isChecked())
opt += OpenMesh::IO::Options::VertexColor;
if (loadFaceColor_->isChecked())
opt += OpenMesh::IO::Options::FaceColor;
if (loadFaceNormal_->isChecked())
opt += OpenMesh::IO::Options::FaceNormal;
if ( OpenFlipper::Options::gui() ){
if ( triMeshHandling_ != 0 ){
triMeshControl = triMeshHandling_->currentIndex();
} else {
// Let openmesh try to read everything it can
opt += OpenMesh::IO::Options::VertexNormal;
opt += OpenMesh::IO::Options::VertexTexCoord;
opt += OpenMesh::IO::Options::VertexColor;
opt += OpenMesh::IO::Options::FaceColor;
opt += OpenMesh::IO::Options::FaceNormal;
triMeshControl = 0;
}
}
int objectId = -1;
if(triMeshControl == 0) {
// If Auto-Detect is selected (triMeshControl == 0)
objectId = loadPolyMeshObject(_filename);
// load file
bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
if (!ok)
{
std::cerr << "Plugin FileOM : Read error for Poly Mesh\n";
emit deleteObject( object->id() );
PolyMeshObject *object = 0;
if(!PluginFunctions::getObject(objectId, object))
return -1;
for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
} else {
int triMeshControl = 1; // 1 == keep polyMesh .. do nothing
// Count number of vertices for the current face
uint count = 0;
for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),f_it); fv_it; ++fv_it )
++count;
if ( OpenFlipper::Options::gui() ){
if ( triMeshHandling_ != 0 ){
triMeshControl = triMeshHandling_->currentIndex();
} else
triMeshControl = 0;
}
//check if it's actually a triangle mesh
if (triMeshControl != 1){ // 1 == do nothing
PolyMesh& mesh = *( object->mesh() );
bool isTriangleMesh = true;
for ( PolyMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end() ; ++f_it) {
// Count number of vertices for the current face
uint count = 0;
for ( PolyMesh::FaceVertexIter fv_it( mesh,f_it); fv_it; ++fv_it )
++count;
// Check if it is a triangle. If not, this is really a poly mesh
if ( count != 3 ) {
isTriangleMesh = false;
break;
}
}
// Mesh loaded as polymesh is actually a triangle mesh. Ask the user to reload as triangle mesh or keep it as poly mesh.
if ( isTriangleMesh )
if ( triMeshControl == 0){ //ask what to do
QMessageBox::StandardButton result = QMessageBox::question ( 0,
tr("TriMesh loaded as PolyMesh"),
tr("You opened the mesh as a poly mesh but actually its a triangle mesh. \nShould it be opened as a triangle mesh?"),
(QMessageBox::Yes | QMessageBox::No ),
QMessageBox::Yes );
// User decided to reload as triangle mesh
if ( result == QMessageBox::No )
isTriangleMesh = false;
}
if ( isTriangleMesh ){
std::cerr << "Plugin FileOM : Reloading mesh as Triangle Mesh\n";
emit deleteObject( object->id() );
return loadTriMeshObject(_filename);
}
// Check if it is a triangle. If not, this is really a poly mesh
if ( count != 3 ) {
return objectId;
}
}
object->mesh()->update_normals();
} else if (triMeshControl == 1) {
// If Ask is selected -> show dialog
objectId = loadPolyMeshObject(_filename);
object->update();
object->show();
emit log(LOGINFO,object->getObjectinfo());
PolyMeshObject *object = 0;
if(!PluginFunctions::getObject(objectId, object))
return -1;
emit openedFile( object->id() );
for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
// Count number of vertices for the current face
uint count = 0;
for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),f_it); fv_it; ++fv_it )
++count;
// Check if it is a triangle. If not, this is really a poly mesh
if ( count != 3 ) {
return objectId;
}
}
return object->id();
QMessageBox::StandardButton result = QMessageBox::question ( 0,
tr("TriMesh loaded as PolyMesh"),
tr("You opened the mesh as a poly mesh but actually its a triangle mesh. \nShould it be opened as a triangle mesh?"),
(QMessageBox::Yes | QMessageBox::No ),
QMessageBox::Yes );
// User decided to reload as triangle mesh
if ( result == QMessageBox::No ) {
return objectId;
}
} else if (triMeshControl == 2) {
// If always open as PolyMesh is selected
return loadPolyMeshObject(_filename);
} else {
emit log(LOGERR,"Error : Could not create new poly mesh object.");
return -1;
// If always open as TriMesh is selected
return loadTriMeshObject(_filename);
}
// Load object as triangle mesh
if(objectId != -1) emit deleteObject(objectId);
return loadTriMeshObject(_filename);
};
//-----------------------------------------------------------------------------------------------------
......@@ -516,17 +462,12 @@ QWidget* FileOMPlugin::loadOptionsWidget(QString /*_currentFilter*/) {
QLabel* label = new QLabel(tr("If PolyMesh is a Triangle Mesh:"));
layout->addWidget(label);
/// \todo : possible options ?:
// Triangle Mesh in File -> Load as Triangle Mesh
// Triangle Mesh in File -> Load as Poly Mesh
// Poly Mesh in File -> Load as Triangle Mesh
// Poly Mesh in File -> Load as Poly Mesh
triMeshHandling_ = new QComboBox();
triMeshHandling_->addItem( tr("Auto-Detect") );
triMeshHandling_->addItem( tr("Ask") );
triMeshHandling_->addItem( tr("Open as PolyMesh") );
triMeshHandling_->addItem( tr("Open as TriangleMesh") );
triMeshHandling_->addItem( tr("Always open as PolyMesh") );
triMeshHandling_->addItem( tr("Always open as TriangleMesh") );
layout->addWidget(triMeshHandling_);
......
......@@ -92,134 +92,84 @@ DataType FilePLYPlugin::supportedType() {
int FilePLYPlugin::loadObject(QString _filename) {
int id = -1;
emit addEmptyObject(DATA_POLY_MESH, id);
int triMeshControl = 0; // 0 == Auto-Detect
PolyMeshObject* object(0);
if(PluginFunctions::getObject( id, object)) {
if (PluginFunctions::objectCount() == 1 )
object->target(true);
object->setFromFileName(_filename);
// call the local function to update names
QFileInfo f(_filename);
object->setName( f.fileName() );
std::string filename = std::string( _filename.toUtf8() );
//set options
OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
if ( !OpenFlipper::Options::loadingSettings() &&
!OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
if (loadVertexNormal_->isChecked())
opt += OpenMesh::IO::Options::VertexNormal;
if (loadVertexTexCoord_->isChecked())
opt += OpenMesh::IO::Options::VertexTexCoord;
if (loadVertexColor_->isChecked())
opt += OpenMesh::IO::Options::VertexColor;
if (loadFaceColor_->isChecked())
opt += OpenMesh::IO::Options::FaceColor;
if ( OpenFlipper::Options::gui() ){
if ( triMeshHandling_ != 0 ){
triMeshControl = triMeshHandling_->currentIndex();
} else {
// Let openmesh try to read everything it can
opt += OpenMesh::IO::Options::VertexNormal;
opt += OpenMesh::IO::Options::VertexTexCoord;
opt += OpenMesh::IO::Options::VertexColor;
opt += OpenMesh::IO::Options::FaceColor;
triMeshControl = 0;
}
}
int objectId = -1;
if(triMeshControl == 0) {
// If Auto-Detect is selected (triMeshControl == 0)
objectId = loadPolyMeshObject(_filename);
// load file
bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
if (!ok)
{
std::cerr << "Plugin FilePLY : Read error for Poly Mesh\n";
emit deleteObject( object->id() );
PolyMeshObject *object = 0;
if(!PluginFunctions::getObject(objectId, object))
return -1;
for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
} else {
int triMeshControl = 1; // 1 == keep polyMesh .. do nothing
// Count number of vertices for the current face
uint count = 0;
for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),f_it); fv_it; ++fv_it )
++count;
if ( OpenFlipper::Options::gui() ){
if ( triMeshHandling_ != 0 ){
triMeshControl = triMeshHandling_->currentIndex();
} else
triMeshControl = 0;
}
//check if it's actually a triangle mesh
if (triMeshControl != 1){ // 1 == do nothing
PolyMesh& mesh = *( object->mesh() );
bool isTriangleMesh = true;
for ( PolyMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end() ; ++f_it) {
// Count number of vertices for the current face
uint count = 0;
for ( PolyMesh::FaceVertexIter fv_it( mesh,f_it); fv_it; ++fv_it )
++count;
// Check if it is a triangle. If not, this is really a poly mesh
if ( count != 3 ) {
isTriangleMesh = false;
break;
}
}
// Mesh loaded as polymesh is actually a triangle mesh. Ask the user to reload as triangle mesh or keep it as poly mesh.
if ( isTriangleMesh )
if ( triMeshControl == 0){ //ask what to do
QMessageBox::StandardButton result = QMessageBox::question ( 0,
tr("TriMesh loaded as PolyMesh"),
tr("You opened the mesh as a poly mesh but actually its a triangle mesh. \nShould it be opened as a triangle mesh?"),
(QMessageBox::Yes | QMessageBox::No ),
QMessageBox::Yes );
// User decided to reload as triangle mesh
if ( result == QMessageBox::No )
isTriangleMesh = false;
}
if ( isTriangleMesh ){
std::cerr << "Plugin FilePLY : Reloading mesh as Triangle Mesh\n";
emit deleteObject( object->id() );
return loadTriMeshObject(_filename);
}
// Check if it is a triangle. If not, this is really a poly mesh
if ( count != 3 ) {
return objectId;
}
}
object->mesh()->update_normals();
object->update();
object->show();
} else if (triMeshControl == 1) {
// If Ask is selected -> show dialog
objectId = loadPolyMeshObject(_filename);
emit log(LOGINFO,object->getObjectinfo());
PolyMeshObject *object = 0;
if(!PluginFunctions::getObject(objectId, object))
return -1;
emit openedFile( object->id() );
for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
// Count number of vertices for the current face
uint count = 0;
for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),f_it); fv_it; ++fv_it )
++count;
// Check if it is a triangle. If not, this is really a poly mesh
if ( count != 3 ) {
return objectId;
}
}
return object->id();
QMessageBox::StandardButton result = QMessageBox::question ( 0,
tr("TriMesh loaded as PolyMesh"),
tr("You opened the mesh as a poly mesh but actually its a triangle mesh. \nShould it be opened as a triangle mesh?"),
(QMessageBox::Yes | QMessageBox::No ),
QMessageBox::Yes );
// User decided to reload as triangle mesh
if ( result == QMessageBox::No ) {
return objectId;
}
} else if (triMeshControl == 2) {
// If always open as PolyMesh is selected
return loadPolyMeshObject(_filename);
} else {
emit log(LOGERR,"Error : Could not create new poly mesh object.");
return -1;
// If always open as TriMesh is selected
return loadTriMeshObject(_filename);
}
// Load object as triangle mesh
if(objectId != -1) emit deleteObject(objectId);
return loadTriMeshObject(_filename);
};
//-----------------------------------------------------------------------------------------------------
......@@ -498,16 +448,11 @@ QWidget* FilePLYPlugin::loadOptionsWidget(QString /*_currentFilter*/) {
layout->addWidget(label);
/// \todo : possible options ?:
// Triangle Mesh in File -> Load as Triangle Mesh
// Triangle Mesh in File -> Load as Poly Mesh
// Poly Mesh in File -> Load as Triangle Mesh
// Poly Mesh in File -> Load as Poly Mesh
triMeshHandling_ = new QComboBox();
triMeshHandling_->addItem( tr("Auto-Detect") );
triMeshHandling_->addItem( tr("Ask") );
triMeshHandling_->addItem( tr("Open as PolyMesh") );
triMeshHandling_->addItem( tr("Open as TriangleMesh") );
triMeshHandling_->addItem( tr("Always open as PolyMesh") );
triMeshHandling_->addItem( tr("Always open as TriangleMesh") );
layout->addWidget(triMeshHandling_);
......
......@@ -70,7 +70,7 @@ int FileSTLPlugin::loadObject(QString _filename) {
bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename );
if (!ok)
{
std::cerr << "Plugin FileSTL : Read error for Poly Mesh\n";
std::cerr << "Plugin FileSTL : Read error for stl mesh.\n";
emit deleteObject( object->id() );
return -1;
......@@ -89,7 +89,7 @@ int FileSTLPlugin::loadObject(QString _filename) {
return object->id();
} else {
emit log(LOGERR,"Error : Could not create new poly mesh object.");
emit log(LOGERR,"Error : Could not create new triangle mesh object.");
return -1;
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment