| 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.3 2007-05-30 18:47:03 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 |
< |
|
| 61 |
< |
bool ConvexHull::genHull(std::vector<Vector3d> pos) |
| 62 |
< |
{ |
| 63 |
< |
FILE *outfile = stdout; |
| 64 |
< |
FILE *errfile = stderr; |
| 65 |
< |
facetT *facet; |
| 66 |
< |
int exitcode; |
| 67 |
< |
boolT ismalloc = False; |
| 68 |
< |
int curlong,totlong; |
| 69 |
< |
|
| 70 |
< |
int numpoints = pos.size(); |
| 71 |
< |
|
| 72 |
< |
coordT points[numpoints][dim_]; |
| 73 |
< |
|
| 74 |
< |
for (int i=0; i<numpoints; i++) |
| 75 |
< |
{ |
| 76 |
< |
points[i][0] = pos[i][0]; |
| 77 |
< |
points[i][1] = pos[i][1]; |
| 78 |
< |
points[i][2] = pos[i][2]; |
| 79 |
< |
} |
| 80 |
< |
|
| 81 |
< |
|
| 82 |
< |
|
| 83 |
< |
qh_initflags (options); |
| 84 |
< |
qh_init_B (points[0], numpoints, dim_, ismalloc); |
| 85 |
< |
qh_qhull(); |
| 86 |
< |
qh_check_output(); |
| 87 |
< |
|
| 88 |
< |
|
| 89 |
< |
|
| 90 |
< |
qh_getarea(qh facet_list); |
| 91 |
< |
volume_ = qh totvol; |
| 92 |
< |
area_ = qh totarea; |
| 93 |
< |
|
| 94 |
< |
|
| 95 |
< |
|
| 96 |
< |
qh_freeqhull(!qh_ALL); |
| 97 |
< |
qh_memfreeshort (&curlong, &totlong); |
| 98 |
< |
if (curlong || totlong) |
| 99 |
< |
fprintf (errfile, "qhull internal warning (main): did not free %d bytes of long memory (%d pieces)\n", |
| 100 |
< |
totlong, curlong); |
| 103 |
< |
|
| 104 |
< |
|
| 105 |
< |
return true; |
| 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[numpoints][dim_]; |
| 71 |
> |
|
| 72 |
> |
for (int i=0; i<numpoints; i++) { |
| 73 |
> |
points[i][0] = pos[i][0]; |
| 74 |
> |
points[i][1] = pos[i][1]; |
| 75 |
> |
points[i][2] = pos[i][2]; |
| 76 |
> |
} |
| 77 |
> |
|
| 78 |
> |
|
| 79 |
> |
|
| 80 |
> |
qh_initflags (const_cast<char *>(options_.c_str())); |
| 81 |
> |
qh_init_B (points[0], 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 |
|
} |