mirror of https://github.com/CGAL/cgal
Add an undocumented manipulator which allows operator<< to dispatch OFF, PLY, etc
This commit is contained in:
parent
64a7f4b66a
commit
388a7678e6
|
|
@ -4,7 +4,7 @@ namespace CGAL {
|
||||||
\relates Polyhedron_3
|
\relates Polyhedron_3
|
||||||
\ingroup PkgPolyhedronIOFunc
|
\ingroup PkgPolyhedronIOFunc
|
||||||
|
|
||||||
This operator reads a polyhedral surface in Object File Format, OFF,
|
This function reads a polyhedral surface in %Object File Format, OFF,
|
||||||
with file extension <TT>.off</TT>, which is also understood by
|
with file extension <TT>.off</TT>, which is also understood by
|
||||||
Geomview \cgalCite{cgal:p-gmgv16-96}, from the input stream `in` and
|
Geomview \cgalCite{cgal:p-gmgv16-96}, from the input stream `in` and
|
||||||
appends it to the polyhedral surface \f$ P\f$. Only the point coordinates
|
appends it to the polyhedral surface \f$ P\f$. Only the point coordinates
|
||||||
|
|
@ -19,46 +19,65 @@ format automatically and can read both.
|
||||||
|
|
||||||
\sa `CGAL::Polyhedron_3<Traits>`
|
\sa `CGAL::Polyhedron_3<Traits>`
|
||||||
\sa `CGAL::Polyhedron_incremental_builder_3<HDS>`
|
\sa `CGAL::Polyhedron_incremental_builder_3<HDS>`
|
||||||
\sa `operator<<(std::ostream&, CGAL::Polyhedron_3<PolyhedronTraits_3>&)`
|
\sa \link PkgPolyhedronIOFunc `operator<<(std::ostream&, Polyhedron_3<PolyhedronTraits_3>&)`\endlink
|
||||||
|
|
||||||
|
This function overloads \link PkgBGLIOFct `read_off(std::istream&,FaceGraph)`\endlink.
|
||||||
|
|
||||||
\cgalHeading{Implementation}
|
\cgalHeading{Implementation}
|
||||||
|
|
||||||
This operator is implemented using the modifier mechanism for
|
This operator is implemented using the modifier mechanism for
|
||||||
polyhedral surfaces and the `CGAL::Polyhedron_incremental_builder_3`
|
polyhedral surfaces and the `Polyhedron_incremental_builder_3`
|
||||||
class, which allows the construction in a single, efficient scan pass
|
class, which allows the construction in a single, efficient scan pass
|
||||||
of the input and handles also all the possible flexibility of the
|
of the input and handles also all the possible flexibility of the
|
||||||
polyhedral surface.
|
polyhedral surface.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
template <class PolyhedronTraits_3>
|
template <class PolyhedronTraits_3>
|
||||||
std::istream& operator>>( std::istream& in, CGAL::Polyhedron_3<PolyhedronTraits_3>& P);
|
bool read_off( std::istream& in, Polyhedron_3<PolyhedronTraits_3>& P);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\relates Polyhedron_3
|
||||||
|
\ingroup PkgPolyhedronIOFunc
|
||||||
|
This operator calls `read_off(std::istream& , Polyhedron_3)`.
|
||||||
|
*/
|
||||||
|
template <class PolyhedronTraits_3>
|
||||||
|
std::istream& operator>>( std::istream& in, Polyhedron_3<PolyhedronTraits_3>& P);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\relates Polyhedron_3
|
\relates Polyhedron_3
|
||||||
\ingroup PkgPolyhedronIOFunc
|
\ingroup PkgPolyhedronIOFunc
|
||||||
|
|
||||||
This operator writes the polyhedral surface \f$P\f$ to the output
|
This function writes the polyhedral surface \f$P\f$ to the output
|
||||||
stream `out` using the Object File Format, OFF, with file extension
|
stream `out` using the %Object File Format, OFF, with file extension
|
||||||
<TT>.off</TT>, which is also understood by GeomView \cgalCite{cgal:p-gmgv16-96}. The
|
<TT>.off</TT>, which is also understood by GeomView \cgalCite{cgal:p-gmgv16-96}. The
|
||||||
output is in ASCII format. From the polyhedral surface, only the point
|
output is in ASCII format. From the polyhedral surface, only the point
|
||||||
coordinates and facets are written. Neither normal vectors nor color
|
coordinates and facets are written. Neither normal vectors nor color
|
||||||
attributes are used.
|
attributes are used.
|
||||||
|
|
||||||
For OFF an ASCII and a binary format exist. The format can be selected
|
For OFF an ASCII and a binary format exist. The format can be selected
|
||||||
with the \cgal modifiers for streams, ::set_ascii_mode and
|
with the \cgal modifiers for streams, `set_ascii_mode()` and
|
||||||
set_binary_mode respectively. The modifier ::set_pretty_mode can be used
|
`set_binary_mode()` respectively. The modifier `set_pretty_mode()` can be used
|
||||||
to allow for (a few) structuring comments in the output. Otherwise,
|
to allow for (a few) structuring comments in the output. Otherwise,
|
||||||
the output would be free of comments. The default for writing is ASCII
|
the output would be free of comments. The default for writing is ASCII
|
||||||
without comments.
|
without comments.
|
||||||
|
|
||||||
|
This function overloads `write_off(std::istream&,FaceGraph)`.
|
||||||
|
|
||||||
\sa `CGAL::Polyhedron_3<Traits>`
|
\sa `CGAL::Polyhedron_3<Traits>`
|
||||||
\sa `CGAL::Polyhedron_incremental_builder_3<HDS>`
|
\sa `CGAL::Polyhedron_incremental_builder_3<HDS>`
|
||||||
\sa `operator>>(std::istream&, CGAL::Polyhedron_3<PolyhedronTraits_3>&)`
|
\sa `operator>>(std::istream&, Polyhedron_3<PolyhedronTraits_3>&)`
|
||||||
|
|
||||||
|
*/template <class PolyhedronTraits_3>
|
||||||
|
bool write_off( std::ostream& out, Polyhedron_3<PolyhedronTraits_3>& P);
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\relates Polyhedron_3
|
||||||
|
\ingroup PkgPolyhedronIOFunc
|
||||||
|
This operator calls `write_off(std::istream& , Polyhedron_3)`.
|
||||||
*/
|
*/
|
||||||
template <class PolyhedronTraits_3>
|
template <class PolyhedronTraits_3>
|
||||||
std::ostream& operator<<( std::ostream& out, CGAL::Polyhedron_3<PolyhedronTraits_3>& P);
|
std::ostream& operator<<( std::ostream& out, Polyhedron_3<PolyhedronTraits_3>& P);
|
||||||
|
|
||||||
} /* namespace CGAL */
|
} /* namespace CGAL */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1600,21 +1600,5 @@ public:
|
||||||
}; /* end Polyhedron_3 */
|
}; /* end Polyhedron_3 */
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\relates Polyhedron_3
|
|
||||||
\ingroup PkgPolyhedronIOFunc
|
|
||||||
|
|
||||||
*/
|
|
||||||
template <class PolyhedronTraits_3>
|
|
||||||
bool read_off( std::istream& in, CGAL::Polyhedron_3<PolyhedronTraits_3>& P);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\relates Polyhedron_3
|
|
||||||
\ingroup PkgPolyhedronIOFunc
|
|
||||||
|
|
||||||
*/
|
|
||||||
template <class PolyhedronTraits_3>
|
|
||||||
bool write_off( std::ostream& out, CGAL::Polyhedron_3<PolyhedronTraits_3>& P);
|
|
||||||
|
|
||||||
|
|
||||||
} /* end namespace CGAL */
|
} /* end namespace CGAL */
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ surface can be used without knowing the halfedge data structure.
|
||||||
## Functions ##
|
## Functions ##
|
||||||
- \link PkgPolyhedronIOFunc `CGAL::operator<<()` \endlink
|
- \link PkgPolyhedronIOFunc `CGAL::operator<<()` \endlink
|
||||||
- \link PkgPolyhedronIOFunc `CGAL::operator>>()` \endlink
|
- \link PkgPolyhedronIOFunc `CGAL::operator>>()` \endlink
|
||||||
|
- \link PkgPolyhedronIOFunc `write_off()` \endlink
|
||||||
|
- \link PkgPolyhedronIOFunc `read_off()` \endlink
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ Circulator
|
||||||
Stream_support
|
Stream_support
|
||||||
HalfedgeDS
|
HalfedgeDS
|
||||||
Miscellany
|
Miscellany
|
||||||
|
BGL
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ Returns the previous mode of `s`.
|
||||||
*/
|
*/
|
||||||
IO::Mode set_pretty_mode(std::ios& s);
|
IO::Mode set_pretty_mode(std::ios& s);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\ingroup PkgIOstreams
|
\ingroup PkgIOstreams
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,13 @@ There are a 11 predefined `Color` constants available:
|
||||||
`DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`,
|
`DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`,
|
||||||
and `YELLOW`.
|
and `YELLOW`.
|
||||||
|
|
||||||
|
\section IOstreamManipulators Manipulators for IO of polyhedral surfaces.
|
||||||
|
|
||||||
|
There exists plenty of file formats for polyhedral surfaces, which can be
|
||||||
|
stored in a `Polyhedron` or a `Surface_mesh`. For the insert and extract
|
||||||
|
operators \cgal provides manipulators such as `CGAL::IO::off`, `CGAL::IO:ply`.
|
||||||
|
|
||||||
|
|
||||||
\section IOstreamStream Stream Support
|
\section IOstreamStream Stream Support
|
||||||
|
|
||||||
Three classes are provided by \cgal as adaptors to input and output stream
|
Three classes are provided by \cgal as adaptors to input and output stream
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
Manual
|
Manual
|
||||||
STL_Extension
|
STL_Extension
|
||||||
Geomview
|
Geomview
|
||||||
|
Surface_mesh
|
||||||
|
Polyhedron
|
||||||
|
|
|
||||||
|
|
@ -41,18 +41,65 @@
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
class IO {
|
|
||||||
|
|
||||||
|
namespace IO {
|
||||||
|
|
||||||
|
class Static {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static int get_static_mode()
|
static int get_mode()
|
||||||
{
|
{
|
||||||
static const int mode = std::ios::xalloc();
|
static const int mode = std::ios::xalloc();
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Mode {ASCII = 0, PRETTY, BINARY};
|
|
||||||
|
static int get_file_format()
|
||||||
|
{
|
||||||
|
static const int file_format = std::ios::xalloc();
|
||||||
|
return file_format;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Mode {ASCII = 0, PRETTY, BINARY};
|
||||||
|
|
||||||
|
enum File_format {OFF = 0, COFF, PLY, OBJ, STL};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ios& off(std::ios& os)
|
||||||
|
{
|
||||||
|
os.iword(IO::Static::get_file_format()) = IO::OFF;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::ios& ply(std::ios& os)
|
||||||
|
{
|
||||||
|
os.iword(IO::Static::get_file_format()) = IO::PLY;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ios& obj(std::ios& os)
|
||||||
|
{
|
||||||
|
os.iword(IO::Static::get_file_format()) = IO::OBJ;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ios& stl(std::ios& os)
|
||||||
|
{
|
||||||
|
os.iword(IO::Static::get_file_format()) = IO::STL;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
IO::File_format file_format(std::ios& os)
|
||||||
|
{
|
||||||
|
return static_cast<IO::File_format>(os.iword(IO::Static::get_file_format()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename Dummy>
|
template <typename Dummy>
|
||||||
struct IO_rep_is_specialized_aux
|
struct IO_rep_is_specialized_aux
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ CGAL_INLINE_FUNCTION
|
||||||
IO::Mode
|
IO::Mode
|
||||||
get_mode(std::ios& i)
|
get_mode(std::ios& i)
|
||||||
{
|
{
|
||||||
return static_cast<IO::Mode>(i.iword(IO::get_static_mode()));
|
return static_cast<IO::Mode>(i.iword(Static::get_mode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
CGAL_INLINE_FUNCTION
|
||||||
|
|
@ -48,7 +48,7 @@ IO::Mode
|
||||||
set_ascii_mode(std::ios& i)
|
set_ascii_mode(std::ios& i)
|
||||||
{
|
{
|
||||||
IO::Mode m = get_mode(i);
|
IO::Mode m = get_mode(i);
|
||||||
i.iword(IO::get_static_mode()) = IO::ASCII;
|
i.iword(Static::get_mode()) = IO::ASCII;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ IO::Mode
|
||||||
set_binary_mode(std::ios& i)
|
set_binary_mode(std::ios& i)
|
||||||
{
|
{
|
||||||
IO::Mode m = get_mode(i);
|
IO::Mode m = get_mode(i);
|
||||||
i.iword(IO::get_static_mode()) = IO::BINARY;
|
i.iword(Static::get_mode()) = IO::BINARY;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ IO::Mode
|
||||||
set_pretty_mode(std::ios& i)
|
set_pretty_mode(std::ios& i)
|
||||||
{
|
{
|
||||||
IO::Mode m = get_mode(i);
|
IO::Mode m = get_mode(i);
|
||||||
i.iword(IO::get_static_mode()) = IO::PRETTY;
|
i.iword(Static::get_mode()) = IO::PRETTY;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +76,7 @@ IO::Mode
|
||||||
set_mode(std::ios& i, IO::Mode m)
|
set_mode(std::ios& i, IO::Mode m)
|
||||||
{
|
{
|
||||||
IO::Mode old = get_mode(i);
|
IO::Mode old = get_mode(i);
|
||||||
i.iword(IO::get_static_mode()) = m;
|
i.iword(Static::get_mode()) = m;
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,21 +84,21 @@ CGAL_INLINE_FUNCTION
|
||||||
bool
|
bool
|
||||||
is_pretty(std::ios& i)
|
is_pretty(std::ios& i)
|
||||||
{
|
{
|
||||||
return i.iword(IO::get_static_mode()) == IO::PRETTY;
|
return i.iword(Static::get_mode()) == IO::PRETTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
CGAL_INLINE_FUNCTION
|
||||||
bool
|
bool
|
||||||
is_ascii(std::ios& i)
|
is_ascii(std::ios& i)
|
||||||
{
|
{
|
||||||
return i.iword(IO::get_static_mode()) == IO::ASCII;
|
return i.iword(Static::get_mode()) == IO::ASCII;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
CGAL_INLINE_FUNCTION
|
||||||
bool
|
bool
|
||||||
is_binary(std::ios& i)
|
is_binary(std::ios& i)
|
||||||
{
|
{
|
||||||
return i.iword(IO::get_static_mode()) == IO::BINARY;
|
return i.iword(Static::get_mode()) == IO::BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
CGAL_INLINE_FUNCTION
|
||||||
|
|
|
||||||
|
|
@ -1989,16 +1989,17 @@ private: //------------------------------------------------------- private data
|
||||||
return os.good();
|
return os.good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// \relates Surface_mesh
|
/// \relates Surface_mesh
|
||||||
/// Inserts the surface mesh in an output stream in Ascii OFF format.
|
///
|
||||||
/// Only the \em point property is inserted in the stream.
|
/// This operator calls `write_off(std::istream& , CGAL::Surface_mesh)`.
|
||||||
/// \pre `operator<<(std::ostream&,const P&)` must be defined.
|
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
std::ostream& operator<<(std::ostream& os, const Surface_mesh<P>& sm)
|
std::ostream& operator<<(std::ostream& os, const Surface_mesh<P>& sm)
|
||||||
{
|
{
|
||||||
write_off(os, sm);
|
if(file_format(os) == IO::OFF){
|
||||||
|
write_off(os, sm);
|
||||||
|
} else {
|
||||||
|
std::cerr << "For Surface_mesh we only support the OFF file format" << std::endl;
|
||||||
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2022,7 +2023,8 @@ private: //------------------------------------------------------- private data
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
/// \relates Surface_mesh
|
/// \relates Surface_mesh
|
||||||
/// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF format.
|
/// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF
|
||||||
|
/// format and appends it to the surface mesh `sm`.
|
||||||
/// The operator reads the point property as well as "v:normal", "v:color", and "f:color".
|
/// The operator reads the point property as well as "v:normal", "v:color", and "f:color".
|
||||||
/// Vertex texture coordinates are ignored.
|
/// Vertex texture coordinates are ignored.
|
||||||
/// \pre `operator>>(std::istream&,const P&)` must be defined.
|
/// \pre `operator>>(std::istream&,const P&)` must be defined.
|
||||||
|
|
@ -2134,10 +2136,7 @@ private: //------------------------------------------------------- private data
|
||||||
|
|
||||||
|
|
||||||
/// \relates Surface_mesh
|
/// \relates Surface_mesh
|
||||||
/// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF format.
|
/// This operator calls `read_off(std::istream& , CGAL::Surface_mesh)`.
|
||||||
/// The operator reads the point property as well as "v:normal", "v:color", and "f:color".
|
|
||||||
/// Vertex texture coordinates are ignored.
|
|
||||||
/// \pre `operator>>(std::istream&,const P&)` must be defined.
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
std::istream& operator>>(std::istream& is, Surface_mesh<P>& sm)
|
std::istream& operator>>(std::istream& is, Surface_mesh<P>& sm)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue