1 // Copyright (c) 1997
2 // Utrecht University (The Netherlands),
3 // ETH Zurich (Switzerland),
4 // INRIA Sophia-Antipolis (France),
5 // Max-Planck-Institute Saarbruecken (Germany),
6 // and Tel-Aviv University (Israel).  All rights reserved.
7 //
8 // This file is part of CGAL (www.cgal.org)
9 //
10 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h $
11 // $Id: File_writer_VRML_2.h 4e519a3 2021-05-05T13:15:37+02:00 Sébastien Loriot
12 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
13 //
14 //
15 // Author(s)     : Lutz Kettner  <kettner@mpi-sb.mpg.de>
16 
17 #ifndef CGAL_IO_FILE_WRITER_VRML_2_H
18 #define CGAL_IO_FILE_WRITER_VRML_2_H
19 
20 #include <CGAL/basic.h>
21 
22 #include <CGAL/IO/VRML/VRML_2_ostream.h>
23 
24 #include <cstddef>
25 #include <iostream>
26 
27 namespace CGAL {
28 
29 class File_writer_VRML_2
30 {
31   VRML_2_ostream m_os;
32   std::size_t m_facets;
33 
34 public:
File_writer_VRML_2()35   File_writer_VRML_2(): m_facets(0) {}
36 
out()37   std::ostream& out() const { return m_os.os(); }
38 
39   void write_header(VRML_2_ostream& o,
40                     std::size_t vertices,
41                     std::size_t halfedges,
42                     std::size_t facets,
43                     const bool /*colors*/ = false,
44                     const bool /*normals*/ = false,
45                     const bool /*textures*/ = false)
46   {
47     m_os = o;
48     m_facets = facets;
49 
50     out() << "        #-- Begin of Polygon Mesh\n";
51     out() << "        # " << vertices << " vertices\n";
52     out() << "        # " << halfedges << " halfedges\n";
53     out() << "        # " << facets << " facets\n";
54     out() << "        Group {\n"
55              "            children [\n"
56              "                Shape {\n"
57              "                    appearance Appearance { material USE Material }\n"
58              "                    geometry IndexedFaceSet {\n"
59              "                        convex FALSE\n"
60              "                        solid  FALSE\n"
61              "                        coord  Coordinate {\n"
62              "                            point [" << std::endl;
63   }
64 
write_footer()65   void write_footer() const
66   {
67     out() << "                        ] #coordIndex\n"
68              "                    } #geometry\n"
69              "                } #Shape\n"
70              "            ] #children\n"
71              "        } #Group" << std::endl;
72   }
73 
write_vertex(const double x,const double y,const double z)74   void write_vertex( const double x, const double y, const double z)
75   {
76     out() << "                                "
77           << IO::oformat(x) << ' ' << IO::oformat(y) << ' ' << IO::oformat(z) << ',' << '\n';
78   }
write_vertex_normal(const double,const double,const double)79   void write_vertex_normal(const double, const double, const double) { }
write_vertex_color(const double,const double,const double)80   void write_vertex_color(const double, const double, const double) { }
write_vertex_texture(const double,const double)81   void write_vertex_texture(const double, const double) { }
82 
write_facet_header()83   void write_facet_header() const
84   {
85     out() << "                            ] #point\n"
86              "                        } #coord Coordinate\n"
87              "                        coordIndex  [" << std::endl;
88   }
89 
write_facet_begin(std::size_t)90   void write_facet_begin(std::size_t) { out() << "                            "; }
write_facet_vertex_index(std::size_t idx)91   void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';}
write_face_color(const double,const double,const double)92   void write_face_color(const double, const double, const double) { }
write_facet_end()93   void write_facet_end() { out() << "-1,\n"; }
94 };
95 
96 } // namespace CGAL
97 
98 #endif // CGAL_IO_FILE_WRITER_VRML_2_H //
99