| 44 | 
  | 
 * | 
| 45 | 
  | 
 *  Created by Charles F. Vardeman II on 11 Dec 2006. | 
| 46 | 
  | 
 *  @author  Charles F. Vardeman II | 
| 47 | 
< | 
 *  @version $Id: ConvexHull.cpp,v 1.2 2007-05-29 22:50:14 chuckv Exp $ | 
| 47 | 
> | 
 *  @version $Id: ConvexHull.cpp,v 1.4 2007-05-30 19:51:07 chuckv Exp $ | 
| 48 | 
  | 
 * | 
| 49 | 
  | 
 */ | 
| 50 | 
  | 
 | 
| 51 | 
– | 
#include "math/ConvexHull.hpp" | 
| 51 | 
  | 
#include <iostream> | 
| 52 | 
  | 
#include <fstream> | 
| 53 | 
+ | 
#include "math/ConvexHull.hpp" | 
| 54 | 
  | 
 | 
| 55 | 
– | 
char options[] = "qhull Qt FA";  | 
| 56 | 
– | 
int dim_ = 3; | 
| 57 | 
– | 
 | 
| 55 | 
  | 
using namespace oopse; | 
| 56 | 
  | 
 | 
| 57 | 
< | 
ConvexHull::ConvexHull(){} | 
| 57 | 
> | 
ConvexHull::ConvexHull() : dim_(3), options_("qhull Qt FA") { | 
| 58 | 
> | 
} | 
| 59 | 
  | 
 | 
