1 |
chuckv |
1202 |
/* Copyright (c) 2007 The University of Notre Dame. All Rights Reserved. |
2 |
|
|
* |
3 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
4 |
|
|
* non-exclusive, royalty free, license to use, modify and |
5 |
|
|
* redistribute this software in source and binary code form, provided |
6 |
|
|
* that the following conditions are met: |
7 |
|
|
* |
8 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
9 |
|
|
* publication of scientific results based in part on use of the |
10 |
|
|
* program. An acceptable form of acknowledgement is citation of |
11 |
|
|
* the article in which the program was described (Matthew |
12 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
13 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
14 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
15 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
16 |
|
|
* |
17 |
|
|
* 2. Redistributions of source code must retain the above copyright |
18 |
|
|
* notice, this list of conditions and the following disclaimer. |
19 |
|
|
* |
20 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
21 |
|
|
* notice, this list of conditions and the following disclaimer in the |
22 |
|
|
* documentation and/or other materials provided with the |
23 |
|
|
* distribution. |
24 |
|
|
* |
25 |
|
|
* This software is provided "AS IS," without a warranty of any |
26 |
|
|
* kind. All express or implied conditions, representations and |
27 |
|
|
* warranties, including any implied warranty of merchantability, |
28 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
29 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
30 |
|
|
* be liable for any damages suffered by licensee as a result of |
31 |
|
|
* using, modifying or distributing the software or its |
32 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
33 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
34 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
35 |
|
|
* damages, however caused and regardless of the theory of liability, |
36 |
|
|
* arising out of the use of or inability to use software, even if the |
37 |
|
|
* University of Notre Dame has been advised of the possibility of |
38 |
|
|
* such damages. |
39 |
|
|
* |
40 |
|
|
* |
41 |
|
|
* AlphaShape.cpp |
42 |
|
|
* |
43 |
|
|
* Purpose: To calculate convexhull, hull volume and radius |
44 |
|
|
* using the CGAL library. |
45 |
|
|
* |
46 |
|
|
* Created by Charles F. Vardeman II on 11 Dec 2006. |
47 |
|
|
* @author Charles F. Vardeman II |
48 |
|
|
* @version $Id: AlphaShape.cpp,v 1.1 2007-12-07 00:48:47 chuckv Exp $ |
49 |
|
|
* |
50 |
|
|
*/ |
51 |
|
|
|
52 |
|
|
#include "math/AlphaShape.hpp" |
53 |
|
|
|
54 |
|
|
#include <iostream> |
55 |
|
|
#include <list> |
56 |
|
|
#include <fstream> |
57 |
|
|
#include <CGAL/IO/alpha_shape_geomview_ostream_3.h> |
58 |
|
|
|
59 |
|
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> |
60 |
|
|
#include <CGAL/Delaunay_triangulation_3.h> |
61 |
|
|
#include <CGAL/Triangulation_hierarchy_3.h> |
62 |
|
|
#include <CGAL/Alpha_shape_3.h> |
63 |
|
|
|
64 |
|
|
|
65 |
|
|
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {}; |
66 |
|
|
|
67 |
|
|
typedef CGAL::Alpha_shape_vertex_base_3<K> Vb; |
68 |
|
|
typedef CGAL::Triangulation_hierarchy_vertex_base_3<Vb> Vbh; |
69 |
|
|
typedef CGAL::Alpha_shape_cell_base_3<K> Fb; |
70 |
|
|
typedef CGAL::Triangulation_data_structure_3<Vbh,Fb> Tds; |
71 |
|
|
typedef CGAL::Delaunay_triangulation_3<K,Tds> Delaunay; |
72 |
|
|
typedef CGAL::Triangulation_hierarchy_3<Delaunay> Delaunay_hierarchy; |
73 |
|
|
typedef CGAL::Alpha_shape_3<Delaunay_hierarchy> Alpha_shape_3; |
74 |
|
|
|
75 |
|
|
typedef K::Point_3 Point; |
76 |
|
|
typedef Alpha_shape_3::Alpha_iterator Alpha_iterator; |
77 |
|
|
typedef Alpha_shape_3::NT NT; |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
using namespace oopse; |
84 |
|
|
|
85 |
|
|
AlphaShape::AlphaShape(){} |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
bool AlphaShape::genHull(std::vector<Vector3d> pos) |
89 |
|
|
{ |
90 |
|
|
Delaunay_hierarchy dt; |
91 |
|
|
//points.reserve(pos.size()); |
92 |
|
|
// Copy the positon vector into a points vector for cgal. |
93 |
|
|
for (int i = 0; i < pos.size(); ++i) |
94 |
|
|
{ |
95 |
|
|
Point pt(pos[i][0],pos[i][1],pos[i][2]); |
96 |
|
|
dt.insert(pt); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/* Generate Alpha Shape */ |
100 |
|
|
|
101 |
|
|
Alpha_shape_3 ashape(dt); |
102 |
|
|
|
103 |
|
|
|
104 |
|
|
/*CGAL::Geomview_stream gv(CGAL::Bbox_3(0,0,0, 2, 2, 2)); |
105 |
|
|
gv.set_line_width(4); |
106 |
|
|
gv.set_trace(false); |
107 |
|
|
gv.set_bg_color(CGAL::Color(0, 200, 200)); |
108 |
|
|
gv.clear();*/ |
109 |
|
|
std::cout << ashape; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
RealType AlphaShape::getVolume() |
113 |
|
|
{ |
114 |
|
|
/* |
115 |
|
|
std::list<Point> L; |
116 |
|
|
L.push_front(Point(0,0,0)); |
117 |
|
|
L.push_front(Point(1,0,0)); |
118 |
|
|
L.push_front(Point(0,1,0)); |
119 |
|
|
|
120 |
|
|
Triangulation T(L.begin(), L.end()); |
121 |
|
|
|
122 |
|
|
int n = T.number_of_vertices(); |
123 |
|
|
|
124 |
|
|
// insertion from a vector : |
125 |
|
|
std::vector<Point> V(3); |
126 |
|
|
V[0] = Point(0,0,1); |
127 |
|
|
V[1] = Point(1,1,1); |
128 |
|
|
V[2] = Point(2,2,2); |
129 |
|
|
|
130 |
|
|
n = n + T.insert(V.begin(), V.end()); |
131 |
|
|
|
132 |
|
|
assert( n == 6 ); // 6 points have been inserted |
133 |
|
|
assert( T.is_valid() ); // checking validity of T |
134 |
|
|
|
135 |
|
|
double sum_v = 0; |
136 |
|
|
for(Triangulation::Cell_iterator c_it = T.cells_begin(); c_it != T.cells_end(); ++c_it) |
137 |
|
|
{ |
138 |
|
|
sum_v += T.tetrahedron(c_it).volume(); |
139 |
|
|
} |
140 |
|
|
std::cout << "sum_v " << sum_v << std::endl; |
141 |
|
|
*/ |
142 |
|
|
return 0.0; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
void AlphaShape::geomviewHull(const std::string& geomFileName) |
146 |
|
|
{ |
147 |
|
|
/* |
148 |
|
|
std::ofstream newGeomFile; |
149 |
|
|
|
150 |
|
|
//create new .md file based on old .md file |
151 |
|
|
newGeomFile.open(geomFileName.c_str()); |
152 |
|
|
|
153 |
|
|
// Write polyhedron in Object File Format (OFF). |
154 |
|
|
CGAL::set_ascii_mode( std::cout); |
155 |
|
|
newGeomFile << "OFF" << std::endl << ch_polyhedron.size_of_vertices() << ' ' |
156 |
|
|
<< ch_polyhedron.size_of_facets() << " 0" << std::endl; |
157 |
|
|
std::copy( ch_polyhedron.points_begin(), ch_polyhedron.points_end(), |
158 |
|
|
std::ostream_iterator<Point_3>( newGeomFile, "\n")); |
159 |
|
|
for ( Facet_iterator i = ch_polyhedron.facets_begin(); i != ch_polyhedron.facets_end(); ++i) |
160 |
|
|
{ |
161 |
|
|
Halfedge_facet_circulator j = i->facet_begin(); |
162 |
|
|
// Facets in polyhedral surfaces are at least triangles. |
163 |
|
|
CGAL_assertion( CGAL::circulator_size(j) >= 3); |
164 |
|
|
newGeomFile << CGAL::circulator_size(j) << ' '; |
165 |
|
|
do |
166 |
|
|
{ |
167 |
|
|
newGeomFile << ' ' << std::distance(ch_polyhedron.vertices_begin(), j->vertex()); |
168 |
|
|
} |
169 |
|
|
while ( ++j != i->facet_begin()); |
170 |
|
|
newGeomFile << std::endl; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
newGeomFile.close(); |
174 |
|
|
*/ |
175 |
|
|
|
176 |
|
|
} |