1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
// Copyright (c) 1997 Utrecht University (The Netherlands),
// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
// and Tel-Aviv University (Israel). All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; version 2.1 of the License.
// See the file LICENSE.LGPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.6-branch/Inventor/include/CGAL/IO/VRML_2_ostream.h $
// $Id: VRML_2_ostream.h 56414 2010-05-21 17:16:35Z reichel $
//
// Author(s) : Andreas Fabri
// Lutz Kettner <kettner@inf.ethz.ch>
// Herve Bronnimann
// Mariette Yvinec <Mariette.Yvinec@sophia.inria.fr>
#ifndef CGAL_IO_VRML_2_OSTREAM_H
#define CGAL_IO_VRML_2_OSTREAM_H
#include <CGAL/basic.h>
#include <iostream>
CGAL_BEGIN_NAMESPACE
class VRML_2_ostream {
public:
VRML_2_ostream() : m_os(0) {}
VRML_2_ostream(std::ostream& o) : m_os(&o) { header();}
~VRML_2_ostream() { close(); }
void open(std::ostream& o) { m_os = &o; header(); }
void close() {
if ( m_os)
footer();
m_os = 0;
}
typedef const void* Const_void_ptr;
operator Const_void_ptr () const {
if ( m_os)
return *m_os;
return 0;
}
std::ostream& os() {
// The behaviour if m_os == 0 could be changed to return
// cerr or a file handle to /dev/null. The latter one would
// mimick the behaviour that one can still use a stream with
// an invalid stream, but without producing any output.
CGAL_assertion( m_os != 0 );
return *m_os;
}
private:
void header() {
os() << "#VRML V2.0 utf8\n"
"# File written with the help of the CGAL Library\n"
"#-- Begin of file header\n"
"Group {\n"
" children [\n"
" Shape {\n"
" appearance DEF A1 Appearance {\n"
" material Material {\n"
" diffuseColor .6 .5 .9\n"
" }\n }\n"
" appearance\n"
" Appearance {\n"
" material DEF Material Material {}\n"
" }\n"
" geometry NULL\n"
" }\n"
" #-- End of file header" << std::endl;
}
void footer() {
os() << " #-- Begin of file footer\n"
" ]\n"
"}\n"
"#-- End of file footer" << std::endl;
}
std::ostream* m_os;
};
inline
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const char* s)
{
os.os() << s;
return os;
}
inline
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const double& d)
{
os.os() << d;
return os;
}
CGAL_END_NAMESPACE
#endif // CGAL_IO_VRML_2_OSTREAM_H
#ifdef CGAL_TETRAHEDRON_3_H
#ifndef CGAL_IO_VRML_2_TETRAHEDRON_3
#define CGAL_IO_VRML_2_TETRAHEDRON_3
CGAL_BEGIN_NAMESPACE
template <class R >
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const Tetrahedron_3<R > &t)
{
const char *Indent = " ";
os << " Group {\n"
" children [\n"
" Shape {\n"
" appearance\n"
" Appearance {\n"
" material USE Material\n"
" } #Appearance\n"
" geometry\n"
" IndexedFaceSet {\n"
" coord Coordinate {\n"
" point [ \n"
<< Indent << " "
<< CGAL::to_double(t[0].x()) << " "
<< CGAL::to_double(t[0].y()) << " "
<< CGAL::to_double(t[0].z()) << " ,\n"
<< Indent << " "
<< CGAL::to_double(t[1].x()) << " "
<< CGAL::to_double(t[1].y()) << " "
<< CGAL::to_double(t[1].z()) << " ,\n"
<< Indent << " "
<< CGAL::to_double(t[2].x()) << " "
<< CGAL::to_double(t[2].y()) << " "
<< CGAL::to_double(t[2].z()) << " ,\n"
<< Indent << " "
<< CGAL::to_double(t[3].x()) << " "
<< CGAL::to_double(t[3].y()) << " "
<< CGAL::to_double(t[3].z()) <<
"\n ]\n"
" }\n"
" solid FALSE\n"
<< Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n"
<< Indent << " 0,2,3,-1, 0,3,1,-1 ]\n"
" } #IndexedFaceSet\n"
" } #Shape\n"
" ] #children\n"
" } #Group\n";
return os;
}
CGAL_END_NAMESPACE
#endif // CGAL_IO_VRML_2_TETRAHEDRON_3
#endif // CGAL_TETRAHEDRON_3_H
#ifdef CGAL_POINT_3_H
#ifndef CGAL_IO_VRML_2_POINT_3
#define CGAL_IO_VRML_2_POINT_3
CGAL_BEGIN_NAMESPACE
template <class R >
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const Point_3<R > &p)
{
const char *Indent = " ";
os << " Group {\n"
" children [\n"
" Shape {\n"
" appearance USE A1\n"
" geometry\n"
" PointSet {\n"
" coord Coordinate {\n"
" point [ ";
os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y())
<< " " << CGAL::to_double(p.z()) << " ]\n";
os << Indent << "}\n";
os << Indent << "} # PointSet\n";
os << " } #Shape\n"
" ] #children\n"
" } #Group\n";
return os;
}
CGAL_END_NAMESPACE
#endif // CGAL_IO_VRML_2_POINT_3
#endif // CGAL_POINT_3_H
#ifdef CGAL_TRIANGLE_3_H
#ifndef CGAL_IO_VRML_2_TRIANGLE_3
#define CGAL_IO_VRML_2_TRIANGLE_3
CGAL_BEGIN_NAMESPACE
template <class R >
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const Triangle_3<R > &t)
{
const char *Indent = " ";
os << " Group {\n"
" children [\n"
" Shape {\n"
" appearance USE A1\n"
" geometry\n"
" IndexedLineSet {\n"
" coord Coordinate {\n"
" point [ \n";
os << Indent ;
os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y())
<< " " << CGAL::to_double(t[0].z()) << ",\n";
os << Indent;
os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y())
<< " " << CGAL::to_double(t[1].z()) << ",\n";
os << Indent;
os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y())
<< " " << CGAL::to_double(t[2].z()) << " ]\n";
os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n";
os << Indent << "} # IndexedLineSet\n";
os << " } #Shape\n"
" ] #children\n"
" } #Group\n";
return os;
}
CGAL_END_NAMESPACE
#endif // CGAL_IO_VRML_2_TRIANGLE_3
#endif // CGAL_TRIANGLE_3_H
#ifdef CGAL_SEGMENT_3_H
#ifndef CGAL_IO_VRML_2_SEGMENT_3
#define CGAL_IO_VRML_2_SEGMENT_3
CGAL_BEGIN_NAMESPACE
template <class R >
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const Segment_3<R > &s)
{
const char *Indent = " ";
os << " Group {\n"
" children [\n"
" Shape {\n"
" appearance USE A1\n"
" geometry\n"
" IndexedLineSet {\n"
" coord Coordinate {\n"
" point [ \n";
os << Indent << CGAL::to_double(s.source().x());
os << " " << CGAL::to_double(s.source().y())
<< " " << CGAL::to_double(s.source().z()) << ",\n";
os << Indent;
os << CGAL::to_double(s.target().x())
<< " " << CGAL::to_double(s.target().y())
<< " " << CGAL::to_double(s.target().z()) << " ]\n";
os << Indent << "}\n" << Indent << "coordIndex [ 0 1 -1 ]\n";
os << Indent << "} # IndexedLineSet\n";
os << " } #Shape\n"
" ] #children\n"
" } #Group\n";
return os;
}
CGAL_END_NAMESPACE
#endif // CGAL_IO_VRML_2_SEGMENT_3
#endif // CGAL_SEGMENT_3_H
#ifdef CGAL_SPHERE_3_H
#ifndef CGAL_IO_VRML_2_SPHERE_3
#define CGAL_IO_VRML_2_SPHERE_3
CGAL_BEGIN_NAMESPACE
template <class R >
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const Sphere_3<R > &s)
{
os << " Group {\n"
" children [\n"
" Transform {\n"
" translation ";
os << CGAL::to_double(s.center().x()) << " "
<< CGAL::to_double(s.center().y()) << " "
<< CGAL::to_double(s.center().z()) << "\n";
os << " children Shape {\n"
" appearance USE A1\n"
" geometry\n"
" Sphere { "
"radius ";
os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n";
os << " } #children Shape\n"
" } # Transform\n"
" ] #children\n"
" } #Group\n";
return os;
}
CGAL_END_NAMESPACE
#endif // CGAL_IO_VRML_2_SEGMENT_3
#endif // CGAL_SPHERE_3_H
|