aimsdata 6.0.0
Neuroimaging data handling
povW.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_IO_POVW_H
35#define AIMS_IO_POVW_H
36
39#include <aims/io/meshheader.h>
40#include <aims/mesh/surface.h>
42#include <cartobase/exception/file.h>
43
44
45namespace aims
46{
47
51 template<int D, class T=Void>
53 {
54 public:
55 PovWriter( const std::string & name )
56 : _name( name ) { }
58
59 inline void write( const AimsTimeSurface<D,T> & thing );
60
62 inline std::string removeExtension(const std::string& name) const;
63
64 private:
65 std::string _name;
66 };
67
68
69 template <int D, class T>
70 inline
72 operator << ( PovWriter<D,T> & writer, const AimsTimeSurface<D,T> & thing )
73 {
74 writer.write( thing );
75 return( writer );
76 }
77
78
79 template <int D, class T>
80 std::string PovWriter<D,T>::removeExtension( const std::string& name ) const
81 {
82 std::string res = name;
83 std::string ext="";
84 if( res.length() > 4 )
85 ext = res.substr( int(res.length() - 4), 4 );
86 if( ext == ".pov" )
87 res = res.substr( 0, res.length() - 4 );
88 return res;
89 }
90
91
92 template <int D, class T>
94 {
95 std::string fname = removeExtension( _name ) + ".pov";
96 std::ofstream os( fname.c_str() );
97 if( !os )
98 throw carto::file_error( fname );
99
100 // write data
101 os << "mesh2 {" << std::endl;
102
103 typename AimsTimeSurface<D,T>::const_iterator is = thing.begin();
104
105 // Only fisrt time step is written
106 if ( is != thing.end() ) {
107 const std::vector<Point3df> &vert = (*is).second.vertex();
108 const std::vector<Point3df> &norm = (*is).second.normal();
109 const std::vector<AimsVector<uint,D> > &poly
110 = (*is).second.polygon();
111
112
113 // vertices
114 os << " vertex_vectors {" << std::endl
115 << vert.size() << "," << std::endl << " ";
116 for( std::vector<Point3df>::const_iterator iv = vert.begin();
117 iv != vert.end(); ++iv ) {
118 os << "<" << (*iv)[0] << "," << (*iv)[1] << "," << (*iv)[2] << ">,";
119 }
120 os << " }" << std::endl;
121
122 // normals
123 if ( ! norm.empty() ) {
124 os << " normal_vectors {" << std::endl
125 << norm.size() << "," << std::endl << " ";
126 for( std::vector<Point3df>::const_iterator in = norm.begin();
127 in != norm.end(); ++in ) {
128 os << "<" << (*in)[0] << "," << (*in)[1] << "," << (*in)[2] << ">,";
129 }
130 os << " }" << std::endl;
131 }
132
133 // polygons
134 os << " face_indices {" << std::endl
135 << poly.size() << "," << std::endl << " ";
136 for( typename std::vector<AimsVector<uint,D> >::const_iterator ip =
137 poly.begin(); ip != poly.end(); ++ip ) {
138 os << "<" << (*ip)[0] << "," << (*ip)[1] << "," << (*ip)[2] << ">,";
139 }
140 os << " }" << std::endl;
141
142 os << " pigment { Gray80 }\n}" << std::endl;
143 }
144 }
145}
146
147
148#endif
#define AIMSDATA_API
The template class to manage a mesh with time if needed.
Definition surface.h:317
std::map< int, AimsSurface< D, T > >::const_iterator const_iterator
Definition surface.h:321
POV (http://www.povray.org) format writer for mesh objects.
Definition povW.h:53
std::string removeExtension(const std::string &name) const
Return a name without .pov extension.
Definition povW.h:80
void write(const AimsTimeSurface< D, T > &thing)
Definition povW.h:93
PovWriter(const std::string &name)
Definition povW.h:55
The class for EcatSino data write operation.
bool write(const T &obj, const std::string &filename, carto::Object options=carto::none(), const std::string *format=0)
Finds the correct format and writes the object, global version.
Definition writer.h:141
AIMSDATA_API PovWriter< D, T > & operator<<(PovWriter< D, T > &writer, const AimsTimeSurface< D, T > &thing)
Definition povW.h:72
float norm(const AimsVector< T, D > &v1)