ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/nanoRodBuilder/GeometryBuilder.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/applications/nanoRodBuilder/GeometryBuilder.cpp (file contents):
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 2239 by chuckv, Sun May 22 21:36:21 2005 UTC

# Line 60 | Line 60
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;
# Line 92 | Line 95 | Polyhedron nanoRodPolyhedron;
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> {
104 > class buildSingleCrystal : public CGAL::Modifier_base<HDS> {
105   public:
106    Vertex_handle end1;
107    Vertex_handle neight1;
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);
# Line 117 | Line 125 | class Build_nanorod : public CGAL::Modifier_base<HDS>
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));
# Line 264 | Line 272 | GeometryBuilder::GeometryBuilder(double length,double
272  
273   GeometryBuilder::GeometryBuilder(double length,double width) {
274    // Create the geometry for nanorod
275 <  Build_nanorod<HalfedgeDS> 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 <        
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,
# Line 285 | Line 302 | GeometryBuilder::GeometryBuilder(double length,double
302                                                          0.0);  
303    std::transform( nanoRodPolyhedron.points_begin(), nanoRodPolyhedron.points_end(), nanoRodPolyhedron.points_begin(), aff_tranformation);
304          
305 <  Point_3 point1(nanorod.end1->point().x(), y1 + nanorod.neight1->point().y(), nanorod.end1->point().z());
306 <  Point_3 point2(nanorod.end2->point().x(), y2+ nanorod.neight2->point().y(), nanorod.end2->point().z());
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    // Construct normal vector for each face.
316    std::transform( nanoRodPolyhedron.facets_begin(), nanoRodPolyhedron.facets_end(), nanoRodPolyhedron.planes_begin(),
317                    Normal_vector());
318 <        
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 < }
348 >  }
349  
350 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines