ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/nanorodBuilder/GeometryBuilder.cpp
Revision: 2148
Committed: Wed Apr 6 16:34:09 2005 UTC (19 years, 2 months ago) by chuckv
File size: 10133 byte(s)
Log Message:
Initial import of nanorod builder.

File Contents

# Content
1 /*
2 * GeometryBuilder.cpp
3 * nanorodBuilder
4 *
5 * Created by Charles Vardeman II on 4/4/05.
6 * Copyright 2005 University of Notre Dame. All rights reserved.
7 *
8 */
9
10 /*
11 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
12 *
13 * The University of Notre Dame grants you ("Licensee") a
14 * non-exclusive, royalty free, license to use, modify and
15 * redistribute this software in source and binary code form, provided
16 * that the following conditions are met:
17 *
18 * 1. Acknowledgement of the program authors must be made in any
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
24 * Parallel Simulation Engine for Molecular Dynamics,"
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.
29 *
30 * 3. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the
33 * distribution.
34 *
35 * This software is provided "AS IS," without a warranty of any
36 * kind. All express or implied conditions, representations and
37 * warranties, including any implied warranty of merchantability,
38 * fitness for a particular purpose or non-infringement, are hereby
39 * excluded. The University of Notre Dame and its licensors shall not
40 * be liable for any damages suffered by licensee as a result of
41 * using, modifying or distributing the software or its
42 * derivatives. In no event will the University of Notre Dame or its
43 * licensors be liable for any lost revenue, profit or data, or for
44 * direct, indirect, special, consequential, incidental or punitive
45 * damages, however caused and regardless of the theory of liability,
46 * arising out of the use of or inability to use software, even if the
47 * University of Notre Dame has been advised of the possibility of
48 * such damages.
49 */
50
51 #include "GeometryBuilder.hpp"
52
53 #include <CGAL/Simple_cartesian.h>
54 #include <CGAL/Polyhedron_incremental_builder_3.h>
55 #include <CGAL/Polyhedron_3.h>
56 #include <CGAL/Homogeneous.h>
57 #include <CGAL/Polyhedron_traits_with_normals_3.h>
58 #include <CGAL/Polyhedron_3.h>
59 #include <CGAL/Aff_transformation_3.h>
60 #include <CGAL/aff_transformation_tags.h>
61 #include <iostream>
62 #include <algorithm>
63
64 using namespace oopse;
65
66 //typedef CGAL::Homogeneous<int> Kernel;
67 typedef CGAL::Simple_cartesian<double> Kernel;
68 //typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
69
70 typedef Kernel::Point_3 Point_3;
71 typedef Kernel::Vector_3 Vector_3;
72 typedef CGAL::Polyhedron_traits_with_normals_3<Kernel> Traits;
73 //typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
74 typedef CGAL::Polyhedron_3<Traits> Polyhedron;
75 typedef Polyhedron::HalfedgeDS HalfedgeDS;
76 typedef Polyhedron::Facet_iterator Facet_iterator;
77 typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_facet_circulator;
78 typedef Polyhedron::Facet_iterator Facet_iterator;
79 typedef Polyhedron::Plane_iterator Plane_iterator;
80 typedef Polyhedron::Vertex_handle Vertex_handle;
81
82 Polyhedron nanoRodPolyhedron;
83
84
85
86
87
88
89
90 //typedef CGAL::Scaling Scaling;
91 //typedef Aff_transformation_3<Kernel> A;( const Scaling,
92 // Kernel::RT s=RT(20),
93 // Kernel::RT hw = RT(1));
94
95 // A modifier creating a triangle with the incremental builder.
96 template <class HDS>
97 class Build_nanorod : public CGAL::Modifier_base<HDS> {
98 public:
99 Vertex_handle end1;
100 Vertex_handle neight1;
101 Vertex_handle end2;
102 Vertex_handle neight2;
103
104 Build_nanorod() {}
105 void operator()( HDS& hds) {
106 // Postcondition: `hds' is a valid polyhedral surface.
107 CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true);
108 B.begin_surface( 12, 15, 6);
109 typedef typename HDS::Vertex Vertex;
110 typedef typename Vertex::Point Point;
111
112
113
114
115
116 B.add_vertex( Point(-0.7887222926324, 0.4874571845315, -0.2562714077342));
117 B.add_vertex( Point(-0.4874571845316, 0.4874571845315, 0.6709272557930));
118 B.add_vertex( Point(-0.7887222926324, -0.4874571845315, -0.2562714077342)); //End vertex
119 end1 = B.add_vertex( Point( 0.0000000000000, 1.0000000000000, 0.0000000000000));
120 B.add_vertex( Point(-0.4874571845315, -0.4874571845316, 0.6709272557930));
121 neight1 = B.add_vertex( Point(-0.0000000000000, 0.4874571845316, -0.8293116961175));
122 B.add_vertex( Point( 0.0000000000000, -0.4874571845316, -0.8293116961175));
123 B.add_vertex( Point( 0.4874571845315, 0.4874571845316, 0.6709272557930));
124 end2 = B.add_vertex( Point(-0.0000000000000, -1.0000000000000, 0.0000000000000)); //End Vertex
125 B.add_vertex( Point( 0.7887222926324, 0.4874571845315, -0.2562714077342));
126 neight2 = B.add_vertex( Point( 0.4874571845316, -0.4874571845315, 0.6709272557930));
127 B.add_vertex( Point( 0.7887222926324, -0.4874571845315, -0.2562714077342));
128
129 B.begin_facet();
130 B.add_vertex_to_facet( 7);
131 B.add_vertex_to_facet( 9);
132 B.add_vertex_to_facet( 11);
133 B.add_vertex_to_facet( 10);
134 B.end_facet();
135
136 B.begin_facet();
137 B.add_vertex_to_facet( 8);
138 B.add_vertex_to_facet( 10);
139 B.add_vertex_to_facet( 11);
140 B.end_facet();
141
142 B.begin_facet();
143 B.add_vertex_to_facet( 3);
144 B.add_vertex_to_facet( 9);
145 B.add_vertex_to_facet( 7);
146 B.end_facet();
147
148 B.begin_facet();
149 B.add_vertex_to_facet( 9);
150 B.add_vertex_to_facet( 5);
151 B.add_vertex_to_facet( 6);
152 B.add_vertex_to_facet( 11);
153 B.end_facet();
154
155 B.begin_facet();
156 B.add_vertex_to_facet( 8);
157 B.add_vertex_to_facet( 11);
158 B.add_vertex_to_facet( 6);
159 B.end_facet();
160
161 B.begin_facet();
162 B.add_vertex_to_facet( 3);
163 B.add_vertex_to_facet( 5);
164 B.add_vertex_to_facet( 9);
165 B.end_facet();
166
167 B.begin_facet();
168 B.add_vertex_to_facet( 5);
169 B.add_vertex_to_facet( 0);
170 B.add_vertex_to_facet( 2);
171 B.add_vertex_to_facet( 6);
172 B.end_facet();
173
174 B.begin_facet();
175 B.add_vertex_to_facet( 8);
176 B.add_vertex_to_facet( 6);
177 B.add_vertex_to_facet( 2);
178 B.end_facet();
179
180 B.begin_facet();
181 B.add_vertex_to_facet( 3);
182 B.add_vertex_to_facet( 0);
183 B.add_vertex_to_facet( 5);
184 B.end_facet();
185
186 B.begin_facet();
187 B.add_vertex_to_facet( 0);
188 B.add_vertex_to_facet( 1);
189 B.add_vertex_to_facet( 4);
190 B.add_vertex_to_facet( 2);
191 B.end_facet();
192
193 B.begin_facet();
194 B.add_vertex_to_facet( 8);
195 B.add_vertex_to_facet( 2);
196 B.add_vertex_to_facet( 4);
197 B.end_facet();
198
199 B.begin_facet();
200 B.add_vertex_to_facet( 3);
201 B.add_vertex_to_facet( 1);
202 B.add_vertex_to_facet( 0);
203 B.end_facet();
204
205 B.begin_facet();
206 B.add_vertex_to_facet( 1);
207 B.add_vertex_to_facet( 7);
208 B.add_vertex_to_facet( 10);
209 B.add_vertex_to_facet( 4);
210 B.end_facet();
211
212 B.begin_facet();
213 B.add_vertex_to_facet( 8);
214 B.add_vertex_to_facet( 4);
215 B.add_vertex_to_facet( 10);
216 B.end_facet();
217
218 B.begin_facet();
219 B.add_vertex_to_facet( 3);
220 B.add_vertex_to_facet( 7);
221 B.add_vertex_to_facet( 1);
222 B.end_facet();
223
224
225 B.end_surface();
226 }
227 };
228
229
230
231 struct Normal_vector {
232 template <class Facet>
233 typename Facet::Plane_3 operator()( Facet& f) {
234 typename Facet::Halfedge_handle h = f.halfedge();
235 // Facet::Plane_3 is the normal vector type. We assume the
236 // CGAL Kernel here and use its global functions.
237 return CGAL::cross_product(
238 h->next()->vertex()->point() - h->vertex()->point(),
239 h->next()->next()->vertex()->point() - h->next()->vertex()->point());
240 }
241 };
242
243
244 bool GeometryBuilder::isInsidePolyhedron(double x, double y, double z) {
245
246 Point_3 point(x,y,z);
247 Plane_iterator i;
248 Facet_iterator j;
249 for ( i =nanoRodPolyhedron.planes_begin(), j = nanoRodPolyhedron.facets_begin(); i != nanoRodPolyhedron.planes_end() && j !=nanoRodPolyhedron.facets_end(); ++i, ++j) {
250 Halfedge_facet_circulator k = j->facet_begin();
251
252 Vector_3 newVector = point - k->vertex()->point();
253 Vector_3 normal = *i;
254 double dot_product = newVector.x() * normal.x() + newVector.y() * normal.y() + newVector.z() * normal.z();
255
256 if (dot_product < 0) {
257 return false;
258 }
259 }
260
261 return true;
262 }
263
264
265 GeometryBuilder::GeometryBuilder(double length,double width) {
266 // Create the geometry for nanorod
267 Build_nanorod<HalfedgeDS> nanorod;
268
269 nanoRodPolyhedron.delegate( nanorod);
270
271 double y1 = nanorod.end1->point().y() - nanorod.neight1->point().y();
272 double y2 = nanorod.end2->point().y() - nanorod.neight2->point().y();
273
274 CGAL::Aff_transformation_3<Kernel> aff_tranformation( width,
275 0.0,
276 0.0,
277 0.0,
278 0.0,
279 length,
280 0.0,
281 0.0,
282 0.0,
283 0.0,
284 width,
285 0.0);
286 std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation);
287
288 Point_3 point1(nanorod.end1->point().x(), y1 + nanorod.neight1->point().y(), nanorod.end1->point().z());
289 Point_3 point2(nanorod.end2->point().x(), y2+ nanorod.neight2->point().y(), nanorod.end2->point().z());
290 nanorod.end1->point() = point1;
291 nanorod.end2->point() = point2;
292
293 // Construct normal vector for each face.
294 std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(),
295 Normal_vector());
296
297
298
299 }
300