Commit 7472854e authored by Mike Kremer's avatar Mike Kremer
Browse files

Changed loadObject function such that the user can now specify whether to...

Changed loadObject function such that the user can now specify whether to auto-detect, ask or always load the mesh as poly/tri-mesh.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7955 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 996def69
......@@ -92,99 +92,59 @@ DataType FileOFFPlugin::supportedType() {
int FileOFFPlugin::loadObject(QString _filename) {
int id = -1;
emit addEmptyObject(DATA_POLY_MESH, id);
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 (loadVertexColor_->isChecked())
opt += OpenMesh::IO::Options::VertexColor;
if (loadFaceColor_->isChecked())
opt += OpenMesh::IO::Options::FaceColor;
// ColorAlpha is only checked if loading binary off's
if (loadAlpha_->isChecked())
opt += OpenMesh::IO::Options::ColorAlpha;
if (loadNormals_->isChecked())
opt += OpenMesh::IO::Options::VertexNormal;
if (loadTexCoords_->isChecked())
opt += OpenMesh::IO::Options::VertexTexCoord;
} else {
// Let openmesh try to read everything it can
opt += OpenMesh::IO::Options::VertexColor;
opt += OpenMesh::IO::Options::FaceColor;
opt += OpenMesh::IO::Options::VertexNormal;
opt += OpenMesh::IO::Options::VertexTexCoord;
}
// load file
bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
if (!ok)
{
std::cerr << "Plugin FileOFF : Read error for Poly Mesh\n";
emit deleteObject( object->id() );
return -1;
} else {
int triMeshControl = 1; // 1 == keep polyMesh .. do nothing
int triMeshControl = 0; // 0 == Auto-Detect
if ( OpenFlipper::Options::gui() ){
if ( triMeshHandling_ != 0 ){
triMeshControl = triMeshHandling_->currentIndex();
} else
} else {
triMeshControl = 0;
}
}
//check if it's actually a triangle mesh
if (triMeshControl != 1){ // 1 == do nothing
int objectId = -1;
PolyMesh& mesh = *( object->mesh() );
if(triMeshControl == 0) {
// If Auto-Detect is selected (triMeshControl == 0)
objectId = loadPolyMeshObject(_filename);
bool isTriangleMesh = true;
PolyMeshObject *object = 0;
if(!PluginFunctions::getObject(objectId, object))
return -1;
for ( PolyMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end() ; ++f_it) {
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( mesh,f_it); fv_it; ++fv_it )
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 ) {
isTriangleMesh = false;
break;
return objectId;
}
}
// 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 )
} else if (triMeshControl == 1) {
// If Ask is selected -> show dialog
objectId = loadPolyMeshObject(_filename);
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) {
if ( triMeshControl == 0){ //ask what to do
// 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;
}
}
QMessageBox::StandardButton result = QMessageBox::question ( 0,
tr("TriMesh loaded as PolyMesh"),
......@@ -193,36 +153,23 @@ int FileOFFPlugin::loadObject(QString _filename) {
QMessageBox::Yes );
// User decided to reload as triangle mesh
if ( result == QMessageBox::No )
isTriangleMesh = false;
if ( result == QMessageBox::No ) {
return objectId;
}
if ( isTriangleMesh ){
std::cerr << "Plugin FileOFF : Reloading mesh as Triangle Mesh\n";
} else if (triMeshControl == 2) {
// If always open as PolyMesh is selected
emit deleteObject( object->id() );
return loadPolyMeshObject(_filename);
} else {
// If always open as TriMesh is selected
return loadTriMeshObject(_filename);
}
}
}
object->mesh()->update_normals();
object->update();
object->show();
emit log(LOGINFO,object->getObjectinfo());
emit openedFile( object->id() );
return object->id();
} else {
emit log(LOGERR,"Error : Could not create new poly mesh object.");
return -1;
}
// Load object as triangle mesh
if(objectId != -1) emit deleteObject(objectId);
return loadTriMeshObject(_filename);
};
//-----------------------------------------------------------------------------------------------------
......@@ -516,16 +463,11 @@ QWidget* FileOFFPlugin::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_);
......
Markdown is supported
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