60 |
|
#include <CGAL/aff_transformation_tags.h> |
61 |
|
#include <iostream> |
62 |
|
#include <algorithm> |
63 |
+ |
#include <fstream> |
64 |
+ |
#include <math.h> |
65 |
|
|
66 |
+ |
using namespace std; |
67 |
|
using namespace oopse; |
68 |
|
|
69 |
|
//typedef CGAL::Homogeneous<int> Kernel; |
97 |
|
|
98 |
|
// A modifier creating a triangle with the incremental builder. |
99 |
|
template <class HDS> |
100 |
< |
class Build_nanorod : public CGAL::Modifier_base<HDS> { |
100 |
> |
class buildSingleCrystal : public CGAL::Modifier_base<HDS> { |
101 |
|
public: |
102 |
|
Vertex_handle end1; |
103 |
|
Vertex_handle neight1; |
104 |
|
Vertex_handle end2; |
105 |
|
Vertex_handle neight2; |
106 |
+ |
Vertex_handle neight3; |
107 |
|
|
108 |
< |
Build_nanorod() {} |
108 |
> |
buildSingleCrystal() {} |
109 |
|
void operator()( HDS& hds) { |
110 |
|
// Postcondition: `hds' is a valid polyhedral surface. |
111 |
|
CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true); |
121 |
|
B.add_vertex( Point(-0.4874571845316, 0.4874571845315, 0.6709272557930)); |
122 |
|
B.add_vertex( Point(-0.7887222926324, -0.4874571845315, -0.2562714077342)); //End vertex |
123 |
|
end1 = B.add_vertex( Point( 0.0000000000000, 1.0000000000000, 0.0000000000000)); |
124 |
< |
B.add_vertex( Point(-0.4874571845315, -0.4874571845316, 0.6709272557930)); |
124 |
> |
neight3 = B.add_vertex( Point(-0.4874571845315, -0.4874571845316, 0.6709272557930)); |
125 |
|
neight1 = B.add_vertex( Point(-0.0000000000000, 0.4874571845316, -0.8293116961175)); |
126 |
|
B.add_vertex( Point( 0.0000000000000, -0.4874571845316, -0.8293116961175)); |
127 |
|
B.add_vertex( Point( 0.4874571845315, 0.4874571845316, 0.6709272557930)); |
268 |
|
|
269 |
|
GeometryBuilder::GeometryBuilder(double length,double width) { |
270 |
|
// Create the geometry for nanorod |
271 |
< |
Build_nanorod<HalfedgeDS> nanorod; |
271 |
> |
buildSingleCrystal<HalfedgeDS> nanorod; |
272 |
|
|
273 |
|
nanoRodPolyhedron.delegate( nanorod); |
274 |
|
|
275 |
|
double y1 = nanorod.end1->point().y() - nanorod.neight1->point().y(); |
276 |
|
double y2 = nanorod.end2->point().y() - nanorod.neight2->point().y(); |
277 |
< |
|
277 |
> |
|
278 |
> |
double endDist = sqrt(pow(nanorod.neight2->point().x() - nanorod.neight3->point().x(),2)+ |
279 |
> |
pow(nanorod.neight2->point().y() - nanorod.neight3->point().y(),2)+ |
280 |
> |
pow(nanorod.neight2->point().z() - nanorod.neight3->point().z(),2)); |
281 |
> |
|
282 |
> |
double endRatio1 = y1/endDist; |
283 |
> |
double endRatio2 = y2/endDist; |
284 |
> |
|
285 |
> |
std::cout << "End dist is " << endDist <<" ratio " << endRatio1 << std::endl; |
286 |
> |
|
287 |
|
CGAL::Aff_transformation_3<Kernel> aff_tranformation( width, |
288 |
|
0.0, |
289 |
|
0.0, |
298 |
|
0.0); |
299 |
|
std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation); |
300 |
|
|
301 |
< |
Point_3 point1(nanorod.end1->point().x(), y1 + nanorod.neight1->point().y(), nanorod.end1->point().z()); |
302 |
< |
Point_3 point2(nanorod.end2->point().x(), y2+ nanorod.neight2->point().y(), nanorod.end2->point().z()); |
301 |
> |
|
302 |
> |
double endDist2 = sqrt(pow(nanorod.neight2->point().x() - nanorod.neight3->point().x(),2)+ |
303 |
> |
pow(nanorod.neight2->point().y() - nanorod.neight3->point().y(),2)+ |
304 |
> |
pow(nanorod.neight2->point().z() - nanorod.neight3->point().z(),2)); |
305 |
> |
|
306 |
> |
Point_3 point1(nanorod.end1->point().x(), endDist2*endRatio1 + nanorod.neight1->point().y(), nanorod.end1->point().z()); |
307 |
> |
Point_3 point2(nanorod.end2->point().x(), endDist2*endRatio2 + nanorod.neight2->point().y(), nanorod.end2->point().z()); |
308 |
|
nanorod.end1->point() = point1; |
309 |
|
nanorod.end2->point() = point2; |
310 |
|
|
311 |
|
// Construct normal vector for each face. |
312 |
|
std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(), |
313 |
|
Normal_vector()); |
314 |
< |
|
314 |
> |
} |
315 |
> |
void GeometryBuilder::dumpGeometry(const std::string& geomFileName){ |
316 |
> |
|
317 |
> |
std::ofstream newGeomFile; |
318 |
> |
|
319 |
> |
//create new .md file based on old .md file |
320 |
> |
newGeomFile.open(geomFileName.c_str()); |
321 |
> |
|
322 |
> |
// Write polyhedron in Object File Format (OFF). |
323 |
> |
CGAL::set_ascii_mode( std::cout); |
324 |
> |
newGeomFile << "OFF" << std::endl << nanoRodPolyhedron.size_of_vertices() << ' ' |
325 |
> |
<< nanoRodPolyhedron.size_of_facets() << " 0" << std::endl; |
326 |
> |
std::copy( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), |
327 |
> |
std::ostream_iterator<Point_3>( newGeomFile, "\n")); |
328 |
> |
for ( Facet_iterator i = nanoRodPolyhedron.facets_begin(); i != nanoRodPolyhedron.facets_end(); ++i) { |
329 |
> |
Halfedge_facet_circulator j = i->facet_begin(); |
330 |
> |
// Facets in polyhedral surfaces are at least triangles. |
331 |
> |
CGAL_assertion( CGAL::circulator_size(j) >= 3); |
332 |
> |
newGeomFile << CGAL::circulator_size(j) << ' '; |
333 |
> |
do { |
334 |
> |
newGeomFile << ' ' << std::distance(nanoRodPolyhedron.vertices_begin(), j->vertex()); |
335 |
> |
} while ( ++j != i->facet_begin()); |
336 |
> |
newGeomFile << std::endl; |
337 |
> |
} |
338 |
> |
|
339 |
> |
newGeomFile.close(); |
340 |
> |
|
341 |
> |
|
342 |
|
|
343 |
|
|
344 |
< |
} |
344 |
> |
} |
345 |
|
|
346 |
+ |
|