Commit 653b1b8f authored by Jan Möbius's avatar Jan Möbius

Added catmull clark subdivider. Thanks to Leon Kos for the code.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@609 fdac6126-5c0c-442c-9429-916003d36597
parent 330ec3d1
......@@ -2,6 +2,8 @@
/** \page subdivider_docu Sudivision Tools
\section Overview
The %OpenMesh library provides a few tools for uniform and adaptive
subdivision:
......@@ -11,11 +13,27 @@ subdivision:
-# OpenMesh::Subdivider::Uniform::ModifiedButterflyT
-# OpenMesh::Subdivider::Uniform::InterpolatingSqrt3LGT
-# OpenMesh::Subdivider::Uniform::CompositeT
-# OpenMesh::Subdivider::Uniform::CatmullClarkT
-# Adaptive subdivision
-# OpenMesh::Subdivider::Adaptive::CompositeT
-# Simple subdivision
-# OpenMesh::Subdivider::Uniform::LongestEdgeT
\section Usage
The subdividers directly work on an OpenMesh. The following example shows how to use them:
\code
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
// Initialize subdivider
OpenMesh::Subdivider::Uniform::CatmullClarkT<PolyMesh> catmull;
// Execute 3 subdivision steps
catmull.attach(mesh_);
catmull( 3 );
catmull.detach();
\endcode
*/
//-----------------------------------------------------------------------------
......@@ -72,11 +72,10 @@
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3InterpolatingSubdividerLabsikGreinerT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
// My stuff
#include <OpenMesh/Apps/Subdivider/SubdivideWidget.hh>
//
using namespace OpenMesh::Subdivider;
......@@ -149,6 +148,7 @@ SubdivideWidget(QWidget* _parent, const char* _name)
QRadioButton* radio4 = new QRadioButton( "Sqrt(3)" );
QRadioButton* radio5 = new QRadioButton( "Interpolating Sqrt3" );
QRadioButton* radio6 = new QRadioButton( "Modified Butterfly" );
// QRadioButton* radio7 = new QRadioButton( "Catmull Clark" ); // Disabled, as it needs a quad mesh!
radio3->setChecked( TRUE );
sel_topo_type = SOP_UniformLoop;
......@@ -158,6 +158,7 @@ SubdivideWidget(QWidget* _parent, const char* _name)
buttonGroup->addButton(radio4, SOP_UniformSqrt3);
buttonGroup->addButton(radio5, SOP_UniformInterpolatingSqrt3);
buttonGroup->addButton(radio6, SOP_ModifiedButterfly);
//buttonGroup->addButton(radio7, SOP_CatmullClark);
vbox->addWidget(radio1);
vbox->addWidget(radio2);
......@@ -165,6 +166,7 @@ SubdivideWidget(QWidget* _parent, const char* _name)
vbox->addWidget(radio4);
vbox->addWidget(radio5);
vbox->addWidget(radio6);
// vbox->addWidget(radio7);
QObject::connect( buttonGroup, SIGNAL( buttonPressed(int) ),
this, SLOT( slot_select_sop(int) ) );
......@@ -191,6 +193,7 @@ SubdivideWidget(QWidget* _parent, const char* _name)
subdivider_[SOP_UniformSqrt3] = new Uniform::Sqrt3T<Mesh>;
subdivider_[SOP_UniformInterpolatingSqrt3] = new Uniform::InterpolatingSqrt3LGT< Mesh >;
subdivider_[SOP_ModifiedButterfly] = new Uniform::ModifiedButterflyT<Mesh>;
subdivider_[SOP_CatmullClark] = new Uniform::CatmullClarkT<Mesh>;
}
......@@ -204,9 +207,10 @@ void SubdivideWidget::slot_select_sop(int i)
case SOP_UniformCompositeLoop:
case SOP_UniformCompositeSqrt3:
case SOP_UniformLoop:
case SOP_UniformSqrt3:
case SOP_UniformInterpolatingSqrt3:
case SOP_ModifiedButterfly:
case SOP_UniformSqrt3: sel_topo_type = (SOPType)i; break;
case SOP_CatmullClark: sel_topo_type = (SOPType)i; break;
default: sel_topo_type = SOP_Undefined;
}
}
......
......@@ -77,6 +77,7 @@ public:
SOP_UniformSqrt3,
SOP_UniformInterpolatingSqrt3,
SOP_ModifiedButterfly,
SOP_CatmullClark,
SOP_Undefined
};
......
......@@ -53,6 +53,7 @@
#include <OpenMesh/Tools/Subdivider/Uniform/CompositeLoopT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3InterpolatingSubdividerLabsikGreinerT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
// ----------------------------------------------------------------------------
......@@ -68,6 +69,7 @@ typedef Uniform::CompositeSqrt3T< CMesh > CompositeSqrt3;
typedef Uniform::CompositeLoopT< CMesh > CompositeLoop;
typedef Uniform::InterpolatingSqrt3LGT< Mesh > InterpolatingSqrt3LG;
typedef Uniform::ModifiedButterflyT< Mesh > ModifiedButterfly;
typedef Uniform::CatmullClarkT< Mesh > CatmullClark;
using OpenMesh::Utils::Timer;
......@@ -195,7 +197,8 @@ int main(int argc, char **argv)
TypeCompSqrt3,
TypeCompLoop,
TypeLabsikGreiner,
TypeModButterfly
TypeModButterfly,
TypeCatmullClark
} st = TypeSqrt3;
Timer::Format fmt = Timer::Automatic;
......@@ -211,6 +214,7 @@ int main(int argc, char **argv)
case 'L': st = TypeCompLoop; break;
case 'b': st = TypeLabsikGreiner; break;
case 'B': st = TypeModButterfly; break;
case 'C': st = TypeCatmullClark; std::cerr << "Not yet supported, as it needs a poly mesh!"; break;
case 'f':
{
switch(*optarg)
......@@ -255,6 +259,7 @@ int main(int argc, char **argv)
rc += mainT<CompositeLoop> ( n, ifname, "", fmt );
rc += mainT<InterpolatingSqrt3LG> ( n, ifname, "", fmt );
rc += mainT<ModifiedButterfly> ( n, ifname, "", fmt );
rc += mainT<CatmullClark> ( n, ifname, "", fmt );
if (rc)
return rc;
......@@ -294,6 +299,8 @@ int main(int argc, char **argv)
return mainT<InterpolatingSqrt3LG> ( n, ifname, ofname, fmt );
case TypeModButterfly:
return mainT<ModifiedButterfly> ( n, ifname, ofname, fmt );
case TypeCatmullClark:
return mainT<CatmullClark> ( n, ifname, ofname, fmt );
}
return 1;
}
......@@ -312,6 +319,7 @@ void usage_and_exit(int _xcode)
<< " -S\tComposite Sqrt3\n"
<< " -b\tInterpolating Sqrt3 Labsik-Greiner\n"
<< " -B\tModified Butterfly\n"
// << " -C\tCatmullClark\n"
<< std::endl;
exit(_xcode);
}
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: 520 $ *
* $Date: 2012-01-20 15:29:31 +0100 (Fr, 20 Jan 2012) $ *
* *
\*===========================================================================*/
/** \file CatmullClarkT.hh
*/
//=============================================================================
//
// CLASS CatmullClarkT
//
//=============================================================================
#ifndef OPENMESH_SUBDIVIDER_UNIFORM_CATMULLCLARKT_HH
#define OPENMESH_SUBDIVIDER_UNIFORM_CATMULLCLARKT_HH
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Subdivider/Uniform/SubdividerT.hh>
// -------------------- STL
#if defined(OM_CC_MIPS)
# include <math.h>
#else
# include <cmath>
#endif
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace OpenMesh { // BEGIN_NS_OPENMESH
namespace Subdivider { // BEGIN_NS_SUBVIDER
namespace Uniform { // BEGIN_NS_UNIFORM
//== CLASS DEFINITION =========================================================
/** \class CatmullClarkT CatmullClarkT.hh
Based on code from Leon Kos, CAD lab, Mech.Eng., University of Ljubljana, Slovenia
(http://www.lecad.fs.uni-lj.si/~leon)
\note Needs a PolyMesh to work on!
*/
template <typename MeshType, typename RealType = float>
class CatmullClarkT : public SubdividerT< MeshType, RealType >
{
public:
typedef typename MeshType::FaceHandle FaceHandle;
typedef typename MeshType::VertexHandle VertexHandle;
typedef typename MeshType::EdgeHandle EdgeHandle;
typedef typename MeshType::HalfedgeHandle HalfedgeHandle;
typedef typename MeshType::Point Point;
typedef typename MeshType::Normal Normal;
typedef typename MeshType::FaceIter FaceIter;
typedef typename MeshType::EdgeIter EdgeIter;
typedef typename MeshType::VertexIter VertexIter;
typedef typename MeshType::VertexEdgeIter VertexEdgeIter;
typedef typename MeshType::VertexFaceIter VertexFaceIter;
typedef typename MeshType::VOHIter VOHIter;
typedef SubdividerT< MeshType, RealType > parent_t;
/// Constructor
CatmullClarkT( ) : parent_t() { }
/// Constructor
CatmullClarkT(MeshType &_m) : parent_t(_m) { }
virtual ~CatmullClarkT() {}
public:
const char *name() const { return "Uniform CatmullClark"; }
protected:
/// Initialize properties and weights
virtual bool prepare( MeshType& _m );
/// Remove properties and weights
virtual bool cleanup( MeshType& _m );
/** \brief Execute n subdivision steps
*
* @param _m Mesh to work on
* @param _n Number of iterations
* @param _update_points Unused here
* @return successful?
*/
virtual bool subdivide( MeshType& _m, size_t _n , const bool _update_points = true);
private:
//===========================================================================
/** @name Topology helpers
* @{ */
//===========================================================================
void split_edge( MeshType& _m, const EdgeHandle& _eh);
void split_face( MeshType& _m, const FaceHandle& _fh);
void compute_midpoint( MeshType& _m, const EdgeHandle& _eh);
void update_vertex(MeshType& _m, const VertexHandle& _vh);
/** @} */
private:
OpenMesh::VPropHandleT< Point > vp_pos_; // next vertex pos
OpenMesh::EPropHandleT< Point > ep_pos_; // new edge pts
OpenMesh::FPropHandleT< Point > fp_pos_; // new face pts
OpenMesh::EPropHandleT<double> creaseWeights_;// crease weights
};
//=============================================================================
} // END_NS_UNIFORM
} // END_NS_SUBDIVIDER
} // END_NS_OPENMESH
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_UNIFORM_CATMULLCLARK_CC)
# define OPENMESH_SUBDIVIDER_TEMPLATES
# include "CatmullClarkT.cc"
#endif
//=============================================================================
#endif // OPENMESH_SUBDIVIDER_UNIFORM_CATMULLCLARKT_HH defined
//=============================================================================
......@@ -85,7 +85,7 @@ public:
CHECK_EDGES = 1,
CHECK_VERTICES = 2,
CHECK_FACES = 4,
CHECK_ALL = 255,
CHECK_ALL = 255
};
......
......@@ -7,6 +7,7 @@
#include "unittests_trimesh_collapse.hh"
#include "unittests_trimesh_circulators.hh"
#include "unittests_decimater.hh"
#include "unittests_subdivider.hh"
#include "unittests_trimesh_normal_calculations.hh"
#include "unittests_trimesh_others.hh"
#include "unittests_add_face.hh"
......
#ifndef INCLUDE_UNITTESTS_SUBIVIDER_HH
#define INCLUDE_UNITTESTS_SUBIVIDER_HH
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/Sqrt3T.hh>
class OpenMeshSubdivider_Poly : public OpenMeshBasePoly {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
// This function is called after all tests are through
virtual void TearDown() {
// Do some final stuff with the member data here...
}
// Member already defined in OpenMeshBase
//Mesh mesh_;
};
class OpenMeshSubdivider_Triangle : public OpenMeshBase {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
// This function is called after all tests are through
virtual void TearDown() {
// Do some final stuff with the member data here...
}
// Member already defined in OpenMeshBase
//Mesh mesh_;
};
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/*
*/
TEST_F(OpenMeshSubdivider_Triangle, Subdivider_Loop) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[9];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
vhandle[2] = mesh_.add_vertex(Mesh::Point(0, 2, 0));
vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
vhandle[4] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
vhandle[5] = mesh_.add_vertex(Mesh::Point(1, 2, 0));
vhandle[6] = mesh_.add_vertex(Mesh::Point(2, 0, 0));
vhandle[7] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
vhandle[8] = mesh_.add_vertex(Mesh::Point(2, 2, 0));
// Add eight faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[8]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]);
mesh_.add_face(face_vhandles);
// Test setup:
// 6 === 7 === 8
// | / | / |
// | / | / |
// | / | / |
// 3 === 4 === 5
// | / | \ |
// | / | \ |
// | / | \ |
// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Uniform::Sqrt3T<Mesh> sqrt3;
// Check setup
EXPECT_EQ(9, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(8, mesh_.n_faces() ) << "Wrong number of faces";
// Execute 3 subdivision steps
sqrt3.attach(mesh_);
sqrt3( 3 );
sqrt3.detach();
// Check setup
EXPECT_EQ(121, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
EXPECT_EQ(216, mesh_.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
}
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/*
*/
TEST_F(OpenMeshSubdivider_Poly, Subdivider_CatmullClark) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[9];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
vhandle[2] = mesh_.add_vertex(Mesh::Point(0, 2, 0));
vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
vhandle[4] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
vhandle[5] = mesh_.add_vertex(Mesh::Point(1, 2, 0));
vhandle[6] = mesh_.add_vertex(Mesh::Point(2, 0, 0));
vhandle[7] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
vhandle[8] = mesh_.add_vertex(Mesh::Point(2, 2, 0));
// Add four faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[8]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
// Test setup:
// 6 === 7 === 8
// | | |
// | | |
// | | |
// 3 === 4 === 5
// | | |
// | | |
// | | |
// 0 === 1 === 2
// Initialize subdivider
OpenMesh::Subdivider::Uniform::CatmullClarkT<PolyMesh> catmull;
// Check setup
EXPECT_EQ(9, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(4, mesh_.n_faces() ) << "Wrong number of faces";
// Execute 3 subdivision steps
catmull.attach(mesh_);
catmull( 3 );
catmull.detach();
EXPECT_EQ(289, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with catmull clark";
EXPECT_EQ(256, mesh_.n_faces() ) << "Wrong number of faces after subdivision with catmull clark";
}
#endif // INCLUDE GUARD
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