From 9bfdc346c3ac9bbc8cd15958e58d9dc6e328beed Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Tue, 31 Jan 2012 04:45:46 +0000 Subject: [PATCH] allow cancel operation for HACD (it takes minutes to complete, blocking modelers such as Maya when accidently pressed) used in Dynamica maya plugin (http://dynamica.googlecode.com) --- Extras/HACD/hacdHACD.cpp | 14 ++++++++++++++ Extras/HACD/hacdHACD.h | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Extras/HACD/hacdHACD.cpp b/Extras/HACD/hacdHACD.cpp index 7473b0f3e..b7d16e565 100644 --- a/Extras/HACD/hacdHACD.cpp +++ b/Extras/HACD/hacdHACD.cpp @@ -25,6 +25,7 @@ #include #include +bool gCancelRequest=false; namespace HACD { double HACD::Concavity(ICHull & ch, std::map & distPoints) @@ -192,6 +193,11 @@ namespace HACD memset(m_normals, 0, sizeof(Vec3) * m_nPoints); for(unsigned long f = 0; f < m_nTriangles; f++) { + if (m_callBack) (*m_callBack)("+ InitializeDualGraph\n", f, m_nTriangles, 0); + + if (gCancelRequest) + return; + i = m_triangles[f].X(); j = m_triangles[f].Y(); k = m_triangles[f].Z(); @@ -660,6 +666,8 @@ namespace HACD bool HACD::Compute(bool fullCH, bool exportDistPoints) { + gCancelRequest = false; + if ( !m_points || !m_triangles || !m_nPoints || !m_nTriangles) { return false; @@ -691,8 +699,14 @@ namespace HACD CreateGraph(); // Compute the surfaces and perimeters of all the faces if (m_callBack) (*m_callBack)("+ Initializing Dual Graph\n", 0.0, 0.0, nV); + if (gCancelRequest) + return false; + InitializeDualGraph(); if (m_callBack) (*m_callBack)("+ Initializing Priority Queue\n", 0.0, 0.0, nV); + if (gCancelRequest) + return false; + InitializePriorityQueue(); // we simplify the graph if (m_callBack) (*m_callBack)("+ Simplification ...\n", 0.0, 0.0, m_nTriangles); diff --git a/Extras/HACD/hacdHACD.h b/Extras/HACD/hacdHACD.h index 6c8dc7b13..c49e370b2 100644 --- a/Extras/HACD/hacdHACD.h +++ b/Extras/HACD/hacdHACD.h @@ -72,7 +72,7 @@ namespace HACD { return lhs.m_priority>rhs.m_priority; } - typedef void (*CallBackFunction)(const char *, double, double, size_t); + typedef bool (*CallBackFunction)(const char *, double, double, size_t); //! Provides an implementation of the Hierarchical Approximate Convex Decomposition (HACD) technique described in "A Simple and Efficient Approach for 3D Mesh Approximate Convex Decomposition" Game Programming Gems 8 - Chapter 2.8, p.202. A short version of the chapter was published in ICIP09 and is available at ftp://ftp.elet.polimi.it/users/Stefano.Tubaro/ICIP_USB_Proceedings_v2/pdfs/0003501.pdf class HACD