Commit ebbe9e89 authored by Jan Möbius's avatar Jan Möbius

Added FixMesh.

refs #364

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15710 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b7d290e5
This diff is collapsed.
/*===========================================================================*\
* *
* OpenMesh *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
* *
* OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenMesh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 653 $ *
* $Date: 2012-08-22 10:49:55 +0200 (Mi, 22 Aug 2012) $ *
* *
\*===========================================================================*/
#ifndef OPENMESH_MESHFIXING_HH
#define OPENMESH_MESHFIXING_HH
//=============================================================================
//
// CLASS MeshFixing
//
//=============================================================================
//== INCLUDES =================================================================
//== NAMESPACE ================================================================
//== CLASS DEFINITION =========================================================
/** \brief Compare two vectors
*
* If they are closer than a specified epsilon, we identify them as equal.
*
*/
class CompareVectors
{
public:
/// Constructor
CompareVectors(double _eps = FLT_MIN);
/// comparison operator
bool operator()( const ACG::Vec3d& _v0, const ACG::Vec3d& _v1 ) const;
private:
const double epsilon_;
};
/** \brief Fix a mesh
*
*/
template<class MeshT>
class MeshFixing {
public:
MeshFixing(MeshT& _mesh, double _epsilon );
bool fix();
private:
TriMesh& mesh_;
/** \brief Add a face to the fixing data
*
* Degenerated faces will already be discarded in this step
*
* @param _p0 Vertex 1
* @param _p1 Vertex 2
* @param _p2 Vertex 3
*/
void add_face(const ACG::Vec3d& _p0, const ACG::Vec3d& _p1, const ACG::Vec3d& _p2);
void fix_topology();
void fix_orientation();
int neighbor(unsigned int _f, unsigned int _v0, unsigned int _v1);
/// Internal vertex type
struct Vertex
{
Vertex(const ACG::Vec3d& _p) : p(_p) { };
ACG::Vec3d p;
/// This vector will contain a list of all faces incident to the current vertex
std::vector<unsigned int> faces;
};
/// Internal face type
struct Face
{
Face(int _i0, int _i1, int _i2) :
component(-1)
{
v[0] = _i0;
v[1] = _i1;
v[2] = _i2;
}
unsigned int v[3];
int component;
};
typedef std::map<ACG::Vec3d, int, CompareVectors> VertexMap;
typedef VertexMap::iterator MapIter;
std::vector<Vertex> vertices_;
std::vector<Face> faces_;
/** Add a vertex to the map
*
* @param _p New vertex
* @return Index of the vertex
*/
int add_vertex(const ACG::Vec3d& _p);
VertexMap vmap_;
};
#if defined(INCLUDE_TEMPLATES) && !defined(OPENMESH_MESHFIXING_CC)
#define OPENMESH_MESHFIXING_TEMPLATES
#include "MeshFixingT.cc"
#endif
#endif
This diff is collapsed.
......@@ -52,6 +52,7 @@
#include <MeshTools/MeshSelectionT.hh>
#include <ACG/Geometry/Algorithms.hh>
#include <Math_Tools/Math_Tools.hh>
#include "MeshFixingT.hh"
//-----------------------------------------------------------------------------
......@@ -88,7 +89,7 @@ initializePlugin()
//Face operations
connect(tool_->triangleAspectButton,SIGNAL(clicked()),this,SLOT(slotDetectTriangleAspect()));
connect(tool_->flipOrientation,SIGNAL(clicked()),this,SLOT(slotFlipOrientation()));
connect(tool_->fixMeshButton,SIGNAL(clicked()),this,SLOT(slotFixMesh()));
connect(tool_->fixTopologyButton,SIGNAL(clicked()),this,SLOT(slotFixTopology()));
//Normal operations
connect(tool_->computeNormals,SIGNAL(clicked()),this,SLOT(slotUpdateNormals()));
......@@ -96,6 +97,9 @@ initializePlugin()
connect(tool_->computeFaceNormals,SIGNAL(clicked()),this,SLOT(slotUpdateFaceNormals()));
connect(tool_->computeHalfedgeNormals,SIGNAL(clicked()),this,SLOT(slotUpdateHalfedgeNormals()));
// General Operations
connect(tool_->fixMeshButton,SIGNAL(clicked()),this,SLOT(slotFixMesh()));
toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"meshrepair-toolbox.png");
tool_->repairCollapseEButton->setIcon(*toolIcon_);
tool_->repairFlipEButton->setIcon(*toolIcon_);
......@@ -179,6 +183,18 @@ void MeshRepairPlugin::slotFlipOrientation(){
//-----------------------------------------------------------------------------
void MeshRepairPlugin::slotFixMesh() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType( DATA_TRIANGLE_MESH ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
fixMesh(o_it->id() , tool_->fixMeshBox->value() );
emit updateView();
}
//-----------------------------------------------------------------------------
void MeshRepairPlugin::slotUpdateVertexNormals() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
updateVertexNormals(o_it->id());
......@@ -258,7 +274,7 @@ void MeshRepairPlugin::slotSnapBoundary()
//-----------------------------------------------------------------------------
void MeshRepairPlugin::slotFixMesh()
void MeshRepairPlugin::slotFixTopology()
{
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH ) ); o_it != PluginFunctions::objectsEnd(); ++o_it)
fixTopology(o_it->id());
......@@ -293,6 +309,10 @@ void MeshRepairPlugin::pluginsInitialized() {
QStringList(tr("objectId")),
QStringList(tr("ID of an object")));
emit setSlotDescription("fixMesh(int,double)",tr("Fixes a mesh."),
QString(tr("objectId,distance")).split(","),
QString(tr("ID of an object;Vertices with distance lower than epsilon will be treated as one")).split(";"));
emit setSlotDescription("removeSelectedEdges(int)",tr("Remove the selected edges"),
QStringList(tr("objectId")),
QStringList(tr("ID of an object")));
......@@ -939,7 +959,31 @@ void MeshRepairPlugin::detectFlatValence3Vertices(int _objectId, double _angle)
}
void
MeshRepairPlugin::fixMesh(int _objectId, double _epsilon) {
// get the target mesh
TriMesh* triMesh = 0;
PluginFunctions::getMesh(_objectId,triMesh);
if (triMesh) {
MeshFixing<TriMesh> fixer(*triMesh,_epsilon);
if ( !fixer.fix() )
emit log(LOGERR, "Fixmesh encountered Problems! Object: " + QString::number(_objectId) + ".");
// Recompute normals
triMesh->update_normals();
emit updatedObject(_objectId, UPDATE_ALL);
emit createBackup(_objectId, "Fixed mesh", UPDATE_ALL);
emit scriptInfo( "fixMesh(" + QString::number(_objectId) + ", " + QString::number(_epsilon) + ")" );
} else
emit log( LOGERR,tr("Unsupported Object Type for mesh fixing!") );
}
//-----------------------------------------------------------------------------
......
......@@ -141,6 +141,9 @@ private slots:
/// Button slot
void slotFlipOrientation();
/// Button slot
void slotFixMesh();
/// Button slot
void slotUpdateVertexNormals();
......@@ -166,7 +169,7 @@ private slots:
void slotSnapBoundary();
/// Button slot
void slotFixMesh();
void slotFixTopology();
//Scripting functions:
public slots:
......@@ -201,6 +204,9 @@ public slots:
/// Flips the normals of all faces by changing the vertex order
void flipOrientation(int _objectId);
/// Fix a mesh
void fixMesh(int _objectId, double _epsilon);
/// Selects all edges of an object which are shorter than the given length
void selectEdgesShorterThan(int _objectId,double _length);
......
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