19 |
|
* publication of scientific results based in part on use of the |
20 |
|
* program. An acceptable form of acknowledgement is citation of |
21 |
|
* the article in which the program was described (Matthew |
22 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
23 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
22 |
> |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
23 |
> |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
24 |
|
* Parallel Simulation Engine for Molecular Dynamics," |
25 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
25 |
> |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
26 |
|
* |
27 |
|
* 2. Redistributions of source code must retain the above copyright |
28 |
|
* notice, this list of conditions and the following disclaimer. |
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; |
95 |
|
// Kernel::RT s=RT(20), |
96 |
|
// Kernel::RT hw = RT(1)); |
97 |
|
|
98 |
+ |
|
99 |
+ |
|
100 |
+ |
|
101 |
+ |
|
102 |
|
// A modifier creating a triangle with the incremental builder. |
103 |
|
template <class HDS> |
104 |
< |
class Build_nanorod : public CGAL::Modifier_base<HDS> { |
105 |
< |
public: |
104 |
> |
class buildSingleCrystal : public CGAL::Modifier_base<HDS> { |
105 |
> |
public: |
106 |
|
Vertex_handle end1; |
107 |
|
Vertex_handle neight1; |
108 |
< |
Vertex_handle end2; |
108 |
> |
Vertex_handle end2; |
109 |
|
Vertex_handle neight2; |
110 |
+ |
Vertex_handle neight3; |
111 |
|
|
112 |
< |
Build_nanorod() {} |
112 |
> |
buildSingleCrystal() {} |
113 |
|
void operator()( HDS& hds) { |
114 |
|
// Postcondition: `hds' is a valid polyhedral surface. |
115 |
|
CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true); |
125 |
|
B.add_vertex( Point(-0.4874571845316, 0.4874571845315, 0.6709272557930)); |
126 |
|
B.add_vertex( Point(-0.7887222926324, -0.4874571845315, -0.2562714077342)); //End vertex |
127 |
|
end1 = B.add_vertex( Point( 0.0000000000000, 1.0000000000000, 0.0000000000000)); |
128 |
< |
B.add_vertex( Point(-0.4874571845315, -0.4874571845316, 0.6709272557930)); |
128 |
> |
neight3 = B.add_vertex( Point(-0.4874571845315, -0.4874571845316, 0.6709272557930)); |
129 |
|
neight1 = B.add_vertex( Point(-0.0000000000000, 0.4874571845316, -0.8293116961175)); |
130 |
|
B.add_vertex( Point( 0.0000000000000, -0.4874571845316, -0.8293116961175)); |
131 |
|
B.add_vertex( Point( 0.4874571845315, 0.4874571845316, 0.6709272557930)); |
251 |
|
|
252 |
|
bool GeometryBuilder::isInsidePolyhedron(double x, double y, double z) { |
253 |
|
|
254 |
< |
Point_3 point(x,y,z); |
254 |
> |
Point_3 point(x,y,z); |
255 |
|
Plane_iterator i; |
256 |
|
Facet_iterator j; |
257 |
|
for ( i =nanoRodPolyhedron.planes_begin(), j = nanoRodPolyhedron.facets_begin(); i != nanoRodPolyhedron.planes_end() && j !=nanoRodPolyhedron.facets_end(); ++i, ++j) { |
271 |
|
|
272 |
|
|
273 |
|
GeometryBuilder::GeometryBuilder(double length,double width) { |
274 |
< |
// Create the geometry for nanorod |
275 |
< |
Build_nanorod<HalfedgeDS> nanorod; |
274 |
> |
// Create the geometry for nanorod |
275 |
> |
buildSingleCrystal<HalfedgeDS> nanorod; |
276 |
|
|
277 |
|
nanoRodPolyhedron.delegate( nanorod); |
278 |
|
|
279 |
< |
double y1 = nanorod.end1->point().y() - nanorod.neight1->point().y(); |
280 |
< |
double y2 = nanorod.end2->point().y() - nanorod.neight2->point().y(); |
281 |
< |
|
282 |
< |
CGAL::Aff_transformation_3<Kernel> aff_tranformation( width, |
283 |
< |
0.0, |
284 |
< |
0.0, |
285 |
< |
0.0, |
286 |
< |
0.0, |
287 |
< |
length, |
288 |
< |
0.0, |
289 |
< |
0.0, |
290 |
< |
0.0, |
291 |
< |
0.0, |
292 |
< |
width, |
293 |
< |
0.0); |
294 |
< |
std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation); |
295 |
< |
|
296 |
< |
Point_3 point1(nanorod.end1->point().x(), y1 + nanorod.neight1->point().y(), nanorod.end1->point().z()); |
297 |
< |
Point_3 point2(nanorod.end2->point().x(), y2+ nanorod.neight2->point().y(), nanorod.end2->point().z()); |
298 |
< |
nanorod.end1->point() = point1; |
299 |
< |
nanorod.end2->point() = point2; |
279 |
> |
double y1 = nanorod.end1->point().y() - nanorod.neight1->point().y(); |
280 |
> |
double y2 = nanorod.end2->point().y() - nanorod.neight2->point().y(); |
281 |
> |
|
282 |
> |
double endDist = sqrt(pow(nanorod.neight2->point().x() - nanorod.neight3->point().x(),2)+ |
283 |
> |
pow(nanorod.neight2->point().y() - nanorod.neight3->point().y(),2)+ |
284 |
> |
pow(nanorod.neight2->point().z() - nanorod.neight3->point().z(),2)); |
285 |
> |
|
286 |
> |
double endRatio1 = y1/endDist; |
287 |
> |
double endRatio2 = y2/endDist; |
288 |
> |
|
289 |
> |
std::cout << "End dist is " << endDist <<" ratio " << endRatio1 << std::endl; |
290 |
> |
|
291 |
> |
CGAL::Aff_transformation_3<Kernel> aff_tranformation( width, |
292 |
> |
0.0, |
293 |
> |
0.0, |
294 |
> |
0.0, |
295 |
> |
0.0, |
296 |
> |
length, |
297 |
> |
0.0, |
298 |
> |
0.0, |
299 |
> |
0.0, |
300 |
> |
0.0, |
301 |
> |
width, |
302 |
> |
0.0); |
303 |
> |
std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation); |
304 |
|
|
293 |
– |
// Construct normal vector for each face. |
294 |
– |
std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(), |
295 |
– |
Normal_vector()); |
296 |
– |
|
305 |
|
|
306 |
+ |
double endDist2 = sqrt(pow(nanorod.neight2->point().x() - nanorod.neight3->point().x(),2)+ |
307 |
+ |
pow(nanorod.neight2->point().y() - nanorod.neight3->point().y(),2)+ |
308 |
+ |
pow(nanorod.neight2->point().z() - nanorod.neight3->point().z(),2)); |
309 |
+ |
|
310 |
+ |
Point_3 point1(nanorod.end1->point().x(), endDist2*endRatio1 + nanorod.neight1->point().y(), nanorod.end1->point().z()); |
311 |
+ |
Point_3 point2(nanorod.end2->point().x(), endDist2*endRatio2 + nanorod.neight2->point().y(), nanorod.end2->point().z()); |
312 |
+ |
nanorod.end1->point() = point1; |
313 |
+ |
nanorod.end2->point() = point2; |
314 |
|
|
315 |
< |
} |
315 |
> |
// Construct normal vector for each face. |
316 |
> |
std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(), |
317 |
> |
Normal_vector()); |
318 |
> |
} |
319 |
> |
void GeometryBuilder::dumpGeometry(const std::string& geomFileName){ |
320 |
> |
|
321 |
> |
std::ofstream newGeomFile; |
322 |
> |
|
323 |
> |
//create new .md file based on old .md file |
324 |
> |
newGeomFile.open(geomFileName.c_str()); |
325 |
> |
|
326 |
> |
// Write polyhedron in Object File Format (OFF). |
327 |
> |
CGAL::set_ascii_mode( std::cout); |
328 |
> |
newGeomFile << "OFF" << std::endl << nanoRodPolyhedron.size_of_vertices() << ' ' |
329 |
> |
<< nanoRodPolyhedron.size_of_facets() << " 0" << std::endl; |
330 |
> |
std::copy( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), |
331 |
> |
std::ostream_iterator<Point_3>( newGeomFile, "\n")); |
332 |
> |
for ( Facet_iterator i = nanoRodPolyhedron.facets_begin(); i != nanoRodPolyhedron.facets_end(); ++i) { |
333 |
> |
Halfedge_facet_circulator j = i->facet_begin(); |
334 |
> |
// Facets in polyhedral surfaces are at least triangles. |
335 |
> |
CGAL_assertion( CGAL::circulator_size(j) >= 3); |
336 |
> |
newGeomFile << CGAL::circulator_size(j) << ' '; |
337 |
> |
do { |
338 |
> |
newGeomFile << ' ' << std::distance(nanoRodPolyhedron.vertices_begin(), j->vertex()); |
339 |
> |
} while ( ++j != i->facet_begin()); |
340 |
> |
newGeomFile << std::endl; |
341 |
> |
} |
342 |
> |
|
343 |
> |
newGeomFile.close(); |
344 |
> |
|
345 |
> |
|
346 |
> |
|
347 |
> |
|
348 |
> |
} |
349 |
|
|
350 |
+ |
|