| 60 | 
+ | 
bool ConvexHull::genHull(std::vector<Vector3d> pos) { | 
| 61 | 
+ | 
  FILE *outfile = stdout; | 
| 62 | 
+ | 
  FILE *errfile = stderr; | 
| 63 | 
+ | 
  facetT *facet; | 
| 64 | 
+ | 
  int exitcode; | 
| 65 | 
+ | 
  boolT ismalloc = False; | 
| 66 | 
+ | 
  int curlong,totlong; | 
| 67 | 
+ | 
   | 
| 68 | 
+ | 
  int numpoints = pos.size(); | 
| 69 | 
+ | 
  | 
| 70 | 
+ | 
  coordT* points; | 
| 71 | 
+ | 
  points = (coordT*) malloc(sizeof(coordT) * (numpoints*dim_));  | 
| 72 | 
  | 
 | 
| 73 | 
< | 
bool ConvexHull::genHull(std::vector<Vector3d> pos) | 
| 74 | 
< | 
{ | 
| 75 | 
< | 
        FILE *outfile = stdout; | 
| 76 | 
< | 
        FILE *errfile = stderr; | 
| 77 | 
< | 
        facetT *facet; | 
| 78 | 
< | 
        int exitcode; | 
| 79 | 
< | 
        boolT ismalloc = False; | 
| 80 | 
< | 
        int curlong,totlong; | 
| 81 | 
< | 
         | 
| 82 | 
< | 
        int numpoints = pos.size(); | 
| 83 | 
< | 
         | 
| 84 | 
< | 
        coordT points[numpoints][dim_]; | 
| 85 | 
< | 
         | 
| 86 | 
< | 
        for (int i=0; i<numpoints; i++) | 
| 87 | 
< | 
        { | 
| 88 | 
< | 
     points[i][0] = pos[i][0]; | 
| 89 | 
< | 
     points[i][1] = pos[i][1]; | 
| 90 | 
< | 
     points[i][2] = pos[i][2];           | 
| 91 | 
< | 
        } | 
| 92 | 
< | 
    | 
| 93 | 
< | 
 | 
| 94 | 
< | 
 | 
| 95 | 
< | 
        qh_initflags (options); | 
| 96 | 
< | 
    qh_init_B (points[0], numpoints, dim_, ismalloc); | 
| 97 | 
< | 
    qh_qhull(); | 
| 98 | 
< | 
    qh_check_output(); | 
| 99 | 
< | 
                                                         | 
| 100 | 
< | 
                                                         | 
| 91 | 
< | 
                                                         | 
| 92 | 
< | 
    qh_getarea(qh facet_list); | 
| 93 | 
< | 
    volume_ = qh totvol;                                                         | 
| 94 | 
< | 
        area_ = qh totarea;                                              | 
| 95 | 
< | 
                                                         | 
| 96 | 
< | 
                                                         | 
| 97 | 
< | 
                                                         | 
| 98 | 
< | 
    qh_freeqhull(!qh_ALL); | 
| 99 | 
< | 
        qh_memfreeshort (&curlong, &totlong); | 
| 100 | 
< | 
        if (curlong || totlong) | 
| 101 | 
< | 
                fprintf (errfile, "qhull internal warning (main): did not free %d bytes of long memory (%d pieces)\n", | 
| 102 | 
< | 
                                 totlong, curlong); | 
| 103 | 
< | 
         | 
| 104 | 
< | 
 | 
| 105 | 
< | 
        return true; | 
| 73 | 
> | 
  for (int i=0; i<numpoints; i++) { | 
| 74 | 
> | 
    points[dim_ * i] = pos[i][0]; | 
| 75 | 
> | 
    points[dim_ * i + 1] = pos[i][1]; | 
| 76 | 
> | 
    points[dim_ * i + 2] = pos[i][2];            | 
| 77 | 
> | 
  } | 
| 78 | 
> | 
   | 
| 79 | 
> | 
   | 
| 80 | 
> | 
  qh_initflags (const_cast<char *>(options_.c_str())); | 
| 81 | 
> | 
  qh_init_B (points, numpoints, dim_, ismalloc); | 
| 82 | 
> | 
  qh_qhull(); | 
| 83 | 
> | 
  qh_check_output(); | 
| 84 | 
> | 
   | 
| 85 | 
> | 
   | 
| 86 | 
> | 
   | 
| 87 | 
> | 
  qh_getarea(qh facet_list); | 
| 88 | 
> | 
  volume_ = qh totvol;                                                   | 
| 89 | 
> | 
  area_ = qh totarea;                                            | 
| 90 | 
> | 
   | 
| 91 | 
> | 
   | 
| 92 | 
> | 
   | 
| 93 | 
> | 
  qh_freeqhull(!qh_ALL); | 
| 94 | 
> | 
  qh_memfreeshort (&curlong, &totlong); | 
| 95 | 
> | 
  if (curlong || totlong) | 
| 96 | 
> | 
    fprintf (errfile, "qhull internal warning (main): did not free %d bytes of long memory (%d pieces)\n", | 
| 97 | 
> | 
             totlong, curlong); | 
| 98 | 
> | 
   | 
| 99 | 
> | 
   | 
| 100 | 
> | 
  return true; | 
| 101 | 
  | 
} | 
| 102 | 
  | 
 | 
| 103 | 
  | 
 | 
| 104 | 
< | 
RealType ConvexHull::getVolume() | 
| 105 | 
< | 
{ | 
| 111 | 
< | 
        return volume_; | 
| 104 | 
> | 
RealType ConvexHull::getVolume() { | 
| 105 | 
> | 
  return volume_; | 
| 106 | 
  | 
} | 
| 107 | 
  | 
 | 
| 108 | 
< | 
void ConvexHull::geomviewHull(const std::string& geomFileName) | 
| 109 | 
< | 
{ | 
| 116 | 
< | 
 | 
| 108 | 
> | 
void ConvexHull::geomviewHull(const std::string& geomFileName) { | 
| 109 | 
> | 
   | 
| 110 | 
  | 
  std::ofstream newGeomFile; | 
| 111 | 
< | 
 | 
| 111 | 
> | 
   | 
| 112 | 
  | 
  //create new .md file based on old .md file | 
| 113 | 
  | 
  newGeomFile.open(geomFileName.c_str()); | 
| 114 | 
< | 
 | 
| 115 | 
< | 
 | 
| 114 | 
> | 
   | 
| 115 | 
> | 
   | 
| 116 | 
  | 
  newGeomFile.close(); | 
| 124 | 
– | 
 | 
| 125 | 
– | 
 | 
| 117 | 
  | 
} |