cimg.cxx 3.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plugins/vtk.h ADDED
@@ -0,0 +1,103 @@
1
+ /*
2
+ #
3
+ # File : vtk.h
4
+ # ( C++ header file - CImg plug-in )
5
+ #
6
+ # Description : CImg plugin that implements a way to save 3d scene as TK legacy file format.
7
+ # This file is a part of the CImg Library project.
8
+ # ( http://cimg.eu )
9
+ #
10
+ # Copyright : Haz-Edine Assemlal
11
+ # ( http://www.cim.mcgill.ca/~assemlal/ )
12
+ #
13
+ # License : CeCILL v2.0
14
+ # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
15
+ #
16
+ # This software is governed by the CeCILL license under French law and
17
+ # abiding by the rules of distribution of free software. You can use,
18
+ # modify and/ or redistribute the software under the terms of the CeCILL
19
+ # license as circulated by CEA, CNRS and INRIA at the following URL
20
+ # "http://www.cecill.info".
21
+ #
22
+ # As a counterpart to the access to the source code and rights to copy,
23
+ # modify and redistribute granted by the license, users are provided only
24
+ # with a limited warranty and the software's author, the holder of the
25
+ # economic rights, and the successive licensors have only limited
26
+ # liability.
27
+ #
28
+ # In this respect, the user's attention is drawn to the risks associated
29
+ # with loading, using, modifying and/or developing or reproducing the
30
+ # software by the user in light of its specific status of free software,
31
+ # that may mean that it is complicated to manipulate, and that also
32
+ # therefore means that it is reserved for developers and experienced
33
+ # professionals having in-depth computer knowledge. Users are therefore
34
+ # encouraged to load and test the software's suitability as regards their
35
+ # requirements in conditions enabling the security of their systems and/or
36
+ # data to be ensured and, more generally, to use and operate it in the
37
+ # same conditions as regards security.
38
+ #
39
+ # The fact that you are presently reading this means that you have had
40
+ # knowledge of the CeCILL license and that you accept its terms.
41
+ #
42
+ */
43
+
44
+ #ifndef cimg_plugin_vtk
45
+ #define cimg_plugin_vtk
46
+
47
+ // Save 3D scene in legacy VTK format
48
+ /* *this: CImgList of points
49
+ * faces: CImgList of faces
50
+ * colors: CImgList of colors,
51
+ * opacities: CImgList of opacities
52
+ */
53
+ template<typename tf, typename tc, typename to>
54
+ CImgList<T>& save_vtk(const char* const filename,
55
+ const CImgList<tf>& faces,
56
+ const CImgList<tc>& colors,
57
+ const CImgList<to>& opacities) {
58
+ // Open file
59
+ std::FILE *const nfile = cimg::fopen(filename,"w");
60
+
61
+ // Header
62
+ std::fprintf(nfile,"# vtk DataFile Version 3.0\n");
63
+ std::fprintf(nfile,"%s\n",filename);
64
+ std::fprintf(nfile,"ASCII\n");
65
+ std::fprintf(nfile,"DATASET UNSTRUCTURED_GRID\n");
66
+
67
+ // Points
68
+ std::fprintf(nfile,"POINTS %u float\n",points.size());
69
+ cimglist_for(points,p)
70
+ std::fprintf(nfile,"%f %f %f\n",points[p](0),points[p](1),points[p](2));
71
+ std::fprintf(nfile,"\n");
72
+
73
+ // Faces (valid only for triangles - type 5)
74
+ if (faces) {
75
+ std::fprintf(nfile,"CELLS %u %u\n",faces.size(),faces.size()*4);
76
+ cimglist_for(faces,f)
77
+ std::fprintf(nfile,"%d %u %u %u\n",3,faces[f](0),faces[f](1),faces[f](2));
78
+ std::fprintf(nfile,"CELL_TYPES %u\n",faces.size());
79
+ cimglist_for(faces,f)
80
+ std::fprintf(nfile,"%d\n",5);
81
+ std::fprintf(nfile,"\n");
82
+ }
83
+
84
+ // Colors and Opacities
85
+ std::fprintf(nfile,"CELL_DATA %d\n",colors.size());
86
+ std::fprintf(nfile,"COLOR_SCALARS colors 4\n");
87
+
88
+ const tc tcmax = cimg::type<tc>::max();
89
+ cimglist_for(colors,t)
90
+ std::fprintf(nfile,"%f %f %f %f\n",
91
+ (float)colors[t](0)/tcmax,
92
+ (float)colors[t](1)/tcmax,
93
+ (float)colors[t](2)/tcmax,
94
+ opacities[t](0));
95
+ std::fprintf(nfile,"\n");
96
+
97
+ // Close file
98
+ cimg::fclose(nfile);
99
+
100
+ return *this;
101
+ }
102
+
103
+ #endif /* cimg_plugin_vtk */