| 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 $ |
| 48 |
> |
* @version $Id: AlphaShape.cpp,v 1.2 2008-05-14 14:31:48 chuckv Exp $ |
| 49 |
|
* |
| 50 |
|
*/ |
| 51 |
|
|
| 54 |
|
#include <iostream> |
| 55 |
|
#include <list> |
| 56 |
|
#include <fstream> |
| 57 |
+ |
#include <CGAL/IO/Geomview_stream.h> |
| 58 |
|
#include <CGAL/IO/alpha_shape_geomview_ostream_3.h> |
| 59 |
|
|
| 60 |
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> |
| 61 |
|
#include <CGAL/Delaunay_triangulation_3.h> |
| 62 |
|
#include <CGAL/Triangulation_hierarchy_3.h> |
| 63 |
|
#include <CGAL/Alpha_shape_3.h> |
| 64 |
+ |
#include <CGAL/Tetrahedron_3.h> |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
struct K : CGAL::Exact_predicates_inexact_constructions_kernel {}; |
| 77 |
|
typedef K::Point_3 Point; |
| 78 |
|
typedef Alpha_shape_3::Alpha_iterator Alpha_iterator; |
| 79 |
|
typedef Alpha_shape_3::NT NT; |
| 80 |
+ |
typedef Alpha_shape_3::Cell_handle Cell_handle; |
| 81 |
+ |
typedef Alpha_shape_3::Vertex_handle Vertex_handle; |
| 82 |
+ |
typedef Alpha_shape_3::Facet Facet; |
| 83 |
+ |
typedef Alpha_shape_3::Edge Edge; |
| 84 |
+ |
typedef CGAL::Tetrahedron_3<K> Tetrahedron; |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 82 |
– |
|
| 89 |
|
using namespace oopse; |
| 90 |
|
|
| 91 |
|
AlphaShape::AlphaShape(){} |
| 96 |
|
Delaunay_hierarchy dt; |
| 97 |
|
//points.reserve(pos.size()); |
| 98 |
|
// Copy the positon vector into a points vector for cgal. |
| 99 |
< |
for (int i = 0; i < pos.size(); ++i) |
| 99 |
> |
for (unsigned int i = 0; i < pos.size(); ++i) |
| 100 |
|
{ |
| 101 |
|
Point pt(pos[i][0],pos[i][1],pos[i][2]); |
| 102 |
|
dt.insert(pt); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
/* Generate Alpha Shape */ |
| 106 |
< |
|
| 106 |
> |
std::cout << "Generating alpha shape" << std::endl; |
| 107 |
|
Alpha_shape_3 ashape(dt); |
| 108 |
|
|
| 109 |
< |
|
| 110 |
< |
/*CGAL::Geomview_stream gv(CGAL::Bbox_3(0,0,0, 2, 2, 2)); |
| 109 |
> |
/* |
| 110 |
> |
CGAL::Geomview_stream gv(CGAL::Bbox_3(0,0,0, 2, 2, 2)); |
| 111 |
|
gv.set_line_width(4); |
| 112 |
|
gv.set_trace(false); |
| 113 |
|
gv.set_bg_color(CGAL::Color(0, 200, 200)); |
| 114 |
< |
gv.clear();*/ |
| 115 |
< |
std::cout << ashape; |
| 114 |
> |
gv.clear(); |
| 115 |
> |
*/ |
| 116 |
> |
Alpha_shape_3::NT alpha_solid = ashape.find_alpha_solid(); |
| 117 |
> |
Alpha_iterator opt = ashape.find_optimal_alpha(1); |
| 118 |
> |
std::cout << "Smallest alpha value to get a solid through data points is " |
| 119 |
> |
<< alpha_solid << std::endl; |
| 120 |
> |
std::cout << "Optimal alpha value to get one connected component is " |
| 121 |
> |
<< *opt << std::endl; |
| 122 |
> |
ashape.set_alpha(*opt); |
| 123 |
> |
assert(ashape.number_of_solid_components() == 1); |
| 124 |
> |
std::list<Cell_handle> cells; |
| 125 |
> |
std::list<Facet> facets; |
| 126 |
> |
std::list<Edge> edges; |
| 127 |
> |
std::list<Vertex_handle> vertices; |
| 128 |
> |
|
| 129 |
> |
ashape.get_alpha_shape_cells(std::back_inserter(cells), |
| 130 |
> |
Alpha_shape_3::INTERIOR); |
| 131 |
> |
ashape.get_alpha_shape_facets(std::back_inserter(facets), |
| 132 |
> |
Alpha_shape_3::REGULAR); |
| 133 |
> |
ashape.get_alpha_shape_facets(std::back_inserter(facets), |
| 134 |
> |
Alpha_shape_3::SINGULAR); |
| 135 |
> |
ashape.get_alpha_shape_edges(std::back_inserter(edges), |
| 136 |
> |
Alpha_shape_3::SINGULAR); |
| 137 |
> |
ashape.get_alpha_shape_vertices(std::back_inserter(vertices), |
| 138 |
> |
Alpha_shape_3::REGULAR); |
| 139 |
> |
std::cout << " The 0-shape has : " << std::endl; |
| 140 |
> |
std::cout << cells.size() << " interior tetrahedra" << std::endl; |
| 141 |
> |
std::cout << facets.size() << " boundary facets" << std::endl; |
| 142 |
> |
std::cout << edges.size() << " singular edges" << std::endl; |
| 143 |
> |
std::cout << vertices.size() << " singular vertices" << std::endl; |
| 144 |
> |
|
| 145 |
> |
RealType volume_; |
| 146 |
> |
std::list<Cell_handle>::iterator thiscell; |
| 147 |
> |
|
| 148 |
> |
for(Alpha_shape_3::Cell_iterator c_it = ashape.cells_begin(); c_it != ashape.cells_end(); ++c_it) |
| 149 |
> |
{ |
| 150 |
> |
volume_ += ashape.tetrahedron(c_it).volume(); |
| 151 |
> |
} |
| 152 |
> |
|
| 153 |
> |
//gv << (Delaunay) ashape; |
| 154 |
> |
//std::cout << ashape; |
| 155 |
> |
|
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
RealType AlphaShape::getVolume() |