| 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; |
| 98 |
|
// A modifier creating a triangle with the incremental builder. |
| 99 |
|
template <class HDS> |
| 100 |
|
class Build_nanorod : public CGAL::Modifier_base<HDS> { |
| 101 |
< |
public: |
| 101 |
> |
public: |
| 102 |
|
Vertex_handle end1; |
| 103 |
|
Vertex_handle neight1; |
| 104 |
< |
Vertex_handle end2; |
| 104 |
> |
Vertex_handle end2; |
| 105 |
|
Vertex_handle neight2; |
| 106 |
+ |
Vertex_handle neight3; |
| 107 |
|
|
| 108 |
|
Build_nanorod() {} |
| 109 |
|
void operator()( HDS& hds) { |
| 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)); |
| 247 |
|
|
| 248 |
|
bool GeometryBuilder::isInsidePolyhedron(double x, double y, double z) { |
| 249 |
|
|
| 250 |
< |
Point_3 point(x,y,z); |
| 250 |
> |
Point_3 point(x,y,z); |
| 251 |
|
Plane_iterator i; |
| 252 |
|
Facet_iterator j; |
| 253 |
|
for ( i =nanoRodPolyhedron.planes_begin(), j = nanoRodPolyhedron.facets_begin(); i != nanoRodPolyhedron.planes_end() && j !=nanoRodPolyhedron.facets_end(); ++i, ++j) { |
| 267 |
|
|
| 268 |
|
|
| 269 |
|
GeometryBuilder::GeometryBuilder(double length,double width) { |
| 270 |
< |
// Create the geometry for nanorod |
| 270 |
> |
// Create the geometry for nanorod |
| 271 |
|
Build_nanorod<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 |
< |
|
| 278 |
< |
CGAL::Aff_transformation_3<Kernel> aff_tranformation( width, |
| 279 |
< |
0.0, |
| 280 |
< |
0.0, |
| 281 |
< |
0.0, |
| 282 |
< |
0.0, |
| 283 |
< |
length, |
| 284 |
< |
0.0, |
| 285 |
< |
0.0, |
| 286 |
< |
0.0, |
| 287 |
< |
0.0, |
| 288 |
< |
width, |
| 289 |
< |
0.0); |
| 290 |
< |
std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation); |
| 291 |
< |
|
| 292 |
< |
Point_3 point1(nanorod.end1->point().x(), y1 + nanorod.neight1->point().y(), nanorod.end1->point().z()); |
| 293 |
< |
Point_3 point2(nanorod.end2->point().x(), y2+ nanorod.neight2->point().y(), nanorod.end2->point().z()); |
| 294 |
< |
nanorod.end1->point() = point1; |
| 295 |
< |
nanorod.end2->point() = point2; |
| 275 |
> |
double y1 = nanorod.end1->point().y() - nanorod.neight1->point().y(); |
| 276 |
> |
double y2 = nanorod.end2->point().y() - nanorod.neight2->point().y(); |
| 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, |
| 290 |
> |
0.0, |
| 291 |
> |
0.0, |
| 292 |
> |
length, |
| 293 |
> |
0.0, |
| 294 |
> |
0.0, |
| 295 |
> |
0.0, |
| 296 |
> |
0.0, |
| 297 |
> |
width, |
| 298 |
> |
0.0); |
| 299 |
> |
std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation); |
| 300 |
|
|
| 293 |
– |
// Construct normal vector for each face. |
| 294 |
– |
std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(), |
| 295 |
– |
Normal_vector()); |
| 296 |
– |
|
| 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 |
< |
} |
| 311 |
> |
// Construct normal vector for each face. |
| 312 |
> |
std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(), |
| 313 |
> |
Normal_vector()); |
| 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 |
> |
} |
| 345 |
|
|
| 346 |
+ |
|