18 02 2004 Radu Ursu

- added in VRML_2_ostream << operators for
        - Point_3
        - Segment_3
        - Triangle_3
        - const char*
        - const double&
- created a small testsuite to test those operators.
This commit is contained in:
Radu Ursu 2004-02-18 16:27:00 +00:00
parent 9f14b76b3f
commit c0cab42781
3 changed files with 165 additions and 0 deletions

View File

@ -1,3 +1,12 @@
18 02 2004 Radu Ursu
- added in VRML_2_ostream << operators for
- Point_3
- Segment_3
- Triangle_3
- const char*
- const double&
- created a small testsuite to test those operators.
Ver 2.11 (22 Oct 2003)
- new header

View File

@ -89,6 +89,22 @@ private:
std::ostream* m_os;
};
VRML_2_ostream&
operator<<(VRML_2_ostream& os,
const char* s)
{
os.os() << s;
return os;
}
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
@ -149,3 +165,120 @@ 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.os() << " Group {\n"
" children [\n"
" Shape {\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.os() << " Group {\n"
" children [\n"
" Shape {\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.os() << " Group {\n"
" children [\n"
" Shape {\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

View File

@ -0,0 +1,23 @@
// examples/Inventor/VRML2.C
// ----------------------------------------
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/VRML_2_ostream.h>
#include <iostream>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Point_3<Kernel> Point;
typedef CGAL::Segment_3<Kernel> Segment;
typedef CGAL::Triangle_3<Kernel> Triangle;
typedef CGAL::Tetrahedron_3<Kernel> Tetrahedron;
int main() {
Point p1(10, 15, 0), p2(0, 0, 0),
p3(-10, 0, -15), p4(15, 15, 15);
Segment s1(p1, p2);
Triangle t1(p1, p2, p3);
Tetrahedron tet1(p1, p2, p3, p4);
CGAL::VRML_2_ostream out( std::cout);
out << s1 << t1 << p1 << tet1;
return 0;
}