Free cookie consent management tool by TermsFeed Policy Generator

# Changeset 10211

Ignore:
Timestamp:
12/09/13 22:42:34 (9 years ago)
Message:

#1886 added a wrapper for calculating the convex hull using qhull

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior
Files:
4 edited

Unmodified
Removed
• ## branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3.csproj

 r10208 prompt4true
• ## branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/QhullWrapper.cs

 r10208 #endregion using System; using System.Collections.Generic; using System.Linq; } public unsafe static List CalculateConvexHull(List points) { int dimension = points.First().Length; int numPoints = points.Count(); List convexHullIndices = new List(); double[] data = new double[dimension * numPoints]; for (int i = 0; i < numPoints; i++) { for (int j = 0; j < dimension; j++) { data[i * dimension + j] = points[i][j]; } } IntPtr result = IntPtr.Zero; Int32 nrOfFacets = -1; Int32 retCode = 0; result = qhull_convex_hull(dimension, numPoints, data, &retCode, &nrOfFacets); if (result != IntPtr.Zero && retCode == 0) { try { var faces = new int[nrOfFacets * dimension]; Marshal.Copy(result, faces, 0, nrOfFacets * dimension); convexHullIndices.AddRange(faces.Distinct()); } finally { qhull_free(result); } } return convexHullIndices; } [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_volume", CallingConvention = CallingConvention.Cdecl)] public static extern double qhull_volume(int dim, int numpoints, [In]double[] data); [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_convex_hull", CallingConvention = CallingConvention.Cdecl)] public unsafe static extern IntPtr qhull_convex_hull(int dim, int numpoints, [In]double[] data, [Out] Int32* retCode, [Out] Int32* nrOfFacets); [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_free", CallingConvention = CallingConvention.Cdecl)] public static extern void qhull_free(IntPtr data); } }
• ## branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests/Program.cs

 r10208 volume = Math.Round(volume, 6); Console.WriteLine("Volume is: " + volume); QhullWrapper.CalculateConvexHull(points); }
• ## branches/HeuristicLab.Analysis.AlgorithmBehavior/qhull-2012.1/src/HeuristicLab.qhull/HeuristicLab_qhull.c

 r10208 #endif __declspec(dllexport) double qhull_volume(int dim, int numpoints, double *data); void print_summary (void); __declspec(dllexport) int* qhull_convex_hull(int dim, int numpoints, double *data, int *retCode, int* nrOfFacets); __declspec(dllexport) void qhull_free(int* data); #ifdef __cplusplus } if (!exitcode) { print_summary(); qh_vertexneighbors(); volume = qh totvol; } else { return -1.0; return -1.0; } qh_freeqhull(!qh_ALL); } int* qhull_convex_hull(int dim, int numpoints, double *data, int *retCode, int* nrOfFacets) { boolT ismalloc= False; char flags[250]; FILE *outfile= stdout; FILE *errfile= stdout; facetT *facet; int curlong, totlong; int i,j, exitcode; int* result = NULL; #if qh_QHpointer if (qh_qh){ printf ("QH6233: Qhull link error.  The global variable qh_qh was not initialized\n\ to NULL by global.c.  Please compile user_eg.c with -Dqh_QHpointer_dllimport\n\ as well as -Dqh_QHpointer, or use libqhullstatic, or use a different tool chain.\n\n"); *retCode = -1; return NULL; } #endif sprintf (flags, "qhull s Tv Qt FA"); exitcode= qh_new_qhull (dim, numpoints, data, ismalloc, flags, outfile, errfile); if (!exitcode) { facetT *facet; vertexT *vertex, **vertexp; unsigned int n = qh num_facets; *nrOfFacets = n; print_summary(); qh_vertexneighbors(); result = (int *) malloc(n*dim*sizeof(int)); i=0; FORALLfacets { j=0; FOREACHvertex_ (facet->vertices) { if (j >= dim) fprintf (errfile,"extra vertex %d of facet %d = %d",j++,i,/*1+*/qh_pointid(vertex->point));    //TODO: handle in return value else result[i+n*j++] = qh_pointid(vertex->point); } if (j < dim) fprintf (errfile,"facet %d only has %d vertices",i,j); i++; } } else { *retCode = -1; return NULL; } qh_freeqhull(!qh_ALL); qh_memfreeshort (&curlong, &totlong); if (curlong || totlong) fprintf (errfile, "qhull internal warning (HeuristicLab_qhull, #1): did not free %d bytes of long memory (%d pieces)\n", totlong, curlong); return result; } void qhull_free(int* data) { free(data); }
Note: See TracChangeset for help on using the changeset viewer.